@helia/remote-pinning
Version:
Add remote pinning capabilities to Helia
2 lines • 51.9 kB
JavaScript
(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 Le=Object.defineProperty;var Ur=Object.getOwnPropertyDescriptor;var _r=Object.getOwnPropertyNames;var kr=Object.prototype.hasOwnProperty;var T=(t,e)=>{for(var r in e)Le(t,r,{get:e[r],enumerable:!0})},Br=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of _r(e))!kr.call(t,o)&&o!==r&&Le(t,o,{get:()=>e[o],enumerable:!(n=Ur(e,o))||n.enumerable});return t};var Mr=t=>Br(Le({},"__esModule",{value:!0}),t);var mi={};T(mi,{createRemotePins:()=>Rr,heliaWithRemotePins:()=>hi});var _t="https://pinning-service.example.com".replace(/\/+$/,""),$r=t=>typeof Blob<"u"&&t instanceof Blob,te=class{constructor(e=new re){this.configuration=e,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=e.middleware}withMiddleware(...e){let r=this.clone();return r.middleware=r.middleware.concat(...e),r}withPreMiddleware(...e){let r=e.map(n=>({pre:n}));return this.withMiddleware(...r)}withPostMiddleware(...e){let r=e.map(n=>({post:n}));return this.withMiddleware(...r)}async request(e,r){let{url:n,init:o}=this.createFetchParams(e,r),i=await this.fetchApi(n,o);if(i.status>=200&&i.status<300)return i;throw i}createFetchParams(e,r){let n=this.configuration.basePath+e.path;e.query!==void 0&&Object.keys(e.query).length!==0&&(n+="?"+this.configuration.queryParamsStringify(e.query));let o=typeof FormData<"u"&&e.body instanceof FormData||e.body instanceof URLSearchParams||$r(e.body)?e.body:JSON.stringify(e.body),i=Object.assign({},this.configuration.headers,e.headers),s={method:e.method,headers:i,body:o,credentials:this.configuration.credentials,...r};return{url:n,init:s}}clone(){let e=this.constructor,r=new e(this.configuration);return r.middleware=this.middleware.slice(),r}},k=class extends Error{constructor(e,r){super(r),this.field=e,this.name="RequiredError"}},ye={csv:",",ssv:" ",tsv:" ",pipes:"|"},re=class{constructor(e={}){this.configuration=e}get basePath(){return this.configuration.basePath!=null?this.configuration.basePath:_t}get fetchApi(){return this.configuration.fetchApi}get middleware(){return this.configuration.middleware||[]}get queryParamsStringify(){return this.configuration.queryParamsStringify||qe}get username(){return this.configuration.username}get password(){return this.configuration.password}get apiKey(){let e=this.configuration.apiKey;if(e)return typeof e=="function"?e:()=>e}get accessToken(){let e=this.configuration.accessToken;if(e)return typeof e=="function"?e:async()=>e}get headers(){return this.configuration.headers}get credentials(){return this.configuration.credentials}};function L(t,e){let r=t[e];return r!=null}function qe(t,e=""){return Object.keys(t).map(r=>{let n=e+(e.length?`[${r}]`:r),o=t[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?qe(o,n):`${encodeURIComponent(n)}=${encodeURIComponent(String(o))}`}).filter(r=>r.length>0).join("&")}var z=class{constructor(e,r=n=>n){this.raw=e,this.transformer=r}async value(){return this.transformer(await this.raw.json())}},ne=class{constructor(e){this.raw=e}async value(){}};function kt(t){return Lr(t,!1)}function Lr(t,e){return t==null?t:{cid:t.cid,name:L(t,"name")?t.name:void 0,origins:L(t,"origins")?t.origins:void 0,meta:L(t,"meta")?t.meta:void 0}}function be(t){if(t!==void 0)return t===null?null:{cid:t.cid,name:t.name,origins:t.origins,meta:t.meta}}var oe;(function(t){t.Queued="queued",t.Pinning="pinning",t.Pinned="pinned",t.Failed="failed"})(oe||(oe={}));function Bt(t){return qr(t,!1)}function qr(t,e){return t}function H(t){return Vr(t,!1)}function Vr(t,e){return t==null?t:{requestid:t.requestid,status:Bt(t.status),created:new Date(t.created),pin:kt(t.pin),delegates:t.delegates,info:L(t,"info")?t.info:void 0}}function Mt(t){return Jr(t,!1)}function Jr(t,e){return t==null?t:{count:t.count,results:t.results.map(H)}}var $t;(function(t){t.Exact="exact",t.Iexact="iexact",t.Partial="partial",t.Ipartial="ipartial"})($t||($t={}));var ie=class extends te{async pinsGetRaw(e,r){let n={};e.cid&&(n.cid=e.cid.join(ye.csv)),e.name!==void 0&&(n.name=e.name),e.match!==void 0&&(n.match=e.match),e.status&&(n.status=e.status.join(ye.csv)),e.before!==void 0&&(n.before=e.before.toISOString()),e.after!==void 0&&(n.after=e.after.toISOString()),e.limit!==void 0&&(n.limit=e.limit),e.meta!==void 0&&(n.meta=e.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 z(i,s=>Mt(s))}async pinsGet(e={},r){return await(await this.pinsGetRaw(e,r)).value()}async pinsPostRaw(e,r){if(e.pin===null||e.pin===void 0)throw new k("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:be(e.pin)},r);return new z(i,s=>H(s))}async pinsPost(e,r){return await(await this.pinsPostRaw(e,r)).value()}async pinsRequestidDeleteRaw(e,r){if(e.requestid===null||e.requestid===void 0)throw new k("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(e.requestid))),method:"DELETE",headers:o,query:n},r);return new ne(i)}async pinsRequestidDelete(e,r){await this.pinsRequestidDeleteRaw(e,r)}async pinsRequestidGetRaw(e,r){if(e.requestid===null||e.requestid===void 0)throw new k("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(e.requestid))),method:"GET",headers:o,query:n},r);return new z(i,s=>H(s))}async pinsRequestidGet(e,r){return await(await this.pinsRequestidGetRaw(e,r)).value()}async pinsRequestidPostRaw(e,r){if(e.requestid===null||e.requestid===void 0)throw new k("requestid","Required parameter requestParameters.requestid was null or undefined when calling pinsRequestidPost.");if(e.pin===null||e.pin===void 0)throw new k("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(e.requestid))),method:"POST",headers:o,query:n,body:be(e.pin)},r);return new z(i,s=>H(s))}async pinsRequestidPost(e,r){return await(await this.pinsRequestidPostRaw(e,r)).value()}};var Ce=class extends re{constructor(e){let r={...e};e.fetchApi==null&&(r.fetchApi=fetch),e.endpointUrl!=null&&(r.basePath=e.endpointUrl),super(r)}};var Ee=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var j=class extends Error{static name="NotFoundError";constructor(e="Not found"){super(e),this.name="NotFoundError"}};var He={};T(He,{base32:()=>_,base32hex:()=>en,base32hexpad:()=>rn,base32hexpadupper:()=>nn,base32hexupper:()=>tn,base32pad:()=>Zr,base32padupper:()=>Yr,base32upper:()=>Xr,base32z:()=>on});var as=new Uint8Array(0);function zt(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 B(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 Lt(t){return new TextEncoder().encode(t)}function qt(t){return new TextDecoder().decode(t)}function Gr(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 a=t.length,d=t.charAt(0),l=Math.log(a)/Math.log(256),c=Math.log(256)/Math.log(a);function u(f){if(f instanceof Uint8Array||(ArrayBuffer.isView(f)?f=new Uint8Array(f.buffer,f.byteOffset,f.byteLength):Array.isArray(f)&&(f=Uint8Array.from(f))),!(f instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(f.length===0)return"";for(var h=0,x=0,w=0,S=f.length;w!==S&&f[w]===0;)w++,h++;for(var D=(S-w)*c+1>>>0,b=new Uint8Array(D);w!==S;){for(var R=f[w],F=0,I=D-1;(R!==0||F<x)&&I!==-1;I--,F++)R+=256*b[I]>>>0,b[I]=R%a>>>0,R=R/a>>>0;if(R!==0)throw new Error("Non-zero carry");x=F,w++}for(var A=D-x;A!==D&&b[A]===0;)A++;for(var W=d.repeat(h);A<D;++A)W+=t.charAt(b[A]);return W}function p(f){if(typeof f!="string")throw new TypeError("Expected String");if(f.length===0)return new Uint8Array;var h=0;if(f[h]!==" "){for(var x=0,w=0;f[h]===d;)x++,h++;for(var S=(f.length-h)*l+1>>>0,D=new Uint8Array(S);f[h];){var b=r[f.charCodeAt(h)];if(b===255)return;for(var R=0,F=S-1;(b!==0||R<w)&&F!==-1;F--,R++)b+=a*D[F]>>>0,D[F]=b%256>>>0,b=b/256>>>0;if(b!==0)throw new Error("Non-zero carry");w=R,h++}if(f[h]!==" "){for(var I=S-w;I!==S&&D[I]===0;)I++;for(var A=new Uint8Array(x+(S-I)),W=x;I!==S;)A[W++]=D[I++];return A}}}function $(f){var h=p(f);if(h)return h;throw new Error(`Non-${e} character`)}return{encode:u,decodeUnsafe:p,decode:$}}var Wr=Gr,Hr=Wr,Jt=Hr;var Ve=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")}},Je=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 Gt(this,e)}},Ge=class{decoders;constructor(e){this.decoders=e}or(e){return Gt(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 Gt(t,e){return new Ge({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var We=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 Ve(e,r,n),this.decoder=new Je(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function K({name:t,prefix:e,encode:r,decode:n}){return new We(t,e,r,n)}function q({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=Jt(r,t);return K({prefix:e,name:t,encode:n,decode:i=>B(o(i))})}function jr(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let i=new Uint8Array(o*r/8|0),s=0,a=0,d=0;for(let l=0;l<o;++l){let c=e[t[l]];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 Kr(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,i="",s=0,a=0;for(let d=0;d<t.length;++d)for(a=a<<8|t[d],s+=8;s>r;)s-=r,i+=e[o&a>>s];if(s!==0&&(i+=e[o&a<<r-s]),n)for(;(i.length*r&7)!==0;)i+="=";return i}function Qr(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function g({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=Qr(n);return K({prefix:e,name:t,encode(i){return Kr(i,n,r)},decode(i){return jr(i,o,r,t)}})}var _=g({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Xr=g({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Zr=g({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Yr=g({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),en=g({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),tn=g({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),rn=g({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),nn=g({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),on=g({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var je={};T(je,{base58btc:()=>v,base58flickr:()=>sn});var v=q({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),sn=q({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Xe={};T(Xe,{base64:()=>Ke,base64pad:()=>an,base64url:()=>Qe,base64urlpad:()=>cn});var Ke=g({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),an=g({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Qe=g({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),cn=g({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});function un(t,e){try{if(typeof t=="string"&&t.length>0)return dn(t);if(typeof t=="number"&&isFinite(t))return e?.long?pn(t):ln(t);throw new Error("Value is not a string or number.")}catch(r){let n=fn(r)?`${r.message}. value=${JSON.stringify(t)}`:"An unknown error has occured.";throw new Error(n)}}function dn(t){if(t=String(t),t.length>100)throw new Error("Value exceeds the maximum length of 100 characters.");let e=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(t);if(!e)return NaN;let r=parseFloat(e[1]),n=(e[2]||"ms").toLowerCase();switch(n){case"years":case"year":case"yrs":case"yr":case"y":return r*315576e5;case"weeks":case"week":case"w":return r*6048e5;case"days":case"day":case"d":return r*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return r*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return r*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return r*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return r;default:throw new Error(`The unit ${n} was matched, but no matching case exists.`)}}var ve=un;function ln(t){let e=Math.abs(t);return e>=864e5?`${Math.round(t/864e5)}d`:e>=36e5?`${Math.round(t/36e5)}h`:e>=6e4?`${Math.round(t/6e4)}m`:e>=1e3?`${Math.round(t/1e3)}s`:`${t}ms`}function pn(t){let e=Math.abs(t);return e>=864e5?Se(t,e,864e5,"day"):e>=36e5?Se(t,e,36e5,"hour"):e>=6e4?Se(t,e,6e4,"minute"):e>=1e3?Se(t,e,1e3,"second"):`${t} ms`}function Se(t,e,r,n){let o=e>=r*1.5;return`${Math.round(t/r)} ${n}${o?"s":""}`}function fn(t){return typeof t=="object"&&t!==null&&"message"in t}function Ze(t){r.debug=r,r.default=r,r.coerce=d,r.disable=i,r.enable=o,r.enabled=s,r.humanize=ve,r.destroy=l,Object.keys(t).forEach(c=>{r[c]=t[c]}),r.names=[],r.skips=[],r.formatters={};function e(c){let u=0;for(let p=0;p<c.length;p++)u=(u<<5)-u+c.charCodeAt(p),u|=0;return r.colors[Math.abs(u)%r.colors.length]}r.selectColor=e;function r(c){let u,p=null,$,f;function h(...x){if(!h.enabled)return;let w=h,S=Number(new Date),D=S-(u||S);w.diff=D,w.prev=u,w.curr=S,u=S,x[0]=r.coerce(x[0]),typeof x[0]!="string"&&x.unshift("%O");let b=0;x[0]=x[0].replace(/%([a-zA-Z%])/g,(F,I)=>{if(F==="%%")return"%";b++;let A=r.formatters[I];if(typeof A=="function"){let W=x[b];F=A.call(w,W),x.splice(b,1),b--}return F}),r.formatArgs.call(w,x),(w.log||r.log).apply(w,x)}return h.namespace=c,h.useColors=r.useColors(),h.color=r.selectColor(c),h.extend=n,h.destroy=r.destroy,Object.defineProperty(h,"enabled",{enumerable:!0,configurable:!1,get:()=>p!==null?p:($!==r.namespaces&&($=r.namespaces,f=r.enabled(c)),f),set:x=>{p=x}}),typeof r.init=="function"&&r.init(h),h}function n(c,u){let p=r(this.namespace+(typeof u>"u"?":":u)+c);return p.log=this.log,p}function o(c){r.save(c),r.namespaces=c,r.names=[],r.skips=[];let u,p=(typeof c=="string"?c:"").split(/[\s,]+/),$=p.length;for(u=0;u<$;u++)p[u]&&(c=p[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,p;for(u=0,p=r.skips.length;u<p;u++)if(r.skips[u].test(c))return!1;for(u=0,p=r.names.length;u<p;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 l(){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 Pe=bn(),hn=["#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 mn(){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 gn(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+ve(this.diff),!this.useColors)return;let e="color: "+this.color;t.splice(1,0,e,"color: inherit");let r=0,n=0;t[0].replace(/%[a-zA-Z%]/g,o=>{o!=="%%"&&(r++,o==="%c"&&(n=r))}),t.splice(n,0,e)}var xn=console.debug??console.log??(()=>{});function wn(t){try{t?Pe?.setItem("debug",t):Pe?.removeItem("debug")}catch{}}function yn(){let t;try{t=Pe?.getItem("debug")}catch{}return!t&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(t=globalThis.process.env.DEBUG),t}function bn(){try{return localStorage}catch{}}function Cn(t){t.j=function(e){try{return JSON.stringify(e)}catch(r){return"[UnexpectedJSONParseError]: "+r.message}}}var Wt=Ze({formatArgs:gn,save:wn,load:yn,useColors:mn,setupFormatters:Cn,colors:hn,storage:Pe,log:xn});var P=Wt;P.formatters.b=t=>t==null?"undefined":v.baseEncode(t);P.formatters.t=t=>t==null?"undefined":_.baseEncode(t);P.formatters.m=t=>t==null?"undefined":Ke.baseEncode(t);P.formatters.p=t=>t==null?"undefined":t.toString();P.formatters.c=t=>t==null?"undefined":t.toString();P.formatters.k=t=>t==null?"undefined":t.toString();P.formatters.a=t=>t==null?"undefined":t.toString();P.formatters.e=t=>t==null?"undefined":Ht(t.stack)??Ht(t.message)??t.toString();function En(t){let e=()=>{};return e.enabled=!1,e.color="",e.diff=0,e.log=()=>{},e.namespace=t,e.destroy=()=>!0,e.extend=()=>e,e}function jt(t){let e=En(`${t}:trace`);return P.enabled(`${t}:trace`)&&P.names.map(r=>r.toString()).find(r=>r.includes(":trace"))!=null&&(e=P(`${t}:trace`)),Object.assign(P(t),{error:P(`${t}:error`),trace:e})}function Ht(t){if(t!=null&&(t=t.trim(),t.length!==0))return t}var Ye={};T(Ye,{base10:()=>Sn});var Sn=q({prefix:"9",name:"base10",alphabet:"0123456789"});var et={};T(et,{base16:()=>vn,base16upper:()=>Pn});var vn=g({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Pn=g({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var tt={};T(tt,{base2:()=>In});var In=g({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var rt={};T(rt,{base256emoji:()=>An});var Kt=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=Kt.reduce((t,e,r)=>(t[r]=e,t),[]),On=Kt.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function Dn(t){return t.reduce((e,r)=>(e+=Tn[r],e),"")}function Fn(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=On[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var An=K({prefix:"\u{1F680}",name:"base256emoji",encode:Dn,decode:Fn});var nt={};T(nt,{base36:()=>se,base36upper:()=>Nn});var se=q({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Nn=q({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ot={};T(ot,{base8:()=>Rn});var Rn=g({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var it={};T(it,{identity:()=>Un});var Un=K({prefix:"\0",name:"identity",encode:t=>qt(t),decode:t=>Lt(t)});var ks=new TextEncoder,Bs=new TextDecoder;var at={};T(at,{identity:()=>no});var Bn=Zt,Qt=128,Mn=127,$n=~Mn,zn=Math.pow(2,31);function Zt(t,e,r){e=e||[],r=r||0;for(var n=r;t>=zn;)e[r++]=t&255|Qt,t/=128;for(;t&$n;)e[r++]=t&255|Qt,t>>>=7;return e[r]=t|0,Zt.bytes=r-n+1,e}var Ln=st,qn=128,Xt=127;function st(t,n){var r=0,n=n||0,o=0,i=n,s,a=t.length;do{if(i>=a)throw st.bytes=0,new RangeError("Could not decode varint");s=t[i++],r+=o<28?(s&Xt)<<o:(s&Xt)*Math.pow(2,o),o+=7}while(s>=qn);return st.bytes=i-n,r}var Vn=Math.pow(2,7),Jn=Math.pow(2,14),Gn=Math.pow(2,21),Wn=Math.pow(2,28),Hn=Math.pow(2,35),jn=Math.pow(2,42),Kn=Math.pow(2,49),Qn=Math.pow(2,56),Xn=Math.pow(2,63),Zn=function(t){return t<Vn?1:t<Jn?2:t<Gn?3:t<Wn?4:t<Hn?5:t<jn?6:t<Kn?7:t<Qn?8:t<Xn?9:10},Yn={encode:Bn,decode:Ln,encodingLength:Zn},eo=Yn,ae=eo;function ce(t,e=0){return[ae.decode(t,e),ae.decode.bytes]}function Q(t,e,r=0){return ae.encode(t,e,r),e}function X(t){return ae.encodingLength(t)}function J(t,e){let r=e.byteLength,n=X(t),o=n+X(r),i=new Uint8Array(o+r);return Q(t,i,0),Q(r,i,n),i.set(e,o),new Z(t,r,e,i)}function Yt(t){let e=B(t),[r,n]=ce(e),[o,i]=ce(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new Z(r,o,s,e)}function er(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&zt(t.bytes,r.bytes)}}var Z=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};var tr=0,to="identity",rr=B;function ro(t){return J(tr,rr(t))}var no={code:tr,name:to,encode:rr,digest:ro};var dt={};T(dt,{sha256:()=>oo,sha512:()=>io});function ut({name:t,code:e,encode:r}){return new ct(t,e,r)}var ct=class{name;code;encode;constructor(e,r,n){this.name=e,this.code=r,this.encode=n}digest(e){if(e instanceof Uint8Array){let r=this.encode(e);return r instanceof Uint8Array?J(this.code,r):r.then(n=>J(this.code,n))}else throw Error("Unknown type, must be binary type")}};function or(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var oo=ut({name:"sha2-256",code:18,encode:or("SHA-256")}),io=ut({name:"sha2-512",code:19,encode:or("SHA-512")});function ir(t,e){let{bytes:r,version:n}=t;switch(n){case 0:return ao(r,lt(t),e??v.encoder);default:return co(r,lt(t),e??_.encoder)}}var sr=new WeakMap;function lt(t){let e=sr.get(t);if(e==null){let r=new Map;return sr.set(t,r),r}return e}var U=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!==de)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==uo)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=J(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&&er(e.multihash,n.multihash)}toString(e){return ir(this,e)}toJSON(){return{"/":ir(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??ar(n,o,i.bytes))}else if(r[lo]===!0){let{version:n,multihash:o,code:i}=r,s=Yt(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!==de)throw new Error(`Version 0 CID must use dag-pb (code: ${de}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=ar(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,de,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=B(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 Z(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[u,p]=ce(e.subarray(r));return r+=p,u},o=n(),i=de;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(),l=r+d,c=l-s;return{version:o,codec:i,multihashCode:a,digestSize:d,multihashSize:c,size:l}}static parse(e,r){let[n,o]=so(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 lt(i).set(n,e),i}};function so(t,e){switch(t[0]){case"Q":{let r=e??v;return[v.prefix,r.decode(`${v.prefix}${t}`)]}case v.prefix:{let r=e??v;return[v.prefix,r.decode(t)]}case _.prefix:{let r=e??_;return[_.prefix,r.decode(t)]}case se.prefix:{let r=e??se;return[se.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 ao(t,e,r){let{prefix:n}=r;if(n!==v.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 co(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 de=112,uo=18;function ar(t,e,r){let n=X(t),o=n+X(e),i=new Uint8Array(o+r.byteLength);return Q(t,i,0),Q(e,i,n),i.set(r,o),i}var lo=Symbol.for("@ipld/js-cid/CID");var le={...it,...tt,...ot,...Ye,...et,...He,...nt,...je,...Xe,...rt},ia={...dt,...at};function pe(t=0){return new Uint8Array(t)}function ur(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var cr=ur("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),pt=ur("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=pe(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),po={utf8:cr,"utf-8":cr,hex:le.base16,latin1:pt,ascii:pt,binary:pt,...le},Te=po;function N(t,e="utf8"){let r=Te[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var C=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},M=class extends Error{static name="ValidationError";name="ValidationError"},fe=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Oe=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function dr(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,e="utf8"){let r=Te[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}var fo=Math.pow(2,7),ho=Math.pow(2,14),mo=Math.pow(2,21),ft=Math.pow(2,28),ht=Math.pow(2,35),mt=Math.pow(2,42),gt=Math.pow(2,49),m=128,E=127;function Y(t){if(t<fo)return 1;if(t<ho)return 2;if(t<mo)return 3;if(t<ft)return 4;if(t<ht)return 5;if(t<mt)return 6;if(t<gt)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function xt(t,e,r=0){switch(Y(t)){case 8:e[r++]=t&255|m,t/=128;case 7:e[r++]=t&255|m,t/=128;case 6:e[r++]=t&255|m,t/=128;case 5:e[r++]=t&255|m,t/=128;case 4:e[r++]=t&255|m,t>>>=7;case 3:e[r++]=t&255|m,t>>>=7;case 2:e[r++]=t&255|m,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function go(t,e){let r=t[e],n=0;if(n+=r&E,r<m||(r=t[e+1],n+=(r&E)<<7,r<m)||(r=t[e+2],n+=(r&E)<<14,r<m)||(r=t[e+3],n+=(r&E)<<21,r<m)||(r=t[e+4],n+=(r&E)*ft,r<m)||(r=t[e+5],n+=(r&E)*ht,r<m)||(r=t[e+6],n+=(r&E)*mt,r<m)||(r=t[e+7],n+=(r&E)*gt,r<m))return n;throw new RangeError("Could not decode varint")}function xo(t,e){let r=t.get(e),n=0;if(n+=r&E,r<m||(r=t.get(e+1),n+=(r&E)<<7,r<m)||(r=t.get(e+2),n+=(r&E)<<14,r<m)||(r=t.get(e+3),n+=(r&E)<<21,r<m)||(r=t.get(e+4),n+=(r&E)*ft,r<m)||(r=t.get(e+5),n+=(r&E)*ht,r<m)||(r=t.get(e+6),n+=(r&E)*mt,r<m)||(r=t.get(e+7),n+=(r&E)*gt,r<m))return n;throw new RangeError("Could not decode varint")}function wt(t,e=0){return t instanceof Uint8Array?go(t,e):xo(t,e)}function he(t,e){e==null&&(e=t.reduce((o,i)=>o+i.length,0));let r=pe(e),n=0;for(let o of t)r.set(o,n),n+=o.length;return r}var De=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let r=this.index,n=e();return n===void 0&&(this.index=r),n}parseWith(e){let r=e();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(e){return this.readAtomically(()=>{let r=this.readChar();if(r===e)return r})}readSeparator(e,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,r,n,o){return this.readAtomically(()=>{let i=0,s=0,a=this.peekChar();if(a===void 0)return;let d=a==="0",l=2**(8*o)-1;for(;;){let c=this.readAtomically(()=>{let u=this.readChar();if(u===void 0)return;let p=Number.parseInt(u,e);if(!Number.isNaN(p))return p});if(c===void 0)break;if(i*=e,i+=c,i>l||(s+=1,r!==void 0&&s>r))return}if(s!==0)return!n&&d&&s>1?void 0:i})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let r=0;r<e.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[r]=n}return e})}readIPv6Addr(){let e=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]=e(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]=e(i.subarray(0,s));return r.set(i.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var yo=45,bo=15,Fe=new De;function yt(t){if(!(t.length>bo))return Fe.new(t).parseWith(()=>Fe.readIPv4Addr())}function bt(t){if(t.includes("%")&&(t=t.split("%")[0]),!(t.length>yo))return Fe.new(t).parseWith(()=>Fe.readIPv6Addr())}function Ae(t){return!!yt(t)}function pr(t){return!!bt(t)}function Et(t){return e=>N(e,t)}function St(t){return e=>V(e,t)}function ee(t){return new DataView(t.buffer).getUint16(t.byteOffset).toString()}function G(t){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof t=="string"?parseInt(t):t),new Uint8Array(e)}function fr(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let r=V(e[0],"base32"),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=G(n);return he([r,o],r.length+o.length)}function hr(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let r=_.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=G(n);return he([r,o],r.length+o.length)}function vt(t){let e=t.subarray(0,t.length-2),r=t.subarray(t.length-2),n=N(e,"base32"),o=ee(r);return`${n}:${o}`}var Pt=function(t){t=t.toString().trim();let e=new Uint8Array(4);return t.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");e[n]=o}),e},mr=function(t){let e=0;t=t.toString().trim();let r=t.split(":",8),n;for(n=0;n<r.length;n++){let i=Ae(r[n]),s;i&&(s=Pt(r[n]),r[n]=N(s.subarray(0,2),"base16")),s!=null&&++n<8&&r.splice(n,0,N(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(e+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[e++]=i>>8&255,o[e++]=i&255}return o},gr=function(t){if(t.byteLength!==4)throw new C("IPv4 address was incorrect length");let e=[];for(let r=0;r<t.byteLength;r++)e.push(t[r]);return e.join(".")},xr=function(t){if(t.byteLength!==16)throw new C("IPv6 address was incorrect length");let e=[];for(let n=0;n<t.byteLength;n+=2){let o=t[n],i=t[n+1],s=`${o.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}`;e.push(s)}let r=e.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 wr(t){try{let e=new URL(`http://[${t}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new C(`Invalid IPv6 address "${t}"`)}}var Ct=Object.values(le).map(t=>t.decoder),Co=function(){let t=Ct[0].or(Ct[1]);return Ct.slice(2).forEach(e=>t=t.or(e)),t}();function yr(t){return Co.decode(t)}function br(t){return e=>t.encoder.encode(e)}function Eo(t){if(parseInt(t).toString()!==t)throw new M("Value must be an integer")}function So(t){if(t<0)throw new M("Value must be a positive integer, or zero")}function vo(t){return e=>{if(e>t)throw new M(`Value must be smaller than or equal to ${t}`)}}function Po(...t){return e=>{for(let r of t)r(e)}}var me=Po(Eo,So,vo(65535));var y=-1,It=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(e){let r;if(typeof e=="string"?r=this.protocolsByName.get(e):r=this.protocolsByCode.get(e),r==null)throw new Oe(`Protocol ${e} was unknown`);return r}addProtocol(e){this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),e.aliases?.forEach(r=>{this.protocolsByName.set(r,e)})}removeProtocol(e){let r=this.protocolsByCode.get(e);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},O=new It,ti=[{code:4,name:"ip4",size:32,valueToBytes:Pt,bytesToValue:gr,validate:t=>{if(!Ae(t))throw new M(`Invalid IPv4 address "${t}"`)}},{code:6,name:"tcp",size:16,valueToBytes:G,bytesToValue:ee,validate:me},{code:273,name:"udp",size:16,valueToBytes:G,bytesToValue:ee,validate:me},{code:33,name:"dccp",size:16,valueToBytes:G,bytesToValue:ee,validate:me},{code:41,name:"ip6",size:128,valueToBytes:mr,bytesToValue:xr,stringToValue:wr,validate:t=>{if(!pr(t))throw new M(`Invalid IPv6 address "${t}"`)}},{code:42,name:"ip6zone",size:y},{code:43,name:"ipcidr",size:8,bytesToValue:Et("base10"),valueToBytes:St("base10")},{code:53,name:"dns",size:y,resolvable:!0},{code:54,name:"dns4",size:y,resolvable:!0},{code:55,name:"dns6",size:y,resolvable:!0},{code:56,name:"dnsaddr",size:y,resolvable:!0},{code:132,name:"sctp",size:16,valueToBytes:G,bytesToValue:ee,validate:me},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:y,path:!0,stringToValue:t=>decodeURIComponent(t),valueToString:t=>encodeURIComponent(t)},{code:421,name:"p2p",aliases:["ipfs"],size:y,bytesToValue:Et("base58btc"),valueToBytes:t=>t.startsWith("Q")||t.startsWith("1")?St("base58btc")(t):U.parse(t).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:vt,valueToBytes:fr},{code:445,name:"onion3",size:296,bytesToValue:vt,valueToBytes:hr},{code:446,name:"garlic64",size:y},{code:447,name:"garlic32",size:y},{code:448,name:"tls"},{code:449,name:"sni",size:y},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:y,bytesToValue:br(Qe),valueToBytes:yr},{code:480,name:"http"},{code:481,name:"http-path",size:y,stringToValue:t=>`/${decodeURIComponent(t)}`,valueToString:t=>encodeURIComponent(t.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:y}];ti.forEach(t=>{O.addProtocol(t)});function Cr(t){let e=[],r=0;for(;r<t.length;){let n=wt(t,r),o=O.getProtocol(n),i=Y(n),s=ri(o,t,r+i),a=0;s>0&&o.size===y&&(a=Y(s));let d=i+a+s,l={code:n,name:o.name,bytes:t.subarray(r,r+d)};if(s>0){let c=r+i+a,u=t.subarray(c,c+s);l.value=o.bytesToValue?.(u)??N(u)}e.push(l),r+=d}return e}function Er(t){let e=0,r=[];for(let n of t){if(n.bytes==null){let o=O.getProtocol(n.code),i=Y(n.code),s,a=0,d=0;n.value!=null&&(s=o.valueToBytes?.(n.value)??V(n.value),a=s.byteLength,o.size===y&&(d=Y(a)));let l=new Uint8Array(i+d+a),c=0;xt(n.code,l,c),c+=i,s!=null&&(o.size===y&&(xt(a,l,c),c+=d),l.set(s,c)),n.bytes=l}r.push(n.bytes),e+=n.bytes.byteLength}return he(r,e)}function Sr(t){if(t.charAt(0)!=="/")throw new C('String multiaddr must start with "/"');let e=[],r="protocol",n="",o="";for(let i=1;i<t.length;i++){let s=t.charAt(i);s!=="/"&&(r==="protocol"?o+=t.charAt(i):n+=t.charAt(i));let a=i===t.length-1;if(s==="/"||a){let d=O.getProtocol(o);if(r==="protocol"){if(d.size==null||d.size===0){e.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 l={code:d.code,name:d.name};if(d.size!=null&&d.size!==0){if(n==="")throw new C(`Component ${o} was missing value`);l.value=d.stringToValue?.(n)??n}e.push(l),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new C("Incomplete multiaddr");return e}function vr(t){return`/${t.flatMap(e=>{if(e.value==null)return e.name;let r=O.getProtocol(e.code);if(r==null)throw new C(`Unknown protocol code ${e.code}`);return[e.name,r.valueToString?.(e.value)??e.value]}).join("/")}`}function ri(t,e,r){return t.size==null||t.size===0?0:t.size>0?t.size/8:wt(e,r)}var ni=Symbol.for("nodejs.util.inspect.custom"),Ut=Symbol.for("@multiformats/multiaddr"),oi=[53,54,55,56],Rt=class extends Error{constructor(e="No available resolver"){super(e),this.name="NoAvailableResolverError"}};function ii(t){if(t==null&&(t="/"),Ir(t))return t.getComponents();if(t instanceof Uint8Array)return Cr(t);if(typeof t=="string")return t=t.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),t===""&&(t="/"),Sr(t);if(Array.isArray(t))return t;throw new C("Must be a string, Uint8Array, Component[], or another Multiaddr")}var ke=class t{[Ut]=!0;#e;#t;#r;constructor(e="/",r={}){this.#e=ii(e),r.validate!==!1&&si(this)}get bytes(){return this.#r==null&&(this.#r=Er(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=vr(this.#e)),this.#t}toJSON(){return this.toString()}toOptions(){let e,r,n,o,i="";for(let{code:a,name:d,value:l}of this.#e)a===42&&(i=`%${l??""}`),oi.includes(a)&&(r="tcp",o=443,n=`${l??""}${i}`,e=a===55?6:4),(a===6||a===273)&&(r=d==="tcp"?"tcp":"udp",o=parseInt(l??"")),(a===4||a===41)&&(r="tcp",n=`${l??""}${i}`,e=a===41?6:4);if(e==null||r==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:e,host:n,transport:r,port:o}}getComponents(){return[...this.#e]}protos(){return this.#e.map(({code:e,value:r})=>{let n=O.getProtocol(e);return{code:e,size:n.size??0,name:n.name,resolvable:!!n.resolvable,path:!!n.path}})}protoCodes(){return this.#e.map(({code:e})=>e)}protoNames(){return this.#e.map(({name:e})=>e)}tuples(){return this.#e.map(({code:e,value:r})=>{if(r==null)return[e];let n=O.getProtocol(e),o=[e];return r!=null&&o.push(n.valueToBytes?.(r)??V(r)),o})}stringTuples(){return this.#e.map(({code:e,value:r})=>r==null?[e]:[e,r])}encapsulate(e){let r=new t(e);return new t([...this.#e,...r.getComponents()],{validate:!1})}decapsulate(e){let r=e.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new fe(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new t(n.slice(0,o),{validate:!1})}decapsulateCode(e){let r;for(let n=this.#e.length-1;n>-1;n--)if(this.#e[n].code===e){r=n;break}return new t(this.#e.slice(0,r),{validate:!1})}getPeerId(){try{let e=[];this.#e.forEach(({code:n,value:o})=>{n===421&&e.push([n,o]),n===290&&(e=[])});let r=e.pop();if(r?.[1]!=null){let n=r[1];return n[0]==="Q"||n[0]==="1"?N(v.decode(`z${n}`),"base58btc"):N(U.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){for(let e of this.#e)if(O.getProtocol(e.code).path)return e.value??null;return null}equals(e){return dr(this.bytes,e.bytes)}async resolve(e){let r=this.protos().find(i=>i.resolvable);if(r==null)return[this];let n=Pr.get(r.name);if(n==null)throw new Rt(`no available resolver for ${r.name}`);return(await n(this,e)).map(i=>xe(i))}nodeAddress(){let e=this.toOptions();if(e.transport!=="tcp"&&e.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${e.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:e.family,address:e.host,port:e.port}}isThinWaistAddress(){return!(this.#e.length!==2||this.#e[0].code!==4&&this.#e[0].code!==41||this.#e[1].code!==6&&this.#e[1].code!==273)}[ni](){return`Multiaddr(${this.toString()})`}};function si(t){t.getComponents().forEach(e=>{let r=O.getProtocol(e.code);e.value!=null&&r.validate?.(e.value)})}var gc=parseInt("0xFFFF",16),xc=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var Pr=new Map;function Ir(t){return!!t?.[Ut]}function xe(t){return new ke(t)}var Dr=()=>{let t=new Error("Delay aborted");return t.name="AbortError",t},li=new WeakMap;function pi({clearTimeout:t,setTimeout:e}={}){return(r,{value:n,signal:o}={})=>{if(o?.aborted)return Promise.reject(Dr());let i,s,a,d=t??clearTimeout,l=()=>{d(i),a(Dr())},c=()=>{o&&o.removeEventListener("abort",l)},u=new Promise((p,$)=>{s=()=>{c(),p(n)},a=$,i=(e??setTimeout)(s,r)});return o&&o.addEventListener("abort",l,{once:!0}),li.set(u,()=>{d(i),i=null,s()}),u}}var fi=pi(),Fr=fi;var Be=class extends Event{type;detail;constructor(e,r){super(e),this.type=e,this.detail=r}};var Me=class extends Error{type;code;constructor(e,r,n){super(e??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=r??"ABORT_ERR"}};async function Ar(t,e,r){if(e==null)return t;if(e.aborted)return t.catch(()=>{}),Promise.reject(new Me(r?.errorMessage,r?.errorCode,r?.errorName));let n,o=new Me(r?.errorMessage,r?.errorCode,r?.errorName);try{return await Promise.race([t,new Promise((i,s)=>{n=()=>{s(o)},e.addEventListener("abort",n)})])}finally{n!=null&&e.removeEventListener("abort",n)}}var $e=class extends Error{static name="PinningFailedError";name="PinningFailedError"};var we=jt("helia:remote-pinning"),ze=class{helia;remotePinningClient;originFilter;delegateFilter;pollInterval;constructor(e,r,n={}){this.helia=e,this.remotePinningClient=r,this.originFilter=n.originFilter??(o=>o),this.delegateFilter=n.delegateFilter??(o=>o),this.pollInterval=n.pollInterval??1e3}async connectToDelegates(e,r){we.trace("connect to %d delegates",e.length);let n={};this.delegateFilter(e).forEach(o=>{let i=o.getPeerId()??`${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 we.error("failed to connect to delegate %s - %e",o,i),i}}))}catch(o){we.error("failed to connect to any delegates - %e",o)}}#e(e=[]){return this.originFilter([...this.helia.libp2p.getMultiaddrs(),...e]).map(r=>r.toString())}async*add(e,r={}){let n=await this.remotePinningClient.pinsPost({pin:{...r,cid:e.toString(),origins:this.#e(r.origins),meta:r.metadata}},r);for(we.trace("initial pinsPost made, status: %s",n.status),this.connectToDelegates(n.delegates.map(o=>xe(o)),r).catch(o=>{we.error("failed to conne