UNPKG

@ipld/dag-cbor

Version:

JS implementation of DAG-CBOR

5 lines (4 loc) 37.5 kB
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.IpldDagCbor = factory()}(typeof self !== 'undefined' ? self : this, function () { "use strict";var IpldDagCbor=(()=>{var De=Object.defineProperty;var Tr=Object.getOwnPropertyDescriptor;var kr=Object.getOwnPropertyNames;var Br=Object.prototype.hasOwnProperty;var Sr=(e,t)=>{for(var r in t)De(e,r,{get:t[r],enumerable:!0})},Ir=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of kr(t))!Br.call(e,o)&&o!==r&&De(e,o,{get:()=>t[o],enumerable:!(n=Tr(t,o))||n.enumerable});return e};var _r=e=>Ir(De({},"__esModule",{value:!0}),e);var no={};Sr(no,{code:()=>eo,decode:()=>ro,decodeOptions:()=>Yn,encode:()=>to,encodeOptions:()=>Wn,name:()=>Zn,toByteView:()=>Ar});var Nr=["Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array","Tagged"];function ze(e){if(e===null)return"null";if(e===void 0)return"undefined";if(e===!0||e===!1)return"boolean";let t=typeof e;if(t==="string"||t==="number"||t==="bigint"||t==="symbol")return t;if(t==="function")return"Function";if(Array.isArray(e))return"Array";if(e instanceof Uint8Array)return"Uint8Array";if(e.constructor===Object)return"Object";let r=Cr(e);return r||"Object"}function Cr(e){let t=Object.prototype.toString.call(e).slice(8,-1);if(Nr.includes(t))return t}var i=class{constructor(t,r,n){this.major=t,this.majorEncoded=t<<5,this.name=r,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(t){return this.major<t.major?-1:this.major>t.major?1:0}static equals(t,r){return t===r||t.major===r.major&&t.name===r.name}};i.uint=new i(0,"uint",!0);i.negint=new i(1,"negint",!0);i.bytes=new i(2,"bytes",!0);i.string=new i(3,"string",!0);i.array=new i(4,"array",!1);i.map=new i(5,"map",!1);i.tag=new i(6,"tag",!1);i.float=new i(7,"float",!0);i.false=new i(7,"false",!0);i.true=new i(7,"true",!0);i.null=new i(7,"null",!0);i.undefined=new i(7,"undefined",!0);i.break=new i(7,"break",!0);var u=class{constructor(t,r,n){this.type=t,this.value=r,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var ie=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",$r=new TextEncoder;function Ee(e){return ie&&globalThis.Buffer.isBuffer(e)}function se(e){return e instanceof Uint8Array?Ee(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e:Uint8Array.from(e)}var Mr=24,Or=200,ve=ie?e=>e.length>=Mr?globalThis.Buffer.from(e):nt(e):e=>e.length>=Or?$r.encode(e):nt(e),M=e=>Uint8Array.from(e),ot=ie?(e,t,r)=>Ee(e)?new Uint8Array(e.subarray(t,r)):e.slice(t,r):(e,t,r)=>e.slice(t,r),it=ie?(e,t)=>(e=e.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),se(globalThis.Buffer.concat(e,t))):(e,t)=>{let r=new Uint8Array(t),n=0;for(let o of e)n+o.length>r.length&&(o=o.subarray(0,r.length-n)),r.set(o,n),n+=o.length;return r},st=ie?e=>globalThis.Buffer.allocUnsafe(e):e=>new Uint8Array(e);function Ae(e,t){if(Ee(e)&&Ee(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 nt(e){let t=[],r=0;for(let n=0;n<e.length;n++){let o=e.charCodeAt(n);o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&n+1<e.length&&(e.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(e.charCodeAt(++n)&1023),t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(o>=55296&&o<=57343&&(o=65533),t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128)}return t}var Dr=256,ce=class{constructor(t=Dr){this.chunkSize=t,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(t){let r=this.chunks[this.chunks.length-1];if(this.cursor+t.length<=this.maxCursor+1){let o=r.length-(this.maxCursor-this.cursor)-1;r.set(t,o)}else{if(r){let o=r.length-(this.maxCursor-this.cursor)-1;o<r.length&&(this.chunks[this.chunks.length-1]=r.subarray(0,o),this.maxCursor=this.cursor-1)}t.length<64&&t.length<this.chunkSize?(r=st(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r),r.set(t,0)):(this.chunks.push(t),this.maxCursor+=t.length)}this.cursor+=t.length}toBytes(t=!1){let r;if(this.chunks.length===1){let n=this.chunks[0];t&&this.cursor>n.length/2?(r=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):r=ot(n,0,this.cursor)}else r=it(this.chunks,this.cursor);return t&&this.reset(),r}},Ue=class{constructor(t){this.dest=t,this.cursor=0,this.chunks=[t]}reset(){this.cursor=0}push(t){if(this.cursor+t.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(t,this.cursor),this.cursor+=t.length}toBytes(t=!1){let r=this.dest.subarray(0,this.cursor);return t&&this.reset(),r}};var f="CBOR decode error:",Te="CBOR encode error:",ae=[];ae[23]=1;ae[24]=2;ae[25]=3;ae[26]=5;ae[27]=9;function F(e,t,r){if(e.length-t<r)throw new Error(`${f} not enough data for type`)}var g=[24,256,65536,4294967296,BigInt("18446744073709551616")];function w(e,t,r){F(e,t,1);let n=e[t];if(r.strict===!0&&n<g[0])throw new Error(`${f} integer encoded in more bytes than necessary (strict decode)`);return n}function b(e,t,r){F(e,t,2);let n=e[t]<<8|e[t+1];if(r.strict===!0&&n<g[1])throw new Error(`${f} integer encoded in more bytes than necessary (strict decode)`);return n}function E(e,t,r){F(e,t,4);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];if(r.strict===!0&&n<g[2])throw new Error(`${f} integer encoded in more bytes than necessary (strict decode)`);return n}function v(e,t,r){F(e,t,8);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3],o=e[t+4]*16777216+(e[t+5]<<16)+(e[t+6]<<8)+e[t+7],s=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&s<g[3])throw new Error(`${f} integer encoded in more bytes than necessary (strict decode)`);if(s<=Number.MAX_SAFE_INTEGER)return Number(s);if(r.allowBigInt===!0)return s;throw new Error(`${f} integers outside of the safe integer range are not supported`)}function ct(e,t,r,n){return new u(i.uint,w(e,t+1,n),2)}function at(e,t,r,n){return new u(i.uint,b(e,t+1,n),3)}function ut(e,t,r,n){return new u(i.uint,E(e,t+1,n),5)}function ft(e,t,r,n){return new u(i.uint,v(e,t+1,n),9)}function U(e,t){return y(e,0,t.value)}function y(e,t,r){if(r<g[0]){let n=Number(r);e.push([t|n])}else if(r<g[1]){let n=Number(r);e.push([t|24,n])}else if(r<g[2]){let n=Number(r);e.push([t|25,n>>>8,n&255])}else if(r<g[3]){let n=Number(r);e.push([t|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(r);if(n<g[4]){let o=[t|27,0,0,0,0,0,0,0],s=Number(n&BigInt(4294967295)),c=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=s&255,s=s>>8,o[7]=s&255,s=s>>8,o[6]=s&255,s=s>>8,o[5]=s&255,o[4]=c&255,c=c>>8,o[3]=c&255,c=c>>8,o[2]=c&255,c=c>>8,o[1]=c&255,e.push(o)}else throw new Error(`${f} encountered BigInt larger than allowable range`)}}U.encodedSize=function(t){return y.encodedSize(t.value)};y.encodedSize=function(t){return t<g[0]?1:t<g[1]?2:t<g[2]?3:t<g[3]?5:9};U.compareTokens=function(t,r){return t.value<r.value?-1:t.value>r.value?1:0};function dt(e,t,r,n){return new u(i.negint,-1-w(e,t+1,n),2)}function lt(e,t,r,n){return new u(i.negint,-1-b(e,t+1,n),3)}function pt(e,t,r,n){return new u(i.negint,-1-E(e,t+1,n),5)}var Fe=BigInt(-1),ht=BigInt(1);function yt(e,t,r,n){let o=v(e,t+1,n);if(typeof o!="bigint"){let s=-1-o;if(s>=Number.MIN_SAFE_INTEGER)return new u(i.negint,s,9)}if(n.allowBigInt!==!0)throw new Error(`${f} integers outside of the safe integer range are not supported`);return new u(i.negint,Fe-BigInt(o),9)}function ke(e,t){let r=t.value,n=typeof r=="bigint"?r*Fe-ht:r*-1-1;y(e,t.type.majorEncoded,n)}ke.encodedSize=function(t){let r=t.value,n=typeof r=="bigint"?r*Fe-ht:r*-1-1;return n<g[0]?1:n<g[1]?2:n<g[2]?3:n<g[3]?5:9};ke.compareTokens=function(t,r){return t.value<r.value?1:t.value>r.value?-1:0};function ue(e,t,r,n){F(e,t,r+n);let o=e.slice(t+r,t+r+n);return new u(i.bytes,o,r+n)}function mt(e,t,r,n){return ue(e,t,1,r)}function gt(e,t,r,n){return ue(e,t,2,w(e,t+1,n))}function xt(e,t,r,n){return ue(e,t,3,b(e,t+1,n))}function wt(e,t,r,n){return ue(e,t,5,E(e,t+1,n))}function bt(e,t,r,n){let o=v(e,t+1,n);if(typeof o=="bigint")throw new Error(`${f} 64-bit integer bytes lengths not supported`);return ue(e,t,9,o)}function Be(e){return e.encodedBytes===void 0&&(e.encodedBytes=i.equals(e.type,i.string)?ve(e.value):e.value),e.encodedBytes}function K(e,t){let r=Be(t);y(e,t.type.majorEncoded,r.length),e.push(r)}K.encodedSize=function(t){let r=Be(t);return y.encodedSize(r.length)+r.length};K.compareTokens=function(t,r){return Fr(Be(t),Be(r))};function Fr(e,t){return e.length<t.length?-1:e.length>t.length?1:Ae(e,t)}var Et=new TextDecoder,Lr=32;function jr(e,t,r){if(r-t<Lr){let o="";for(let s=t;s<r;s++){let c=e[s];if(c&128)return Et.decode(e.subarray(t,r));o+=String.fromCharCode(c)}return o}return Et.decode(e.subarray(t,r))}function fe(e,t,r,n,o){let s=r+n;F(e,t,s);let c=new u(i.string,jr(e,t+r,t+s),s);return o.retainStringBytes===!0&&(c.byteValue=e.slice(t+r,t+s)),c}function vt(e,t,r,n){return fe(e,t,1,r,n)}function At(e,t,r,n){return fe(e,t,2,w(e,t+1,n),n)}function Ut(e,t,r,n){return fe(e,t,3,b(e,t+1,n),n)}function Tt(e,t,r,n){return fe(e,t,5,E(e,t+1,n),n)}function kt(e,t,r,n){let o=v(e,t+1,n);if(typeof o=="bigint")throw new Error(`${f} 64-bit integer string lengths not supported`);return fe(e,t,9,o,n)}var Bt=K;function X(e,t,r,n){return new u(i.array,n,r)}function St(e,t,r,n){return X(e,t,1,r)}function It(e,t,r,n){return X(e,t,2,w(e,t+1,n))}function _t(e,t,r,n){return X(e,t,3,b(e,t+1,n))}function Nt(e,t,r,n){return X(e,t,5,E(e,t+1,n))}function Ct(e,t,r,n){let o=v(e,t+1,n);if(typeof o=="bigint")throw new Error(`${f} 64-bit integer array lengths not supported`);return X(e,t,9,o)}function $t(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${f} indefinite length items not allowed`);return X(e,t,1,1/0)}function Se(e,t){y(e,i.array.majorEncoded,t.value)}Se.compareTokens=U.compareTokens;Se.encodedSize=function(t){return y.encodedSize(t.value)};function W(e,t,r,n){return new u(i.map,n,r)}function Mt(e,t,r,n){return W(e,t,1,r)}function Ot(e,t,r,n){return W(e,t,2,w(e,t+1,n))}function Dt(e,t,r,n){return W(e,t,3,b(e,t+1,n))}function zt(e,t,r,n){return W(e,t,5,E(e,t+1,n))}function Ft(e,t,r,n){let o=v(e,t+1,n);if(typeof o=="bigint")throw new Error(`${f} 64-bit integer map lengths not supported`);return W(e,t,9,o)}function Rt(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${f} indefinite length items not allowed`);return W(e,t,1,1/0)}function Ie(e,t){y(e,i.map.majorEncoded,t.value)}Ie.compareTokens=U.compareTokens;Ie.encodedSize=function(t){return y.encodedSize(t.value)};function Lt(e,t,r,n){return new u(i.tag,r,1)}function jt(e,t,r,n){return new u(i.tag,w(e,t+1,n),2)}function Vt(e,t,r,n){return new u(i.tag,b(e,t+1,n),3)}function Pt(e,t,r,n){return new u(i.tag,E(e,t+1,n),5)}function qt(e,t,r,n){return new u(i.tag,v(e,t+1,n),9)}function _e(e,t){y(e,i.tag.majorEncoded,t.value)}_e.compareTokens=U.compareTokens;_e.encodedSize=function(t){return y.encodedSize(t.value)};var Re=20,Le=21,je=22,Ve=23;function Gt(e,t,r,n){if(n.allowUndefined===!1)throw new Error(`${f} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new u(i.null,null,1):new u(i.undefined,void 0,1)}function Jt(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${f} indefinite length items not allowed`);return new u(i.break,void 0,1)}function Pe(e,t,r){if(r){if(r.allowNaN===!1&&Number.isNaN(e))throw new Error(`${f} NaN values are not supported`);if(r.allowInfinity===!1&&(e===1/0||e===-1/0))throw new Error(`${f} Infinity values are not supported`)}return new u(i.float,e,t)}function Ht(e,t,r,n){return Pe(qe(e,t+1),3,n)}function Kt(e,t,r,n){return Pe(Ge(e,t+1),5,n)}function Xt(e,t,r,n){return Pe(Zt(e,t+1),9,n)}function de(e,t,r){let n=t.value;if(n===!1)e.push([i.float.majorEncoded|Re]);else if(n===!0)e.push([i.float.majorEncoded|Le]);else if(n===null)e.push([i.float.majorEncoded|je]);else if(n===void 0)e.push([i.float.majorEncoded|Ve]);else{let o,s=!1;(!r||r.float64!==!0)&&(Qt(n),o=qe(S,1),n===o||Number.isNaN(n)?(S[0]=249,e.push(S.slice(0,3)),s=!0):(Yt(n),o=Ge(S,1),n===o&&(S[0]=250,e.push(S.slice(0,5)),s=!0))),s||(Jr(n),o=Zt(S,1),S[0]=251,e.push(S.slice(0,9)))}}de.encodedSize=function(t,r){let n=t.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!r||r.float64!==!0){Qt(n);let o=qe(S,1);if(n===o||Number.isNaN(n))return 3;if(Yt(n),o=Ge(S,1),n===o)return 5}return 9};var Wt=new ArrayBuffer(9),T=new DataView(Wt,1),S=new Uint8Array(Wt,0);function Qt(e){if(e===1/0)T.setUint16(0,31744,!1);else if(e===-1/0)T.setUint16(0,64512,!1);else if(Number.isNaN(e))T.setUint16(0,32256,!1);else{T.setFloat32(0,e);let t=T.getUint32(0),r=(t&2139095040)>>23,n=t&8388607;if(r===255)T.setUint16(0,31744,!1);else if(r===0)T.setUint16(0,(t&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?T.setUint16(0,0):o<-14?T.setUint16(0,(t&2147483648)>>16|1<<24+o,!1):T.setUint16(0,(t&2147483648)>>16|o+15<<10|n>>13,!1)}}}function qe(e,t){if(e.length-t<2)throw new Error(`${f} not enough data for float16`);let r=(e[t]<<8)+e[t+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,s;return n===0?s=o*2**-24:n!==31?s=(o+1024)*2**(n-25):s=o===0?1/0:NaN,r&32768?-s:s}function Yt(e){T.setFloat32(0,e,!1)}function Ge(e,t){if(e.length-t<4)throw new Error(`${f} not enough data for float32`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,4).getFloat32(0,!1)}function Jr(e){T.setFloat64(0,e,!1)}function Zt(e,t){if(e.length-t<8)throw new Error(`${f} not enough data for float64`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,8).getFloat64(0,!1)}de.compareTokens=U.compareTokens;function l(e,t,r){throw new Error(`${f} encountered invalid minor (${r}) for major ${e[t]>>>5}`)}function Ne(e){return()=>{throw new Error(`${f} ${e}`)}}var a=[];for(let e=0;e<=23;e++)a[e]=l;a[24]=ct;a[25]=at;a[26]=ut;a[27]=ft;a[28]=l;a[29]=l;a[30]=l;a[31]=l;for(let e=32;e<=55;e++)a[e]=l;a[56]=dt;a[57]=lt;a[58]=pt;a[59]=yt;a[60]=l;a[61]=l;a[62]=l;a[63]=l;for(let e=64;e<=87;e++)a[e]=mt;a[88]=gt;a[89]=xt;a[90]=wt;a[91]=bt;a[92]=l;a[93]=l;a[94]=l;a[95]=Ne("indefinite length bytes/strings are not supported");for(let e=96;e<=119;e++)a[e]=vt;a[120]=At;a[121]=Ut;a[122]=Tt;a[123]=kt;a[124]=l;a[125]=l;a[126]=l;a[127]=Ne("indefinite length bytes/strings are not supported");for(let e=128;e<=151;e++)a[e]=St;a[152]=It;a[153]=_t;a[154]=Nt;a[155]=Ct;a[156]=l;a[157]=l;a[158]=l;a[159]=$t;for(let e=160;e<=183;e++)a[e]=Mt;a[184]=Ot;a[185]=Dt;a[186]=zt;a[187]=Ft;a[188]=l;a[189]=l;a[190]=l;a[191]=Rt;for(let e=192;e<=215;e++)a[e]=Lt;a[216]=jt;a[217]=Vt;a[218]=Pt;a[219]=qt;a[220]=l;a[221]=l;a[222]=l;a[223]=l;for(let e=224;e<=243;e++)a[e]=Ne("simple values are not supported");a[244]=l;a[245]=l;a[246]=l;a[247]=Gt;a[248]=Ne("simple values are not supported");a[249]=Ht;a[250]=Kt;a[251]=Xt;a[252]=l;a[253]=l;a[254]=l;a[255]=Jt;var I=[];for(let e=0;e<24;e++)I[e]=new u(i.uint,e,1);for(let e=-1;e>=-24;e--)I[31-e]=new u(i.negint,e,1);I[64]=new u(i.bytes,new Uint8Array(0),1);I[96]=new u(i.string,"",1);I[128]=new u(i.array,0,1);I[160]=new u(i.map,0,1);I[244]=new u(i.false,!1,1);I[245]=new u(i.true,!0,1);I[246]=new u(i.null,null,1);function Je(e){switch(e.type){case i.false:return M([244]);case i.true:return M([245]);case i.null:return M([246]);case i.bytes:return e.value.length?void 0:M([64]);case i.string:return e.value===""?M([96]):void 0;case i.array:return e.value===0?M([128]):void 0;case i.map:return e.value===0?M([160]):void 0;case i.uint:return e.value<24?M([Number(e.value)]):void 0;case i.negint:if(e.value>=-24)return M([31-Number(e.value)])}}var Kr={float64:!1,mapSorter:Qr,quickEncodeToken:Je},or=Object.freeze({float64:!0,mapSorter:Yr,quickEncodeToken:Je});function Xr(){let e=[];return e[i.uint.major]=U,e[i.negint.major]=ke,e[i.bytes.major]=K,e[i.string.major]=Bt,e[i.array.major]=Se,e[i.map.major]=Ie,e[i.tag.major]=_e,e[i.float.major]=de,e}var Y=Xr(),Ce=new ce,pe=class e{constructor(t,r){this.obj=t,this.parent=r}includes(t){let r=this;do if(r.obj===t)return!0;while(r=r.parent);return!1}static createCheck(t,r){if(t&&t.includes(r))throw new Error(`${Te} object contains circular references`);return new e(r,t)}},j={null:new u(i.null,null),undefined:new u(i.undefined,void 0),true:new u(i.true,!0),false:new u(i.false,!1),emptyArray:new u(i.array,0),emptyMap:new u(i.map,0)},O={number(e,t,r,n){return!Number.isInteger(e)||!Number.isSafeInteger(e)?new u(i.float,e):e>=0?new u(i.uint,e):new u(i.negint,e)},bigint(e,t,r,n){return e>=BigInt(0)?new u(i.uint,e):new u(i.negint,e)},Uint8Array(e,t,r,n){return new u(i.bytes,e)},string(e,t,r,n){return new u(i.string,e)},boolean(e,t,r,n){return e?j.true:j.false},null(e,t,r,n){return j.null},undefined(e,t,r,n){return j.undefined},ArrayBuffer(e,t,r,n){return new u(i.bytes,new Uint8Array(e))},DataView(e,t,r,n){return new u(i.bytes,new Uint8Array(e.buffer,e.byteOffset,e.byteLength))},Array(e,t,r,n){if(!e.length)return r.addBreakTokens===!0?[j.emptyArray,new u(i.break)]:j.emptyArray;n=pe.createCheck(n,e);let o=[],s=0;for(let c of e)o[s++]=Q(c,r,n);return r.addBreakTokens?[new u(i.array,e.length),o,new u(i.break)]:[new u(i.array,e.length),o]},Object(e,t,r,n){let o=t!=="Object",s=o?e.keys():Object.keys(e),c=o?e.size:s.length,d;if(c){d=new Array(c),n=pe.createCheck(n,e);let p=!o&&r.ignoreUndefinedProperties,m=0;for(let _ of s){let H=o?e.get(_):e[_];p&&H===void 0||(d[m++]=[Q(_,r,n),Q(H,r,n)])}m<c&&(d.length=m)}return d?.length?(Wr(d,r),r.addBreakTokens?[new u(i.map,d.length),d,new u(i.break)]:[new u(i.map,d.length),d]):r.addBreakTokens===!0?[j.emptyMap,new u(i.break)]:j.emptyMap},Tagged(e,t,r,n){return[new u(i.tag,e.tag),Q(e.value,r,n)]}};O.Map=O.Object;O.Buffer=O.Uint8Array;for(let e of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))O[`${e}Array`]=O.DataView;function Q(e,t={},r){let n=ze(e),o=t&&t.typeEncoders&&t.typeEncoders[n]||O[n];if(typeof o=="function"){let c=o(e,n,t,r);if(c!=null)return c}let s=O[n];if(!s)throw new Error(`${Te} unsupported type: ${n}`);return s(e,n,t,r)}function Wr(e,t){t.mapSorter&&e.sort(t.mapSorter)}function Qr(e,t){let r=Array.isArray(e[0])?e[0][0]:e[0],n=Array.isArray(t[0])?t[0][0]:t[0];if(r.type!==n.type)return r.type.compare(n.type);let o=r.type.major,s=Y[o].compareTokens(r,n);return s===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),s}function Yr(e,t){if(e[0]instanceof u&&t[0]instanceof u){let r=e[0],n=t[0];return r._keyBytes||(r._keyBytes=er(r.value)),n._keyBytes||(n._keyBytes=er(n.value)),Ae(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function er(e){return sr(e,Y,or)}function le(e,t,r,n){if(Array.isArray(t))for(let o of t)le(e,o,r,n);else r[t.type.major](e,t,n)}var tr=i.uint.majorEncoded,rr=i.negint.majorEncoded,Zr=i.bytes.majorEncoded,en=i.string.majorEncoded,nr=i.array.majorEncoded,tn=i.float.majorEncoded|Re,rn=i.float.majorEncoded|Le,nn=i.float.majorEncoded|je,on=i.float.majorEncoded|Ve,sn=BigInt(-1),cn=BigInt(1);function an(e){return e.addBreakTokens!==!0}function ir(e,t,r,n){let o=ze(t),s=r.typeEncoders&&r.typeEncoders[o];if(s){let c=s(t,o,r,n);if(c!=null){le(e,c,Y,r);return}}switch(o){case"null":e.push([nn]);return;case"undefined":e.push([on]);return;case"boolean":e.push([t?rn:tn]);return;case"number":!Number.isInteger(t)||!Number.isSafeInteger(t)?de(e,new u(i.float,t),r):t>=0?y(e,tr,t):y(e,rr,t*-1-1);return;case"bigint":t>=BigInt(0)?y(e,tr,t):y(e,rr,t*sn-cn);return;case"string":{let c=ve(t);y(e,en,c.length),e.push(c);return}case"Uint8Array":y(e,Zr,t.length),e.push(t);return;case"Array":if(!t.length){e.push([nr]);return}n=pe.createCheck(n,t),y(e,nr,t.length);for(let c of t)ir(e,c,r,n);return;case"Object":case"Map":{let c=O.Object(t,o,r,n);le(e,c,Y,r)}return;default:{let c=O[o];if(!c)throw new Error(`${Te} unsupported type: ${o}`);let d=c(t,o,r,n);le(e,d,Y,r)}}}function sr(e,t,r,n){let o=n instanceof Uint8Array,s=o?new Ue(n):Ce,c=Q(e,r);if(!Array.isArray(c)&&r.quickEncodeToken){let d=r.quickEncodeToken(c);if(d)return o?(s.push(d),s.toBytes()):d;let p=t[c.type.major];if(p.encodedSize){let m=p.encodedSize(c,r);if(o||(s=new ce(m)),p(s,c,r),s.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${c} was wrong`);return o?s.toBytes():se(s.chunks[0])}}return s.reset(),le(s,c,t,r),s.toBytes(!0)}function He(e,t){return t=Object.assign({},Kr,t),an(t)?(Ce.reset(),ir(Ce,e,t,void 0),Ce.toBytes(!0)):sr(e,Y,t)}var un={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},$e=class{constructor(t,r={}){this._pos=0,this.data=t,this.options=r}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let t=this.data[this._pos],r=I[t];if(r===void 0){let n=a[t];if(!n)throw new Error(`${f} no decoder for major type ${t>>>5} (byte 0x${t.toString(16).padStart(2,"0")})`);let o=t&31;r=n(this.data,this._pos,o,this.options)}return this._pos+=r.encodedLength,r}},V=Symbol.for("DONE"),Z=Symbol.for("BREAK");function fn(e,t,r){let n=[];for(let o=0;o<e.value;o++){let s=P(t,r);if(s===Z){if(e.value===1/0)break;throw new Error(`${f} got unexpected break to lengthed array`)}if(s===V)throw new Error(`${f} found array but not enough entries (got ${o}, expected ${e.value})`);n[o]=s}return n}function dn(e,t,r){let n=r.useMaps===!0,o=r.rejectDuplicateMapKeys===!0,s=n?void 0:{},c=n?new Map:void 0;for(let d=0;d<e.value;d++){let p=P(t,r);if(p===Z){if(e.value===1/0)break;throw new Error(`${f} got unexpected break to lengthed map`)}if(p===V)throw new Error(`${f} found map but not enough entries (got ${d} [no key], expected ${e.value})`);if(!n&&typeof p!="string")throw new Error(`${f} non-string keys not supported (got ${typeof p})`);if(o&&(n&&c.has(p)||!n&&Object.hasOwn(s,p)))throw new Error(`${f} found repeat map key "${p}"`);let m=P(t,r);if(m===V)throw new Error(`${f} found map but not enough entries (got ${d} [no value], expected ${e.value})`);n?c.set(p,m):s[p]=m}return n?c:s}function*ln(e,t,r){for(let n=0;n<e.value;n++){let o=P(t,r);if(o===Z){if(e.value===1/0)break;throw new Error(`${f} got unexpected break to lengthed map`)}if(o===V)throw new Error(`${f} found map but not enough entries (got ${n} [no key], expected ${e.value})`);let s=P(t,r);if(s===V)throw new Error(`${f} found map but not enough entries (got ${n} [no value], expected ${e.value})`);yield[o,s]}}function pn(e,t){let r=!1,n=function(){if(r)throw new Error(`${f} tag decode() may only be called once`);r=!0;let o=P(e,t);if(o===V)throw new Error(`${f} tag content missing`);if(o===Z)throw new Error(`${f} got unexpected break in tag content`);return o};return n.entries=function(){if(r)throw new Error(`${f} tag decode() may only be called once`);r=!0;let o=e.next();if(!i.equals(o.type,i.map))throw new Error(`${f} entries() requires map content, got ${o.type.name}`);let s=[];for(let c of ln(o,e,t))s.push(c);return s},Object.defineProperty(n,"_called",{get(){return r},enumerable:!1}),n}function P(e,t){if(e.done())return V;let r=e.next();if(i.equals(r.type,i.break))return Z;if(r.type.terminal)return r.value;if(i.equals(r.type,i.array))return fn(r,e,t);if(i.equals(r.type,i.map))return dn(r,e,t);if(i.equals(r.type,i.tag)){if(t.tags&&typeof t.tags[r.value]=="function"){let n=pn(e,t),o=t.tags[r.value](n);if(!n._called)throw new Error(`${f} tag decoder must call decode() or entries()`);return o}throw new Error(`${f} tag not supported (${r.value})`)}throw new Error("unsupported")}function cr(e,t){if(!(e instanceof Uint8Array))throw new Error(`${f} data to decode must be a Uint8Array`);t=Object.assign({},un,t);let r=se(e),n=t.tokenizer||new $e(r,t),o=P(n,t);if(o===V)throw new Error(`${f} did not find any content to decode`);if(o===Z)throw new Error(`${f} got unexpected break`);return[o,e.subarray(n.pos())]}function Ke(e,t){let[r,n]=cr(e,t);if(n.length>0)throw new Error(`${f} too many terminals, data makes no sense`);return r}var Me=class e{constructor(t,r){if(typeof t!="number"||!Number.isInteger(t)||t<0)throw new TypeError("Tagged: tag must be a non-negative integer");this.tag=t,this.value=r}static decoder(t){return r=>new e(t,r())}static preserve(...t){let r={};for(let n of t)r[n]=e.decoder(n);return r}};Object.defineProperty(Me.prototype,Symbol.toStringTag,{value:"Tagged"});var si=new Uint8Array(0);function ar(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function ee(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return J(e);if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return J(new Uint8Array(e.buffer,e.byteOffset,e.byteLength));throw new Error("Unknown type, must be binary type")}function yn(e){return e?.buffer instanceof ArrayBuffer}function J(e){return yn(e)?e:e.slice()}function mn(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 s=e.charAt(o),c=s.charCodeAt(0);if(r[c]!==255)throw new TypeError(s+" is ambiguous");r[c]=o}var d=e.length,p=e.charAt(0),m=Math.log(d)/Math.log(256),_=Math.log(256)/Math.log(d);function H(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var x=0,q=0,k=0,N=h.length;k!==N&&h[k]===0;)k++,x++;for(var C=(N-k)*_+1>>>0,A=new Uint8Array(C);k!==N;){for(var $=h[k],L=0,B=C-1;($!==0||L<q)&&B!==-1;B--,L++)$+=256*A[B]>>>0,A[B]=$%d>>>0,$=$/d>>>0;if($!==0)throw new Error("Non-zero carry");q=L,k++}for(var z=C-q;z!==C&&A[z]===0;)z++;for(var be=p.repeat(x);z<C;++z)be+=e.charAt(A[z]);return be}function we(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;var x=0;if(h[x]!==" "){for(var q=0,k=0;h[x]===p;)q++,x++;for(var N=(h.length-x)*m+1>>>0,C=new Uint8Array(N);h[x];){var A=r[h.charCodeAt(x)];if(A===255)return;for(var $=0,L=N-1;(A!==0||$<k)&&L!==-1;L--,$++)A+=d*C[L]>>>0,C[L]=A%256>>>0,A=A/256>>>0;if(A!==0)throw new Error("Non-zero carry");k=$,x++}if(h[x]!==" "){for(var B=N-k;B!==N&&C[B]===0;)B++;for(var z=new Uint8Array(q+(N-B)),be=q;B!==N;)z[be++]=C[B++];return z}}}function Ur(h){var x=we(h);if(x)return x;throw new Error(`Non-${t} character`)}return{encode:H,decodeUnsafe:we,decode:Ur}}var gn=mn,xn=gn,ur=xn;var Xe=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},We=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return fr(this,t)}},Qe=class{decoders;constructor(t){this.decoders=t}or(t){return fr(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function fr(e,t){return new Qe({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var Ye=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Xe(t,r,n),this.decoder=new We(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function dr({name:e,prefix:t,encode:r,decode:n}){return new Ye(e,t,r,n)}function te({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=ur(r,e);return dr({prefix:t,name:e,encode:n,decode:s=>ee(o(s))})}function wn(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),c=0,d=0,p=0;for(let m=0;m<o;++m){let _=t[e[m]];if(_===void 0)throw new SyntaxError(`Non-${n} character`);d=d<<r|_,c+=r,c>=8&&(c-=8,s[p++]=255&d>>c)}if(c>=r||(255&d<<8-c)!==0)throw new SyntaxError("Unexpected end of data");return s}function bn(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",c=0,d=0;for(let p=0;p<e.length;++p)for(d=d<<8|e[p],c+=8;c>r;)c-=r,s+=t[o&d>>c];if(c!==0&&(s+=t[o&d<<r-c]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function En(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function D({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=En(n);return dr({prefix:t,name:e,encode(s){return bn(s,n,r)},decode(s){return wn(s,o,r,e)}})}var he=D({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),pi=D({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),hi=D({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),yi=D({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),mi=D({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),gi=D({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),xi=D({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),wi=D({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),bi=D({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Oe=te({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Ai=te({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var R=te({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ki=te({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var vn=hr,lr=128,An=127,Un=~An,Tn=Math.pow(2,31);function hr(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Tn;)t[r++]=e&255|lr,e/=128;for(;e&Un;)t[r++]=e&255|lr,e>>>=7;return t[r]=e|0,hr.bytes=r-n+1,t}var kn=Ze,Bn=128,pr=127;function Ze(e,n){var r=0,n=n||0,o=0,s=n,c,d=e.length;do{if(s>=d)throw Ze.bytes=0,new RangeError("Could not decode varint");c=e[s++],r+=o<28?(c&pr)<<o:(c&pr)*Math.pow(2,o),o+=7}while(c>=Bn);return Ze.bytes=s-n,r}var Sn=Math.pow(2,7),In=Math.pow(2,14),_n=Math.pow(2,21),Nn=Math.pow(2,28),Cn=Math.pow(2,35),$n=Math.pow(2,42),Mn=Math.pow(2,49),On=Math.pow(2,56),Dn=Math.pow(2,63),zn=function(e){return e<Sn?1:e<In?2:e<_n?3:e<Nn?4:e<Cn?5:e<$n?6:e<Mn?7:e<On?8:e<Dn?9:10},Fn={encode:vn,decode:kn,encodingLength:zn},Rn=Fn,ye=Rn;function me(e,t=0){return[ye.decode(e,t),ye.decode.bytes]}function re(e,t,r=0){return ye.encode(e,t,r),t}function ne(e){return ye.encodingLength(e)}function mr(e,t){let r=t.byteLength,n=ne(e),o=n+ne(r),s=new Uint8Array(o+r);return re(e,s,0),re(r,s,n),s.set(t,o),new oe(e,r,t,s)}function gr(e){let t=ee(e),[r,n]=me(t),[o,s]=me(t.subarray(n)),c=t.subarray(n+s);if(c.byteLength!==o)throw new Error("Incorrect length");return new oe(r,o,c,t)}function xr(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&ar(e.bytes,r.bytes)}}var oe=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=J(n),this.bytes=J(o)}};function wr(e,t){let{bytes:r,version:n}=e;return n===0?Vn(r,et(e),t??R.encoder):Pn(r,et(e),t??he.encoder)}var br=new WeakMap;function et(e){let t=br.get(e);if(t==null){let r=new Map;return br.set(e,r),r}return t}var xe=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=J(o),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==ge)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==qn)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:r}=this.multihash,n=mr(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&xr(t.multihash,n.multihash)}toString(t){return wr(this,t)}toJSON(){return{"/":wr(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:c}=r;return new e(n,o,s,c??Er(n,o,s.bytes))}else if(r[Gn]===!0){let{version:n,multihash:o,code:s}=r,c=gr(o);return e.create(n,s,c)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==ge)throw new Error(`Version 0 CID must use dag-pb (code: ${ge}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Er(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,ge,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=ee(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),c=new oe(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(c):e.createV1(r.codec,c),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[H,we]=me(t.subarray(r));return r+=we,H},o=n(),s=ge;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let c=r,d=n(),p=n(),m=r+p,_=m-c;return{version:o,codec:s,multihashCode:d,digestSize:p,multihashSize:_,size:m}}static parse(t,r){let[n,o]=jn(t,r),s=e.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return et(s).set(n,t),s}};function jn(e,t){switch(e[0]){case"Q":{let r=t??R;return[R.prefix,r.decode(`${R.prefix}${e}`)]}case R.prefix:{let r=t??R;return[R.prefix,r.decode(e)]}case he.prefix:{let r=t??he;return[he.prefix,r.decode(e)]}case Oe.prefix:{let r=t??Oe;return[Oe.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function Vn(e,t,r){let{prefix:n}=r;if(n!==R.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let s=r.encode(e).slice(1);return t.set(n,s),s}else return o}function Pn(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let s=r.encode(e);return t.set(n,s),s}else return o}var ge=112,qn=18;function Er(e,t,r){let n=ne(e),o=n+ne(t),s=new Uint8Array(o+r.byteLength);return re(e,s,0),re(t,s,n),s.set(r,o),s}var Gn=Symbol.for("@ipld/js-cid/CID");var vr=42;function Ar(e){return e instanceof ArrayBuffer?new Uint8Array(e,0,e.byteLength):e}function Jn(e){if(e.asCID!==e&&e["/"]!==e.bytes)return null;let t=xe.asCID(e);if(!t)return null;let r=new Uint8Array(t.bytes.byteLength+1);return r.set(t.bytes,1),[new u(i.tag,vr),new u(i.bytes,r)]}function Hn(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function Kn(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}function Xn(e){for(let t of e.keys())if(typeof t!="string"||t.length===0)throw new Error("Non-string Map keys are not supported by the IPLD Data Model and cannot be encoded");return null}var tt={float64:!0,typeEncoders:{Map:Xn,Object:Jn,undefined:Hn,number:Kn}},Wn={...tt,typeEncoders:{...tt.typeEncoders}};function Qn(e){let t=e();if(t[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return xe.decode(t.subarray(1))}var rt={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:{[vr]:Qn}},Yn={...rt,tags:{...rt.tags}},Zn="dag-cbor",eo=113,to=e=>He(e,tt),ro=e=>Ke(Ar(e),rt);return _r(no);})(); return IpldDagCbor})); //# sourceMappingURL=index.min.js.map