5 lines
19 KiB
JavaScript
5 lines
19 KiB
JavaScript
|
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.IpldDagPb = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
||
|
|
"use strict";var IpldDagPb=(()=>{var $=Object.defineProperty;var Ae=Object.getOwnPropertyDescriptor;var Te=Object.getOwnPropertyNames;var ze=Object.prototype.hasOwnProperty;var Ne=(e,t)=>{for(var r in t)$(e,r,{get:t[r],enumerable:!0})},Le=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Te(t))!ze.call(e,o)&&o!==r&&$(e,o,{get:()=>t[o],enumerable:!(n=Ae(t,o))||n.enumerable});return e};var Ie=e=>Le($({},"__esModule",{value:!0}),e);var gr={};Ne(gr,{code:()=>mr,createLink:()=>ve,createNode:()=>ge,decode:()=>xr,encode:()=>yr,name:()=>br,prepare:()=>W,validate:()=>Z});var Er=new Uint8Array(0);function Y(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 T(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 Be(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var i=e.charAt(o),s=i.charCodeAt(0);if(r[s]!==255)throw new TypeError(i+" is ambiguous");r[s]=o}var a=e.length,f=e.charAt(0),p=Math.log(a)/Math.log(256),A=Math.log(256)/Math.log(a);function G(c){if(c instanceof Uint8Array||(ArrayBuffer.isView(c)?c=new Uint8Array(c.buffer,c.byteOffset,c.byteLength):Array.isArray(c)&&(c=Uint8Array.from(c))),!(c instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(c.length===0)return"";for(var d=0,D=0,u=0,w=c.length;u!==w&&c[u]===0;)u++,d++;for(var b=(w-u)*A+1>>>0,h=new Uint8Array(b);u!==w;){for(var m=c[u],E=0,l=b-1;(m!==0||E<D)&&l!==-1;l--,E++)m+=256*h[l]>>>0,h[l]=m%a>>>0,m=m/a>>>0;if(m!==0)throw new Error("Non-zero carry");D=E,u++}for(var x=b-D;x!==b&&h[x]===0;)x++;for(var M=f.repeat(d);x<b;++x)M+=e.charAt(h[x]);return M}function H(c){if(typeof c!="string")throw new TypeError("Expected String");if(c.length===0)return new Uint8Array;var d=0;if(c[d]!==" "){for(var D=0,u=0;c[d]===f;)D++,d++;for(var w=(c.length-d)*p+1>>>0,b=new Uint8Array(w);c[d];){var h=r[c.charCodeAt(d)];if(h===255)return;for(var m=0,E=w-1;(h!==0||m<u)&&E!==-1;E--,m++)h+=a*b[E]>>>0,b[E]=h%256>>>0,h=h/256>>>0;if(h!==0)throw new Error("Non-zero carry");u=m,d++}if(c[d]!==" "){for(var l=w-u;l!==w&&b[l]===0;)l++;for(var x=new Uint8Array(D+(w-l)),M=D;l!==w;)x[M++]=b[l++];return x}}}function De(c){var d=H(c);if(d)return d;throw new Error(`Non-${t} character`)}return{encode:G,decodeUnsafe:H,decode:De}}var Ce=Be,ke=Ce,_=ke;var F=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},j=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return ee(this,t)}},q=class{decoders;constructor(t){this.decoders=t}or(t){return ee(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function ee(e,t){return new q({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var R=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new F(t,r,n),this.decoder=new j(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}}
|
||
|
|
return IpldDagPb}));
|
||
|
|
//# sourceMappingURL=index.min.js.map
|