@ipld/dag-pb
Advanced tools
Comparing version 4.0.5 to 4.0.6
(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 G=Object.defineProperty;var Ee=Object.getOwnPropertyDescriptor;var De=Object.getOwnPropertyNames;var Ae=Object.prototype.hasOwnProperty;var Te=(r,t)=>{for(var e in t)G(r,e,{get:t[e],enumerable:!0})},Ne=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of De(t))!Ae.call(r,o)&&o!==e&&G(r,o,{get:()=>t[o],enumerable:!(n=Ee(t,o))||n.enumerable});return r};var ze=r=>Ne(G({},"__esModule",{value:!0}),r);var br={};Te(br,{code:()=>lr,createLink:()=>xe,createNode:()=>ge,decode:()=>mr,encode:()=>wr,name:()=>ur,prepare:()=>X,validate:()=>W});var Le=_,Z=128,Ie=127,Be=~Ie,ke=Math.pow(2,31);function _(r,t,e){t=t||[],e=e||0;for(var n=e;r>=ke;)t[e++]=r&255|Z,r/=128;for(;r&Be;)t[e++]=r&255|Z,r>>>=7;return t[e]=r|0,_.bytes=e-n+1,t}var Ce=$,Pe=128,Y=127;function $(r,n){var e=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw $.bytes=0,new RangeError("Could not decode varint");s=r[i++],e+=o<28?(s&Y)<<o:(s&Y)*Math.pow(2,o),o+=7}while(s>=Pe);return $.bytes=i-n,e}var Se=Math.pow(2,7),Ue=Math.pow(2,14),He=Math.pow(2,21),Me=Math.pow(2,28),Oe=Math.pow(2,35),Ge=Math.pow(2,42),$e=Math.pow(2,49),Ve=Math.pow(2,56),Fe=Math.pow(2,63),je=function(r){return r<Se?1:r<Ue?2:r<He?3:r<Me?4:r<Oe?5:r<Ge?6:r<$e?7:r<Ve?8:r<Fe?9:10},qe={encode:Le,decode:Ce,encodingLength:je},Re=qe,k=Re;var C=(r,t=0)=>[k.decode(r,t),k.decode.bytes],N=(r,t,e=0)=>(k.encode(r,t,e),t),z=r=>k.encodingLength(r);var vr=new Uint8Array(0);var re=(r,t)=>{if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0},L=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 te=(r,t)=>{let e=t.byteLength,n=z(r),o=n+z(e),i=new Uint8Array(o+e);return N(r,i,0),N(e,i,n),i.set(t,o),new I(r,e,t,i)},ne=r=>{let t=L(r),[e,n]=C(t),[o,i]=C(t.subarray(n)),s=t.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new I(e,o,s,t)},oe=(r,t)=>{if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&re(r.bytes,e.bytes)}},I=class{constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function Qe(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var i=r.charAt(o),s=i.charCodeAt(0);if(e[s]!==255)throw new TypeError(i+" is ambiguous");e[s]=o}var a=r.length,f=r.charAt(0),g=Math.log(a)/Math.log(256),h=Math.log(256)/Math.log(a);function T(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,A=0,u=0,w=c.length;u!==w&&c[u]===0;)u++,d++;for(var m=(w-u)*h+1>>>0,p=new Uint8Array(m);u!==w;){for(var b=c[u],D=0,l=m-1;(b!==0||D<A)&&l!==-1;l--,D++)b+=256*p[l]>>>0,p[l]=b%a>>>0,b=b/a>>>0;if(b!==0)throw new Error("Non-zero carry");A=D,u++}for(var x=m-A;x!==m&&p[x]===0;)x++;for(var M=f.repeat(d);x<m;++x)M+=r.charAt(p[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 A=0,u=0;c[d]===f;)A++,d++;for(var w=(c.length-d)*g+1>>>0,m=new Uint8Array(w);c[d];){var p=e[c.charCodeAt(d)];if(p===255)return;for(var b=0,D=w-1;(p!==0||b<u)&&D!==-1;D--,b++)p+=a*m[D]>>>0,m[D]=p%256>>>0,p=p/256>>>0;if(p!==0)throw new Error("Non-zero carry");u=b,d++}if(c[d]!==" "){for(var l=w-u;l!==w&&m[l]===0;)l++;for(var x=new Uint8Array(A+(w-l)),M=A;l!==w;)x[M++]=m[l++];return x}}}function ve(c){var d=H(c);if(d)return d;throw new Error(`Non-${t} character`)}return{encode:T,decodeUnsafe:H,decode:ve}}var Ke=Qe,Xe=Ke,ie=Xe;var V=class{constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},F=class{constructor(t,e,n){if(this.name=t,this.prefix=e,e.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=e.codePointAt(0),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 se(this,t)}},j=class{constructor(t){this.decoders=t}or(t){return se(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},se=(r,t)=>new j({...r.decoders||{[r.prefix]:r},...t.decoders||{[t.prefix]:t}}),q=class{constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new V(t,e,n),this.decoder=new F(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}},ae=({name:r,prefix:t,encode:e,decode:n})=>new q(r,t,e,n),R=({prefix:r,name:t,alphabet:e})=>{let{encode:n,decode:o}=ie(e,t);return ae({prefix:r,name:t,encode:n,decode:i=>L(o(i))})},We=(r,t,e,n)=>{let o={};for(let h=0;h<t.length;++h)o[t[h]]=h;let i=r.length;for(;r[i-1]==="=";)--i;let s=new Uint8Array(i*e/8|0),a=0,f=0,g=0;for(let h=0;h<i;++h){let T=o[r[h]];if(T===void 0)throw new SyntaxError(`Non-${n} character`);f=f<<e|T,a+=e,a>=8&&(a-=8,s[g++]=255&f>>a)}if(a>=e||255&f<<8-a)throw new SyntaxError("Unexpected end of data");return s},Ze=(r,t,e)=>{let n=t[t.length-1]==="=",o=(1<<e)-1,i="",s=0,a=0;for(let f=0;f<r.length;++f)for(a=a<<8|r[f],s+=8;s>e;)s-=e,i+=t[o&a>>s];if(s&&(i+=t[o&a<<e-s]),n)for(;i.length*e&7;)i+="=";return i},y=({name:r,prefix:t,bitsPerChar:e,alphabet:n})=>ae({prefix:t,name:r,encode(o){return Ze(o,n,e)},decode(o){return We(o,n,e,r)}});var v=R({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ir=R({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var P=y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Cr=y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Pr=y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Sr=y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ur=y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Hr=y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Mr=y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Or=y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Gr=y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ce=(r,t)=>{let{bytes:e,version:n}=r;switch(n){case 0:return _e(e,J(r),t||v.encoder);default:return er(e,J(r),t||P.encoder)}};var fe=new WeakMap,J=r=>{let t=fe.get(r);if(t==null){let e=new Map;return fe.set(r,e),e}return t},E=class r{constructor(t,e,n,o){this.code=e,this.version=t,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:t,multihash:e}=this;if(t!==S)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==rr)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}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:e}=this.multihash,n=te(t,e);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(t){return r.equals(this,t)}static equals(t,e){let n=e;return n&&t.code===n.code&&t.version===n.version&&oe(t.multihash,n.multihash)}toString(t){return ce(this,t)}toJSON(){return{"/":ce(this)}}link(){return this}get[Symbol.toStringTag](){return"CID"}[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:i,bytes:s}=e;return new r(n,o,i,s||de(n,o,i.bytes))}else if(e[tr]===!0){let{version:n,multihash:o,code:i}=e,s=ne(o);return r.create(n,i,s)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==S)throw new Error(`Version 0 CID must use dag-pb (code: ${S}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=de(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,S,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=L(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let i=o.subarray(e.multihashSize-e.digestSize),s=new I(e.multihashCode,e.digestSize,i,o);return[e.version===0?r.createV0(s):r.createV1(e.codec,s),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[T,H]=C(t.subarray(e));return e+=H,T},o=n(),i=S;if(o===18?(o=0,e=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=e,a=n(),f=n(),g=e+f,h=g-s;return{version:o,codec:i,multihashCode:a,digestSize:f,multihashSize:h,size:g}}static parse(t,e){let[n,o]=Ye(t,e),i=r.decode(o);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return J(i).set(n,t),i}},Ye=(r,t)=>{switch(r[0]){case"Q":{let e=t||v;return[v.prefix,e.decode(`${v.prefix}${r}`)]}case v.prefix:{let e=t||v;return[v.prefix,e.decode(r)]}case P.prefix:{let e=t||P;return[P.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}},_e=(r,t,e)=>{let{prefix:n}=e;if(n!==v.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let i=e.encode(r).slice(1);return t.set(n,i),i}else return o},er=(r,t,e)=>{let{prefix:n}=e,o=t.get(n);if(o==null){let i=e.encode(r);return t.set(n,i),i}else return o},S=112,rr=18,de=(r,t,e)=>{let n=z(r),o=n+z(t),i=new Uint8Array(o+e.byteLength);return N(r,i,0),N(t,i,n),i.set(e,o),i},tr=Symbol.for("@ipld/js-cid/CID");var nr=new TextDecoder;function Q(r,t){let e=0;for(let n=0;;n+=7){if(n>=64)throw new Error("protobuf: varint overflow");if(t>=r.length)throw new Error("protobuf: unexpected end of data");let o=r[t++];if(e+=n<28?(o&127)<<n:(o&127)*2**n,o<128)break}return[e,t]}function O(r,t){let e;[e,t]=Q(r,t);let n=t+e;if(e<0||n<0)throw new Error("protobuf: invalid length");if(n>r.length)throw new Error("protobuf: unexpected end of data");return[r.subarray(t,n),n]}function he(r,t){let e;return[e,t]=Q(r,t),[e&7,e>>3,t]}function or(r){let t={},e=r.length,n=0;for(;n<e;){let o,i;if([o,i,n]=he(r,n),i===1){if(t.Hash)throw new Error("protobuf: (PBLink) duplicate Hash section");if(o!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${o}) for Hash`);if(t.Name!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Name before Hash");if(t.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Hash");[t.Hash,n]=O(r,n)}else if(i===2){if(t.Name!==void 0)throw new Error("protobuf: (PBLink) duplicate Name section");if(o!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${o}) for Name`);if(t.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Name");let s;[s,n]=O(r,n),t.Name=nr.decode(s)}else if(i===3){if(t.Tsize!==void 0)throw new Error("protobuf: (PBLink) duplicate Tsize section");if(o!==0)throw new Error(`protobuf: (PBLink) wrong wireType (${o}) for Tsize`);[t.Tsize,n]=Q(r,n)}else throw new Error(`protobuf: (PBLink) invalid fieldNumber, expected 1, 2 or 3, got ${i}`)}if(n>e)throw new Error("protobuf: (PBLink) unexpected end of data");return t}function pe(r){let t=r.length,e=0,n,o=!1,i;for(;e<t;){let a,f;if([a,f,e]=he(r,e),a!==2)throw new Error(`protobuf: (PBNode) invalid wireType, expected 2, got ${a}`);if(f===1){if(i)throw new Error("protobuf: (PBNode) duplicate Data section");[i,e]=O(r,e),n&&(o=!0)}else if(f===2){if(o)throw new Error("protobuf: (PBNode) duplicate Links section");n||(n=[]);let g;[g,e]=O(r,e),n.push(or(g))}else throw new Error(`protobuf: (PBNode) invalid fieldNumber, expected 1 or 2, got ${f}`)}if(e>t)throw new Error("protobuf: (PBNode) unexpected end of data");let s={};return i&&(s.Data=i),s.Links=n||[],s}var le=new TextEncoder,ue=2**32,ir=2**31;function sr(r,t){let e=t.length;if(typeof r.Tsize=="number"){if(r.Tsize<0)throw new Error("Tsize cannot be negative");if(!Number.isSafeInteger(r.Tsize))throw new Error("Tsize too large for encoding");e=U(t,e,r.Tsize)-1,t[e]=24}if(typeof r.Name=="string"){let n=le.encode(r.Name);e-=n.length,t.set(n,e),e=U(t,e,n.length)-1,t[e]=18}return r.Hash&&(e-=r.Hash.length,t.set(r.Hash,e),e=U(t,e,r.Hash.length)-1,t[e]=10),t.length-e}function we(r){let t=cr(r),e=new Uint8Array(t),n=t;if(r.Data&&(n-=r.Data.length,e.set(r.Data,n),n=U(e,n,r.Data.length)-1,e[n]=10),r.Links)for(let o=r.Links.length-1;o>=0;o--){let i=sr(r.Links[o],e.subarray(0,n));n-=i,n=U(e,n,i)-1,e[n]=18}return e}function ar(r){let t=0;if(r.Hash){let e=r.Hash.length;t+=1+e+B(e)}if(typeof r.Name=="string"){let e=le.encode(r.Name).length;t+=1+e+B(e)}return typeof r.Tsize=="number"&&(t+=1+B(r.Tsize)),t}function cr(r){let t=0;if(r.Data){let e=r.Data.length;t+=1+e+B(e)}if(r.Links)for(let e of r.Links){let n=ar(e);t+=1+n+B(n)}return t}function U(r,t,e){t-=B(e);let n=t;for(;e>=ir;)r[t++]=e&127|128,e/=128;for(;e>=128;)r[t++]=e&127|128,e>>>=7;return r[t]=e,n}function B(r){return r%2===0&&r++,Math.floor((fr(r)+6)/7)}function fr(r){let t=0;return r>=ue&&(r=Math.floor(r/ue),t=32),r>=65536&&(r>>>=16,t+=16),r>=256&&(r>>>=8,t+=8),t+dr[r]}var dr=[0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8];var hr=["Data","Links"],pr=["Hash","Name","Tsize"],K=new TextEncoder;function be(r,t){if(r===t)return 0;let e=r.Name?K.encode(r.Name):[],n=t.Name?K.encode(t.Name):[],o=e.length,i=n.length;for(let s=0,a=Math.min(o,i);s<a;++s)if(e[s]!==n[s]){o=e[s],i=n[s];break}return o<i?-1:i<o?1:0}function me(r,t){return!Object.keys(r).some(e=>!t.includes(e))}function ye(r){if(typeof r.asCID=="object"){let e=E.asCID(r);if(!e)throw new TypeError("Invalid DAG-PB form");return{Hash:e}}if(typeof r!="object"||Array.isArray(r))throw new TypeError("Invalid DAG-PB form");let t={};if(r.Hash){let e=E.asCID(r.Hash);try{e||(typeof r.Hash=="string"?e=E.parse(r.Hash):r.Hash instanceof Uint8Array&&(e=E.decode(r.Hash)))}catch(n){throw new TypeError(`Invalid DAG-PB form: ${n.message}`)}e&&(t.Hash=e)}if(!t.Hash)throw new TypeError("Invalid DAG-PB form");return typeof r.Name=="string"&&(t.Name=r.Name),typeof r.Tsize=="number"&&(t.Tsize=r.Tsize),t}function X(r){if((r instanceof Uint8Array||typeof r=="string")&&(r={Data:r}),typeof r!="object"||Array.isArray(r))throw new TypeError("Invalid DAG-PB form");let t={};if(r.Data!==void 0)if(typeof r.Data=="string")t.Data=K.encode(r.Data);else if(r.Data instanceof Uint8Array)t.Data=r.Data;else throw new TypeError("Invalid DAG-PB form");if(r.Links!==void 0)if(Array.isArray(r.Links))t.Links=r.Links.map(ye),t.Links.sort(be);else throw new TypeError("Invalid DAG-PB form");else t.Links=[];return t}function W(r){if(!r||typeof r!="object"||Array.isArray(r)||r instanceof Uint8Array||r["/"]&&r["/"]===r.bytes)throw new TypeError("Invalid DAG-PB form");if(!me(r,hr))throw new TypeError("Invalid DAG-PB form (extraneous properties)");if(r.Data!==void 0&&!(r.Data instanceof Uint8Array))throw new TypeError("Invalid DAG-PB form (Data must be bytes)");if(!Array.isArray(r.Links))throw new TypeError("Invalid DAG-PB form (Links must be a list)");for(let t=0;t<r.Links.length;t++){let e=r.Links[t];if(!e||typeof e!="object"||Array.isArray(e)||e instanceof Uint8Array||e["/"]&&e["/"]===e.bytes)throw new TypeError("Invalid DAG-PB form (bad link)");if(!me(e,pr))throw new TypeError("Invalid DAG-PB form (extraneous properties on link)");if(e.Hash===void 0)throw new TypeError("Invalid DAG-PB form (link must have a Hash)");if(e.Hash==null||!e.Hash["/"]||e.Hash["/"]!==e.Hash.bytes)throw new TypeError("Invalid DAG-PB form (link Hash must be a CID)");if(e.Name!==void 0&&typeof e.Name!="string")throw new TypeError("Invalid DAG-PB form (link Name must be a string)");if(e.Tsize!==void 0){if(typeof e.Tsize!="number"||e.Tsize%1!==0)throw new TypeError("Invalid DAG-PB form (link Tsize must be an integer)");if(e.Tsize<0)throw new TypeError("Invalid DAG-PB form (link Tsize cannot be negative)")}if(t>0&&be(e,r.Links[t-1])===-1)throw new TypeError("Invalid DAG-PB form (links must be sorted by Name bytes)")}}function ge(r,t=[]){return X({Data:r,Links:t})}function xe(r,t,e){return ye({Hash:e,Name:r,Tsize:t})}var ur="dag-pb",lr=112;function wr(r){W(r);let t={};return r.Links&&(t.Links=r.Links.map(e=>{let n={};return e.Hash&&(n.Hash=e.Hash.bytes),e.Name!==void 0&&(n.Name=e.Name),e.Tsize!==void 0&&(n.Tsize=e.Tsize),n})),r.Data&&(t.Data=r.Data),we(t)}function mr(r){let t=pe(r),e={};return t.Data&&(e.Data=t.Data),t.Links&&(e.Links=t.Links.map(n=>{let o={};try{o.Hash=E.decode(n.Hash)}catch{}if(!o.Hash)throw new Error("Invalid Hash field found in link, expected CID");return n.Name!==void 0&&(o.Name=n.Name),n.Tsize!==void 0&&(o.Tsize=n.Tsize),o})),e}return ze(br);})(); | ||
"use strict";var IpldDagPb=(()=>{var G=Object.defineProperty;var Ee=Object.getOwnPropertyDescriptor;var De=Object.getOwnPropertyNames;var Ae=Object.prototype.hasOwnProperty;var Te=(r,t)=>{for(var e in t)G(r,e,{get:t[e],enumerable:!0})},Ne=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of De(t))!Ae.call(r,o)&&o!==e&&G(r,o,{get:()=>t[o],enumerable:!(n=Ee(t,o))||n.enumerable});return r};var ze=r=>Ne(G({},"__esModule",{value:!0}),r);var br={};Te(br,{code:()=>lr,createLink:()=>xe,createNode:()=>ge,decode:()=>mr,encode:()=>wr,name:()=>ur,prepare:()=>X,validate:()=>W});function Le(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var i=r.charAt(o),s=i.charCodeAt(0);if(e[s]!==255)throw new TypeError(i+" is ambiguous");e[s]=o}var a=r.length,f=r.charAt(0),g=Math.log(a)/Math.log(256),h=Math.log(256)/Math.log(a);function T(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,A=0,u=0,w=c.length;u!==w&&c[u]===0;)u++,d++;for(var m=(w-u)*h+1>>>0,p=new Uint8Array(m);u!==w;){for(var b=c[u],D=0,l=m-1;(b!==0||D<A)&&l!==-1;l--,D++)b+=256*p[l]>>>0,p[l]=b%a>>>0,b=b/a>>>0;if(b!==0)throw new Error("Non-zero carry");A=D,u++}for(var x=m-A;x!==m&&p[x]===0;)x++;for(var M=f.repeat(d);x<m;++x)M+=r.charAt(p[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 A=0,u=0;c[d]===f;)A++,d++;for(var w=(c.length-d)*g+1>>>0,m=new Uint8Array(w);c[d];){var p=e[c.charCodeAt(d)];if(p===255)return;for(var b=0,D=w-1;(p!==0||b<u)&&D!==-1;D--,b++)p+=a*m[D]>>>0,m[D]=p%256>>>0,p=p/256>>>0;if(p!==0)throw new Error("Non-zero carry");u=b,d++}if(c[d]!==" "){for(var l=w-u;l!==w&&m[l]===0;)l++;for(var x=new Uint8Array(A+(w-l)),M=A;l!==w;)x[M++]=m[l++];return x}}}function ve(c){var d=H(c);if(d)return d;throw new Error(`Non-${t} character`)}return{encode:T,decodeUnsafe:H,decode:ve}}var Ie=Le,Be=Ie,Z=Be;var xr=new Uint8Array(0);var Y=(r,t)=>{if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0},N=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 $=class{constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},V=class{constructor(t,e,n){if(this.name=t,this.prefix=e,e.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=e.codePointAt(0),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 _(this,t)}},F=class{constructor(t){this.decoders=t}or(t){return _(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},_=(r,t)=>new F({...r.decoders||{[r.prefix]:r},...t.decoders||{[t.prefix]:t}}),j=class{constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new $(t,e,n),this.decoder=new V(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}},ee=({name:r,prefix:t,encode:e,decode:n})=>new j(r,t,e,n),q=({prefix:r,name:t,alphabet:e})=>{let{encode:n,decode:o}=Z(e,t);return ee({prefix:r,name:t,encode:n,decode:i=>N(o(i))})},ke=(r,t,e,n)=>{let o={};for(let h=0;h<t.length;++h)o[t[h]]=h;let i=r.length;for(;r[i-1]==="=";)--i;let s=new Uint8Array(i*e/8|0),a=0,f=0,g=0;for(let h=0;h<i;++h){let T=o[r[h]];if(T===void 0)throw new SyntaxError(`Non-${n} character`);f=f<<e|T,a+=e,a>=8&&(a-=8,s[g++]=255&f>>a)}if(a>=e||255&f<<8-a)throw new SyntaxError("Unexpected end of data");return s},Ce=(r,t,e)=>{let n=t[t.length-1]==="=",o=(1<<e)-1,i="",s=0,a=0;for(let f=0;f<r.length;++f)for(a=a<<8|r[f],s+=8;s>e;)s-=e,i+=t[o&a>>s];if(s&&(i+=t[o&a<<e-s]),n)for(;i.length*e&7;)i+="=";return i},y=({name:r,prefix:t,bitsPerChar:e,alphabet:n})=>ee({prefix:t,name:r,encode(o){return Ce(o,n,e)},decode(o){return ke(o,n,e,r)}});var k=y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Nr=y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),zr=y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Lr=y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ir=y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Br=y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),kr=y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Cr=y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Pr=y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var v=q({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Hr=q({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Pe=ne,re=128,Se=127,Ue=~Se,He=Math.pow(2,31);function ne(r,t,e){t=t||[],e=e||0;for(var n=e;r>=He;)t[e++]=r&255|re,r/=128;for(;r&Ue;)t[e++]=r&255|re,r>>>=7;return t[e]=r|0,ne.bytes=e-n+1,t}var Me=R,Oe=128,te=127;function R(r,n){var e=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw R.bytes=0,new RangeError("Could not decode varint");s=r[i++],e+=o<28?(s&te)<<o:(s&te)*Math.pow(2,o),o+=7}while(s>=Oe);return R.bytes=i-n,e}var Ge=Math.pow(2,7),$e=Math.pow(2,14),Ve=Math.pow(2,21),Fe=Math.pow(2,28),je=Math.pow(2,35),qe=Math.pow(2,42),Re=Math.pow(2,49),Je=Math.pow(2,56),Qe=Math.pow(2,63),Ke=function(r){return r<Ge?1:r<$e?2:r<Ve?3:r<Fe?4:r<je?5:r<qe?6:r<Re?7:r<Je?8:r<Qe?9:10},Xe={encode:Pe,decode:Me,encodingLength:Ke},We=Xe,C=We;var P=(r,t=0)=>[C.decode(r,t),C.decode.bytes],z=(r,t,e=0)=>(C.encode(r,t,e),t),L=r=>C.encodingLength(r);var ie=(r,t)=>{let e=t.byteLength,n=L(r),o=n+L(e),i=new Uint8Array(o+e);return z(r,i,0),z(e,i,n),i.set(t,o),new I(r,e,t,i)},se=r=>{let t=N(r),[e,n]=P(t),[o,i]=P(t.subarray(n)),s=t.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new I(e,o,s,t)},ae=(r,t)=>{if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Y(r.bytes,e.bytes)}},I=class{constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};var ce=(r,t)=>{let{bytes:e,version:n}=r;switch(n){case 0:return _e(e,J(r),t||v.encoder);default:return er(e,J(r),t||k.encoder)}};var fe=new WeakMap,J=r=>{let t=fe.get(r);if(t==null){let e=new Map;return fe.set(r,e),e}return t},E=class r{constructor(t,e,n,o){this.code=e,this.version=t,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:t,multihash:e}=this;if(t!==S)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==rr)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}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:e}=this.multihash,n=ie(t,e);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(t){return r.equals(this,t)}static equals(t,e){let n=e;return n&&t.code===n.code&&t.version===n.version&&ae(t.multihash,n.multihash)}toString(t){return ce(this,t)}toJSON(){return{"/":ce(this)}}link(){return this}get[Symbol.toStringTag](){return"CID"}[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:i,bytes:s}=e;return new r(n,o,i,s||de(n,o,i.bytes))}else if(e[tr]===!0){let{version:n,multihash:o,code:i}=e,s=se(o);return r.create(n,i,s)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==S)throw new Error(`Version 0 CID must use dag-pb (code: ${S}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=de(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,S,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=N(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let i=o.subarray(e.multihashSize-e.digestSize),s=new I(e.multihashCode,e.digestSize,i,o);return[e.version===0?r.createV0(s):r.createV1(e.codec,s),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[T,H]=P(t.subarray(e));return e+=H,T},o=n(),i=S;if(o===18?(o=0,e=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=e,a=n(),f=n(),g=e+f,h=g-s;return{version:o,codec:i,multihashCode:a,digestSize:f,multihashSize:h,size:g}}static parse(t,e){let[n,o]=Ye(t,e),i=r.decode(o);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return J(i).set(n,t),i}},Ye=(r,t)=>{switch(r[0]){case"Q":{let e=t||v;return[v.prefix,e.decode(`${v.prefix}${r}`)]}case v.prefix:{let e=t||v;return[v.prefix,e.decode(r)]}case k.prefix:{let e=t||k;return[k.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}},_e=(r,t,e)=>{let{prefix:n}=e;if(n!==v.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let i=e.encode(r).slice(1);return t.set(n,i),i}else return o},er=(r,t,e)=>{let{prefix:n}=e,o=t.get(n);if(o==null){let i=e.encode(r);return t.set(n,i),i}else return o},S=112,rr=18,de=(r,t,e)=>{let n=L(r),o=n+L(t),i=new Uint8Array(o+e.byteLength);return z(r,i,0),z(t,i,n),i.set(e,o),i},tr=Symbol.for("@ipld/js-cid/CID");var nr=new TextDecoder;function Q(r,t){let e=0;for(let n=0;;n+=7){if(n>=64)throw new Error("protobuf: varint overflow");if(t>=r.length)throw new Error("protobuf: unexpected end of data");let o=r[t++];if(e+=n<28?(o&127)<<n:(o&127)*2**n,o<128)break}return[e,t]}function O(r,t){let e;[e,t]=Q(r,t);let n=t+e;if(e<0||n<0)throw new Error("protobuf: invalid length");if(n>r.length)throw new Error("protobuf: unexpected end of data");return[r.subarray(t,n),n]}function he(r,t){let e;return[e,t]=Q(r,t),[e&7,e>>3,t]}function or(r){let t={},e=r.length,n=0;for(;n<e;){let o,i;if([o,i,n]=he(r,n),i===1){if(t.Hash)throw new Error("protobuf: (PBLink) duplicate Hash section");if(o!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${o}) for Hash`);if(t.Name!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Name before Hash");if(t.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Hash");[t.Hash,n]=O(r,n)}else if(i===2){if(t.Name!==void 0)throw new Error("protobuf: (PBLink) duplicate Name section");if(o!==2)throw new Error(`protobuf: (PBLink) wrong wireType (${o}) for Name`);if(t.Tsize!==void 0)throw new Error("protobuf: (PBLink) invalid order, found Tsize before Name");let s;[s,n]=O(r,n),t.Name=nr.decode(s)}else if(i===3){if(t.Tsize!==void 0)throw new Error("protobuf: (PBLink) duplicate Tsize section");if(o!==0)throw new Error(`protobuf: (PBLink) wrong wireType (${o}) for Tsize`);[t.Tsize,n]=Q(r,n)}else throw new Error(`protobuf: (PBLink) invalid fieldNumber, expected 1, 2 or 3, got ${i}`)}if(n>e)throw new Error("protobuf: (PBLink) unexpected end of data");return t}function pe(r){let t=r.length,e=0,n,o=!1,i;for(;e<t;){let a,f;if([a,f,e]=he(r,e),a!==2)throw new Error(`protobuf: (PBNode) invalid wireType, expected 2, got ${a}`);if(f===1){if(i)throw new Error("protobuf: (PBNode) duplicate Data section");[i,e]=O(r,e),n&&(o=!0)}else if(f===2){if(o)throw new Error("protobuf: (PBNode) duplicate Links section");n||(n=[]);let g;[g,e]=O(r,e),n.push(or(g))}else throw new Error(`protobuf: (PBNode) invalid fieldNumber, expected 1 or 2, got ${f}`)}if(e>t)throw new Error("protobuf: (PBNode) unexpected end of data");let s={};return i&&(s.Data=i),s.Links=n||[],s}var le=new TextEncoder,ue=2**32,ir=2**31;function sr(r,t){let e=t.length;if(typeof r.Tsize=="number"){if(r.Tsize<0)throw new Error("Tsize cannot be negative");if(!Number.isSafeInteger(r.Tsize))throw new Error("Tsize too large for encoding");e=U(t,e,r.Tsize)-1,t[e]=24}if(typeof r.Name=="string"){let n=le.encode(r.Name);e-=n.length,t.set(n,e),e=U(t,e,n.length)-1,t[e]=18}return r.Hash&&(e-=r.Hash.length,t.set(r.Hash,e),e=U(t,e,r.Hash.length)-1,t[e]=10),t.length-e}function we(r){let t=cr(r),e=new Uint8Array(t),n=t;if(r.Data&&(n-=r.Data.length,e.set(r.Data,n),n=U(e,n,r.Data.length)-1,e[n]=10),r.Links)for(let o=r.Links.length-1;o>=0;o--){let i=sr(r.Links[o],e.subarray(0,n));n-=i,n=U(e,n,i)-1,e[n]=18}return e}function ar(r){let t=0;if(r.Hash){let e=r.Hash.length;t+=1+e+B(e)}if(typeof r.Name=="string"){let e=le.encode(r.Name).length;t+=1+e+B(e)}return typeof r.Tsize=="number"&&(t+=1+B(r.Tsize)),t}function cr(r){let t=0;if(r.Data){let e=r.Data.length;t+=1+e+B(e)}if(r.Links)for(let e of r.Links){let n=ar(e);t+=1+n+B(n)}return t}function U(r,t,e){t-=B(e);let n=t;for(;e>=ir;)r[t++]=e&127|128,e/=128;for(;e>=128;)r[t++]=e&127|128,e>>>=7;return r[t]=e,n}function B(r){return r%2===0&&r++,Math.floor((fr(r)+6)/7)}function fr(r){let t=0;return r>=ue&&(r=Math.floor(r/ue),t=32),r>=65536&&(r>>>=16,t+=16),r>=256&&(r>>>=8,t+=8),t+dr[r]}var dr=[0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8];var hr=["Data","Links"],pr=["Hash","Name","Tsize"],K=new TextEncoder;function be(r,t){if(r===t)return 0;let e=r.Name?K.encode(r.Name):[],n=t.Name?K.encode(t.Name):[],o=e.length,i=n.length;for(let s=0,a=Math.min(o,i);s<a;++s)if(e[s]!==n[s]){o=e[s],i=n[s];break}return o<i?-1:i<o?1:0}function me(r,t){return!Object.keys(r).some(e=>!t.includes(e))}function ye(r){if(typeof r.asCID=="object"){let e=E.asCID(r);if(!e)throw new TypeError("Invalid DAG-PB form");return{Hash:e}}if(typeof r!="object"||Array.isArray(r))throw new TypeError("Invalid DAG-PB form");let t={};if(r.Hash){let e=E.asCID(r.Hash);try{e||(typeof r.Hash=="string"?e=E.parse(r.Hash):r.Hash instanceof Uint8Array&&(e=E.decode(r.Hash)))}catch(n){throw new TypeError(`Invalid DAG-PB form: ${n.message}`)}e&&(t.Hash=e)}if(!t.Hash)throw new TypeError("Invalid DAG-PB form");return typeof r.Name=="string"&&(t.Name=r.Name),typeof r.Tsize=="number"&&(t.Tsize=r.Tsize),t}function X(r){if((r instanceof Uint8Array||typeof r=="string")&&(r={Data:r}),typeof r!="object"||Array.isArray(r))throw new TypeError("Invalid DAG-PB form");let t={};if(r.Data!==void 0)if(typeof r.Data=="string")t.Data=K.encode(r.Data);else if(r.Data instanceof Uint8Array)t.Data=r.Data;else throw new TypeError("Invalid DAG-PB form");if(r.Links!==void 0)if(Array.isArray(r.Links))t.Links=r.Links.map(ye),t.Links.sort(be);else throw new TypeError("Invalid DAG-PB form");else t.Links=[];return t}function W(r){if(!r||typeof r!="object"||Array.isArray(r)||r instanceof Uint8Array||r["/"]&&r["/"]===r.bytes)throw new TypeError("Invalid DAG-PB form");if(!me(r,hr))throw new TypeError("Invalid DAG-PB form (extraneous properties)");if(r.Data!==void 0&&!(r.Data instanceof Uint8Array))throw new TypeError("Invalid DAG-PB form (Data must be bytes)");if(!Array.isArray(r.Links))throw new TypeError("Invalid DAG-PB form (Links must be a list)");for(let t=0;t<r.Links.length;t++){let e=r.Links[t];if(!e||typeof e!="object"||Array.isArray(e)||e instanceof Uint8Array||e["/"]&&e["/"]===e.bytes)throw new TypeError("Invalid DAG-PB form (bad link)");if(!me(e,pr))throw new TypeError("Invalid DAG-PB form (extraneous properties on link)");if(e.Hash===void 0)throw new TypeError("Invalid DAG-PB form (link must have a Hash)");if(e.Hash==null||!e.Hash["/"]||e.Hash["/"]!==e.Hash.bytes)throw new TypeError("Invalid DAG-PB form (link Hash must be a CID)");if(e.Name!==void 0&&typeof e.Name!="string")throw new TypeError("Invalid DAG-PB form (link Name must be a string)");if(e.Tsize!==void 0){if(typeof e.Tsize!="number"||e.Tsize%1!==0)throw new TypeError("Invalid DAG-PB form (link Tsize must be an integer)");if(e.Tsize<0)throw new TypeError("Invalid DAG-PB form (link Tsize cannot be negative)")}if(t>0&&be(e,r.Links[t-1])===-1)throw new TypeError("Invalid DAG-PB form (links must be sorted by Name bytes)")}}function ge(r,t=[]){return X({Data:r,Links:t})}function xe(r,t,e){return ye({Hash:e,Name:r,Tsize:t})}var ur="dag-pb",lr=112;function wr(r){W(r);let t={};return r.Links&&(t.Links=r.Links.map(e=>{let n={};return e.Hash&&(n.Hash=e.Hash.bytes),e.Name!==void 0&&(n.Name=e.Name),e.Tsize!==void 0&&(n.Tsize=e.Tsize),n})),r.Data&&(t.Data=r.Data),we(t)}function mr(r){let t=pe(r),e={};return t.Data&&(e.Data=t.Data),t.Links&&(e.Links=t.Links.map(n=>{let o={};try{o.Hash=E.decode(n.Hash)}catch{}if(!o.Hash)throw new Error("Invalid Hash field found in link, expected CID");return n.Name!==void 0&&(o.Name=n.Name),n.Tsize!==void 0&&(o.Tsize=n.Tsize),o})),e}return ze(br);})(); | ||
return IpldDagPb})); |
@@ -5,10 +5,15 @@ { | ||
"ByteView": "https://ipld.github.io/js-dag-pb/types/ByteView.html", | ||
".:ByteView": "https://ipld.github.io/js-dag-pb/types/ByteView.html", | ||
"code": "https://ipld.github.io/js-dag-pb/variables/code.html", | ||
".:code": "https://ipld.github.io/js-dag-pb/variables/code.html", | ||
"name": "https://ipld.github.io/js-dag-pb/variables/name.html", | ||
".:name": "https://ipld.github.io/js-dag-pb/variables/name.html", | ||
"createLink": "https://ipld.github.io/js-dag-pb/functions/createLink.html", | ||
"createNode": "https://ipld.github.io/js-dag-pb/functions/createNode.html", | ||
"decode": "https://ipld.github.io/js-dag-pb/functions/decode.html", | ||
".:decode": "https://ipld.github.io/js-dag-pb/functions/decode.html", | ||
"encode": "https://ipld.github.io/js-dag-pb/functions/encode.html", | ||
".:encode": "https://ipld.github.io/js-dag-pb/functions/encode.html", | ||
"prepare": "https://ipld.github.io/js-dag-pb/functions/prepare.html", | ||
"validate": "https://ipld.github.io/js-dag-pb/functions/validate.html" | ||
} |
{ | ||
"name": "@ipld/dag-pb", | ||
"version": "4.0.5", | ||
"version": "4.0.6", | ||
"description": "JS implementation of DAG-PB", | ||
@@ -169,4 +169,4 @@ "author": "Rod <rod@vagg.org> (http://r.va.gg/)", | ||
"devDependencies": { | ||
"aegir": "^40.0.8" | ||
"aegir": "^41.0.0" | ||
} | ||
} |
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
53169
825