morphit/node_modules/uint8arrays/dist/index.min.js

4 lines
20 KiB
JavaScript

(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Uint8Arrays = factory()}(typeof self !== 'undefined' ? self : this, function () {
"use strict";var Uint8Arrays=(()=>{var Q=Object.defineProperty;var Ke=Object.getOwnPropertyDescriptor;var We=Object.getOwnPropertyNames;var He=Object.prototype.hasOwnProperty;var p=(e,r)=>{for(var t in r)Q(e,t,{get:r[t],enumerable:!0})},Ze=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of We(r))!He.call(e,o)&&o!==t&&Q(e,o,{get:()=>r[o],enumerable:!(n=Ke(r,o))||n.enumerable});return e};var Ye=e=>Ze(Q({},"__esModule",{value:!0}),e);var pt={};p(pt,{alloc:()=>ge,allocUnsafe:()=>U,compare:()=>ve,concat:()=>Ae,equals:()=>be,fromString:()=>Ge,toString:()=>Xe,withArrayBuffer:()=>xe,xor:()=>we,xorCompare:()=>ye});function be(e,r){if(e===r)return!0;if(e.byteLength!==r.byteLength)return!1;for(let t=0;t<e.byteLength;t++)if(e[t]!==r[t])return!1;return!0}function _e(e){return e.buffer instanceof ArrayBuffer}function xe(e){return _e(e)?e:e.slice()}function ye(e,r){if(e.byteLength!==r.byteLength)throw new Error("Inputs should have the same length");for(let t=0;t<e.byteLength;t++)if(e[t]!==r[t])return e[t]<r[t]?-1:1;return 0}function ge(e=0){return new Uint8Array(e)}function U(e=0){return new Uint8Array(e)}function er(e){return e?.buffer instanceof ArrayBuffer}function j(e){if(er(e))return e;let r=e.slice();return new Uint8Array(r.buffer,0,r.byteLength)}function we(e,r){if(e.length!==r.length)throw new Error("Inputs should have the same length");let t=U(e.length);for(let n=0;n<e.length;n++)t[n]=e[n]^r[n];return j(t)}function ve(e,r){for(let t=0;t<e.byteLength;t++){if(e[t]<r[t])return-1;if(e[t]>r[t])return 1}return e.byteLength>r.byteLength?1:e.byteLength<r.byteLength?-1:0}function Ae(e,r){r==null&&(r=e.reduce((o,i)=>o+i.length,0));let t=U(r),n=0;for(let o of e)t.set(o,n),n+=o.length;return j(t)}var Y={};p(Y,{base10:()=>cr});var Ct=new Uint8Array(0);function Ee(e,r){if(e===r)return!0;if(e.byteLength!==r.byteLength)return!1;for(let t=0;t<e.byteLength;t++)if(e[t]!==r[t])return!1;return!0}function v(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return D(e);if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return D(new Uint8Array(e.buffer,e.byteOffset,e.byteLength));throw new Error("Unknown type, must be binary type")}function Ue(e){return new TextEncoder().encode(e)}function Ce(e){return new TextDecoder().decode(e)}function rr(e){return e?.buffer instanceof ArrayBuffer}function D(e){return rr(e)?e:e.slice()}function tr(e,r){if(e.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<e.length;o++){var i=e.charAt(o),s=i.charCodeAt(0);if(t[s]!==255)throw new TypeError(i+" is ambiguous");t[s]=o}var f=e.length,h=e.charAt(0),A=Math.log(f)/Math.log(256),L=Math.log(256)/Math.log(f);function X(a){if(a instanceof Uint8Array||(ArrayBuffer.isView(a)?a=new Uint8Array(a.buffer,a.byteOffset,a.byteLength):Array.isArray(a)&&(a=Uint8Array.from(a))),!(a instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(a.length===0)return"";for(var u=0,S=0,l=0,b=a.length;l!==b&&a[l]===0;)l++,u++;for(var x=(b-l)*L+1>>>0,d=new Uint8Array(x);l!==b;){for(var y=a[l],E=0,m=x-1;(y!==0||E<S)&&m!==-1;m--,E++)y+=256*d[m]>>>0,d[m]=y%f>>>0,y=y/f>>>0;if(y!==0)throw new Error("Non-zero carry");S=E,l++}for(var w=x-S;w!==x&&d[w]===0;)w++;for(var F=h.repeat(u);w<x;++w)F+=e.charAt(d[w]);return F}function q(a){if(typeof a!="string")throw new TypeError("Expected String");if(a.length===0)return new Uint8Array;var u=0;if(a[u]!==" "){for(var S=0,l=0;a[u]===h;)S++,u++;for(var b=(a.length-u)*A+1>>>0,x=new Uint8Array(b);a[u];){var d=t[a.charCodeAt(u)];if(d===255)return;for(var y=0,E=b-1;(d!==0||y<l)&&E!==-1;E--,y++)d+=f*x[E]>>>0,x[E]=d%256>>>0,d=d/256>>>0;if(d!==0)throw new Error("Non-zero carry");l=y,u++}if(a[u]!==" "){for(var m=b-l;m!==b&&x[m]===0;)m++;for(var w=new Uint8Array(S+(b-m)),F=S;m!==b;)w[F++]=x[m++];return w}}}function Qe(a){var u=q(a);if(u)return u;throw new Error(`Non-${r} character`)}return{encode:X,decodeUnsafe:q,decode:Qe}}var nr=tr,or=nr,De=or;var K=class{name;prefix;baseEncode;constructor(r,t,n){this.name=r,this.prefix=t,this.baseEncode=n}encode(r){if(r instanceof Uint8Array)return`${this.prefix}${this.baseEncode(r)}`;throw Error("Unknown type, must be binary type")}},W=class{name;prefix;baseDecode;prefixCodePoint;constructor(r,t,n){this.name=r,this.prefix=t;let o=t.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(r){if(typeof r=="string"){if(r.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(r)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(r.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(r){return Le(this,r)}},H=class{decoders;constructor(r){this.decoders=r}or(r){return Le(this,r)}decode(r){let t=r[0],n=this.decoders[t];if(n!=null)return n.decode(r);throw RangeError(`Unable to decode multibase string ${JSON.stringify(r)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Le(e,r){return new H({...e.decoders??{[e.prefix]:e},...r.decoders??{[r.prefix]:r}})}var Z=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(r,t,n,o){this.name=r,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new K(r,t,n),this.decoder=new W(r,t,o)}encode(r){return this.encoder.encode(r)}decode(r){return this.decoder.decode(r)}};function B({name:e,prefix:r,encode:t,decode:n}){return new Z(e,r,t,n)}function C({name:e,prefix:r,alphabet:t}){let{encode:n,decode:o}=De(t,e);return B({prefix:r,name:e,encode:n,decode:i=>v(o(i))})}function ir(e,r,t,n){let o=e.length;for(;e[o-1]==="=";)--o;let i=new Uint8Array(o*t/8|0),s=0,f=0,h=0;for(let A=0;A<o;++A){let L=r[e[A]];if(L===void 0)throw new SyntaxError(`Non-${n} character`);f=f<<t|L,s+=t,s>=8&&(s-=8,i[h++]=255&f>>s)}if(s>=t||(255&f<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function sr(e,r,t){let n=r[r.length-1]==="=",o=(1<<t)-1,i="",s=0,f=0;for(let h=0;h<e.length;++h)for(f=f<<8|e[h],s+=8;s>t;)s-=t,i+=r[o&f>>s];if(s!==0&&(i+=r[o&f<<t-s]),n)for(;(i.length*t&7)!==0;)i+="=";return i}function ar(e){let r={};for(let t=0;t<e.length;++t)r[e[t]]=t;return r}function c({name:e,prefix:r,bitsPerChar:t,alphabet:n}){let o=ar(n);return B({prefix:r,name:e,encode(i){return sr(i,n,t)},decode(i){return ir(i,o,t,e)}})}var cr=C({prefix:"9",name:"base10",alphabet:"0123456789"});var _={};p(_,{base16:()=>fr,base16upper:()=>ur});var fr=c({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),ur=c({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ee={};p(ee,{base2:()=>pr});var pr=c({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var re={};p(re,{base256emoji:()=>br});var Be=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),dr=Be.reduce((e,r,t)=>(e[t]=r,e),[]),hr=Be.reduce((e,r,t)=>{let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);return e[n]=t,e},[]);function lr(e){return e.reduce((r,t)=>(r+=dr[t],r),"")}function mr(e){let r=[];for(let t of e){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=hr[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);r.push(o)}return new Uint8Array(r)}var br=B({prefix:"\u{1F680}",name:"base256emoji",encode:lr,decode:mr});var te={};p(te,{base32:()=>I,base32hex:()=>wr,base32hexpad:()=>Ar,base32hexpadupper:()=>Er,base32hexupper:()=>vr,base32pad:()=>yr,base32padupper:()=>gr,base32upper:()=>xr,base32z:()=>Ur});var I=c({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),xr=c({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),yr=c({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),gr=c({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),wr=c({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),vr=c({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ar=c({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Er=c({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ur=c({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ne={};p(ne,{base36:()=>O,base36upper:()=>Cr});var O=C({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Cr=C({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var oe={};p(oe,{base58btc:()=>g,base58flickr:()=>Sr});var g=C({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Sr=C({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ie={};p(ie,{base64:()=>Dr,base64pad:()=>Lr,base64url:()=>Br,base64urlpad:()=>Ir});var Dr=c({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Lr=c({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Br=c({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Ir=c({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var se={};p(se,{base8:()=>zr});var zr=c({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ae={};p(ae,{identity:()=>Mr});var Mr=B({prefix:"\0",name:"identity",encode:e=>Ce(e),decode:e=>Ue(e)});var Ft=new TextEncoder,jt=new TextDecoder;var fe={};p(fe,{identity:()=>rt});var Or=Me,Ie=128,$r=127,Vr=~$r,kr=Math.pow(2,31);function Me(e,r,t){r=r||[],t=t||0;for(var n=t;e>=kr;)r[t++]=e&255|Ie,e/=128;for(;e&Vr;)r[t++]=e&255|Ie,e>>>=7;return r[t]=e|0,Me.bytes=t-n+1,r}var Pr=ce,qr=128,ze=127;function ce(e,n){var t=0,n=n||0,o=0,i=n,s,f=e.length;do{if(i>=f)throw ce.bytes=0,new RangeError("Could not decode varint");s=e[i++],t+=o<28?(s&ze)<<o:(s&ze)*Math.pow(2,o),o+=7}while(s>=qr);return ce.bytes=i-n,t}var Fr=Math.pow(2,7),jr=Math.pow(2,14),Rr=Math.pow(2,21),Jr=Math.pow(2,28),Gr=Math.pow(2,35),Xr=Math.pow(2,42),Qr=Math.pow(2,49),Kr=Math.pow(2,56),Wr=Math.pow(2,63),Hr=function(e){return e<Fr?1:e<jr?2:e<Rr?3:e<Jr?4:e<Gr?5:e<Xr?6:e<Qr?7:e<Kr?8:e<Wr?9:10},Zr={encode:Or,decode:Pr,encodingLength:Hr},Yr=Zr,$=Yr;function V(e,r=0){return[$.decode(e,r),$.decode.bytes]}function z(e,r,t=0){return $.encode(e,r,t),r}function M(e){return $.encodingLength(e)}function N(e,r){let t=r.byteLength,n=M(e),o=n+M(t),i=new Uint8Array(o+t);return z(e,i,0),z(t,i,n),i.set(r,o),new T(e,t,r,i)}function Te(e){let r=v(e),[t,n]=V(r),[o,i]=V(r.subarray(n)),s=r.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new T(t,o,s,r)}function Ne(e,r){if(e===r)return!0;{let t=r;return e.code===t.code&&e.size===t.size&&t.bytes instanceof Uint8Array&&Ee(e.bytes,t.bytes)}}var T=class{code;size;digest;bytes;constructor(r,t,n,o){this.code=r,this.size=t,this.digest=D(n),this.bytes=D(o)}};var Oe=0,_r="identity",$e=v;function et(e,r){if(r?.truncate!=null&&r.truncate!==e.byteLength){if(r.truncate<0||r.truncate>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r.truncate)}return N(Oe,$e(e))}var rt={code:Oe,name:_r,encode:$e,digest:et};var de={};p(de,{sha256:()=>nt,sha512:()=>ot});var tt=20;function pe({name:e,code:r,encode:t,minDigestLength:n,maxDigestLength:o}){return new ue(e,r,t,n,o)}var ue=class{name;code;encode;minDigestLength;maxDigestLength;constructor(r,t,n,o,i){this.name=r,this.code=t,this.encode=n,this.minDigestLength=o??tt,this.maxDigestLength=i}digest(r,t){if(t?.truncate!=null){if(t.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&t.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(r instanceof Uint8Array){let n=this.encode(r);return n instanceof Uint8Array?Ve(n,this.code,t?.truncate):n.then(o=>Ve(o,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function Ve(e,r,t){if(t!=null&&t!==e.byteLength){if(t>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,t)}return N(r,e)}function Pe(e){return async r=>new Uint8Array(await crypto.subtle.digest(e,r))}var nt=pe({name:"sha2-256",code:18,encode:Pe("SHA-256")}),ot=pe({name:"sha2-512",code:19,encode:Pe("SHA-512")});function qe(e,r){let{bytes:t,version:n}=e;return n===0?st(t,he(e),r??g.encoder):at(t,he(e),r??I.encoder)}var Fe=new WeakMap;function he(e){let r=Fe.get(e);if(r==null){let t=new Map;return Fe.set(e,t),t}return r}var J=class e{code;version;multihash;bytes;"/";constructor(r,t,n,o){this.code=t,this.version=r,this.multihash=n,this.bytes=D(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:r,multihash:t}=this;if(r!==P)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==ct)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(t)}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:r,digest:t}=this.multihash,n=N(r,t);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(r){return e.equals(this,r)}static equals(r,t){let n=t;return n!=null&&r.code===n.code&&r.version===n.version&&Ne(r.multihash,n.multihash)}toString(r){return qe(this,r)}toJSON(){return{"/":qe(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(r){if(r==null)return null;let t=r;if(t instanceof e)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:i,bytes:s}=t;return new e(n,o,i,s??je(n,o,i.bytes))}else if(t[ft]===!0){let{version:n,multihash:o,code:i}=t,s=Te(o);return e.create(n,i,s)}else return null}static create(r,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(r){case 0:{if(t!==P)throw new Error(`Version 0 CID must use dag-pb (code: ${P}) block encoding`);return new e(r,t,n,n.bytes)}case 1:{let o=je(r,t,n.bytes);return new e(r,t,n,o)}default:throw new Error("Invalid version")}}static createV0(r){return e.create(0,P,r)}static createV1(r,t){return e.create(1,r,t)}static decode(r){let[t,n]=e.decodeFirst(r);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(r){let t=e.inspectBytes(r),n=t.size-t.multihashSize,o=v(r.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let i=o.subarray(t.multihashSize-t.digestSize),s=new T(t.multihashCode,t.digestSize,i,o);return[t.version===0?e.createV0(s):e.createV1(t.codec,s),r.subarray(t.size)]}static inspectBytes(r){let t=0,n=()=>{let[X,q]=V(r.subarray(t));return t+=q,X},o=n(),i=P;if(o===18?(o=0,t=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=t,f=n(),h=n(),A=t+h,L=A-s;return{version:o,codec:i,multihashCode:f,digestSize:h,multihashSize:L,size:A}}static parse(r,t){let[n,o]=it(r,t),i=e.decode(o);if(i.version===0&&r[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return he(i).set(n,r),i}};function it(e,r){switch(e[0]){case"Q":{let t=r??g;return[g.prefix,t.decode(`${g.prefix}${e}`)]}case g.prefix:{let t=r??g;return[g.prefix,t.decode(e)]}case I.prefix:{let t=r??I;return[I.prefix,t.decode(e)]}case O.prefix:{let t=r??O;return[O.prefix,t.decode(e)]}default:{if(r==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],r.decode(e)]}}}function st(e,r,t){let{prefix:n}=t;if(n!==g.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=r.get(n);if(o==null){let i=t.encode(e).slice(1);return r.set(n,i),i}else return o}function at(e,r,t){let{prefix:n}=t,o=r.get(n);if(o==null){let i=t.encode(e);return r.set(n,i),i}else return o}var P=112,ct=18;function je(e,r,t){let n=M(e),o=n+M(r),i=new Uint8Array(o+t.byteLength);return z(e,i,0),z(r,i,n),i.set(t,o),i}var ft=Symbol.for("@ipld/js-cid/CID");var le={...ae,...ee,...se,...Y,..._,...te,...ne,...oe,...ie,...re},pn={...de,...fe};function Je(e,r,t,n){return{name:e,prefix:r,encoder:{name:e,prefix:r,encode:t},decoder:{decode:n}}}var Re=Je("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),me=Je("ascii","a",e=>{let r="a";for(let t=0;t<e.length;t++)r+=String.fromCharCode(e[t]);return r},e=>{e=e.substring(1);let r=U(e.length);for(let t=0;t<e.length;t++)r[t]=e.charCodeAt(t);return r}),ut={utf8:Re,"utf-8":Re,hex:le.base16,latin1:me,ascii:me,binary:me,...le},G=ut;function Ge(e,r="utf8"){let t=G[r];if(t==null)throw new Error(`Unsupported encoding "${r}"`);return t.decoder.decode(`${t.prefix}${e}`)}function Xe(e,r="utf8"){let t=G[r];if(t==null)throw new Error(`Unsupported encoding "${r}"`);return t.encoder.encode(e).substring(1)}return Ye(pt);})();
return Uint8Arrays}));
//# sourceMappingURL=index.min.js.map