morphit/node_modules/interface-datastore/dist/index.min.js

4 lines
21 KiB
JavaScript

(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.InterfaceDatastore = factory()}(typeof self !== 'undefined' ? self : this, function () {
"use strict";var InterfaceDatastore=(()=>{var X=Object.defineProperty;var Re=Object.getOwnPropertyDescriptor;var Je=Object.getOwnPropertyNames;var Ge=Object.prototype.hasOwnProperty;var u=(t,e)=>{for(var r in e)X(t,r,{get:e[r],enumerable:!0})},Ke=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Je(e))!Ge.call(t,o)&&o!==r&&X(t,o,{get:()=>e[o],enumerable:!(n=Re(e,o))||n.enumerable});return t};var Xe=t=>Ke(X({},"__esModule",{value:!0}),t);var sr={};u(sr,{Key:()=>G});var Z={};u(Z,{base10:()=>et});var cr=new Uint8Array(0);function me(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function v(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")}function xe(t){return new TextEncoder().encode(t)}function ge(t){return new TextDecoder().decode(t)}function Qe(t,e){if(t.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<t.length;o++){var i=t.charAt(o),s=i.charCodeAt(0);if(r[s]!==255)throw new TypeError(i+" is ambiguous");r[s]=o}var f=t.length,d=t.charAt(0),A=Math.log(f)/Math.log(256),U=Math.log(256)/Math.log(f);function K(a){if(a instanceof Uint8Array||(ArrayBuffer.isView(a)?a=new Uint8Array(a.buffer,a.byteOffset,a.byteLength):Array.isArray(a)&&(a=Uint8Array.from(a))),!(a instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(a.length===0)return"";for(var h=0,D=0,l=0,m=a.length;l!==m&&a[l]===0;)l++,h++;for(var x=(m-l)*U+1>>>0,p=new Uint8Array(x);l!==m;){for(var g=a[l],E=0,b=x-1;(g!==0||E<D)&&b!==-1;b--,E++)g+=256*p[b]>>>0,p[b]=g%f>>>0,g=g/f>>>0;if(g!==0)throw new Error("Non-zero carry");D=E,l++}for(var y=x-D;y!==x&&p[y]===0;)y++;for(var q=d.repeat(h);y<x;++y)q+=t.charAt(p[y]);return q}function F(a){if(typeof a!="string")throw new TypeError("Expected String");if(a.length===0)return new Uint8Array;var h=0;if(a[h]!==" "){for(var D=0,l=0;a[h]===d;)D++,h++;for(var m=(a.length-h)*A+1>>>0,x=new Uint8Array(m);a[h];){var p=r[a.charCodeAt(h)];if(p===255)return;for(var g=0,E=m-1;(p!==0||g<l)&&E!==-1;E--,g++)p+=f*x[E]>>>0,x[E]=p%256>>>0,p=p/256>>>0;if(p!==0)throw new Error("Non-zero carry");l=g,h++}if(a[h]!==" "){for(var b=m-l;b!==m&&x[b]===0;)b++;for(var y=new Uint8Array(D+(m-b)),q=D;b!==m;)y[q++]=x[b++];return y}}}function ke(a){var h=F(a);if(h)return h;throw new Error(`Non-${e} character`)}return{encode:K,decodeUnsafe:F,decode:ke}}var We=Qe,He=We,ye=He;var Q=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},W=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,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(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 ve(this,e)}},H=class{decoders;constructor(e){this.decoders=e}or(e){return ve(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function ve(t,e){return new H({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var _=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Q(e,r,n),this.decoder=new W(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function I({name:t,prefix:e,encode:r,decode:n}){return new _(t,e,r,n)}function C({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=ye(r,t);return I({prefix:e,name:t,encode:n,decode:i=>v(o(i))})}function _e(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let i=new Uint8Array(o*r/8|0),s=0,f=0,d=0;for(let A=0;A<o;++A){let U=e[t[A]];if(U===void 0)throw new SyntaxError(`Non-${n} character`);f=f<<r|U,s+=r,s>=8&&(s-=8,i[d++]=255&f>>s)}if(s>=r||(255&f<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function Ze(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,i="",s=0,f=0;for(let d=0;d<t.length;++d)for(f=f<<8|t[d],s+=8;s>r;)s-=r,i+=e[o&f>>s];if(s!==0&&(i+=e[o&f<<r-s]),n)for(;(i.length*r&7)!==0;)i+="=";return i}function Ye(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function c({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=Ye(n);return I({prefix:e,name:t,encode(i){return Ze(i,n,r)},decode(i){return _e(i,o,r,t)}})}var et=C({prefix:"9",name:"base10",alphabet:"0123456789"});var Y={};u(Y,{base16:()=>tt,base16upper:()=>rt});var tt=c({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),rt=c({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ee={};u(ee,{base2:()=>nt});var nt=c({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var te={};u(te,{base256emoji:()=>ct});var Se=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}"),ot=Se.reduce((t,e,r)=>(t[r]=e,t),[]),it=Se.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function st(t){return t.reduce((e,r)=>(e+=ot[r],e),"")}function at(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=it[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var ct=I({prefix:"\u{1F680}",name:"base256emoji",encode:st,decode:at});var re={};u(re,{base32:()=>L,base32hex:()=>pt,base32hexpad:()=>lt,base32hexpadupper:()=>bt,base32hexupper:()=>dt,base32pad:()=>ht,base32padupper:()=>ut,base32upper:()=>ft,base32z:()=>mt});var L=c({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),ft=c({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),ht=c({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),ut=c({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),pt=c({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),dt=c({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),lt=c({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),bt=c({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),mt=c({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ne={};u(ne,{base36:()=>O,base36upper:()=>xt});var O=C({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),xt=C({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var oe={};u(oe,{base58btc:()=>w,base58flickr:()=>gt});var w=C({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),gt=C({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ie={};u(ie,{base64:()=>wt,base64pad:()=>yt,base64url:()=>vt,base64urlpad:()=>St});var wt=c({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),yt=c({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),vt=c({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),St=c({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var se={};u(se,{base8:()=>At});var At=c({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ae={};u(ae,{identity:()=>Et});var Et=I({prefix:"\0",name:"identity",encode:t=>ge(t),decode:t=>xe(t)});var Er=new TextEncoder,Cr=new TextDecoder;var fe={};u(fe,{identity:()=>Xt});var Ut=Ce,Ae=128,It=127,Lt=~It,zt=Math.pow(2,31);function Ce(t,e,r){e=e||[],r=r||0;for(var n=r;t>=zt;)e[r++]=t&255|Ae,t/=128;for(;t&Lt;)e[r++]=t&255|Ae,t>>>=7;return e[r]=t|0,Ce.bytes=r-n+1,e}var Nt=ce,Tt=128,Ee=127;function ce(t,n){var r=0,n=n||0,o=0,i=n,s,f=t.length;do{if(i>=f)throw ce.bytes=0,new RangeError("Could not decode varint");s=t[i++],r+=o<28?(s&Ee)<<o:(s&Ee)*Math.pow(2,o),o+=7}while(s>=Tt);return ce.bytes=i-n,r}var Mt=Math.pow(2,7),Ot=Math.pow(2,14),Bt=Math.pow(2,21),$t=Math.pow(2,28),Vt=Math.pow(2,35),Pt=Math.pow(2,42),Ft=Math.pow(2,49),qt=Math.pow(2,56),jt=Math.pow(2,63),kt=function(t){return t<Mt?1:t<Ot?2:t<Bt?3:t<$t?4:t<Vt?5:t<Pt?6:t<Ft?7:t<qt?8:t<jt?9:10},Rt={encode:Ut,decode:Nt,encodingLength:kt},Jt=Rt,B=Jt;function $(t,e=0){return[B.decode(t,e),B.decode.bytes]}function z(t,e,r=0){return B.encode(t,e,r),e}function N(t){return B.encodingLength(t)}function M(t,e){let r=e.byteLength,n=N(t),o=n+N(r),i=new Uint8Array(o+r);return z(t,i,0),z(r,i,n),i.set(e,o),new T(t,r,e,i)}function De(t){let e=v(t),[r,n]=$(e),[o,i]=$(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new T(r,o,s,e)}function Ue(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&me(t.bytes,r.bytes)}}var T=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};var Ie=0,Gt="identity",Le=v;function Kt(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return M(Ie,Le(t))}var Xt={code:Ie,name:Gt,encode:Le,digest:Kt};var pe={};u(pe,{sha256:()=>Wt,sha512:()=>Ht});var Qt=20;function ue({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new he(t,e,r,n,o)}var he=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,i){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??Qt,this.maxDigestLength=i}digest(e,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?ze(n,this.code,r?.truncate):n.then(o=>ze(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function ze(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return M(e,t)}function Te(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var Wt=ue({name:"sha2-256",code:18,encode:Te("SHA-256")}),Ht=ue({name:"sha2-512",code:19,encode:Te("SHA-512")});function Me(t,e){let{bytes:r,version:n}=t;return n===0?Zt(r,de(t),e??w.encoder):Yt(r,de(t),e??L.encoder)}var Oe=new WeakMap;function de(t){let e=Oe.get(t);if(e==null){let r=new Map;return Oe.set(t,r),r}return e}var k=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,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:e,multihash:r}=this;if(e!==P)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==er)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.createV0(r)}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:e,digest:r}=this.multihash,n=M(e,r);return t.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(e){return t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&Ue(e.multihash,n.multihash)}toString(e){return Me(this,e)}toJSON(){return{"/":Me(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:i,bytes:s}=r;return new t(n,o,i,s??Be(n,o,i.bytes))}else if(r[tr]===!0){let{version:n,multihash:o,code:i}=r,s=De(o);return t.create(n,i,s)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==P)throw new Error(`Version 0 CID must use dag-pb (code: ${P}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=Be(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,P,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,o=v(e.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=o.subarray(r.multihashSize-r.digestSize),s=new T(r.multihashCode,r.digestSize,i,o);return[r.version===0?t.createV0(s):t.createV1(r.codec,s),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[K,F]=$(e.subarray(r));return r+=F,K},o=n(),i=P;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=r,f=n(),d=n(),A=r+d,U=A-s;return{version:o,codec:i,multihashCode:f,digestSize:d,multihashSize:U,size:A}}static parse(e,r){let[n,o]=_t(e,r),i=t.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return de(i).set(n,e),i}};function _t(t,e){switch(t[0]){case"Q":{let r=e??w;return[w.prefix,r.decode(`${w.prefix}${t}`)]}case w.prefix:{let r=e??w;return[w.prefix,r.decode(t)]}case L.prefix:{let r=e??L;return[L.prefix,r.decode(t)]}case O.prefix:{let r=e??O;return[O.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function Zt(t,e,r){let{prefix:n}=r;if(n!==w.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let i=r.encode(t).slice(1);return e.set(n,i),i}else return o}function Yt(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let i=r.encode(t);return e.set(n,i),i}else return o}var P=112,er=18;function Be(t,e,r){let n=N(t),o=n+N(e),i=new Uint8Array(o+r.byteLength);return z(t,i,0),z(e,i,n),i.set(r,o),i}var tr=Symbol.for("@ipld/js-cid/CID");var le={...ae,...ee,...se,...Z,...Y,...re,...ne,...oe,...ie,...te},Xr={...pe,...fe};function $e(t=0){return new Uint8Array(t)}function Pe(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Ve=Pe("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),be=Pe("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=$e(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),rr={utf8:Ve,"utf-8":Ve,hex:le.base16,latin1:be,ascii:be,binary:be,...le},R=rr;function Fe(t,e="utf8"){let r=R[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function qe(t,e="utf8"){let r=R[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var S="/",je=new TextEncoder().encode(S),J=je[0],G=class t{_buf;constructor(e,r){if(typeof e=="string")this._buf=Fe(e);else if(e instanceof Uint8Array)this._buf=e;else throw new Error("Invalid key, should be String of Uint8Array");if(r==null&&(r=!0),r&&this.clean(),this._buf.byteLength===0||this._buf[0]!==J)throw new Error("Invalid key")}toString(e="utf8"){return qe(this._buf,e)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(e){return new t(e.join(S))}static random(){return new t(Math.random().toString().substring(2))}static asKey(e){return e instanceof Uint8Array||typeof e=="string"?new t(e):typeof e.uint8Array=="function"?new t(e.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=je),this._buf[0]!==J){let e=new Uint8Array(this._buf.byteLength+1);e.fill(J,0,1),e.set(this._buf,1),this._buf=e}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===J;)this._buf=this._buf.subarray(0,-1)}less(e){let r=this.list(),n=e.list();for(let o=0;o<r.length;o++){if(n.length<o+1)return!1;let i=r[o],s=n[o];if(i<s)return!0;if(i>s)return!1}return r.length<n.length}reverse(){return t.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let e=this.namespaces();return e[e.length-1]}list(){return this.toString().split(S).slice(1)}type(){return nr(this.baseNamespace())}name(){return or(this.baseNamespace())}instance(e){return new t(this.toString()+":"+e)}path(){let e=this.parent().toString();return e.endsWith(S)||(e+=S),e+=this.type(),new t(e)}parent(){let e=this.list();return e.length===1?new t(S):new t(e.slice(0,-1).join(S))}child(e){return this.toString()===S?e:e.toString()===S?this:new t(this.toString()+e.toString(),!1)}isAncestorOf(e){return e.toString()===this.toString()?!1:e.toString().startsWith(this.toString())}isDecendantOf(e){return e.toString()===this.toString()?!1:this.toString().startsWith(e.toString())}isTopLevel(){return this.list().length===1}concat(...e){return t.withNamespaces([...this.namespaces(),...ir(e.map(r=>r.namespaces()))])}};function nr(t){let e=t.split(":");return e.length<2?"":e.slice(0,-1).join(":")}function or(t){let e=t.split(":");return e[e.length-1]}function ir(t){return[].concat(...t)}return Xe(sr);})();
return InterfaceDatastore}));
//# sourceMappingURL=index.min.js.map