UNPKG

@helia/remote-pinning

Version:
12 lines 52.1 kB
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.HeliaRemotePinning = factory()}(typeof self !== 'undefined' ? self : this, function () { "use strict";var HeliaRemotePinning=(()=>{var Ue=Object.defineProperty;var Tr=Object.getOwnPropertyDescriptor;var Sr=Object.getOwnPropertyNames;var vr=Object.prototype.hasOwnProperty;var P=(e,t)=>{for(var r in t)Ue(e,r,{get:t[r],enumerable:!0})},Ir=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Sr(t))!vr.call(e,o)&&o!==r&&Ue(e,o,{get:()=>t[o],enumerable:!(n=Tr(t,o))||n.enumerable});return e};var Or=e=>Ir(Ue({},"__esModule",{value:!0}),e);var pi={};P(pi,{createRemotePins:()=>Cr,heliaWithRemotePins:()=>fi});var yt="https://pinning-service.example.com".replace(/\/+$/,""),Pr=e=>typeof Blob<"u"&&e instanceof Blob,te=class{constructor(t=new re){this.configuration=t,this.fetchApi=async(r,n)=>{let o={url:r,init:n};for(let s of this.middleware)s.pre&&(o=await s.pre({fetch:this.fetchApi,...o})||o);let i=await(this.configuration.fetchApi||fetch)(o.url,o.init);for(let s of this.middleware)s.post&&(i=await s.post({fetch:this.fetchApi,url:o.url,init:o.init,response:i.clone()})||i);return i},this.middleware=t.middleware}withMiddleware(...t){let r=this.clone();return r.middleware=r.middleware.concat(...t),r}withPreMiddleware(...t){let r=t.map(n=>({pre:n}));return this.withMiddleware(...r)}withPostMiddleware(...t){let r=t.map(n=>({post:n}));return this.withMiddleware(...r)}async request(t,r){let{url:n,init:o}=this.createFetchParams(t,r),i=await this.fetchApi(n,o);if(i.status>=200&&i.status<300)return i;throw i}createFetchParams(t,r){let n=this.configuration.basePath+t.path;t.query!==void 0&&Object.keys(t.query).length!==0&&(n+="?"+this.configuration.queryParamsStringify(t.query));let o=typeof FormData<"u"&&t.body instanceof FormData||t.body instanceof URLSearchParams||Pr(t.body)?t.body:JSON.stringify(t.body),i=Object.assign({},this.configuration.headers,t.headers),s={method:t.method,headers:i,body:o,credentials:this.configuration.credentials,...r};return{url:n,init:s}}clone(){let t=this.constructor,r=new t(this.configuration);return r.middleware=this.middleware.slice(),r}},U=class extends Error{constructor(t,r){super(r),this.field=t,this.name="RequiredError"}},xe={csv:",",ssv:" ",tsv:" ",pipes:"|"},re=class{constructor(t={}){this.configuration=t}get basePath(){return this.configuration.basePath!=null?this.configuration.basePath:yt}get fetchApi(){return this.configuration.fetchApi}get middleware(){return this.configuration.middleware||[]}get queryParamsStringify(){return this.configuration.queryParamsStringify||_e}get username(){return this.configuration.username}get password(){return this.configuration.password}get apiKey(){let t=this.configuration.apiKey;if(t)return typeof t=="function"?t:()=>t}get accessToken(){let t=this.configuration.accessToken;if(t)return typeof t=="function"?t:async()=>t}get headers(){return this.configuration.headers}get credentials(){return this.configuration.credentials}};function q(e,t){let r=e[t];return r!=null}function _e(e,t=""){return Object.keys(e).map(r=>{let n=t+(t.length?`[${r}]`:r),o=e[r];if(o instanceof Array){let i=o.map(s=>encodeURIComponent(String(s))).join(`&${encodeURIComponent(n)}=`);return`${encodeURIComponent(n)}=${i}`}return o instanceof Date?`${encodeURIComponent(n)}=${encodeURIComponent(o.toISOString())}`:o instanceof Object?_e(o,n):`${encodeURIComponent(n)}=${encodeURIComponent(String(o))}`}).filter(r=>r.length>0).join("&")}var B=class{constructor(t,r=n=>n){this.raw=t,this.transformer=r}async value(){return this.transformer(await this.raw.json())}},ne=class{constructor(t){this.raw=t}async value(){}};function Ct(e){return Fr(e,!1)}function Fr(e,t){return e==null?e:{cid:e.cid,name:q(e,"name")?e.name:void 0,origins:q(e,"origins")?e.origins:void 0,meta:q(e,"meta")?e.meta:void 0}}function we(e){if(e!==void 0)return e===null?null:{cid:e.cid,name:e.name,origins:e.origins,meta:e.meta}}var oe;(function(e){e.Queued="queued",e.Pinning="pinning",e.Pinned="pinned",e.Failed="failed"})(oe||(oe={}));function Et(e){return Ar(e,!1)}function Ar(e,t){return e}function W(e){return Nr(e,!1)}function Nr(e,t){return e==null?e:{requestid:e.requestid,status:Et(e.status),created:new Date(e.created),pin:Ct(e.pin),delegates:e.delegates,info:q(e,"info")?e.info:void 0}}function Tt(e){return Rr(e,!1)}function Rr(e,t){return e==null?e:{count:e.count,results:e.results.map(W)}}var St;(function(e){e.Exact="exact",e.Iexact="iexact",e.Partial="partial",e.Ipartial="ipartial"})(St||(St={}));var ie=class extends te{async pinsGetRaw(t,r){let n={};t.cid&&(n.cid=t.cid.join(xe.csv)),t.name!==void 0&&(n.name=t.name),t.match!==void 0&&(n.match=t.match),t.status&&(n.status=t.status.join(xe.csv)),t.before!==void 0&&(n.before=t.before.toISOString()),t.after!==void 0&&(n.after=t.after.toISOString()),t.limit!==void 0&&(n.limit=t.limit),t.meta!==void 0&&(n.meta=t.meta);let o={};if(this.configuration&&this.configuration.accessToken){let s=this.configuration.accessToken,a=await s("accessToken",[]);a&&(o.Authorization=`Bearer ${a}`)}let i=await this.request({path:"/pins",method:"GET",headers:o,query:n},r);return new B(i,s=>Tt(s))}async pinsGet(t={},r){return await(await this.pinsGetRaw(t,r)).value()}async pinsPostRaw(t,r){if(t.pin===null||t.pin===void 0)throw new U("pin","Required parameter requestParameters.pin was null or undefined when calling pinsPost.");let n={},o={};if(o["Content-Type"]="application/json",this.configuration&&this.configuration.accessToken){let s=this.configuration.accessToken,a=await s("accessToken",[]);a&&(o.Authorization=`Bearer ${a}`)}let i=await this.request({path:"/pins",method:"POST",headers:o,query:n,body:we(t.pin)},r);return new B(i,s=>W(s))}async pinsPost(t,r){return await(await this.pinsPostRaw(t,r)).value()}async pinsRequestidDeleteRaw(t,r){if(t.requestid===null||t.requestid===void 0)throw new U("requestid","Required parameter requestParameters.requestid was null or undefined when calling pinsRequestidDelete.");let n={},o={};if(this.configuration&&this.configuration.accessToken){let s=this.configuration.accessToken,a=await s("accessToken",[]);a&&(o.Authorization=`Bearer ${a}`)}let i=await this.request({path:"/pins/{requestid}".replace("{requestid}",encodeURIComponent(String(t.requestid))),method:"DELETE",headers:o,query:n},r);return new ne(i)}async pinsRequestidDelete(t,r){await this.pinsRequestidDeleteRaw(t,r)}async pinsRequestidGetRaw(t,r){if(t.requestid===null||t.requestid===void 0)throw new U("requestid","Required parameter requestParameters.requestid was null or undefined when calling pinsRequestidGet.");let n={},o={};if(this.configuration&&this.configuration.accessToken){let s=this.configuration.accessToken,a=await s("accessToken",[]);a&&(o.Authorization=`Bearer ${a}`)}let i=await this.request({path:"/pins/{requestid}".replace("{requestid}",encodeURIComponent(String(t.requestid))),method:"GET",headers:o,query:n},r);return new B(i,s=>W(s))}async pinsRequestidGet(t,r){return await(await this.pinsRequestidGetRaw(t,r)).value()}async pinsRequestidPostRaw(t,r){if(t.requestid===null||t.requestid===void 0)throw new U("requestid","Required parameter requestParameters.requestid was null or undefined when calling pinsRequestidPost.");if(t.pin===null||t.pin===void 0)throw new U("pin","Required parameter requestParameters.pin was null or undefined when calling pinsRequestidPost.");let n={},o={};if(o["Content-Type"]="application/json",this.configuration&&this.configuration.accessToken){let s=this.configuration.accessToken,a=await s("accessToken",[]);a&&(o.Authorization=`Bearer ${a}`)}let i=await this.request({path:"/pins/{requestid}".replace("{requestid}",encodeURIComponent(String(t.requestid))),method:"POST",headers:o,query:n,body:we(t.pin)},r);return new B(i,s=>W(s))}async pinsRequestidPost(t,r){return await(await this.pinsRequestidPostRaw(t,r)).value()}};var be=class extends re{constructor(t){let r={...t};t.fetchApi==null&&(r.fetchApi=fetch),t.endpointUrl!=null&&(r.basePath=t.endpointUrl),super(r)}};var ye=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}};var H=class extends Error{static name="NotFoundError";constructor(t="Not found"){super(t),this.name="NotFoundError"}};var qe={};P(qe,{base32:()=>A,base32hex:()=>Vr,base32hexpad:()=>Gr,base32hexpadupper:()=>Wr,base32hexupper:()=>Jr,base32pad:()=>zr,base32padupper:()=>kr,base32upper:()=>qr,base32z:()=>Hr});var is=new Uint8Array(0);function vt(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function _(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function It(e){return new TextEncoder().encode(e)}function Ot(e){return new TextDecoder().decode(e)}function Ur(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var i=e.charAt(o),s=i.charCodeAt(0);if(r[s]!==255)throw new TypeError(i+" is ambiguous");r[s]=o}var a=e.length,d=e.charAt(0),f=Math.log(a)/Math.log(256),c=Math.log(256)/Math.log(a);function u(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var y=0,x=0,m=0,w=p.length;m!==w&&p[m]===0;)m++,y++;for(var T=(w-m)*c+1>>>0,I=new Uint8Array(T);m!==w;){for(var S=p[m],R=0,v=T-1;(S!==0||R<x)&&v!==-1;v--,R++)S+=256*I[v]>>>0,I[v]=S%a>>>0,S=S/a>>>0;if(S!==0)throw new Error("Non-zero carry");x=R,m++}for(var F=T-x;F!==T&&I[F]===0;)F++;for(var k=d.repeat(y);F<T;++F)k+=e.charAt(I[F]);return k}function l(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var y=0;if(p[y]!==" "){for(var x=0,m=0;p[y]===d;)x++,y++;for(var w=(p.length-y)*f+1>>>0,T=new Uint8Array(w);p[y];){var I=r[p.charCodeAt(y)];if(I===255)return;for(var S=0,R=w-1;(I!==0||S<m)&&R!==-1;R--,S++)I+=a*T[R]>>>0,T[R]=I%256>>>0,I=I/256>>>0;if(I!==0)throw new Error("Non-zero carry");m=S,y++}if(p[y]!==" "){for(var v=w-m;v!==w&&T[v]===0;)v++;for(var F=new Uint8Array(x+(w-v)),k=x;v!==w;)F[k++]=T[v++];return F}}}function N(p){var y=l(p);if(y)return y;throw new Error(`Non-${t} character`)}return{encode:u,decodeUnsafe:l,decode:N}}var _r=Ur,$r=_r,Dt=$r;var $e=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Me=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Ft(this,t)}},Le=class{decoders;constructor(t){this.decoders=t}or(t){return Ft(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Ft(e,t){return new Le({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var Be=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new $e(t,r,n),this.decoder=new Me(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function X({name:e,prefix:t,encode:r,decode:n}){return new Be(e,t,r,n)}function z({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Dt(r,e);return X({prefix:t,name:e,encode:n,decode:i=>_(o(i))})}function Mr(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let i=new Uint8Array(o*r/8|0),s=0,a=0,d=0;for(let f=0;f<o;++f){let c=t[e[f]];if(c===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|c,s+=r,s>=8&&(s-=8,i[d++]=255&a>>s)}if(s>=r||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function Lr(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,i="",s=0,a=0;for(let d=0;d<e.length;++d)for(a=a<<8|e[d],s+=8;s>r;)s-=r,i+=t[o&a>>s];if(s!==0&&(i+=t[o&a<<r-s]),n)for(;(i.length*r&7)!==0;)i+="=";return i}function Br(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function g({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=Br(n);return X({prefix:t,name:e,encode(i){return Lr(i,n,r)},decode(i){return Mr(i,o,r,e)}})}var A=g({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),qr=g({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),zr=g({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),kr=g({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Vr=g({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Jr=g({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Gr=g({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Wr=g({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Hr=g({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ze={};P(ze,{base58btc:()=>D,base58flickr:()=>Xr});var D=z({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Xr=z({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Je={};P(Je,{base64:()=>ke,base64pad:()=>jr,base64url:()=>Ve,base64urlpad:()=>Kr});var ke=g({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),jr=g({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ve=g({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Kr=g({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});function Qr(e,t){if(typeof e=="string")return Zr(e);if(typeof e=="number")return tn(e,t);throw Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(e)}`)}var Ce=Qr;function Zr(e){if(typeof e!="string"||e.length===0||e.length>100)throw Error(`Value provided to ms.parse() must be a string with length between 1 and 99. value=${JSON.stringify(e)}`);let t=/^(?<value>-?\d*\.?\d+) *(?<unit>milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.exec(e);if(!t?.groups)return NaN;let{value:r,unit:n="ms"}=t.groups,o=parseFloat(r),i=n.toLowerCase();switch(i){case"years":case"year":case"yrs":case"yr":case"y":return o*315576e5;case"months":case"month":case"mo":return o*26298e5;case"weeks":case"week":case"w":return o*6048e5;case"days":case"day":case"d":return o*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return o*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return o*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return o*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return o;default:throw Error(`Unknown unit "${i}" provided to ms.parse(). value=${JSON.stringify(e)}`)}}function Yr(e){let t=Math.abs(e);return t>=315576e5?`${Math.round(e/315576e5)}y`:t>=26298e5?`${Math.round(e/26298e5)}mo`:t>=6048e5?`${Math.round(e/6048e5)}w`:t>=864e5?`${Math.round(e/864e5)}d`:t>=36e5?`${Math.round(e/36e5)}h`:t>=6e4?`${Math.round(e/6e4)}m`:t>=1e3?`${Math.round(e/1e3)}s`:`${e}ms`}function en(e){let t=Math.abs(e);return t>=315576e5?V(e,t,315576e5,"year"):t>=26298e5?V(e,t,26298e5,"month"):t>=6048e5?V(e,t,6048e5,"week"):t>=864e5?V(e,t,864e5,"day"):t>=36e5?V(e,t,36e5,"hour"):t>=6e4?V(e,t,6e4,"minute"):t>=1e3?V(e,t,1e3,"second"):`${e} ms`}function tn(e,t){if(typeof e!="number"||!Number.isFinite(e))throw Error("Value provided to ms.format() must be of type number.");return t?.long?en(e):Yr(e)}function V(e,t,r,n){let o=t>=r*1.5;return`${Math.round(e/r)} ${n}${o?"s":""}`}function Ge(e){r.debug=r,r.default=r,r.coerce=d,r.disable=i,r.enable=o,r.enabled=s,r.humanize=Ce,r.destroy=f,Object.keys(e).forEach(c=>{r[c]=e[c]}),r.names=[],r.skips=[],r.formatters={};function t(c){let u=0;for(let l=0;l<c.length;l++)u=(u<<5)-u+c.charCodeAt(l),u|=0;return r.colors[Math.abs(u)%r.colors.length]}r.selectColor=t;function r(c,u){let l,N=null,p,y;function x(...m){if(!x.enabled)return;let w=x,T=Number(new Date),I=T-(l||T);w.diff=I,w.prev=l,w.curr=T,l=T,m[0]=r.coerce(m[0]),typeof m[0]!="string"&&m.unshift("%O");let S=0;m[0]=m[0].replace(/%([a-zA-Z%])/g,(v,F)=>{if(v==="%%")return"%";S++;let k=r.formatters[F];if(typeof k=="function"){let Er=m[S];v=k.call(w,Er),m.splice(S,1),S--}return v}),r.formatArgs.call(w,m),u?.onLog!=null&&u.onLog(...m),(w.log||r.log).apply(w,m)}return x.namespace=c,x.useColors=r.useColors(),x.color=r.selectColor(c),x.extend=n,x.destroy=r.destroy,Object.defineProperty(x,"enabled",{enumerable:!0,configurable:!1,get:()=>N!==null?N:(p!==r.namespaces&&(p=r.namespaces,y=r.enabled(c)),y),set:m=>{N=m}}),typeof r.init=="function"&&r.init(x),x}function n(c,u){let l=r(this.namespace+(typeof u>"u"?":":u)+c);return l.log=this.log,l}function o(c){r.save(c),r.namespaces=c,r.names=[],r.skips=[];let u,l=(typeof c=="string"?c:"").split(/[\s,]+/),N=l.length;for(u=0;u<N;u++)l[u]&&(c=l[u].replace(/\*/g,".*?"),c[0]==="-"?r.skips.push(new RegExp("^"+c.substr(1)+"$")):r.names.push(new RegExp("^"+c+"$")))}function i(){let c=[...r.names.map(a),...r.skips.map(a).map(u=>"-"+u)].join(",");return r.enable(""),c}function s(c){if(c[c.length-1]==="*")return!0;let u,l;for(u=0,l=r.skips.length;u<l;u++)if(r.skips[u].test(c))return!1;for(u=0,l=r.names.length;u<l;u++)if(r.names[u].test(c))return!0;return!1}function a(c){return c.toString().substring(2,c.toString().length-2).replace(/\.\*\?$/,"*")}function d(c){return c instanceof Error?c.stack??c.message:c}function f(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return r.setupFormatters(r.formatters),r.enable(r.load()),r}var Ee=un(),rn=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function nn(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/(edge|trident)\/(\d+)/)!=null?!1:typeof document<"u"&&document.documentElement?.style?.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/firefox\/(\d+)/)!=null&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/applewebkit\/(\d+)/)}function on(e){if(e[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+e[0]+(this.useColors?"%c ":" ")+"+"+Ce(this.diff),!this.useColors)return;let t="color: "+this.color;e.splice(1,0,t,"color: inherit");let r=0,n=0;e[0].replace(/%[a-zA-Z%]/g,o=>{o!=="%%"&&(r++,o==="%c"&&(n=r))}),e.splice(n,0,t)}var sn=console.debug??console.log??(()=>{});function an(e){try{e?Ee?.setItem("debug",e):Ee?.removeItem("debug")}catch{}}function cn(){let e;try{e=Ee?.getItem("debug")}catch{}return!e&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(e=globalThis.process.env.DEBUG),e}function un(){try{return localStorage}catch{}}function dn(e){e.j=function(t){try{return JSON.stringify(t)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var At=Ge({formatArgs:on,save:an,load:cn,useColors:nn,setupFormatters:dn,colors:rn,storage:Ee,log:sn});var O=At;O.formatters.b=e=>e==null?"undefined":D.baseEncode(e);O.formatters.t=e=>e==null?"undefined":A.baseEncode(e);O.formatters.m=e=>e==null?"undefined":ke.baseEncode(e);O.formatters.p=e=>e==null?"undefined":e.toString();O.formatters.c=e=>e==null?"undefined":e.toString();O.formatters.k=e=>e==null?"undefined":e.toString();O.formatters.a=e=>e==null?"undefined":e.toString();function Nt(e,t=""){let r=Rt(e.message),n=Rt(e.stack);return r!=null&&n!=null?n.includes(r)?`${n.split(` `).join(` ${t}`)}`:`${r} ${t}${n.split(` `).join(` ${t}`)}`:n!=null?`${n.split(` `).join(` ${t}`)}`:r!=null?`${r}`:`${e.toString()}`}function ln(e){return e instanceof AggregateError||e?.name==="AggregateError"&&Array.isArray(e.errors)}function Ut(e,t=""){if(ln(e)){let r=Nt(e,t);return e.errors.length>0?(t=`${t} `,r+=` ${t}${e.errors.map(n=>`${Ut(n,`${t}`)}`).join(` ${t}`)}`):r+=` ${t}[Error list was empty]`,r.trim()}return Nt(e,t)}O.formatters.e=e=>e==null?"undefined":Ut(e);function fn(e){let t=()=>{};return t.enabled=!1,t.color="",t.diff=0,t.log=()=>{},t.namespace=e,t.destroy=()=>!0,t.extend=()=>t,t}function We(e,t){let r=fn(`${e}:trace`);return O.enabled(`${e}:trace`)&&O.names.map(n=>n.toString()).find(n=>n.includes(":trace"))!=null&&(r=O(`${e}:trace`,t)),Object.assign(O(e,t),{error:O(`${e}:error`,t),trace:r,newScope:n=>We(`${e}:${n}`,t)})}function Rt(e){if(e!=null&&(e=e.trim(),e.length!==0))return e}function _t(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function se(e=0){return new Uint8Array(e)}var pn=Math.pow(2,7),mn=Math.pow(2,14),hn=Math.pow(2,21),He=Math.pow(2,28),Xe=Math.pow(2,35),je=Math.pow(2,42),Ke=Math.pow(2,49),h=128,E=127;function j(e){if(e<pn)return 1;if(e<mn)return 2;if(e<hn)return 3;if(e<He)return 4;if(e<Xe)return 5;if(e<je)return 6;if(e<Ke)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Qe(e,t,r=0){switch(j(e)){case 8:t[r++]=e&255|h,e/=128;case 7:t[r++]=e&255|h,e/=128;case 6:t[r++]=e&255|h,e/=128;case 5:t[r++]=e&255|h,e/=128;case 4:t[r++]=e&255|h,e>>>=7;case 3:t[r++]=e&255|h,e>>>=7;case 2:t[r++]=e&255|h,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function gn(e,t){let r=e[t],n=0;if(n+=r&E,r<h||(r=e[t+1],n+=(r&E)<<7,r<h)||(r=e[t+2],n+=(r&E)<<14,r<h)||(r=e[t+3],n+=(r&E)<<21,r<h)||(r=e[t+4],n+=(r&E)*He,r<h)||(r=e[t+5],n+=(r&E)*Xe,r<h)||(r=e[t+6],n+=(r&E)*je,r<h)||(r=e[t+7],n+=(r&E)*Ke,r<h))return n;throw new RangeError("Could not decode varint")}function xn(e,t){let r=e.get(t),n=0;if(n+=r&E,r<h||(r=e.get(t+1),n+=(r&E)<<7,r<h)||(r=e.get(t+2),n+=(r&E)<<14,r<h)||(r=e.get(t+3),n+=(r&E)<<21,r<h)||(r=e.get(t+4),n+=(r&E)*He,r<h)||(r=e.get(t+5),n+=(r&E)*Xe,r<h)||(r=e.get(t+6),n+=(r&E)*je,r<h)||(r=e.get(t+7),n+=(r&E)*Ke,r<h))return n;throw new RangeError("Could not decode varint")}function Ze(e,t=0){return e instanceof Uint8Array?gn(e,t):xn(e,t)}function ae(e,t){t==null&&(t=e.reduce((o,i)=>o+i.length,0));let r=se(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var Ye={};P(Ye,{base10:()=>bn});var bn=z({prefix:"9",name:"base10",alphabet:"0123456789"});var et={};P(et,{base16:()=>yn,base16upper:()=>Cn});var yn=g({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Cn=g({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var tt={};P(tt,{base2:()=>En});var En=g({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var rt={};P(rt,{base256emoji:()=>On});var $t=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}"),Tn=$t.reduce((e,t,r)=>(e[r]=t,e),[]),Sn=$t.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function vn(e){return e.reduce((t,r)=>(t+=Tn[r],t),"")}function In(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Sn[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var On=X({prefix:"\u{1F680}",name:"base256emoji",encode:vn,decode:In});var nt={};P(nt,{base36:()=>ce,base36upper:()=>Pn});var ce=z({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Pn=z({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ot={};P(ot,{base8:()=>Dn});var Dn=g({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var it={};P(it,{identity:()=>Fn});var Fn=X({prefix:"\0",name:"identity",encode:e=>Ot(e),decode:e=>It(e)});var ks=new TextEncoder,Vs=new TextDecoder;var at={};P(at,{identity:()=>Yn});var Rn=Bt,Mt=128,Un=127,_n=~Un,$n=Math.pow(2,31);function Bt(e,t,r){t=t||[],r=r||0;for(var n=r;e>=$n;)t[r++]=e&255|Mt,e/=128;for(;e&_n;)t[r++]=e&255|Mt,e>>>=7;return t[r]=e|0,Bt.bytes=r-n+1,t}var Mn=st,Ln=128,Lt=127;function st(e,n){var r=0,n=n||0,o=0,i=n,s,a=e.length;do{if(i>=a)throw st.bytes=0,new RangeError("Could not decode varint");s=e[i++],r+=o<28?(s&Lt)<<o:(s&Lt)*Math.pow(2,o),o+=7}while(s>=Ln);return st.bytes=i-n,r}var Bn=Math.pow(2,7),qn=Math.pow(2,14),zn=Math.pow(2,21),kn=Math.pow(2,28),Vn=Math.pow(2,35),Jn=Math.pow(2,42),Gn=Math.pow(2,49),Wn=Math.pow(2,56),Hn=Math.pow(2,63),Xn=function(e){return e<Bn?1:e<qn?2:e<zn?3:e<kn?4:e<Vn?5:e<Jn?6:e<Gn?7:e<Wn?8:e<Hn?9:10},jn={encode:Rn,decode:Mn,encodingLength:Xn},Kn=jn,ue=Kn;function de(e,t=0){return[ue.decode(e,t),ue.decode.bytes]}function K(e,t,r=0){return ue.encode(e,t,r),t}function Q(e){return ue.encodingLength(e)}function Y(e,t){let r=t.byteLength,n=Q(e),o=n+Q(r),i=new Uint8Array(o+r);return K(e,i,0),K(r,i,n),i.set(t,o),new Z(e,r,t,i)}function qt(e){let t=_(e),[r,n]=de(t),[o,i]=de(t.subarray(n)),s=t.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Z(r,o,s,t)}function zt(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&vt(e.bytes,r.bytes)}}var Z=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};var kt=0,Qn="identity",Vt=_;function Zn(e,t){if(t?.truncate!=null&&t.truncate!==e.byteLength){if(t.truncate<0||t.truncate>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,t.truncate)}return Y(kt,Vt(e))}var Yn={code:kt,name:Qn,encode:Vt,digest:Zn};var dt={};P(dt,{sha256:()=>to,sha512:()=>ro});var eo=20;function ut({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new ct(e,t,r,n,o)}var ct=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,i){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??eo,this.maxDigestLength=i}digest(t,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(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?Jt(n,this.code,r?.truncate):n.then(o=>Jt(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Jt(e,t,r){if(r!=null&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return Y(t,e)}function Wt(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var to=ut({name:"sha2-256",code:18,encode:Wt("SHA-256")}),ro=ut({name:"sha2-512",code:19,encode:Wt("SHA-512")});function Ht(e,t){let{bytes:r,version:n}=e;return n===0?oo(r,lt(e),t??D.encoder):io(r,lt(e),t??A.encoder)}var Xt=new WeakMap;function lt(e){let t=Xt.get(e);if(t==null){let r=new Map;return Xt.set(e,r),r}return t}var $=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,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:r}=this;if(t!==fe)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==so)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.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:t,digest:r}=this.multihash,n=Y(t,r);return e.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 e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&zt(t.multihash,n.multihash)}toString(t){return Ht(this,t)}toJSON(){return{"/":Ht(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:i,bytes:s}=r;return new e(n,o,i,s??jt(n,o,i.bytes))}else if(r[ao]===!0){let{version:n,multihash:o,code:i}=r,s=qt(o);return e.create(n,i,s)}else return null}static create(t,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(t){case 0:{if(r!==fe)throw new Error(`Version 0 CID must use dag-pb (code: ${fe}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=jt(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,fe,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=_(t.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 Z(r.multihashCode,r.digestSize,i,o);return[r.version===0?e.createV0(s):e.createV1(r.codec,s),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[u,l]=de(t.subarray(r));return r+=l,u},o=n(),i=fe;if(o===18?(o=0,r=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=r,a=n(),d=n(),f=r+d,c=f-s;return{version:o,codec:i,multihashCode:a,digestSize:d,multihashSize:c,size:f}}static parse(t,r){let[n,o]=no(t,r),i=e.decode(o);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return lt(i).set(n,t),i}};function no(e,t){switch(e[0]){case"Q":{let r=t??D;return[D.prefix,r.decode(`${D.prefix}${e}`)]}case D.prefix:{let r=t??D;return[D.prefix,r.decode(e)]}case A.prefix:{let r=t??A;return[A.prefix,r.decode(e)]}case ce.prefix:{let r=t??ce;return[ce.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function oo(e,t,r){let{prefix:n}=r;if(n!==D.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let i=r.encode(e).slice(1);return t.set(n,i),i}else return o}function io(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let i=r.encode(e);return t.set(n,i),i}else return o}var fe=112,so=18;function jt(e,t,r){let n=Q(e),o=n+Q(t),i=new Uint8Array(o+r.byteLength);return K(e,i,0),K(t,i,n),i.set(r,o),i}var ao=Symbol.for("@ipld/js-cid/CID");var pe={...it,...tt,...ot,...Ye,...et,...qe,...nt,...ze,...Je,...rt},la={...dt,...at};function Qt(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Kt=Qt("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),ft=Qt("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=se(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),co={utf8:Kt,"utf-8":Kt,hex:pe.base16,latin1:ft,ascii:ft,binary:ft,...pe},Se=co;function me(e,t="utf8"){let r=Se[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function J(e,t="utf8"){let r=Se[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var C=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},M=class extends Error{static name="ValidationError";name="ValidationError"},ve=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Ie=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var Oe=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let r=this.index,n=t();return n===void 0&&(this.index=r),n}parseWith(t){let r=t();if(this.index===this.input.length)return r}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let r=this.readChar();if(r===t)return r})}readSeparator(t,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,r,n,o){return this.readAtomically(()=>{let i=0,s=0,a=this.peekChar();if(a===void 0)return;let d=a==="0",f=2**(8*o)-1;for(;;){let c=this.readAtomically(()=>{let u=this.readChar();if(u===void 0)return;let l=Number.parseInt(u,t);if(!Number.isNaN(l))return l});if(c===void 0)break;if(i*=t,i+=c,i>f||(s+=1,r!==void 0&&s>r))return}if(s!==0)return!n&&d&&s>1?void 0:i})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let r=0;r<t.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[r]=n}return t})}readIPv6Addr(){let t=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let s=this.readSeparator(":",n,()=>this.readIPv4Addr());if(s!==void 0)return r[o]=s[0],r[o+1]=s[1],r[o+2]=s[2],r[o+3]=s[3],[o+4,!0]}let i=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(i===void 0)return[o,!1];r[o]=i>>8,r[o+1]=i&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=t(r);if(n===16)return r;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let i=new Uint8Array(14),s=16-(n+2),[a]=t(i.subarray(0,s));return r.set(i.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var uo=45,lo=15,Pe=new Oe;function Zt(e){if(!(e.length>lo))return Pe.new(e).parseWith(()=>Pe.readIPv4Addr())}function Yt(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>uo))return Pe.new(e).parseWith(()=>Pe.readIPv6Addr())}function De(e){return!!Zt(e)}function er(e){return!!Yt(e)}function mt(e){return t=>J(t,e)}function ht(e){return t=>me(t,e)}function ee(e){return new DataView(e.buffer).getUint16(e.byteOffset).toString()}function G(e){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof e=="string"?parseInt(e):e),new Uint8Array(t)}function tr(e){let t=e.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let r=me(t[0],"base32"),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=G(n);return ae([r,o],r.length+o.length)}function rr(e){let t=e.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let r=A.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=G(n);return ae([r,o],r.length+o.length)}function gt(e){let t=e.subarray(0,e.length-2),r=e.subarray(e.length-2),n=J(t,"base32"),o=ee(r);return`${n}:${o}`}var xt=function(e){e=e.toString().trim();let t=new Uint8Array(4);return e.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new C("Invalid byte value in IP address");t[n]=o}),t},nr=function(e){let t=0;e=e.toString().trim();let r=e.split(":",8),n;for(n=0;n<r.length;n++){let i=De(r[n]),s;i&&(s=xt(r[n]),r[n]=J(s.subarray(0,2),"base16")),s!=null&&++n<8&&r.splice(n,0,J(s.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let i=[n,1];for(n=9-r.length;n>0;n--)i.push("0");r.splice.apply(r,i)}let o=new Uint8Array(t+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let i=parseInt(r[n],16);if(isNaN(i)||i<0||i>65535)throw new C("Invalid byte value in IP address");o[t++]=i>>8&255,o[t++]=i&255}return o},or=function(e){if(e.byteLength!==4)throw new C("IPv4 address was incorrect length");let t=[];for(let r=0;r<e.byteLength;r++)t.push(e[r]);return t.join(".")},ir=function(e){if(e.byteLength!==16)throw new C("IPv6 address was incorrect length");let t=[];for(let n=0;n<e.byteLength;n+=2){let o=e[n],i=e[n+1],s=`${o.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}`;t.push(s)}let r=t.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new C(`Invalid IPv6 address "${r}"`)}};function sr(e){try{let t=new URL(`http://[${e}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new C(`Invalid IPv6 address "${e}"`)}}var pt=Object.values(pe).map(e=>e.decoder),fo=(function(){let e=pt[0].or(pt[1]);return pt.slice(2).forEach(t=>e=e.or(t)),e})();function ar(e){return fo.decode(e)}function cr(e){return t=>e.encoder.encode(t)}function po(e){if(parseInt(e).toString()!==e)throw new M("Value must be an integer")}function mo(e){if(e<0)throw new M("Value must be a positive integer, or zero")}function ho(e){return t=>{if(t>e)throw new M(`Value must be smaller than or equal to ${e}`)}}function go(...e){return t=>{for(let r of e)r(t)}}var he=go(po,mo,ho(65535));var b=-1,wt=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(t){let r;if(typeof t=="string"?r=this.protocolsByName.get(t):r=this.protocolsByCode.get(t),r==null)throw new Ie(`Protocol ${t} was unknown`);return r}addProtocol(t){this.protocolsByCode.set(t.code,t),this.protocolsByName.set(t.name,t),t.aliases?.forEach(r=>{this.protocolsByName.set(r,t)})}removeProtocol(t){let r=this.protocolsByCode.get(t);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},L=new wt,ni=[{code:4,name:"ip4",size:32,valueToBytes:xt,bytesToValue:or,validate:e=>{if(!De(e))throw new M(`Invalid IPv4 address "${e}"`)}},{code:6,name:"tcp",size:16,valueToBytes:G,bytesToValue:ee,validate:he},{code:273,name:"udp",size:16,valueToBytes:G,bytesToValue:ee,validate:he},{code:33,name:"dccp",size:16,valueToBytes:G,bytesToValue:ee,validate:he},{code:41,name:"ip6",size:128,valueToBytes:nr,bytesToValue:ir,stringToValue:sr,validate:e=>{if(!er(e))throw new M(`Invalid IPv6 address "${e}"`)}},{code:42,name:"ip6zone",size:b},{code:43,name:"ipcidr",size:8,bytesToValue:mt("base10"),valueToBytes:ht("base10")},{code:53,name:"dns",size:b},{code:54,name:"dns4",size:b},{code:55,name:"dns6",size:b},{code:56,name:"dnsaddr",size:b},{code:132,name:"sctp",size:16,valueToBytes:G,bytesToValue:ee,validate:he},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:b,stringToValue:e=>decodeURIComponent(e),valueToString:e=>encodeURIComponent(e)},{code:421,name:"p2p",aliases:["ipfs"],size:b,bytesToValue:mt("base58btc"),valueToBytes:e=>e.startsWith("Q")||e.startsWith("1")?ht("base58btc")(e):$.parse(e).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:gt,valueToBytes:tr},{code:445,name:"onion3",size:296,bytesToValue:gt,valueToBytes:rr},{code:446,name:"garlic64",size:b},{code:447,name:"garlic32",size:b},{code:448,name:"tls"},{code:449,name:"sni",size:b},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:b,bytesToValue:cr(Ve),valueToBytes:ar},{code:480,name:"http"},{code:481,name:"http-path",size:b,stringToValue:e=>`/${decodeURIComponent(e)}`,valueToString:e=>encodeURIComponent(e.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:b}];ni.forEach(e=>{L.addProtocol(e)});function ur(e){let t=[],r=0;for(;r<e.length;){let n=Ze(e,r),o=L.getProtocol(n),i=j(n),s=oi(o,e,r+i),a=0;s>0&&o.size===b&&(a=j(s));let d=i+a+s,f={code:n,name:o.name,bytes:e.subarray(r,r+d)};if(s>0){let c=r+i+a,u=e.subarray(c,c+s);f.value=o.bytesToValue?.(u)??J(u)}t.push(f),r+=d}return t}function dr(e){let t=0,r=[];for(let n of e){if(n.bytes==null){let o=L.getProtocol(n.code),i=j(n.code),s,a=0,d=0;n.value!=null&&(s=o.valueToBytes?.(n.value)??me(n.value),a=s.byteLength,o.size===b&&(d=j(a)));let f=new Uint8Array(i+d+a),c=0;Qe(n.code,f,c),c+=i,s!=null&&(o.size===b&&(Qe(a,f,c),c+=d),f.set(s,c)),n.bytes=f}r.push(n.bytes),t+=n.bytes.byteLength}return ae(r,t)}function lr(e){if(e.charAt(0)!=="/")throw new C('String multiaddr must start with "/"');let t=[],r="protocol",n="",o="";for(let i=1;i<e.length;i++){let s=e.charAt(i);s!=="/"&&(r==="protocol"?o+=e.charAt(i):n+=e.charAt(i));let a=i===e.length-1;if(s==="/"||a){let d=L.getProtocol(o);if(r==="protocol"){if(d.size==null||d.size===0){t.push({code:d.code,name:d.name}),n="",o="",r="protocol";continue}else if(a)throw new C(`Component ${o} was missing value`);r="value"}else if(r==="value"){let f={code:d.code,name:d.name};if(d.size!=null&&d.size!==0){if(n==="")throw new C(`Component ${o} was missing value`);f.value=d.stringToValue?.(n)??n}t.push(f),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new C("Incomplete multiaddr");return t}function fr(e){return`/${e.flatMap(t=>{if(t.value==null)return t.name;let r=L.getProtocol(t.code);if(r==null)throw new C(`Unknown protocol code ${t.code}`);return[t.name,r.valueToString?.(t.value)??t.value]}).join("/")}`}function oi(e,t,r){return e.size==null||e.size===0?0:e.size>0?e.size/8:Ze(t,r)}var ii=Symbol.for("nodejs.util.inspect.custom"),bt=Symbol.for("@multiformats/multiaddr");function si(e){if(e==null&&(e="/"),pr(e))return e.getComponents();if(e instanceof Uint8Array)return ur(e);if(typeof e=="string")return e=e.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),e===""&&(e="/"),lr(e);if(Array.isArray(e))return e;throw new C("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Fe=class e{[bt]=!0;#e;#t;#r;constructor(t="/",r={}){this.#e=si(t),r.validate!==!1&&ai(this)}get bytes(){return this.#r==null&&(this.#r=dr(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=fr(this.#e)),this.#t}toJSON(){return this.toString()}getComponents(){return[...this.#e.map(t=>({...t}))]}encapsulate(t){let r=new e(t);return new e([...this.#e,...r.getComponents()],{validate:!1})}decapsulate(t){let r=t.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new ve(`Address ${this.toString()} does not contain subaddress: ${r}`);return new e(n.slice(0,o),{validate:!1})}decapsulateCode(t){let r;for(let n=this.#e.length-1;n>-1;n--)if(this.#e[n].code===t){r=n;break}return new e(this.#e.slice(0,r),{validate:!1})}equals(t){return _t(this.bytes,t.bytes)}[ii](){return`Multiaddr(${this.toString()})`}};function ai(e){e.getComponents().forEach(t=>{let r=L.getProtocol(t.code);t.value!=null&&r.validate?.(t.value)})}function pr(e){return!!e?.[bt]}function mr(e){return new Fe(e)}var hr=Symbol.for("sindresorhus/unlimited-timeout#brand");function gr(e,t,...r){if(typeof e!="function")throw new TypeError("Expected callback to be a function");t??=0,t=Number(t);let n=!1,o={[hr]:!0,id:void 0,cleared:!1,ref(){return n=!1,o.id?.ref?.(),o},unref(){return n=!0,o.id?.unref?.(),o}};if(t===Number.POSITIVE_INFINITY||t>Number.MAX_SAFE_INTEGER)return o;(!Number.isFinite(t)||t<0)&&(t=0);let i=performance.now()+t,s=a=>{o.cleared||(a<=2147483647?(o.id=globalThis.setTimeout(()=>{o.cleared||e(...r)},a),n&&o.id?.unref?.()):(o.id=globalThis.setTimeout(()=>{let d=performance.now(),f=Math.max(0,i-d);s(f)},2147483647),n&&o.id?.unref?.()))};return s(t),o}function xr(e){!e||typeof e!="object"||!e[hr]||(e.cleared=!0,e.id!==void 0&&(globalThis.clearTimeout(e.id),e.id=void 0))}var ci=new WeakMap;function ui({clearTimeout:e,setTimeout:t}={}){return(r,{value:n,signal:o}={})=>{if(o?.aborted)return Promise.reject(o.reason);let i,s,a,d=e??clearTimeout,f=()=>{d(i),a(o.reason)},c=()=>{o&&o.removeEventListener("abort",f)},u=new Promise((l,N)=>{s=()=>{c(),l(n)},a=N,i=(t??setTimeout)(s,r)});return o&&o.addEventListener("abort",f,{once:!0}),ci.set(u,()=>{d(i),i=null,s()}),u}}var di=ui({setTimeout:gr,clearTimeout:xr}),wr=di;var Ae=class extends Event{type;detail;constructor(t,r){super(t),this.type=t,this.detail=r}};function li(e){return e.reason}async function br(e,t,r){if(t==null)return e;let n=r?.translateError??li;if(t.aborted)return e.catch(()=>{}),Promise.reject(n(t));let o;try{return await Promise.race([e,new Promise((i,s)=>{o=()=>{s(n(t))},t.addEventListener("abort",o)})])}finally{o!=null&&t.removeEventListener("abort",o)}}var Ne=class extends Error{static name="PinningFailedError";name="PinningFailedError"};var ge=We("helia:remote-pinning"),Re=class{helia;remotePinningClient;originFilter;delegateFilter;pollInterval;constructor(t,r,n={}){this.helia=t,this.remotePinningClient=r,this.originFilter=n.originFilter??(o=>o),this.delegateFilter=n.delegateFilter??(o=>o),this.pollInterval=n.pollInterval??1e3}async connectToDelegates(t,r){ge.trace("connect to %d delegates",t.length);let n={};this.delegateFilter(t).forEach(o=>{let i=o.getComponents().filter(s=>s.name==="p2p").map(s=>s.value).pop()??`${Math.random()}`;n[i]??=[],n[i].push(o)});try{await Promise.any(Object.values(n).map(async o=>{try{await this.helia.libp2p.dial(o,r)}catch(i){throw ge.error("failed to connect to delegate %s - %e",o,i),i}}))}catch(o){ge.error("failed to connect to any delegates - %e",o)}}#e(t=[]){return this.originFilter([...this.helia.libp2p.getMultiaddrs(),...t]).map(r=>r.toString())}async*add(t,r={}){let n=await this.remotePinningClient.pinsPost({pin:{...r,cid:t.toString(),origins:this.#e(