var __defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(e,t,r)=>t in e?__defProp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,__spreadValues=(e,t)=>{for(var r in t||(t={}))__hasOwnProp.call(t,r)&&__defNormalProp(e,r,t[r]);if(__getOwnPropSymbols)for(var r of __getOwnPropSymbols(t))__propIsEnum.call(t,r)&&__defNormalProp(e,r,t[r]);return e},__spreadProps=(e,t)=>__defProps(e,__getOwnPropDescs(t));function getIterator(e){if("function"==typeof e.next)return e;if("function"==typeof e[Symbol.iterator])return e[Symbol.iterator]();if("function"==typeof e[Symbol.asyncIterator])return e[Symbol.asyncIterator]();throw new TypeError('"values" does not to conform to any of the iterator or iterable protocols')}function defer(){let e,t;return{promise:new Promise(((r,n)=>{t=r,e=n})),reject:e,resolve:t}}function _transform(e,t,r){const n=getIterator(r),o=[],i=[];let s=!1,a=!1,c=0,u=null;function l(){for(;i.length>0&&o.length>0;){const{resolve:e}=i.shift();e({done:!1,value:o.shift()})}for(;i.length>0&&0===c&&s;){const{resolve:e,reject:t}=i.shift();u?(t(u),u=null):e({done:!0,value:void 0})}}async function f(){if(s)l();else if(!(a||c+o.length>=e)){a=!0,c++;try{const{done:e,value:r}=await n.next();e?(s=!0,c--,l()):async function(e){try{const r=await t(e);o.push(r)}catch(r){s=!0,u=r}c--,l(),f()}(r)}catch(r){s=!0,c--,u=r,l()}a=!1,f()}}const h={next:async function(){if(0===o.length){const e=defer();return i.push(e),f(),e.promise}const e=o.shift();return f(),{done:!1,value:e}},[Symbol.asyncIterator]:()=>h};return h}function transform(e,t,r){return void 0===t?(t,r)=>r?transform(e,t,r):transform(e,t):void 0===r?r=>transform(e,t,r):_transform(e,t,r)}var commonjsGlobal="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function getAugmentedNamespace(e){if(e.__esModule)return e;var t=Object.defineProperty({},"__esModule",{value:!0});return Object.keys(e).forEach((function(r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})})),t}var pRetry$2={exports:{}},retry$2={};function RetryOperation(e,t){"boolean"==typeof t&&(t={forever:t}),this._originalTimeouts=JSON.parse(JSON.stringify(e)),this._timeouts=e,this._options=t||{},this._maxRetryTime=t&&t.maxRetryTime||1/0,this._fn=null,this._errors=[],this._attempts=1,this._operationTimeout=null,this._operationTimeoutCb=null,this._timeout=null,this._operationStart=null,this._timer=null,this._options.forever&&(this._cachedTimeouts=this._timeouts.slice(0))}var retry_operation=RetryOperation,exports,RetryOperation2;RetryOperation.prototype.reset=function(){this._attempts=1,this._timeouts=this._originalTimeouts.slice(0)},RetryOperation.prototype.stop=function(){this._timeout&&clearTimeout(this._timeout),this._timer&&clearTimeout(this._timer),this._timeouts=[],this._cachedTimeouts=null},RetryOperation.prototype.retry=function(e){if(this._timeout&&clearTimeout(this._timeout),!e)return!1;var t=(new Date).getTime();if(e&&t-this._operationStart>=this._maxRetryTime)return this._errors.push(e),this._errors.unshift(new Error("RetryOperation timeout occurred")),!1;this._errors.push(e);var r=this._timeouts.shift();if(void 0===r){if(!this._cachedTimeouts)return!1;this._errors.splice(0,this._errors.length-1),r=this._cachedTimeouts.slice(-1)}var n=this;return this._timer=setTimeout((function(){n._attempts++,n._operationTimeoutCb&&(n._timeout=setTimeout((function(){n._operationTimeoutCb(n._attempts)}),n._operationTimeout),n._options.unref&&n._timeout.unref()),n._fn(n._attempts)}),r),this._options.unref&&this._timer.unref(),!0},RetryOperation.prototype.attempt=function(e,t){this._fn=e,t&&(t.timeout&&(this._operationTimeout=t.timeout),t.cb&&(this._operationTimeoutCb=t.cb));var r=this;this._operationTimeoutCb&&(this._timeout=setTimeout((function(){r._operationTimeoutCb()}),r._operationTimeout)),this._operationStart=(new Date).getTime(),this._fn(this._attempts)},RetryOperation.prototype.try=function(e){console.log("Using RetryOperation.try() is deprecated"),this.attempt(e)},RetryOperation.prototype.start=function(e){console.log("Using RetryOperation.start() is deprecated"),this.attempt(e)},RetryOperation.prototype.start=RetryOperation.prototype.try,RetryOperation.prototype.errors=function(){return this._errors},RetryOperation.prototype.attempts=function(){return this._attempts},RetryOperation.prototype.mainError=function(){if(0===this._errors.length)return null;for(var e={},t=null,r=0,n=0;n=r&&(t=o,r=s)}return t},exports=retry$2,RetryOperation2=retry_operation,exports.operation=function(e){var t=exports.timeouts(e);return new RetryOperation2(t,{forever:e&&(e.forever||e.retries===1/0),unref:e&&e.unref,maxRetryTime:e&&e.maxRetryTime})},exports.timeouts=function(e){if(e instanceof Array)return[].concat(e);var t={retries:10,factor:2,minTimeout:1e3,maxTimeout:1/0,randomize:!1};for(var r in e)t[r]=e[r];if(t.minTimeout>t.maxTimeout)throw new Error("minTimeout is greater than maxTimeout");for(var n=[],o=0;o{const n=r.retries-(t-1);return e.attemptNumber=t,e.retriesLeft=n,e},isNetworkError=e=>networkErrorMsgs.includes(e),pRetry=(e,t)=>new Promise(((r,n)=>{t=__spreadValues({onFailedAttempt:()=>{},retries:10},t);const o=retry.operation(t);o.attempt((async i=>{try{r(await e(i))}catch(s){if(!(s instanceof Error))return void n(new TypeError(`Non-error was thrown: "${s}". You should only throw errors.`));if(s instanceof AbortError)o.stop(),n(s.originalError);else if(s instanceof TypeError&&!isNetworkError(s.message))o.stop(),n(s);else{decorateErrorWithCounts(s,i,t);try{await t.onFailedAttempt(s)}catch(a){return void n(a)}o.retry(s)||n(o.mainError())}}}))}));pRetry$2.exports=pRetry,pRetry$2.exports.default=pRetry,pRetry$2.exports.AbortError=AbortError;var pRetry$1=pRetry$2.exports;const last=async e=>{let t;for await(const r of e)t=r;return t};var itLast=last,itPipe={exports:{}};const rawPipe=(...e)=>{let t;for(;e.length;)t=e.shift()(t);return t},isIterable$1=e=>e&&("function"==typeof e[Symbol.asyncIterator]||"function"==typeof e[Symbol.iterator]||"function"==typeof e.next),isDuplex=e=>e&&"function"==typeof e.sink&&isIterable$1(e.source),duplexPipelineFn=e=>t=>(e.sink(t),e.source),pipe=(...e)=>{if(isDuplex(e[0])){const t=e[0];e[0]=()=>t.source}else if(isIterable$1(e[0])){const t=e[0];e[0]=()=>t}if(e.length>1&&isDuplex(e[e.length-1])&&(e[e.length-1]=e[e.length-1].sink),e.length>2)for(let t=1;tNumber.MAX_SAFE_INTEGER)throw encode$8.bytes=0,new RangeError("Could not encode varint");t=t||[];for(var n=r=r||0;e>=INT$1;)t[r++]=255&e|MSB$3,e/=128;for(;e&MSBALL$1;)t[r++]=255&e|MSB$3,e>>>=7;return t[r]=0|e,encode$8.bytes=r-n+1,t}var decode$a=read$1,MSB$2=128,REST$2=127;function read$1(e,t){var r,n=0,o=0,i=t=t||0,s=e.length;do{if(i>=s||o>49)throw read$1.bytes=0,new RangeError("Could not decode varint");r=e[i++],n+=o<28?(r&REST$2)<=MSB$2);return read$1.bytes=i-t,n}var N1$1=Math.pow(2,7),N2$1=Math.pow(2,14),N3$1=Math.pow(2,21),N4$1=Math.pow(2,28),N5$1=Math.pow(2,35),N6$1=Math.pow(2,42),N7$1=Math.pow(2,49),N8$1=Math.pow(2,56),N9$1=Math.pow(2,63),length$1=function(e){return e=INT;)t[r++]=255&e|MSB,e/=128;for(;e&MSBALL;)t[r++]=255&e|MSB,e>>>=7;return t[r]=0|e,encode$7.bytes=r-n+1,t}var decode$9=read,MSB$1=128,REST$1=127;function read(e,t){var r,n=0,o=0,i=t=t||0,s=e.length;do{if(i>=s)throw read.bytes=0,new RangeError("Could not decode varint");r=e[i++],n+=o<28?(r&REST$1)<=MSB$1);return read.bytes=i-t,n}var N1=Math.pow(2,7),N2=Math.pow(2,14),N3=Math.pow(2,21),N4=Math.pow(2,28),N5=Math.pow(2,35),N6=Math.pow(2,42),N7=Math.pow(2,49),N8=Math.pow(2,56),N9=Math.pow(2,63),length=function(e){return e[_brrp_varint.decode(e),_brrp_varint.decode.bytes],encodeTo=(e,t,r=0)=>(_brrp_varint.encode(e,t,r),t),encodingLength=e=>_brrp_varint.encodingLength(e),empty=new Uint8Array(0),fromHex=e=>{const t=e.match(/../g);return t?new Uint8Array(t.map((e=>parseInt(e,16)))):empty},equals$2=(e,t)=>{if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r{if(e instanceof Uint8Array&&"Uint8Array"===e.constructor.name)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")},fromString$3=e=>(new TextEncoder).encode(e),toString$1=e=>(new TextDecoder).decode(e),create$4=(e,t)=>{const r=t.byteLength,n=encodingLength(e),o=n+encodingLength(r),i=new Uint8Array(o+r);return encodeTo(e,i,0),encodeTo(r,i,n),i.set(t,o),new Digest$1(e,r,t,i)},decode$7=e=>{const t=coerce(e),[r,n]=decode$8(t),[o,i]=decode$8(t.subarray(n)),s=t.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Digest$1(r,o,s,t)},equals$1=(e,t)=>e===t||e.code===t.code&&e.size===t.size&&equals$2(e.bytes,t.bytes);class Digest$1{constructor(e,t,r,n){this.code=e,this.size=t,this.digest=r,this.bytes=n}}var digest=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",create:create$4,decode:decode$7,equals:equals$1,Digest:Digest$1});function base(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n>>0,s=new Uint8Array(i);e[t];){var l=r[e.charCodeAt(t)];if(255===l)return;for(var f=0,h=i-1;(0!==l||f>>0,s[h]=l%256>>>0,l=l/256>>>0;if(0!==l)throw new Error("Non-zero carry");o=f,t++}if(" "!==e[t]){for(var d=i-o;d!==i&&0===s[d];)d++;for(var p=new Uint8Array(n+(i-d)),y=n;d!==i;)p[y++]=s[d++];return p}}}return{encode:function(t){if(t instanceof Uint8Array||(ArrayBuffer.isView(t)?t=new Uint8Array(t.buffer,t.byteOffset,t.byteLength):Array.isArray(t)&&(t=Uint8Array.from(t))),!(t instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(0===t.length)return"";for(var r=0,n=0,o=0,i=t.length;o!==i&&0===t[o];)o++,r++;for(var s=(i-o)*l+1>>>0,u=new Uint8Array(s);o!==i;){for(var f=t[o],h=0,d=s-1;(0!==f||h>>0,u[d]=f%a>>>0,f=f/a>>>0;if(0!==f)throw new Error("Non-zero carry");n=h,o++}for(var p=s-n;p!==s&&0===u[p];)p++;for(var y=c.repeat(r);pnew Codec(e,t,r,n),baseX=({prefix:e,name:t,alphabet:r})=>{const{encode:n,decode:o}=_brrp__multiformats_scope_baseX(r,t);return from$1({prefix:e,name:t,encode:n,decode:e=>coerce(o(e))})},decode$6=(e,t,r,n)=>{const o={};for(let l=0;l=8&&(a-=8,s[u++]=255&c>>a)}if(a>=r||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return s},encode$6=(e,t,r)=>{const n="="===t[t.length-1],o=(1<r;)s-=r,i+=t[o&a>>s];if(s&&(i+=t[o&a<from$1({prefix:t,name:e,encode:e=>encode$6(e,n,r),decode:t=>decode$6(t,n,r,e)}),base58btc=baseX({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),base58flickr=baseX({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var base58=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",base58btc:base58btc,base58flickr:base58flickr});const base32$1=rfc4648({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),base32upper=rfc4648({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),base32pad=rfc4648({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),base32padupper=rfc4648({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),base32hex=rfc4648({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),base32hexupper=rfc4648({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),base32hexpad=rfc4648({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),base32hexpadupper=rfc4648({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),base32z=rfc4648({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var base32$2=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",base32:base32$1,base32upper:base32upper,base32pad:base32pad,base32padupper:base32padupper,base32hex:base32hex,base32hexupper:base32hexupper,base32hexpad:base32hexpad,base32hexpadupper:base32hexpadupper,base32z:base32z});class CID$1{constructor(e,t,r,n){this.code=t,this.version=e,this.multihash=r,this.bytes=n,this.byteOffset=n.byteOffset,this.byteLength=n.byteLength,this.asCID=this,this._baseCache=new Map,Object.defineProperties(this,{byteOffset:hidden,byteLength:hidden,code:readonly$1,version:readonly$1,multihash:readonly$1,bytes:readonly$1,_baseCache:hidden,asCID:hidden})}toV0(){switch(this.version){case 0:return this;default:{const{code:e,multihash:t}=this;if(e!==DAG_PB_CODE)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==SHA_256_CODE)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return CID$1.createV0(t)}}}toV1(){switch(this.version){case 0:{const{code:e,digest:t}=this.multihash,r=create$4(e,t);return CID$1.createV1(this.code,r)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}equals(e){return e&&this.code===e.code&&this.version===e.version&&equals$1(this.multihash,e.multihash)}toString(e){const{bytes:t,version:r,_baseCache:n}=this;switch(r){case 0:return toStringV0(t,n,e||base58btc.encoder);default:return toStringV1(t,n,e||base32$1.encoder)}}toJSON(){return{code:this.code,version:this.version,hash:this.multihash.bytes}}get[Symbol.toStringTag](){return"CID"}[Symbol.for("nodejs.util.inspect.custom")](){return"CID("+this.toString()+")"}static isCID(e){return deprecate(/^0\.0/,IS_CID_DEPRECATION),!(!e||!e[cidSymbol]&&e.asCID!==e)}get toBaseEncodedString(){throw new Error("Deprecated, use .toString()")}get codec(){throw new Error('"codec" property is deprecated, use integer "code" property instead')}get buffer(){throw new Error("Deprecated .buffer property, use .bytes to get Uint8Array instead")}get multibaseName(){throw new Error('"multibaseName" property is deprecated')}get prefix(){throw new Error('"prefix" property is deprecated')}static asCID(e){if(e instanceof CID$1)return e;if(null!=e&&e.asCID===e){const{version:t,code:r,multihash:n,bytes:o}=e;return new CID$1(t,r,n,o||encodeCID(t,r,n.bytes))}if(null!=e&&!0===e[cidSymbol]){const{version:t,multihash:r,code:n}=e,o=decode$7(r);return CID$1.create(t,n,o)}return null}static create(e,t,r){if("number"!=typeof t)throw new Error("String codecs are no longer supported");switch(e){case 0:if(t!==DAG_PB_CODE)throw new Error(`Version 0 CID must use dag-pb (code: ${DAG_PB_CODE}) block encoding`);return new CID$1(e,t,r,r.bytes);case 1:{const n=encodeCID(e,t,r.bytes);return new CID$1(e,t,r,n)}default:throw new Error("Invalid version")}}static createV0(e){return CID$1.create(0,DAG_PB_CODE,e)}static createV1(e,t){return CID$1.create(1,e,t)}static decode(e){const[t,r]=CID$1.decodeFirst(e);if(r.length)throw new Error("Incorrect length");return t}static decodeFirst(e){const t=CID$1.inspectBytes(e),r=t.size-t.multihashSize,n=coerce(e.subarray(r,r+t.multihashSize));if(n.byteLength!==t.multihashSize)throw new Error("Incorrect length");const o=n.subarray(t.multihashSize-t.digestSize),i=new Digest$1(t.multihashCode,t.digestSize,o,n);return[0===t.version?CID$1.createV0(i):CID$1.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0;const r=()=>{const[r,n]=decode$8(e.subarray(t));return t+=n,r};let n=r(),o=DAG_PB_CODE;if(18===n?(n=0,t=0):1===n&&(o=r()),0!==n&&1!==n)throw new RangeError(`Invalid CID version ${n}`);const i=t,s=r(),a=r(),c=t+a;return{version:n,codec:o,multihashCode:s,digestSize:a,multihashSize:c-i,size:c}}static parse(e,t){const[r,n]=parseCIDtoBytes(e,t),o=CID$1.decode(n);return o._baseCache.set(r,e),o}}const parseCIDtoBytes=(e,t)=>{switch(e[0]){case"Q":{const r=t||base58btc;return[base58btc.prefix,r.decode(`${base58btc.prefix}${e}`)]}case base58btc.prefix:{const r=t||base58btc;return[base58btc.prefix,r.decode(e)]}case base32$1.prefix:{const r=t||base32$1;return[base32$1.prefix,r.decode(e)]}default:if(null==t)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}},toStringV0=(e,t,r)=>{const{prefix:n}=r;if(n!==base58btc.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);const o=t.get(n);if(null==o){const o=r.encode(e).slice(1);return t.set(n,o),o}return o},toStringV1=(e,t,r)=>{const{prefix:n}=r,o=t.get(n);if(null==o){const o=r.encode(e);return t.set(n,o),o}return o},DAG_PB_CODE=112,SHA_256_CODE=18,encodeCID=(e,t,r)=>{const n=encodingLength(e),o=n+encodingLength(t),i=new Uint8Array(o+r.byteLength);return encodeTo(e,i,0),encodeTo(t,i,n),i.set(r,o),i},cidSymbol=Symbol.for("@ipld/js-cid/CID"),readonly$1={writable:!1,configurable:!1,enumerable:!0},hidden={writable:!1,enumerable:!1,configurable:!1},version="0.0.0-dev",deprecate=(e,t)=>{if(!e.test(version))throw new Error(t);console.warn(t)},IS_CID_DEPRECATION="CID.isCID(v) is deprecated and will be removed in the next major release.\nFollowing code pattern:\n\nif (CID.isCID(value)) {\n doSomethingWithCID(value)\n}\n\nIs replaced with:\n\nconst cid = CID.asCID(value)\nif (cid) {\n // Make sure to use cid instead of value\n doSomethingWithCID(cid)\n}\n";var cid=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",CID:CID$1});const typeofs=["string","number","bigint","symbol"],objectTypeNames=["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 is(e){if(null===e)return"null";if(void 0===e)return"undefined";if(!0===e||!1===e)return"boolean";const t=typeof e;if(typeofs.includes(t))return t;if("function"===t)return"Function";if(Array.isArray(e))return"Array";if(isBuffer$1(e))return"Buffer";const r=getObjectType(e);return r||"Object"}function isBuffer$1(e){return e&&e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer.call(null,e)}function getObjectType(e){const t=Object.prototype.toString.call(e).slice(8,-1);if(objectTypeNames.includes(t))return t}class Type{constructor(e,t,r){this.major=e,this.majorEncoded=e<<5,this.name=t,this.terminal=r}toString(){return`Type[${this.major}].${this.name}`}compare(e){return this.majore.major?1:0}}Type.uint=new Type(0,"uint",!0),Type.negint=new Type(1,"negint",!0),Type.bytes=new Type(2,"bytes",!0),Type.string=new Type(3,"string",!0),Type.array=new Type(4,"array",!1),Type.map=new Type(5,"map",!1),Type.tag=new Type(6,"tag",!1),Type.float=new Type(7,"float",!0),Type.false=new Type(7,"false",!0),Type.true=new Type(7,"true",!0),Type.null=new Type(7,"null",!0),Type.undefined=new Type(7,"undefined",!0),Type.break=new Type(7,"break",!0);class Token{constructor(e,t,r){this.type=e,this.value=t,this.encodedLength=r,this.encodedBytes=void 0}toString(){return`Token[${this.type}].${this.value}`}}const useBuffer=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&"function"==typeof globalThis.Buffer.isBuffer,textDecoder$1=new TextDecoder,textEncoder$2=new TextEncoder;function isBuffer(e){return useBuffer&&globalThis.Buffer.isBuffer(e)}function asU8A(e){return e instanceof Uint8Array?isBuffer(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e:Uint8Array.from(e)}const toString=useBuffer?(e,t,r)=>r-t>64?globalThis.Buffer.from(e.subarray(t,r)).toString("utf8"):utf8Slice(e,t,r):(e,t,r)=>r-t>64?textDecoder$1.decode(e.subarray(t,r)):utf8Slice(e,t,r),fromString$2=useBuffer?e=>e.length>64?globalThis.Buffer.from(e):utf8ToBytes(e):e=>e.length>64?textEncoder$2.encode(e):utf8ToBytes(e),fromArray=e=>Uint8Array.from(e),slice=useBuffer?(e,t,r)=>isBuffer(e)?new Uint8Array(e.subarray(t,r)):e.slice(t,r):(e,t,r)=>e.slice(t,r),concat$2=useBuffer?(e,t)=>(e=e.map((e=>e instanceof Uint8Array?e:globalThis.Buffer.from(e))),asU8A(globalThis.Buffer.concat(e,t))):(e,t)=>{const r=new Uint8Array(t);let 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},alloc=useBuffer?e=>globalThis.Buffer.allocUnsafe(e):e=>new Uint8Array(e);function compare(e,t){if(isBuffer(e)&&isBuffer(t))return e.compare(t);for(let r=0;r55295&&r<57344){if(!o){if(r>56319){(t-=3)>-1&&i.push(239,191,189);continue}if(s+1===n){(t-=3)>-1&&i.push(239,191,189);continue}o=r;continue}if(r<56320){(t-=3)>-1&&i.push(239,191,189),o=r;continue}r=65536+(o-55296<<10|r-56320)}else o&&(t-=3)>-1&&i.push(239,191,189);if(o=null,r<128){if((t-=1)<0)break;i.push(r)}else if(r<2048){if((t-=2)<0)break;i.push(r>>6|192,63&r|128)}else if(r<65536){if((t-=3)<0)break;i.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;i.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return i}function utf8Slice(e,t,r){const n=[];for(;t239?4:o>223?3:o>191?2:1;if(t+s<=r){let r,n,a,c;switch(s){case 1:o<128&&(i=o);break;case 2:r=e[t+1],128==(192&r)&&(c=(31&o)<<6|63&r,c>127&&(i=c));break;case 3:r=e[t+1],n=e[t+2],128==(192&r)&&128==(192&n)&&(c=(15&o)<<12|(63&r)<<6|63&n,c>2047&&(c<55296||c>57343)&&(i=c));break;case 4:r=e[t+1],n=e[t+2],a=e[t+3],128==(192&r)&&128==(192&n)&&128==(192&a)&&(c=(15&o)<<18|(63&r)<<12|(63&n)<<6|63&a,c>65535&&c<1114112&&(i=c))}}null===i?(i=65533,s=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|1023&i),n.push(i),t+=s}return decodeCodePointsArray(n)}const MAX_ARGUMENTS_LENGTH=4096;function decodeCodePointsArray(e){const t=e.length;if(t<=MAX_ARGUMENTS_LENGTH)return String.fromCharCode.apply(String,e);let r="",n=0;for(;nr.length/2?(t=this.cursor===r.length?r:r.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):t=slice(r,0,this.cursor)}else t=concat$2(this.chunks,this.cursor);return e&&this.reset(),t}}const decodeErrPrefix="CBOR decode error:",encodeErrPrefix="CBOR encode error:";function assertEnoughData(e,t,r){if(e.length-t>>8,255&n])}else if(r>>24&255,n>>>16&255,n>>>8&255,255&n])}else{const n=BigInt(r);if(!(n>BigInt(32)&BigInt(4294967295));r[8]=255&o,o>>=8,r[7]=255&o,o>>=8,r[6]=255&o,o>>=8,r[5]=255&o,r[4]=255&i,i>>=8,r[3]=255&i,i>>=8,r[2]=255&i,i>>=8,r[1]=255&i,e.push(r)}}}function decodeNegint8(e,t,r,n){return new Token(Type.negint,-1-readUint8(e,t+1,n),2)}function decodeNegint16(e,t,r,n){return new Token(Type.negint,-1-readUint16(e,t+1,n),3)}function decodeNegint32(e,t,r,n){return new Token(Type.negint,-1-readUint32(e,t+1,n),5)}encodeUint.encodedSize=function(e){return encodeUintValue.encodedSize(e.value)},encodeUintValue.encodedSize=function(e){return et.value?1:0};const neg1b=BigInt(-1),pos1b=BigInt(1);function decodeNegint64(e,t,r,n){const o=readUint64(e,t+1,n);if("bigint"!=typeof o){const e=-1-o;if(e>=Number.MIN_SAFE_INTEGER)return new Token(Type.negint,e,9)}if(!0!==n.allowBigInt)throw new Error(`${decodeErrPrefix} integers outside of the safe integer range are not supported`);return new Token(Type.negint,neg1b-BigInt(o),9)}function encodeNegint(e,t){const r=t.value,n="bigint"==typeof r?r*neg1b-pos1b:-1*r-1;encodeUintValue(e,t.type.majorEncoded,n)}function toToken$3(e,t,r,n){assertEnoughData(e,t,r+n);const o=slice(e,t+r,t+r+n);return new Token(Type.bytes,o,r+n)}function decodeBytesCompact(e,t,r,n){return toToken$3(e,t,1,r)}function decodeBytes8(e,t,r,n){return toToken$3(e,t,2,readUint8(e,t+1,n))}function decodeBytes16(e,t,r,n){return toToken$3(e,t,3,readUint16(e,t+1,n))}function decodeBytes32(e,t,r,n){return toToken$3(e,t,5,readUint32(e,t+1,n))}function decodeBytes64(e,t,r,n){const o=readUint64(e,t+1,n);if("bigint"==typeof o)throw new Error(`${decodeErrPrefix} 64-bit integer bytes lengths not supported`);return toToken$3(e,t,9,o)}function tokenBytes(e){return void 0===e.encodedBytes&&(e.encodedBytes=e.type===Type.string?fromString$2(e.value):e.value),e.encodedBytes}function encodeBytes(e,t){const r=tokenBytes(t);encodeUintValue(e,t.type.majorEncoded,r.length),e.push(r)}function compareBytes(e,t){return e.lengtht.length?1:compare(e,t)}function toToken$2(e,t,r,n){const o=r+n;return assertEnoughData(e,t,o),new Token(Type.string,toString(e,t+r,t+o),o)}function decodeStringCompact(e,t,r,n){return toToken$2(e,t,1,r)}function decodeString8(e,t,r,n){return toToken$2(e,t,2,readUint8(e,t+1,n))}function decodeString16(e,t,r,n){return toToken$2(e,t,3,readUint16(e,t+1,n))}function decodeString32(e,t,r,n){return toToken$2(e,t,5,readUint32(e,t+1,n))}function decodeString64(e,t,r,n){const o=readUint64(e,t+1,n);if("bigint"==typeof o)throw new Error(`${decodeErrPrefix} 64-bit integer string lengths not supported`);return toToken$2(e,t,9,o)}encodeNegint.encodedSize=function(e){const t=e.value,r="bigint"==typeof t?t*neg1b-pos1b:-1*t-1;return rt.value?-1:0},encodeBytes.encodedSize=function(e){const t=tokenBytes(e);return encodeUintValue.encodedSize(t.length)+t.length},encodeBytes.compareTokens=function(e,t){return compareBytes(tokenBytes(e),tokenBytes(t))};const encodeString=encodeBytes;function toToken$1(e,t,r,n){return new Token(Type.array,n,r)}function decodeArrayCompact(e,t,r,n){return toToken$1(e,t,1,r)}function decodeArray8(e,t,r,n){return toToken$1(e,t,2,readUint8(e,t+1,n))}function decodeArray16(e,t,r,n){return toToken$1(e,t,3,readUint16(e,t+1,n))}function decodeArray32(e,t,r,n){return toToken$1(e,t,5,readUint32(e,t+1,n))}function decodeArray64(e,t,r,n){const o=readUint64(e,t+1,n);if("bigint"==typeof o)throw new Error(`${decodeErrPrefix} 64-bit integer array lengths not supported`);return toToken$1(e,t,9,o)}function decodeArrayIndefinite(e,t,r,n){if(!1===n.allowIndefinite)throw new Error(`${decodeErrPrefix} indefinite length items not allowed`);return toToken$1(e,t,1,1/0)}function encodeArray(e,t){encodeUintValue(e,Type.array.majorEncoded,t.value)}function toToken(e,t,r,n){return new Token(Type.map,n,r)}function decodeMapCompact(e,t,r,n){return toToken(e,t,1,r)}function decodeMap8(e,t,r,n){return toToken(e,t,2,readUint8(e,t+1,n))}function decodeMap16(e,t,r,n){return toToken(e,t,3,readUint16(e,t+1,n))}function decodeMap32(e,t,r,n){return toToken(e,t,5,readUint32(e,t+1,n))}function decodeMap64(e,t,r,n){const o=readUint64(e,t+1,n);if("bigint"==typeof o)throw new Error(`${decodeErrPrefix} 64-bit integer map lengths not supported`);return toToken(e,t,9,o)}function decodeMapIndefinite(e,t,r,n){if(!1===n.allowIndefinite)throw new Error(`${decodeErrPrefix} indefinite length items not allowed`);return toToken(e,t,1,1/0)}function encodeMap(e,t){encodeUintValue(e,Type.map.majorEncoded,t.value)}function decodeTagCompact(e,t,r,n){return new Token(Type.tag,r,1)}function decodeTag8(e,t,r,n){return new Token(Type.tag,readUint8(e,t+1,n),2)}function decodeTag16(e,t,r,n){return new Token(Type.tag,readUint16(e,t+1,n),3)}function decodeTag32(e,t,r,n){return new Token(Type.tag,readUint32(e,t+1,n),5)}function decodeTag64(e,t,r,n){return new Token(Type.tag,readUint64(e,t+1,n),9)}function encodeTag(e,t){encodeUintValue(e,Type.tag.majorEncoded,t.value)}encodeArray.compareTokens=encodeUint.compareTokens,encodeMap.compareTokens=encodeUint.compareTokens,encodeTag.compareTokens=encodeUint.compareTokens;const MINOR_FALSE=20,MINOR_TRUE=21,MINOR_NULL=22,MINOR_UNDEFINED=23;function decodeUndefined(e,t,r,n){if(!1===n.allowUndefined)throw new Error(`${decodeErrPrefix} undefined values are not supported`);return new Token(Type.undefined,void 0,1)}function decodeBreak(e,t,r,n){if(!1===n.allowIndefinite)throw new Error(`${decodeErrPrefix} indefinite length items not allowed`);return new Token(Type.break,void 0,1)}function createToken(e,t,r){if(r){if(!1===r.allowNaN&&Number.isNaN(e))throw new Error(`${decodeErrPrefix} NaN values are not supported`);if(!1===r.allowInfinity&&(e===1/0||e===-1/0))throw new Error(`${decodeErrPrefix} Infinity values are not supported`)}return new Token(Type.float,e,t)}function decodeFloat16(e,t,r,n){return createToken(readFloat16(e,t+1),3,n)}function decodeFloat32(e,t,r,n){return createToken(readFloat32(e,t+1),5,n)}function decodeFloat64(e,t,r,n){return createToken(readFloat64(e,t+1),9,n)}function encodeFloat(e,t,r){const n=t.value;if(!1===n)e.push([Type.float.majorEncoded|MINOR_FALSE]);else if(!0===n)e.push([Type.float.majorEncoded|MINOR_TRUE]);else if(null===n)e.push([Type.float.majorEncoded|MINOR_NULL]);else if(void 0===n)e.push([Type.float.majorEncoded|MINOR_UNDEFINED]);else{let t,o=!1;r&&!0===r.float64||(encodeFloat16(n),t=readFloat16(ui8a,1),n===t||Number.isNaN(n)?(ui8a[0]=249,e.push(ui8a.slice(0,3)),o=!0):(encodeFloat32(n),t=readFloat32(ui8a,1),n===t&&(ui8a[0]=250,e.push(ui8a.slice(0,5)),o=!0))),o||(encodeFloat64(n),t=readFloat64(ui8a,1),ui8a[0]=251,e.push(ui8a.slice(0,9)))}}encodeFloat.encodedSize=function(e,t){const r=e.value;if(!1===r||!0===r||null==r)return 1;let n;if(!t||!0!==t.float64){if(encodeFloat16(r),n=readFloat16(ui8a,1),r===n||Number.isNaN(r))return 3;if(encodeFloat32(r),n=readFloat32(ui8a,1),r===n)return 5}return 9};const buffer$1=new ArrayBuffer(9),dataView=new DataView(buffer$1,1),ui8a=new Uint8Array(buffer$1,0);function encodeFloat16(e){if(e===1/0)dataView.setUint16(0,31744,!1);else if(e===-1/0)dataView.setUint16(0,64512,!1);else if(Number.isNaN(e))dataView.setUint16(0,32256,!1);else{dataView.setFloat32(0,e);const t=dataView.getUint32(0),r=(2139095040&t)>>23,n=8388607&t;if(255===r)dataView.setUint16(0,31744,!1);else if(0===r)dataView.setUint16(0,(2147483648&e)>>16|n>>13,!1);else{const e=r-127;e<-24?dataView.setUint16(0,0):e<-14?dataView.setUint16(0,(2147483648&t)>>16|1<<24+e,!1):dataView.setUint16(0,(2147483648&t)>>16|e+15<<10|n>>13,!1)}}}function readFloat16(e,t){if(e.length-t<2)throw new Error(`${decodeErrPrefix} not enough data for float16`);const r=(e[t]<<8)+e[t+1];if(31744===r)return 1/0;if(64512===r)return-1/0;if(32256===r)return NaN;const n=r>>10&31,o=1023&r;let i;return i=0===n?o*2**-24:31!==n?(o+1024)*2**(n-25):0===o?1/0:NaN,32768&r?-i:i}function encodeFloat32(e){dataView.setFloat32(0,e,!1)}function readFloat32(e,t){if(e.length-t<4)throw new Error(`${decodeErrPrefix} not enough data for float32`);const r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,4).getFloat32(0,!1)}function encodeFloat64(e){dataView.setFloat64(0,e,!1)}function readFloat64(e,t){if(e.length-t<8)throw new Error(`${decodeErrPrefix} not enough data for float64`);const r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,8).getFloat64(0,!1)}function invalidMinor(e,t,r){throw new Error(`${decodeErrPrefix} encountered invalid minor (${r}) for major ${e[t]>>>5}`)}function errorer(e){return()=>{throw new Error(`${decodeErrPrefix} ${e}`)}}encodeFloat.compareTokens=encodeUint.compareTokens;const jump=[];for(let e=0;e<=23;e++)jump[e]=invalidMinor;jump[24]=decodeUint8,jump[25]=decodeUint16,jump[26]=decodeUint32,jump[27]=decodeUint64,jump[28]=invalidMinor,jump[29]=invalidMinor,jump[30]=invalidMinor,jump[31]=invalidMinor;for(let e=32;e<=55;e++)jump[e]=invalidMinor;jump[56]=decodeNegint8,jump[57]=decodeNegint16,jump[58]=decodeNegint32,jump[59]=decodeNegint64,jump[60]=invalidMinor,jump[61]=invalidMinor,jump[62]=invalidMinor,jump[63]=invalidMinor;for(let e=64;e<=87;e++)jump[e]=decodeBytesCompact;jump[88]=decodeBytes8,jump[89]=decodeBytes16,jump[90]=decodeBytes32,jump[91]=decodeBytes64,jump[92]=invalidMinor,jump[93]=invalidMinor,jump[94]=invalidMinor,jump[95]=errorer("indefinite length bytes/strings are not supported");for(let e=96;e<=119;e++)jump[e]=decodeStringCompact;jump[120]=decodeString8,jump[121]=decodeString16,jump[122]=decodeString32,jump[123]=decodeString64,jump[124]=invalidMinor,jump[125]=invalidMinor,jump[126]=invalidMinor,jump[127]=errorer("indefinite length bytes/strings are not supported");for(let e=128;e<=151;e++)jump[e]=decodeArrayCompact;jump[152]=decodeArray8,jump[153]=decodeArray16,jump[154]=decodeArray32,jump[155]=decodeArray64,jump[156]=invalidMinor,jump[157]=invalidMinor,jump[158]=invalidMinor,jump[159]=decodeArrayIndefinite;for(let e=160;e<=183;e++)jump[e]=decodeMapCompact;jump[184]=decodeMap8,jump[185]=decodeMap16,jump[186]=decodeMap32,jump[187]=decodeMap64,jump[188]=invalidMinor,jump[189]=invalidMinor,jump[190]=invalidMinor,jump[191]=decodeMapIndefinite;for(let e=192;e<=215;e++)jump[e]=decodeTagCompact;jump[216]=decodeTag8,jump[217]=decodeTag16,jump[218]=decodeTag32,jump[219]=decodeTag64,jump[220]=invalidMinor,jump[221]=invalidMinor,jump[222]=invalidMinor,jump[223]=invalidMinor;for(let e=224;e<=243;e++)jump[e]=errorer("simple values are not supported");jump[244]=invalidMinor,jump[245]=invalidMinor,jump[246]=invalidMinor,jump[247]=decodeUndefined,jump[248]=errorer("simple values are not supported"),jump[249]=decodeFloat16,jump[250]=decodeFloat32,jump[251]=decodeFloat64,jump[252]=invalidMinor,jump[253]=invalidMinor,jump[254]=invalidMinor,jump[255]=decodeBreak;const quick=[];for(let e=0;e<24;e++)quick[e]=new Token(Type.uint,e,1);for(let e=-1;e>=-24;e--)quick[31-e]=new Token(Type.negint,e,1);function quickEncodeToken(e){switch(e.type){case Type.false:return fromArray([244]);case Type.true:return fromArray([245]);case Type.null:return fromArray([246]);case Type.bytes:return e.value.length?void 0:fromArray([64]);case Type.string:return""===e.value?fromArray([96]):void 0;case Type.array:return 0===e.value?fromArray([128]):void 0;case Type.map:return 0===e.value?fromArray([160]):void 0;case Type.uint:return e.value<24?fromArray([Number(e.value)]):void 0;case Type.negint:if(e.value>=-24)return fromArray([31-Number(e.value)])}}quick[64]=new Token(Type.bytes,new Uint8Array(0),1),quick[96]=new Token(Type.string,"",1),quick[128]=new Token(Type.array,0,1),quick[160]=new Token(Type.map,0,1),quick[244]=new Token(Type.false,!1,1),quick[245]=new Token(Type.true,!0,1),quick[246]=new Token(Type.null,null,1);const defaultEncodeOptions={float64:!1,mapSorter:mapSorter,quickEncodeToken:quickEncodeToken},cborEncoders=[];cborEncoders[Type.uint.major]=encodeUint,cborEncoders[Type.negint.major]=encodeNegint,cborEncoders[Type.bytes.major]=encodeBytes,cborEncoders[Type.string.major]=encodeString,cborEncoders[Type.array.major]=encodeArray,cborEncoders[Type.map.major]=encodeMap,cborEncoders[Type.tag.major]=encodeTag,cborEncoders[Type.float.major]=encodeFloat;const buf=new Bl;class Ref{constructor(e,t){this.obj=e,this.parent=t}includes(e){let t=this;do{if(t.obj===e)return!0}while(t=t.parent);return!1}static createCheck(e,t){if(e&&e.includes(t))throw new Error(`${encodeErrPrefix} object contains circular references`);return new Ref(t,e)}}const simpleTokens={null:new Token(Type.null,null),undefined:new Token(Type.undefined,void 0),true:new Token(Type.true,!0),false:new Token(Type.false,!1),emptyArray:new Token(Type.array,0),emptyMap:new Token(Type.map,0)},typeEncoders={number:(e,t,r,n)=>Number.isInteger(e)&&Number.isSafeInteger(e)?new Token(e>=0?Type.uint:Type.negint,e):new Token(Type.float,e),bigint:(e,t,r,n)=>e>=BigInt(0)?new Token(Type.uint,e):new Token(Type.negint,e),Uint8Array:(e,t,r,n)=>new Token(Type.bytes,e),string:(e,t,r,n)=>new Token(Type.string,e),boolean:(e,t,r,n)=>e?simpleTokens.true:simpleTokens.false,null:(e,t,r,n)=>simpleTokens.null,undefined:(e,t,r,n)=>simpleTokens.undefined,ArrayBuffer:(e,t,r,n)=>new Token(Type.bytes,new Uint8Array(e)),DataView:(e,t,r,n)=>new Token(Type.bytes,new Uint8Array(e.buffer,e.byteOffset,e.byteLength)),Array(e,t,r,n){if(!e.length)return!0===r.addBreakTokens?[simpleTokens.emptyArray,new Token(Type.break)]:simpleTokens.emptyArray;n=Ref.createCheck(n,e);const o=[];let i=0;for(const s of e)o[i++]=objectToTokens(s,r,n);return r.addBreakTokens?[new Token(Type.array,e.length),o,new Token(Type.break)]:[new Token(Type.array,e.length),o]},Object(e,t,r,n){const o="Object"!==t,i=o?e.keys():Object.keys(e),s=o?e.size:i.length;if(!s)return!0===r.addBreakTokens?[simpleTokens.emptyMap,new Token(Type.break)]:simpleTokens.emptyMap;n=Ref.createCheck(n,e);const a=[];let c=0;for(const u of i)a[c++]=[objectToTokens(u,r,n),objectToTokens(o?e.get(u):e[u],r,n)];return sortMapEntries(a,r),r.addBreakTokens?[new Token(Type.map,s),a,new Token(Type.break)]:[new Token(Type.map,s),a]}};typeEncoders.Map=typeEncoders.Object,typeEncoders.Buffer=typeEncoders.Uint8Array;for(const e of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))typeEncoders[`${e}Array`]=typeEncoders.DataView;function objectToTokens(e,t={},r){const n=is(e),o=t&&t.typeEncoders&&t.typeEncoders[n]||typeEncoders[n];if("function"==typeof o){const i=o(e,n,t,r);if(null!=i)return i}const i=typeEncoders[n];if(!i)throw new Error(`${encodeErrPrefix} unsupported type: ${n}`);return i(e,n,t,r)}function sortMapEntries(e,t){t.mapSorter&&e.sort(t.mapSorter)}function mapSorter(e,t){const 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);const o=r.type.major,i=cborEncoders[o].compareTokens(r,n);return 0===i&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function tokensToEncoded(e,t,r,n){if(Array.isArray(t))for(const o of t)tokensToEncoded(e,o,r,n);else r[t.type.major](e,t,n)}function encodeCustom(e,t,r){const n=objectToTokens(e,r);if(!Array.isArray(n)&&r.quickEncodeToken){const e=r.quickEncodeToken(n);if(e)return e;const o=t[n.type.major];if(o.encodedSize){const e=o.encodedSize(n,r),t=new Bl(e);if(o(t,n,r),1!==t.chunks.length)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return asU8A(t.chunks[0])}}return tokensToEncoded(buf,n,t,r),buf.toBytes(!0)}function encode$5(e,t){return t=Object.assign({},defaultEncodeOptions,t),encodeCustom(e,cborEncoders,t)}const defaultDecodeOptions={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0};class Tokeniser{constructor(e,t={}){this.pos=0,this.data=e,this.options=t}done(){return this.pos>=this.data.length}next(){const e=this.data[this.pos];let t=quick[e];if(void 0===t){const r=jump[e];if(!r)throw new Error(`${decodeErrPrefix} no decoder for major type ${e>>>5} (byte 0x${e.toString(16).padStart(2,"0")})`);const n=31&e;t=r(this.data,this.pos,n,this.options)}return this.pos+=t.encodedLength,t}}const DONE=Symbol.for("DONE"),BREAK=Symbol.for("BREAK");function tokenToArray(e,t,r){const n=[];for(let o=0;oencode$5(e,encodeOptions),decode$4=e=>decode$5(e,decodeOptions);var cbor=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",name:name$2,code:code$3,encode:encode$4,decode:decode$4});const CIDV0_BYTES={SHA2_256:18,LENGTH:32,DAG_PB:112};async function readVarint(e){const t=await e.upTo(8),r=varint$1.decode(t);return e.seek(varint$1.decode.bytes),r}async function readHeader(e){const t=await readVarint(e);if(0===t)throw new Error("Invalid CAR header (zero length)");const r=await e.exactly(t);e.seek(t);const n=decode$4(r);if(null==n||Array.isArray(n)||"object"!=typeof n)throw new Error("Invalid CAR header format");if(1!==n.version){if("string"==typeof n.version)throw new Error(`Invalid CAR version: "${n.version}"`);throw new Error(`Invalid CAR version: ${n.version}`)}if(!Array.isArray(n.roots))throw new Error("Invalid CAR header format");if(Object.keys(n).filter((e=>"roots"!==e&&"version"!==e)).length)throw new Error("Invalid CAR header format");return n}async function readMultihash(e){const t=await e.upTo(8);varint$1.decode(t);const r=varint$1.decode.bytes,n=varint$1.decode(t.subarray(varint$1.decode.bytes)),o=r+varint$1.decode.bytes+n,i=await e.exactly(o);return e.seek(o),i}async function readCid(e){const t=await e.exactly(2);if(t[0]===CIDV0_BYTES.SHA2_256&&t[1]===CIDV0_BYTES.LENGTH){const t=await e.exactly(34);e.seek(34);const r=decode$7(t);return CID$1.create(0,CIDV0_BYTES.DAG_PB,r)}const r=await readVarint(e);if(1!==r)throw new Error(`Unexpected CID version (${r})`);const n=await readVarint(e),o=await readMultihash(e),i=decode$7(o);return CID$1.create(r,n,i)}async function readBlockHead(e){const t=e.pos;let r=await readVarint(e);if(0===r)throw new Error("Invalid CAR section (zero length)");r+=e.pos-t;return{cid:await readCid(e),length:r,blockLength:r-(e.pos-t)}}async function readBlock(e){const{cid:t,blockLength:r}=await readBlockHead(e),n=await e.exactly(r);return e.seek(r),{bytes:n,cid:t}}async function readBlockIndex(e){const t=e.pos,{cid:r,length:n,blockLength:o}=await readBlockHead(e),i={cid:r,length:n,blockLength:o,offset:t,blockOffset:e.pos};return e.seek(i.blockLength),i}function createDecoder(e){const t=readHeader(e);return{header:()=>t,async*blocks(){for(await t;(await e.upTo(8)).length>0;)yield await readBlock(e)},async*blocksIndex(){for(await t;(await e.upTo(8)).length>0;)yield await readBlockIndex(e)}}}function bytesReader(e){let t=0;return{upTo:async r=>e.subarray(t,t+Math.min(r,e.length-t)),async exactly(r){if(r>e.length-t)throw new Error("Unexpected end of data");return e.subarray(t,t+r)},seek(e){t+=e},get pos(){return t}}}function chunkReader(e){let t=0,r=0,n=0,o=new Uint8Array(0);const i=async t=>{r=o.length-n;const i=[o.subarray(n)];for(;rr&&i.push(t.subarray(-r)):i.push(t),r+=t.length}o=new Uint8Array(i.reduce(((e,t)=>e+t.length),0));let s=0;for(const e of i)o.set(e,s),s+=e.length;n=0};return{upTo:async e=>(o.length-ne.cid.toString()))}get version(){return this._version}async getRoots(){return this._roots}async has(e){return this._keys.indexOf(e.toString())>-1}async get(e){const t=this._keys.indexOf(e.toString());return t>-1?this._blocks[t]:void 0}async*blocks(){for(const e of this._blocks)yield e}async*cids(){for(const e of this._blocks)yield e.cid}static async fromBytes(e){if(!(e instanceof Uint8Array))throw new TypeError("fromBytes() requires a Uint8Array");return decodeReaderComplete(bytesReader(e))}static async fromIterable(e){if(!e||"function"!=typeof e[Symbol.asyncIterator])throw new TypeError("fromIterable() requires an async iterable");return decodeReaderComplete(asyncIterableReader(e))}}async function decodeReaderComplete(e){const t=createDecoder(e),{version:r,roots:n}=await t.header(),o=[];for await(const i of t.blocks())o.push(i);return new CarReader(r,n,o)}class CarIteratorBase{constructor(e,t,r){this._version=e,this._roots=t,this._iterable=r,this._decoded=!1}get version(){return this._version}async getRoots(){return this._roots}}class CarBlockIterator extends CarIteratorBase{[Symbol.asyncIterator](){if(this._decoded)throw new Error("Cannot decode more than once");if(!this._iterable)throw new Error("Block iterable not found");return this._decoded=!0,this._iterable[Symbol.asyncIterator]()}static async fromBytes(e){const{version:t,roots:r,iterator:n}=await fromBytes(e);return new CarBlockIterator(t,r,n)}static async fromIterable(e){const{version:t,roots:r,iterator:n}=await fromIterable(e);return new CarBlockIterator(t,r,n)}}async function fromBytes(e){if(!(e instanceof Uint8Array))throw new TypeError("fromBytes() requires a Uint8Array");return decodeIterator(bytesReader(e))}async function fromIterable(e){if(!e||"function"!=typeof e[Symbol.asyncIterator])throw new TypeError("fromIterable() requires an async iterable");return decodeIterator(asyncIterableReader(e))}async function decodeIterator(e){const t=createDecoder(e),{version:r,roots:n}=await t.header();return{version:r,roots:n,iterator:t.blocks()}}function createHeader(e){const t=encode$4({version:1,roots:e}),r=varint$1.encode(t.length),n=new Uint8Array(r.length+t.length);return n.set(r,0),n.set(t,r.length),n}function createEncoder(e){return{async setRoots(t){const r=createHeader(t);await e.write(r)},async writeBlock(t){const{cid:r,bytes:n}=t;await e.write(new Uint8Array(varint$1.encode(r.bytes.length+n.length))),await e.write(r.bytes),n.length&&await e.write(n)},close:async()=>e.end()}}function noop$1(){}function create$3(){const e=[];let t=null,r=noop$1,n=!1,o=null,i=noop$1;const s=()=>(t||(t=new Promise((e=>{r=()=>{t=null,r=noop$1,e()}}))),t),a={async next(){const t=e.shift();return t?(0===e.length&&r(),{done:!1,value:t}):n?(r(),{done:!0,value:void 0}):(o||(o=new Promise((e=>{i=()=>(o=null,i=noop$1,e(a.next()))}))),o)}};return{writer:{write(t){e.push(t);const r=s();return i(),r},async end(){n=!0;const e=s();return i(),e}},iterator:a}}class CarWriter{constructor(e,t){this._encoder=t,this._mutex=t.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");const t=CID$1.asCID(e.cid);if(!t)throw new TypeError("Can only write {cid, bytes} objects");return this._mutex=this._mutex.then((()=>this._encoder.writeBlock({cid:t,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()}static create(e){e=toRoots(e);const{encoder:t,iterator:r}=encodeWriter();return{writer:new CarWriter(e,t),out:new CarWriterOut(r)}}static createAppender(){const{encoder:e,iterator:t}=encodeWriter();e.setRoots=()=>Promise.resolve();return{writer:new CarWriter([],e),out:new CarWriterOut(t)}}static async updateRootsInBytes(e,t){const r=bytesReader(e);await readHeader(r);const n=createHeader(t);if(r.pos!==n.length)throw new Error(`updateRoots() can only overwrite a header of the same length (old header is ${r.pos} bytes, new header is ${n.length} bytes)`);return e.set(n,0),e}}class CarWriterOut{constructor(e){this._iterator=e}[Symbol.asyncIterator](){if(this._iterating)throw new Error("Multiple iterator not supported");return this._iterating=!0,this._iterator}}function encodeWriter(){const e=create$3(),{writer:t,iterator:r}=e;return{encoder:createEncoder(t),iterator:r}}function toRoots(e){if(void 0===e)return[];if(!Array.isArray(e)){const t=CID$1.asCID(e);if(!t)throw new TypeError("roots must be a single CID or an array of CIDs");return[t]}const t=[];for(const r of e){const e=CID$1.asCID(r);if(!e)throw new TypeError("roots must be a single CID or an array of CIDs");t.push(e)}return t}async function*batch$1(e,t=1){let r=[];t<1&&(t=1);for await(const n of e)for(r.push(n);r.length>=t;)yield r.slice(0,t),r=r.slice(t);for(;r.length;)yield r.slice(0,t),r=r.slice(t)}var itBatch=batch$1;const batch=itBatch;async function*parallelBatch(e,t=1){for await(const r of batch(e,t)){const e=r.map((e=>e().then((e=>({ok:!0,value:e})),(e=>({ok:!1,err:e})))));for(let t=0;t{if("[object Object]"!==Object.prototype.toString.call(e))return!1;const t=Object.getPrototypeOf(e);return null===t||t===Object.prototype};const isOptionObject=isPlainObj,{hasOwnProperty:hasOwnProperty$3}=Object.prototype,{propertyIsEnumerable:propertyIsEnumerable}=Object,defineProperty=(e,t,r)=>Object.defineProperty(e,t,{value:r,writable:!0,enumerable:!0,configurable:!0}),globalThis$1=commonjsGlobal,defaultMergeOptions={concatArrays:!1,ignoreUndefined:!1},getEnumerableOwnPropertyKeys=e=>{const t=[];for(const r in e)hasOwnProperty$3.call(e,r)&&t.push(r);if(Object.getOwnPropertySymbols){const r=Object.getOwnPropertySymbols(e);for(const n of r)propertyIsEnumerable.call(e,n)&&t.push(n)}return t};function clone(e){return Array.isArray(e)?cloneArray(e):isOptionObject(e)?cloneOptionObject(e):e}function cloneArray(e){const t=e.slice(0,0);return getEnumerableOwnPropertyKeys(e).forEach((r=>{defineProperty(t,r,clone(e[r]))})),t}function cloneOptionObject(e){const t=null===Object.getPrototypeOf(e)?Object.create(null):{};return getEnumerableOwnPropertyKeys(e).forEach((r=>{defineProperty(t,r,clone(e[r]))})),t}const mergeKeys=(e,t,r,n)=>(r.forEach((r=>{void 0===t[r]&&n.ignoreUndefined||(r in e&&e[r]!==Object.getPrototypeOf(e)?defineProperty(e,r,merge(e[r],t[r],n)):defineProperty(e,r,clone(t[r])))})),e),concatArrays=(e,t,r)=>{let n=e.slice(0,0),o=0;return[e,t].forEach((t=>{const i=[];for(let r=0;r!i.includes(e))),r)})),n};function merge(e,t,r){return r.concatArrays&&Array.isArray(e)&&Array.isArray(t)?concatArrays(e,t,r):isOptionObject(t)&&isOptionObject(e)?mergeKeys(e,t,getEnumerableOwnPropertyKeys(t),r):clone(t)}var mergeOptions=function(...e){const t=merge(clone(defaultMergeOptions),this!==globalThis$1&&this||{},defaultMergeOptions);let r={_:{}};for(const n of e)if(void 0!==n){if(!isOptionObject(n))throw new TypeError("`"+n+"` is not an Option Object");r=merge(r,{_:n},t)}return r._};const from=({name:e,code:t,encode:r})=>new Hasher(e,t,r);class Hasher{constructor(e,t,r){this.name=e,this.code=t,this.encode=r}async digest(e){if(e instanceof Uint8Array){const t=await this.encode(e);return create$4(this.code,t)}throw Error("Unknown type, must be binary type")}}const sha=e=>async t=>new Uint8Array(await crypto.subtle.digest(e,t)),sha256=from({name:"sha2-256",code:18,encode:sha("SHA-256")}),sha512=from({name:"sha2-512",code:19,encode:sha("SHA-512")});var sha2=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",sha256:sha256,sha512:sha512}),murmurHash3js={exports:{}};!function(e,t){!function(r,n){var o={version:"3.0.0",x86:{},x64:{},inputValidation:!0};function i(e){if(!Array.isArray(e)&&!ArrayBuffer.isView(e))return!1;for(var t=0;t255)return!1;return!0}function s(e,t){return(65535&e)*t+(((e>>>16)*t&65535)<<16)}function a(e,t){return e<>>32-t}function c(e){return e=s(e^=e>>>16,2246822507),e=s(e^=e>>>13,3266489909),e^=e>>>16}function u(e,t){e=[e[0]>>>16,65535&e[0],e[1]>>>16,65535&e[1]],t=[t[0]>>>16,65535&t[0],t[1]>>>16,65535&t[1]];var r=[0,0,0,0];return r[3]+=e[3]+t[3],r[2]+=r[3]>>>16,r[3]&=65535,r[2]+=e[2]+t[2],r[1]+=r[2]>>>16,r[2]&=65535,r[1]+=e[1]+t[1],r[0]+=r[1]>>>16,r[1]&=65535,r[0]+=e[0]+t[0],r[0]&=65535,[r[0]<<16|r[1],r[2]<<16|r[3]]}function l(e,t){e=[e[0]>>>16,65535&e[0],e[1]>>>16,65535&e[1]],t=[t[0]>>>16,65535&t[0],t[1]>>>16,65535&t[1]];var r=[0,0,0,0];return r[3]+=e[3]*t[3],r[2]+=r[3]>>>16,r[3]&=65535,r[2]+=e[2]*t[3],r[1]+=r[2]>>>16,r[2]&=65535,r[2]+=e[3]*t[2],r[1]+=r[2]>>>16,r[2]&=65535,r[1]+=e[1]*t[3],r[0]+=r[1]>>>16,r[1]&=65535,r[1]+=e[2]*t[2],r[0]+=r[1]>>>16,r[1]&=65535,r[1]+=e[3]*t[1],r[0]+=r[1]>>>16,r[1]&=65535,r[0]+=e[0]*t[3]+e[1]*t[2]+e[2]*t[1]+e[3]*t[0],r[0]&=65535,[r[0]<<16|r[1],r[2]<<16|r[3]]}function f(e,t){return 32===(t%=64)?[e[1],e[0]]:t<32?[e[0]<>>32-t,e[1]<>>32-t]:(t-=32,[e[1]<>>32-t,e[0]<>>32-t])}function h(e,t){return 0===(t%=64)?e:t<32?[e[0]<>>32-t,e[1]<>>1]),e=d(e=l(e,[4283543511,3981806797]),[0,e[0]>>>1]),e=d(e=l(e,[3301882366,444984403]),[0,e[0]>>>1])}o.x86.hash32=function(e,t){if(o.inputValidation&&!i(e))return n;t=t||0;for(var r=e.length%4,u=e.length-r,l=t,f=0,h=3432918353,d=461845907,p=0;p>>0},o.x86.hash128=function(e,t){if(o.inputValidation&&!i(e))return n;t=t||0;for(var r=e.length%16,u=e.length-r,l=t,f=t,h=t,d=t,p=0,y=0,m=0,g=0,b=597399067,w=2869860233,_=951274213,v=2716044179,$=0;$>>0).toString(16)).slice(-8)+("00000000"+(f>>>0).toString(16)).slice(-8)+("00000000"+(h>>>0).toString(16)).slice(-8)+("00000000"+(d>>>0).toString(16)).slice(-8)},o.x64.hash128=function(e,t){if(o.inputValidation&&!i(e))return n;t=t||0;for(var r=e.length%16,s=e.length-r,a=[0,t],c=[0,t],y=[0,0],m=[0,0],g=[2277735313,289559509],b=[1291169091,658871167],w=0;w>>0).toString(16)).slice(-8)+("00000000"+(a[1]>>>0).toString(16)).slice(-8)+("00000000"+(c[0]>>>0).toString(16)).slice(-8)+("00000000"+(c[1]>>>0).toString(16)).slice(-8)},e.exports&&(t=e.exports=o),t.murmurHash3=o}()}(murmurHash3js,murmurHash3js.exports);var murmurhash3jsRevisited=murmurHash3js.exports;function fromNumberTo32BitBuf(e){const t=new Array(4);for(let r=0;r<4;r++)t[r]=255&e,e>>=8;return new Uint8Array(t)}from({name:"murmur3-32",code:35,encode:e=>fromNumberTo32BitBuf(murmurhash3jsRevisited.x86.hash32(e))});const murmur3128=from({name:"murmur3-128",code:34,encode:e=>fromHex(murmurhash3jsRevisited.x64.hash128(e))});async function hamtHashFn(e){return(await murmur3128.encode(e)).slice(0,8).reverse()}mergeOptions.bind({ignoreUndefined:!0});const defaultOptions={chunker:"fixed",strategy:"balanced",rawLeaves:!1,onlyHash:!1,reduceSingleLeafToSelf:!0,hasher:sha256,leafType:"file",cidVersion:0,progress:()=>()=>{},shardSplitThreshold:1e3,fileImportConcurrency:50,blockWriteConcurrency:10,minChunkSize:262144,maxChunkSize:262144,avgChunkSize:262144,window:16,polynomial:0x3df305dfb2a804,maxChildrenPerNode:174,layerRepeat:4,wrapWithDirectory:!1,recursive:!1,hidden:!1,timeout:void 0,hamtHashFn:hamtHashFn,hamtHashCode:34,hamtBucketBits:8};var defaultOptions$1=(e={})=>mergeOptions(defaultOptions,e);function assign(e,t){for(const r in t)Object.defineProperty(e,r,{value:t[r],enumerable:!0,configurable:!0});return e}function createError(e,t,r){if(!e||"string"==typeof e)throw new TypeError("Please pass an Error to err-code");r||(r={}),"object"==typeof t&&(r=t,t=""),t&&(r.code=t);try{return assign(e,r)}catch(n){r.message=e.message,r.stack=e.stack;const t=function(){};t.prototype=Object.create(Object.getPrototypeOf(e));return assign(new t,r)}}var errCode$3=createError,indexMinimal={},minimal$1={},aspromise=asPromise;function asPromise(e,t){for(var r=new Array(arguments.length-1),n=0,o=2,i=!0;o1&&"="===e.charAt(t);)++r;return Math.ceil(3*e.length)/4-r};for(var r=new Array(64),n=new Array(123),o=0;o<64;)n[r[o]=o<26?o+65:o<52?o+71:o<62?o-4:o-59|43]=o++;t.encode=function(e,t,n){for(var o,i=null,s=[],a=0,c=0;t>2],o=(3&u)<<4,c=1;break;case 1:s[a++]=r[o|u>>4],o=(15&u)<<2,c=2;break;case 2:s[a++]=r[o|u>>6],s[a++]=r[63&u],c=0}a>8191&&((i||(i=[])).push(String.fromCharCode.apply(String,s)),a=0)}return c&&(s[a++]=r[o],s[a++]=61,1===c&&(s[a++]=61)),i?(a&&i.push(String.fromCharCode.apply(String,s.slice(0,a))),i.join("")):String.fromCharCode.apply(String,s.slice(0,a))};var i="invalid encoding";t.decode=function(e,t,r){for(var o,s=r,a=0,c=0;c1)break;if(void 0===(u=n[u]))throw Error(i);switch(a){case 0:o=u,a=1;break;case 1:t[r++]=o<<2|(48&u)>>4,o=u,a=2;break;case 2:t[r++]=(15&o)<<4|(60&u)>>2,o=u,a=3;break;case 3:t[r++]=(3&o)<<6|u,a=0}}if(1===a)throw Error(i);return r-s},t.test=function(e){return/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(e)}}();var eventemitter=EventEmitter;function EventEmitter(){this._listeners={}}EventEmitter.prototype.on=function(e,t,r){return(this._listeners[e]||(this._listeners[e]=[])).push({fn:t,ctx:r||this}),this},EventEmitter.prototype.off=function(e,t){if(void 0===e)this._listeners={};else if(void 0===t)this._listeners[e]=[];else for(var r=this._listeners[e],n=0;n0?0:2147483648,r,n);else if(isNaN(t))e(2143289344,r,n);else if(t>34028234663852886e22)e((o<<31|2139095040)>>>0,r,n);else if(t<11754943508222875e-54)e((o<<31|Math.round(t/1401298464324817e-60))>>>0,r,n);else{var i=Math.floor(Math.log(t)/Math.LN2);e((o<<31|i+127<<23|8388607&Math.round(t*Math.pow(2,-i)*8388608))>>>0,r,n)}}function r(e,t,r){var n=e(t,r),o=2*(n>>31)+1,i=n>>>23&255,s=8388607&n;return 255===i?s?NaN:o*(1/0):0===i?1401298464324817e-60*o*s:o*Math.pow(2,i-150)*(s+8388608)}e.writeFloatLE=t.bind(null,writeUintLE),e.writeFloatBE=t.bind(null,writeUintBE),e.readFloatLE=r.bind(null,readUintLE),e.readFloatBE=r.bind(null,readUintBE)}(),"undefined"!=typeof Float64Array?function(){var t=new Float64Array([-0]),r=new Uint8Array(t.buffer),n=128===r[7];function o(e,n,o){t[0]=e,n[o]=r[0],n[o+1]=r[1],n[o+2]=r[2],n[o+3]=r[3],n[o+4]=r[4],n[o+5]=r[5],n[o+6]=r[6],n[o+7]=r[7]}function i(e,n,o){t[0]=e,n[o]=r[7],n[o+1]=r[6],n[o+2]=r[5],n[o+3]=r[4],n[o+4]=r[3],n[o+5]=r[2],n[o+6]=r[1],n[o+7]=r[0]}function s(e,n){return r[0]=e[n],r[1]=e[n+1],r[2]=e[n+2],r[3]=e[n+3],r[4]=e[n+4],r[5]=e[n+5],r[6]=e[n+6],r[7]=e[n+7],t[0]}function a(e,n){return r[7]=e[n],r[6]=e[n+1],r[5]=e[n+2],r[4]=e[n+3],r[3]=e[n+4],r[2]=e[n+5],r[1]=e[n+6],r[0]=e[n+7],t[0]}e.writeDoubleLE=n?o:i,e.writeDoubleBE=n?i:o,e.readDoubleLE=n?s:a,e.readDoubleBE=n?a:s}():function(){function t(e,t,r,n,o,i){var s=n<0?1:0;if(s&&(n=-n),0===n)e(0,o,i+t),e(1/n>0?0:2147483648,o,i+r);else if(isNaN(n))e(0,o,i+t),e(2146959360,o,i+r);else if(n>17976931348623157e292)e(0,o,i+t),e((s<<31|2146435072)>>>0,o,i+r);else{var a;if(n<22250738585072014e-324)e((a=n/5e-324)>>>0,o,i+t),e((s<<31|a/4294967296)>>>0,o,i+r);else{var c=Math.floor(Math.log(n)/Math.LN2);1024===c&&(c=1023),e(4503599627370496*(a=n*Math.pow(2,-c))>>>0,o,i+t),e((s<<31|c+1023<<20|1048576*a&1048575)>>>0,o,i+r)}}}function r(e,t,r,n,o){var i=e(n,o+t),s=e(n,o+r),a=2*(s>>31)+1,c=s>>>20&2047,u=4294967296*(1048575&s)+i;return 2047===c?u?NaN:a*(1/0):0===c?5e-324*a*u:a*Math.pow(2,c-1075)*(u+4503599627370496)}e.writeDoubleLE=t.bind(null,writeUintLE,0,4),e.writeDoubleBE=t.bind(null,writeUintBE,4,0),e.readDoubleLE=r.bind(null,readUintLE,0,4),e.readDoubleBE=r.bind(null,readUintBE,4,0)}(),e}function writeUintLE(e,t,r){t[r]=255&e,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function writeUintBE(e,t,r){t[r]=e>>>24,t[r+1]=e>>>16&255,t[r+2]=e>>>8&255,t[r+3]=255&e}function readUintLE(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0}function readUintBE(e,t){return(e[t]<<24|e[t+1]<<16|e[t+2]<<8|e[t+3])>>>0}var inquire_1=inquire;function inquire(moduleName){try{var mod=eval("quire".replace(/^/,"re"))(moduleName);if(mod&&(mod.length||Object.keys(mod).length))return mod}catch(e){}return null}var utf8$2={},utf82;utf82=utf8$2,utf82.length=function(e){for(var t=0,r=0,n=0;n191&&n<224?i[s++]=(31&n)<<6|63&e[t++]:n>239&&n<365?(n=((7&n)<<18|(63&e[t++])<<12|(63&e[t++])<<6|63&e[t++])-65536,i[s++]=55296+(n>>10),i[s++]=56320+(1023&n)):i[s++]=(15&n)<<12|(63&e[t++])<<6|63&e[t++],s>8191&&((o||(o=[])).push(String.fromCharCode.apply(String,i)),s=0);return o?(s&&o.push(String.fromCharCode.apply(String,i.slice(0,s))),o.join("")):String.fromCharCode.apply(String,i.slice(0,s))},utf82.write=function(e,t,r){for(var n,o,i=r,s=0;s>6|192,t[r++]=63&n|128):55296==(64512&n)&&56320==(64512&(o=e.charCodeAt(s+1)))?(n=65536+((1023&n)<<10)+(1023&o),++s,t[r++]=n>>18|240,t[r++]=n>>12&63|128,t[r++]=n>>6&63|128,t[r++]=63&n|128):(t[r++]=n>>12|224,t[r++]=n>>6&63|128,t[r++]=63&n|128);return r-i};var pool_1=pool;function pool(e,t,r){var n=r||8192,o=n>>>1,i=null,s=n;return function(r){if(r<1||r>o)return e(r);s+r>n&&(i=e(n),s=0);var a=t.call(i,s,s+=r);return 7&s&&(s=1+(7|s)),a}}var longbits=LongBits$2,util$7=minimal$1;function LongBits$2(e,t){this.lo=e>>>0,this.hi=t>>>0}var zero=LongBits$2.zero=new LongBits$2(0,0);zero.toNumber=function(){return 0},zero.zzEncode=zero.zzDecode=function(){return this},zero.length=function(){return 1};var zeroHash=LongBits$2.zeroHash="\0\0\0\0\0\0\0\0";LongBits$2.fromNumber=function(e){if(0===e)return zero;var t=e<0;t&&(e=-e);var r=e>>>0,n=(e-r)/4294967296>>>0;return t&&(n=~n>>>0,r=~r>>>0,++r>4294967295&&(r=0,++n>4294967295&&(n=0))),new LongBits$2(r,n)},LongBits$2.from=function(e){if("number"==typeof e)return LongBits$2.fromNumber(e);if(util$7.isString(e)){if(!util$7.Long)return LongBits$2.fromNumber(parseInt(e,10));e=util$7.Long.fromString(e)}return e.low||e.high?new LongBits$2(e.low>>>0,e.high>>>0):zero},LongBits$2.prototype.toNumber=function(e){if(!e&&this.hi>>>31){var t=1+~this.lo>>>0,r=~this.hi>>>0;return t||(r=r+1>>>0),-(t+4294967296*r)}return this.lo+4294967296*this.hi},LongBits$2.prototype.toLong=function(e){return util$7.Long?new util$7.Long(0|this.lo,0|this.hi,Boolean(e)):{low:0|this.lo,high:0|this.hi,unsigned:Boolean(e)}};var charCodeAt=String.prototype.charCodeAt;LongBits$2.fromHash=function(e){return e===zeroHash?zero:new LongBits$2((charCodeAt.call(e,0)|charCodeAt.call(e,1)<<8|charCodeAt.call(e,2)<<16|charCodeAt.call(e,3)<<24)>>>0,(charCodeAt.call(e,4)|charCodeAt.call(e,5)<<8|charCodeAt.call(e,6)<<16|charCodeAt.call(e,7)<<24)>>>0)},LongBits$2.prototype.toHash=function(){return String.fromCharCode(255&this.lo,this.lo>>>8&255,this.lo>>>16&255,this.lo>>>24,255&this.hi,this.hi>>>8&255,this.hi>>>16&255,this.hi>>>24)},LongBits$2.prototype.zzEncode=function(){var e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this},LongBits$2.prototype.zzDecode=function(){var e=-(1&this.lo);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this},LongBits$2.prototype.length=function(){var e=this.lo,t=(this.lo>>>28|this.hi<<4)>>>0,r=this.hi>>>24;return 0===r?0===t?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:r<128?9:10},function(e){var t=minimal$1;function r(e,t,r){for(var n=Object.keys(t),o=0;o0)},t.Buffer=function(){try{var e=t.inquire("buffer").Buffer;return e.prototype.utf8Write?e:null}catch(r){return null}}(),t._Buffer_from=null,t._Buffer_allocUnsafe=null,t.newBuffer=function(e){return"number"==typeof e?t.Buffer?t._Buffer_allocUnsafe(e):new t.Array(e):t.Buffer?t._Buffer_from(e):"undefined"==typeof Uint8Array?e:new Uint8Array(e)},t.Array="undefined"!=typeof Uint8Array?Uint8Array:Array,t.Long=t.global.dcodeIO&&t.global.dcodeIO.Long||t.global.Long||t.inquire("long"),t.key2Re=/^true|false|0|1$/,t.key32Re=/^-?(?:0|[1-9][0-9]*)$/,t.key64Re=/^(?:[\\x00-\\xff]{8}|-?(?:0|[1-9][0-9]*))$/,t.longToHash=function(e){return e?t.LongBits.from(e).toHash():t.LongBits.zeroHash},t.longFromHash=function(e,r){var n=t.LongBits.fromHash(e);return t.Long?t.Long.fromBits(n.lo,n.hi,r):n.toNumber(Boolean(r))},t.merge=r,t.lcFirst=function(e){return e.charAt(0).toLowerCase()+e.substring(1)},t.newError=n,t.ProtocolError=n("ProtocolError"),t.oneOfGetter=function(e){for(var t={},r=0;r-1;--r)if(1===t[e[r]]&&void 0!==this[e[r]]&&null!==this[e[r]])return e[r]}},t.oneOfSetter=function(e){return function(t){for(var r=0;r127;)t[r++]=127&e|128,e>>>=7;t[r]=e}function VarintOp(e,t){this.len=e,this.next=void 0,this.val=t}function writeVarint64(e,t,r){for(;e.hi;)t[r++]=127&e.lo|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=127&e.lo|128,e.lo=e.lo>>>7;t[r++]=e.lo}function writeFixed32(e,t,r){t[r]=255&e,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}Writer$1.create=create$2(),Writer$1.alloc=function(e){return new util$6.Array(e)},util$6.Array!==Array&&(Writer$1.alloc=util$6.pool(Writer$1.alloc,util$6.Array.prototype.subarray)),Writer$1.prototype._push=function(e,t,r){return this.tail=this.tail.next=new Op(e,t,r),this.len+=t,this},VarintOp.prototype=Object.create(Op.prototype),VarintOp.prototype.fn=writeVarint32,Writer$1.prototype.uint32=function(e){return this.len+=(this.tail=this.tail.next=new VarintOp((e>>>=0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this},Writer$1.prototype.int32=function(e){return e<0?this._push(writeVarint64,10,LongBits$1.fromNumber(e)):this.uint32(e)},Writer$1.prototype.sint32=function(e){return this.uint32((e<<1^e>>31)>>>0)},Writer$1.prototype.uint64=function(e){var t=LongBits$1.from(e);return this._push(writeVarint64,t.length(),t)},Writer$1.prototype.int64=Writer$1.prototype.uint64,Writer$1.prototype.sint64=function(e){var t=LongBits$1.from(e).zzEncode();return this._push(writeVarint64,t.length(),t)},Writer$1.prototype.bool=function(e){return this._push(writeByte,1,e?1:0)},Writer$1.prototype.fixed32=function(e){return this._push(writeFixed32,4,e>>>0)},Writer$1.prototype.sfixed32=Writer$1.prototype.fixed32,Writer$1.prototype.fixed64=function(e){var t=LongBits$1.from(e);return this._push(writeFixed32,4,t.lo)._push(writeFixed32,4,t.hi)},Writer$1.prototype.sfixed64=Writer$1.prototype.fixed64,Writer$1.prototype.float=function(e){return this._push(util$6.float.writeFloatLE,4,e)},Writer$1.prototype.double=function(e){return this._push(util$6.float.writeDoubleLE,8,e)};var writeBytes=util$6.Array.prototype.set?function(e,t,r){t.set(e,r)}:function(e,t,r){for(var n=0;n>>0;if(!t)return this._push(writeByte,1,0);if(util$6.isString(e)){var r=Writer$1.alloc(t=base64$2.length(e));base64$2.decode(e,r,0),e=r}return this.uint32(t)._push(writeBytes,t,e)},Writer$1.prototype.string=function(e){var t=utf8$1.length(e);return t?this.uint32(t)._push(utf8$1.write,t,e):this._push(writeByte,1,0)},Writer$1.prototype.fork=function(){return this.states=new State(this),this.head=this.tail=new Op(noop,0,0),this.len=0,this},Writer$1.prototype.reset=function(){return this.states?(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 Op(noop,0,0),this.len=0),this},Writer$1.prototype.ldelim=function(){var e=this.head,t=this.tail,r=this.len;return this.reset().uint32(r),r&&(this.tail.next=e.next,this.tail=t,this.len+=r),this},Writer$1.prototype.finish=function(){for(var e=this.head.next,t=this.constructor.alloc(this.len),r=0;e;)e.fn(e.val,t,r),r+=e.len,e=e.next;return t},Writer$1._configure=function(e){BufferWriter$1=e,Writer$1.create=create$2(),BufferWriter$1._configure()};var writer_buffer=BufferWriter,Writer=writer;(BufferWriter.prototype=Object.create(Writer.prototype)).constructor=BufferWriter;var util$5=minimal$1;function BufferWriter(){Writer.call(this)}function writeStringBuffer(e,t,r){e.length<40?util$5.utf8.write(e,t,r):t.utf8Write?t.utf8Write(e,r):t.write(e,r)}BufferWriter._configure=function(){BufferWriter.alloc=util$5._Buffer_allocUnsafe,BufferWriter.writeBytesBuffer=util$5.Buffer&&util$5.Buffer.prototype instanceof Uint8Array&&"set"===util$5.Buffer.prototype.set.name?function(e,t,r){t.set(e,r)}:function(e,t,r){if(e.copy)e.copy(t,r,0,e.length);else for(var n=0;n>>0;return this.uint32(t),t&&this._push(BufferWriter.writeBytesBuffer,t,e),this},BufferWriter.prototype.string=function(e){var t=util$5.Buffer.byteLength(e);return this.uint32(t),t&&this._push(writeStringBuffer,t,e),this},BufferWriter._configure();var reader=Reader$1,util$4=minimal$1,BufferReader$1,LongBits=util$4.LongBits,utf8=util$4.utf8;function indexOutOfRange(e,t){return RangeError("index out of range: "+e.pos+" + "+(t||1)+" > "+e.len)}function Reader$1(e){this.buf=e,this.pos=0,this.len=e.length}var create_array="undefined"!=typeof Uint8Array?function(e){if(e instanceof Uint8Array||Array.isArray(e))return new Reader$1(e);throw Error("illegal buffer")}:function(e){if(Array.isArray(e))return new Reader$1(e);throw Error("illegal buffer")},create$1=function(){return util$4.Buffer?function(e){return(Reader$1.create=function(e){return util$4.Buffer.isBuffer(e)?new BufferReader$1(e):create_array(e)})(e)}:create_array},value;function readLongVarint(){var e=new LongBits(0,0),t=0;if(!(this.len-this.pos>4)){for(;t<3;++t){if(this.pos>=this.len)throw indexOutOfRange(this);if(e.lo=(e.lo|(127&this.buf[this.pos])<<7*t)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(127&this.buf[this.pos++])<<7*t)>>>0,e}for(;t<4;++t)if(e.lo=(e.lo|(127&this.buf[this.pos])<<7*t)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(127&this.buf[this.pos])<<28)>>>0,e.hi=(e.hi|(127&this.buf[this.pos])>>4)>>>0,this.buf[this.pos++]<128)return e;if(t=0,this.len-this.pos>4){for(;t<5;++t)if(e.hi=(e.hi|(127&this.buf[this.pos])<<7*t+3)>>>0,this.buf[this.pos++]<128)return e}else for(;t<5;++t){if(this.pos>=this.len)throw indexOutOfRange(this);if(e.hi=(e.hi|(127&this.buf[this.pos])<<7*t+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}function readFixed32_end(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}function readFixed64(){if(this.pos+8>this.len)throw indexOutOfRange(this,8);return new LongBits(readFixed32_end(this.buf,this.pos+=4),readFixed32_end(this.buf,this.pos+=4))}Reader$1.create=create$1(),Reader$1.prototype._slice=util$4.Array.prototype.subarray||util$4.Array.prototype.slice,Reader$1.prototype.uint32=(value=4294967295,function(){if(value=(127&this.buf[this.pos])>>>0,this.buf[this.pos++]<128)return value;if(value=(value|(127&this.buf[this.pos])<<7)>>>0,this.buf[this.pos++]<128)return value;if(value=(value|(127&this.buf[this.pos])<<14)>>>0,this.buf[this.pos++]<128)return value;if(value=(value|(127&this.buf[this.pos])<<21)>>>0,this.buf[this.pos++]<128)return value;if(value=(value|(15&this.buf[this.pos])<<28)>>>0,this.buf[this.pos++]<128)return value;if((this.pos+=5)>this.len)throw this.pos=this.len,indexOutOfRange(this,10);return value}),Reader$1.prototype.int32=function(){return 0|this.uint32()},Reader$1.prototype.sint32=function(){var e=this.uint32();return e>>>1^-(1&e)|0},Reader$1.prototype.bool=function(){return 0!==this.uint32()},Reader$1.prototype.fixed32=function(){if(this.pos+4>this.len)throw indexOutOfRange(this,4);return readFixed32_end(this.buf,this.pos+=4)},Reader$1.prototype.sfixed32=function(){if(this.pos+4>this.len)throw indexOutOfRange(this,4);return 0|readFixed32_end(this.buf,this.pos+=4)},Reader$1.prototype.float=function(){if(this.pos+4>this.len)throw indexOutOfRange(this,4);var e=util$4.float.readFloatLE(this.buf,this.pos);return this.pos+=4,e},Reader$1.prototype.double=function(){if(this.pos+8>this.len)throw indexOutOfRange(this,4);var e=util$4.float.readDoubleLE(this.buf,this.pos);return this.pos+=8,e},Reader$1.prototype.bytes=function(){var e=this.uint32(),t=this.pos,r=this.pos+e;if(r>this.len)throw indexOutOfRange(this,e);return this.pos+=e,Array.isArray(this.buf)?this.buf.slice(t,r):t===r?new this.buf.constructor(0):this._slice.call(this.buf,t,r)},Reader$1.prototype.string=function(){var e=this.bytes();return utf8.read(e,0,e.length)},Reader$1.prototype.skip=function(e){if("number"==typeof e){if(this.pos+e>this.len)throw indexOutOfRange(this,e);this.pos+=e}else do{if(this.pos>=this.len)throw indexOutOfRange(this)}while(128&this.buf[this.pos++]);return this},Reader$1.prototype.skipType=function(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;4!=(e=7&this.uint32());)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error("invalid wire type "+e+" at offset "+this.pos)}return this},Reader$1._configure=function(e){BufferReader$1=e,Reader$1.create=create$1(),BufferReader$1._configure();var t=util$4.Long?"toLong":"toNumber";util$4.merge(Reader$1.prototype,{int64:function(){return readLongVarint.call(this)[t](!1)},uint64:function(){return readLongVarint.call(this)[t](!0)},sint64:function(){return readLongVarint.call(this).zzDecode()[t](!1)},fixed64:function(){return readFixed64.call(this)[t](!0)},sfixed64:function(){return readFixed64.call(this)[t](!1)}})};var reader_buffer=BufferReader,Reader=reader;(BufferReader.prototype=Object.create(Reader.prototype)).constructor=BufferReader;var util$3=minimal$1;function BufferReader(e){Reader.call(this,e)}BufferReader._configure=function(){util$3.Buffer&&(BufferReader.prototype._slice=util$3.Buffer.prototype.slice)},BufferReader.prototype.string=function(){var e=this.uint32();return this.buf.utf8Slice?this.buf.utf8Slice(this.pos,this.pos=Math.min(this.pos+e,this.len)):this.buf.toString("utf-8",this.pos,this.pos=Math.min(this.pos+e,this.len))},BufferReader._configure();var rpc={},service=Service,util$2=minimal$1;function Service(e,t,r){if("function"!=typeof e)throw TypeError("rpcImpl must be a function");util$2.EventEmitter.call(this),this.rpcImpl=e,this.requestDelimited=Boolean(t),this.responseDelimited=Boolean(r)}(Service.prototype=Object.create(util$2.EventEmitter.prototype)).constructor=Service,Service.prototype.rpcCall=function e(t,r,n,o,i){if(!o)throw TypeError("request must be specified");var s=this;if(!i)return util$2.asPromise(e,s,t,r,n,o);if(s.rpcImpl)try{return s.rpcImpl(t,r[s.requestDelimited?"encodeDelimited":"encode"](o).finish(),(function(e,r){if(e)return s.emit("error",e,t),i(e);if(null!==r){if(!(r instanceof n))try{r=n[s.responseDelimited?"decodeDelimited":"decode"](r)}catch(o){return s.emit("error",o,t),i(o)}return s.emit("data",r,t),i(null,r)}s.end(!0)}))}catch(a){return s.emit("error",a,t),void setTimeout((function(){i(a)}),0)}else setTimeout((function(){i(Error("already ended"))}),0)},Service.prototype.end=function(e){return this.rpcImpl&&(e||this.rpcImpl(null,null,null),this.rpcImpl=null,this.emit("end").off()),this},rpc.Service=service;var roots={};!function(e){var t=indexMinimal;function r(){t.util._configure(),t.Writer._configure(t.BufferWriter),t.Reader._configure(t.BufferReader)}t.build="minimal",t.Writer=writer,t.BufferWriter=writer_buffer,t.Reader=reader,t.BufferReader=reader_buffer,t.util=minimal$1,t.rpc=rpc,t.roots=roots,t.configure=r,r()}();var minimal=indexMinimal;const $Reader=minimal.Reader,$Writer=minimal.Writer,$util=minimal.util,$root=minimal.roots["ipfs-unixfs"]||(minimal.roots["ipfs-unixfs"]={}),Data=$root.Data=(()=>{function e(e){if(this.blocksizes=[],e)for(var t=Object.keys(e),r=0;r>>3){case 1:n.Type=e.int32();break;case 2:n.Data=e.bytes();break;case 3:n.filesize=e.uint64();break;case 4:if(n.blocksizes&&n.blocksizes.length||(n.blocksizes=[]),2==(7&o))for(var i=e.uint32()+e.pos;e.pos>>0,e.filesize.high>>>0).toNumber(!0))),e.blocksizes){if(!Array.isArray(e.blocksizes))throw TypeError(".Data.blocksizes: array expected");t.blocksizes=[];for(var r=0;r>>0,e.blocksizes[r].high>>>0).toNumber(!0))}if(null!=e.hashType&&($util.Long?(t.hashType=$util.Long.fromValue(e.hashType)).unsigned=!0:"string"==typeof e.hashType?t.hashType=parseInt(e.hashType,10):"number"==typeof e.hashType?t.hashType=e.hashType:"object"==typeof e.hashType&&(t.hashType=new $util.LongBits(e.hashType.low>>>0,e.hashType.high>>>0).toNumber(!0))),null!=e.fanout&&($util.Long?(t.fanout=$util.Long.fromValue(e.fanout)).unsigned=!0:"string"==typeof e.fanout?t.fanout=parseInt(e.fanout,10):"number"==typeof e.fanout?t.fanout=e.fanout:"object"==typeof e.fanout&&(t.fanout=new $util.LongBits(e.fanout.low>>>0,e.fanout.high>>>0).toNumber(!0))),null!=e.mode&&(t.mode=e.mode>>>0),null!=e.mtime){if("object"!=typeof e.mtime)throw TypeError(".Data.mtime: object expected");t.mtime=$root.UnixTime.fromObject(e.mtime)}return t},e.toObject=function(e,t){t||(t={});var r={};if((t.arrays||t.defaults)&&(r.blocksizes=[]),t.defaults){if(r.Type=t.enums===String?"Raw":0,t.bytes===String?r.Data="":(r.Data=[],t.bytes!==Array&&(r.Data=$util.newBuffer(r.Data))),$util.Long){var n=new $util.Long(0,0,!0);r.filesize=t.longs===String?n.toString():t.longs===Number?n.toNumber():n}else r.filesize=t.longs===String?"0":0;if($util.Long){n=new $util.Long(0,0,!0);r.hashType=t.longs===String?n.toString():t.longs===Number?n.toNumber():n}else r.hashType=t.longs===String?"0":0;if($util.Long){n=new $util.Long(0,0,!0);r.fanout=t.longs===String?n.toString():t.longs===Number?n.toNumber():n}else r.fanout=t.longs===String?"0":0;r.mode=0,r.mtime=null}if(null!=e.Type&&e.hasOwnProperty("Type")&&(r.Type=t.enums===String?$root.Data.DataType[e.Type]:e.Type),null!=e.Data&&e.hasOwnProperty("Data")&&(r.Data=t.bytes===String?$util.base64.encode(e.Data,0,e.Data.length):t.bytes===Array?Array.prototype.slice.call(e.Data):e.Data),null!=e.filesize&&e.hasOwnProperty("filesize")&&("number"==typeof e.filesize?r.filesize=t.longs===String?String(e.filesize):e.filesize:r.filesize=t.longs===String?$util.Long.prototype.toString.call(e.filesize):t.longs===Number?new $util.LongBits(e.filesize.low>>>0,e.filesize.high>>>0).toNumber(!0):e.filesize),e.blocksizes&&e.blocksizes.length){r.blocksizes=[];for(var o=0;o>>0,e.blocksizes[o].high>>>0).toNumber(!0):e.blocksizes[o]}return null!=e.hashType&&e.hasOwnProperty("hashType")&&("number"==typeof e.hashType?r.hashType=t.longs===String?String(e.hashType):e.hashType:r.hashType=t.longs===String?$util.Long.prototype.toString.call(e.hashType):t.longs===Number?new $util.LongBits(e.hashType.low>>>0,e.hashType.high>>>0).toNumber(!0):e.hashType),null!=e.fanout&&e.hasOwnProperty("fanout")&&("number"==typeof e.fanout?r.fanout=t.longs===String?String(e.fanout):e.fanout:r.fanout=t.longs===String?$util.Long.prototype.toString.call(e.fanout):t.longs===Number?new $util.LongBits(e.fanout.low>>>0,e.fanout.high>>>0).toNumber(!0):e.fanout),null!=e.mode&&e.hasOwnProperty("mode")&&(r.mode=e.mode),null!=e.mtime&&e.hasOwnProperty("mtime")&&(r.mtime=$root.UnixTime.toObject(e.mtime,t)),r},e.prototype.toJSON=function(){return this.constructor.toObject(this,minimal.util.toJSONOptions)},e.DataType=function(){const e={},t=Object.create(e);return t[e[0]="Raw"]=0,t[e[1]="Directory"]=1,t[e[2]="File"]=2,t[e[3]="Metadata"]=3,t[e[4]="Symlink"]=4,t[e[5]="HAMTShard"]=5,t}(),e})();$root.UnixTime=(()=>{function e(e){if(e)for(var t=Object.keys(e),r=0;r>>3){case 1:n.Seconds=e.int64();break;case 2:n.FractionalNanoseconds=e.fixed32();break;default:e.skipType(7&o)}}if(!n.hasOwnProperty("Seconds"))throw $util.ProtocolError("missing required 'Seconds'",{instance:n});return n},e.fromObject=function(e){if(e instanceof $root.UnixTime)return e;var t=new $root.UnixTime;return null!=e.Seconds&&($util.Long?(t.Seconds=$util.Long.fromValue(e.Seconds)).unsigned=!1:"string"==typeof e.Seconds?t.Seconds=parseInt(e.Seconds,10):"number"==typeof e.Seconds?t.Seconds=e.Seconds:"object"==typeof e.Seconds&&(t.Seconds=new $util.LongBits(e.Seconds.low>>>0,e.Seconds.high>>>0).toNumber())),null!=e.FractionalNanoseconds&&(t.FractionalNanoseconds=e.FractionalNanoseconds>>>0),t},e.toObject=function(e,t){t||(t={});var r={};if(t.defaults){if($util.Long){var n=new $util.Long(0,0,!1);r.Seconds=t.longs===String?n.toString():t.longs===Number?n.toNumber():n}else r.Seconds=t.longs===String?"0":0;r.FractionalNanoseconds=0}return null!=e.Seconds&&e.hasOwnProperty("Seconds")&&("number"==typeof e.Seconds?r.Seconds=t.longs===String?String(e.Seconds):e.Seconds:r.Seconds=t.longs===String?$util.Long.prototype.toString.call(e.Seconds):t.longs===Number?new $util.LongBits(e.Seconds.low>>>0,e.Seconds.high>>>0).toNumber():e.Seconds),null!=e.FractionalNanoseconds&&e.hasOwnProperty("FractionalNanoseconds")&&(r.FractionalNanoseconds=e.FractionalNanoseconds),r},e.prototype.toJSON=function(){return this.constructor.toObject(this,minimal.util.toJSONOptions)},e})(),$root.Metadata=(()=>{function e(e){if(e)for(var t=Object.keys(e),r=0;r>>3){case 1:n.MimeType=e.string();break;default:e.skipType(7&o)}}return n},e.fromObject=function(e){if(e instanceof $root.Metadata)return e;var t=new $root.Metadata;return null!=e.MimeType&&(t.MimeType=String(e.MimeType)),t},e.toObject=function(e,t){t||(t={});var r={};return t.defaults&&(r.MimeType=""),null!=e.MimeType&&e.hasOwnProperty("MimeType")&&(r.MimeType=e.MimeType),r},e.prototype.toJSON=function(){return this.constructor.toObject(this,minimal.util.toJSONOptions)},e})();const PBData=Data,types=["raw","directory","file","metadata","symlink","hamt-sharded-directory"],dirTypes=["directory","hamt-sharded-directory"],DEFAULT_FILE_MODE=parseInt("0644",8),DEFAULT_DIRECTORY_MODE=parseInt("0755",8);function parseMode$1(e){if(null!=e)return"number"==typeof e?4095&e:"0"===(e=e.toString()).substring(0,1)?4095&parseInt(e,8):4095&parseInt(e,10)}function parseMtime$1(e){if(null==e)return;let t;if(null!=e.secs&&(t={secs:e.secs,nsecs:e.nsecs}),null!=e.Seconds&&(t={secs:e.Seconds,nsecs:e.FractionalNanoseconds}),Array.isArray(e)&&(t={secs:e[0],nsecs:e[1]}),e instanceof Date){const r=e.getTime(),n=Math.floor(r/1e3);t={secs:n,nsecs:1e3*(r-1e3*n)}}if(Object.prototype.hasOwnProperty.call(t,"secs")){if(null!=t&&null!=t.nsecs&&(t.nsecs<0||t.nsecs>999999999))throw errCode$3(new Error("mtime-nsecs must be within the range [0,999999999]"),"ERR_INVALID_MTIME_NSECS");return t}}class UnixFS{static unmarshal(e){const t=PBData.decode(e),r=PBData.toObject(t,{defaults:!1,arrays:!0,longs:Number,objects:!1}),n=new UnixFS({type:types[r.Type],data:r.Data,blockSizes:r.blocksizes,mode:r.mode,mtime:r.mtime?{secs:r.mtime.Seconds,nsecs:r.mtime.FractionalNanoseconds}:void 0});return n._originalMode=r.mode||0,n}constructor(e={type:"file"}){const{type:t,data:r,blockSizes:n,hashType:o,fanout:i,mtime:s,mode:a}=e;if(t&&!types.includes(t))throw errCode$3(new Error("Type: "+t+" is not valid"),"ERR_INVALID_TYPE");this.type=t||"file",this.data=r,this.hashType=o,this.fanout=i,this.blockSizes=n||[],this._originalMode=0,this.mode=parseMode$1(a),s&&(this.mtime=parseMtime$1(s),this.mtime&&!this.mtime.nsecs&&(this.mtime.nsecs=0))}set mode(e){this._mode=this.isDirectory()?DEFAULT_DIRECTORY_MODE:DEFAULT_FILE_MODE;const t=parseMode$1(e);void 0!==t&&(this._mode=t)}get mode(){return this._mode}isDirectory(){return Boolean(this.type&&dirTypes.includes(this.type))}addBlockSize(e){this.blockSizes.push(e)}removeBlockSize(e){this.blockSizes.splice(e,1)}fileSize(){if(this.isDirectory())return 0;let e=0;return this.blockSizes.forEach((t=>{e+=t})),this.data&&(e+=this.data.length),e}marshal(){let e;switch(this.type){case"raw":e=PBData.DataType.Raw;break;case"directory":e=PBData.DataType.Directory;break;case"file":e=PBData.DataType.File;break;case"metadata":e=PBData.DataType.Metadata;break;case"symlink":e=PBData.DataType.Symlink;break;case"hamt-sharded-directory":e=PBData.DataType.HAMTShard;break;default:throw errCode$3(new Error("Type: "+e+" is not valid"),"ERR_INVALID_TYPE")}let t,r,n=this.data;if(this.data&&this.data.length||(n=void 0),null!=this.mode&&(t=4294963200&this._originalMode|(parseMode$1(this.mode)||0),t!==DEFAULT_FILE_MODE||this.isDirectory()||(t=void 0),t===DEFAULT_DIRECTORY_MODE&&this.isDirectory()&&(t=void 0)),null!=this.mtime){const e=parseMtime$1(this.mtime);e&&(r={Seconds:e.secs,FractionalNanoseconds:e.nsecs},0===r.FractionalNanoseconds&&delete r.FractionalNanoseconds)}const o={Type:e,Data:n,filesize:this.isDirectory()?void 0:this.fileSize(),blocksizes:this.blockSizes,hashType:this.hashType,fanout:this.fanout,mode:t,mtime:r};return PBData.encode(o).finish()}}var src$3=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",parseMode:parseMode$1,parseMtime:parseMtime$1,UnixFS:UnixFS});const textDecoder=new TextDecoder;function decodeVarint(e,t){let r=0;for(let n=0;;n+=7){if(n>=64)throw new Error("protobuf: varint overflow");if(t>=e.length)throw new Error("protobuf: unexpected end of data");const o=e[t++];if(r+=n<28?(127&o)<e.length)throw new Error("protobuf: unexpected end of data");return[e.subarray(t,n),n]}function decodeKey(e,t){let r;return[r,t]=decodeVarint(e,t),[7&r,r>>3,t]}function decodeLink(e){const t={},r=e.length;let n=0;for(;nr)throw new Error("protobuf: (PBLink) unexpected end of data");return t}function decodeNode(e){const t=e.length;let r,n,o=0,i=!1;for(;ot)throw new Error("protobuf: (PBNode) unexpected end of data");const s={};return n&&(s.Data=n),s.Links=r||[],s}const textEncoder$1=new TextEncoder,maxInt32=2**32,maxUInt32=2**31;function encodeLink(e,t){let r=t.length;if("number"==typeof e.Tsize){if(e.Tsize<0)throw new Error("Tsize cannot be negative");if(!Number.isSafeInteger(e.Tsize))throw new Error("Tsize too large for encoding");r=encodeVarint(t,r,e.Tsize)-1,t[r]=24}if("string"==typeof e.Name){const n=textEncoder$1.encode(e.Name);r-=n.length,t.set(n,r),r=encodeVarint(t,r,n.length)-1,t[r]=18}return e.Hash&&(r-=e.Hash.length,t.set(e.Hash,r),r=encodeVarint(t,r,e.Hash.length)-1,t[r]=10),t.length-r}function encodeNode(e){const t=sizeNode(e),r=new Uint8Array(t);let n=t;if(e.Data&&(n-=e.Data.length,r.set(e.Data,n),n=encodeVarint(r,n,e.Data.length)-1,r[n]=10),e.Links)for(let o=e.Links.length-1;o>=0;o--){const t=encodeLink(e.Links[o],r.subarray(0,n));n-=t,n=encodeVarint(r,n,t)-1,r[n]=18}return r}function sizeLink(e){let t=0;if(e.Hash){const r=e.Hash.length;t+=1+r+sov(r)}if("string"==typeof e.Name){const r=textEncoder$1.encode(e.Name).length;t+=1+r+sov(r)}return"number"==typeof e.Tsize&&(t+=1+sov(e.Tsize)),t}function sizeNode(e){let t=0;if(e.Data){const r=e.Data.length;t+=1+r+sov(r)}if(e.Links)for(const r of e.Links){const e=sizeLink(r);t+=1+e+sov(e)}return t}function encodeVarint(e,t,r){const n=t-=sov(r);for(;r>=maxUInt32;)e[t++]=127&r|128,r/=128;for(;r>=128;)e[t++]=127&r|128,r>>>=7;return e[t]=r,n}function sov(e){return e%2==0&&e++,Math.floor((len64(e)+6)/7)}function len64(e){let t=0;return e>=maxInt32&&(e=Math.floor(e/maxInt32),t=32),e>=65536&&(e>>>=16,t+=16),e>=256&&(e>>>=8,t+=8),t+len8tab[e]}const len8tab=[0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8],pbNodeProperties=["Data","Links"],pbLinkProperties=["Hash","Name","Tsize"],textEncoder=new TextEncoder;function linkComparator(e,t){if(e===t)return 0;const r=e.Name?textEncoder.encode(e.Name):[],n=t.Name?textEncoder.encode(t.Name):[];let o=r.length,i=n.length;for(let s=0,a=Math.min(o,i);s!t.includes(e)))}function asLink(e){if("object"==typeof e.asCID){const t=CID$1.asCID(e);if(!t)throw new TypeError("Invalid DAG-PB form");return{Hash:t}}if("object"!=typeof e||Array.isArray(e))throw new TypeError("Invalid DAG-PB form");const t={};if(e.Hash){let n=CID$1.asCID(e.Hash);try{n||("string"==typeof e.Hash?n=CID$1.parse(e.Hash):e.Hash instanceof Uint8Array&&(n=CID$1.decode(e.Hash)))}catch(r){throw new TypeError(`Invalid DAG-PB form: ${r.message}`)}n&&(t.Hash=n)}if(!t.Hash)throw new TypeError("Invalid DAG-PB form");return"string"==typeof e.Name&&(t.Name=e.Name),"number"==typeof e.Tsize&&(t.Tsize=e.Tsize),t}function prepare(e){if((e instanceof Uint8Array||"string"==typeof e)&&(e={Data:e}),"object"!=typeof e||Array.isArray(e))throw new TypeError("Invalid DAG-PB form");const t={};if(void 0!==e.Data)if("string"==typeof e.Data)t.Data=textEncoder.encode(e.Data);else{if(!(e.Data instanceof Uint8Array))throw new TypeError("Invalid DAG-PB form");t.Data=e.Data}if(void 0!==e.Links){if(!Array.isArray(e.Links))throw new TypeError("Invalid DAG-PB form");t.Links=e.Links.map(asLink),t.Links.sort(linkComparator)}else t.Links=[];return t}function validate(e){if(!e||"object"!=typeof e||Array.isArray(e))throw new TypeError("Invalid DAG-PB form");if(!hasOnlyProperties(e,pbNodeProperties))throw new TypeError("Invalid DAG-PB form (extraneous properties)");if(void 0!==e.Data&&!(e.Data instanceof Uint8Array))throw new TypeError("Invalid DAG-PB form (Data must be a Uint8Array)");if(!Array.isArray(e.Links))throw new TypeError("Invalid DAG-PB form (Links must be an array)");for(let t=0;t0&&-1===linkComparator(r,e.Links[t-1]))throw new TypeError("Invalid DAG-PB form (links must be sorted by Name bytes)")}}function createNode(e,t=[]){return prepare({Data:e,Links:t})}function createLink(e,t,r){return asLink({Hash:r,Name:e,Tsize:t})}const name$1="dag-pb",code$2=112;function encode$3(e){validate(e);const t={};return e.Links&&(t.Links=e.Links.map((e=>{const t={};return e.Hash&&(t.Hash=e.Hash.bytes),void 0!==e.Name&&(t.Name=e.Name),void 0!==e.Tsize&&(t.Tsize=e.Tsize),t}))),e.Data&&(t.Data=e.Data),encodeNode(t)}function decode$3(e){const t=decodeNode(e),r={};return t.Data&&(r.Data=t.Data),t.Links&&(r.Links=t.Links.map((e=>{const t={};try{t.Hash=CID$1.decode(e.Hash)}catch(r){}if(!t.Hash)throw new Error("Invalid Hash field found in link, expected CID");return void 0!==e.Name&&(t.Name=e.Name),void 0!==e.Tsize&&(t.Tsize=e.Tsize),t}))),r}var pb=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",name:name$1,code:code$2,encode:encode$3,decode:decode$3,prepare:prepare,validate:validate,createNode:createNode,createLink:createLink});const persist=async(e,t,r)=>{r.codec||(r.codec=pb),r.hasher||(r.hasher=sha256),void 0===r.cidVersion&&(r.cidVersion=1),r.codec===pb&&r.hasher!==sha256&&(r.cidVersion=1);const n=await r.hasher.digest(e),o=CID$1.create(r.cidVersion,r.codec.code,n);return r.onlyHash||await t.put(o,e,{signal:r.signal}),o},dirBuilder=async(e,t,r)=>{const n=new UnixFS({type:"directory",mtime:e.mtime,mode:e.mode}),o=encode$3(prepare({Data:n.marshal()}));return{cid:await persist(o,t,r),path:e.path,unixfs:n,size:o.length}},raw$1=e=>coerce(e),{name:name,code:code$1,encode:encode$2,decode:decode$2}={name:"raw",code:85,decode:raw$1,encode:raw$1};var raw$2=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",name:name,code:code$1,encode:encode$2,decode:decode$2});const all$2=async e=>{const t=[];for await(const r of e)t.push(r);return t};var itAll=all$2;async function flat(e,t){return t(await itAll(e))}function balanced(e,t,r){return reduceToParents(e,t,r)}async function reduceToParents(e,t,r){const n=[];for await(const o of itBatch(e,r.maxChildrenPerNode))n.push(await t(o));return n.length>1?reduceToParents(n,t,r):n[0]}async function trickleStream(e,t,r){const n=new Root(r.layerRepeat);let o=0,i=1,s=n;for await(const a of itBatch(e,r.maxChildrenPerNode))s.isFull()&&(s!==n&&n.addChild(await s.reduce(t)),o&&o%r.layerRepeat==0&&i++,s=new SubTree(i,r.layerRepeat,o),o++),s.append(a);return s&&s!==n&&n.addChild(await s.reduce(t)),n.reduce(t)}class SubTree{constructor(e,t,r=0){this.maxDepth=e,this.layerRepeat=t,this.currentDepth=1,this.iteration=r,this.root=this.node=this.parent={children:[],depth:this.currentDepth,maxDepth:e,maxChildren:(this.maxDepth-this.currentDepth)*this.layerRepeat}}isFull(){if(!this.root.data)return!1;if(this.currentDepthe.data)).map((e=>this._reduce(e,t))))),t((e.data||[]).concat(r))}_findParent(e,t){const r=e.parent;if(r&&0!==r.depth)return r.children.length!==r.maxChildren&&r.maxChildren?r:this._findParent(r,t)}}class Root extends SubTree{constructor(e){super(0,e),this.root.depth=0,this.currentDepth=1}addChild(e){this.root.children.push(e)}reduce(e){return e((this.root.data||[]).concat(this.root.children))}}async function*bufferImporter(e,t,r){for await(let n of e.content)yield async()=>{let o;r.progress(n.length,e.path);const i={codec:pb,cidVersion:r.cidVersion,hasher:r.hasher,onlyHash:r.onlyHash};return r.rawLeaves?(i.codec=raw$2,i.cidVersion=1):(o=new UnixFS({type:r.leafType,data:n,mtime:e.mtime,mode:e.mode}),n=encode$3({Data:o.marshal(),Links:[]})),{cid:await persist(n,t,i),unixfs:o,size:n.length}}}const dagBuilders={flat:flat,balanced:balanced,trickle:trickleStream};async function*buildFileBatch(e,t,r){let n,o,i=-1;o="function"==typeof r.bufferImporter?r.bufferImporter:bufferImporter;for await(const s of itParallelBatch(o(e,t,r),r.blockWriteConcurrency))i++,0!==i?(1===i&&n&&(yield n,n=null),yield s):n=s;n&&(n.single=!0,yield n)}const reduce=(e,t,r)=>async function(n){if(1===n.length&&n[0].single&&r.reduceSingleLeafToSelf){const o=n[0];if(o.cid.code===code$1&&(void 0!==e.mtime||void 0!==e.mode)){let n=await t.get(o.cid);o.unixfs=new UnixFS({type:"file",mtime:e.mtime,mode:e.mode,data:n}),n=encode$3(prepare({Data:o.unixfs.marshal()})),o.cid=await persist(n,t,__spreadProps(__spreadValues({},r),{codec:pb,hasher:r.hasher,cidVersion:r.cidVersion})),o.size=n.length}return{cid:o.cid,path:e.path,unixfs:o.unixfs,size:o.size}}const o=new UnixFS({type:"file",mtime:e.mtime,mode:e.mode}),i=n.filter((e=>!(e.cid.code!==code$1||!e.size)||(!(!e.unixfs||e.unixfs.data||!e.unixfs.fileSize())||Boolean(e.unixfs&&e.unixfs.data&&e.unixfs.data.length)))).map((e=>e.cid.code===code$1?(o.addBlockSize(e.size),{Name:"",Tsize:e.size,Hash:e.cid}):(e.unixfs&&e.unixfs.data?o.addBlockSize(e.unixfs.data.length):o.addBlockSize(e.unixfs&&e.unixfs.fileSize()||0),{Name:"",Tsize:e.size,Hash:e.cid}))),s={Data:o.marshal(),Links:i},a=encode$3(prepare(s));return{cid:await persist(a,t,r),path:e.path,unixfs:o,size:a.length+s.Links.reduce(((e,t)=>e+t.Tsize),0)}};function fileBuilder(e,t,r){const n=dagBuilders[r.strategy];if(!n)throw errCode$3(new Error(`Unknown importer build strategy name: ${r.strategy}`),"ERR_BAD_STRATEGY");return n(buildFileBatch(e,t,r),reduce(e,t,r),r)}var buffer={},base64Js={};base64Js.byteLength=byteLength,base64Js.toByteArray=toByteArray,base64Js.fromByteArray=fromByteArray;for(var lookup=[],revLookup=[],Arr="undefined"!=typeof Uint8Array?Uint8Array:Array,code="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",i=0,len=code.length;i0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");return-1===r&&(r=t),[r,r===t?0:4-r%4]}function byteLength(e){var t=getLens(e),r=t[0],n=t[1];return 3*(r+n)/4-n}function _byteLength(e,t,r){return 3*(t+r)/4-r}function toByteArray(e){var t,r,n=getLens(e),o=n[0],i=n[1],s=new Arr(_byteLength(e,o,i)),a=0,c=i>0?o-4:o;for(r=0;r>16&255,s[a++]=t>>8&255,s[a++]=255&t;return 2===i&&(t=revLookup[e.charCodeAt(r)]<<2|revLookup[e.charCodeAt(r+1)]>>4,s[a++]=255&t),1===i&&(t=revLookup[e.charCodeAt(r)]<<10|revLookup[e.charCodeAt(r+1)]<<4|revLookup[e.charCodeAt(r+2)]>>2,s[a++]=t>>8&255,s[a++]=255&t),s}function tripletToBase64(e){return lookup[e>>18&63]+lookup[e>>12&63]+lookup[e>>6&63]+lookup[63&e]}function encodeChunk(e,t,r){for(var n,o=[],i=t;ia?a:s+i));return 1===n?(t=e[r-1],o.push(lookup[t>>2]+lookup[t<<4&63]+"==")):2===n&&(t=(e[r-2]<<8)+e[r-1],o.push(lookup[t>>10]+lookup[t>>4&63]+lookup[t<<2&63]+"=")),o.join("")}revLookup["-".charCodeAt(0)]=62,revLookup["_".charCodeAt(0)]=63;var ieee754={ /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh */ read:function(e,t,r,n,o){var i,s,a=8*o-n-1,c=(1<>1,l=-7,f=r?o-1:0,h=r?-1:1,d=e[t+f];for(f+=h,i=d&(1<<-l)-1,d>>=-l,l+=a;l>0;i=256*i+e[t+f],f+=h,l-=8);for(s=i&(1<<-l)-1,i>>=-l,l+=n;l>0;s=256*s+e[t+f],f+=h,l-=8);if(0===i)i=1-u;else{if(i===c)return s?NaN:1/0*(d?-1:1);s+=Math.pow(2,n),i-=u}return(d?-1:1)*s*Math.pow(2,i-n)},write:function(e,t,r,n,o,i){var s,a,c,u=8*i-o-1,l=(1<>1,h=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,d=n?0:i-1,p=n?1:-1,y=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,s=l):(s=Math.floor(Math.log(t)/Math.LN2),t*(c=Math.pow(2,-s))<1&&(s--,c*=2),(t+=s+f>=1?h/c:h*Math.pow(2,1-f))*c>=2&&(s++,c/=2),s+f>=l?(a=0,s=l):s+f>=1?(a=(t*c-1)*Math.pow(2,o),s+=f):(a=t*Math.pow(2,f-1)*Math.pow(2,o),s=0));o>=8;e[r+d]=255&a,d+=p,a/=256,o-=8);for(s=s<0;e[r+d]=255&s,d+=p,s/=256,u-=8);e[r+d-p]|=128*y}}; /*! * The buffer module from node.js, for the browser. * * @author Feross Aboukhadijeh * @license MIT */ !function(e){const t=base64Js,r=ieee754,n="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;e.Buffer=s,e.SlowBuffer=function(e){+e!=e&&(e=0);return s.alloc(+e)},e.INSPECT_MAX_BYTES=50;const o=2147483647;function i(e){if(e>o)throw new RangeError('The value "'+e+'" is invalid for option "size"');const t=new Uint8Array(e);return Object.setPrototypeOf(t,s.prototype),t}function s(e,t,r){if("number"==typeof e){if("string"==typeof t)throw new TypeError('The "string" argument must be of type string. Received type number');return u(e)}return a(e,t,r)}function a(e,t,r){if("string"==typeof e)return function(e,t){"string"==typeof t&&""!==t||(t="utf8");if(!s.isEncoding(t))throw new TypeError("Unknown encoding: "+t);const r=0|d(e,t);let n=i(r);const o=n.write(e,t);o!==r&&(n=n.slice(0,o));return n}(e,t);if(ArrayBuffer.isView(e))return function(e){if(G(e,Uint8Array)){const t=new Uint8Array(e);return f(t.buffer,t.byteOffset,t.byteLength)}return l(e)}(e);if(null==e)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);if(G(e,ArrayBuffer)||e&&G(e.buffer,ArrayBuffer))return f(e,t,r);if("undefined"!=typeof SharedArrayBuffer&&(G(e,SharedArrayBuffer)||e&&G(e.buffer,SharedArrayBuffer)))return f(e,t,r);if("number"==typeof e)throw new TypeError('The "value" argument must not be of type number. Received type number');const n=e.valueOf&&e.valueOf();if(null!=n&&n!==e)return s.from(n,t,r);const o=function(e){if(s.isBuffer(e)){const t=0|h(e.length),r=i(t);return 0===r.length||e.copy(r,0,0,t),r}if(void 0!==e.length)return"number"!=typeof e.length||Y(e.length)?i(0):l(e);if("Buffer"===e.type&&Array.isArray(e.data))return l(e.data)}(e);if(o)return o;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof e[Symbol.toPrimitive])return s.from(e[Symbol.toPrimitive]("string"),t,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e)}function c(e){if("number"!=typeof e)throw new TypeError('"size" argument must be of type number');if(e<0)throw new RangeError('The value "'+e+'" is invalid for option "size"')}function u(e){return c(e),i(e<0?0:0|h(e))}function l(e){const t=e.length<0?0:0|h(e.length),r=i(t);for(let n=0;n=o)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+o.toString(16)+" bytes");return 0|e}function d(e,t){if(s.isBuffer(e))return e.length;if(ArrayBuffer.isView(e)||G(e,ArrayBuffer))return e.byteLength;if("string"!=typeof e)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof e);const r=e.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===r)return 0;let o=!1;for(;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return H(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return W(e).length;default:if(o)return n?-1:H(e).length;t=(""+t).toLowerCase(),o=!0}}function p(e,t,r){let n=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return S(this,t,r);case"utf8":case"utf-8":return T(this,t,r);case"ascii":return A(this,t,r);case"latin1":case"binary":return k(this,t,r);case"base64":return E(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return I(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}function y(e,t,r){const n=e[t];e[t]=e[r],e[r]=n}function m(e,t,r,n,o){if(0===e.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),Y(r=+r)&&(r=o?0:e.length-1),r<0&&(r=e.length+r),r>=e.length){if(o)return-1;r=e.length-1}else if(r<0){if(!o)return-1;r=0}if("string"==typeof t&&(t=s.from(t,n)),s.isBuffer(t))return 0===t.length?-1:g(e,t,r,n,o);if("number"==typeof t)return t&=255,"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):g(e,[t],r,n,o);throw new TypeError("val must be string, number or Buffer")}function g(e,t,r,n,o){let i,s=1,a=e.length,c=t.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(e.length<2||t.length<2)return-1;s=2,a/=2,c/=2,r/=2}function u(e,t){return 1===s?e[t]:e.readUInt16BE(t*s)}if(o){let n=-1;for(i=r;ia&&(r=a-c),i=r;i>=0;i--){let r=!0;for(let n=0;no&&(n=o):n=o;const i=t.length;let s;for(n>i/2&&(n=i/2),s=0;s>8,o=r%256,i.push(o),i.push(n);return i}(t,e.length-r),e,r,n)}function E(e,r,n){return 0===r&&n===e.length?t.fromByteArray(e):t.fromByteArray(e.slice(r,n))}function T(e,t,r){r=Math.min(e.length,r);const n=[];let o=t;for(;o239?4:t>223?3:t>191?2:1;if(o+s<=r){let r,n,a,c;switch(s){case 1:t<128&&(i=t);break;case 2:r=e[o+1],128==(192&r)&&(c=(31&t)<<6|63&r,c>127&&(i=c));break;case 3:r=e[o+1],n=e[o+2],128==(192&r)&&128==(192&n)&&(c=(15&t)<<12|(63&r)<<6|63&n,c>2047&&(c<55296||c>57343)&&(i=c));break;case 4:r=e[o+1],n=e[o+2],a=e[o+3],128==(192&r)&&128==(192&n)&&128==(192&a)&&(c=(15&t)<<18|(63&r)<<12|(63&n)<<6|63&a,c>65535&&c<1114112&&(i=c))}}null===i?(i=65533,s=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|1023&i),n.push(i),o+=s}return function(e){const t=e.length;if(t<=B)return String.fromCharCode.apply(String,e);let r="",n=0;for(;nn.length?(s.isBuffer(t)||(t=s.from(t)),t.copy(n,o)):Uint8Array.prototype.set.call(n,t,o);else{if(!s.isBuffer(t))throw new TypeError('"list" argument must be an Array of Buffers');t.copy(n,o)}o+=t.length}return n},s.byteLength=d,s.prototype._isBuffer=!0,s.prototype.swap16=function(){const e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let t=0;tr&&(t+=" ... "),""},n&&(s.prototype[n]=s.prototype.inspect),s.prototype.compare=function(e,t,r,n,o){if(G(e,Uint8Array)&&(e=s.from(e,e.offset,e.byteLength)),!s.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(void 0===t&&(t=0),void 0===r&&(r=e?e.length:0),void 0===n&&(n=0),void 0===o&&(o=this.length),t<0||r>e.length||n<0||o>this.length)throw new RangeError("out of range index");if(n>=o&&t>=r)return 0;if(n>=o)return-1;if(t>=r)return 1;if(this===e)return 0;let i=(o>>>=0)-(n>>>=0),a=(r>>>=0)-(t>>>=0);const c=Math.min(i,a),u=this.slice(n,o),l=e.slice(t,r);for(let s=0;s>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}const o=this.length-t;if((void 0===r||r>o)&&(r=o),e.length>0&&(r<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");let i=!1;for(;;)switch(n){case"hex":return b(this,e,t,r);case"utf8":case"utf-8":return w(this,e,t,r);case"ascii":case"latin1":case"binary":return _(this,e,t,r);case"base64":return v(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return $(this,e,t,r);default:if(i)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),i=!0}},s.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};const B=4096;function A(e,t,r){let n="";r=Math.min(e.length,r);for(let o=t;on)&&(r=n);let o="";for(let i=t;ir)throw new RangeError("Trying to access beyond buffer length")}function x(e,t,r,n,o,i){if(!s.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>o||te.length)throw new RangeError("Index out of range")}function O(e,t,r,n,o){F(t,n,o,e,r,7);let i=Number(t&BigInt(4294967295));e[r++]=i,i>>=8,e[r++]=i,i>>=8,e[r++]=i,i>>=8,e[r++]=i;let s=Number(t>>BigInt(32)&BigInt(4294967295));return e[r++]=s,s>>=8,e[r++]=s,s>>=8,e[r++]=s,s>>=8,e[r++]=s,r}function R(e,t,r,n,o){F(t,n,o,e,r,7);let i=Number(t&BigInt(4294967295));e[r+7]=i,i>>=8,e[r+6]=i,i>>=8,e[r+5]=i,i>>=8,e[r+4]=i;let s=Number(t>>BigInt(32)&BigInt(4294967295));return e[r+3]=s,s>>=8,e[r+2]=s,s>>=8,e[r+1]=s,s>>=8,e[r]=s,r+8}function D(e,t,r,n,o,i){if(r+n>e.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function U(e,t,n,o,i){return t=+t,n>>>=0,i||D(e,0,n,4),r.write(e,t,n,o,23,4),n+4}function N(e,t,n,o,i){return t=+t,n>>>=0,i||D(e,0,n,8),r.write(e,t,n,o,52,8),n+8}s.prototype.slice=function(e,t){const r=this.length;(e=~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),(t=void 0===t?r:~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),t>>=0,t>>>=0,r||C(e,t,this.length);let n=this[e],o=1,i=0;for(;++i>>=0,t>>>=0,r||C(e,t,this.length);let n=this[e+--t],o=1;for(;t>0&&(o*=256);)n+=this[e+--t]*o;return n},s.prototype.readUint8=s.prototype.readUInt8=function(e,t){return e>>>=0,t||C(e,1,this.length),this[e]},s.prototype.readUint16LE=s.prototype.readUInt16LE=function(e,t){return e>>>=0,t||C(e,2,this.length),this[e]|this[e+1]<<8},s.prototype.readUint16BE=s.prototype.readUInt16BE=function(e,t){return e>>>=0,t||C(e,2,this.length),this[e]<<8|this[e+1]},s.prototype.readUint32LE=s.prototype.readUInt32LE=function(e,t){return e>>>=0,t||C(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},s.prototype.readUint32BE=s.prototype.readUInt32BE=function(e,t){return e>>>=0,t||C(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},s.prototype.readBigUInt64LE=X((function(e){M(e>>>=0,"offset");const t=this[e],r=this[e+7];void 0!==t&&void 0!==r||z(e,this.length-8);const n=t+256*this[++e]+65536*this[++e]+this[++e]*2**24,o=this[++e]+256*this[++e]+65536*this[++e]+r*2**24;return BigInt(n)+(BigInt(o)<>>=0,"offset");const t=this[e],r=this[e+7];void 0!==t&&void 0!==r||z(e,this.length-8);const n=t*2**24+65536*this[++e]+256*this[++e]+this[++e],o=this[++e]*2**24+65536*this[++e]+256*this[++e]+r;return(BigInt(n)<>>=0,t>>>=0,r||C(e,t,this.length);let n=this[e],o=1,i=0;for(;++i=o&&(n-=Math.pow(2,8*t)),n},s.prototype.readIntBE=function(e,t,r){e>>>=0,t>>>=0,r||C(e,t,this.length);let n=t,o=1,i=this[e+--n];for(;n>0&&(o*=256);)i+=this[e+--n]*o;return o*=128,i>=o&&(i-=Math.pow(2,8*t)),i},s.prototype.readInt8=function(e,t){return e>>>=0,t||C(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},s.prototype.readInt16LE=function(e,t){e>>>=0,t||C(e,2,this.length);const r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},s.prototype.readInt16BE=function(e,t){e>>>=0,t||C(e,2,this.length);const r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},s.prototype.readInt32LE=function(e,t){return e>>>=0,t||C(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},s.prototype.readInt32BE=function(e,t){return e>>>=0,t||C(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},s.prototype.readBigInt64LE=X((function(e){M(e>>>=0,"offset");const t=this[e],r=this[e+7];void 0!==t&&void 0!==r||z(e,this.length-8);const n=this[e+4]+256*this[e+5]+65536*this[e+6]+(r<<24);return(BigInt(n)<>>=0,"offset");const t=this[e],r=this[e+7];void 0!==t&&void 0!==r||z(e,this.length-8);const n=(t<<24)+65536*this[++e]+256*this[++e]+this[++e];return(BigInt(n)<>>=0,t||C(e,4,this.length),r.read(this,e,!0,23,4)},s.prototype.readFloatBE=function(e,t){return e>>>=0,t||C(e,4,this.length),r.read(this,e,!1,23,4)},s.prototype.readDoubleLE=function(e,t){return e>>>=0,t||C(e,8,this.length),r.read(this,e,!0,52,8)},s.prototype.readDoubleBE=function(e,t){return e>>>=0,t||C(e,8,this.length),r.read(this,e,!1,52,8)},s.prototype.writeUintLE=s.prototype.writeUIntLE=function(e,t,r,n){if(e=+e,t>>>=0,r>>>=0,!n){x(this,e,t,r,Math.pow(2,8*r)-1,0)}let o=1,i=0;for(this[t]=255&e;++i>>=0,r>>>=0,!n){x(this,e,t,r,Math.pow(2,8*r)-1,0)}let o=r-1,i=1;for(this[t+o]=255&e;--o>=0&&(i*=256);)this[t+o]=e/i&255;return t+r},s.prototype.writeUint8=s.prototype.writeUInt8=function(e,t,r){return e=+e,t>>>=0,r||x(this,e,t,1,255,0),this[t]=255&e,t+1},s.prototype.writeUint16LE=s.prototype.writeUInt16LE=function(e,t,r){return e=+e,t>>>=0,r||x(this,e,t,2,65535,0),this[t]=255&e,this[t+1]=e>>>8,t+2},s.prototype.writeUint16BE=s.prototype.writeUInt16BE=function(e,t,r){return e=+e,t>>>=0,r||x(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=255&e,t+2},s.prototype.writeUint32LE=s.prototype.writeUInt32LE=function(e,t,r){return e=+e,t>>>=0,r||x(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e,t+4},s.prototype.writeUint32BE=s.prototype.writeUInt32BE=function(e,t,r){return e=+e,t>>>=0,r||x(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},s.prototype.writeBigUInt64LE=X((function(e,t=0){return O(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))})),s.prototype.writeBigUInt64BE=X((function(e,t=0){return R(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))})),s.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t>>>=0,!n){const n=Math.pow(2,8*r-1);x(this,e,t,r,n-1,-n)}let o=0,i=1,s=0;for(this[t]=255&e;++o>0)-s&255;return t+r},s.prototype.writeIntBE=function(e,t,r,n){if(e=+e,t>>>=0,!n){const n=Math.pow(2,8*r-1);x(this,e,t,r,n-1,-n)}let o=r-1,i=1,s=0;for(this[t+o]=255&e;--o>=0&&(i*=256);)e<0&&0===s&&0!==this[t+o+1]&&(s=1),this[t+o]=(e/i>>0)-s&255;return t+r},s.prototype.writeInt8=function(e,t,r){return e=+e,t>>>=0,r||x(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=255&e,t+1},s.prototype.writeInt16LE=function(e,t,r){return e=+e,t>>>=0,r||x(this,e,t,2,32767,-32768),this[t]=255&e,this[t+1]=e>>>8,t+2},s.prototype.writeInt16BE=function(e,t,r){return e=+e,t>>>=0,r||x(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=255&e,t+2},s.prototype.writeInt32LE=function(e,t,r){return e=+e,t>>>=0,r||x(this,e,t,4,2147483647,-2147483648),this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},s.prototype.writeInt32BE=function(e,t,r){return e=+e,t>>>=0,r||x(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},s.prototype.writeBigInt64LE=X((function(e,t=0){return O(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),s.prototype.writeBigInt64BE=X((function(e,t=0){return R(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),s.prototype.writeFloatLE=function(e,t,r){return U(this,e,t,!0,r)},s.prototype.writeFloatBE=function(e,t,r){return U(this,e,t,!1,r)},s.prototype.writeDoubleLE=function(e,t,r){return N(this,e,t,!0,r)},s.prototype.writeDoubleBE=function(e,t,r){return N(this,e,t,!1,r)},s.prototype.copy=function(e,t,r,n){if(!s.isBuffer(e))throw new TypeError("argument should be a Buffer");if(r||(r=0),n||0===n||(n=this.length),t>=e.length&&(t=e.length),t||(t=0),n>0&&n=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),e.length-t>>=0,r=void 0===r?this.length:r>>>0,e||(e=0),"number"==typeof e)for(o=t;o=n+4;r-=3)t=`_${e.slice(r-3,r)}${t}`;return`${e.slice(0,r)}${t}`}function F(e,t,r,n,o,i){if(e>r||e3?0===t||t===BigInt(0)?`>= 0${n} and < 2${n} ** ${8*(i+1)}${n}`:`>= -(2${n} ** ${8*(i+1)-1}${n}) and < 2 ** ${8*(i+1)-1}${n}`:`>= ${t}${n} and <= ${r}${n}`,new P.ERR_OUT_OF_RANGE("value",o,e)}!function(e,t,r){M(t,"offset"),void 0!==e[t]&&void 0!==e[t+r]||z(t,e.length-(r+1))}(n,o,i)}function M(e,t){if("number"!=typeof e)throw new P.ERR_INVALID_ARG_TYPE(t,"number",e)}function z(e,t,r){if(Math.floor(e)!==e)throw M(e,r),new P.ERR_OUT_OF_RANGE(r||"offset","an integer",e);if(t<0)throw new P.ERR_BUFFER_OUT_OF_BOUNDS;throw new P.ERR_OUT_OF_RANGE(r||"offset",`>= ${r?1:0} and <= ${t}`,e)}L("ERR_BUFFER_OUT_OF_BOUNDS",(function(e){return e?`${e} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"}),RangeError),L("ERR_INVALID_ARG_TYPE",(function(e,t){return`The "${e}" argument must be of type number. Received type ${typeof t}`}),TypeError),L("ERR_OUT_OF_RANGE",(function(e,t,r){let n=`The value of "${e}" is out of range.`,o=r;return Number.isInteger(r)&&Math.abs(r)>2**32?o=j(String(r)):"bigint"==typeof r&&(o=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(o=j(o)),o+="n"),n+=` It must be ${t}. Received ${o}`,n}),RangeError);const V=/[^+/0-9A-Za-z-_]/g;function H(e,t){let r;t=t||1/0;const n=e.length;let o=null;const i=[];for(let s=0;s55295&&r<57344){if(!o){if(r>56319){(t-=3)>-1&&i.push(239,191,189);continue}if(s+1===n){(t-=3)>-1&&i.push(239,191,189);continue}o=r;continue}if(r<56320){(t-=3)>-1&&i.push(239,191,189),o=r;continue}r=65536+(o-55296<<10|r-56320)}else o&&(t-=3)>-1&&i.push(239,191,189);if(o=null,r<128){if((t-=1)<0)break;i.push(r)}else if(r<2048){if((t-=2)<0)break;i.push(r>>6|192,63&r|128)}else if(r<65536){if((t-=3)<0)break;i.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;i.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return i}function W(e){return t.toByteArray(function(e){if((e=(e=e.split("=")[0]).trim().replace(V,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function q(e,t,r,n){let o;for(o=0;o=t.length||o>=e.length);++o)t[o+r]=e[o];return o}function G(e,t){return e instanceof t||null!=e&&null!=e.constructor&&null!=e.constructor.name&&e.constructor.name===t.name}function Y(e){return e!=e}const K=function(){const e="0123456789abcdef",t=new Array(256);for(let r=0;r<16;++r){const n=16*r;for(let o=0;o<16;++o)t[n+o]=e[r]+e[o]}return t}();function X(e){return"undefined"==typeof BigInt?Z:e}function Z(){throw new Error("BigInt not supported")}}(buffer);const{Buffer:Buffer}=buffer,symbol=Symbol.for("BufferList");function BufferList(e){if(!(this instanceof BufferList))return new BufferList(e);BufferList._init.call(this,e)}BufferList._init=function(e){Object.defineProperty(this,symbol,{value:!0}),this._bufs=[],this.length=0,e&&this.append(e)},BufferList.prototype._new=function(e){return new BufferList(e)},BufferList.prototype._offset=function(e){if(0===e)return[0,0];let t=0;for(let r=0;rthis.length||e<0)return;const t=this._offset(e);return this._bufs[t[0]][t[1]]},BufferList.prototype.slice=function(e,t){return"number"==typeof e&&e<0&&(e+=this.length),"number"==typeof t&&t<0&&(t+=this.length),this.copy(null,0,e,t)},BufferList.prototype.copy=function(e,t,r,n){if(("number"!=typeof r||r<0)&&(r=0),("number"!=typeof n||n>this.length)&&(n=this.length),r>=this.length)return e||Buffer.alloc(0);if(n<=0)return e||Buffer.alloc(0);const o=!!e,i=this._offset(r),s=n-r;let a=s,c=o&&t||0,u=i[1];if(0===r&&n===this.length){if(!o)return 1===this._bufs.length?this._bufs[0]:Buffer.concat(this._bufs,this.length);for(let t=0;tt)){this._bufs[l].copy(e,c,u,u+a),c+=t;break}this._bufs[l].copy(e,c,u),c+=t,a-=t,u&&(u=0)}return e.length>c?e.slice(0,c):e},BufferList.prototype.shallowSlice=function(e,t){if(e=e||0,t="number"!=typeof t?this.length:t,e<0&&(e+=this.length),t<0&&(t+=this.length),e===t)return this._new();const r=this._offset(e),n=this._offset(t),o=this._bufs.slice(r[0],n[0]+1);return 0===n[1]?o.pop():o[o.length-1]=o[o.length-1].slice(0,n[1]),0!==r[1]&&(o[0]=o[0].slice(r[1])),this._new(o)},BufferList.prototype.toString=function(e,t,r){return this.slice(t,r).toString(e)},BufferList.prototype.consume=function(e){if(e=Math.trunc(e),Number.isNaN(e)||e<=0)return this;for(;this._bufs.length;){if(!(e>=this._bufs[0].length)){this._bufs[0]=this._bufs[0].slice(e),this.length-=e;break}e-=this._bufs[0].length,this.length-=this._bufs[0].length,this._bufs.shift()}return this},BufferList.prototype.duplicate=function(){const e=this._new();for(let t=0;tthis.length?this.length:t;const n=this._offset(t);let o=n[0],i=n[1];for(;o=e.length){const r=t.indexOf(e,i);if(-1!==r)return this._reverseOffset([o,r]);i=t.length-e.length+1}else{const t=this._reverseOffset([o,i]);if(this._match(t,e))return t;i++}}i=0}return-1},BufferList.prototype._match=function(e,t){if(this.length-e=0?u.subarray(0,l):u}}var rabin$1=Rabin$1,loader={};const ID_OFFSET=-8,SIZE_OFFSET=-4,ARRAYBUFFER_ID=0,STRING_ID=1,ARRAYBUFFERVIEW=1,ARRAY=2,VAL_ALIGN_OFFSET=5,VAL_SIGNED=1024,VAL_FLOAT=2048,VAL_MANAGED=8192,ARRAYBUFFERVIEW_BUFFER_OFFSET=0,ARRAYBUFFERVIEW_DATASTART_OFFSET=4,ARRAYBUFFERVIEW_DATALENGTH_OFFSET=8,ARRAYBUFFERVIEW_SIZE=12,ARRAY_LENGTH_OFFSET=12,ARRAY_SIZE=16,BIGINT="undefined"!=typeof BigUint64Array,THIS=Symbol(),CHUNKSIZE=1024;function getStringImpl(e,t){const r=new Uint32Array(e),n=new Uint16Array(e);var o=r[t+SIZE_OFFSET>>>2]>>>1,i=t>>>1;if(o<=CHUNKSIZE)return String.fromCharCode.apply(String,n.subarray(i,i+o));const s=[];do{const e=n[i+CHUNKSIZE-1],t=e>=55296&&e<56320?CHUNKSIZE-1:CHUNKSIZE;s.push(String.fromCharCode.apply(String,n.subarray(i,i+=t))),o-=t}while(o>CHUNKSIZE);return s.join("")+String.fromCharCode.apply(String,n.subarray(i,i+o))}function preInstantiate(e){const t={};function r(e,t){return e?getStringImpl(e.buffer,t):""}const n=e.env=e.env||{};return n.abort=n.abort||function(e,o,i,s){const a=t.memory||n.memory;throw Error("abort: "+r(a,e)+" at "+r(a,o)+":"+i+":"+s)},n.trace=n.trace||function(e,o){const i=t.memory||n.memory;console.log("trace: "+r(i,e)+(o?" ":"")+Array.prototype.slice.call(arguments,2,2+o).join(", "))},e.Math=e.Math||Math,e.Date=e.Date||Date,t}function postInstantiate(e,t){const r=t.exports,n=r.memory,o=r.table,i=r.__alloc,s=r.__retain,a=r.__rtti_base||-1;function c(e){const t=new Uint32Array(n.buffer);if((e>>>=0)>=t[a>>>2])throw Error("invalid id: "+e);return t[(a+4>>>2)+2*e]}function u(e){const t=new Uint32Array(n.buffer);if((e>>>=0)>=t[a>>>2])throw Error("invalid id: "+e);return t[(a+4>>>2)+2*e+1]}function l(e){return 31-Math.clz32(e>>>VAL_ALIGN_OFFSET&31)}function f(e,t,r){const o=n.buffer;if(r)switch(e){case 2:return new Float32Array(o);case 3:return new Float64Array(o)}else switch(e){case 0:return new(t?Int8Array:Uint8Array)(o);case 1:return new(t?Int16Array:Uint16Array)(o);case 2:return new(t?Int32Array:Uint32Array)(o);case 3:return new(t?BigInt64Array:BigUint64Array)(o)}throw Error("unsupported align: "+e)}function h(e){const t=new Uint32Array(n.buffer),r=t[e+ID_OFFSET>>>2],o=c(r);if(!(o&ARRAYBUFFERVIEW))throw Error("not an array: "+r);const i=l(o);var s=t[e+ARRAYBUFFERVIEW_DATASTART_OFFSET>>>2];const a=o&ARRAY?t[e+ARRAY_LENGTH_OFFSET>>>2]:t[s+SIZE_OFFSET>>>2]>>>i;return f(i,o&VAL_SIGNED,o&VAL_FLOAT).subarray(s>>>=i,s+a)}function d(e,t,r){return new e(p(e,t,r))}function p(e,t,r){const o=n.buffer,i=new Uint32Array(o),s=i[r+ARRAYBUFFERVIEW_DATASTART_OFFSET>>>2];return new e(o,s,i[s+SIZE_OFFSET>>>2]>>>t)}return e.__allocString=function(e){const t=e.length,r=i(t<<1,STRING_ID),o=new Uint16Array(n.buffer);for(var s=0,a=r>>>1;s>>2]!==STRING_ID)throw Error("not a string: "+e);return getStringImpl(t,e)},e.__allocArray=function(e,t){const r=c(e);if(!(r&(ARRAYBUFFERVIEW|ARRAY)))throw Error("not an array: "+e+" @ "+r);const o=l(r),a=t.length,u=i(a<>>2]=s(u),d[h+ARRAYBUFFERVIEW_DATASTART_OFFSET>>>2]=u,d[h+ARRAYBUFFERVIEW_DATALENGTH_OFFSET>>>2]=a<>>2]=a);const p=f(o,r&VAL_SIGNED,r&VAL_FLOAT);if(r&VAL_MANAGED)for(let n=0;n>>o)+n]=s(t[n]);else p.set(t,u>>>o);return h},e.__getArrayView=h,e.__getArray=function(e){const t=h(e),r=t.length,n=new Array(r);for(let o=0;o>>2];return t.slice(e,e+r)},e.__getInt8Array=d.bind(null,Int8Array,0),e.__getInt8ArrayView=p.bind(null,Int8Array,0),e.__getUint8Array=d.bind(null,Uint8Array,0),e.__getUint8ArrayView=p.bind(null,Uint8Array,0),e.__getUint8ClampedArray=d.bind(null,Uint8ClampedArray,0),e.__getUint8ClampedArrayView=p.bind(null,Uint8ClampedArray,0),e.__getInt16Array=d.bind(null,Int16Array,1),e.__getInt16ArrayView=p.bind(null,Int16Array,1),e.__getUint16Array=d.bind(null,Uint16Array,1),e.__getUint16ArrayView=p.bind(null,Uint16Array,1),e.__getInt32Array=d.bind(null,Int32Array,2),e.__getInt32ArrayView=p.bind(null,Int32Array,2),e.__getUint32Array=d.bind(null,Uint32Array,2),e.__getUint32ArrayView=p.bind(null,Uint32Array,2),BIGINT&&(e.__getInt64Array=d.bind(null,BigInt64Array,3),e.__getInt64ArrayView=p.bind(null,BigInt64Array,3),e.__getUint64Array=d.bind(null,BigUint64Array,3),e.__getUint64ArrayView=p.bind(null,BigUint64Array,3)),e.__getFloat32Array=d.bind(null,Float32Array,2),e.__getFloat32ArrayView=p.bind(null,Float32Array,2),e.__getFloat64Array=d.bind(null,Float64Array,3),e.__getFloat64ArrayView=p.bind(null,Float64Array,3),e.__instanceof=function(e,t){const r=new Uint32Array(n.buffer);var o=r[e+ID_OFFSET>>>2];if(o<=r[a>>>2])do{if(o==t)return!0}while(o=u(o));return!1},e.memory=e.memory||n,e.table=e.table||o,demangle(r,e)}function isResponse(e){return"undefined"!=typeof Response&&e instanceof Response}async function instantiate$1(e,t){return isResponse(e=await e)?instantiateStreaming(e,t):postInstantiate(preInstantiate(t||(t={})),await WebAssembly.instantiate(e instanceof WebAssembly.Module?e:await WebAssembly.compile(e),t))}function instantiateSync(e,t){return postInstantiate(preInstantiate(t||(t={})),new WebAssembly.Instance(e instanceof WebAssembly.Module?e:new WebAssembly.Module(e),t))}async function instantiateStreaming(e,t){return WebAssembly.instantiateStreaming?postInstantiate(preInstantiate(t||(t={})),(await WebAssembly.instantiateStreaming(e,t)).instance):instantiate$1(isResponse(e=await e)?e.arrayBuffer():e,t)}function demangle(e,t){var r=t?Object.create(t):{},n=e.__argumentsLength?function(t){e.__argumentsLength.value=t}:e.__setArgumentsLength||e.__setargc||function(){};for(let o in e){if(!Object.prototype.hasOwnProperty.call(e,o))continue;const t=e[o];let i=o.split("."),s=r;for(;i.length>1;){let e=i.shift();Object.prototype.hasOwnProperty.call(s,e)||(s[e]={}),s=s[e]}let a=i[0],c=a.indexOf("#");if(c>=0){let r=a.substring(0,c),i=s[r];if(void 0===i||!i.prototype){let e=function(...t){return e.wrap(e.prototype.constructor(0,...t))};e.prototype={valueOf:function(){return this[THIS]}},e.wrap=function(t){return Object.create(e.prototype,{[THIS]:{value:t,writable:!1}})},i&&Object.getOwnPropertyNames(i).forEach((t=>Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t)))),s[r]=e}if(a=a.substring(c+1),s=s[r].prototype,/^(get|set):/.test(a)){if(!Object.prototype.hasOwnProperty.call(s,a=a.substring(4))){let t=e[o.replace("set:","get:")],r=e[o.replace("get:","set:")];Object.defineProperty(s,a,{get:function(){return t(this[THIS])},set:function(e){r(this[THIS],e)},enumerable:!0})}}else"constructor"===a?(s[a]=(...e)=>(n(e.length),t(...e))).original=t:(s[a]=function(...e){return n(e.length),t(this[THIS],...e)}).original=t}else/^(get|set):/.test(a)?Object.prototype.hasOwnProperty.call(s,a=a.substring(4))||Object.defineProperty(s,a,{get:e[o.replace("set:","get:")],set:e[o.replace("get:","set:")],enumerable:!0}):"function"==typeof t&&t!==n?(s[a]=(...e)=>(n(e.length),t(...e))).original=t:s[a]=t}return r}loader.instantiate=instantiate$1,loader.instantiateSync=instantiateSync,loader.instantiateStreaming=instantiateStreaming,loader.demangle=demangle;const{instantiate:instantiate}=loader;function loadWebAssembly(e={}){if(!loadWebAssembly.supported)return null;var t=new Uint8Array([0,97,115,109,1,0,0,0,1,78,14,96,2,127,126,0,96,1,127,1,126,96,2,127,127,0,96,1,127,1,127,96,1,127,0,96,2,127,127,1,127,96,3,127,127,127,1,127,96,0,0,96,3,127,127,127,0,96,0,1,127,96,4,127,127,127,127,0,96,5,127,127,127,127,127,1,127,96,1,126,1,127,96,2,126,126,1,126,2,13,1,3,101,110,118,5,97,98,111,114,116,0,10,3,54,53,2,2,8,9,3,5,2,8,6,5,3,4,2,6,9,12,13,2,5,11,3,2,3,2,3,2,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,6,7,7,4,4,5,3,1,0,1,6,47,9,127,1,65,0,11,127,1,65,0,11,127,0,65,3,11,127,0,65,4,11,127,1,65,0,11,127,1,65,0,11,127,1,65,0,11,127,0,65,240,2,11,127,0,65,6,11,7,240,5,41,6,109,101,109,111,114,121,2,0,7,95,95,97,108,108,111,99,0,10,8,95,95,114,101,116,97,105,110,0,11,9,95,95,114,101,108,101,97,115,101,0,12,9,95,95,99,111,108,108,101,99,116,0,51,11,95,95,114,116,116,105,95,98,97,115,101,3,7,13,73,110,116,51,50,65,114,114,97,121,95,73,68,3,2,13,85,105,110,116,56,65,114,114,97,121,95,73,68,3,3,6,100,101,103,114,101,101,0,16,3,109,111,100,0,17,5,82,97,98,105,110,3,8,16,82,97,98,105,110,35,103,101,116,58,119,105,110,100,111,119,0,21,16,82,97,98,105,110,35,115,101,116,58,119,105,110,100,111,119,0,22,21,82,97,98,105,110,35,103,101,116,58,119,105,110,100,111,119,95,115,105,122,101,0,23,21,82,97,98,105,110,35,115,101,116,58,119,105,110,100,111,119,95,115,105,122,101,0,24,14,82,97,98,105,110,35,103,101,116,58,119,112,111,115,0,25,14,82,97,98,105,110,35,115,101,116,58,119,112,111,115,0,26,15,82,97,98,105,110,35,103,101,116,58,99,111,117,110,116,0,27,15,82,97,98,105,110,35,115,101,116,58,99,111,117,110,116,0,28,13,82,97,98,105,110,35,103,101,116,58,112,111,115,0,29,13,82,97,98,105,110,35,115,101,116,58,112,111,115,0,30,15,82,97,98,105,110,35,103,101,116,58,115,116,97,114,116,0,31,15,82,97,98,105,110,35,115,101,116,58,115,116,97,114,116,0,32,16,82,97,98,105,110,35,103,101,116,58,100,105,103,101,115,116,0,33,16,82,97,98,105,110,35,115,101,116,58,100,105,103,101,115,116,0,34,21,82,97,98,105,110,35,103,101,116,58,99,104,117,110,107,95,115,116,97,114,116,0,35,21,82,97,98,105,110,35,115,101,116,58,99,104,117,110,107,95,115,116,97,114,116,0,36,22,82,97,98,105,110,35,103,101,116,58,99,104,117,110,107,95,108,101,110,103,116,104,0,37,22,82,97,98,105,110,35,115,101,116,58,99,104,117,110,107,95,108,101,110,103,116,104,0,38,31,82,97,98,105,110,35,103,101,116,58,99,104,117,110,107,95,99,117,116,95,102,105,110,103,101,114,112,114,105,110,116,0,39,31,82,97,98,105,110,35,115,101,116,58,99,104,117,110,107,95,99,117,116,95,102,105,110,103,101,114,112,114,105,110,116,0,40,20,82,97,98,105,110,35,103,101,116,58,112,111,108,121,110,111,109,105,97,108,0,41,20,82,97,98,105,110,35,115,101,116,58,112,111,108,121,110,111,109,105,97,108,0,42,17,82,97,98,105,110,35,103,101,116,58,109,105,110,115,105,122,101,0,43,17,82,97,98,105,110,35,115,101,116,58,109,105,110,115,105,122,101,0,44,17,82,97,98,105,110,35,103,101,116,58,109,97,120,115,105,122,101,0,45,17,82,97,98,105,110,35,115,101,116,58,109,97,120,115,105,122,101,0,46,14,82,97,98,105,110,35,103,101,116,58,109,97,115,107,0,47,14,82,97,98,105,110,35,115,101,116,58,109,97,115,107,0,48,17,82,97,98,105,110,35,99,111,110,115,116,114,117,99,116,111,114,0,20,17,82,97,98,105,110,35,102,105,110,103,101,114,112,114,105,110,116,0,49,8,1,50,10,165,31,53,199,1,1,4,127,32,1,40,2,0,65,124,113,34,2,65,128,2,73,4,127,32,2,65,4,118,33,4,65,0,5,32,2,65,31,32,2,103,107,34,3,65,4,107,118,65,16,115,33,4,32,3,65,7,107,11,33,3,32,1,40,2,20,33,2,32,1,40,2,16,34,5,4,64,32,5,32,2,54,2,20,11,32,2,4,64,32,2,32,5,54,2,16,11,32,1,32,0,32,4,32,3,65,4,116,106,65,2,116,106,40,2,96,70,4,64,32,0,32,4,32,3,65,4,116,106,65,2,116,106,32,2,54,2,96,32,2,69,4,64,32,0,32,3,65,2,116,106,32,0,32,3,65,2,116,106,40,2,4,65,1,32,4,116,65,127,115,113,34,1,54,2,4,32,1,69,4,64,32,0,32,0,40,2,0,65,1,32,3,116,65,127,115,113,54,2,0,11,11,11,11,226,2,1,6,127,32,1,40,2,0,33,3,32,1,65,16,106,32,1,40,2,0,65,124,113,106,34,4,40,2,0,34,5,65,1,113,4,64,32,3,65,124,113,65,16,106,32,5,65,124,113,106,34,2,65,240,255,255,255,3,73,4,64,32,0,32,4,16,1,32,1,32,2,32,3,65,3,113,114,34,3,54,2,0,32,1,65,16,106,32,1,40,2,0,65,124,113,106,34,4,40,2,0,33,5,11,11,32,3,65,2,113,4,64,32,1,65,4,107,40,2,0,34,2,40,2,0,34,6,65,124,113,65,16,106,32,3,65,124,113,106,34,7,65,240,255,255,255,3,73,4,64,32,0,32,2,16,1,32,2,32,7,32,6,65,3,113,114,34,3,54,2,0,32,2,33,1,11,11,32,4,32,5,65,2,114,54,2,0,32,4,65,4,107,32,1,54,2,0,32,0,32,3,65,124,113,34,2,65,128,2,73,4,127,32,2,65,4,118,33,4,65,0,5,32,2,65,31,32,2,103,107,34,2,65,4,107,118,65,16,115,33,4,32,2,65,7,107,11,34,3,65,4,116,32,4,106,65,2,116,106,40,2,96,33,2,32,1,65,0,54,2,16,32,1,32,2,54,2,20,32,2,4,64,32,2,32,1,54,2,16,11,32,0,32,4,32,3,65,4,116,106,65,2,116,106,32,1,54,2,96,32,0,32,0,40,2,0,65,1,32,3,116,114,54,2,0,32,0,32,3,65,2,116,106,32,0,32,3,65,2,116,106,40,2,4,65,1,32,4,116,114,54,2,4,11,119,1,1,127,32,2,2,127,32,0,40,2,160,12,34,2,4,64,32,2,32,1,65,16,107,70,4,64,32,2,40,2,0,33,3,32,1,65,16,107,33,1,11,11,32,1,11,107,34,2,65,48,73,4,64,15,11,32,1,32,3,65,2,113,32,2,65,32,107,65,1,114,114,54,2,0,32,1,65,0,54,2,16,32,1,65,0,54,2,20,32,1,32,2,106,65,16,107,34,2,65,2,54,2,0,32,0,32,2,54,2,160,12,32,0,32,1,16,2,11,155,1,1,3,127,35,0,34,0,69,4,64,65,1,63,0,34,0,74,4,127,65,1,32,0,107,64,0,65,0,72,5,65,0,11,4,64,0,11,65,176,3,34,0,65,0,54,2,0,65,208,15,65,0,54,2,0,3,64,32,1,65,23,73,4,64,32,1,65,2,116,65,176,3,106,65,0,54,2,4,65,0,33,2,3,64,32,2,65,16,73,4,64,32,1,65,4,116,32,2,106,65,2,116,65,176,3,106,65,0,54,2,96,32,2,65,1,106,33,2,12,1,11,11,32,1,65,1,106,33,1,12,1,11,11,65,176,3,65,224,15,63,0,65,16,116,16,3,65,176,3,36,0,11,32,0,11,45,0,32,0,65,240,255,255,255,3,79,4,64,65,32,65,224,0,65,201,3,65,29,16,0,0,11,32,0,65,15,106,65,112,113,34,0,65,16,32,0,65,16,75,27,11,169,1,1,1,127,32,0,32,1,65,128,2,73,4,127,32,1,65,4,118,33,1,65,0,5,32,1,65,248,255,255,255,1,73,4,64,32,1,65,1,65,27,32,1,103,107,116,106,65,1,107,33,1,11,32,1,65,31,32,1,103,107,34,2,65,4,107,118,65,16,115,33,1,32,2,65,7,107,11,34,2,65,2,116,106,40,2,4,65,127,32,1,116,113,34,1,4,127,32,0,32,1,104,32,2,65,4,116,106,65,2,116,106,40,2,96,5,32,0,40,2,0,65,127,32,2,65,1,106,116,113,34,1,4,127,32,0,32,0,32,1,104,34,0,65,2,116,106,40,2,4,104,32,0,65,4,116,106,65,2,116,106,40,2,96,5,65,0,11,11,11,111,1,1,127,63,0,34,2,32,1,65,248,255,255,255,1,73,4,127,32,1,65,1,65,27,32,1,103,107,116,65,1,107,106,5,32,1,11,65,16,32,0,40,2,160,12,32,2,65,16,116,65,16,107,71,116,106,65,255,255,3,106,65,128,128,124,113,65,16,118,34,1,32,2,32,1,74,27,64,0,65,0,72,4,64,32,1,64,0,65,0,72,4,64,0,11,11,32,0,32,2,65,16,116,63,0,65,16,116,16,3,11,113,1,2,127,32,1,40,2,0,34,3,65,124,113,32,2,107,34,4,65,32,79,4,64,32,1,32,2,32,3,65,2,113,114,54,2,0,32,2,32,1,65,16,106,106,34,1,32,4,65,16,107,65,1,114,54,2,0,32,0,32,1,16,2,5,32,1,32,3,65,126,113,54,2,0,32,1,65,16,106,32,1,40,2,0,65,124,113,106,32,1,65,16,106,32,1,40,2,0,65,124,113,106,40,2,0,65,125,113,54,2,0,11,11,91,1,2,127,32,0,32,1,16,5,34,4,16,6,34,3,69,4,64,65,1,36,1,65,0,36,1,32,0,32,4,16,6,34,3,69,4,64,32,0,32,4,16,7,32,0,32,4,16,6,33,3,11,11,32,3,65,0,54,2,4,32,3,32,2,54,2,8,32,3,32,1,54,2,12,32,0,32,3,16,1,32,0,32,3,32,4,16,8,32,3,11,13,0,16,4,32,0,32,1,16,9,65,16,106,11,33,1,1,127,32,0,65,172,3,75,4,64,32,0,65,16,107,34,1,32,1,40,2,4,65,1,106,54,2,4,11,32,0,11,18,0,32,0,65,172,3,75,4,64,32,0,65,16,107,16,52,11,11,140,3,1,1,127,2,64,32,1,69,13,0,32,0,65,0,58,0,0,32,0,32,1,106,65,1,107,65,0,58,0,0,32,1,65,2,77,13,0,32,0,65,1,106,65,0,58,0,0,32,0,65,2,106,65,0,58,0,0,32,0,32,1,106,34,2,65,2,107,65,0,58,0,0,32,2,65,3,107,65,0,58,0,0,32,1,65,6,77,13,0,32,0,65,3,106,65,0,58,0,0,32,0,32,1,106,65,4,107,65,0,58,0,0,32,1,65,8,77,13,0,32,1,65,0,32,0,107,65,3,113,34,1,107,33,2,32,0,32,1,106,34,0,65,0,54,2,0,32,0,32,2,65,124,113,34,1,106,65,4,107,65,0,54,2,0,32,1,65,8,77,13,0,32,0,65,4,106,65,0,54,2,0,32,0,65,8,106,65,0,54,2,0,32,0,32,1,106,34,2,65,12,107,65,0,54,2,0,32,2,65,8,107,65,0,54,2,0,32,1,65,24,77,13,0,32,0,65,12,106,65,0,54,2,0,32,0,65,16,106,65,0,54,2,0,32,0,65,20,106,65,0,54,2,0,32,0,65,24,106,65,0,54,2,0,32,0,32,1,106,34,2,65,28,107,65,0,54,2,0,32,2,65,24,107,65,0,54,2,0,32,2,65,20,107,65,0,54,2,0,32,2,65,16,107,65,0,54,2,0,32,0,32,0,65,4,113,65,24,106,34,2,106,33,0,32,1,32,2,107,33,1,3,64,32,1,65,32,79,4,64,32,0,66,0,55,3,0,32,0,65,8,106,66,0,55,3,0,32,0,65,16,106,66,0,55,3,0,32,0,65,24,106,66,0,55,3,0,32,1,65,32,107,33,1,32,0,65,32,106,33,0,12,1,11,11,11,11,178,1,1,3,127,32,1,65,240,255,255,255,3,32,2,118,75,4,64,65,144,1,65,192,1,65,23,65,56,16,0,0,11,32,1,32,2,116,34,3,65,0,16,10,34,2,32,3,16,13,32,0,69,4,64,65,12,65,2,16,10,34,0,65,172,3,75,4,64,32,0,65,16,107,34,1,32,1,40,2,4,65,1,106,54,2,4,11,11,32,0,65,0,54,2,0,32,0,65,0,54,2,4,32,0,65,0,54,2,8,32,2,34,1,32,0,40,2,0,34,4,71,4,64,32,1,65,172,3,75,4,64,32,1,65,16,107,34,5,32,5,40,2,4,65,1,106,54,2,4,11,32,4,16,12,11,32,0,32,1,54,2,0,32,0,32,2,54,2,4,32,0,32,3,54,2,8,32,0,11,46,1,2,127,65,12,65,5,16,10,34,0,65,172,3,75,4,64,32,0,65,16,107,34,1,32,1,40,2,4,65,1,106,54,2,4,11,32,0,65,128,2,65,3,16,14,11,9,0,65,63,32,0,121,167,107,11,49,1,2,127,65,63,32,1,121,167,107,33,2,3,64,65,63,32,0,121,167,107,32,2,107,34,3,65,0,78,4,64,32,0,32,1,32,3,172,134,133,33,0,12,1,11,11,32,0,11,40,0,32,1,32,0,40,2,8,79,4,64,65,128,2,65,192,2,65,163,1,65,44,16,0,0,11,32,1,32,0,40,2,4,106,65,0,58,0,0,11,38,0,32,1,32,0,40,2,8,79,4,64,65,128,2,65,192,2,65,152,1,65,44,16,0,0,11,32,1,32,0,40,2,4,106,45,0,0,11,254,5,2,1,127,4,126,32,0,69,4,64,65,232,0,65,6,16,10,34,0,65,172,3,75,4,64,32,0,65,16,107,34,5,32,5,40,2,4,65,1,106,54,2,4,11,11,32,0,65,0,54,2,0,32,0,65,0,54,2,4,32,0,65,0,54,2,8,32,0,66,0,55,3,16,32,0,66,0,55,3,24,32,0,66,0,55,3,32,32,0,66,0,55,3,40,32,0,66,0,55,3,48,32,0,66,0,55,3,56,32,0,66,0,55,3,64,32,0,66,0,55,3,72,32,0,66,0,55,3,80,32,0,66,0,55,3,88,32,0,66,0,55,3,96,32,0,32,2,173,55,3,80,32,0,32,3,173,55,3,88,65,12,65,4,16,10,34,2,65,172,3,75,4,64,32,2,65,16,107,34,3,32,3,40,2,4,65,1,106,54,2,4,11,32,2,32,4,65,0,16,14,33,2,32,0,40,2,0,16,12,32,0,32,2,54,2,0,32,0,32,4,54,2,4,32,0,66,1,32,1,173,134,66,1,125,55,3,96,32,0,66,243,130,183,218,216,230,232,30,55,3,72,35,4,69,4,64,65,0,33,2,3,64,32,2,65,128,2,72,4,64,32,2,65,255,1,113,173,33,6,32,0,41,3,72,34,7,33,8,65,63,32,7,121,167,107,33,1,3,64,65,63,32,6,121,167,107,32,1,107,34,3,65,0,78,4,64,32,6,32,8,32,3,172,134,133,33,6,12,1,11,11,65,0,33,4,3,64,32,4,32,0,40,2,4,65,1,107,72,4,64,32,6,66,8,134,33,6,32,0,41,3,72,34,7,33,8,65,63,32,7,121,167,107,33,1,3,64,65,63,32,6,121,167,107,32,1,107,34,3,65,0,78,4,64,32,6,32,8,32,3,172,134,133,33,6,12,1,11,11,32,4,65,1,106,33,4,12,1,11,11,35,6,40,2,4,32,2,65,3,116,106,32,6,55,3,0,32,2,65,1,106,33,2,12,1,11,11,65,63,32,0,41,3,72,121,167,107,172,33,7,65,0,33,2,3,64,32,2,65,128,2,72,4,64,35,5,33,1,32,2,172,32,7,134,34,8,33,6,65,63,32,0,41,3,72,34,9,121,167,107,33,3,3,64,65,63,32,6,121,167,107,32,3,107,34,4,65,0,78,4,64,32,6,32,9,32,4,172,134,133,33,6,12,1,11,11,32,1,40,2,4,32,2,65,3,116,106,32,6,32,8,132,55,3,0,32,2,65,1,106,33,2,12,1,11,11,65,1,36,4,11,32,0,66,0,55,3,24,32,0,66,0,55,3,32,65,0,33,2,3,64,32,2,32,0,40,2,4,72,4,64,32,0,40,2,0,32,2,16,18,32,2,65,1,106,33,2,12,1,11,11,32,0,66,0,55,3,40,32,0,65,0,54,2,8,32,0,66,0,55,3,16,32,0,66,0,55,3,40,32,0,40,2,0,32,0,40,2,8,16,19,33,1,32,0,40,2,8,32,0,40,2,0,40,2,4,106,65,1,58,0,0,32,0,32,0,41,3,40,35,6,40,2,4,32,1,65,3,116,106,41,3,0,133,55,3,40,32,0,32,0,40,2,8,65,1,106,32,0,40,2,4,111,54,2,8,32,0,35,5,40,2,4,32,0,41,3,40,34,6,66,45,136,167,65,3,116,106,41,3,0,32,6,66,8,134,66,1,132,133,55,3,40,32,0,11,38,1,1,127,32,0,40,2,0,34,0,65,172,3,75,4,64,32,0,65,16,107,34,1,32,1,40,2,4,65,1,106,54,2,4,11,32,0,11,55,1,2,127,32,1,32,0,40,2,0,34,2,71,4,64,32,1,65,172,3,75,4,64,32,1,65,16,107,34,3,32,3,40,2,4,65,1,106,54,2,4,11,32,2,16,12,11,32,0,32,1,54,2,0,11,7,0,32,0,40,2,4,11,9,0,32,0,32,1,54,2,4,11,7,0,32,0,40,2,8,11,9,0,32,0,32,1,54,2,8,11,7,0,32,0,41,3,16,11,9,0,32,0,32,1,55,3,16,11,7,0,32,0,41,3,24,11,9,0,32,0,32,1,55,3,24,11,7,0,32,0,41,3,32,11,9,0,32,0,32,1,55,3,32,11,7,0,32,0,41,3,40,11,9,0,32,0,32,1,55,3,40,11,7,0,32,0,41,3,48,11,9,0,32,0,32,1,55,3,48,11,7,0,32,0,41,3,56,11,9,0,32,0,32,1,55,3,56,11,7,0,32,0,41,3,64,11,9,0,32,0,32,1,55,3,64,11,7,0,32,0,41,3,72,11,9,0,32,0,32,1,55,3,72,11,7,0,32,0,41,3,80,11,9,0,32,0,32,1,55,3,80,11,7,0,32,0,41,3,88,11,9,0,32,0,32,1,55,3,88,11,7,0,32,0,41,3,96,11,9,0,32,0,32,1,55,3,96,11,172,4,2,5,127,1,126,32,2,65,172,3,75,4,64,32,2,65,16,107,34,4,32,4,40,2,4,65,1,106,54,2,4,11,32,2,33,4,65,0,33,2,32,1,40,2,8,33,5,32,1,40,2,4,33,6,3,64,2,127,65,0,33,3,3,64,32,3,32,5,72,4,64,32,3,32,6,106,45,0,0,33,1,32,0,40,2,0,32,0,40,2,8,16,19,33,7,32,0,40,2,8,32,0,40,2,0,40,2,4,106,32,1,58,0,0,32,0,32,0,41,3,40,35,6,40,2,4,32,7,65,3,116,106,41,3,0,133,55,3,40,32,0,32,0,40,2,8,65,1,106,32,0,40,2,4,111,54,2,8,32,0,35,5,40,2,4,32,0,41,3,40,34,8,66,45,136,167,65,3,116,106,41,3,0,32,1,173,32,8,66,8,134,132,133,55,3,40,32,0,32,0,41,3,16,66,1,124,55,3,16,32,0,32,0,41,3,24,66,1,124,55,3,24,32,0,41,3,16,32,0,41,3,80,90,4,127,32,0,41,3,40,32,0,41,3,96,131,80,5,65,0,11,4,127,65,1,5,32,0,41,3,16,32,0,41,3,88,90,11,4,64,32,0,32,0,41,3,32,55,3,48,32,0,32,0,41,3,16,55,3,56,32,0,32,0,41,3,40,55,3,64,65,0,33,1,3,64,32,1,32,0,40,2,4,72,4,64,32,0,40,2,0,32,1,16,18,32,1,65,1,106,33,1,12,1,11,11,32,0,66,0,55,3,40,32,0,65,0,54,2,8,32,0,66,0,55,3,16,32,0,66,0,55,3,40,32,0,40,2,0,32,0,40,2,8,16,19,33,1,32,0,40,2,8,32,0,40,2,0,40,2,4,106,65,1,58,0,0,32,0,32,0,41,3,40,35,6,40,2,4,32,1,65,3,116,106,41,3,0,133,55,3,40,32,0,32,0,40,2,8,65,1,106,32,0,40,2,4,111,54,2,8,32,0,35,5,40,2,4,32,0,41,3,40,34,8,66,45,136,167,65,3,116,106,41,3,0,32,8,66,8,134,66,1,132,133,55,3,40,32,3,65,1,106,12,3,11,32,3,65,1,106,33,3,12,1,11,11,65,127,11,34,1,65,0,78,4,64,32,5,32,1,107,33,5,32,1,32,6,106,33,6,32,2,34,1,65,1,106,33,2,32,4,40,2,4,32,1,65,2,116,106,32,0,41,3,56,62,2,0,12,1,11,11,32,4,11,10,0,16,15,36,5,16,15,36,6,11,3,0,1,11,73,1,2,127,32,0,40,2,4,34,1,65,255,255,255,255,0,113,34,2,65,1,70,4,64,32,0,65,16,106,16,53,32,0,32,0,40,2,0,65,1,114,54,2,0,35,0,32,0,16,2,5,32,0,32,2,65,1,107,32,1,65,128,128,128,128,127,113,114,54,2,4,11,11,58,0,2,64,2,64,2,64,32,0,65,8,107,40,2,0,14,7,0,0,1,1,1,1,1,2,11,15,11,32,0,40,2,0,34,0,4,64,32,0,65,172,3,79,4,64,32,0,65,16,107,16,52,11,11,15,11,0,11,11,137,3,7,0,65,16,11,55,40,0,0,0,1,0,0,0,1,0,0,0,40,0,0,0,97,0,108,0,108,0,111,0,99,0,97,0,116,0,105,0,111,0,110,0,32,0,116,0,111,0,111,0,32,0,108,0,97,0,114,0,103,0,101,0,65,208,0,11,45,30,0,0,0,1,0,0,0,1,0,0,0,30,0,0,0,126,0,108,0,105,0,98,0,47,0,114,0,116,0,47,0,116,0,108,0,115,0,102,0,46,0,116,0,115,0,65,128,1,11,43,28,0,0,0,1,0,0,0,1,0,0,0,28,0,0,0,73,0,110,0,118,0,97,0,108,0,105,0,100,0,32,0,108,0,101,0,110,0,103,0,116,0,104,0,65,176,1,11,53,38,0,0,0,1,0,0,0,1,0,0,0,38,0,0,0,126,0,108,0,105,0,98,0,47,0,97,0,114,0,114,0,97,0,121,0,98,0,117,0,102,0,102,0,101,0,114,0,46,0,116,0,115,0,65,240,1,11,51,36,0,0,0,1,0,0,0,1,0,0,0,36,0,0,0,73,0,110,0,100,0,101,0,120,0,32,0,111,0,117,0,116,0,32,0,111,0,102,0,32,0,114,0,97,0,110,0,103,0,101,0,65,176,2,11,51,36,0,0,0,1,0,0,0,1,0,0,0,36,0,0,0,126,0,108,0,105,0,98,0,47,0,116,0,121,0,112,0,101,0,100,0,97,0,114,0,114,0,97,0,121,0,46,0,116,0,115,0,65,240,2,11,53,7,0,0,0,16,0,0,0,0,0,0,0,16,0,0,0,0,0,0,0,16,0,0,0,0,0,0,0,145,4,0,0,2,0,0,0,49,0,0,0,2,0,0,0,17,1,0,0,2,0,0,0,16,0,34,16,115,111,117,114,99,101,77,97,112,112,105,110,103,85,82,76,16,46,47,114,97,98,105,110,46,119,97,115,109,46,109,97,112]);return instantiate(new Response(new Blob([t],{type:"application/wasm"})),e)}loadWebAssembly.supported="undefined"!=typeof WebAssembly;var rabinWasm=loadWebAssembly;const Rabin=rabin$1,getRabin=rabinWasm,create=async(e,t,r,n,o)=>{const i=await getRabin();return new Rabin(i,e,t,r,n,o)};var src$2={Rabin:Rabin,create:create};async function*rabinChunker(e,t){let r,n,o;if(t.minChunkSize&&t.maxChunkSize&&t.avgChunkSize)o=t.avgChunkSize,r=t.minChunkSize,n=t.maxChunkSize;else{if(!t.avgChunkSize)throw errCode$3(new Error("please specify an average chunk size"),"ERR_INVALID_AVG_CHUNK_SIZE");o=t.avgChunkSize,r=o/3,n=o+o/2}if(r<16)throw errCode$3(new Error("rabin min must be greater than 16"),"ERR_INVALID_MIN_CHUNK_SIZE");n=i;)if(yield r.slice(0,i),o=!0,i===r.length)r=new BufferList_1,n=0;else{const e=new BufferList_1;e.append(r.shallowSlice(i)),r=e,n-=i}o&&!n||(yield r.slice(0,n))}const identity$2=from$1({prefix:"\0",name:"identity",encode:e=>toString$1(e),decode:e=>fromString$3(e)});var identityBase=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",identity:identity$2});const base2=rfc4648({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var base2$1=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",base2:base2});const base8=rfc4648({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var base8$1=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",base8:base8});const base10=baseX({prefix:"9",name:"base10",alphabet:"0123456789"});var base10$1=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",base10:base10});const base16=rfc4648({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),base16upper=rfc4648({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var base16$1=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",base16:base16,base16upper:base16upper});const base36=baseX({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),base36upper=baseX({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var base36$1=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",base36:base36,base36upper:base36upper});const base64=rfc4648({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),base64pad=rfc4648({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),base64url=rfc4648({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),base64urlpad=rfc4648({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var base64$1=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",base64:base64,base64pad:base64pad,base64url:base64url,base64urlpad:base64urlpad});const identity=from({name:"identity",code:0,encode:e=>coerce(e)});var identity$1=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",identity:identity});const bases=__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({},identityBase),base2$1),base8$1),base10$1),base16$1),base32$2),base36$1),base58),base64$1);function createCodec(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}__spreadValues(__spreadValues({},sha2),identity$1);const string=createCodec("utf8","u",(e=>"u"+new TextDecoder("utf8").decode(e)),(e=>(new TextEncoder).encode(e.substring(1)))),ascii=createCodec("ascii","a",(e=>{let t="a";for(let r=0;r{e=e.substring(1);const t=new Uint8Array(e.length);for(let r=0;re&&"."!==e)).join("/")),n.content){let e,o;e="function"==typeof r.chunker?r.chunker:"rabin"===r.chunker?rabinChunker:fixedSizeChunker,o="function"==typeof r.chunkValidator?r.chunkValidator:validateChunks;const i={path:n.path,mtime:n.mtime,mode:n.mode,content:e(o(contentAsAsyncIterable(n.content),r),r)};yield()=>fileBuilder(i,t,r)}else{if(!n.path)throw new Error("Import candidate must have content or path or both");{const e={path:n.path,mtime:n.mtime,mode:n.mode};yield()=>dirBuilder(e,t,r)}}}class Dir{constructor(e,t){this.options=t||{},this.root=e.root,this.dir=e.dir,this.path=e.path,this.dirty=e.dirty,this.flat=e.flat,this.parent=e.parent,this.parentKey=e.parentKey,this.unixfs=e.unixfs,this.mode=e.mode,this.mtime=e.mtime,this.cid=void 0,this.size=void 0}async put(e,t){}get(e){return Promise.resolve(this)}async*eachChildSeries(){}async*flush(e){}}class DirFlat extends Dir{constructor(e,t){super(e,t),this._children={}}async put(e,t){this.cid=void 0,this.size=void 0,this._children[e]=t}get(e){return Promise.resolve(this._children[e])}childCount(){return Object.keys(this._children).length}directChildrenCount(){return this.childCount()}onlyChild(){return this._children[Object.keys(this._children)[0]]}async*eachChildSeries(){const e=Object.keys(this._children);for(let t=0;te+(null==t.Tsize?0:t.Tsize)),0);this.cid=s,this.size=a,yield{cid:s,unixfs:n,path:this.path,size:a}}}const BITS_PER_BYTE=7;var sparseArray=class{constructor(){this._bitArrays=[],this._data=[],this._length=0,this._changedLength=!1,this._changedData=!1}set(e,t){let r=this._internalPositionFor(e,!1);if(void 0===t)-1!==r&&(this._unsetInternalPos(r),this._unsetBit(e),this._changedLength=!0,this._changedData=!0);else{let n=!1;-1===r?(r=this._data.length,this._setBit(e),this._changedData=!0):n=!0,this._setInternalPos(r,e,t,n),this._changedLength=!0}}unset(e){this.set(e,void 0)}get(e){this._sortData();const t=this._internalPositionFor(e,!0);if(-1!==t)return this._data[t][1]}push(e){return this.set(this.length,e),this.length}get length(){if(this._sortData(),this._changedLength){const e=this._data[this._data.length-1];this._length=e?e[0]+1:0,this._changedLength=!1}return this._length}forEach(e){let t=0;for(;t=this._bitArrays.length)return-1;const n=this._bitArrays[r],o=e-r*BITS_PER_BYTE;if(!((n&1<0))return-1;return this._bitArrays.slice(0,r).reduce(popCountReduce,0)+popCount(n&~(4294967295<=t)o.push(i);else if(o[0][0]<=t)o.unshift(i);else{const e=Math.round(o.length/2);this._data=o.slice(0,e).concat(i).concat(o.slice(e))}else this._data.push(i);this._changedData=!0,this._changedLength=!0}}_unsetInternalPos(e){this._data.splice(e,1)}_sortData(){this._changedData&&this._data.sort(sortInternal),this._changedData=!1}bitField(){const e=[];let t,r=8,n=0,o=0;const i=this._bitArrays.slice();for(;i.length||n;){0===n&&(t=i.shift(),n=7);const s=Math.min(n,r);o|=(t&~(255<>>=s,n-=s,r-=s,r&&(n||i.length)||(e.push(o),o=0,r=8)}for(var s=e.length-1;s>0;s--){if(0!==e[s])break;e.pop()}return e}compactArray(){return this._sortData(),this._data.map(valueOnly)}};function popCountReduce(e,t){return e+popCount(t)}function popCount(e){let t=e;return t-=t>>1&1431655765,t=(858993459&t)+(t>>2&858993459),16843009*(t+(t>>4)&252645135)>>24}function sortInternal(e,t){return e[0]-t[0]}function valueOnly(e){return e[1]}var require$$1$2=getAugmentedNamespace(fromString$1);const SparseArray=sparseArray,{fromString:uint8ArrayFromString$1}=require$$1$2;class Bucket$1{constructor(e,t,r=0){this._options=e,this._popCount=0,this._parent=t,this._posAtParent=r,this._children=new SparseArray,this.key=null}async put(e,t){const r=await this._findNewBucketAndPos(e);await r.bucket._putAt(r,e,t)}async get(e){const t=await this._findChild(e);if(t)return t.value}async del(e){const t=await this._findPlace(e),r=t.bucket._at(t.pos);r&&r.key===e&&t.bucket._delAt(t.pos)}leafCount(){return this._children.compactArray().reduce(((e,t)=>t instanceof Bucket$1?e+t.leafCount():e+1),0)}childrenCount(){return this._children.length}onlyChild(){return this._children.get(0)}*eachLeafSeries(){const e=this._children.compactArray();for(const t of e)t instanceof Bucket$1?yield*t.eachLeafSeries():yield t;return[]}serialize(e,t){return t(this._children.reduce(((r,n,o)=>(n&&(n instanceof Bucket$1?r.push(n.serialize(e,t)):r.push(e(n,o))),r)),[]))}asyncTransform(e,t){return asyncTransformBucket(this,e,t)}toJSON(){return this.serialize(mapNode,reduceNodes)}prettyPrint(){return JSON.stringify(this.toJSON(),null," ")}tableSize(){return Math.pow(2,this._options.bits)}async _findChild(e){const t=await this._findPlace(e),r=t.bucket._at(t.pos);if(!(r instanceof Bucket$1))return r&&r.key===e?r:void 0}async _findPlace(e){const t=this._options.hash("string"==typeof e?uint8ArrayFromString$1(e):e),r=await t.take(this._options.bits),n=this._children.get(r);return n instanceof Bucket$1?n._findPlace(t):{bucket:this,pos:r,hash:t,existingChild:n}}async _findNewBucketAndPos(e){const t=await this._findPlace(e);if(t.existingChild&&t.existingChild.key!==e){const e=new Bucket$1(this._options,t.bucket,t.pos);t.bucket._putObjectAt(t.pos,e);const r=await e._findPlace(t.existingChild.hash);return r.bucket._putAt(r,t.existingChild.key,t.existingChild.value),e._findNewBucketAndPos(t.hash)}return t}_putAt(e,t,r){this._putObjectAt(e.pos,{key:t,value:r,hash:e.hash})}_putObjectAt(e,t){this._children.get(e)||this._popCount++,this._children.set(e,t)}_delAt(e){if(-1===e)throw new Error("Invalid position");this._children.get(e)&&this._popCount--,this._children.unset(e),this._level()}_level(){if(this._parent&&this._popCount<=1)if(1===this._popCount){const e=this._children.find(exists);if(e&&!(e instanceof Bucket$1)){const t=e.hash;t.untake(this._options.bits);const r={pos:this._posAtParent,hash:t,bucket:this._parent};this._parent._putAt(r,e.key,e.value)}}else this._parent._delAt(this._posAtParent)}_at(e){return this._children.get(e)}}function exists(e){return Boolean(e)}function mapNode(e,t){return e.key}function reduceNodes(e){return e}async function asyncTransformBucket(e,t,r){const n=[];for(const o of e._children.compactArray())if(o instanceof Bucket$1)await asyncTransformBucket(o,t,r);else{const r=await t(o);n.push({bitField:e._children.bitField(),children:r})}return r(n)}var bucket=Bucket$1,consumableHash={exports:{}};const START_MASKS=[255,254,252,248,240,224,192,128],STOP_MASKS=[1,3,7,15,31,63,127,255];var consumableBuffer=class{constructor(e){this._value=e,this._currentBytePos=e.length-1,this._currentBitPos=7}availableBits(){return this._currentBitPos+1+8*this._currentBytePos}totalBits(){return 8*this._value.length}take(e){let t=e,r=0;for(;t&&this._haveBits();){const e=this._value[this._currentBytePos],n=this._currentBitPos+1,o=Math.min(n,t);r=(r<7;)this._currentBitPos-=8,this._currentBytePos+=1}_haveBits(){return this._currentBytePos>=0}};function byteBitsToInt(e,t,r){return(e&maskFor(t,r))>>>t}function maskFor(e,t){return START_MASKS[e]&STOP_MASKS[Math.min(t+e-1,7)]}function concat(e,t){t||(t=e.reduce(((e,t)=>e+t.length),0));const r=new Uint8Array(t);let n=0;for(const o of e)r.set(o,n),n+=o.length;return r}var concat$1=Object.freeze({__proto__:null,[Symbol.toStringTag]:"Module",concat:concat}),require$$1$1=getAugmentedNamespace(concat$1);const ConsumableBuffer=consumableBuffer,{concat:uint8ArrayConcat}=require$$1$1;function wrapHash$1(e){return function(t){return t instanceof InfiniteHash?t:new InfiniteHash(t,e)}}class InfiniteHash{constructor(e,t){if(!(e instanceof Uint8Array))throw new Error("can only hash Uint8Arrays");this._value=e,this._hashFn=t,this._depth=-1,this._availableBits=0,this._currentBufferIndex=0,this._buffers=[]}async take(e){let t=e;for(;this._availableBits0;){const e=this._buffers[this._currentBufferIndex],n=Math.min(e.availableBits(),t);r=(r<0;){const e=this._buffers[this._currentBufferIndex],r=Math.min(e.totalBits()-e.availableBits(),t);e.untake(r),t-=r,this._availableBits+=r,this._currentBufferIndex>0&&e.totalBits()===e.availableBits()&&(this._depth--,this._currentBufferIndex--)}}async _produceMoreBits(){this._depth++;const e=this._depth?uint8ArrayConcat([this._value,Uint8Array.from([this._depth])]):this._value,t=await this._hashFn(e),r=new ConsumableBuffer(t);this._buffers.push(r),this._availableBits+=r.availableBits()}}consumableHash.exports=wrapHash$1,consumableHash.exports.InfiniteHash=InfiniteHash;const Bucket=bucket,wrapHash=consumableHash.exports;function createHAMT(e){if(!e||!e.hashFn)throw new Error("please define an options.hashFn");const t={bits:e.bits||8,hash:wrapHash(e.hashFn)};return new Bucket(t)}var src$1={createHAMT:createHAMT,Bucket:Bucket};class DirSharded extends Dir{constructor(e,t){super(e,t),this._bucket=src$1.createHAMT({hashFn:t.hamtHashFn,bits:t.hamtBucketBits})}async put(e,t){await this._bucket.put(e,t)}get(e){return this._bucket.get(e)}childCount(){return this._bucket.leafCount()}directChildrenCount(){return this._bucket.childrenCount()}onlyChild(){return this._bucket.onlyChild()}async*eachChildSeries(){for await(const{key:e,value:t}of this._bucket.eachLeafSeries())yield{key:e,child:t}}async*flush(e){for await(const t of flush(this._bucket,e,this,this.options))yield __spreadProps(__spreadValues({},t),{path:this.path})}}async function*flush(e,t,r,n){const o=e._children,i=[];let s=0;for(let h=0;h=r&&(o=await convertToShard(t,n));const i=o.parent;if(i){if(o!==t){if(e&&(e.parent=o),!o.parentKey)throw new Error("No parent key found");await i.put(o.parentKey,o)}return flatToShard(o,i,r,n)}return o}async function convertToShard(e,t){const r=new DirSharded({root:e.root,dir:!0,parent:e.parent,parentKey:e.parentKey,path:e.path,dirty:e.dirty,flat:!1,mtime:e.mtime,mode:e.mode},t);for await(const{key:n,child:o}of e.eachChildSeries())await r.put(n,o);return r}const toPathComponents$1=(e="")=>(e.trim().match(/([^\\^/]|\\\/)+/g)||[]).filter(Boolean);async function addToTree(e,t,r){const n=toPathComponents$1(e.path||""),o=n.length-1;let i=t,s="";for(let a=0;at.next(),push:e=>{n.push(e)},next:()=>n.length?{done:!1,value:n.shift()}:t.next(),[r](){return this}}}var itPeekable$2=peekableIterator;const map$2=async function*(e,t){for await(const r of e)yield t(r)};var itMap=map$2;function isBytes$2(e){return ArrayBuffer.isView(e)||e instanceof ArrayBuffer}function isBlob$2(e){return e.constructor&&("Blob"===e.constructor.name||"File"===e.constructor.name)&&"function"==typeof e.stream}function isFileObject$1(e){return"object"==typeof e&&(e.path||e.content)}const isReadableStream$2=e=>e&&"function"==typeof e.getReader;var utils={isBytes:isBytes$2,isBlob:isBlob$2,isFileObject:isFileObject$1,isReadableStream:isReadableStream$2};const errCode$2=errCode$3,{fromString:uint8ArrayFromString}=require$$1$2,browserStreamToIt$1=browserReadablestreamToIt,blobToIt=blobToIt_1,itPeekable$1=itPeekable$2,all$1=itAll,map$1=itMap,{isBytes:isBytes$1,isReadableStream:isReadableStream$1,isBlob:isBlob$1}=utils;async function*toAsyncIterable(e){if(isBytes$1(e))yield toBytes(e);else if("string"==typeof e||e instanceof String)yield toBytes(e.toString());else{if(!isBlob$1(e)){if(isReadableStream$1(e)&&(e=browserStreamToIt$1(e)),Symbol.iterator in e||Symbol.asyncIterator in e){const t=itPeekable$1(e),{value:r,done:n}=await t.peek();if(n)return void(yield*[]);if(t.push(r),Number.isInteger(r))return void(yield Uint8Array.from(await all$1(t)));if(isBytes$1(r)||"string"==typeof r||r instanceof String)return void(yield*map$1(t,toBytes))}throw errCode$2(new Error(`Unexpected input: ${e}`),"ERR_UNEXPECTED_INPUT")}yield*blobToIt(e)}}function toBytes(e){return e instanceof Uint8Array?e:ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e instanceof ArrayBuffer?new Uint8Array(e):Array.isArray(e)?Uint8Array.from(e):uint8ArrayFromString(e.toString())}var normaliseContent$1=toAsyncIterable,require$$5=getAugmentedNamespace(src$3);const errCode$1=errCode$3,browserStreamToIt=browserReadablestreamToIt,itPeekable=itPeekable$2,map=itMap,{isBytes:isBytes,isBlob:isBlob,isReadableStream:isReadableStream,isFileObject:isFileObject}=utils,{parseMtime:parseMtime,parseMode:parseMode}=require$$5;var normaliseInput$1=async function*(e,t){if(null==e)throw errCode$1(new Error(`Unexpected input: ${e}`),"ERR_UNEXPECTED_INPUT");if("string"==typeof e||e instanceof String)yield toFileObject(e.toString(),t);else if(isBytes(e)||isBlob(e))yield toFileObject(e,t);else{if(isReadableStream(e)&&(e=browserStreamToIt(e)),Symbol.iterator in e||Symbol.asyncIterator in e){const r=itPeekable(e),{value:n,done:o}=await r.peek();if(o)return void(yield*[]);if(r.push(n),Number.isInteger(n)||isBytes(n))return void(yield toFileObject(r,t));if(isFileObject(n)||isBlob(n)||"string"==typeof n||n instanceof String)return void(yield*map(r,(e=>toFileObject(e,t))));if(n[Symbol.iterator]||n[Symbol.asyncIterator]||isReadableStream(n))return void(yield*map(r,(e=>toFileObject(e,t))))}if(!isFileObject(e))throw errCode$1(new Error("Unexpected input: "+typeof e),"ERR_UNEXPECTED_INPUT");yield toFileObject(e,t)}};async function toFileObject(e,t){const{path:r,mode:n,mtime:o,content:i}=e,s={path:r||"",mode:parseMode(n),mtime:parseMtime(o)};return i?s.content=await t(i):r||(s.content=await t(e)),s}const normaliseContent=normaliseContent$1,normalise=normaliseInput$1;function normaliseInput(e){return normalise(e,normaliseContent)}var normaliseInput_1={normaliseInput:normaliseInput};const drain$1=async e=>{for await(const t of e);};var itDrain=drain$1;const filter$1=async function*(e,t){for await(const r of e)await t(r)&&(yield r)};var itFilter=filter$1;const take$1=async function*(e,t){let r=0;if(!(t<1))for await(const n of e)if(yield n,r++,r===t)return};var itTake=take$1;const drain=itDrain,filter=itFilter,take=itTake,all=itAll,sortAll=(e,t)=>async function*(){const r=await all(e);yield*r.sort(t)}();class BlockstoreAdapter$1{open(){return Promise.reject(new Error(".open is not implemented"))}close(){return Promise.reject(new Error(".close is not implemented"))}put(e,t,r){return Promise.reject(new Error(".put is not implemented"))}get(e,t){return Promise.reject(new Error(".get is not implemented"))}has(e,t){return Promise.reject(new Error(".has is not implemented"))}delete(e,t){return Promise.reject(new Error(".delete is not implemented"))}async*putMany(e,t={}){for await(const{key:r,value:n}of e)await this.put(r,n,t),yield{key:r,value:n}}async*getMany(e,t={}){for await(const r of e)yield this.get(r,t)}async*deleteMany(e,t={}){for await(const r of e)await this.delete(r,t),yield r}batch(){let e=[],t=[];return{put(t,r){e.push({key:t,value:r})},delete(e){t.push(e)},commit:async r=>{await drain(this.putMany(e,r)),e=[],await drain(this.deleteMany(t,r)),t=[]}}}async*_all(e,t){throw new Error("._all is not implemented")}async*_allKeys(e,t){throw new Error("._allKeys is not implemented")}query(e,t){let r=this._all(e,t);if(null!=e.prefix&&(r=filter(r,(t=>t.key.toString().startsWith(e.prefix||"")))),Array.isArray(e.filters)&&(r=e.filters.reduce(((e,t)=>filter(e,t)),r)),Array.isArray(e.orders)&&(r=e.orders.reduce(((e,t)=>sortAll(e,t)),r)),null!=e.offset){let t=0;r=filter(r,(()=>t++>=(e.offset||0)))}return null!=e.limit&&(r=take(r,e.limit)),r}queryKeys(e,t){let r=this._allKeys(e,t);if(null!=e.prefix&&(r=filter(r,(t=>t.toString().startsWith(e.prefix||"")))),Array.isArray(e.filters)&&(r=e.filters.reduce(((e,t)=>filter(e,t)),r)),Array.isArray(e.orders)&&(r=e.orders.reduce(((e,t)=>sortAll(e,t)),r)),null!=e.offset){let t=0;r=filter(r,(()=>t++>=e.offset))}return null!=e.limit&&(r=take(r,e.limit)),r}}var adapter=BlockstoreAdapter$1,require$$1=getAugmentedNamespace(base32$2),require$$2=getAugmentedNamespace(raw$2),require$$3=getAugmentedNamespace(cid),require$$4=getAugmentedNamespace(digest);const errCode=errCode$3;function notFoundError(e){return e=e||new Error("Not Found"),errCode(e,"ERR_NOT_FOUND")}var errors={notFoundError:notFoundError};const Adapter=adapter,{base32:base32}=require$$1,raw=require$$2,{CID:CID}=require$$3,Digest=require$$4,Errors=errors;class MemoryBlockstore$1 extends Adapter{constructor(){super(),this.data={}}open(){return Promise.resolve()}close(){return Promise.resolve()}async put(e,t){this.data[base32.encode(e.multihash.bytes)]=t}async get(e){if(!(await this.has(e)))throw Errors.notFoundError();return this.data[base32.encode(e.multihash.bytes)]}async has(e){return void 0!==this.data[base32.encode(e.multihash.bytes)]}async delete(e){delete this.data[base32.encode(e.multihash.bytes)]}async*_all(){yield*Object.entries(this.data).map((([e,t])=>({key:CID.createV1(raw.code,Digest.decode(base32.decode(e))),value:t})))}async*_allKeys(){yield*Object.entries(this.data).map((([e])=>CID.createV1(raw.code,Digest.decode(base32.decode(e)))))}}var memory=MemoryBlockstore$1;const BlockstoreAdapter=adapter,MemoryBlockstore=memory;var src={BlockstoreAdapter:BlockstoreAdapter,MemoryBlockstore:MemoryBlockstore};class MemoryBlockStore extends src.BlockstoreAdapter{constructor(){super(),this.store=new Map}async*blocks(){for(const[e,t]of this.store.entries())yield{cid:CID$1.parse(e),bytes:t}}put(e,t){return this.store.set(e.toString(),t),Promise.resolve()}get(e){const t=this.store.get(e.toString());if(!t)throw new Error(`block with cid ${e.toString()} no found`);return Promise.resolve(t)}close(){return this.store.clear(),Promise.resolve()}}const unixfsImporterOptionsDefault={cidVersion:1,chunker:"fixed",maxChunkSize:262144,hasher:sha256,rawLeaves:!0,wrapWithDirectory:!0,maxChildrenPerNode:174};async function pack({input:e,blockstore:t,hasher:r,maxChunkSize:n,maxChildrenPerNode:o,wrapWithDirectory:i}){if(!e||Array.isArray(e)&&!e.length)throw new Error("missing input file(s)");const s=t||new MemoryBlockStore,a=await itLast(pipe$1(normaliseInput_1.normaliseInput(e),(e=>importer(e,s,__spreadProps(__spreadValues({},unixfsImporterOptionsDefault),{hasher:r||unixfsImporterOptionsDefault.hasher,maxChunkSize:n||unixfsImporterOptionsDefault.maxChunkSize,maxChildrenPerNode:o||unixfsImporterOptionsDefault.maxChildrenPerNode,wrapWithDirectory:!1!==i&&unixfsImporterOptionsDefault.wrapWithDirectory})))));if(!a||!a.cid)throw new Error("given input could not be parsed correctly");const c=a.cid,{writer:u,out:l}=await CarWriter.create([c]),f=l[Symbol.asyncIterator]();let h;return{root:c,out:{[Symbol.asyncIterator](){if(null!=h)throw new Error("Multiple iterator not supported");return h=(async()=>{for await(const e of s.blocks())await u.put(e);await u.close(),t||await s.close()})(),{async next(){const e=await f.next();return e.done&&await h,e}}}}}}var querystring$2={};function hasOwnProperty$2(e,t){return Object.prototype.hasOwnProperty.call(e,t)}var decode$1=function(e,t,r,n){t=t||"&",r=r||"=";var o={};if("string"!=typeof e||0===e.length)return o;var i=/\+/g;e=e.split(t);var s=1e3;n&&"number"==typeof n.maxKeys&&(s=n.maxKeys);var a=e.length;s>0&&a>s&&(a=s);for(var c=0;c=0?(u=d.substr(0,p),l=d.substr(p+1)):(u=d,l=""),f=decodeURIComponent(u),h=decodeURIComponent(l),hasOwnProperty$2(o,f)?Array.isArray(o[f])?o[f].push(h):o[f]=[o[f],h]:o[f]=h}return o},stringifyPrimitive$1=function(e){switch(typeof e){case"string":return e;case"boolean":return e?"true":"false";case"number":return isFinite(e)?e:"";default:return""}},encode$1=function(e,t,r,n){return t=t||"&",r=r||"=",null===e&&(e=void 0),"object"==typeof e?Object.keys(e).map((function(n){var o=encodeURIComponent(stringifyPrimitive$1(n))+r;return Array.isArray(e[n])?e[n].map((function(e){return o+encodeURIComponent(stringifyPrimitive$1(e))})).join(t):o+encodeURIComponent(stringifyPrimitive$1(e[n]))})).filter(Boolean).join(t):n?encodeURIComponent(stringifyPrimitive$1(n))+r+encodeURIComponent(stringifyPrimitive$1(e)):""};querystring$2.decode=querystring$2.parse=decode$1,querystring$2.encode=querystring$2.stringify=encode$1;var url$1={},punycode$1={exports:{}}; /*! https://mths.be/punycode v1.3.2 by @mathias */ !function(e,t){!function(r){var n=t&&!t.nodeType&&t,o=e&&!e.nodeType&&e,i="object"==typeof commonjsGlobal&&commonjsGlobal;i.global!==i&&i.window!==i&&i.self!==i||(r=i);var s,a,c=2147483647,u=36,l=/^xn--/,f=/[^\x20-\x7E]/,h=/[\x2E\u3002\uFF0E\uFF61]/g,d={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},p=Math.floor,y=String.fromCharCode;function m(e){throw RangeError(d[e])}function g(e,t){for(var r=e.length,n=[];r--;)n[r]=t(e[r]);return n}function b(e,t){var r=e.split("@"),n="";return r.length>1&&(n=r[0]+"@",e=r[1]),n+g((e=e.replace(h,".")).split("."),t).join(".")}function w(e){for(var t,r,n=[],o=0,i=e.length;o=55296&&t<=56319&&o65535&&(t+=y((e-=65536)>>>10&1023|55296),e=56320|1023&e),t+=y(e)})).join("")}function v(e,t){return e+22+75*(e<26)-((0!=t)<<5)}function $(e,t,r){var n=0;for(e=r?p(e/700):e>>1,e+=p(e/t);e>455;n+=u)e=p(e/35);return p(n+36*e/(e+38))}function E(e){var t,r,n,o,i,s,a,l,f,h,d,y=[],g=e.length,b=0,w=128,v=72;for((r=e.lastIndexOf("-"))<0&&(r=0),n=0;n=128&&m("not-basic"),y.push(e.charCodeAt(n));for(o=r>0?r+1:0;o=g&&m("invalid-input"),((l=(d=e.charCodeAt(o++))-48<10?d-22:d-65<26?d-65:d-97<26?d-97:u)>=u||l>p((c-b)/s))&&m("overflow"),b+=l*s,!(l<(f=a<=v?1:a>=v+26?26:a-v));a+=u)s>p(c/(h=u-f))&&m("overflow"),s*=h;v=$(b-i,t=y.length+1,0==i),p(b/t)>c-w&&m("overflow"),w+=p(b/t),b%=t,y.splice(b++,0,w)}return _(y)}function T(e){var t,r,n,o,i,s,a,l,f,h,d,g,b,_,E,T=[];for(g=(e=w(e)).length,t=128,r=0,i=72,s=0;s=t&&dp((c-r)/(b=n+1))&&m("overflow"),r+=(a-t)*b,t=a,s=0;sc&&m("overflow"),d==t){for(l=r,f=u;!(l<(h=f<=i?1:f>=i+26?26:f-i));f+=u)E=l-h,_=u-h,T.push(y(v(h+E%_,0))),l=p(E/_);T.push(y(v(l,0))),i=$(r,b,n==o),r=0,++n}++r,++t}return T.join("")}if(s={version:"1.3.2",ucs2:{decode:w,encode:_},decode:E,encode:T,toASCII:function(e){return b(e,(function(e){return f.test(e)?"xn--"+T(e):e}))},toUnicode:function(e){return b(e,(function(e){return l.test(e)?E(e.slice(4).toLowerCase()):e}))}},n&&o)if(e.exports==n)o.exports=s;else for(a in s)s.hasOwnProperty(a)&&(n[a]=s[a]);else r.punycode=s}(commonjsGlobal)}(punycode$1,punycode$1.exports);var util$1={isString:function(e){return"string"==typeof e},isObject:function(e){return"object"==typeof e&&null!==e},isNull:function(e){return null===e},isNullOrUndefined:function(e){return null==e}},querystring$1={};function hasOwnProperty$1(e,t){return Object.prototype.hasOwnProperty.call(e,t)}var decode=function(e,t,r,n){t=t||"&",r=r||"=";var o={};if("string"!=typeof e||0===e.length)return o;var i=/\+/g;e=e.split(t);var s=1e3;n&&"number"==typeof n.maxKeys&&(s=n.maxKeys);var a=e.length;s>0&&a>s&&(a=s);for(var c=0;c=0?(u=d.substr(0,p),l=d.substr(p+1)):(u=d,l=""),f=decodeURIComponent(u),h=decodeURIComponent(l),hasOwnProperty$1(o,f)?Array.isArray(o[f])?o[f].push(h):o[f]=[o[f],h]:o[f]=h}return o},stringifyPrimitive=function(e){switch(typeof e){case"string":return e;case"boolean":return e?"true":"false";case"number":return isFinite(e)?e:"";default:return""}},encode=function(e,t,r,n){return t=t||"&",r=r||"=",null===e&&(e=void 0),"object"==typeof e?Object.keys(e).map((function(n){var o=encodeURIComponent(stringifyPrimitive(n))+r;return Array.isArray(e[n])?e[n].map((function(e){return o+encodeURIComponent(stringifyPrimitive(e))})).join(t):o+encodeURIComponent(stringifyPrimitive(e[n]))})).join(t):n?encodeURIComponent(stringifyPrimitive(n))+r+encodeURIComponent(stringifyPrimitive(e)):""};querystring$1.decode=querystring$1.parse=decode,querystring$1.encode=querystring$1.stringify=encode;var punycode=punycode$1.exports,util=util$1;function Url(){this.protocol=null,this.slashes=null,this.auth=null,this.host=null,this.port=null,this.hostname=null,this.hash=null,this.search=null,this.query=null,this.pathname=null,this.path=null,this.href=null}url$1.parse=urlParse,url$1.resolve=urlResolve,url$1.resolveObject=urlResolveObject,url$1.format=urlFormat,url$1.Url=Url;var protocolPattern=/^([a-z0-9.+-]+:)/i,portPattern=/:[0-9]*$/,simplePathPattern=/^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,delims=["<",">",'"',"`"," ","\r","\n","\t"],unwise=["{","}","|","\\","^","`"].concat(delims),autoEscape=["'"].concat(unwise),nonHostChars=["%","/","?",";","#"].concat(autoEscape),hostEndingChars=["/","?","#"],hostnameMaxLen=255,hostnamePartPattern=/^[+a-z0-9A-Z_-]{0,63}$/,hostnamePartStart=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,unsafeProtocol={javascript:!0,"javascript:":!0},hostlessProtocol={javascript:!0,"javascript:":!0},slashedProtocol={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},querystring=querystring$1;function urlParse(e,t,r){if(e&&util.isObject(e)&&e instanceof Url)return e;var n=new Url;return n.parse(e,t,r),n}function urlFormat(e){return util.isString(e)&&(e=urlParse(e)),e instanceof Url?e.format():Url.prototype.format.call(e)}function urlResolve(e,t){return urlParse(e,!1,!0).resolve(t)}function urlResolveObject(e,t){return e?urlParse(e,!1,!0).resolveObject(t):t}Url.prototype.parse=function(e,t,r){if(!util.isString(e))throw new TypeError("Parameter 'url' must be a string, not "+typeof e);var n=e.indexOf("?"),o=-1!==n&&n127?_+="x":_+=w[v];if(!_.match(hostnamePartPattern)){var E=g.slice(0,p),T=g.slice(p+1),B=w.match(hostnamePartStart);B&&(E.push(B[1]),T.unshift(B[2])),T.length&&(s="/"+T.join(".")+s),this.hostname=E.join(".");break}}}this.hostname.length>hostnameMaxLen?this.hostname="":this.hostname=this.hostname.toLowerCase(),m||(this.hostname=punycode.toASCII(this.hostname));var A=this.port?":"+this.port:"",k=this.hostname||"";this.host=k+A,this.href+=this.host,m&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),"/"!==s[0]&&(s="/"+s))}if(!unsafeProtocol[u])for(p=0,b=autoEscape.length;p0)&&r.host.split("@"))&&(r.auth=B.shift(),r.host=r.hostname=B.shift());return r.search=e.search,r.query=e.query,util.isNull(r.pathname)&&util.isNull(r.search)||(r.path=(r.pathname?r.pathname:"")+(r.search?r.search:"")),r.href=r.format(),r}if(!w.length)return r.pathname=null,r.search?r.path="/"+r.search:r.path=null,r.href=r.format(),r;for(var v=w.slice(-1)[0],$=(r.host||e.host||w.length>1)&&("."===v||".."===v)||""===v,E=0,T=w.length;T>=0;T--)"."===(v=w[T])?w.splice(T,1):".."===v?(w.splice(T,1),E++):E&&(w.splice(T,1),E--);if(!g&&!b)for(;E--;E)w.unshift("..");!g||""===w[0]||w[0]&&"/"===w[0].charAt(0)||w.unshift(""),$&&"/"!==w.join("/").substr(-1)&&w.push("");var B,A=""===w[0]||w[0]&&"/"===w[0].charAt(0);_&&(r.hostname=r.host=A?"":w.length?w.shift():"",(B=!!(r.host&&r.host.indexOf("@")>0)&&r.host.split("@"))&&(r.auth=B.shift(),r.host=r.hostname=B.shift()));return(g=g||r.host&&w.length)&&!A&&w.unshift(""),w.length?r.pathname=w.join("/"):(r.pathname=null,r.path=null),util.isNull(r.pathname)&&util.isNull(r.search)||(r.path=(r.pathname?r.pathname:"")+(r.search?r.search:"")),r.auth=e.auth||r.auth,r.slashes=r.slashes||e.slashes,r.href=r.format(),r},Url.prototype.parseHost=function(){var e=this.host,t=portPattern.exec(e);t&&(":"!==(t=t[0])&&(this.port=t.substr(1)),e=e.substr(0,e.length-t.length)),e&&(this.hostname=e)};var immutable=extend,hasOwnProperty=Object.prototype.hasOwnProperty;function extend(){for(var e={},t=0;t]*)>(.*)/),r=t[1],n=t[2].split(";"),o=url.parse(r),i=qs.parse(o.query);n.shift();var s=n.reduce(createObjects,{});return(s=xtend(i,s)).url=r,s}catch(a){return null}}var parseLinkHeader=function(e){return e?e.split(/,\s*Promise.all(e.map((e=>{if(null==e.Name)throw new Error("Unexpected Link without a Name");if(2===e.Name.length){const n=parseInt(e.Name,16);return t._putObjectAt(n,new src$1.Bucket({hash:r._options.hash,bits:r._options.bits},t,n))}return r.put(e.Name.substring(2),!0)}))),toPrefix=e=>e.toString(16).toUpperCase().padStart(2,"0").substring(0,2),toBucketPath=e=>{let t=e.bucket;const r=[];for(;t._parent;)r.push(t),t=t._parent;return r.push(t),r.reverse()},findShardCid=async(e,t,r,n,o)=>{if(!n){const e=src$1.createHAMT({hashFn:hashFn});n={rootBucket:e,hamtDepth:1,lastBucket:e}}await addLinksToHamtBucket(e.Links,n.lastBucket,n.rootBucket);const i=await n.rootBucket._findNewBucketAndPos(t);let s=toPrefix(i.pos);const a=toBucketPath(i);a.length>n.hamtDepth&&(n.lastBucket=a[n.hamtDepth],s=toPrefix(n.lastBucket._posAtParent));const c=e.Links.find((e=>{if(null==e.Name)return!1;const r=e.Name.substring(0,2),n=e.Name.substring(2);return r===s&&(!n||n===t)}));if(!c)return null;if(null!=c.Name&&c.Name.substring(2)===t)return c.Hash;n.hamtDepth++;return e=decode$3(await r.get(c.Hash,o)),findShardCid(e,t,r,n,o)};function extractDataFromBlock(e,t,r,n){const o=t+e.length;return r>=o||n=t&&n=t&&r{if(t||(t=0),t<0)throw errCode$3(new Error("Offset must be greater than or equal to 0"),"ERR_INVALID_PARAMS");if(t>e)throw errCode$3(new Error("Offset must be less than the file size"),"ERR_INVALID_PARAMS");if(r||0===r||(r=e-t),r<0)throw errCode$3(new Error("Length must be greater than or equal to 0"),"ERR_INVALID_PARAMS");return t+r>e&&(r=e-t),{offset:t,length:r}};async function*emitBytes(e,t,r,n,o=0,i){if(t instanceof Uint8Array){const e=extractDataFromBlock(t,o,r,n);return e.length&&(yield e),o+=e.length}if(null==t.Data)throw errCode$3(new Error("no data in PBNode"),"ERR_NOT_UNIXFS");let s;try{s=UnixFS.unmarshal(t.Data)}catch(c){throw errCode$3(c,"ERR_NOT_UNIXFS")}if(s.data&&s.data.length){const e=extractDataFromBlock(s.data,o,r,n);e.length&&(yield e),o+=s.data.length}let a=o;for(let u=0;u=a&&ra&&n<=l||rl){const t=await e.get(c.Hash,{signal:i.signal});let s;switch(c.Hash.code){case code$2:s=await decode$3(t);break;case code$1:s=t;break;case code$3:s=await decode$4(t);break;default:throw Error(`Unsupported codec: ${c.Hash.code}`)}for await(const a of emitBytes(e,s,r,n,o,i))o+=a.length,yield a}o=l,a=l+1}}const fileContent=(e,t,r,n,o,i,s)=>function(e={}){const n=r.fileSize();if(void 0===n)throw new Error("File was a directory");const{offset:o,length:i}=validateOffsetAndLength(n,e.offset,e.length);return emitBytes(s,t,o,o+i,0,e)},directoryContent=(e,t,r,n,o,i,s)=>async function*(e={}){const r=e.offset||0,a=e.length||t.Links.length,c=t.Links.slice(r,a);for(const t of c){const r=await o(t.Hash,t.Name||"",`${n}/${t.Name||""}`,[],i+1,s,e);r.entry&&(yield r.entry)}},hamtShardedDirectoryContent=(e,t,r,n,o,i,s)=>function(e={}){return listDirectory(t,n,o,i,s,e)};async function*listDirectory(e,t,r,n,o,i){const s=e.Links;for(const a of s){const s=null!=a.Name?a.Name.substring(2):null;if(s){const e=await r(a.Hash,s,`${t}/${s}`,[],n+1,o,i);yield e.entry}else{e=decode$3(await o.get(a.Hash));for await(const s of listDirectory(e,t,r,n,o,i))yield s}}}const findLinkCid=(e,t)=>{const r=e.Links.find((e=>e.Name===t));return r&&r.Hash},contentExporters={raw:fileContent,file:fileContent,directory:directoryContent,"hamt-sharded-directory":hamtShardedDirectoryContent,metadata:(e,t,r,n,o,i,s)=>()=>[],symlink:(e,t,r,n,o,i,s)=>()=>[]},unixFsResolver=async(e,t,r,n,o,i,s,a)=>{const c=decode$3(await s.get(e,a));let u,l;if(t||(t=e.toString()),null==c.Data)throw errCode$3(new Error("no data in PBNode"),"ERR_NOT_UNIXFS");try{u=UnixFS.unmarshal(c.Data)}catch(f){throw errCode$3(f,"ERR_NOT_UNIXFS")}if(r||(r=t),n.length){let e;if(e=u&&"hamt-sharded-directory"===u.type?await findShardCid(c,n[0],s):findLinkCid(c,n[0]),!e)throw errCode$3(new Error("file does not exist"),"ERR_NOT_FOUND");const t=n.shift();l={cid:e,toResolve:n,name:t||"",path:`${r}/${t}`}}return{entry:{type:u.isDirectory()?"directory":"file",name:t,path:r,cid:e,content:contentExporters[u.type](e,c,u,r,o,i,s),unixfs:u,depth:i,node:c,size:u.fileSize()},next:l}},rawContent$1=e=>async function*(t={}){const{offset:r,length:n}=validateOffsetAndLength(e.length,t.offset,t.length);yield extractDataFromBlock(e,0,r,r+n)},resolve$3=async(e,t,r,n,o,i,s,a)=>{if(n.length)throw errCode$3(new Error(`No link named ${r} found in raw node ${e}`),"ERR_NOT_FOUND");const c=await s.get(e,a);return{entry:{type:"raw",name:t,path:r,cid:e,content:rawContent$1(c),depth:i,size:c.length,node:c}}},resolve$2=async(e,t,r,n,o,i,s,a)=>{const c=await s.get(e),u=decode$4(c);let l=u,f=r;for(;n.length;){const o=n[0];if(!(o in l))throw errCode$3(new Error(`No property named ${o} found in cbor node ${e}`),"ERR_NO_PROP");{n.shift(),f=`${f}/${o}`;const s=CID$1.asCID(l[o]);if(s)return{entry:{type:"object",name:t,path:r,cid:e,node:c,depth:i,size:c.length,content:async function*(){yield u}},next:{cid:s,name:o,path:f,toResolve:n}};l=l[o]}}return{entry:{type:"object",name:t,path:r,cid:e,node:c,depth:i,size:c.length,content:async function*(){yield u}}}},rawContent=e=>async function*(t={}){const{offset:r,length:n}=validateOffsetAndLength(e.length,t.offset,t.length);yield extractDataFromBlock(e,0,r,r+n)},resolve$1=async(e,t,r,n,o,i,s,a)=>{if(n.length)throw errCode$3(new Error(`No link named ${r} found in raw node ${e}`),"ERR_NOT_FOUND");const c=await decode$7(e.multihash.bytes);return{entry:{type:"identity",name:t,path:r,cid:e,content:rawContent(c.digest),depth:i,size:c.digest.length,node:c.digest}}},resolvers={[code$2]:unixFsResolver,[code$1]:resolve$3,[code$3]:resolve$2,[identity.code]:resolve$1};function resolve(e,t,r,n,o,i,s){const a=resolvers[e.code];if(!a)throw errCode$3(new Error(`No resolver for code ${e.code}`),"ERR_NO_RESOLVER");return a(e,t,r,n,resolve,o,i,s)}const toPathComponents=(e="")=>(e.trim().match(/([^\\^/]|\\\/)+/g)||[]).filter(Boolean),cidAndRest=e=>{if(e instanceof Uint8Array)return{cid:CID$1.decode(e),toResolve:[]};const t=CID$1.asCID(e);if(t)return{cid:t,toResolve:[]};if("string"==typeof e){0===e.indexOf("/ipfs/")&&(e=e.substring(6));const t=toPathComponents(e);return{cid:CID$1.parse(t[0]),toResolve:t.slice(1)}}throw errCode$3(new Error(`Unknown path type ${e}`),"ERR_BAD_PATH")};async function*walkPath(e,t,r={}){let{cid:n,toResolve:o}=cidAndRest(e),i=n.toString(),s=i;const a=o.length;for(;;){const c=await resolve(n,i,s,o,a,t,r);if(!c.entry&&!c.next)throw errCode$3(new Error(`Could not resolve ${e}`),"ERR_NOT_FOUND");if(c.entry&&(yield c.entry),!c.next)return;o=c.next.toResolve,n=c.next.cid,i=c.next.name,s=c.next.path}}async function exporter(e,t,r={}){const n=await itLast(walkPath(e,t,r));if(!n)throw errCode$3(new Error(`Could not resolve ${e}`),"ERR_NOT_FOUND");return n}async function*recursive(e,t,r={}){const n=await exporter(e,t,r);if(n&&(yield n,"directory"===n.type))for await(const o of async function*e(t,r){for await(const n of t.content(r))yield n,n instanceof Uint8Array||"directory"===n.type&&(yield*e(n,r))}(n,r))yield o}function equals(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r{const r=await e.get(t);return null==r?void 0:r.bytes}})}}async function isValid({cid:e,bytes:t}){return equals((await sha256.digest(t)).digest,e.multihash.digest)}async function*unpackStream(e,{roots:t,blockstore:r}={}){const n=await CarBlockIterator.fromIterable(asAsyncIterable(e)),o=r||new MemoryBlockStore;for await(const s of n)await o.put(s.cid,s.bytes);const i=VerifyingGetOnlyBlockStore.fromBlockstore(o);t&&0!==t.length||(t=await n.getRoots());for(const s of t)yield*recursive(s,i)}function asAsyncIterable(e){return Symbol.asyncIterator in e?e:browserReadablestreamToIt(e)}const readonly=({enumerable:e=!0,configurable:t=!1}={})=>({enumerable:e,configurable:t,writable:!1}),links=function*(e,t){if(null!=e&&!(e instanceof Uint8Array))for(const[r,n]of Object.entries(e)){const e=[...t,r];if(null!=n&&"object"==typeof n)if(Array.isArray(n))for(const[t,r]of n.entries()){const n=[...e,t],o=CID$1.asCID(r);o?yield[n.join("/"),o]:"object"==typeof r&&(yield*links(r,n))}else{const t=CID$1.asCID(n);t?yield[e.join("/"),t]:yield*links(n,e)}}},tree=function*(e,t){if(null!=e)for(const[r,n]of Object.entries(e)){const e=[...t,r];if(yield e.join("/"),!(null==n||n instanceof Uint8Array||"object"!=typeof n||CID$1.asCID(n)))if(Array.isArray(n))for(const[t,r]of n.entries()){const n=[...e,t];yield n.join("/"),"object"!=typeof r||CID$1.asCID(r)||(yield*tree(r,n))}else yield*tree(n,e)}},get=(e,t)=>{let r=e;for(const[n,o]of t.entries()){if(r=r[o],null==r)throw new Error(`Object has no property at ${t.slice(0,n+1).map((e=>`[${JSON.stringify(e)}]`)).join("")}`);const e=CID$1.asCID(r);if(e)return{value:e,remaining:t.slice(n+1).join("/")}}return{value:r}};class Block{constructor({cid:e,bytes:t,value:r}){if(!e||!t||void 0===r)throw new Error("Missing required argument");this.cid=e,this.bytes=t,this.value=r,this.asBlock=this,Object.defineProperties(this,{cid:readonly(),bytes:readonly(),value:readonly(),asBlock:readonly()})}links(){return links(this.value,[])}tree(){return tree(this.value,[])}get(e="/"){return get(this.value,e.split("/").filter(Boolean))}}class TreewalkCarSplitter{constructor(e,t,r={}){if("number"!=typeof t||t<=0)throw new Error("invalid target chunk size");this._reader=e,this._targetSize=t,this._decoders=[pb,raw$2,cbor,...r.decoders||[]]}async*cars(){const e=await this._reader.getRoots();if(1!==e.length)throw new Error(`unexpected number of roots: ${e.length}`);let t;for await(const r of this._cars(e[0]))t=r.channel,r.out&&(yield r.out);if(!t)throw new Error("missing CAR writer channel");t.writer.close(),yield t.out}async _get(e){const t=await this._reader.get(e);if(!t)throw new Error(`missing block for ${e}`);const{bytes:r}=t,n=this._decoders.find((t=>t.code===e.code));if(!n)throw new Error(`missing decoder for ${e.code}`);return new Block({cid:e,bytes:r,value:n.decode(r)})}async*_cars(e,t=[],r){const n=await this._get(e);if((r=r||Object.assign(CarWriter.create(e),{size:0})).size>0&&r.size+n.bytes.byteLength>=this._targetSize){r.writer.close();const{out:e}=r;r=newCar(t),yield{channel:r,out:e}}t=t.concat(n),r.size+=n.bytes.byteLength,r.writer.put(n);for(const[,o]of n.links())for await(const e of this._cars(o,t,r))r=e.channel,yield e;if(!r)throw new Error("missing CAR writer channel");yield{channel:r}}static async fromIterable(e,t,r){const n=await CarReader.fromIterable(e);return new TreewalkCarSplitter(n,t,r)}static async fromBlob(e,t,r){const n=await e.arrayBuffer(),o=await CarReader.fromBytes(new Uint8Array(n));return new TreewalkCarSplitter(o,t,r)}}function newCar(e){const t=Object.assign(CarWriter.create(e[0].cid),{size:e.reduce(((e,t)=>e+t.bytes.byteLength),0)});for(const r of e)t.writer.put(r);return t}const fetch=globalThis.fetch,Blob$1=globalThis.Blob,File=globalThis.File,Blockstore=MemoryBlockStore,MAX_PUT_RETRIES=5,MAX_CONCURRENT_UPLOADS=3,MAX_CHUNK_SIZE=10485760;class Web3Storage{constructor({token:e,endpoint:t=new URL("https://api.web3.storage")}){this.token=e,this.endpoint=t}static headers(e){if(!e)throw new Error("missing token");return{Authorization:`Bearer ${e}`,"X-Client":"web3.storage"}}static async put({endpoint:e,token:t},r,{onRootCidReady:n,onStoredChunk:o,maxRetries:i=MAX_PUT_RETRIES,wrapWithDirectory:s=!0,name:a}={}){const c=new Blockstore;try{const{out:u,root:l}=await pack({input:Array.from(r).map((e=>({path:e.name,content:e.stream()}))),blockstore:c,wrapWithDirectory:s,maxChunkSize:1048576,maxChildrenPerNode:1024});n&&n(l.toString());const f=await CarReader.fromIterable(u);return await Web3Storage.putCar({endpoint:e,token:t},f,{onStoredChunk:o,maxRetries:i,name:a})}finally{await c.close()}}static async putCar({endpoint:e,token:t},r,{name:n,onStoredChunk:o,maxRetries:i=MAX_PUT_RETRIES,decoders:s}={}){const a=MAX_CHUNK_SIZE,c=new URL("/car",e);let u=Web3Storage.headers(t);n&&(u=__spreadProps(__spreadValues({},u),{"X-Name":n}));const l=await r.getRoots();if(null==l[0])throw new Error("missing root CID");if(l.length>1)throw new Error("too many roots");const f=l[0].toString(),h=new TreewalkCarSplitter(r,a,{decoders:s}),d=transform(MAX_CONCURRENT_UPLOADS,(async e=>{const t=[];for await(const o of e)t.push(o);const r=new Blob$1(t,{type:"application/car"}),n=await pRetry$1((async()=>{const e=await fetch(c.toString(),{method:"POST",headers:u,body:r}),t=await e.json();if(!e.ok)throw new Error(t.message);if(t.cid!==f)throw new Error(`root CID mismatch, expected: ${f}, received: ${t.cid}`);return t.cid}),{retries:i});return o&&o(r.size),n}));for await(const p of d(h.cars()));return f}static async get({endpoint:e,token:t},r){const n=new URL(`/car/${r}`,e);return toWeb3Response(await fetch(n.toString(),{method:"GET",headers:Web3Storage.headers(t)}))}static async delete({endpoint:e,token:t},r){throw console.log("Not deleting",r,e,t),Error(".delete not implemented yet")}static async status({endpoint:e,token:t},r){const n=new URL(`/status/${r}`,e),o=await fetch(n.toString(),{method:"GET",headers:Web3Storage.headers(t)});if(404!==o.status){if(!o.ok)throw new Error(o.statusText);return o.json()}}static async*list(e,{before:t=(new Date).toISOString(),maxResults:r=1/0}={}){let n=0;const o=r>100?100:r;for await(const i of paginator((function({endpoint:e,token:t},{before:r,size:n}){const o=new URLSearchParams({before:r,size:n.toString()}),i=new URL(`/user/uploads?${o}`,e);return fetch(i.toString(),{method:"GET",headers:__spreadProps(__spreadValues({},Web3Storage.headers(t)),{"Access-Control-Request-Headers":"Link"})})}),e,{before:t,size:o})){if(!i.ok)throw new Error(`${i.status} ${i.statusText}`);const e=await i.json();for(const t of e){if(++n>r)return;yield t}}}put(e,t){return Web3Storage.put(this,e,t)}putCar(e,t){return Web3Storage.putCar(this,e,t)}get(e){return Web3Storage.get(this,e)}delete(e){return Web3Storage.delete(this,e)}status(e){return Web3Storage.status(this,e)}list(e){return Web3Storage.list(this,e)}}async function toWeb3File({content:e,path:t,cid:r}){const n=[];for await(const i of e())n.push(i);const o=new File(n,toFilenameWithPath(t));return Object.assign(o,{cid:r.toString()})}function toFilenameWithPath(e){const t=e.indexOf("/");return-1===t?e:e.substring(t+1)}function toWeb3Response(e){const t=Object.assign(e,{unixFsIterator:async function*(){if(!e.ok)throw new Error(`Response was not ok: ${e.status} ${e.statusText} - Check for { "ok": false } on the Response object before calling .unixFsIterator`);if(!e.body)throw new Error("No body on response");const t=new Blockstore;try{for await(const r of unpackStream(e.body,{blockstore:t}))yield r}finally{await t.close()}},files:async()=>{if(!e.ok)throw new Error(`Response was not ok: ${e.status} ${e.statusText} - Check for { "ok": false } on the Response object before calling .files`);const r=[];for await(const e of t.unixFsIterator()){if("directory"===e.type)continue;const t=await toWeb3File(e);r.push(t)}return r}});return t}async function*paginator(e,t,r){let n=await e(t,r);yield n;let o=parseLinkHeader(n.headers.get("Link")||"");for(;o&&o.next;)n=await e(t,o.next),yield n,o=parseLinkHeader(n.headers.get("Link")||"")}export{Web3Storage as W};