var Z=Object.defineProperty;var Y=(r,t,e)=>t in r?Z(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e;var c=(r,t,e)=>Y(r,typeof t!="symbol"?t+"":t,e);const H=new Uint8Array(0);function Qe(r){const t=r.match(/../g);return t!=null?new Uint8Array(t.map(e=>parseInt(e,16))):H}function ee(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n>>0,u=new Uint8Array(y);p!==w;){for(var g=a[p],E=0,b=y-1;(g!==0||E>>0,u[b]=g%d>>>0,g=g/d>>>0;if(g!==0)throw new Error("Non-zero carry");A=E,p++}for(var v=y-A;v!==y&&u[v]===0;)v++;for(var O=l.repeat(f);v>>0,y=new Uint8Array(w);a[f];){var u=e[a.charCodeAt(f)];if(u===255)return;for(var g=0,E=w-1;(u!==0||g>>0,y[E]=u%256>>>0,u=u/256>>>0;if(u!==0)throw new Error("Non-zero carry");p=g,f++}if(a[f]!==" "){for(var b=w-p;b!==w&&y[b]===0;)b++;for(var v=new Uint8Array(A+(w-b)),O=A;b!==w;)v[O++]=y[b++];return v}}}function W(a){var f=M(a);if(f)return f;throw new Error(`Non-${t} character`)}return{encode:I,decodeUnsafe:M,decode:W}}var re=te,ne=re;class oe{constructor(t,e,n){c(this,"name");c(this,"prefix");c(this,"baseEncode");this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}}class se{constructor(t,e,n){c(this,"name");c(this,"prefix");c(this,"baseDecode");c(this,"prefixCodePoint");this.name=t,this.prefix=e;const o=e.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 G(this,t)}}class ie{constructor(t){c(this,"decoders");this.decoders=t}or(t){return G(this,t)}decode(t){const e=t[0],n=this.decoders[e];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 G(r,t){return new ie({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}class ae{constructor(t,e,n,o){c(this,"name");c(this,"prefix");c(this,"baseEncode");c(this,"baseDecode");c(this,"encoder");c(this,"decoder");this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new oe(t,e,n),this.decoder=new se(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}}function K({name:r,prefix:t,encode:e,decode:n}){return new ae(r,t,e,n)}function T({name:r,prefix:t,alphabet:e}){const{encode:n,decode:o}=ne(e,r);return K({prefix:t,name:r,encode:n,decode:s=>F(o(s))})}function ce(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;const s=new Uint8Array(o*e/8|0);let i=0,d=0,l=0;for(let S=0;S=8&&(i-=8,s[l++]=255&d>>i)}if(i>=e||255&d<<8-i)throw new SyntaxError("Unexpected end of data");return s}function de(r,t,e){const n=t[t.length-1]==="=",o=(1<e;)i-=e,s+=t[o&d>>i];if(i!==0&&(s+=t[o&d<=Ee;)t[e++]=r&255|R,r/=128;for(;r&Se;)t[e++]=r&255|R,r>>>=7;return t[e]=r|0,X.bytes=e-n+1,t}var Ae=j,ze=128,_=127;function j(r,n){var e=0,n=n||0,o=0,s=n,i,d=r.length;do{if(s>=d)throw j.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&_)<=ze);return j.bytes=s-n,e}var Ce=Math.pow(2,7),Ue=Math.pow(2,14),Me=Math.pow(2,21),Oe=Math.pow(2,28),$e=Math.pow(2,35),Ne=Math.pow(2,42),De=Math.pow(2,49),Ve=Math.pow(2,56),Te=Math.pow(2,63),Ie=function(r){return r{const[I,M]=L(t.subarray(e));return e+=M,I};let o=n(),s=C;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);const i=e,d=n(),l=n(),S=e+l,z=S-i;return{version:o,codec:s,multihashCode:d,digestSize:l,multihashSize:z,size:S}}static parse(t,e){const[n,o]=Fe(t,e),s=h.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return B(s).set(n,t),s}}function Fe(r,t){switch(r[0]){case"Q":{const e=t??x;return[x.prefix,e.decode(`${x.prefix}${r}`)]}case x.prefix:{const e=t??x;return[x.prefix,e.decode(r)]}case U.prefix:{const e=t??U;return[U.prefix,e.decode(r)]}case $.prefix:{const e=t??$;return[$.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function Pe(r,t,e){const{prefix:n}=e;if(n!==x.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);const o=t.get(n);if(o==null){const s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function Re(r,t,e){const{prefix:n}=e,o=t.get(n);if(o==null){const s=e.encode(r);return t.set(n,s),s}else return o}const C=112,_e=18;function J(r,t,e){const n=V(r),o=n+V(t),s=new Uint8Array(o+e.byteLength);return D(r,s,0),D(t,s,n),s.set(e,o),s}const qe=Symbol.for("@ipld/js-cid/CID"),Ye=Object.freeze(Object.defineProperty({__proto__:null,CID:h,format:k},Symbol.toStringTag,{value:"Module"}));export{h as C,$ as a,x as b,Le as c,ke as d,U as e,Qe as f,T as g,K as h,Ge as i,F as j,Ze as k,We as l,Xe as m,Ye as n,m as r,Ke as t}; //# sourceMappingURL=cid-DnxG1pfC.js.map