uint8arrays
Advanced tools
Comparing version 3.1.0 to 3.1.1
@@ -5,5 +5,7 @@ 'use strict'; | ||
var asUint8array = require('./util/as-uint8array.js'); | ||
function alloc(size = 0) { | ||
if (globalThis.Buffer != null && globalThis.Buffer.alloc != null) { | ||
return globalThis.Buffer.alloc(size); | ||
return asUint8array.asUint8Array(globalThis.Buffer.alloc(size)); | ||
} | ||
@@ -14,3 +16,3 @@ return new Uint8Array(size); | ||
if (globalThis.Buffer != null && globalThis.Buffer.allocUnsafe != null) { | ||
return globalThis.Buffer.allocUnsafe(size); | ||
return asUint8array.asUint8Array(globalThis.Buffer.allocUnsafe(size)); | ||
} | ||
@@ -17,0 +19,0 @@ return new Uint8Array(size); |
@@ -6,2 +6,3 @@ 'use strict'; | ||
var alloc = require('./alloc.js'); | ||
var asUint8array = require('./util/as-uint8array.js'); | ||
@@ -18,5 +19,5 @@ function concat(arrays, length) { | ||
} | ||
return output; | ||
return asUint8array.asUint8Array(output); | ||
} | ||
exports.concat = concat; |
@@ -6,2 +6,3 @@ 'use strict'; | ||
var bases = require('./util/bases.js'); | ||
var asUint8array = require('./util/as-uint8array.js'); | ||
@@ -14,3 +15,3 @@ function fromString(string, encoding = 'utf8') { | ||
if ((encoding === 'utf8' || encoding === 'utf-8') && globalThis.Buffer != null && globalThis.Buffer.from != null) { | ||
return globalThis.Buffer.from(string, 'utf8'); | ||
return asUint8array.asUint8Array(globalThis.Buffer.from(string, 'utf-8')); | ||
} | ||
@@ -17,0 +18,0 @@ return base.decoder.decode(`${ base.prefix }${ string }`); |
@@ -6,2 +6,3 @@ 'use strict'; | ||
var alloc = require('./alloc.js'); | ||
var asUint8array = require('./util/as-uint8array.js'); | ||
@@ -16,5 +17,5 @@ function xor(a, b) { | ||
} | ||
return result; | ||
return asUint8array.asUint8Array(result); | ||
} | ||
exports.xor = xor; |
@@ -0,4 +1,5 @@ | ||
import { asUint8Array } from './util/as-uint8array.js'; | ||
export function alloc(size = 0) { | ||
if (globalThis.Buffer != null && globalThis.Buffer.alloc != null) { | ||
return globalThis.Buffer.alloc(size); | ||
return asUint8Array(globalThis.Buffer.alloc(size)); | ||
} | ||
@@ -9,5 +10,5 @@ return new Uint8Array(size); | ||
if (globalThis.Buffer != null && globalThis.Buffer.allocUnsafe != null) { | ||
return globalThis.Buffer.allocUnsafe(size); | ||
return asUint8Array(globalThis.Buffer.allocUnsafe(size)); | ||
} | ||
return new Uint8Array(size); | ||
} |
import { allocUnsafe } from './alloc.js'; | ||
import { asUint8Array } from './util/as-uint8array.js'; | ||
export function concat(arrays, length) { | ||
@@ -12,3 +13,3 @@ if (!length) { | ||
} | ||
return output; | ||
return asUint8Array(output); | ||
} |
import bases from './util/bases.js'; | ||
import { asUint8Array } from './util/as-uint8array.js'; | ||
export function fromString(string, encoding = 'utf8') { | ||
@@ -8,5 +9,5 @@ const base = bases[encoding]; | ||
if ((encoding === 'utf8' || encoding === 'utf-8') && globalThis.Buffer != null && globalThis.Buffer.from != null) { | ||
return globalThis.Buffer.from(string, 'utf8'); | ||
return asUint8Array(globalThis.Buffer.from(string, 'utf-8')); | ||
} | ||
return base.decoder.decode(`${ base.prefix }${ string }`); | ||
} |
import { allocUnsafe } from './alloc.js'; | ||
import { asUint8Array } from './util/as-uint8array.js'; | ||
export function xor(a, b) { | ||
@@ -10,3 +11,3 @@ if (a.length !== b.length) { | ||
} | ||
return result; | ||
return asUint8Array(result); | ||
} |
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Uint8arrays = factory()}(typeof self !== 'undefined' ? self : this, function () { | ||
var Uint8arrays=(()=>{var ue=Object.defineProperty;var $e=r=>ue(r,"__esModule",{value:!0});var h=(r,e)=>{$e(r);for(var t in e)ue(r,t,{get:e[t],enumerable:!0})};var Yt={};h(Yt,{compare:()=>De,concat:()=>ie,equals:()=>ae,fromString:()=>Me,toString:()=>Ve,xor:()=>Pe});function De(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 U(r=0){return globalThis.Buffer!=null&&globalThis.Buffer.allocUnsafe!=null?globalThis.Buffer.allocUnsafe(r):new Uint8Array(r)}function ie(r,e){e||(e=r.reduce((s,n)=>s+n.length,0));let t=U(e),o=0;for(let s of r)t.set(s,o),o+=s.length;return t}function ae(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}var J={};h(J,{identity:()=>Ke});function qe(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),o=0;o<t.length;o++)t[o]=255;for(var s=0;s<r.length;s++){var n=r.charAt(s),D=n.charCodeAt(0);if(t[D]!==255)throw new TypeError(n+" is ambiguous");t[D]=s}var a=r.length,f=r.charAt(0),B=Math.log(a)/Math.log(256),p=Math.log(256)/Math.log(a);function S(u){if(u instanceof Uint8Array||(ArrayBuffer.isView(u)?u=new Uint8Array(u.buffer,u.byteOffset,u.byteLength):Array.isArray(u)&&(u=Uint8Array.from(u))),!(u instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(u.length===0)return"";for(var d=0,j=0,b=0,C=u.length;b!==C&&u[b]===0;)b++,d++;for(var E=(C-b)*p+1>>>0,l=new Uint8Array(E);b!==C;){for(var g=u[b],v=0,m=E-1;(g!==0||v<j)&&m!==-1;m--,v++)g+=256*l[m]>>>0,l[m]=g%a>>>0,g=g/a>>>0;if(g!==0)throw new Error("Non-zero carry");j=v,b++}for(var x=E-j;x!==E&&l[x]===0;)x++;for(var k=f.repeat(d);x<E;++x)k+=r.charAt(l[x]);return k}function P(u){if(typeof u!="string")throw new TypeError("Expected String");if(u.length===0)return new Uint8Array;var d=0;if(u[d]!==" "){for(var j=0,b=0;u[d]===f;)j++,d++;for(var C=(u.length-d)*B+1>>>0,E=new Uint8Array(C);u[d];){var l=t[u.charCodeAt(d)];if(l===255)return;for(var g=0,v=C-1;(l!==0||g<b)&&v!==-1;v--,g++)l+=a*E[v]>>>0,E[v]=l%256>>>0,l=l/256>>>0;if(l!==0)throw new Error("Non-zero carry");b=g,d++}if(u[d]!==" "){for(var m=C-b;m!==C&&E[m]===0;)m++;for(var x=new Uint8Array(j+(C-m)),k=j;m!==C;)x[k++]=E[m++];return x}}}function ke(u){var d=P(u);if(d)return d;throw new Error(`Non-${e} character`)}return{encode:S,decodeUnsafe:P,decode:ke}}var Re=qe,Je=Re,ce=Je;var ur=new Uint8Array(0);var fe=(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},y=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")};var de=r=>new TextEncoder().encode(r),he=r=>new TextDecoder().decode(r);var le=class{constructor(e,t,o){this.name=e,this.prefix=t,this.baseEncode=o}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},be=class{constructor(e,t,o){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=o}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 Ce(this,e)}},me=class{constructor(e){this.decoders=e}or(e){return Ce(this,e)}decode(e){let t=e[0],o=this.decoders[t];if(o)return o.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},Ce=(r,e)=>new me({...r.decoders||{[r.prefix]:r},...e.decoders||{[e.prefix]:e}}),Ee=class{constructor(e,t,o,s){this.name=e,this.prefix=t,this.baseEncode=o,this.baseDecode=s,this.encoder=new le(e,t,o),this.decoder=new be(e,t,s)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}},T=({name:r,prefix:e,encode:t,decode:o})=>new Ee(r,e,t,o),A=({prefix:r,name:e,alphabet:t})=>{let{encode:o,decode:s}=ce(t,e);return T({prefix:r,name:e,encode:o,decode:n=>y(s(n))})},Xe=(r,e,t,o)=>{let s={};for(let p=0;p<e.length;++p)s[e[p]]=p;let n=r.length;for(;r[n-1]==="=";)--n;let D=new Uint8Array(n*t/8|0),a=0,f=0,B=0;for(let p=0;p<n;++p){let S=s[r[p]];if(S===void 0)throw new SyntaxError(`Non-${o} character`);f=f<<t|S,a+=t,a>=8&&(a-=8,D[B++]=255&f>>a)}if(a>=t||255&f<<8-a)throw new SyntaxError("Unexpected end of data");return D},Ge=(r,e,t)=>{let o=e[e.length-1]==="=",s=(1<<t)-1,n="",D=0,a=0;for(let f=0;f<r.length;++f)for(a=a<<8|r[f],D+=8;D>t;)D-=t,n+=e[s&a>>D];if(D&&(n+=e[s&a<<t-D]),o)for(;n.length*t&7;)n+="=";return n},i=({name:r,prefix:e,bitsPerChar:t,alphabet:o})=>T({prefix:e,name:r,encode(s){return Ge(s,o,t)},decode(s){return Xe(s,o,t,r)}});var Ke=T({prefix:"\0",name:"identity",encode:r=>he(r),decode:r=>de(r)});var X={};h(X,{base2:()=>Qe});var Qe=i({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var G={};h(G,{base8:()=>He});var He=i({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var K={};h(K,{base10:()=>We});var We=A({prefix:"9",name:"base10",alphabet:"0123456789"});var Q={};h(Q,{base16:()=>Ze,base16upper:()=>Ye});var Ze=i({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Ye=i({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var H={};h(H,{base32:()=>z,base32hex:()=>rt,base32hexpad:()=>st,base32hexpadupper:()=>nt,base32hexupper:()=>ot,base32pad:()=>et,base32padupper:()=>tt,base32upper:()=>_e,base32z:()=>ut});var z=i({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),_e=i({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),et=i({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),tt=i({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),rt=i({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),ot=i({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),st=i({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),nt=i({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ut=i({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var W={};h(W,{base36:()=>Dt,base36upper:()=>it});var Dt=A({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),it=A({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Z={};h(Z,{base58btc:()=>w,base58flickr:()=>at});var w=A({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),at=A({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Y={};h(Y,{base64:()=>ct,base64pad:()=>ft,base64url:()=>dt,base64urlpad:()=>ht});var ct=i({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),ft=i({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),dt=i({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),ht=i({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var _={};h(_,{base256emoji:()=>Ct});var ge=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}"),pt=ge.reduce((r,e,t)=>(r[t]=e,r),[]),lt=ge.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);function bt(r){return r.reduce((e,t)=>(e+=pt[t],e),"")}function mt(r){let e=[];for(let t of r){let o=lt[t.codePointAt(0)];if(o===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var Ct=T({prefix:"\u{1F680}",name:"base256emoji",encode:bt,decode:mt});var re={};h(re,{sha256:()=>Mt,sha512:()=>Vt});var Et=xe,we=128,gt=127,wt=~gt,xt=Math.pow(2,31);function xe(r,e,t){e=e||[],t=t||0;for(var o=t;r>=xt;)e[t++]=r&255|we,r/=128;for(;r&wt;)e[t++]=r&255|we,r>>>=7;return e[t]=r|0,xe.bytes=t-o+1,e}var yt=ee,vt=128,ye=127;function ee(r,e){var t=0,e=e||0,o=0,s=e,n,D=r.length;do{if(s>=D)throw ee.bytes=0,new RangeError("Could not decode varint");n=r[s++],t+=o<28?(n&ye)<<o:(n&ye)*Math.pow(2,o),o+=7}while(n>=vt);return ee.bytes=s-e,t}var At=Math.pow(2,7),jt=Math.pow(2,14),Ft=Math.pow(2,21),Bt=Math.pow(2,28),St=Math.pow(2,35),Ut=Math.pow(2,42),Tt=Math.pow(2,49),zt=Math.pow(2,56),It=Math.pow(2,63),Lt=function(r){return r<At?1:r<jt?2:r<Ft?3:r<Bt?4:r<St?5:r<Ut?6:r<Tt?7:r<zt?8:r<It?9:10},Nt={encode:Et,decode:yt,encodingLength:Lt},Ot=Nt,N=Ot;var O=r=>[N.decode(r),N.decode.bytes],I=(r,e,t=0)=>(N.encode(r,e,t),e),L=r=>N.encodingLength(r);var F=(r,e)=>{let t=e.byteLength,o=L(r),s=o+L(t),n=new Uint8Array(s+t);return I(r,n,0),I(t,n,o),n.set(e,s),new M(r,t,e,n)},Ae=r=>{let e=y(r),[t,o]=O(e),[s,n]=O(e.subarray(o)),D=e.subarray(o+n);if(D.byteLength!==s)throw new Error("Incorrect length");return new M(t,s,D,e)},je=(r,e)=>r===e?!0:r.code===e.code&&r.size===e.size&&fe(r.bytes,e.bytes),M=class{constructor(e,t,o,s){this.code=e,this.size=t,this.digest=o,this.bytes=s}};var te=({name:r,code:e,encode:t})=>new Be(r,e,t),Be=class{constructor(e,t,o){this.name=e,this.code=t,this.encode=o}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?F(this.code,t):t.then(o=>F(this.code,o))}else throw Error("Unknown type, must be binary type")}};var Ue=r=>async e=>new Uint8Array(await crypto.subtle.digest(r,e)),Mt=te({name:"sha2-256",code:18,encode:Ue("SHA-256")}),Vt=te({name:"sha2-512",code:19,encode:Ue("SHA-512")});var oe={};h(oe,{identity:()=>$t});var Te=0,Pt="identity",ze=y,kt=r=>F(Te,ze(r)),$t={code:Te,name:Pt,encode:ze,digest:kt};var Ur=new TextEncoder,Tr=new TextDecoder;var c=class{constructor(e,t,o,s){this.code=t,this.version=e,this.multihash=o,this.bytes=s,this.byteOffset=s.byteOffset,this.byteLength=s.byteLength,this.asCID=this,this._baseCache=new Map,Object.defineProperties(this,{byteOffset:q,byteLength:q,code:$,version:$,multihash:$,bytes:$,_baseCache:q,asCID:q})}toV0(){switch(this.version){case 0:return this;default:{let{code:e,multihash:t}=this;if(e!==V)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Kt)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return c.createV0(t)}}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,o=F(e,t);return c.createV1(this.code,o)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}equals(e){return e&&this.code===e.code&&this.version===e.version&&je(this.multihash,e.multihash)}toString(e){let{bytes:t,version:o,_baseCache:s}=this;switch(o){case 0:return Xt(t,s,e||w.encoder);default:return Gt(t,s,e||z.encoder)}}toJSON(){return{code:this.code,version:this.version,hash:this.multihash.bytes}}get[Symbol.toStringTag](){return"CID"}[Symbol.for("nodejs.util.inspect.custom")](){return"CID("+this.toString()+")"}static isCID(e){return Ht(/^0\.0/,Wt),!!(e&&(e[Le]||e.asCID===e))}get toBaseEncodedString(){throw new Error("Deprecated, use .toString()")}get codec(){throw new Error('"codec" property is deprecated, use integer "code" property instead')}get buffer(){throw new Error("Deprecated .buffer property, use .bytes to get Uint8Array instead")}get multibaseName(){throw new Error('"multibaseName" property is deprecated')}get prefix(){throw new Error('"prefix" property is deprecated')}static asCID(e){if(e instanceof c)return e;if(e!=null&&e.asCID===e){let{version:t,code:o,multihash:s,bytes:n}=e;return new c(t,o,s,n||Ie(t,o,s.bytes))}else if(e!=null&&e[Le]===!0){let{version:t,multihash:o,code:s}=e,n=Ae(o);return c.create(t,s,n)}else return null}static create(e,t,o){if(typeof t!="number")throw new Error("String codecs are no longer supported");switch(e){case 0:{if(t!==V)throw new Error(`Version 0 CID must use dag-pb (code: ${V}) block encoding`);return new c(e,t,o,o.bytes)}case 1:{let s=Ie(e,t,o.bytes);return new c(e,t,o,s)}default:throw new Error("Invalid version")}}static createV0(e){return c.create(0,V,e)}static createV1(e,t){return c.create(1,e,t)}static decode(e){let[t,o]=c.decodeFirst(e);if(o.length)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=c.inspectBytes(e),o=t.size-t.multihashSize,s=y(e.subarray(o,o+t.multihashSize));if(s.byteLength!==t.multihashSize)throw new Error("Incorrect length");let n=s.subarray(t.multihashSize-t.digestSize),D=new M(t.multihashCode,t.digestSize,n,s);return[t.version===0?c.createV0(D):c.createV1(t.codec,D),e.subarray(t.size)]}static inspectBytes(e){let t=0,o=()=>{let[S,P]=O(e.subarray(t));return t+=P,S},s=o(),n=V;if(s===18?(s=0,t=0):s===1&&(n=o()),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let D=t,a=o(),f=o(),B=t+f,p=B-D;return{version:s,codec:n,multihashCode:a,digestSize:f,multihashSize:p,size:B}}static parse(e,t){let[o,s]=Jt(e,t),n=c.decode(s);return n._baseCache.set(o,e),n}},Jt=(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 z.prefix:{let t=e||z;return[z.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)]}}},Xt=(r,e,t)=>{let{prefix:o}=t;if(o!==w.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let s=e.get(o);if(s==null){let n=t.encode(r).slice(1);return e.set(o,n),n}else return s},Gt=(r,e,t)=>{let{prefix:o}=t,s=e.get(o);if(s==null){let n=t.encode(r);return e.set(o,n),n}else return s},V=112,Kt=18,Ie=(r,e,t)=>{let o=L(r),s=o+L(e),n=new Uint8Array(s+t.byteLength);return I(r,n,0),I(e,n,o),n.set(t,s),n},Le=Symbol.for("@ipld/js-cid/CID"),$={writable:!1,configurable:!1,enumerable:!0},q={writable:!1,enumerable:!1,configurable:!1},Qt="0.0.0-dev",Ht=(r,e)=>{if(r.test(Qt))console.warn(e);else throw new Error(e)},Wt=`CID.isCID(v) is deprecated and will be removed in the next major release. | ||
var Uint8arrays=(()=>{var De=Object.defineProperty;var qe=r=>De(r,"__esModule",{value:!0});var h=(r,e)=>{qe(r);for(var t in e)De(r,t,{get:e[t],enumerable:!0})};var _t={};h(_t,{compare:()=>ie,concat:()=>ae,equals:()=>ce,fromString:()=>Ve,toString:()=>Pe,xor:()=>ke});function ie(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 v(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function T(r=0){return globalThis.Buffer!=null&&globalThis.Buffer.allocUnsafe!=null?v(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}function ae(r,e){e||(e=r.reduce((s,n)=>s+n.length,0));let t=T(e),o=0;for(let s of r)t.set(s,o),o+=s.length;return v(t)}function ce(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}var X={};h(X,{identity:()=>Qe});function Re(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),o=0;o<t.length;o++)t[o]=255;for(var s=0;s<r.length;s++){var n=r.charAt(s),D=n.charCodeAt(0);if(t[D]!==255)throw new TypeError(n+" is ambiguous");t[D]=s}var a=r.length,f=r.charAt(0),S=Math.log(a)/Math.log(256),p=Math.log(256)/Math.log(a);function U(u){if(u instanceof Uint8Array||(ArrayBuffer.isView(u)?u=new Uint8Array(u.buffer,u.byteOffset,u.byteLength):Array.isArray(u)&&(u=Uint8Array.from(u))),!(u instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(u.length===0)return"";for(var d=0,F=0,b=0,C=u.length;b!==C&&u[b]===0;)b++,d++;for(var E=(C-b)*p+1>>>0,l=new Uint8Array(E);b!==C;){for(var g=u[b],A=0,m=E-1;(g!==0||A<F)&&m!==-1;m--,A++)g+=256*l[m]>>>0,l[m]=g%a>>>0,g=g/a>>>0;if(g!==0)throw new Error("Non-zero carry");F=A,b++}for(var y=E-F;y!==E&&l[y]===0;)y++;for(var $=f.repeat(d);y<E;++y)$+=r.charAt(l[y]);return $}function k(u){if(typeof u!="string")throw new TypeError("Expected String");if(u.length===0)return new Uint8Array;var d=0;if(u[d]!==" "){for(var F=0,b=0;u[d]===f;)F++,d++;for(var C=(u.length-d)*S+1>>>0,E=new Uint8Array(C);u[d];){var l=t[u.charCodeAt(d)];if(l===255)return;for(var g=0,A=C-1;(l!==0||g<b)&&A!==-1;A--,g++)l+=a*E[A]>>>0,E[A]=l%256>>>0,l=l/256>>>0;if(l!==0)throw new Error("Non-zero carry");b=g,d++}if(u[d]!==" "){for(var m=C-b;m!==C&&E[m]===0;)m++;for(var y=new Uint8Array(F+(C-m)),$=F;m!==C;)y[$++]=E[m++];return y}}}function $e(u){var d=k(u);if(d)return d;throw new Error(`Non-${e} character`)}return{encode:U,decodeUnsafe:k,decode:$e}}var Je=Re,Xe=Je,fe=Xe;var cr=new Uint8Array(0);var de=(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},x=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")};var he=r=>new TextEncoder().encode(r),pe=r=>new TextDecoder().decode(r);var be=class{constructor(e,t,o){this.name=e,this.prefix=t,this.baseEncode=o}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},me=class{constructor(e,t,o){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=o}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 Ee(this,e)}},Ce=class{constructor(e){this.decoders=e}or(e){return Ee(this,e)}decode(e){let t=e[0],o=this.decoders[t];if(o)return o.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},Ee=(r,e)=>new Ce({...r.decoders||{[r.prefix]:r},...e.decoders||{[e.prefix]:e}}),ge=class{constructor(e,t,o,s){this.name=e,this.prefix=t,this.baseEncode=o,this.baseDecode=s,this.encoder=new be(e,t,o),this.decoder=new me(e,t,s)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}},z=({name:r,prefix:e,encode:t,decode:o})=>new ge(r,e,t,o),j=({prefix:r,name:e,alphabet:t})=>{let{encode:o,decode:s}=fe(t,e);return z({prefix:r,name:e,encode:o,decode:n=>x(s(n))})},Ge=(r,e,t,o)=>{let s={};for(let p=0;p<e.length;++p)s[e[p]]=p;let n=r.length;for(;r[n-1]==="=";)--n;let D=new Uint8Array(n*t/8|0),a=0,f=0,S=0;for(let p=0;p<n;++p){let U=s[r[p]];if(U===void 0)throw new SyntaxError(`Non-${o} character`);f=f<<t|U,a+=t,a>=8&&(a-=8,D[S++]=255&f>>a)}if(a>=t||255&f<<8-a)throw new SyntaxError("Unexpected end of data");return D},Ke=(r,e,t)=>{let o=e[e.length-1]==="=",s=(1<<t)-1,n="",D=0,a=0;for(let f=0;f<r.length;++f)for(a=a<<8|r[f],D+=8;D>t;)D-=t,n+=e[s&a>>D];if(D&&(n+=e[s&a<<t-D]),o)for(;n.length*t&7;)n+="=";return n},i=({name:r,prefix:e,bitsPerChar:t,alphabet:o})=>z({prefix:e,name:r,encode(s){return Ke(s,o,t)},decode(s){return Ge(s,o,t,r)}});var Qe=z({prefix:"\0",name:"identity",encode:r=>pe(r),decode:r=>he(r)});var G={};h(G,{base2:()=>He});var He=i({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var K={};h(K,{base8:()=>We});var We=i({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Q={};h(Q,{base10:()=>Ze});var Ze=j({prefix:"9",name:"base10",alphabet:"0123456789"});var H={};h(H,{base16:()=>Ye,base16upper:()=>_e});var Ye=i({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),_e=i({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var W={};h(W,{base32:()=>L,base32hex:()=>ot,base32hexpad:()=>nt,base32hexpadupper:()=>ut,base32hexupper:()=>st,base32pad:()=>tt,base32padupper:()=>rt,base32upper:()=>et,base32z:()=>Dt});var L=i({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),et=i({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),tt=i({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),rt=i({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ot=i({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),st=i({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),nt=i({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ut=i({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Dt=i({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Z={};h(Z,{base36:()=>it,base36upper:()=>at});var it=j({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),at=j({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Y={};h(Y,{base58btc:()=>w,base58flickr:()=>ct});var w=j({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ct=j({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var _={};h(_,{base64:()=>ft,base64pad:()=>dt,base64url:()=>ht,base64urlpad:()=>pt});var ft=i({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),dt=i({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),ht=i({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),pt=i({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var ee={};h(ee,{base256emoji:()=>Et});var we=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}"),lt=we.reduce((r,e,t)=>(r[t]=e,r),[]),bt=we.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);function mt(r){return r.reduce((e,t)=>(e+=lt[t],e),"")}function Ct(r){let e=[];for(let t of r){let o=bt[t.codePointAt(0)];if(o===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var Et=z({prefix:"\u{1F680}",name:"base256emoji",encode:mt,decode:Ct});var oe={};h(oe,{sha256:()=>Vt,sha512:()=>Pt});var gt=xe,ye=128,wt=127,yt=~wt,xt=Math.pow(2,31);function xe(r,e,t){e=e||[],t=t||0;for(var o=t;r>=xt;)e[t++]=r&255|ye,r/=128;for(;r&yt;)e[t++]=r&255|ye,r>>>=7;return e[t]=r|0,xe.bytes=t-o+1,e}var At=te,vt=128,Ae=127;function te(r,e){var t=0,e=e||0,o=0,s=e,n,D=r.length;do{if(s>=D)throw te.bytes=0,new RangeError("Could not decode varint");n=r[s++],t+=o<28?(n&Ae)<<o:(n&Ae)*Math.pow(2,o),o+=7}while(n>=vt);return te.bytes=s-e,t}var jt=Math.pow(2,7),Ft=Math.pow(2,14),Bt=Math.pow(2,21),St=Math.pow(2,28),Ut=Math.pow(2,35),Tt=Math.pow(2,42),zt=Math.pow(2,49),Lt=Math.pow(2,56),It=Math.pow(2,63),Ot=function(r){return r<jt?1:r<Ft?2:r<Bt?3:r<St?4:r<Ut?5:r<Tt?6:r<zt?7:r<Lt?8:r<It?9:10},Nt={encode:gt,decode:At,encodingLength:Ot},Mt=Nt,N=Mt;var M=(r,e=0)=>[N.decode(r,e),N.decode.bytes],I=(r,e,t=0)=>(N.encode(r,e,t),e),O=r=>N.encodingLength(r);var B=(r,e)=>{let t=e.byteLength,o=O(r),s=o+O(t),n=new Uint8Array(s+t);return I(r,n,0),I(t,n,o),n.set(e,s),new V(r,t,e,n)},je=r=>{let e=x(r),[t,o]=M(e),[s,n]=M(e.subarray(o)),D=e.subarray(o+n);if(D.byteLength!==s)throw new Error("Incorrect length");return new V(t,s,D,e)},Fe=(r,e)=>r===e?!0:r.code===e.code&&r.size===e.size&&de(r.bytes,e.bytes),V=class{constructor(e,t,o,s){this.code=e,this.size=t,this.digest=o,this.bytes=s}};var re=({name:r,code:e,encode:t})=>new Se(r,e,t),Se=class{constructor(e,t,o){this.name=e,this.code=t,this.encode=o}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?B(this.code,t):t.then(o=>B(this.code,o))}else throw Error("Unknown type, must be binary type")}};var Te=r=>async e=>new Uint8Array(await crypto.subtle.digest(r,e)),Vt=re({name:"sha2-256",code:18,encode:Te("SHA-256")}),Pt=re({name:"sha2-512",code:19,encode:Te("SHA-512")});var se={};h(se,{identity:()=>qt});var ze=0,kt="identity",Le=x,$t=r=>B(ze,Le(r)),qt={code:ze,name:kt,encode:Le,digest:$t};var Ir=new TextEncoder,Or=new TextDecoder;var c=class{constructor(e,t,o,s){this.code=t,this.version=e,this.multihash=o,this.bytes=s,this.byteOffset=s.byteOffset,this.byteLength=s.byteLength,this.asCID=this,this._baseCache=new Map,Object.defineProperties(this,{byteOffset:R,byteLength:R,code:q,version:q,multihash:q,bytes:q,_baseCache:R,asCID:R})}toV0(){switch(this.version){case 0:return this;default:{let{code:e,multihash:t}=this;if(e!==P)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Qt)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return c.createV0(t)}}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,o=B(e,t);return c.createV1(this.code,o)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}equals(e){return e&&this.code===e.code&&this.version===e.version&&Fe(this.multihash,e.multihash)}toString(e){let{bytes:t,version:o,_baseCache:s}=this;switch(o){case 0:return Gt(t,s,e||w.encoder);default:return Kt(t,s,e||L.encoder)}}toJSON(){return{code:this.code,version:this.version,hash:this.multihash.bytes}}get[Symbol.toStringTag](){return"CID"}[Symbol.for("nodejs.util.inspect.custom")](){return"CID("+this.toString()+")"}static isCID(e){return Wt(/^0\.0/,Zt),!!(e&&(e[Oe]||e.asCID===e))}get toBaseEncodedString(){throw new Error("Deprecated, use .toString()")}get codec(){throw new Error('"codec" property is deprecated, use integer "code" property instead')}get buffer(){throw new Error("Deprecated .buffer property, use .bytes to get Uint8Array instead")}get multibaseName(){throw new Error('"multibaseName" property is deprecated')}get prefix(){throw new Error('"prefix" property is deprecated')}static asCID(e){if(e instanceof c)return e;if(e!=null&&e.asCID===e){let{version:t,code:o,multihash:s,bytes:n}=e;return new c(t,o,s,n||Ie(t,o,s.bytes))}else if(e!=null&&e[Oe]===!0){let{version:t,multihash:o,code:s}=e,n=je(o);return c.create(t,s,n)}else return null}static create(e,t,o){if(typeof t!="number")throw new Error("String codecs are no longer supported");switch(e){case 0:{if(t!==P)throw new Error(`Version 0 CID must use dag-pb (code: ${P}) block encoding`);return new c(e,t,o,o.bytes)}case 1:{let s=Ie(e,t,o.bytes);return new c(e,t,o,s)}default:throw new Error("Invalid version")}}static createV0(e){return c.create(0,P,e)}static createV1(e,t){return c.create(1,e,t)}static decode(e){let[t,o]=c.decodeFirst(e);if(o.length)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=c.inspectBytes(e),o=t.size-t.multihashSize,s=x(e.subarray(o,o+t.multihashSize));if(s.byteLength!==t.multihashSize)throw new Error("Incorrect length");let n=s.subarray(t.multihashSize-t.digestSize),D=new V(t.multihashCode,t.digestSize,n,s);return[t.version===0?c.createV0(D):c.createV1(t.codec,D),e.subarray(t.size)]}static inspectBytes(e){let t=0,o=()=>{let[U,k]=M(e.subarray(t));return t+=k,U},s=o(),n=P;if(s===18?(s=0,t=0):s===1&&(n=o()),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let D=t,a=o(),f=o(),S=t+f,p=S-D;return{version:s,codec:n,multihashCode:a,digestSize:f,multihashSize:p,size:S}}static parse(e,t){let[o,s]=Xt(e,t),n=c.decode(s);return n._baseCache.set(o,e),n}},Xt=(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)]}}},Gt=(r,e,t)=>{let{prefix:o}=t;if(o!==w.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let s=e.get(o);if(s==null){let n=t.encode(r).slice(1);return e.set(o,n),n}else return s},Kt=(r,e,t)=>{let{prefix:o}=t,s=e.get(o);if(s==null){let n=t.encode(r);return e.set(o,n),n}else return s},P=112,Qt=18,Ie=(r,e,t)=>{let o=O(r),s=o+O(e),n=new Uint8Array(s+t.byteLength);return I(r,n,0),I(e,n,o),n.set(t,s),n},Oe=Symbol.for("@ipld/js-cid/CID"),q={writable:!1,configurable:!1,enumerable:!0},R={writable:!1,enumerable:!1,configurable:!1},Ht="0.0.0-dev",Wt=(r,e)=>{if(r.test(Ht))console.warn(e);else throw new Error(e)},Zt=`CID.isCID(v) is deprecated and will be removed in the next major release. | ||
Following code pattern: | ||
@@ -16,3 +16,3 @@ | ||
} | ||
`;var se={...J,...X,...G,...K,...Q,...H,...W,...Z,...Y,..._},$r={...re,...oe};function Ne(r,e,t,o){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:o}}}var Oe=Ne("utf8","u",r=>{let e=new TextDecoder("utf8");return"u"+e.decode(r)},r=>new TextEncoder().encode(r.substring(1))),ne=Ne("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=U(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Zt={utf8:Oe,"utf-8":Oe,hex:se.base16,latin1:ne,ascii:ne,binary:ne,...se},R=Zt;function Me(r,e="utf8"){let t=R[e];if(!t)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(r,"utf8"):t.decoder.decode(`${t.prefix}${r}`)}function Ve(r,e="utf8"){let t=R[e];if(!t)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):t.encoder.encode(r).substring(1)}function Pe(r,e){if(r.length!==e.length)throw new Error("Inputs should have the same length");let t=U(r.length);for(let o=0;o<r.length;o++)t[o]=r[o]^e[o];return t}return Yt;})(); | ||
`;var ne={...X,...G,...K,...Q,...H,...W,...Z,...Y,..._,...ee},Xr={...oe,...se};function Ne(r,e,t,o){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:o}}}var Me=Ne("utf8","u",r=>{let e=new TextDecoder("utf8");return"u"+e.decode(r)},r=>new TextEncoder().encode(r.substring(1))),ue=Ne("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=T(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Yt={utf8:Me,"utf-8":Me,hex:ne.base16,latin1:ue,ascii:ue,binary:ue,...ne},J=Yt;function Ve(r,e="utf8"){let t=J[e];if(!t)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?v(globalThis.Buffer.from(r,"utf-8")):t.decoder.decode(`${t.prefix}${r}`)}function Pe(r,e="utf8"){let t=J[e];if(!t)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):t.encoder.encode(r).substring(1)}function ke(r,e){if(r.length!==e.length)throw new Error("Inputs should have the same length");let t=T(r.length);for(let o=0;o<r.length;o++)t[o]=r[o]^e[o];return v(t)}return _t;})(); | ||
return Uint8arrays})); |
{ | ||
"name": "uint8arrays", | ||
"version": "3.1.0", | ||
"version": "3.1.1", | ||
"description": "Utility functions to make dealing with Uint8Arrays easier", | ||
@@ -93,4 +93,4 @@ "main": "./cjs/src/index.js", | ||
"achingbrain <alex@achingbrain.net>", | ||
"Cayman <caymannava@gmail.com>", | ||
"Irakli Gozalishvili <contact@gozala.io>", | ||
"Cayman <caymannava@gmail.com>", | ||
"Hugo Dias <hugomrdias@gmail.com>", | ||
@@ -97,0 +97,0 @@ "Mircea Nistor <mirceanis@gmail.com>", |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
95342
56
550