@helia/dag-cbor 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,3 +1,3 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.HeliaDagCbor = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var HeliaDagCbor=(()=>{var Oe=Object.defineProperty;var Hr=Object.getOwnPropertyDescriptor;var Wr=Object.getOwnPropertyNames;var Zr=Object.prototype.hasOwnProperty;var Yr=(e,t)=>{for(var r in t)Oe(e,r,{get:t[r],enumerable:!0})},en=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Wr(t))!Zr.call(e,o)&&o!==r&&Oe(e,o,{get:()=>t[o],enumerable:!(n=Hr(t,o))||n.enumerable});return e};var tn=e=>en(Oe({},"__esModule",{value:!0}),e);var jo={};Yr(jo,{dagCbor:()=>qo});var rn=["string","number","bigint","symbol"],nn=["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 ft(e){if(e===null)return"null";if(e===void 0)return"undefined";if(e===!0||e===!1)return"boolean";let t=typeof e;if(rn.includes(t))return t;if(t==="function")return"Function";if(Array.isArray(e))return"Array";if(on(e))return"Buffer";let r=sn(e);return r||"Object"}function on(e){return e&&e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer.call(null,e)}function sn(e){let t=Object.prototype.toString.call(e).slice(8,-1);if(nn.includes(t))return t}var s=class{constructor(t,r,n){this.major=t,this.majorEncoded=t<<5,this.name=r,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(t){return this.major<t.major?-1:this.major>t.major?1:0}};s.uint=new s(0,"uint",!0);s.negint=new s(1,"negint",!0);s.bytes=new s(2,"bytes",!0);s.string=new s(3,"string",!0);s.array=new s(4,"array",!1);s.map=new s(5,"map",!1);s.tag=new s(6,"tag",!1);s.float=new s(7,"float",!0);s.false=new s(7,"false",!0);s.true=new s(7,"true",!0);s.null=new s(7,"null",!0);s.undefined=new s(7,"undefined",!0);s.break=new s(7,"break",!0);var d=class{constructor(t,r,n){this.type=t,this.value=r,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var X=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",cn=new TextDecoder,an=new TextEncoder;function Ue(e){return X&&globalThis.Buffer.isBuffer(e)}function Ve(e){return e instanceof Uint8Array?Ue(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e:Uint8Array.from(e)}var mt=X?(e,t,r)=>r-t>64?globalThis.Buffer.from(e.subarray(t,r)).toString("utf8"):ht(e,t,r):(e,t,r)=>r-t>64?cn.decode(e.subarray(t,r)):ht(e,t,r),yt=X?e=>e.length>64?globalThis.Buffer.from(e):lt(e):e=>e.length>64?an.encode(e):lt(e),V=e=>Uint8Array.from(e),H=X?(e,t,r)=>Ue(e)?new Uint8Array(e.subarray(t,r)):e.slice(t,r):(e,t,r)=>e.slice(t,r),gt=X?(e,t)=>(e=e.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),Ve(globalThis.Buffer.concat(e,t))):(e,t)=>{let r=new Uint8Array(t),n=0;for(let o of e)n+o.length>r.length&&(o=o.subarray(0,r.length-n)),r.set(o,n),n+=o.length;return r},wt=X?e=>globalThis.Buffer.allocUnsafe(e):e=>new Uint8Array(e);function bt(e,t){if(Ue(e)&&Ue(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 lt(e,t=1/0){let r,n=e.length,o=null,i=[];for(let c=0;c<n;++c){if(r=e.charCodeAt(c),r>55295&&r<57344){if(!o){if(r>56319){(t-=3)>-1&&i.push(239,191,189);continue}else if(c+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=(o-55296<<10|r-56320)+65536}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,r&63|128)}else if(r<65536){if((t-=3)<0)break;i.push(r>>12|224,r>>6&63|128,r&63|128)}else if(r<1114112){if((t-=4)<0)break;i.push(r>>18|240,r>>12&63|128,r>>6&63|128,r&63|128)}else throw new Error("Invalid code point")}return i}function ht(e,t,r){let n=[];for(;t<r;){let o=e[t],i=null,c=o>239?4:o>223?3:o>191?2:1;if(t+c<=r){let u,h,x,p;switch(c){case 1:o<128&&(i=o);break;case 2:u=e[t+1],(u&192)===128&&(p=(o&31)<<6|u&63,p>127&&(i=p));break;case 3:u=e[t+1],h=e[t+2],(u&192)===128&&(h&192)===128&&(p=(o&15)<<12|(u&63)<<6|h&63,p>2047&&(p<55296||p>57343)&&(i=p));break;case 4:u=e[t+1],h=e[t+2],x=e[t+3],(u&192)===128&&(h&192)===128&&(x&192)===128&&(p=(o&15)<<18|(u&63)<<12|(h&63)<<6|x&63,p>65535&&p<1114112&&(i=p))}}i===null?(i=65533,c=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|i&1023),n.push(i),t+=c}return un(n)}var pt=4096;function un(e){let t=e.length;if(t<=pt)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=pt));return r}var dn=256,ae=class{constructor(t=dn){this.chunkSize=t,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(t){let r=this.chunks[this.chunks.length-1];if(this.cursor+t.length<=this.maxCursor+1){let o=r.length-(this.maxCursor-this.cursor)-1;r.set(t,o)}else{if(r){let o=r.length-(this.maxCursor-this.cursor)-1;o<r.length&&(this.chunks[this.chunks.length-1]=r.subarray(0,o),this.maxCursor=this.cursor-1)}t.length<64&&t.length<this.chunkSize?(r=wt(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r),r.set(t,0)):(this.chunks.push(t),this.maxCursor+=t.length)}this.cursor+=t.length}toBytes(t=!1){let r;if(this.chunks.length===1){let n=this.chunks[0];t&&this.cursor>n.length/2?(r=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):r=H(n,0,this.cursor)}else r=gt(this.chunks,this.cursor);return t&&this.reset(),r}};var l="CBOR decode error:",Fe="CBOR encode error:",ue=[];ue[23]=1;ue[24]=2;ue[25]=3;ue[26]=5;ue[27]=9;function q(e,t,r){if(e.length-t<r)throw new Error(`${l} not enough data for type`)}var S=[24,256,65536,4294967296,BigInt("18446744073709551616")];function B(e,t,r){q(e,t,1);let n=e[t];if(r.strict===!0&&n<S[0])throw new Error(`${l} integer encoded in more bytes than necessary (strict decode)`);return n}function N(e,t,r){q(e,t,2);let n=e[t]<<8|e[t+1];if(r.strict===!0&&n<S[1])throw new Error(`${l} integer encoded in more bytes than necessary (strict decode)`);return n}function $(e,t,r){q(e,t,4);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];if(r.strict===!0&&n<S[2])throw new Error(`${l} integer encoded in more bytes than necessary (strict decode)`);return n}function z(e,t,r){q(e,t,8);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3],o=e[t+4]*16777216+(e[t+5]<<16)+(e[t+6]<<8)+e[t+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&i<S[3])throw new Error(`${l} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(r.allowBigInt===!0)return i;throw new Error(`${l} integers outside of the safe integer range are not supported`)}function xt(e,t,r,n){return new d(s.uint,B(e,t+1,n),2)}function vt(e,t,r,n){return new d(s.uint,N(e,t+1,n),3)}function Et(e,t,r,n){return new d(s.uint,$(e,t+1,n),5)}function At(e,t,r,n){return new d(s.uint,z(e,t+1,n),9)}function D(e,t){return k(e,0,t.value)}function k(e,t,r){if(r<S[0]){let n=Number(r);e.push([t|n])}else if(r<S[1]){let n=Number(r);e.push([t|24,n])}else if(r<S[2]){let n=Number(r);e.push([t|25,n>>>8,n&255])}else if(r<S[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<S[4]){let o=[t|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),c=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=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(`${l} encountered BigInt larger than allowable range`)}}D.encodedSize=function(t){return k.encodedSize(t.value)};k.encodedSize=function(t){return t<S[0]?1:t<S[1]?2:t<S[2]?3:t<S[3]?5:9};D.compareTokens=function(t,r){return t.value<r.value?-1:t.value>r.value?1:0};function Ut(e,t,r,n){return new d(s.negint,-1-B(e,t+1,n),2)}function St(e,t,r,n){return new d(s.negint,-1-N(e,t+1,n),3)}function Tt(e,t,r,n){return new d(s.negint,-1-$(e,t+1,n),5)}var Le=BigInt(-1),kt=BigInt(1);function It(e,t,r,n){let o=z(e,t+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new d(s.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${l} integers outside of the safe integer range are not supported`);return new d(s.negint,Le-BigInt(o),9)}function Se(e,t){let r=t.value,n=typeof r=="bigint"?r*Le-kt:r*-1-1;k(e,t.type.majorEncoded,n)}Se.encodedSize=function(t){let r=t.value,n=typeof r=="bigint"?r*Le-kt:r*-1-1;return n<S[0]?1:n<S[1]?2:n<S[2]?3:n<S[3]?5:9};Se.compareTokens=function(t,r){return t.value<r.value?1:t.value>r.value?-1:0};function de(e,t,r,n){q(e,t,r+n);let o=H(e,t+r,t+r+n);return new d(s.bytes,o,r+n)}function Ct(e,t,r,n){return de(e,t,1,r)}function Bt(e,t,r,n){return de(e,t,2,B(e,t+1,n))}function Nt(e,t,r,n){return de(e,t,3,N(e,t+1,n))}function $t(e,t,r,n){return de(e,t,5,$(e,t+1,n))}function zt(e,t,r,n){let o=z(e,t+1,n);if(typeof o=="bigint")throw new Error(`${l} 64-bit integer bytes lengths not supported`);return de(e,t,9,o)}function Te(e){return e.encodedBytes===void 0&&(e.encodedBytes=e.type===s.string?yt(e.value):e.value),e.encodedBytes}function W(e,t){let r=Te(t);k(e,t.type.majorEncoded,r.length),e.push(r)}W.encodedSize=function(t){let r=Te(t);return k.encodedSize(r.length)+r.length};W.compareTokens=function(t,r){return ln(Te(t),Te(r))};function ln(e,t){return e.length<t.length?-1:e.length>t.length?1:bt(e,t)}function fe(e,t,r,n,o){let i=r+n;q(e,t,i);let c=new d(s.string,mt(e,t+r,t+i),i);return o.retainStringBytes===!0&&(c.byteValue=H(e,t+r,t+i)),c}function Dt(e,t,r,n){return fe(e,t,1,r,n)}function Mt(e,t,r,n){return fe(e,t,2,B(e,t+1,n),n)}function _t(e,t,r,n){return fe(e,t,3,N(e,t+1,n),n)}function Ot(e,t,r,n){return fe(e,t,5,$(e,t+1,n),n)}function Vt(e,t,r,n){let o=z(e,t+1,n);if(typeof o=="bigint")throw new Error(`${l} 64-bit integer string lengths not supported`);return fe(e,t,9,o,n)}var Ft=W;function Z(e,t,r,n){return new d(s.array,n,r)}function Lt(e,t,r,n){return Z(e,t,1,r)}function Rt(e,t,r,n){return Z(e,t,2,B(e,t+1,n))}function Pt(e,t,r,n){return Z(e,t,3,N(e,t+1,n))}function qt(e,t,r,n){return Z(e,t,5,$(e,t+1,n))}function jt(e,t,r,n){let o=z(e,t+1,n);if(typeof o=="bigint")throw new Error(`${l} 64-bit integer array lengths not supported`);return Z(e,t,9,o)}function Gt(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${l} indefinite length items not allowed`);return Z(e,t,1,1/0)}function ke(e,t){k(e,s.array.majorEncoded,t.value)}ke.compareTokens=D.compareTokens;ke.encodedSize=function(t){return k.encodedSize(t.value)};function Y(e,t,r,n){return new d(s.map,n,r)}function Jt(e,t,r,n){return Y(e,t,1,r)}function Kt(e,t,r,n){return Y(e,t,2,B(e,t+1,n))}function Qt(e,t,r,n){return Y(e,t,3,N(e,t+1,n))}function Xt(e,t,r,n){return Y(e,t,5,$(e,t+1,n))}function Ht(e,t,r,n){let o=z(e,t+1,n);if(typeof o=="bigint")throw new Error(`${l} 64-bit integer map lengths not supported`);return Y(e,t,9,o)}function Wt(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${l} indefinite length items not allowed`);return Y(e,t,1,1/0)}function Ie(e,t){k(e,s.map.majorEncoded,t.value)}Ie.compareTokens=D.compareTokens;Ie.encodedSize=function(t){return k.encodedSize(t.value)};function Zt(e,t,r,n){return new d(s.tag,r,1)}function Yt(e,t,r,n){return new d(s.tag,B(e,t+1,n),2)}function er(e,t,r,n){return new d(s.tag,N(e,t+1,n),3)}function tr(e,t,r,n){return new d(s.tag,$(e,t+1,n),5)}function rr(e,t,r,n){return new d(s.tag,z(e,t+1,n),9)}function Ce(e,t){k(e,s.tag.majorEncoded,t.value)}Ce.compareTokens=D.compareTokens;Ce.encodedSize=function(t){return k.encodedSize(t.value)};var wn=20,bn=21,xn=22,vn=23;function nr(e,t,r,n){if(n.allowUndefined===!1)throw new Error(`${l} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new d(s.null,null,1):new d(s.undefined,void 0,1)}function or(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${l} indefinite length items not allowed`);return new d(s.break,void 0,1)}function Re(e,t,r){if(r){if(r.allowNaN===!1&&Number.isNaN(e))throw new Error(`${l} NaN values are not supported`);if(r.allowInfinity===!1&&(e===1/0||e===-1/0))throw new Error(`${l} Infinity values are not supported`)}return new d(s.float,e,t)}function ir(e,t,r,n){return Re(Pe(e,t+1),3,n)}function sr(e,t,r,n){return Re(qe(e,t+1),5,n)}function cr(e,t,r,n){return Re(fr(e,t+1),9,n)}function Be(e,t,r){let n=t.value;if(n===!1)e.push([s.float.majorEncoded|wn]);else if(n===!0)e.push([s.float.majorEncoded|bn]);else if(n===null)e.push([s.float.majorEncoded|xn]);else if(n===void 0)e.push([s.float.majorEncoded|vn]);else{let o,i=!1;(!r||r.float64!==!0)&&(ur(n),o=Pe(_,1),n===o||Number.isNaN(n)?(_[0]=249,e.push(_.slice(0,3)),i=!0):(dr(n),o=qe(_,1),n===o&&(_[0]=250,e.push(_.slice(0,5)),i=!0))),i||(En(n),o=fr(_,1),_[0]=251,e.push(_.slice(0,9)))}}Be.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){ur(n);let o=Pe(_,1);if(n===o||Number.isNaN(n))return 3;if(dr(n),o=qe(_,1),n===o)return 5}return 9};var ar=new ArrayBuffer(9),M=new DataView(ar,1),_=new Uint8Array(ar,0);function ur(e){if(e===1/0)M.setUint16(0,31744,!1);else if(e===-1/0)M.setUint16(0,64512,!1);else if(Number.isNaN(e))M.setUint16(0,32256,!1);else{M.setFloat32(0,e);let t=M.getUint32(0),r=(t&2139095040)>>23,n=t&8388607;if(r===255)M.setUint16(0,31744,!1);else if(r===0)M.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?M.setUint16(0,0):o<-14?M.setUint16(0,(t&2147483648)>>16|1<<24+o,!1):M.setUint16(0,(t&2147483648)>>16|o+15<<10|n>>13,!1)}}}function Pe(e,t){if(e.length-t<2)throw new Error(`${l} not enough data for float16`);let r=(e[t]<<8)+e[t+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,r&32768?-i:i}function dr(e){M.setFloat32(0,e,!1)}function qe(e,t){if(e.length-t<4)throw new Error(`${l} not enough data for float32`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,4).getFloat32(0,!1)}function En(e){M.setFloat64(0,e,!1)}function fr(e,t){if(e.length-t<8)throw new Error(`${l} not enough data for float64`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,8).getFloat64(0,!1)}Be.compareTokens=D.compareTokens;function m(e,t,r){throw new Error(`${l} encountered invalid minor (${r}) for major ${e[t]>>>5}`)}function Ne(e){return()=>{throw new Error(`${l} ${e}`)}}var a=[];for(let e=0;e<=23;e++)a[e]=m;a[24]=xt;a[25]=vt;a[26]=Et;a[27]=At;a[28]=m;a[29]=m;a[30]=m;a[31]=m;for(let e=32;e<=55;e++)a[e]=m;a[56]=Ut;a[57]=St;a[58]=Tt;a[59]=It;a[60]=m;a[61]=m;a[62]=m;a[63]=m;for(let e=64;e<=87;e++)a[e]=Ct;a[88]=Bt;a[89]=Nt;a[90]=$t;a[91]=zt;a[92]=m;a[93]=m;a[94]=m;a[95]=Ne("indefinite length bytes/strings are not supported");for(let e=96;e<=119;e++)a[e]=Dt;a[120]=Mt;a[121]=_t;a[122]=Ot;a[123]=Vt;a[124]=m;a[125]=m;a[126]=m;a[127]=Ne("indefinite length bytes/strings are not supported");for(let e=128;e<=151;e++)a[e]=Lt;a[152]=Rt;a[153]=Pt;a[154]=qt;a[155]=jt;a[156]=m;a[157]=m;a[158]=m;a[159]=Gt;for(let e=160;e<=183;e++)a[e]=Jt;a[184]=Kt;a[185]=Qt;a[186]=Xt;a[187]=Ht;a[188]=m;a[189]=m;a[190]=m;a[191]=Wt;for(let e=192;e<=215;e++)a[e]=Zt;a[216]=Yt;a[217]=er;a[218]=tr;a[219]=rr;a[220]=m;a[221]=m;a[222]=m;a[223]=m;for(let e=224;e<=243;e++)a[e]=Ne("simple values are not supported");a[244]=m;a[245]=m;a[246]=m;a[247]=nr;a[248]=Ne("simple values are not supported");a[249]=ir;a[250]=sr;a[251]=cr;a[252]=m;a[253]=m;a[254]=m;a[255]=or;var O=[];for(let e=0;e<24;e++)O[e]=new d(s.uint,e,1);for(let e=-1;e>=-24;e--)O[31-e]=new d(s.negint,e,1);O[64]=new d(s.bytes,new Uint8Array(0),1);O[96]=new d(s.string,"",1);O[128]=new d(s.array,0,1);O[160]=new d(s.map,0,1);O[244]=new d(s.false,!1,1);O[245]=new d(s.true,!0,1);O[246]=new d(s.null,null,1);function lr(e){switch(e.type){case s.false:return V([244]);case s.true:return V([245]);case s.null:return V([246]);case s.bytes:return e.value.length?void 0:V([64]);case s.string:return e.value===""?V([96]):void 0;case s.array:return e.value===0?V([128]):void 0;case s.map:return e.value===0?V([160]):void 0;case s.uint:return e.value<24?V([Number(e.value)]):void 0;case s.negint:if(e.value>=-24)return V([31-Number(e.value)])}}var Un={float64:!1,mapSorter:kn,quickEncodeToken:lr};function Sn(){let e=[];return e[s.uint.major]=D,e[s.negint.major]=Se,e[s.bytes.major]=W,e[s.string.major]=Ft,e[s.array.major]=ke,e[s.map.major]=Ie,e[s.tag.major]=Ce,e[s.float.major]=Be,e}var hr=Sn(),je=new ae,ze=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(`${Fe} object contains circular references`);return new e(r,t)}},J={null:new d(s.null,null),undefined:new d(s.undefined,void 0),true:new d(s.true,!0),false:new d(s.false,!1),emptyArray:new d(s.array,0),emptyMap:new d(s.map,0)},K={number(e,t,r,n){return!Number.isInteger(e)||!Number.isSafeInteger(e)?new d(s.float,e):e>=0?new d(s.uint,e):new d(s.negint,e)},bigint(e,t,r,n){return e>=BigInt(0)?new d(s.uint,e):new d(s.negint,e)},Uint8Array(e,t,r,n){return new d(s.bytes,e)},string(e,t,r,n){return new d(s.string,e)},boolean(e,t,r,n){return e?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 d(s.bytes,new Uint8Array(e))},DataView(e,t,r,n){return new d(s.bytes,new Uint8Array(e.buffer,e.byteOffset,e.byteLength))},Array(e,t,r,n){if(!e.length)return r.addBreakTokens===!0?[J.emptyArray,new d(s.break)]:J.emptyArray;n=ze.createCheck(n,e);let o=[],i=0;for(let c of e)o[i++]=$e(c,r,n);return r.addBreakTokens?[new d(s.array,e.length),o,new d(s.break)]:[new d(s.array,e.length),o]},Object(e,t,r,n){let o=t!=="Object",i=o?e.keys():Object.keys(e),c=o?e.size:i.length;if(!c)return r.addBreakTokens===!0?[J.emptyMap,new d(s.break)]:J.emptyMap;n=ze.createCheck(n,e);let u=[],h=0;for(let x of i)u[h++]=[$e(x,r,n),$e(o?e.get(x):e[x],r,n)];return Tn(u,r),r.addBreakTokens?[new d(s.map,c),u,new d(s.break)]:[new d(s.map,c),u]}};K.Map=K.Object;K.Buffer=K.Uint8Array;for(let e of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))K[`${e}Array`]=K.DataView;function $e(e,t={},r){let n=ft(e),o=t&&t.typeEncoders&&t.typeEncoders[n]||K[n];if(typeof o=="function"){let c=o(e,n,t,r);if(c!=null)return c}let i=K[n];if(!i)throw new Error(`${Fe} unsupported type: ${n}`);return i(e,n,t,r)}function Tn(e,t){t.mapSorter&&e.sort(t.mapSorter)}function kn(e,t){let r=Array.isArray(e[0])?e[0][0]:e[0],n=Array.isArray(t[0])?t[0][0]:t[0];if(r.type!==n.type)return r.type.compare(n.type);let o=r.type.major,i=hr[o].compareTokens(r,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function pr(e,t,r,n){if(Array.isArray(t))for(let o of t)pr(e,o,r,n);else r[t.type.major](e,t,n)}function In(e,t,r){let n=$e(e,r);if(!Array.isArray(n)&&r.quickEncodeToken){let o=r.quickEncodeToken(n);if(o)return o;let i=t[n.type.major];if(i.encodedSize){let c=i.encodedSize(n,r),u=new ae(c);if(i(u,n,r),u.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return Ve(u.chunks[0])}}return je.reset(),pr(je,n,t,r),je.toBytes(!0)}function Ge(e,t){return t=Object.assign({},Un,t),In(e,hr,t)}var Cn={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},Je=class{constructor(t,r={}){this.pos=0,this.data=t,this.options=r}done(){return this.pos>=this.data.length}next(){let t=this.data[this.pos],r=O[t];if(r===void 0){let n=a[t];if(!n)throw new Error(`${l} no decoder for major type ${t>>>5} (byte 0x${t.toString(16).padStart(2,"0")})`);let o=t&31;r=n(this.data,this.pos,o,this.options)}return this.pos+=r.encodedLength,r}},le=Symbol.for("DONE"),De=Symbol.for("BREAK");function Bn(e,t,r){let n=[];for(let o=0;o<e.value;o++){let i=he(t,r);if(i===De){if(e.value===1/0)break;throw new Error(`${l} got unexpected break to lengthed array`)}if(i===le)throw new Error(`${l} found array but not enough entries (got ${o}, expected ${e.value})`);n[o]=i}return n}function Nn(e,t,r){let n=r.useMaps===!0,o=n?void 0:{},i=n?new Map:void 0;for(let c=0;c<e.value;c++){let u=he(t,r);if(u===De){if(e.value===1/0)break;throw new Error(`${l} got unexpected break to lengthed map`)}if(u===le)throw new Error(`${l} found map but not enough entries (got ${c} [no key], expected ${e.value})`);if(n!==!0&&typeof u!="string")throw new Error(`${l} non-string keys not supported (got ${typeof u})`);if(r.rejectDuplicateMapKeys===!0&&(n&&i.has(u)||!n&&u in o))throw new Error(`${l} found repeat map key "${u}"`);let h=he(t,r);if(h===le)throw new Error(`${l} found map but not enough entries (got ${c} [no value], expected ${e.value})`);n?i.set(u,h):o[u]=h}return n?i:o}function he(e,t){if(e.done())return le;let r=e.next();if(r.type===s.break)return De;if(r.type.terminal)return r.value;if(r.type===s.array)return Bn(r,e,t);if(r.type===s.map)return Nn(r,e,t);if(r.type===s.tag){if(t.tags&&typeof t.tags[r.value]=="function"){let n=he(e,t);return t.tags[r.value](n)}throw new Error(`${l} tag not supported (${r.value})`)}throw new Error("unsupported")}function Ke(e,t){if(!(e instanceof Uint8Array))throw new Error(`${l} data to decode must be a Uint8Array`);t=Object.assign({},Cn,t);let r=t.tokenizer||new Je(e,t),n=he(r,t);if(n===le)throw new Error(`${l} did not find any content to decode`);if(n===De)throw new Error(`${l} got unexpected break`);if(!r.done())throw new Error(`${l} too many terminals, data makes no sense`);return n}var zn=gr,mr=128,Dn=127,Mn=~Dn,_n=Math.pow(2,31);function gr(e,t,r){t=t||[],r=r||0;for(var n=r;e>=_n;)t[r++]=e&255|mr,e/=128;for(;e&Mn;)t[r++]=e&255|mr,e>>>=7;return t[r]=e|0,gr.bytes=r-n+1,t}var On=Qe,Vn=128,yr=127;function Qe(e,n){var r=0,n=n||0,o=0,i=n,c,u=e.length;do{if(i>=u)throw Qe.bytes=0,new RangeError("Could not decode varint");c=e[i++],r+=o<28?(c&yr)<<o:(c&yr)*Math.pow(2,o),o+=7}while(c>=Vn);return Qe.bytes=i-n,r}var Fn=Math.pow(2,7),Ln=Math.pow(2,14),Rn=Math.pow(2,21),Pn=Math.pow(2,28),qn=Math.pow(2,35),jn=Math.pow(2,42),Gn=Math.pow(2,49),Jn=Math.pow(2,56),Kn=Math.pow(2,63),Qn=function(e){return e<Fn?1:e<Ln?2:e<Rn?3:e<Pn?4:e<qn?5:e<jn?6:e<Gn?7:e<Jn?8:e<Kn?9:10},Xn={encode:zn,decode:On,encodingLength:Qn},Hn=Xn,pe=Hn;var me=(e,t=0)=>[pe.decode(e,t),pe.decode.bytes],ee=(e,t,r=0)=>(pe.encode(e,t,r),t),te=e=>pe.encodingLength(e);var Gi=new Uint8Array(0);var br=(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},re=e=>{if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")};var xr=(e,t)=>{let r=t.byteLength,n=te(e),o=n+te(r),i=new Uint8Array(o+r);return ee(e,i,0),ee(r,i,n),i.set(t,o),new ne(e,r,t,i)},vr=e=>{let t=re(e),[r,n]=me(t),[o,i]=me(t.subarray(n)),c=t.subarray(n+i);if(c.byteLength!==o)throw new Error("Incorrect length");return new ne(r,o,c,t)},Er=(e,t)=>{if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&br(e.bytes,r.bytes)}},ne=class{constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function Zn(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),c=i.charCodeAt(0);if(r[c]!==255)throw new TypeError(i+" is ambiguous");r[c]=o}var u=e.length,h=e.charAt(0),x=Math.log(u)/Math.log(256),p=Math.log(256)/Math.log(u);function C(f){if(f instanceof Uint8Array||(ArrayBuffer.isView(f)?f=new Uint8Array(f.buffer,f.byteOffset,f.byteLength):Array.isArray(f)&&(f=Uint8Array.from(f))),!(f instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(f.length===0)return"";for(var y=0,I=0,w=0,v=f.length;w!==v&&f[w]===0;)w++,y++;for(var E=(v-w)*p+1>>>0,g=new Uint8Array(E);w!==v;){for(var A=f[w],T=0,b=E-1;(A!==0||T<I)&&b!==-1;b--,T++)A+=256*g[b]>>>0,g[b]=A%u>>>0,A=A/u>>>0;if(A!==0)throw new Error("Non-zero carry");I=T,w++}for(var U=E-I;U!==E&&g[U]===0;)U++;for(var P=h.repeat(y);U<E;++U)P+=e.charAt(g[U]);return P}function R(f){if(typeof f!="string")throw new TypeError("Expected String");if(f.length===0)return new Uint8Array;var y=0;if(f[y]!==" "){for(var I=0,w=0;f[y]===h;)I++,y++;for(var v=(f.length-y)*x+1>>>0,E=new Uint8Array(v);f[y];){var g=r[f.charCodeAt(y)];if(g===255)return;for(var A=0,T=v-1;(g!==0||A<w)&&T!==-1;T--,A++)g+=u*E[T]>>>0,E[T]=g%256>>>0,g=g/256>>>0;if(g!==0)throw new Error("Non-zero carry");w=A,y++}if(f[y]!==" "){for(var b=v-w;b!==v&&E[b]===0;)b++;for(var U=new Uint8Array(I+(v-b)),P=I;b!==v;)U[P++]=E[b++];return U}}}function _e(f){var y=R(f);if(y)return y;throw new Error(`Non-${t} character`)}return{encode:C,decodeUnsafe:R,decode:_e}}var Yn=Zn,eo=Yn,Ar=eo;var Xe=class{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")}},He=class{constructor(t,r,n){if(this.name=t,this.prefix=r,r.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=r.codePointAt(0),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 Ur(this,t)}},We=class{constructor(t){this.decoders=t}or(t){return Ur(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},Ur=(e,t)=>new We({...e.decoders||{[e.prefix]:e},...t.decoders||{[t.prefix]:t}}),Ze=class{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 He(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}},Sr=({name:e,prefix:t,encode:r,decode:n})=>new Ze(e,t,r,n),Ye=({prefix:e,name:t,alphabet:r})=>{let{encode:n,decode:o}=Ar(r,t);return Sr({prefix:e,name:t,encode:n,decode:i=>re(o(i))})},to=(e,t,r,n)=>{let o={};for(let p=0;p<t.length;++p)o[t[p]]=p;let i=e.length;for(;e[i-1]==="=";)--i;let c=new Uint8Array(i*r/8|0),u=0,h=0,x=0;for(let p=0;p<i;++p){let C=o[e[p]];if(C===void 0)throw new SyntaxError(`Non-${n} character`);h=h<<r|C,u+=r,u>=8&&(u-=8,c[x++]=255&h>>u)}if(u>=r||255&h<<8-u)throw new SyntaxError("Unexpected end of data");return c},ro=(e,t,r)=>{let n=t[t.length-1]==="=",o=(1<<r)-1,i="",c=0,u=0;for(let h=0;h<e.length;++h)for(u=u<<8|e[h],c+=8;c>r;)c-=r,i+=t[o&u>>c];if(c&&(i+=t[o&u<<r-c]),n)for(;i.length*r&7;)i+="=";return i},F=({name:e,prefix:t,bitsPerChar:r,alphabet:n})=>Sr({prefix:t,name:e,encode(o){return ro(o,n,r)},decode(o){return to(o,n,r,e)}});var j=Ye({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Yi=Ye({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ye=F({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),rs=F({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),ns=F({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),os=F({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),is=F({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),ss=F({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),cs=F({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),as=F({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),us=F({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Tr=(e,t)=>{let{bytes:r,version:n}=e;switch(n){case 0:return oo(r,et(e),t||j.encoder);default:return io(r,et(e),t||ye.encoder)}};var kr=new WeakMap,et=e=>{let t=kr.get(e);if(t==null){let r=new Map;return kr.set(e,r),r}return t},we=class e{constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==ge)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==so)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=xr(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&&t.code===n.code&&t.version===n.version&&Er(t.multihash,n.multihash)}toString(t){return Tr(this,t)}toJSON(){return{"/":Tr(this)}}link(){return this}get[Symbol.toStringTag](){return"CID"}[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:i,bytes:c}=r;return new e(n,o,i,c||Ir(n,o,i.bytes))}else if(r[co]===!0){let{version:n,multihash:o,code:i}=r,c=vr(o);return e.create(n,i,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=Ir(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)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=re(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=o.subarray(r.multihashSize-r.digestSize),c=new ne(r.multihashCode,r.digestSize,i,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[C,R]=me(t.subarray(r));return r+=R,C},o=n(),i=ge;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let c=r,u=n(),h=n(),x=r+h,p=x-c;return{version:o,codec:i,multihashCode:u,digestSize:h,multihashSize:p,size:x}}static parse(t,r){let[n,o]=no(t,r),i=e.decode(o);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return et(i).set(n,t),i}},no=(e,t)=>{switch(e[0]){case"Q":{let r=t||j;return[j.prefix,r.decode(`${j.prefix}${e}`)]}case j.prefix:{let r=t||j;return[j.prefix,r.decode(e)]}case ye.prefix:{let r=t||ye;return[ye.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}},oo=(e,t,r)=>{let{prefix:n}=r;if(n!==j.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let i=r.encode(e).slice(1);return t.set(n,i),i}else return o},io=(e,t,r)=>{let{prefix:n}=r,o=t.get(n);if(o==null){let i=r.encode(e);return t.set(n,i),i}else return o},ge=112,so=18,Ir=(e,t,r)=>{let n=te(e),o=n+te(t),i=new Uint8Array(o+r.byteLength);return ee(e,i,0),ee(t,i,n),i.set(r,o),i},co=Symbol.for("@ipld/js-cid/CID");var Cr=42;function ao(e){if(e.asCID!==e&&e["/"]!==e.bytes)return null;let t=we.asCID(e);if(!t)return null;let r=new Uint8Array(t.bytes.byteLength+1);return r.set(t.bytes,1),[new d(s.tag,Cr),new d(s.bytes,r)]}function uo(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function fo(e){if(Number.isNaN(e))throw new Error("`NaN` is not supported by the IPLD Data Model and cannot be encoded");if(e===1/0||e===-1/0)throw new Error("`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded");return null}var lo={float64:!0,typeEncoders:{Object:ao,undefined:uo,number:fo}};function ho(e){if(e[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return we.decode(e.subarray(1))}var Br={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};Br.tags[Cr]=ho;var Nr=113,$r=e=>Ge(e,lo),zr=e=>Ke(e,Br);var mo=_r,Dr=128,yo=127,go=~yo,wo=Math.pow(2,31);function _r(e,t,r){t=t||[],r=r||0;for(var n=r;e>=wo;)t[r++]=e&255|Dr,e/=128;for(;e&go;)t[r++]=e&255|Dr,e>>>=7;return t[r]=e|0,_r.bytes=r-n+1,t}var bo=tt,xo=128,Mr=127;function tt(e,n){var r=0,n=n||0,o=0,i=n,c,u=e.length;do{if(i>=u)throw tt.bytes=0,new RangeError("Could not decode varint");c=e[i++],r+=o<28?(c&Mr)<<o:(c&Mr)*Math.pow(2,o),o+=7}while(c>=xo);return tt.bytes=i-n,r}var vo=Math.pow(2,7),Eo=Math.pow(2,14),Ao=Math.pow(2,21),Uo=Math.pow(2,28),So=Math.pow(2,35),To=Math.pow(2,42),ko=Math.pow(2,49),Io=Math.pow(2,56),Co=Math.pow(2,63),Bo=function(e){return e<vo?1:e<Eo?2:e<Ao?3:e<Uo?4:e<So?5:e<To?6:e<ko?7:e<Io?8:e<Co?9:10},No={encode:mo,decode:bo,encodingLength:Bo},$o=No,be=$o;var xe=(e,t=0)=>[be.decode(e,t),be.decode.bytes],oe=(e,t,r=0)=>(be.encode(e,t,r),t),ie=e=>be.encodingLength(e);var bs=new Uint8Array(0);var Vr=(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},se=e=>{if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")};var ve=(e,t)=>{let r=t.byteLength,n=ie(e),o=n+ie(r),i=new Uint8Array(o+r);return oe(e,i,0),oe(r,i,n),i.set(t,o),new ce(e,r,t,i)},Fr=e=>{let t=se(e),[r,n]=xe(t),[o,i]=xe(t.subarray(n)),c=t.subarray(n+i);if(c.byteLength!==o)throw new Error("Incorrect length");return new ce(r,o,c,t)},Lr=(e,t)=>{if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Vr(e.bytes,r.bytes)}},ce=class{constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function zo(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),c=i.charCodeAt(0);if(r[c]!==255)throw new TypeError(i+" is ambiguous");r[c]=o}var u=e.length,h=e.charAt(0),x=Math.log(u)/Math.log(256),p=Math.log(256)/Math.log(u);function C(f){if(f instanceof Uint8Array||(ArrayBuffer.isView(f)?f=new Uint8Array(f.buffer,f.byteOffset,f.byteLength):Array.isArray(f)&&(f=Uint8Array.from(f))),!(f instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(f.length===0)return"";for(var y=0,I=0,w=0,v=f.length;w!==v&&f[w]===0;)w++,y++;for(var E=(v-w)*p+1>>>0,g=new Uint8Array(E);w!==v;){for(var A=f[w],T=0,b=E-1;(A!==0||T<I)&&b!==-1;b--,T++)A+=256*g[b]>>>0,g[b]=A%u>>>0,A=A/u>>>0;if(A!==0)throw new Error("Non-zero carry");I=T,w++}for(var U=E-I;U!==E&&g[U]===0;)U++;for(var P=h.repeat(y);U<E;++U)P+=e.charAt(g[U]);return P}function R(f){if(typeof f!="string")throw new TypeError("Expected String");if(f.length===0)return new Uint8Array;var y=0;if(f[y]!==" "){for(var I=0,w=0;f[y]===h;)I++,y++;for(var v=(f.length-y)*x+1>>>0,E=new Uint8Array(v);f[y];){var g=r[f.charCodeAt(y)];if(g===255)return;for(var A=0,T=v-1;(g!==0||A<w)&&T!==-1;T--,A++)g+=u*E[T]>>>0,E[T]=g%256>>>0,g=g/256>>>0;if(g!==0)throw new Error("Non-zero carry");w=A,y++}if(f[y]!==" "){for(var b=v-w;b!==v&&E[b]===0;)b++;for(var U=new Uint8Array(I+(v-b)),P=I;b!==v;)U[P++]=E[b++];return U}}}function _e(f){var y=R(f);if(y)return y;throw new Error(`Non-${t} character`)}return{encode:C,decodeUnsafe:R,decode:_e}}var Do=zo,Mo=Do,Pr=Mo;var rt=class{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")}},nt=class{constructor(t,r,n){if(this.name=t,this.prefix=r,r.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=r.codePointAt(0),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 qr(this,t)}},ot=class{constructor(t){this.decoders=t}or(t){return qr(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},qr=(e,t)=>new ot({...e.decoders||{[e.prefix]:e},...t.decoders||{[t.prefix]:t}}),it=class{constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new rt(t,r,n),this.decoder=new nt(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}},jr=({name:e,prefix:t,encode:r,decode:n})=>new it(e,t,r,n),st=({prefix:e,name:t,alphabet:r})=>{let{encode:n,decode:o}=Pr(r,t);return jr({prefix:e,name:t,encode:n,decode:i=>se(o(i))})},_o=(e,t,r,n)=>{let o={};for(let p=0;p<t.length;++p)o[t[p]]=p;let i=e.length;for(;e[i-1]==="=";)--i;let c=new Uint8Array(i*r/8|0),u=0,h=0,x=0;for(let p=0;p<i;++p){let C=o[e[p]];if(C===void 0)throw new SyntaxError(`Non-${n} character`);h=h<<r|C,u+=r,u>=8&&(u-=8,c[x++]=255&h>>u)}if(u>=r||255&h<<8-u)throw new SyntaxError("Unexpected end of data");return c},Oo=(e,t,r)=>{let n=t[t.length-1]==="=",o=(1<<r)-1,i="",c=0,u=0;for(let h=0;h<e.length;++h)for(u=u<<8|e[h],c+=8;c>r;)c-=r,i+=t[o&u>>c];if(c&&(i+=t[o&u<<r-c]),n)for(;i.length*r&7;)i+="=";return i},L=({name:e,prefix:t,bitsPerChar:r,alphabet:n})=>jr({prefix:t,name:e,encode(o){return Oo(o,n,r)},decode(o){return _o(o,n,r,e)}});var G=st({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ks=st({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ee=L({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Bs=L({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ns=L({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),$s=L({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),zs=L({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ds=L({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ms=L({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),_s=L({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Os=L({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Gr=(e,t)=>{let{bytes:r,version:n}=e;switch(n){case 0:return Fo(r,ct(e),t||G.encoder);default:return Lo(r,ct(e),t||Ee.encoder)}};var Jr=new WeakMap,ct=e=>{let t=Jr.get(e);if(t==null){let r=new Map;return Jr.set(e,r),r}return t},Me=class e{constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==Ae)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Ro)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:r}=this.multihash,n=ve(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&&t.code===n.code&&t.version===n.version&&Lr(t.multihash,n.multihash)}toString(t){return Gr(this,t)}toJSON(){return{"/":Gr(this)}}link(){return this}get[Symbol.toStringTag](){return"CID"}[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:i,bytes:c}=r;return new e(n,o,i,c||Kr(n,o,i.bytes))}else if(r[Po]===!0){let{version:n,multihash:o,code:i}=r,c=Fr(o);return e.create(n,i,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!==Ae)throw new Error(`Version 0 CID must use dag-pb (code: ${Ae}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Kr(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,Ae,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=se(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=o.subarray(r.multihashSize-r.digestSize),c=new ce(r.multihashCode,r.digestSize,i,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[C,R]=xe(t.subarray(r));return r+=R,C},o=n(),i=Ae;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let c=r,u=n(),h=n(),x=r+h,p=x-c;return{version:o,codec:i,multihashCode:u,digestSize:h,multihashSize:p,size:x}}static parse(t,r){let[n,o]=Vo(t,r),i=e.decode(o);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return ct(i).set(n,t),i}},Vo=(e,t)=>{switch(e[0]){case"Q":{let r=t||G;return[G.prefix,r.decode(`${G.prefix}${e}`)]}case G.prefix:{let r=t||G;return[G.prefix,r.decode(e)]}case Ee.prefix:{let r=t||Ee;return[Ee.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}},Fo=(e,t,r)=>{let{prefix:n}=r;if(n!==G.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let i=r.encode(e).slice(1);return t.set(n,i),i}else return o},Lo=(e,t,r)=>{let{prefix:n}=r,o=t.get(n);if(o==null){let i=r.encode(e);return t.set(n,i),i}else return o},Ae=112,Ro=18,Kr=(e,t,r)=>{let n=ie(e),o=n+ie(t),i=new Uint8Array(o+r.byteLength);return oe(e,i,0),oe(t,i,n),i.set(r,o),i},Po=Symbol.for("@ipld/js-cid/CID");var ut=({name:e,code:t,encode:r})=>new at(e,t,r),at=class{constructor(t,r,n){this.name=t,this.code=r,this.encode=n}digest(t){if(t instanceof Uint8Array){let r=this.encode(t);return r instanceof Uint8Array?ve(this.code,r):r.then(n=>ve(this.code,n))}else throw Error("Unknown type, must be binary type")}};var Qr=e=>async t=>new Uint8Array(await crypto.subtle.digest(e,t)),Xr=ut({name:"sha2-256",code:18,encode:Qr("SHA-256")}),Js=ut({name:"sha2-512",code:19,encode:Qr("SHA-512")});var dt=class{components;constructor(t){this.components=t}async add(t,r={}){let n=$r(t),o=await(r.hasher??Xr).digest(n),i=Me.createV1(Nr,o);return await this.components.blockstore.put(i,n,r),i}async get(t,r={}){let n=await this.components.blockstore.get(t,r);return zr(n)}};function qo(e){return new dt(e)}return tn(jo);})();
2
+ "use strict";var HeliaDagCbor=(()=>{var ke=Object.defineProperty;var wr=Object.getOwnPropertyDescriptor;var br=Object.getOwnPropertyNames;var xr=Object.prototype.hasOwnProperty;var Er=(e,t)=>{for(var r in t)ke(e,r,{get:t[r],enumerable:!0})},Ur=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of br(t))!xr.call(e,o)&&o!==r&&ke(e,o,{get:()=>t[o],enumerable:!(n=wr(t,o))||n.enumerable});return e};var vr=e=>Ur(ke({},"__esModule",{value:!0}),e);var zn={};Er(zn,{dagCbor:()=>Dn});var Ar=["string","number","bigint","symbol"],kr=["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 Je(e){if(e===null)return"null";if(e===void 0)return"undefined";if(e===!0||e===!1)return"boolean";let t=typeof e;if(Ar.includes(t))return t;if(t==="function")return"Function";if(Array.isArray(e))return"Array";if(Tr(e))return"Buffer";let r=Sr(e);return r||"Object"}function Tr(e){return e&&e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer.call(null,e)}function Sr(e){let t=Object.prototype.toString.call(e).slice(8,-1);if(kr.includes(t))return t}var s=class{constructor(t,r,n){this.major=t,this.majorEncoded=t<<5,this.name=r,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(t){return this.major<t.major?-1:this.major>t.major?1:0}};s.uint=new s(0,"uint",!0);s.negint=new s(1,"negint",!0);s.bytes=new s(2,"bytes",!0);s.string=new s(3,"string",!0);s.array=new s(4,"array",!1);s.map=new s(5,"map",!1);s.tag=new s(6,"tag",!1);s.float=new s(7,"float",!0);s.false=new s(7,"false",!0);s.true=new s(7,"true",!0);s.null=new s(7,"null",!0);s.undefined=new s(7,"undefined",!0);s.break=new s(7,"break",!0);var a=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 J=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Br=new TextDecoder,Ir=new TextEncoder;function he(e){return J&&globalThis.Buffer.isBuffer(e)}function Te(e){return e instanceof Uint8Array?he(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e:Uint8Array.from(e)}var Qe=J?(e,t,r)=>r-t>64?globalThis.Buffer.from(e.subarray(t,r)).toString("utf8"):He(e,t,r):(e,t,r)=>r-t>64?Br.decode(e.subarray(t,r)):He(e,t,r),We=J?e=>e.length>64?globalThis.Buffer.from(e):Ke(e):e=>e.length>64?Ir.encode(e):Ke(e),M=e=>Uint8Array.from(e),K=J?(e,t,r)=>he(e)?new Uint8Array(e.subarray(t,r)):e.slice(t,r):(e,t,r)=>e.slice(t,r),Ze=J?(e,t)=>(e=e.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),Te(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},Ye=J?e=>globalThis.Buffer.allocUnsafe(e):e=>new Uint8Array(e);function et(e,t){if(he(e)&&he(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 Ke(e,t=1/0){let r,n=e.length,o=null,i=[];for(let u=0;u<n;++u){if(r=e.charCodeAt(u),r>55295&&r<57344){if(!o){if(r>56319){(t-=3)>-1&&i.push(239,191,189);continue}else if(u+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=(o-55296<<10|r-56320)+65536}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,r&63|128)}else if(r<65536){if((t-=3)<0)break;i.push(r>>12|224,r>>6&63|128,r&63|128)}else if(r<1114112){if((t-=4)<0)break;i.push(r>>18|240,r>>12&63|128,r>>6&63|128,r&63|128)}else throw new Error("Invalid code point")}return i}function He(e,t,r){let n=[];for(;t<r;){let o=e[t],i=null,u=o>239?4:o>223?3:o>191?2:1;if(t+u<=r){let d,p,w,h;switch(u){case 1:o<128&&(i=o);break;case 2:d=e[t+1],(d&192)===128&&(h=(o&31)<<6|d&63,h>127&&(i=h));break;case 3:d=e[t+1],p=e[t+2],(d&192)===128&&(p&192)===128&&(h=(o&15)<<12|(d&63)<<6|p&63,h>2047&&(h<55296||h>57343)&&(i=h));break;case 4:d=e[t+1],p=e[t+2],w=e[t+3],(d&192)===128&&(p&192)===128&&(w&192)===128&&(h=(o&15)<<18|(d&63)<<12|(p&63)<<6|w&63,h>65535&&h<1114112&&(i=h))}}i===null?(i=65533,u=1):i>65535&&(i-=65536,n.push(i>>>10&1023|55296),i=56320|i&1023),n.push(i),t+=u}return Cr(n)}var Xe=4096;function Cr(e){let t=e.length;if(t<=Xe)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=Xe));return r}var Nr=256,te=class{constructor(t=Nr){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=Ye(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=K(n,0,this.cursor)}else r=Ze(this.chunks,this.cursor);return t&&this.reset(),r}};var f="CBOR decode error:",Se="CBOR encode error:",re=[];re[23]=1;re[24]=2;re[25]=3;re[26]=5;re[27]=9;function O(e,t,r){if(e.length-t<r)throw new Error(`${f} not enough data for type`)}var y=[24,256,65536,4294967296,BigInt("18446744073709551616")];function x(e,t,r){O(e,t,1);let n=e[t];if(r.strict===!0&&n<y[0])throw new Error(`${f} integer encoded in more bytes than necessary (strict decode)`);return n}function E(e,t,r){O(e,t,2);let n=e[t]<<8|e[t+1];if(r.strict===!0&&n<y[1])throw new Error(`${f} integer encoded in more bytes than necessary (strict decode)`);return n}function U(e,t,r){O(e,t,4);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];if(r.strict===!0&&n<y[2])throw new Error(`${f} integer encoded in more bytes than necessary (strict decode)`);return n}function v(e,t,r){O(e,t,8);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3],o=e[t+4]*16777216+(e[t+5]<<16)+(e[t+6]<<8)+e[t+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&i<y[3])throw new Error(`${f} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(r.allowBigInt===!0)return i;throw new Error(`${f} integers outside of the safe integer range are not supported`)}function tt(e,t,r,n){return new a(s.uint,x(e,t+1,n),2)}function rt(e,t,r,n){return new a(s.uint,E(e,t+1,n),3)}function nt(e,t,r,n){return new a(s.uint,U(e,t+1,n),5)}function ot(e,t,r,n){return new a(s.uint,v(e,t+1,n),9)}function k(e,t){return g(e,0,t.value)}function g(e,t,r){if(r<y[0]){let n=Number(r);e.push([t|n])}else if(r<y[1]){let n=Number(r);e.push([t|24,n])}else if(r<y[2]){let n=Number(r);e.push([t|25,n>>>8,n&255])}else if(r<y[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<y[4]){let o=[t|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),u=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=u&255,u=u>>8,o[3]=u&255,u=u>>8,o[2]=u&255,u=u>>8,o[1]=u&255,e.push(o)}else throw new Error(`${f} encountered BigInt larger than allowable range`)}}k.encodedSize=function(t){return g.encodedSize(t.value)};g.encodedSize=function(t){return t<y[0]?1:t<y[1]?2:t<y[2]?3:t<y[3]?5:9};k.compareTokens=function(t,r){return t.value<r.value?-1:t.value>r.value?1:0};function it(e,t,r,n){return new a(s.negint,-1-x(e,t+1,n),2)}function st(e,t,r,n){return new a(s.negint,-1-E(e,t+1,n),3)}function ct(e,t,r,n){return new a(s.negint,-1-U(e,t+1,n),5)}var Be=BigInt(-1),at=BigInt(1);function ut(e,t,r,n){let o=v(e,t+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new a(s.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${f} integers outside of the safe integer range are not supported`);return new a(s.negint,Be-BigInt(o),9)}function me(e,t){let r=t.value,n=typeof r=="bigint"?r*Be-at:r*-1-1;g(e,t.type.majorEncoded,n)}me.encodedSize=function(t){let r=t.value,n=typeof r=="bigint"?r*Be-at:r*-1-1;return n<y[0]?1:n<y[1]?2:n<y[2]?3:n<y[3]?5:9};me.compareTokens=function(t,r){return t.value<r.value?1:t.value>r.value?-1:0};function ne(e,t,r,n){O(e,t,r+n);let o=K(e,t+r,t+r+n);return new a(s.bytes,o,r+n)}function dt(e,t,r,n){return ne(e,t,1,r)}function ft(e,t,r,n){return ne(e,t,2,x(e,t+1,n))}function lt(e,t,r,n){return ne(e,t,3,E(e,t+1,n))}function pt(e,t,r,n){return ne(e,t,5,U(e,t+1,n))}function ht(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 ne(e,t,9,o)}function ye(e){return e.encodedBytes===void 0&&(e.encodedBytes=e.type===s.string?We(e.value):e.value),e.encodedBytes}function H(e,t){let r=ye(t);g(e,t.type.majorEncoded,r.length),e.push(r)}H.encodedSize=function(t){let r=ye(t);return g.encodedSize(r.length)+r.length};H.compareTokens=function(t,r){return $r(ye(t),ye(r))};function $r(e,t){return e.length<t.length?-1:e.length>t.length?1:et(e,t)}function oe(e,t,r,n,o){let i=r+n;O(e,t,i);let u=new a(s.string,Qe(e,t+r,t+i),i);return o.retainStringBytes===!0&&(u.byteValue=K(e,t+r,t+i)),u}function mt(e,t,r,n){return oe(e,t,1,r,n)}function yt(e,t,r,n){return oe(e,t,2,x(e,t+1,n),n)}function gt(e,t,r,n){return oe(e,t,3,E(e,t+1,n),n)}function wt(e,t,r,n){return oe(e,t,5,U(e,t+1,n),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 string lengths not supported`);return oe(e,t,9,o,n)}var xt=H;function X(e,t,r,n){return new a(s.array,n,r)}function Et(e,t,r,n){return X(e,t,1,r)}function Ut(e,t,r,n){return X(e,t,2,x(e,t+1,n))}function vt(e,t,r,n){return X(e,t,3,E(e,t+1,n))}function At(e,t,r,n){return X(e,t,5,U(e,t+1,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 array lengths not supported`);return X(e,t,9,o)}function Tt(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 ge(e,t){g(e,s.array.majorEncoded,t.value)}ge.compareTokens=k.compareTokens;ge.encodedSize=function(t){return g.encodedSize(t.value)};function Q(e,t,r,n){return new a(s.map,n,r)}function St(e,t,r,n){return Q(e,t,1,r)}function Bt(e,t,r,n){return Q(e,t,2,x(e,t+1,n))}function It(e,t,r,n){return Q(e,t,3,E(e,t+1,n))}function Ct(e,t,r,n){return Q(e,t,5,U(e,t+1,n))}function Nt(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 Q(e,t,9,o)}function _t(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${f} indefinite length items not allowed`);return Q(e,t,1,1/0)}function we(e,t){g(e,s.map.majorEncoded,t.value)}we.compareTokens=k.compareTokens;we.encodedSize=function(t){return g.encodedSize(t.value)};function $t(e,t,r,n){return new a(s.tag,r,1)}function Mt(e,t,r,n){return new a(s.tag,x(e,t+1,n),2)}function Dt(e,t,r,n){return new a(s.tag,E(e,t+1,n),3)}function zt(e,t,r,n){return new a(s.tag,U(e,t+1,n),5)}function Ot(e,t,r,n){return new a(s.tag,v(e,t+1,n),9)}function be(e,t){g(e,s.tag.majorEncoded,t.value)}be.compareTokens=k.compareTokens;be.encodedSize=function(t){return g.encodedSize(t.value)};var Vr=20,Lr=21,Rr=22,Pr=23;function Ft(e,t,r,n){if(n.allowUndefined===!1)throw new Error(`${f} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new a(s.null,null,1):new a(s.undefined,void 0,1)}function Vt(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${f} indefinite length items not allowed`);return new a(s.break,void 0,1)}function Ie(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 a(s.float,e,t)}function Lt(e,t,r,n){return Ie(Ce(e,t+1),3,n)}function Rt(e,t,r,n){return Ie(Ne(e,t+1),5,n)}function Pt(e,t,r,n){return Ie(Jt(e,t+1),9,n)}function xe(e,t,r){let n=t.value;if(n===!1)e.push([s.float.majorEncoded|Vr]);else if(n===!0)e.push([s.float.majorEncoded|Lr]);else if(n===null)e.push([s.float.majorEncoded|Rr]);else if(n===void 0)e.push([s.float.majorEncoded|Pr]);else{let o,i=!1;(!r||r.float64!==!0)&&(qt(n),o=Ce(I,1),n===o||Number.isNaN(n)?(I[0]=249,e.push(I.slice(0,3)),i=!0):(Gt(n),o=Ne(I,1),n===o&&(I[0]=250,e.push(I.slice(0,5)),i=!0))),i||(jr(n),o=Jt(I,1),I[0]=251,e.push(I.slice(0,9)))}}xe.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=Ce(I,1);if(n===o||Number.isNaN(n))return 3;if(Gt(n),o=Ne(I,1),n===o)return 5}return 9};var jt=new ArrayBuffer(9),T=new DataView(jt,1),I=new Uint8Array(jt,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,(e&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 Ce(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,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,r&32768?-i:i}function Gt(e){T.setFloat32(0,e,!1)}function Ne(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 Jt(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)}xe.compareTokens=k.compareTokens;function l(e,t,r){throw new Error(`${f} encountered invalid minor (${r}) for major ${e[t]>>>5}`)}function Ee(e){return()=>{throw new Error(`${f} ${e}`)}}var c=[];for(let e=0;e<=23;e++)c[e]=l;c[24]=tt;c[25]=rt;c[26]=nt;c[27]=ot;c[28]=l;c[29]=l;c[30]=l;c[31]=l;for(let e=32;e<=55;e++)c[e]=l;c[56]=it;c[57]=st;c[58]=ct;c[59]=ut;c[60]=l;c[61]=l;c[62]=l;c[63]=l;for(let e=64;e<=87;e++)c[e]=dt;c[88]=ft;c[89]=lt;c[90]=pt;c[91]=ht;c[92]=l;c[93]=l;c[94]=l;c[95]=Ee("indefinite length bytes/strings are not supported");for(let e=96;e<=119;e++)c[e]=mt;c[120]=yt;c[121]=gt;c[122]=wt;c[123]=bt;c[124]=l;c[125]=l;c[126]=l;c[127]=Ee("indefinite length bytes/strings are not supported");for(let e=128;e<=151;e++)c[e]=Et;c[152]=Ut;c[153]=vt;c[154]=At;c[155]=kt;c[156]=l;c[157]=l;c[158]=l;c[159]=Tt;for(let e=160;e<=183;e++)c[e]=St;c[184]=Bt;c[185]=It;c[186]=Ct;c[187]=Nt;c[188]=l;c[189]=l;c[190]=l;c[191]=_t;for(let e=192;e<=215;e++)c[e]=$t;c[216]=Mt;c[217]=Dt;c[218]=zt;c[219]=Ot;c[220]=l;c[221]=l;c[222]=l;c[223]=l;for(let e=224;e<=243;e++)c[e]=Ee("simple values are not supported");c[244]=l;c[245]=l;c[246]=l;c[247]=Ft;c[248]=Ee("simple values are not supported");c[249]=Lt;c[250]=Rt;c[251]=Pt;c[252]=l;c[253]=l;c[254]=l;c[255]=Vt;var C=[];for(let e=0;e<24;e++)C[e]=new a(s.uint,e,1);for(let e=-1;e>=-24;e--)C[31-e]=new a(s.negint,e,1);C[64]=new a(s.bytes,new Uint8Array(0),1);C[96]=new a(s.string,"",1);C[128]=new a(s.array,0,1);C[160]=new a(s.map,0,1);C[244]=new a(s.false,!1,1);C[245]=new a(s.true,!0,1);C[246]=new a(s.null,null,1);function Kt(e){switch(e.type){case s.false:return M([244]);case s.true:return M([245]);case s.null:return M([246]);case s.bytes:return e.value.length?void 0:M([64]);case s.string:return e.value===""?M([96]):void 0;case s.array:return e.value===0?M([128]):void 0;case s.map:return e.value===0?M([160]):void 0;case s.uint:return e.value<24?M([Number(e.value)]):void 0;case s.negint:if(e.value>=-24)return M([31-Number(e.value)])}}var Gr={float64:!1,mapSorter:Hr,quickEncodeToken:Kt};function Jr(){let e=[];return e[s.uint.major]=k,e[s.negint.major]=me,e[s.bytes.major]=H,e[s.string.major]=xt,e[s.array.major]=ge,e[s.map.major]=we,e[s.tag.major]=be,e[s.float.major]=xe,e}var Ht=Jr(),_e=new te,ve=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(`${Se} object contains circular references`);return new e(r,t)}},L={null:new a(s.null,null),undefined:new a(s.undefined,void 0),true:new a(s.true,!0),false:new a(s.false,!1),emptyArray:new a(s.array,0),emptyMap:new a(s.map,0)},R={number(e,t,r,n){return!Number.isInteger(e)||!Number.isSafeInteger(e)?new a(s.float,e):e>=0?new a(s.uint,e):new a(s.negint,e)},bigint(e,t,r,n){return e>=BigInt(0)?new a(s.uint,e):new a(s.negint,e)},Uint8Array(e,t,r,n){return new a(s.bytes,e)},string(e,t,r,n){return new a(s.string,e)},boolean(e,t,r,n){return e?L.true:L.false},null(e,t,r,n){return L.null},undefined(e,t,r,n){return L.undefined},ArrayBuffer(e,t,r,n){return new a(s.bytes,new Uint8Array(e))},DataView(e,t,r,n){return new a(s.bytes,new Uint8Array(e.buffer,e.byteOffset,e.byteLength))},Array(e,t,r,n){if(!e.length)return r.addBreakTokens===!0?[L.emptyArray,new a(s.break)]:L.emptyArray;n=ve.createCheck(n,e);let o=[],i=0;for(let u of e)o[i++]=Ue(u,r,n);return r.addBreakTokens?[new a(s.array,e.length),o,new a(s.break)]:[new a(s.array,e.length),o]},Object(e,t,r,n){let o=t!=="Object",i=o?e.keys():Object.keys(e),u=o?e.size:i.length;if(!u)return r.addBreakTokens===!0?[L.emptyMap,new a(s.break)]:L.emptyMap;n=ve.createCheck(n,e);let d=[],p=0;for(let w of i)d[p++]=[Ue(w,r,n),Ue(o?e.get(w):e[w],r,n)];return Kr(d,r),r.addBreakTokens?[new a(s.map,u),d,new a(s.break)]:[new a(s.map,u),d]}};R.Map=R.Object;R.Buffer=R.Uint8Array;for(let e of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))R[`${e}Array`]=R.DataView;function Ue(e,t={},r){let n=Je(e),o=t&&t.typeEncoders&&t.typeEncoders[n]||R[n];if(typeof o=="function"){let u=o(e,n,t,r);if(u!=null)return u}let i=R[n];if(!i)throw new Error(`${Se} unsupported type: ${n}`);return i(e,n,t,r)}function Kr(e,t){t.mapSorter&&e.sort(t.mapSorter)}function Hr(e,t){let r=Array.isArray(e[0])?e[0][0]:e[0],n=Array.isArray(t[0])?t[0][0]:t[0];if(r.type!==n.type)return r.type.compare(n.type);let o=r.type.major,i=Ht[o].compareTokens(r,n);return i===0&&console.warn("WARNING: complex key types used, CBOR key sorting guarantees are gone"),i}function Xt(e,t,r,n){if(Array.isArray(t))for(let o of t)Xt(e,o,r,n);else r[t.type.major](e,t,n)}function Xr(e,t,r){let n=Ue(e,r);if(!Array.isArray(n)&&r.quickEncodeToken){let o=r.quickEncodeToken(n);if(o)return o;let i=t[n.type.major];if(i.encodedSize){let u=i.encodedSize(n,r),d=new te(u);if(i(d,n,r),d.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${n} was wrong`);return Te(d.chunks[0])}}return _e.reset(),Xt(_e,n,t,r),_e.toBytes(!0)}function $e(e,t){return t=Object.assign({},Gr,t),Xr(e,Ht,t)}var Qr={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},Me=class{constructor(t,r={}){this.pos=0,this.data=t,this.options=r}done(){return this.pos>=this.data.length}next(){let t=this.data[this.pos],r=C[t];if(r===void 0){let n=c[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}},ie=Symbol.for("DONE"),Ae=Symbol.for("BREAK");function Wr(e,t,r){let n=[];for(let o=0;o<e.value;o++){let i=se(t,r);if(i===Ae){if(e.value===1/0)break;throw new Error(`${f} got unexpected break to lengthed array`)}if(i===ie)throw new Error(`${f} found array but not enough entries (got ${o}, expected ${e.value})`);n[o]=i}return n}function Zr(e,t,r){let n=r.useMaps===!0,o=n?void 0:{},i=n?new Map:void 0;for(let u=0;u<e.value;u++){let d=se(t,r);if(d===Ae){if(e.value===1/0)break;throw new Error(`${f} got unexpected break to lengthed map`)}if(d===ie)throw new Error(`${f} found map but not enough entries (got ${u} [no key], expected ${e.value})`);if(n!==!0&&typeof d!="string")throw new Error(`${f} non-string keys not supported (got ${typeof d})`);if(r.rejectDuplicateMapKeys===!0&&(n&&i.has(d)||!n&&d in o))throw new Error(`${f} found repeat map key "${d}"`);let p=se(t,r);if(p===ie)throw new Error(`${f} found map but not enough entries (got ${u} [no value], expected ${e.value})`);n?i.set(d,p):o[d]=p}return n?i:o}function se(e,t){if(e.done())return ie;let r=e.next();if(r.type===s.break)return Ae;if(r.type.terminal)return r.value;if(r.type===s.array)return Wr(r,e,t);if(r.type===s.map)return Zr(r,e,t);if(r.type===s.tag){if(t.tags&&typeof t.tags[r.value]=="function"){let n=se(e,t);return t.tags[r.value](n)}throw new Error(`${f} tag not supported (${r.value})`)}throw new Error("unsupported")}function De(e,t){if(!(e instanceof Uint8Array))throw new Error(`${f} data to decode must be a Uint8Array`);t=Object.assign({},Qr,t);let r=t.tokenizer||new Me(e,t),n=se(r,t);if(n===ie)throw new Error(`${f} did not find any content to decode`);if(n===Ae)throw new Error(`${f} got unexpected break`);if(!r.done())throw new Error(`${f} too many terminals, data makes no sense`);return n}var en=Zt,Qt=128,tn=127,rn=~tn,nn=Math.pow(2,31);function Zt(e,t,r){t=t||[],r=r||0;for(var n=r;e>=nn;)t[r++]=e&255|Qt,e/=128;for(;e&rn;)t[r++]=e&255|Qt,e>>>=7;return t[r]=e|0,Zt.bytes=r-n+1,t}var on=ze,sn=128,Wt=127;function ze(e,n){var r=0,n=n||0,o=0,i=n,u,d=e.length;do{if(i>=d)throw ze.bytes=0,new RangeError("Could not decode varint");u=e[i++],r+=o<28?(u&Wt)<<o:(u&Wt)*Math.pow(2,o),o+=7}while(u>=sn);return ze.bytes=i-n,r}var cn=Math.pow(2,7),an=Math.pow(2,14),un=Math.pow(2,21),dn=Math.pow(2,28),fn=Math.pow(2,35),ln=Math.pow(2,42),pn=Math.pow(2,49),hn=Math.pow(2,56),mn=Math.pow(2,63),yn=function(e){return e<cn?1:e<an?2:e<un?3:e<dn?4:e<fn?5:e<ln?6:e<pn?7:e<hn?8:e<mn?9:10},gn={encode:en,decode:on,encodingLength:yn},wn=gn,ce=wn;var ae=(e,t=0)=>[ce.decode(e,t),ce.decode.bytes],W=(e,t,r=0)=>(ce.encode(e,t,r),t),Z=e=>ce.encodingLength(e);var Fo=new Uint8Array(0);var er=(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},Y=e=>{if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")};var ue=(e,t)=>{let r=t.byteLength,n=Z(e),o=n+Z(r),i=new Uint8Array(o+r);return W(e,i,0),W(r,i,n),i.set(t,o),new ee(e,r,t,i)},tr=e=>{let t=Y(e),[r,n]=ae(t),[o,i]=ae(t.subarray(n)),u=t.subarray(n+i);if(u.byteLength!==o)throw new Error("Incorrect length");return new ee(r,o,u,t)},rr=(e,t)=>{if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&er(e.bytes,r.bytes)}},ee=class{constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function bn(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),u=i.charCodeAt(0);if(r[u]!==255)throw new TypeError(i+" is ambiguous");r[u]=o}var d=e.length,p=e.charAt(0),w=Math.log(d)/Math.log(256),h=Math.log(256)/Math.log(d);function G(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var b=0,P=0,S=0,N=m.length;S!==N&&m[S]===0;)S++,b++;for(var _=(N-S)*h+1>>>0,A=new Uint8Array(_);S!==N;){for(var $=m[S],V=0,B=_-1;($!==0||V<P)&&B!==-1;B--,V++)$+=256*A[B]>>>0,A[B]=$%d>>>0,$=$/d>>>0;if($!==0)throw new Error("Non-zero carry");P=V,S++}for(var z=_-P;z!==_&&A[z]===0;)z++;for(var pe=p.repeat(b);z<_;++z)pe+=e.charAt(A[z]);return pe}function le(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var b=0;if(m[b]!==" "){for(var P=0,S=0;m[b]===p;)P++,b++;for(var N=(m.length-b)*w+1>>>0,_=new Uint8Array(N);m[b];){var A=r[m.charCodeAt(b)];if(A===255)return;for(var $=0,V=N-1;(A!==0||$<S)&&V!==-1;V--,$++)A+=d*_[V]>>>0,_[V]=A%256>>>0,A=A/256>>>0;if(A!==0)throw new Error("Non-zero carry");S=$,b++}if(m[b]!==" "){for(var B=N-S;B!==N&&_[B]===0;)B++;for(var z=new Uint8Array(P+(N-B)),pe=P;B!==N;)z[pe++]=_[B++];return z}}}function gr(m){var b=le(m);if(b)return b;throw new Error(`Non-${t} character`)}return{encode:G,decodeUnsafe:le,decode:gr}}var xn=bn,En=xn,or=En;var Oe=class{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")}},Fe=class{constructor(t,r,n){if(this.name=t,this.prefix=r,r.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=r.codePointAt(0),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 ir(this,t)}},Ve=class{constructor(t){this.decoders=t}or(t){return ir(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},ir=(e,t)=>new Ve({...e.decoders||{[e.prefix]:e},...t.decoders||{[t.prefix]:t}}),Le=class{constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Oe(t,r,n),this.decoder=new Fe(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}},sr=({name:e,prefix:t,encode:r,decode:n})=>new Le(e,t,r,n),Re=({prefix:e,name:t,alphabet:r})=>{let{encode:n,decode:o}=or(r,t);return sr({prefix:e,name:t,encode:n,decode:i=>Y(o(i))})},Un=(e,t,r,n)=>{let o={};for(let h=0;h<t.length;++h)o[t[h]]=h;let i=e.length;for(;e[i-1]==="=";)--i;let u=new Uint8Array(i*r/8|0),d=0,p=0,w=0;for(let h=0;h<i;++h){let G=o[e[h]];if(G===void 0)throw new SyntaxError(`Non-${n} character`);p=p<<r|G,d+=r,d>=8&&(d-=8,u[w++]=255&p>>d)}if(d>=r||255&p<<8-d)throw new SyntaxError("Unexpected end of data");return u},vn=(e,t,r)=>{let n=t[t.length-1]==="=",o=(1<<r)-1,i="",u=0,d=0;for(let p=0;p<e.length;++p)for(d=d<<8|e[p],u+=8;u>r;)u-=r,i+=t[o&d>>u];if(u&&(i+=t[o&d<<r-u]),n)for(;i.length*r&7;)i+="=";return i},D=({name:e,prefix:t,bitsPerChar:r,alphabet:n})=>sr({prefix:t,name:e,encode(o){return vn(o,n,r)},decode(o){return Un(o,n,r,e)}});var F=Re({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Jo=Re({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var de=D({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Xo=D({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Qo=D({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Wo=D({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Zo=D({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Yo=D({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ei=D({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ti=D({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ri=D({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var cr=(e,t)=>{let{bytes:r,version:n}=e;switch(n){case 0:return kn(r,Pe(e),t||F.encoder);default:return Tn(r,Pe(e),t||de.encoder)}};var ar=new WeakMap,Pe=e=>{let t=ar.get(e);if(t==null){let r=new Map;return ar.set(e,r),r}return t},q=class e{constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==fe)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Sn)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=ue(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&&t.code===n.code&&t.version===n.version&&rr(t.multihash,n.multihash)}toString(t){return cr(this,t)}toJSON(){return{"/":cr(this)}}link(){return this}get[Symbol.toStringTag](){return"CID"}[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:i,bytes:u}=r;return new e(n,o,i,u||ur(n,o,i.bytes))}else if(r[Bn]===!0){let{version:n,multihash:o,code:i}=r,u=tr(o);return e.create(n,i,u)}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!==fe)throw new Error(`Version 0 CID must use dag-pb (code: ${fe}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=ur(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,fe,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=Y(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=o.subarray(r.multihashSize-r.digestSize),u=new ee(r.multihashCode,r.digestSize,i,o);return[r.version===0?e.createV0(u):e.createV1(r.codec,u),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[G,le]=ae(t.subarray(r));return r+=le,G},o=n(),i=fe;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let u=r,d=n(),p=n(),w=r+p,h=w-u;return{version:o,codec:i,multihashCode:d,digestSize:p,multihashSize:h,size:w}}static parse(t,r){let[n,o]=An(t,r),i=e.decode(o);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Pe(i).set(n,t),i}},An=(e,t)=>{switch(e[0]){case"Q":{let r=t||F;return[F.prefix,r.decode(`${F.prefix}${e}`)]}case F.prefix:{let r=t||F;return[F.prefix,r.decode(e)]}case de.prefix:{let r=t||de;return[de.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}},kn=(e,t,r)=>{let{prefix:n}=r;if(n!==F.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let i=r.encode(e).slice(1);return t.set(n,i),i}else return o},Tn=(e,t,r)=>{let{prefix:n}=r,o=t.get(n);if(o==null){let i=r.encode(e);return t.set(n,i),i}else return o},fe=112,Sn=18,ur=(e,t,r)=>{let n=Z(e),o=n+Z(t),i=new Uint8Array(o+r.byteLength);return W(e,i,0),W(t,i,n),i.set(r,o),i},Bn=Symbol.for("@ipld/js-cid/CID");var dr=42;function In(e){if(e.asCID!==e&&e["/"]!==e.bytes)return null;let t=q.asCID(e);if(!t)return null;let r=new Uint8Array(t.bytes.byteLength+1);return r.set(t.bytes,1),[new a(s.tag,dr),new a(s.bytes,r)]}function Cn(){throw new Error("`undefined` is not supported by the IPLD Data Model and cannot be encoded")}function Nn(e){if(Number.isNaN(e))throw new Error("`NaN` is not supported by the IPLD Data Model and cannot be encoded");if(e===1/0||e===-1/0)throw new Error("`Infinity` and `-Infinity` is not supported by the IPLD Data Model and cannot be encoded");return null}var _n={float64:!0,typeEncoders:{Object:In,undefined:Cn,number:Nn}};function $n(e){if(e[0]!==0)throw new Error("Invalid CID for CBOR tag 42; expected leading 0x00");return q.decode(e.subarray(1))}var fr={allowIndefinite:!1,coerceUndefinedToNull:!0,allowNaN:!1,allowInfinity:!1,allowBigInt:!0,strict:!0,useMaps:!1,rejectDuplicateMapKeys:!0,tags:[]};fr.tags[dr]=$n;var lr=113,pr=e=>$e(e,_n),hr=e=>De(e,fr);var qe=({name:e,code:t,encode:r})=>new je(e,t,r),je=class{constructor(t,r,n){this.name=t,this.code=r,this.encode=n}digest(t){if(t instanceof Uint8Array){let r=this.encode(t);return r instanceof Uint8Array?ue(this.code,r):r.then(n=>ue(this.code,n))}else throw Error("Unknown type, must be binary type")}};var mr=e=>async t=>new Uint8Array(await crypto.subtle.digest(e,t)),yr=qe({name:"sha2-256",code:18,encode:mr("SHA-256")}),li=qe({name:"sha2-512",code:19,encode:mr("SHA-512")});var Ge=class{components;constructor(t){this.components=t}async add(t,r={}){let n=pr(t),o=await(r.hasher??yr).digest(n),i=q.createV1(lr,o);return await this.components.blockstore.put(i,n,r),i}async get(t,r={}){let n=await this.components.blockstore.get(t,r);return hr(n)}};function Dn(e){return new Ge(e)}return vr(zn);})();
3
3
  return HeliaDagCbor}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@helia/dag-cbor",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Add/get IPLD blocks containing dag-cbor with your Helia node",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/ipfs/helia-dag-cbor/tree/master/packages/dag-cbor#readme",
@@ -135,11 +135,11 @@
135
135
  "release": "aegir release"
136
136
  },
137
137
  "dependencies": {
138
- "@helia/interface": "^1.0.0",
138
+ "@helia/interface": "^2.0.0",
139
139
  "@ipld/dag-cbor": "^9.0.0",
140
140
  "@libp2p/interfaces": "^3.3.1",
141
141
  "interface-blockstore": "^5.0.0",
142
- "multiformats": "^11.0.1",
142
+ "multiformats": "^12.0.1",
143
143
  "progress-events": "^1.0.0"
144
144
  },
145
145
  "devDependencies": {