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