-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.min.js
1 lines (1 loc) · 7 KB
/
index.min.js
1
function e(e,t=0,r=1,n){let s=[];for(let i=0;i<r;i++){let r=0,i=0,o=[];const a=127;for(;;){if(t>=e.length)throw new RangeError("buffer overflow");let n=e[t++];if(i|=(n&a)<<r,r+=7,r>=8&&(o.push(255&i),i>>=8,r-=8),n<=a)break}r&&o.push(i),s.push(n(o.reverse()))}return s.push(t),s}function t(e){return"0x"+e.map((e=>e.toString(16).padStart(2,"0"))).join("")}function r(e){let t=e.reduce(((e,t)=>256*e+t),0);if(!Number.isSafeInteger(t))throw new RangeError("unsafe");return t}function n(t,n,s){return e(t,n,s,r)}function s(e,t,r=0){if("number"==typeof t&&!Number.isSafeInteger(t))throw new RangeError("unsafe");if((t=BigInt(t))<0)throw new RangeError("negative");const n=127n;for(;t>n;)e[r++]=128|Number(t&n),t>>=7n;return e[r++]=Number(t),r}var i=Object.freeze({__proto__:null,read:n,readBigInt:function(r,n,s){return e(r,n,s,(e=>BigInt(t(e))))},readHex:function(r,n,s){return e(r,n,s,t)},write:s});class o{constructor(e){let t=this.chars=[...e];this.map=new Map(t.map(((e,t)=>[e,t])))}get length(){return this.map.size}indexOf(e){let t=this.map.get(e);if(!Number.isInteger(t))throw new TypeError(`invalid digit "${e}"`);return t}encode(e){return Array.from(e,(e=>this.chars[e])).join("")}}class a{constructor(e){let t=this.table=new o(e),r=t.length,n=this.bits=Math.log2(r);if(r<2||!Number.isInteger(n))throw new TypeError;t.chars.push("=")}decode(e){let{table:t,bits:r}=this,n=e.length,s=0,i=0,o=0;for(;n&&"="==e[n-1];)--n;let a=new Uint8Array(n*r>>3);for(let h=0;h<n;h++)i=i<<r|t.indexOf(e[h]),o+=r,o>=8&&(a[s++]=i>>(o-=8)&255);if(i<<8-o&255)throw new Error("invalid");return a}encode(e,t){let{table:r,bits:n}=this,s=(1<<n)-1,i=0,o=0,a=[];for(let t=0,r=e.length;t<r;t++)for(i=i<<8|e[t],o+=8;o>=n;)a.push(i>>(o-=n)&s);for(o&&a.push(i<<n-o&s);t&&a.length*n&7;)a.push(s+1);return r.encode(a)}}class h{constructor(e){this.table=new o(e)}decode(e){let{table:t}=this,r=t.length,n=e.length,s=new Uint8Array(n),i=0;for(let n of e){let e=t.indexOf(n);for(let t=0;t<i;t++)e+=s[t]*r,s[t]=e,e>>=8;for(;e;)s[i++]=e,e>>=8}for(let r=0;r<n&&e[r]===t.chars[0];r++)i++;return s.subarray(0,i).reverse()}encode(e){let{table:t}=this,r=t.length,n=[];for(let t of e){for(let e=0;e<n.length;++e){let s=n[e]<<8|t;n[e]=s%r,t=s/r|0}for(;t;)n.push(t%r),t=t/r|0}for(let t=0;t<e.length&&!e[t];t++)n.push(0);return t.encode(n.reverse())}}const c=new o("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),l=[996825010,642813549,513874426,1027748829,705979059];function f(e){let t=1;for(let r of e){let e=t>>25;t=(33554431&t)<<5^r;for(let r=0;r<5;r++)e>>r&1&&(t^=l[r])}return t}function d(e){let t=Array.from(e,(t=>{let r=t.codePointAt(0);if(r<33||r>126)throw new Error(`invalid hrp character: ${e}`);return r})),r=t.length;if(!r||r>83)throw new Error("invalid hrp length");return[...t.map((e=>e>>5)),0,...t.map((e=>31&e))]}class u{constructor(e,t,r=1){this.hrp=e,this.v32=t,this.type=r}toString(){return this.hrp+"1"+c.encode(this.v32)+c.encode(function(e,t,r){let n=f([...d(t),...r,0,0,0,0,0,0])^e;return[25,20,15,10,5,0].map((e=>n>>e&31))}(this.type,this.hrp,this.v32))}static decode(e){let t=e.toLowerCase();if(e!==t&&e!==e.toUpperCase())throw new Error("mixed case");let r=t.lastIndexOf("1");if(r<1)throw new Error("no hrp");if(t.length-r<7)throw new Error("no check");let n=t.slice(0,r),s=Uint8Array.from(t.slice(r+1),(e=>c.indexOf(e)));return new this(n,s.subarray(0,-6),f([...d(n),...s]))}}Object.defineProperty(u,"M",{value:734539939,writable:!1,configurable:!1});const w=new Map,p=new Set;class g{static[Symbol.iterator](){return p.values()}static decode(e){let t=e.codePointAt(0),r=this.for(String.fromCodePoint(t)),n=r.decode(e.slice(t<65536?1:2));return{base:r,data:n}}static for(e){if(e instanceof this)return e;let t=w.get(e);if(!t)throw new Error(`unknown multibase: ${e}`);return t}constructor(e,t){if(1!==e.length)throw new Error("invalid prefix");this.prefix=e,this.name=t,w.set(e,this),w.set(t,this),p.add(this)}encodeWithPrefix(e){return this.prefix+this.encode(e)}}class b{static from(e){"string"==typeof e&&(e=g.decode(e));let[t,r,s]=n(e,0,2);if((e=new Uint8Array(e.slice(s))).length!==r)throw new Error(`expected ${r}, got ${e.length} bytes`);return new this(t,e)}constructor(e,t){this.codec=e,this.data=t}get bytes(){let e=[];return this.write(e),Uint8Array.from(e)}write(e,t=0){let{data:r,codec:n}=this;return t=s(e,r.length,s(e,n,t)),r.forEach((r=>e[t++]=r)),t}}function m(e,t,r,n,s=[]){let i=0,o=0,a=(1<<r)-1;for(let n of e){if(n<0||n>>t)throw new Error("invalid digit");for(i=(65535&i)<<t|n,o+=t;o>=r;)o-=r,s.push(i>>o&a)}if(n)o&&s.push(i<<r-o&a);else if(o>=t||i<<r-o&a)throw new Error("malformed");return Uint8Array.from(s)}const y="ABCDEFGHIJKLMNOPQRSTUVWXYZ",v=y.toLowerCase(),x="0123456789";function E(e){return e.replaceAll(/[0OIl]/g,"")}const A=new a(y+v+x+"+/"),I=new a(y+v+x+"-_"),C=new h(E(x+y+v)),U=new h(E(x+v+y)),S=new h(x+v),k=new a("ybndrfg8ejkmcpqxot1uwisza345h769"),O=new a(x+v.slice(0,-4)),j=new a("abcdefghijklmnopqrstuvwxyz234567"),z=new a(x+"abcdef"),N=new h(x),P=new a("01234567"),M=new a("01");class $ extends g{constructor(e,t,r,{casing:n,padding:s}={}){super(e,t),this.coder=r,this.casing=n,this.padding=s}decode(e){return void 0!==this.casing&&(e=e.toLowerCase()),this.coder.decode(e)}encode(e){let t=this.coder.encode(e,this.padding);return this.casing&&(t=t.toUpperCase()),t}}new $("0","base2",M),new $("7","base8",P),new $("9","base10",N),new $("f","base16",z,{casing:!1}),new $("F","base16upper",z,{casing:!0}),new $("v","base32hex",O,{casing:!1}),new $("V","base32hexupper",O,{casing:!0}),new $("t","base32hexpad",O,{casing:!1,padding:!0}),new $("T","base32hexpadupper",O,{casing:!0,padding:!0}),new $("b","base32",j,{casing:!1}),new $("B","base32upper",j,{casing:!0}),new $("c","base32pad",j,{casing:!1,padding:!0}),new $("C","base32padupper",j,{casing:!0,padding:!0}),new $("h","base32z",k),new $("k","base36",S,{casing:!1}),new $("K","base36upper",S,{casing:!0}),new $("z","base58btc",C),new $("Z","base58flickr",U),new $("m","base64",A),new $("M","base64pad",A,{padding:!0}),new $("u","base64url",I),new $("U","base64urlpad",I,{padding:!0});class B{static from(e){let t;if("string"==typeof e)if(46==e.length&&e.startsWith("Qm"))e=C.decode(e);else if(({base:t,data:e}=g.decode(e)),18==e[0])throw new Error("CIDv0 cannot be multibase");try{let[r,s,i]=n(e,0,2);if(18==r){let t=b.from(e);if(32!=t.data.length)throw new Error("CIDv0 must be 32-bytes");return new this(0,112,t)}return new this(r,s,b.from(e.slice(i)),t)}catch(e){throw new Error(`malformed CID: ${e.message}`)}}constructor(e,t,r,n){this.version=e,this.codec=t,this.hash=r,this.base=n}get bytes(){let{version:e,codec:t,hash:r}=this;if(e){let n=[];return r.write(n,s(n,t,s(n,e))),Uint8Array.from(n)}return r.bytes}upgrade(){let{version:e,codec:t,hash:r,base:n}=this;return new B(e||1,t,r,n)}toString(e){let{version:t,base:r,bytes:n}=this;return t?g.for(e||r||"k").encodeWithPrefix(n):C.encode(n)}}export{N as Base10,z as Base16,M as Base2,j as Base32,O as Base32Hex,k as Base32Z,S as Base36,C as Base58BTC,U as Base58Flickr,A as Base64,I as Base64URL,P as Base8,u as Bech32,B as CID,o as CharTable,g as Multibase,$ as Multibased,b as Multihash,h as Prefix0,a as RFC4648,m as convert,i as uvarint};