Socket
Socket
Sign inDemoInstall

uint8arrays

Package Overview
Dependencies
1
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 5.0.2 to 5.0.3

dist/src/alloc.node.d.ts

2

dist/index.min.js
(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 X=Object.defineProperty;var je=Object.getOwnPropertyDescriptor;var Re=Object.getOwnPropertyNames;var Je=Object.prototype.hasOwnProperty;var u=(e,t)=>{for(var r in t)X(e,r,{get:t[r],enumerable:!0})},Xe=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Re(t))!Je.call(e,n)&&n!==r&&X(e,n,{get:()=>t[n],enumerable:!(o=je(t,n))||o.enumerable});return e};var Qe=e=>Xe(X({},"__esModule",{value:!0}),e);var tr={};u(tr,{compare:()=>le,concat:()=>me,equals:()=>be,fromString:()=>$e,toString:()=>Fe,xor:()=>ke});function le(e,t){if(globalThis.Buffer!=null)return globalThis.Buffer.compare(e,t);for(let r=0;r<e.byteLength;r++){if(e[r]<t[r])return-1;if(e[r]>t[r])return 1}return e.byteLength>t.byteLength?1:e.byteLength<t.byteLength?-1:0}function A(e){return globalThis.Buffer!=null?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e}function z(e=0){return globalThis.Buffer?.allocUnsafe!=null?A(globalThis.Buffer.allocUnsafe(e)):new Uint8Array(e)}function me(e,t){if(globalThis.Buffer!=null)return A(globalThis.Buffer.concat(e,t));t==null&&(t=e.reduce((n,i)=>n+i.length,0));let r=z(t),o=0;for(let n of e)r.set(n,o),o+=n.length;return A(r)}function be(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}var W={};u(W,{base10:()=>Ye});var dr=new Uint8Array(0);function xe(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function C(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")}function ge(e){return new TextEncoder().encode(e)}function we(e){return new TextDecoder().decode(e)}function Ge(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),o=0;o<r.length;o++)r[o]=255;for(var n=0;n<e.length;n++){var i=e.charAt(n),s=i.charCodeAt(0);if(r[s]!==255)throw new TypeError(i+" is ambiguous");r[s]=n}var c=e.length,p=e.charAt(0),T=Math.log(c)/Math.log(256),h=Math.log(256)/Math.log(c);function B(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 d=0,E=0,m=0,x=a.length;m!==x&&a[m]===0;)m++,d++;for(var g=(x-m)*h+1>>>0,l=new Uint8Array(g);m!==x;){for(var w=a[m],S=0,b=g-1;(w!==0||S<E)&&b!==-1;b--,S++)w+=256*l[b]>>>0,l[b]=w%c>>>0,w=w/c>>>0;if(w!==0)throw new Error("Non-zero carry");E=S,m++}for(var v=g-E;v!==g&&l[v]===0;)v++;for(var q=p.repeat(d);v<g;++v)q+=e.charAt(l[v]);return q}function k(a){if(typeof a!="string")throw new TypeError("Expected String");if(a.length===0)return new Uint8Array;var d=0;if(a[d]!==" "){for(var E=0,m=0;a[d]===p;)E++,d++;for(var x=(a.length-d)*T+1>>>0,g=new Uint8Array(x);a[d];){var l=r[a.charCodeAt(d)];if(l===255)return;for(var w=0,S=x-1;(l!==0||w<m)&&S!==-1;S--,w++)l+=c*g[S]>>>0,g[S]=l%256>>>0,l=l/256>>>0;if(l!==0)throw new Error("Non-zero carry");m=w,d++}if(a[d]!==" "){for(var b=x-m;b!==x&&g[b]===0;)b++;for(var v=new Uint8Array(E+(x-b)),q=E;b!==x;)v[q++]=g[b++];return v}}}function qe(a){var d=k(a);if(d)return d;throw new Error(`Non-${t} character`)}return{encode:B,decodeUnsafe:k,decode:qe}}var Ke=Ge,He=Ke,ve=He;var Q=class{name;prefix;baseEncode;constructor(t,r,o){this.name=t,this.prefix=r,this.baseEncode=o}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},G=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,o){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=o}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 Ae(this,t)}},K=class{decoders;constructor(t){this.decoders=t}or(t){return Ae(this,t)}decode(t){let r=t[0],o=this.decoders[r];if(o!=null)return o.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Ae(e,t){return new K({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var H=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,o,n){this.name=t,this.prefix=r,this.baseEncode=o,this.baseDecode=n,this.encoder=new Q(t,r,o),this.decoder=new G(t,r,n)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function I({name:e,prefix:t,encode:r,decode:o}){return new H(e,t,r,o)}function U({name:e,prefix:t,alphabet:r}){let{encode:o,decode:n}=ve(r,e);return I({prefix:t,name:e,encode:o,decode:i=>C(n(i))})}function We(e,t,r,o){let n={};for(let h=0;h<t.length;++h)n[t[h]]=h;let i=e.length;for(;e[i-1]==="=";)--i;let s=new Uint8Array(i*r/8|0),c=0,p=0,T=0;for(let h=0;h<i;++h){let B=n[e[h]];if(B===void 0)throw new SyntaxError(`Non-${o} character`);p=p<<r|B,c+=r,c>=8&&(c-=8,s[T++]=255&p>>c)}if(c>=r||255&p<<8-c)throw new SyntaxError("Unexpected end of data");return s}function Ze(e,t,r){let o=t[t.length-1]==="=",n=(1<<r)-1,i="",s=0,c=0;for(let p=0;p<e.length;++p)for(c=c<<8|e[p],s+=8;s>r;)s-=r,i+=t[n&c>>s];if(s!==0&&(i+=t[n&c<<r-s]),o)for(;i.length*r&7;)i+="=";return i}function f({name:e,prefix:t,bitsPerChar:r,alphabet:o}){return I({prefix:t,name:e,encode(n){return Ze(n,o,r)},decode(n){return We(n,o,r,e)}})}var Ye=U({prefix:"9",name:"base10",alphabet:"0123456789"});var Z={};u(Z,{base16:()=>_e,base16upper:()=>et});var _e=f({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),et=f({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Y={};u(Y,{base2:()=>tt});var tt=f({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var _={};u(_,{base256emoji:()=>st});var Ce=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}"),rt=Ce.reduce((e,t,r)=>(e[r]=t,e),[]),ot=Ce.reduce((e,t,r)=>(e[t.codePointAt(0)]=r,e),[]);function nt(e){return e.reduce((t,r)=>(t+=rt[r],t),"")}function it(e){let t=[];for(let r of e){let o=ot[r.codePointAt(0)];if(o===void 0)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var st=I({prefix:"\u{1F680}",name:"base256emoji",encode:nt,decode:it});var ee={};u(ee,{base32:()=>L,base32hex:()=>pt,base32hexpad:()=>ut,base32hexpadupper:()=>ht,base32hexupper:()=>dt,base32pad:()=>ct,base32padupper:()=>ft,base32upper:()=>at,base32z:()=>lt});var L=f({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),at=f({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),ct=f({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),ft=f({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),pt=f({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),dt=f({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ut=f({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ht=f({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),lt=f({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var te={};u(te,{base36:()=>mt,base36upper:()=>bt});var mt=U({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),bt=U({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var re={};u(re,{base58btc:()=>y,base58flickr:()=>xt});var y=U({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),xt=U({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var oe={};u(oe,{base64:()=>gt,base64pad:()=>wt,base64url:()=>yt,base64urlpad:()=>vt});var gt=f({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),wt=f({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),yt=f({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),vt=f({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var ne={};u(ne,{base8:()=>At});var At=f({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ie={};u(ie,{identity:()=>Ct});var Ct=I({prefix:"\0",name:"identity",encode:e=>we(e),decode:e=>ge(e)});var Dr=new TextEncoder,Tr=new TextDecoder;var ae={};u(ae,{identity:()=>Qt});var Et=Ee,Se=128,Dt=127,Tt=~Dt,Bt=Math.pow(2,31);function Ee(e,t,r){t=t||[],r=r||0;for(var o=r;e>=Bt;)t[r++]=e&255|Se,e/=128;for(;e&Tt;)t[r++]=e&255|Se,e>>>=7;return t[r]=e|0,Ee.bytes=r-o+1,t}var zt=se,It=128,Ue=127;function se(e,o){var r=0,o=o||0,n=0,i=o,s,c=e.length;do{if(i>=c)throw se.bytes=0,new RangeError("Could not decode varint");s=e[i++],r+=n<28?(s&Ue)<<n:(s&Ue)*Math.pow(2,n),n+=7}while(s>=It);return se.bytes=i-o,r}var Lt=Math.pow(2,7),Ot=Math.pow(2,14),Mt=Math.pow(2,21),Nt=Math.pow(2,28),Vt=Math.pow(2,35),Pt=Math.pow(2,42),$t=Math.pow(2,49),Ft=Math.pow(2,56),kt=Math.pow(2,63),qt=function(e){return e<Lt?1:e<Ot?2:e<Mt?3:e<Nt?4:e<Vt?5:e<Pt?6:e<$t?7:e<Ft?8:e<kt?9:10},jt={encode:Et,decode:zt,encodingLength:qt},Rt=jt,V=Rt;function P(e,t=0){return[V.decode(e,t),V.decode.bytes]}function O(e,t,r=0){return V.encode(e,t,r),t}function M(e){return V.encodingLength(e)}function D(e,t){let r=t.byteLength,o=M(e),n=o+M(r),i=new Uint8Array(n+r);return O(e,i,0),O(r,i,o),i.set(t,n),new N(e,r,t,i)}function De(e){let t=C(e),[r,o]=P(t),[n,i]=P(t.subarray(o)),s=t.subarray(o+i);if(s.byteLength!==n)throw new Error("Incorrect length");return new N(r,n,s,t)}function Te(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&xe(e.bytes,r.bytes)}}var N=class{code;size;digest;bytes;constructor(t,r,o,n){this.code=t,this.size=r,this.digest=o,this.bytes=n}};var Be=0,Jt="identity",ze=C;function Xt(e){return D(Be,ze(e))}var Qt={code:Be,name:Jt,encode:ze,digest:Xt};var pe={};u(pe,{sha256:()=>Gt,sha512:()=>Kt});function fe({name:e,code:t,encode:r}){return new ce(e,t,r)}var ce=class{name;code;encode;constructor(t,r,o){this.name=t,this.code=r,this.encode=o}digest(t){if(t instanceof Uint8Array){let r=this.encode(t);return r instanceof Uint8Array?D(this.code,r):r.then(o=>D(this.code,o))}else throw Error("Unknown type, must be binary type")}};function Le(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var Gt=fe({name:"sha2-256",code:18,encode:Le("SHA-256")}),Kt=fe({name:"sha2-512",code:19,encode:Le("SHA-512")});function Oe(e,t){let{bytes:r,version:o}=e;switch(o){case 0:return Wt(r,de(e),t??y.encoder);default:return Zt(r,de(e),t??L.encoder)}}var Me=new WeakMap;function de(e){let t=Me.get(e);if(t==null){let r=new Map;return Me.set(e,r),r}return t}var R=class e{code;version;multihash;bytes;"/";constructor(t,r,o,n){this.code=r,this.version=t,this.multihash=o,this.bytes=n,this["/"]=n}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!==F)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Yt)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,o=D(t,r);return e.createV1(this.code,o)}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 o=r;return o!=null&&t.code===o.code&&t.version===o.version&&Te(t.multihash,o.multihash)}toString(t){return Oe(this,t)}toJSON(){return{"/":Oe(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:o,code:n,multihash:i,bytes:s}=r;return new e(o,n,i,s??Ne(o,n,i.bytes))}else if(r[_t]===!0){let{version:o,multihash:n,code:i}=r,s=De(n);return e.create(o,i,s)}else return null}static create(t,r,o){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(o.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==F)throw new Error(`Version 0 CID must use dag-pb (code: ${F}) block encoding`);return new e(t,r,o,o.bytes)}case 1:{let n=Ne(t,r,o.bytes);return new e(t,r,o,n)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,F,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,o]=e.decodeFirst(t);if(o.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),o=r.size-r.multihashSize,n=C(t.subarray(o,o+r.multihashSize));if(n.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=n.subarray(r.multihashSize-r.digestSize),s=new N(r.multihashCode,r.digestSize,i,n);return[r.version===0?e.createV0(s):e.createV1(r.codec,s),t.subarray(r.size)]}static inspectBytes(t){let r=0,o=()=>{let[B,k]=P(t.subarray(r));return r+=k,B},n=o(),i=F;if(n===18?(n=0,r=0):i=o(),n!==0&&n!==1)throw new RangeError(`Invalid CID version ${n}`);let s=r,c=o(),p=o(),T=r+p,h=T-s;return{version:n,codec:i,multihashCode:c,digestSize:p,multihashSize:h,size:T}}static parse(t,r){let[o,n]=Ht(t,r),i=e.decode(n);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return de(i).set(o,t),i}};function Ht(e,t){switch(e[0]){case"Q":{let r=t??y;return[y.prefix,r.decode(`${y.prefix}${e}`)]}case y.prefix:{let r=t??y;return[y.prefix,r.decode(e)]}case L.prefix:{let r=t??L;return[L.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)]}}}function Wt(e,t,r){let{prefix:o}=r;if(o!==y.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let n=t.get(o);if(n==null){let i=r.encode(e).slice(1);return t.set(o,i),i}else return n}function Zt(e,t,r){let{prefix:o}=r,n=t.get(o);if(n==null){let i=r.encode(e);return t.set(o,i),i}else return n}var F=112,Yt=18;function Ne(e,t,r){let o=M(e),n=o+M(t),i=new Uint8Array(n+r.byteLength);return O(e,i,0),O(t,i,o),i.set(r,n),i}var _t=Symbol.for("@ipld/js-cid/CID");var ue={...ie,...Y,...ne,...W,...Z,...ee,...te,...re,...oe,..._},Hr={...pe,...ae};function Pe(e,t,r,o){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:o}}}var Ve=Pe("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),he=Pe("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=z(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),er={utf8:Ve,"utf-8":Ve,hex:ue.base16,latin1:he,ascii:he,binary:he,...ue},J=er;function $e(e,t="utf8"){let r=J[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return(t==="utf8"||t==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?A(globalThis.Buffer.from(e,"utf-8")):r.decoder.decode(`${r.prefix}${e}`)}function Fe(e,t="utf8"){let r=J[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return(t==="utf8"||t==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString("utf8"):r.encoder.encode(e).substring(1)}function ke(e,t){if(e.length!==t.length)throw new Error("Inputs should have the same length");let r=z(e.length);for(let o=0;o<e.length;o++)r[o]=e[o]^t[o];return A(r)}return Qe(tr);})();
"use strict";var Uint8Arrays=(()=>{var J=Object.defineProperty;var qe=Object.getOwnPropertyDescriptor;var je=Object.getOwnPropertyNames;var Re=Object.prototype.hasOwnProperty;var h=(r,e)=>{for(var t in e)J(r,t,{get:e[t],enumerable:!0})},Je=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of je(e))!Re.call(r,o)&&o!==t&&J(r,o,{get:()=>e[o],enumerable:!(n=qe(e,o))||n.enumerable});return r};var Xe=r=>Je(J({},"__esModule",{value:!0}),r);var tr={};h(tr,{compare:()=>le,concat:()=>be,equals:()=>ue,fromString:()=>$e,toString:()=>ke,xor:()=>me});function ue(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function I(r=0){return new Uint8Array(r)}function me(r,e){if(r.length!==e.length)throw new Error("Inputs should have the same length");let t=I(r.length);for(let n=0;n<r.length;n++)t[n]=r[n]^e[n];return t}function le(r,e){for(let t=0;t<r.byteLength;t++){if(r[t]<e[t])return-1;if(r[t]>e[t])return 1}return r.byteLength>e.byteLength?1:r.byteLength<e.byteLength?-1:0}function be(r,e){e==null&&(e=r.reduce((o,i)=>o+i.length,0));let t=I(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}var H={};h(H,{base10:()=>Ye});var ur=new Uint8Array(0);function xe(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function A(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function ge(r){return new TextEncoder().encode(r)}function ye(r){return new TextDecoder().decode(r)}function Ge(r,e){if(r.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<r.length;o++){var i=r.charAt(o),s=i.charCodeAt(0);if(t[s]!==255)throw new TypeError(i+" is ambiguous");t[s]=o}var c=r.length,p=r.charAt(0),D=Math.log(c)/Math.log(256),u=Math.log(256)/Math.log(c);function z(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 d=0,E=0,l=0,x=a.length;l!==x&&a[l]===0;)l++,d++;for(var g=(x-l)*u+1>>>0,m=new Uint8Array(g);l!==x;){for(var y=a[l],S=0,b=g-1;(y!==0||S<E)&&b!==-1;b--,S++)y+=256*m[b]>>>0,m[b]=y%c>>>0,y=y/c>>>0;if(y!==0)throw new Error("Non-zero carry");E=S,l++}for(var v=g-E;v!==g&&m[v]===0;)v++;for(var F=p.repeat(d);v<g;++v)F+=r.charAt(m[v]);return F}function k(a){if(typeof a!="string")throw new TypeError("Expected String");if(a.length===0)return new Uint8Array;var d=0;if(a[d]!==" "){for(var E=0,l=0;a[d]===p;)E++,d++;for(var x=(a.length-d)*D+1>>>0,g=new Uint8Array(x);a[d];){var m=t[a.charCodeAt(d)];if(m===255)return;for(var y=0,S=x-1;(m!==0||y<l)&&S!==-1;S--,y++)m+=c*g[S]>>>0,g[S]=m%256>>>0,m=m/256>>>0;if(m!==0)throw new Error("Non-zero carry");l=y,d++}if(a[d]!==" "){for(var b=x-l;b!==x&&g[b]===0;)b++;for(var v=new Uint8Array(E+(x-b)),F=E;b!==x;)v[F++]=g[b++];return v}}}function Fe(a){var d=k(a);if(d)return d;throw new Error(`Non-${e} character`)}return{encode:z,decodeUnsafe:k,decode:Fe}}var Ke=Ge,He=Ke,ve=He;var X=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Q=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){if(this.name=e,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Ae(this,e)}},G=class{decoders;constructor(e){this.decoders=e}or(e){return Ae(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Ae(r,e){return new G({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var K=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new X(e,t,n),this.decoder=new Q(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function M({name:r,prefix:e,encode:t,decode:n}){return new K(r,e,t,n)}function C({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=ve(t,r);return M({prefix:e,name:r,encode:n,decode:i=>A(o(i))})}function We(r,e,t,n){let o={};for(let u=0;u<e.length;++u)o[e[u]]=u;let i=r.length;for(;r[i-1]==="=";)--i;let s=new Uint8Array(i*t/8|0),c=0,p=0,D=0;for(let u=0;u<i;++u){let z=o[r[u]];if(z===void 0)throw new SyntaxError(`Non-${n} character`);p=p<<t|z,c+=t,c>=8&&(c-=8,s[D++]=255&p>>c)}if(c>=t||255&p<<8-c)throw new SyntaxError("Unexpected end of data");return s}function Ze(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,i="",s=0,c=0;for(let p=0;p<r.length;++p)for(c=c<<8|r[p],s+=8;s>t;)s-=t,i+=e[o&c>>s];if(s!==0&&(i+=e[o&c<<t-s]),n)for(;i.length*t&7;)i+="=";return i}function f({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return M({prefix:e,name:r,encode(o){return Ze(o,n,t)},decode(o){return We(o,n,t,r)}})}var Ye=C({prefix:"9",name:"base10",alphabet:"0123456789"});var W={};h(W,{base16:()=>_e,base16upper:()=>et});var _e=f({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),et=f({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Z={};h(Z,{base2:()=>tt});var tt=f({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Y={};h(Y,{base256emoji:()=>st});var Se=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}"),rt=Se.reduce((r,e,t)=>(r[t]=e,r),[]),nt=Se.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);function ot(r){return r.reduce((e,t)=>(e+=rt[t],e),"")}function it(r){let e=[];for(let t of r){let n=nt[t.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(n)}return new Uint8Array(e)}var st=M({prefix:"\u{1F680}",name:"base256emoji",encode:ot,decode:it});var _={};h(_,{base32:()=>L,base32hex:()=>pt,base32hexpad:()=>ht,base32hexpadupper:()=>ut,base32hexupper:()=>dt,base32pad:()=>ct,base32padupper:()=>ft,base32upper:()=>at,base32z:()=>mt});var L=f({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),at=f({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),ct=f({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),ft=f({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),pt=f({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),dt=f({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ht=f({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ut=f({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),mt=f({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ee={};h(ee,{base36:()=>lt,base36upper:()=>bt});var lt=C({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),bt=C({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var te={};h(te,{base58btc:()=>w,base58flickr:()=>xt});var w=C({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),xt=C({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var re={};h(re,{base64:()=>gt,base64pad:()=>yt,base64url:()=>wt,base64urlpad:()=>vt});var gt=f({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),yt=f({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),wt=f({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),vt=f({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var ne={};h(ne,{base8:()=>At});var At=f({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var oe={};h(oe,{identity:()=>St});var St=M({prefix:"\0",name:"identity",encode:r=>ye(r),decode:r=>ge(r)});var Ir=new TextEncoder,Mr=new TextDecoder;var se={};h(se,{identity:()=>Qt});var Ut=Ue,Ce=128,Dt=127,zt=~Dt,It=Math.pow(2,31);function Ue(r,e,t){e=e||[],t=t||0;for(var n=t;r>=It;)e[t++]=r&255|Ce,r/=128;for(;r&zt;)e[t++]=r&255|Ce,r>>>=7;return e[t]=r|0,Ue.bytes=t-n+1,e}var Mt=ie,Lt=128,Ee=127;function ie(r,n){var t=0,n=n||0,o=0,i=n,s,c=r.length;do{if(i>=c)throw ie.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&Ee)<<o:(s&Ee)*Math.pow(2,o),o+=7}while(s>=Lt);return ie.bytes=i-n,t}var Nt=Math.pow(2,7),Tt=Math.pow(2,14),Ot=Math.pow(2,21),Bt=Math.pow(2,28),Vt=Math.pow(2,35),Pt=Math.pow(2,42),$t=Math.pow(2,49),kt=Math.pow(2,56),Ft=Math.pow(2,63),qt=function(r){return r<Nt?1:r<Tt?2:r<Ot?3:r<Bt?4:r<Vt?5:r<Pt?6:r<$t?7:r<kt?8:r<Ft?9:10},jt={encode:Ut,decode:Mt,encodingLength:qt},Rt=jt,B=Rt;function V(r,e=0){return[B.decode(r,e),B.decode.bytes]}function N(r,e,t=0){return B.encode(r,e,t),e}function T(r){return B.encodingLength(r)}function U(r,e){let t=e.byteLength,n=T(r),o=n+T(t),i=new Uint8Array(o+t);return N(r,i,0),N(t,i,n),i.set(e,o),new O(r,t,e,i)}function De(r){let e=A(r),[t,n]=V(e),[o,i]=V(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new O(t,o,s,e)}function ze(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&xe(r.bytes,t.bytes)}}var O=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};var Ie=0,Jt="identity",Me=A;function Xt(r){return U(Ie,Me(r))}var Qt={code:Ie,name:Jt,encode:Me,digest:Xt};var fe={};h(fe,{sha256:()=>Gt,sha512:()=>Kt});function ce({name:r,code:e,encode:t}){return new ae(r,e,t)}var ae=class{name;code;encode;constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?U(this.code,t):t.then(n=>U(this.code,n))}else throw Error("Unknown type, must be binary type")}};function Ne(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var Gt=ce({name:"sha2-256",code:18,encode:Ne("SHA-256")}),Kt=ce({name:"sha2-512",code:19,encode:Ne("SHA-512")});function Te(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return Wt(t,pe(r),e??w.encoder);default:return Zt(t,pe(r),e??L.encoder)}}var Oe=new WeakMap;function pe(r){let e=Oe.get(r);if(e==null){let t=new Map;return Oe.set(r,t),t}return e}var j=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,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:e,multihash:t}=this;if(e!==$)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Yt)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.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:e,digest:t}=this.multihash,n=U(e,t);return r.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(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&ze(e.multihash,n.multihash)}toString(e){return Te(this,e)}toJSON(){return{"/":Te(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:i,bytes:s}=t;return new r(n,o,i,s??Be(n,o,i.bytes))}else if(t[_t]===!0){let{version:n,multihash:o,code:i}=t,s=De(o);return r.create(n,i,s)}else return null}static create(e,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(e){case 0:{if(t!==$)throw new Error(`Version 0 CID must use dag-pb (code: ${$}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=Be(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,$,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=A(e.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 O(t.multihashCode,t.digestSize,i,o);return[t.version===0?r.createV0(s):r.createV1(t.codec,s),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[z,k]=V(e.subarray(t));return t+=k,z},o=n(),i=$;if(o===18?(o=0,t=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=t,c=n(),p=n(),D=t+p,u=D-s;return{version:o,codec:i,multihashCode:c,digestSize:p,multihashSize:u,size:D}}static parse(e,t){let[n,o]=Ht(e,t),i=r.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return pe(i).set(n,e),i}};function Ht(r,e){switch(r[0]){case"Q":{let t=e??w;return[w.prefix,t.decode(`${w.prefix}${r}`)]}case w.prefix:{let t=e??w;return[w.prefix,t.decode(r)]}case L.prefix:{let t=e??L;return[L.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function Wt(r,e,t){let{prefix:n}=t;if(n!==w.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let i=t.encode(r).slice(1);return e.set(n,i),i}else return o}function Zt(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let i=t.encode(r);return e.set(n,i),i}else return o}var $=112,Yt=18;function Be(r,e,t){let n=T(r),o=n+T(e),i=new Uint8Array(o+t.byteLength);return N(r,i,0),N(e,i,n),i.set(t,o),i}var _t=Symbol.for("@ipld/js-cid/CID");var de={...oe,...Z,...ne,...H,...W,..._,...ee,...te,...re,...Y},Zr={...fe,...se};function Pe(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Ve=Pe("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),he=Pe("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=I(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),er={utf8:Ve,"utf-8":Ve,hex:de.base16,latin1:he,ascii:he,binary:he,...de},R=er;function $e(r,e="utf8"){let t=R[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function ke(r,e="utf8"){let t=R[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}return Xe(tr);})();
return Uint8Arrays}));

@@ -1,2 +0,1 @@

import { asUint8Array } from './util/as-uint8array.js';
/**

@@ -7,5 +6,2 @@ * Returns a `Uint8Array` of the requested size. Referenced memory will

export function alloc(size = 0) {
if (globalThis.Buffer?.alloc != null) {
return asUint8Array(globalThis.Buffer.alloc(size));
}
return new Uint8Array(size);

@@ -19,7 +15,4 @@ }

export function allocUnsafe(size = 0) {
if (globalThis.Buffer?.allocUnsafe != null) {
return asUint8Array(globalThis.Buffer.allocUnsafe(size));
}
return new Uint8Array(size);
}
//# sourceMappingURL=alloc.js.map

@@ -5,5 +5,2 @@ /**

export function compare(a, b) {
if (globalThis.Buffer != null) {
return globalThis.Buffer.compare(a, b);
}
for (let i = 0; i < a.byteLength; i++) {

@@ -10,0 +7,0 @@ if (a[i] < b[i]) {

@@ -1,3 +0,3 @@

import { allocUnsafe } from './alloc.js';
import { asUint8Array } from './util/as-uint8array.js';
import { allocUnsafe } from '#alloc';
import { asUint8Array } from '#util/as-uint8array';
/**

@@ -7,5 +7,2 @@ * Returns a new Uint8Array created by concatenating the passed Uint8Arrays

export function concat(arrays, length) {
if (globalThis.Buffer != null) {
return asUint8Array(globalThis.Buffer.concat(arrays, length));
}
if (length == null) {

@@ -12,0 +9,0 @@ length = arrays.reduce((acc, curr) => acc + curr.length, 0);

@@ -1,2 +0,1 @@

import { asUint8Array } from './util/as-uint8array.js';
import bases, {} from './util/bases.js';

@@ -15,5 +14,2 @@ /**

}
if ((encoding === 'utf8' || encoding === 'utf-8') && globalThis.Buffer != null && globalThis.Buffer.from != null) {
return asUint8Array(globalThis.Buffer.from(string, 'utf-8'));
}
// add multibase prefix

@@ -20,0 +16,0 @@ return base.decoder.decode(`${base.prefix}${string}`); // eslint-disable-line @typescript-eslint/restrict-template-expressions

@@ -12,3 +12,3 @@ /**

*
* Create a new `Uint8Array`. If `globalThis.Buffer` is defined, it will be used in preference to `globalThis.Uint8Array`.
* Create a new `Uint8Array`. When running under Node.js, `Buffer` will be used in preference to `Uint8Array`.
*

@@ -25,3 +25,3 @@ * ### Example

*
* Create a new `Uint8Array`. If `globalThis.Buffer` is defined, it will be used in preference to `globalThis.Uint8Array`.
* Create a new `Uint8Array`. When running under Node.js, `Buffer` will be used in preference to `Uint8Array`.
*

@@ -147,10 +147,10 @@ * On platforms that support it, memory referenced by the returned `Uint8Array` will not be initialized.

*/
import { compare } from './compare.js';
import { concat } from './concat.js';
import { equals } from './equals.js';
import { fromString } from './from-string.js';
import { toString } from './to-string.js';
import { xor } from './xor.js';
import { compare } from '#compare';
import { concat } from '#concat';
import { fromString } from '#from-string';
import { toString } from '#to-string';
export { compare, concat, equals, fromString, toString, xor };
export type { SupportedEncodings } from './util/bases.js';
//# sourceMappingURL=index.d.ts.map

@@ -12,3 +12,3 @@ /**

*
* Create a new `Uint8Array`. If `globalThis.Buffer` is defined, it will be used in preference to `globalThis.Uint8Array`.
* Create a new `Uint8Array`. When running under Node.js, `Buffer` will be used in preference to `Uint8Array`.
*

@@ -25,3 +25,3 @@ * ### Example

*
* Create a new `Uint8Array`. If `globalThis.Buffer` is defined, it will be used in preference to `globalThis.Uint8Array`.
* Create a new `Uint8Array`. When running under Node.js, `Buffer` will be used in preference to `Uint8Array`.
*

@@ -147,9 +147,9 @@ * On platforms that support it, memory referenced by the returned `Uint8Array` will not be initialized.

*/
import { compare } from './compare.js';
import { concat } from './concat.js';
import { equals } from './equals.js';
import { fromString } from './from-string.js';
import { toString } from './to-string.js';
import { xor } from './xor.js';
import { compare } from '#compare';
import { concat } from '#concat';
import { fromString } from '#from-string';
import { toString } from '#to-string';
export { compare, concat, equals, fromString, toString, xor };
//# sourceMappingURL=index.js.map

@@ -14,5 +14,2 @@ import bases, {} from './util/bases.js';

}
if ((encoding === 'utf8' || encoding === 'utf-8') && globalThis.Buffer != null && globalThis.Buffer.from != null) {
return globalThis.Buffer.from(array.buffer, array.byteOffset, array.byteLength).toString('utf8');
}
// strip multibase prefix

@@ -19,0 +16,0 @@ return base.encoder.encode(array).substring(1);

@@ -6,7 +6,4 @@ /**

export function asUint8Array(buf) {
if (globalThis.Buffer != null) {
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
}
return buf;
}
//# sourceMappingURL=as-uint8array.js.map
import { bases } from 'multiformats/basics';
import { allocUnsafe } from '../alloc.js';
import { allocUnsafe } from '#alloc';
function createCodec(name, prefix, encode, decode) {

@@ -4,0 +4,0 @@ return {

@@ -1,3 +0,3 @@

import { allocUnsafe } from './alloc.js';
import { asUint8Array } from './util/as-uint8array.js';
import { allocUnsafe } from '#alloc';
import { asUint8Array } from '#util/as-uint8array';
/**

@@ -4,0 +4,0 @@ * Returns the xor distance between two arrays

{
"name": "uint8arrays",
"version": "5.0.2",
"version": "5.0.3",
"description": "Utility functions to make dealing with Uint8Arrays easier",

@@ -50,2 +50,3 @@ "author": "Alex Potsides <alex@achingbrain.net>",

"types": "./dist/src/alloc.d.ts",
"node": "./dist/src/alloc.node.js",
"import": "./dist/src/alloc.js"

@@ -55,2 +56,3 @@ },

"types": "./dist/src/compare.d.ts",
"node": "./dist/src/compare.node.js",
"import": "./dist/src/compare.js"

@@ -60,2 +62,3 @@ },

"types": "./dist/src/concat.d.ts",
"node": "./dist/src/concat.node.js",
"import": "./dist/src/concat.js"

@@ -69,2 +72,3 @@ },

"types": "./dist/src/from-string.d.ts",
"node": "./dist/src/from-string.node.js",
"import": "./dist/src/from-string.js"

@@ -74,2 +78,3 @@ },

"types": "./dist/src/to-string.d.ts",
"node": "./dist/src/to-string.node.js",
"import": "./dist/src/to-string.js"

@@ -82,2 +87,34 @@ },

},
"imports": {
"#util/as-uint8array": {
"types": "./dist/src/util/as-uint8array.d.ts",
"node": "./dist/src/util/as-uint8array.node.js",
"import": "./dist/src/util/as-uint8array.js"
},
"#alloc": {
"types": "./dist/src/alloc.d.ts",
"node": "./dist/src/alloc.node.js",
"import": "./dist/src/alloc.js"
},
"#compare": {
"types": "./dist/src/compare.d.ts",
"node": "./dist/src/compare.node.js",
"import": "./dist/src/compare.js"
},
"#concat": {
"types": "./dist/src/concat.d.ts",
"node": "./dist/src/concat.node.js",
"import": "./dist/src/concat.js"
},
"#from-string": {
"types": "./dist/src/from-string.d.ts",
"node": "./dist/src/from-string.node.js",
"import": "./dist/src/from-string.js"
},
"#to-string": {
"types": "./dist/src/to-string.d.ts",
"node": "./dist/src/to-string.node.js",
"import": "./dist/src/to-string.js"
}
},
"eslintConfig": {

@@ -196,3 +233,11 @@ "extends": "ipfs",

"benchmark": "^2.1.4"
},
"react-native": {
"#util/as-uint8array": "./dist/src/util/as-uint8array.js",
"#alloc": "./dist/src/alloc.js",
"#compare": "./dist/src/compare.js",
"#concat": "./dist/src/concat.js",
"#from-string": "./dist/src/from-string.js",
"#to-string": "./dist/src/to-string.js"
}
}

@@ -8,2 +8,17 @@ [![codecov](https://img.shields.io/codecov/c/github/achingbrain/uint8arrays.svg?style=flat-square)](https://codecov.io/gh/achingbrain/uint8arrays)

<!--
!IMPORTANT!
Everything in this README between "# About" and "# Install" is automatically
generated and will be overwritten the next time the doc generator is run.
To make changes to this section, please update the @packageDocumentation section
of src/index.js or src/index.ts
To experiment with formatting, please run "npm run docs" from the root of this
repo and examine the changes made.
-->
`Uint8Array`s bring memory-efficient(ish) byte handling to browsers - they are similar to Node.js `Buffer`s but lack a lot of the utility methods present on that class.

@@ -17,3 +32,3 @@

Create a new `Uint8Array`. If `globalThis.Buffer` is defined, it will be used in preference to `globalThis.Uint8Array`.
Create a new `Uint8Array`. When running under Node.js, `Buffer` will be used in preference to `Uint8Array`.

@@ -30,3 +45,3 @@ ### Example

Create a new `Uint8Array`. If `globalThis.Buffer` is defined, it will be used in preference to `globalThis.Uint8Array`.
Create a new `Uint8Array`. When running under Node.js, `Buffer` will be used in preference to `Uint8Array`.

@@ -33,0 +48,0 @@ On platforms that support it, memory referenced by the returned `Uint8Array` will not be initialized.

@@ -1,3 +0,1 @@

import { asUint8Array } from './util/as-uint8array.js'
/**

@@ -8,6 +6,2 @@ * Returns a `Uint8Array` of the requested size. Referenced memory will

export function alloc (size: number = 0): Uint8Array {
if (globalThis.Buffer?.alloc != null) {
return asUint8Array(globalThis.Buffer.alloc(size))
}
return new Uint8Array(size)

@@ -22,7 +16,3 @@ }

export function allocUnsafe (size: number = 0): Uint8Array {
if (globalThis.Buffer?.allocUnsafe != null) {
return asUint8Array(globalThis.Buffer.allocUnsafe(size))
}
return new Uint8Array(size)
}

@@ -5,6 +5,2 @@ /**

export function compare (a: Uint8Array, b: Uint8Array): number {
if (globalThis.Buffer != null) {
return globalThis.Buffer.compare(a, b)
}
for (let i = 0; i < a.byteLength; i++) {

@@ -11,0 +7,0 @@ if (a[i] < b[i]) {

@@ -1,3 +0,3 @@

import { allocUnsafe } from './alloc.js'
import { asUint8Array } from './util/as-uint8array.js'
import { allocUnsafe } from '#alloc'
import { asUint8Array } from '#util/as-uint8array'

@@ -8,6 +8,2 @@ /**

export function concat (arrays: Uint8Array[], length?: number): Uint8Array {
if (globalThis.Buffer != null) {
return asUint8Array(globalThis.Buffer.concat(arrays, length))
}
if (length == null) {

@@ -14,0 +10,0 @@ length = arrays.reduce((acc, curr) => acc + curr.length, 0)

@@ -1,2 +0,1 @@

import { asUint8Array } from './util/as-uint8array.js'
import bases, { type SupportedEncodings } from './util/bases.js'

@@ -20,8 +19,4 @@

if ((encoding === 'utf8' || encoding === 'utf-8') && globalThis.Buffer != null && globalThis.Buffer.from != null) {
return asUint8Array(globalThis.Buffer.from(string, 'utf-8'))
}
// add multibase prefix
return base.decoder.decode(`${base.prefix}${string}`) // eslint-disable-line @typescript-eslint/restrict-template-expressions
}

@@ -12,3 +12,3 @@ /**

*
* Create a new `Uint8Array`. If `globalThis.Buffer` is defined, it will be used in preference to `globalThis.Uint8Array`.
* Create a new `Uint8Array`. When running under Node.js, `Buffer` will be used in preference to `Uint8Array`.
*

@@ -25,3 +25,3 @@ * ### Example

*
* Create a new `Uint8Array`. If `globalThis.Buffer` is defined, it will be used in preference to `globalThis.Uint8Array`.
* Create a new `Uint8Array`. When running under Node.js, `Buffer` will be used in preference to `Uint8Array`.
*

@@ -148,8 +148,8 @@ * On platforms that support it, memory referenced by the returned `Uint8Array` will not be initialized.

import { compare } from './compare.js'
import { concat } from './concat.js'
import { equals } from './equals.js'
import { fromString } from './from-string.js'
import { toString } from './to-string.js'
import { xor } from './xor.js'
import { compare } from '#compare'
import { concat } from '#concat'
import { fromString } from '#from-string'
import { toString } from '#to-string'

@@ -156,0 +156,0 @@ export {

@@ -19,8 +19,4 @@ import bases, { type SupportedEncodings } from './util/bases.js'

if ((encoding === 'utf8' || encoding === 'utf-8') && globalThis.Buffer != null && globalThis.Buffer.from != null) {
return globalThis.Buffer.from(array.buffer, array.byteOffset, array.byteLength).toString('utf8')
}
// strip multibase prefix
return base.encoder.encode(array).substring(1)
}

@@ -6,7 +6,3 @@ /**

export function asUint8Array (buf: Uint8Array): Uint8Array {
if (globalThis.Buffer != null) {
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength)
}
return buf
}
import { bases } from 'multiformats/basics'
import { allocUnsafe } from '../alloc.js'
import type { MultibaseCodec } from 'multiformats'
import { allocUnsafe } from '#alloc'

@@ -5,0 +5,0 @@ function createCodec (name: string, prefix: string, encode: (buf: Uint8Array) => string, decode: (str: string) => Uint8Array): MultibaseCodec<any> {

@@ -1,3 +0,3 @@

import { allocUnsafe } from './alloc.js'
import { asUint8Array } from './util/as-uint8array.js'
import { allocUnsafe } from '#alloc'
import { asUint8Array } from '#util/as-uint8array'

@@ -4,0 +4,0 @@ /**

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc