nft.storage
Version:
A client library for the https://nft.storage/ service. It provides a convenient interface for working with the HTTP API from a web browser or Node.js
1 lines • 221 kB
JavaScript
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(e){s=!0,u=e}c--,l(),f()}(r)}catch(e){s=!0,c--,u=e,l()}a=!1,f()}}const d={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]:()=>d};return d}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 getDefaultExportFromCjs(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}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;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<this._errors.length;n++){var o=this._errors[n],i=o.message,s=(e[i]||0)+1;e[i]=s,s>=r&&(t=o,r=s)}return t},function(e){var t=retry_operation;e.operation=function(r){var n=e.timeouts(r);return new t(n,{forever:r&&(r.forever||r.retries===1/0),unref:r&&r.unref,maxRetryTime:r&&r.maxRetryTime})},e.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<t.retries;o++)n.push(this.createTimeout(o,t));return e&&e.forever&&!n.length&&n.push(this.createTimeout(o,t)),n.sort((function(e,t){return e-t})),n},e.createTimeout=function(e,t){var r=t.randomize?Math.random()+1:1,n=Math.round(r*Math.max(t.minTimeout,1)*Math.pow(t.factor,e));return n=Math.min(n,t.maxTimeout)},e.wrap=function(t,r,n){if(r instanceof Array&&(n=r,r=null),!n)for(var o in n=[],t)"function"==typeof t[o]&&n.push(o);for(var i=0;i<n.length;i++){var s=n[i],a=t[s];t[s]=function(n){var o=e.operation(r),i=Array.prototype.slice.call(arguments,1),s=i.pop();i.push((function(e){o.retry(e)||(e&&(arguments[0]=o.mainError()),s.apply(this,arguments))})),o.attempt((function(){n.apply(t,i)}))}.bind(t,a),t[s].options=r}}}(retry$2);var retry$1=retry$2;const retry=retry$1,networkErrorMsgs=["Failed to fetch","NetworkError when attempting to fetch resource.","The Internet connection appears to be offline.","Network request failed"];class AbortError extends Error{constructor(e){super(),e instanceof Error?(this.originalError=e,({message:e}=e)):(this.originalError=new Error(e),this.originalError.stack=this.stack),this.name="AbortError",this.message=e}}const decorateErrorWithCounts=(e,t,r)=>{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={onFailedAttempt:()=>{},retries:10,...t};const o=retry.operation(t);o.attempt((async i=>{try{r(await e(i))}catch(e){if(!(e instanceof Error))return void n(new TypeError(`Non-error was thrown: "${e}". You should only throw errors.`));if(e instanceof AbortError)o.stop(),n(e.originalError);else if(e instanceof TypeError&&!isNetworkError(e.message))o.stop(),n(e);else{decorateErrorWithCounts(e,i,t);try{await t.onFailedAttempt(e)}catch(e){return void n(e)}o.retry(e)||n(o.mainError())}}}))}));pRetry$2.exports=pRetry,pRetry$2.exports.default=pRetry;var AbortError_1=pRetry$2.exports.AbortError=AbortError,pRetry$1=pRetry$2.exports,encode_1$1=encode$c,MSB$3=128,REST$3=127,MSBALL$1=~REST$3,INT$1=Math.pow(2,31);function encode$c(e,t,r){if(Number.MAX_SAFE_INTEGER&&e>Number.MAX_SAFE_INTEGER)throw encode$c.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$c.bytes=r-n+1,t}var decode$d=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)<<o:(r&REST$2)*Math.pow(2,o),o+=7}while(r>=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<N1$1?1:e<N2$1?2:e<N3$1?3:e<N4$1?4:e<N5$1?5:e<N6$1?6:e<N7$1?7:e<N8$1?8:e<N9$1?9:10},varint$1={encode:encode_1$1,decode:decode$d,encodingLength:length$1},encode_1=encode$b,MSB=128,REST=127,MSBALL=~REST,INT=Math.pow(2,31);function encode$b(e,t,r){t=t||[];for(var n=r=r||0;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$b.bytes=r-n+1,t}var decode$c=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)<<o:(r&REST$1)*Math.pow(2,o),o+=7}while(r>=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<N1?1:e<N2?2:e<N3?3:e<N4?4:e<N5?5:e<N6?6:e<N7?7:e<N8?8:e<N9?9:10},varint={encode:encode_1,decode:decode$c,encodingLength:length},_brrp_varint=varint;const decode$b=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$1=(e,t)=>{if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0},coerce=e=>{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$5=(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(e,r,t,i)},decode$a=e=>{const t=coerce(e),[r,n]=decode$b(t),[o,i]=decode$b(t.subarray(n)),s=t.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Digest(r,o,s,t)},equals=(e,t)=>e===t||e.code===t.code&&e.size===t.size&&equals$1(e.bytes,t.bytes);class Digest{constructor(e,t,r,n){this.code=e,this.size=t,this.digest=r,this.bytes=n}}function base(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var i=e.charAt(o),s=i.charCodeAt(0);if(255!==r[s])throw new TypeError(i+" is ambiguous");r[s]=o}var a=e.length,c=e.charAt(0),u=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function f(e){if("string"!=typeof e)throw new TypeError("Expected String");if(0===e.length)return new Uint8Array;var t=0;if(" "!==e[t]){for(var n=0,o=0;e[t]===c;)n++,t++;for(var i=(e.length-t)*u+1>>>0,s=new Uint8Array(i);e[t];){var l=r[e.charCodeAt(t)];if(255===l)return;for(var f=0,d=i-1;(0!==l||f<o)&&-1!==d;d--,f++)l+=a*s[d]>>>0,s[d]=l%256>>>0,l=l/256>>>0;if(0!==l)throw new Error("Non-zero carry");o=f,t++}if(" "!==e[t]){for(var h=i-o;h!==i&&0===s[h];)h++;for(var p=new Uint8Array(n+(i-h)),y=n;h!==i;)p[y++]=s[h++];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],d=0,h=s-1;(0!==f||d<n)&&-1!==h;h--,d++)f+=256*u[h]>>>0,u[h]=f%a>>>0,f=f/a>>>0;if(0!==f)throw new Error("Non-zero carry");n=d,o++}for(var p=s-n;p!==s&&0===u[p];)p++;for(var y=c.repeat(r);p<s;++p)y+=e.charAt(u[p]);return y},decodeUnsafe:f,decode:function(e){var r=f(e);if(r)return r;throw new Error(`Non-${t} character`)}}}var src$2=base,_brrp__multiformats_scope_baseX=src$2;class Encoder{constructor(e,t,r){this.name=e,this.prefix=t,this.baseEncode=r}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}}class Decoder{constructor(e,t,r){if(this.name=e,this.prefix=t,void 0===t.codePointAt(0))throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),this.baseDecode=r}decode(e){if("string"==typeof e){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}throw Error("Can only multibase decode strings")}or(e){return or(this,e)}}class ComposedDecoder{constructor(e){this.decoders=e}or(e){return or(this,e)}decode(e){const t=e[0],r=this.decoders[t];if(r)return r.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}}const or=(e,t)=>new ComposedDecoder({...e.decoders||{[e.prefix]:e},...t.decoders||{[t.prefix]:t}});class Codec{constructor(e,t,r,n){this.name=e,this.prefix=t,this.baseEncode=r,this.baseDecode=n,this.encoder=new Encoder(e,t,r),this.decoder=new Decoder(e,t,n)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}}const from$1=({name:e,prefix:t,encode:r,decode:n})=>new 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$9=(e,t,r,n)=>{const o={};for(let e=0;e<t.length;++e)o[t[e]]=e;let i=e.length;for(;"="===e[i-1];)--i;const s=new Uint8Array(i*r/8|0);let a=0,c=0,u=0;for(let t=0;t<i;++t){const i=o[e[t]];if(void 0===i)throw new SyntaxError(`Non-${n} character`);c=c<<r|i,a+=r,a>=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$a=(e,t,r)=>{const n="="===t[t.length-1],o=(1<<r)-1;let i="",s=0,a=0;for(let n=0;n<e.length;++n)for(a=a<<8|e[n],s+=8;s>r;)s-=r,i+=t[o&a>>s];if(s&&(i+=t[o&a<<r-s]),n)for(;i.length*r&7;)i+="=";return i},rfc4648=({name:e,prefix:t,bitsPerChar:r,alphabet:n})=>from$1({prefix:t,name:e,encode:e=>encode$a(e,n,r),decode:t=>decode$9(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,base58btc:base58btc,base58flickr:base58flickr});const base32=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$1=Object.freeze({__proto__:null,base32:base32,base32upper:base32upper,base32pad:base32pad,base32padupper:base32padupper,base32hex:base32hex,base32hexupper:base32hexupper,base32hexpad:base32hexpad,base32hexpadupper:base32hexpadupper,base32z:base32z});class CID{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(){if(0===this.version)return this;{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.createV0(t)}}toV1(){switch(this.version){case 0:{const{code:e,digest:t}=this.multihash,r=create$5(e,t);return CID.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(this.multihash,e.multihash)}toString(e){const{bytes:t,version:r,_baseCache:n}=this;return 0===r?toStringV0(t,n,e||base58btc.encoder):toStringV1(t,n,e||base32.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)return e;if(null!=e&&e.asCID===e){const{version:t,code:r,multihash:n,bytes:o}=e;return new CID(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$a(r);return CID.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(e,t,r,r.bytes);case 1:{const n=encodeCID(e,t,r.bytes);return new CID(e,t,r,n)}default:throw new Error("Invalid version")}}static createV0(e){return CID.create(0,DAG_PB_CODE,e)}static createV1(e,t){return CID.create(1,e,t)}static decode(e){const[t,r]=CID.decodeFirst(e);if(r.length)throw new Error("Incorrect length");return t}static decodeFirst(e){const t=CID.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(t.multihashCode,t.digestSize,o,n);return[0===t.version?CID.createV0(i):CID.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0;const r=()=>{const[r,n]=decode$b(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.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.prefix:{const r=t||base32;return[base32.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",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.major<e.major?-1:this.major>e.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$1{constructor(e,t,r){this.type=e,this.value=t,this.encodedLength=r,this.encodedBytes=void 0,this.byteValue=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 t of e)n+t.length>r.length&&(t=t.subarray(0,r.length-n)),r.set(t,n),n+=t.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;r<e.length;r++)if(e[r]!==t[r])return e[r]<t[r]?-1:1;return 0}function utf8ToBytes(e,t=1/0){let r;const n=e.length;let o=null;const i=[];for(let s=0;s<n;++s){if(r=e.charCodeAt(s),r>55295&&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(;t<r;){const o=e[t];let i=null,s=o>239?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(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=MAX_ARGUMENTS_LENGTH));return r}const defaultChunkSize=256;class Bl{constructor(e=defaultChunkSize){this.chunkSize=e,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),null!==this._initReuseChunk&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(e){let t=this.chunks[this.chunks.length-1];if(this.cursor+e.length<=this.maxCursor+1){const r=t.length-(this.maxCursor-this.cursor)-1;t.set(e,r)}else{if(t){const e=t.length-(this.maxCursor-this.cursor)-1;e<t.length&&(this.chunks[this.chunks.length-1]=t.subarray(0,e),this.maxCursor=this.cursor-1)}e.length<64&&e.length<this.chunkSize?(t=alloc(this.chunkSize),this.chunks.push(t),this.maxCursor+=t.length,null===this._initReuseChunk&&(this._initReuseChunk=t),t.set(e,0)):(this.chunks.push(e),this.maxCursor+=e.length)}this.cursor+=e.length}toBytes(e=!1){let t;if(1===this.chunks.length){const r=this.chunks[0];e&&this.cursor>r.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<r)throw new Error(`${decodeErrPrefix} not enough data for type`)}const uintBoundaries=[24,256,65536,4294967296,BigInt("18446744073709551616")];function readUint8(e,t,r){assertEnoughData(e,t,1);const n=e[t];if(!0===r.strict&&n<uintBoundaries[0])throw new Error(`${decodeErrPrefix} integer encoded in more bytes than necessary (strict decode)`);return n}function readUint16(e,t,r){assertEnoughData(e,t,2);const n=e[t]<<8|e[t+1];if(!0===r.strict&&n<uintBoundaries[1])throw new Error(`${decodeErrPrefix} integer encoded in more bytes than necessary (strict decode)`);return n}function readUint32(e,t,r){assertEnoughData(e,t,4);const n=16777216*e[t]+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];if(!0===r.strict&&n<uintBoundaries[2])throw new Error(`${decodeErrPrefix} integer encoded in more bytes than necessary (strict decode)`);return n}function readUint64(e,t,r){assertEnoughData(e,t,8);const n=16777216*e[t]+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3],o=16777216*e[t+4]+(e[t+5]<<16)+(e[t+6]<<8)+e[t+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(!0===r.strict&&i<uintBoundaries[3])throw new Error(`${decodeErrPrefix} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(!0===r.allowBigInt)return i;throw new Error(`${decodeErrPrefix} integers outside of the safe integer range are not supported`)}function decodeUint8(e,t,r,n){return new Token$1(Type.uint,readUint8(e,t+1,n),2)}function decodeUint16(e,t,r,n){return new Token$1(Type.uint,readUint16(e,t+1,n),3)}function decodeUint32(e,t,r,n){return new Token$1(Type.uint,readUint32(e,t+1,n),5)}function decodeUint64(e,t,r,n){return new Token$1(Type.uint,readUint64(e,t+1,n),9)}function encodeUint(e,t){return encodeUintValue(e,0,t.value)}function encodeUintValue(e,t,r){if(r<uintBoundaries[0]){const n=Number(r);e.push([t|n])}else if(r<uintBoundaries[1]){const n=Number(r);e.push([24|t,n])}else if(r<uintBoundaries[2]){const n=Number(r);e.push([25|t,n>>>8,255&n])}else if(r<uintBoundaries[3]){const n=Number(r);e.push([26|t,n>>>24&255,n>>>16&255,n>>>8&255,255&n])}else{const n=BigInt(r);if(!(n<uintBoundaries[4]))throw new Error(`${decodeErrPrefix} encountered BigInt larger than allowable range`);{const r=[27|t,0,0,0,0,0,0,0];let o=Number(n&BigInt(4294967295)),i=Number(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$1(Type.negint,-1-readUint8(e,t+1,n),2)}function decodeNegint16(e,t,r,n){return new Token$1(Type.negint,-1-readUint16(e,t+1,n),3)}function decodeNegint32(e,t,r,n){return new Token$1(Type.negint,-1-readUint32(e,t+1,n),5)}encodeUint.encodedSize=function(e){return encodeUintValue.encodedSize(e.value)},encodeUintValue.encodedSize=function(e){return e<uintBoundaries[0]?1:e<uintBoundaries[1]?2:e<uintBoundaries[2]?3:e<uintBoundaries[3]?5:9},encodeUint.compareTokens=function(e,t){return e.value<t.value?-1:e.value>t.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$1(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$1(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$1(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.length<t.length?-1:e.length>t.length?1:compare(e,t)}function toToken$2(e,t,r,n,o){const i=r+n;assertEnoughData(e,t,i);const s=new Token$1(Type.string,toString(e,t+r,t+i),i);return!0===o.retainStringBytes&&(s.byteValue=slice(e,t+r,t+i)),s}function decodeStringCompact(e,t,r,n){return toToken$2(e,t,1,r,n)}function decodeString8(e,t,r,n){return toToken$2(e,t,2,readUint8(e,t+1,n),n)}function decodeString16(e,t,r,n){return toToken$2(e,t,3,readUint16(e,t+1,n),n)}function decodeString32(e,t,r,n){return toToken$2(e,t,5,readUint32(e,t+1,n),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,n)}encodeNegint.encodedSize=function(e){const t=e.value,r="bigint"==typeof t?t*neg1b-pos1b:-1*t-1;return r<uintBoundaries[0]?1:r<uintBoundaries[1]?2:r<uintBoundaries[2]?3:r<uintBoundaries[3]?5:9},encodeNegint.compareTokens=function(e,t){return e.value<t.value?1:e.value>t.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$1(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$1(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$1(Type.tag,r,1)}function decodeTag8(e,t,r,n){return new Token$1(Type.tag,readUint8(e,t+1,n),2)}function decodeTag16(e,t,r,n){return new Token$1(Type.tag,readUint16(e,t+1,n),3)}function decodeTag32(e,t,r,n){return new Token$1(Type.tag,readUint32(e,t+1,n),5)}function decodeTag64(e,t,r,n){return new Token$1(Type.tag,readUint64(e,t+1,n),9)}function encodeTag(e,t){encodeUintValue(e,Type.tag.majorEncoded,t.value)}encodeArray.compareTokens=encodeUint.compareTokens,encodeArray.encodedSize=function(e){return encodeUintValue.encodedSize(e.value)},encodeMap.compareTokens=encodeUint.compareTokens,encodeMap.encodedSize=function(e){return encodeUintValue.encodedSize(e.value)},encodeTag.compareTokens=encodeUint.compareTokens,encodeTag.encodedSize=function(e){return encodeUintValue.encodedSize(e.value)};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!0===n.coerceUndefinedToNull?new Token$1(Type.null,null,1):new Token$1(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$1(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$1(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;if(!t||!0!==t.float64){encodeFloat16(r);let e=readFloat16(ui8a,1);if(r===e||Number.isNaN(r))return 3;if(encodeFloat32(r),e=readFloat32(ui8a,1),r===e)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$1(Type.uint,e,1);for(let e=-1;e>=-24;e--)quick[31-e]=new Token$1(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$1(Type.bytes,new Uint8Array(0),1),quick[96]=new Token$1(Type.string,"",1),quick[128]=new Token$1(Type.array,0,1),quick[160]=new Token$1(Type.map,0,1),quick[244]=new Token$1(Type.false,!1,1),quick[245]=new Token$1(Type.true,!0,1),quick[246]=new Token$1(Type.null,null,1);const defaultEncodeOptions={float64:!1,mapSorter:mapSorter,quickEncodeToken:quickEncodeToken};function makeCborEncoders(){const e=[];return e[Type.uint.major]=encodeUint,e[Type.negint.major]=encodeNegint,e[Type.bytes.major]=encodeBytes,e[Type.string.major]=encodeString,e[Type.array.major]=encodeArray,e[Type.map.major]=encodeMap,e[Type.tag.major]=encodeTag,e[Type.float.major]=encodeFloat,e}const cborEncoders=makeCborEncoders(),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$1(Type.null,null),undefined:new Token$1(Type.undefined,void 0),true:new Token$1(Type.true,!0),false:new Token$1(Type.false,!1),emptyArray:new Token$1(Type.array,0),emptyMap:new Token$1(Type.map,0)},typeEncoders={number:(e,t,r,n)=>Number.isInteger(e)&&Number.isSafeInteger(e)?new Token$1(e>=0?Type.uint:Type.negint,e):new Token$1(Type.float,e),bigint:(e,t,r,n)=>e>=BigInt(0)?new Token$1(Type.uint,e):new Token$1(Type.negint,e),Uint8Array:(e,t,r,n)=>new Token$1(Type.bytes,e),string:(e,t,r,n)=>new Token$1(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$1(Type.bytes,new Uint8Array(e)),DataView:(e,t,r,n)=>new Token$1(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$1(Type.break)]:simpleTokens.emptyArray;n=Ref.createCheck(n,e);const o=[];let i=0;for(const t of e)o[i++]=objectToTokens(t,r,n);return r.addBreakTokens?[new Token$1(Type.array,e.length),o,new Token$1(Type.break)]:[new Token$1(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$1(Type.break)]:simpleTokens.emptyMap;n=Ref.createCheck(n,e);const a=[];let c=0;for(const t of i)a[c++]=[objectToTokens(t,r,n),objectToTokens(o?e.get(t):e[t],r,n)];return sortMapEntries(a,r),r.addBreakTokens?[new Token$1(Type.map,s),a,new Token$1(Type.break)]:[new Token$1(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 buf.reset(),tokensToEncoded(buf,n,t,r),buf.toBytes(!0)}function encode$9(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;o<e.value;o++){const i=tokensToObject(t,r);if(i===BREAK){if(e.value===1/0)break;throw new Error(`${decodeErrPrefix} got unexpected break to lengthed array`)}if(i===DONE)throw new Error(`${decodeErrPrefix} found array but not enough entries (got ${o}, expected ${e.value})`);n[o]=i}return n}function tokenToMap(e,t,r){const n=!0===r.useMaps,o=n?void 0:{},i=n?new Map:void 0;for(let s=0;s<e.value;s++){const a=tokensToObject(t,r);if(a===BREAK){if(e.value===1/0)break;throw new Error(`${decodeErrPrefix} got unexpected break to lengthed map`)}if(a===DONE)throw new Error(`${decodeErrPrefix} found map but not enough entries (got ${s} [no key], expected ${e.value})`);if(!0!==n&&"string"!=typeof a)throw new Error(`${decodeErrPrefix} non-string keys not supported (got ${typeof a})`);const c=tokensToObject(t,r);if(c===DONE)throw new Error(`${decodeErrPrefix} found map but not enough entries (got ${s} [no value], expected ${e.value})`);n?i.set(a,c):o[a]=c}return n?i:o}function tokensToObject(e,t){if(e.done())return DONE;const r=e.next();if(r.type===Type.break)return BREAK;if(r.type.terminal)return r.value;if(r.type===Type.array)return tokenToArray(r,e,t);if(r.type===Type.map)return tokenToMap(r,e,t);if(r.type===Type.tag){if(t.tags&&"function"==typeof t.tags[r.value]){const n=tokensToObject(e,t);return t.tags[r.value](n)}throw new Error(`${decodeErrPrefix} tag not supported (${r.value})`)}throw new Error("unsupported")}function decode$8(e,t){if(!(e instanceof Uint8Array))throw new Error(`${decodeErrPrefix} data to decode must be a Uint8Array`);const r=(t=Object.assign({},defaultDecodeOptions,t)).tokenizer||new Tokeniser(e,t),n=tokensToObject(r,t);if(n===DONE)throw new Error(`${decodeErrPrefix} did not find any content to decode`);if(n===BREAK)throw new Error(`${decodeErrPrefix} got unexpected break`);if(!r.done())throw new Error(`${decodeErrPrefix} too many terminals, data makes no sense`);return n}const CID_CBOR_TAG$3=42;function cidEncoder$3(e){if(e.asCID!==e)return null;const t=CID.asCID(e);if(!t)return null;const r=new Uint8Array(t.bytes.byteLength+1);return r.set(t.bytes,1),[new Token$1(Type.tag,CID_CBOR_TAG$3),new Token$1(Type.bytes,r)]}function undefinedEncoder$3(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function numberEncoder$3(e){if(Number.isNaN(e))throw new Error("`NaN` is not supported by the IPLD Data Model and cannot be encoded");if(e===1/0||e===-1/0)throw new Error("`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded");return null}const encodeOptions$3={float64:!0,typeEncoders:{Object:cidEncoder$3,undefined:undefinedEncoder$3,number:numberEncoder$3}};function cidDecoder$3(e){if(0!==e[0])throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return CID.decode(e.subarray(1))}const decodeOptions$3={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,tags:[]};decodeOptions$3.tags[CID_CBOR_TAG$3]=cidDecoder$3;const encode$8=e=>encode$9(e,encodeOptions$3),decode$7=e=>decode$8(e,decodeOptions$3),CIDV0_BYTES={SHA2_256:18,LENGTH:32,DAG_PB:112};async function readVarint$1(e){const t=await e.upTo(8),r=varint$1.decode(t);return e.seek(varint$1.decode.bytes),r}async function readHeader$1(e){const t=await readVarint$1(e);if(0===t)throw new Error("Invalid CAR header (zero length)");const r=await e.exactly(t);e.seek(t);const n=decode$7(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$a(t);return CID.create(0,CIDV0_BYTES.DAG_PB,r)}const r=await readVarint$1(e);if(1!==r)throw new Error(`Unexpected CID version