You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

@multiformats/multiaddr-to-uri

Package Overview
Dependencies
Maintainers
10
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@multiformats/multiaddr-to-uri - npm Package Compare versions

Comparing version
11.0.0
to
11.0.1
dist/index.min.js.map

Sorry, the diff of this file is too big to display

+2
-1
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.MultiformatsMultiaddrToUri = factory()}(typeof self !== 'undefined' ? self : this, function () {
"use strict";var MultiformatsMultiaddrToUri=(()=>{var pe=Object.defineProperty;var Ot=Object.getOwnPropertyDescriptor;var Rt=Object.getOwnPropertyNames;var jt=Object.prototype.hasOwnProperty;var b=(r,e)=>{for(var t in e)pe(r,t,{get:e[t],enumerable:!0})},qt=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Rt(e))!jt.call(r,o)&&o!==t&&pe(r,o,{get:()=>e[o],enumerable:!(n=Ot(e,o))||n.enumerable});return r};var Gt=r=>qt(pe({},"__esModule",{value:!0}),r);var Cn={};b(Cn,{multiaddrToUri:()=>Pn});var me={};b(me,{base58btc:()=>x,base58flickr:()=>Kt});var $n=new Uint8Array(0);function Ye(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function F(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function _e(r){return new TextEncoder().encode(r)}function et(r){return new TextDecoder().decode(r)}function Wt(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var i=r.charAt(o),a=i.charCodeAt(0);if(t[a]!==255)throw new TypeError(i+" is ambiguous");t[a]=o}var s=r.length,u=r.charAt(0),m=Math.log(s)/Math.log(256),f=Math.log(256)/Math.log(s);function E(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var w=0,M=0,A=0,U=d.length;A!==U&&d[A]===0;)A++,w++;for(var P=(U-A)*f+1>>>0,v=new Uint8Array(P);A!==U;){for(var C=d[A],D=0,S=P-1;(C!==0||D<M)&&S!==-1;S--,D++)C+=256*v[S]>>>0,v[S]=C%s>>>0,C=C/s>>>0;if(C!==0)throw new Error("Non-zero carry");M=D,A++}for(var $=P-M;$!==P&&v[$]===0;)$++;for(var re=u.repeat(w);$<P;++$)re+=r.charAt(v[$]);return re}function k(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var w=0;if(d[w]!==" "){for(var M=0,A=0;d[w]===u;)M++,w++;for(var U=(d.length-w)*m+1>>>0,P=new Uint8Array(U);d[w];){var v=t[d.charCodeAt(w)];if(v===255)return;for(var C=0,D=U-1;(v!==0||C<A)&&D!==-1;D--,C++)v+=s*P[D]>>>0,P[D]=v%256>>>0,v=v/256>>>0;if(v!==0)throw new Error("Non-zero carry");A=C,w++}if(d[w]!==" "){for(var S=U-A;S!==U&&P[S]===0;)S++;for(var $=new Uint8Array(M+(U-S)),re=M;S!==U;)$[re++]=P[S++];return $}}}function y(d){var w=k(d);if(w)return w;throw new Error(`Non-${e} character`)}return{encode:E,decodeUnsafe:k,decode:y}}var Jt=Wt,Ht=Jt,rt=Ht;var ue=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},le=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let o=t.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 nt(this,e)}},fe=class{decoders;constructor(e){this.decoders=e}or(e){return nt(this,e)}decode(e){let t=e[0],n=this.decoders[t];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 nt(r,e){return new fe({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var he=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new ue(e,t,n),this.decoder=new le(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function R({name:r,prefix:e,encode:t,decode:n}){return new he(r,e,t,n)}function V({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=rt(t,r);return R({prefix:e,name:r,encode:n,decode:i=>F(o(i))})}function Xt(r,e,t,n){let o={};for(let f=0;f<e.length;++f)o[e[f]]=f;let i=r.length;for(;r[i-1]==="=";)--i;let a=new Uint8Array(i*t/8|0),s=0,u=0,m=0;for(let f=0;f<i;++f){let E=o[r[f]];if(E===void 0)throw new SyntaxError(`Non-${n} character`);u=u<<t|E,s+=t,s>=8&&(s-=8,a[m++]=255&u>>s)}if(s>=t||255&u<<8-s)throw new SyntaxError("Unexpected end of data");return a}function Qt(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,i="",a=0,s=0;for(let u=0;u<r.length;++u)for(s=s<<8|r[u],a+=8;a>t;)a-=t,i+=e[o&s>>a];if(a!==0&&(i+=e[o&s<<t-a]),n)for(;i.length*t&7;)i+="=";return i}function l({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return R({prefix:e,name:r,encode(o){return Qt(o,n,t)},decode(o){return Xt(o,n,t,r)}})}var x=V({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Kt=V({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var we={};b(we,{base32:()=>N,base32hex:()=>er,base32hexpad:()=>rr,base32hexpadupper:()=>nr,base32hexupper:()=>tr,base32pad:()=>Yt,base32padupper:()=>_t,base32upper:()=>Zt,base32z:()=>or});var N=l({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Zt=l({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Yt=l({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),_t=l({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),er=l({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),tr=l({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),rr=l({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),nr=l({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),or=l({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var xe={};b(xe,{base36:()=>K,base36upper:()=>ir});var K=V({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),ir=V({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var sr=st,ot=128,ar=127,cr=~ar,dr=Math.pow(2,31);function st(r,e,t){e=e||[],t=t||0;for(var n=t;r>=dr;)e[t++]=r&255|ot,r/=128;for(;r&cr;)e[t++]=r&255|ot,r>>>=7;return e[t]=r|0,st.bytes=t-n+1,e}var pr=ge,ur=128,it=127;function ge(r,n){var t=0,n=n||0,o=0,i=n,a,s=r.length;do{if(i>=s)throw ge.bytes=0,new RangeError("Could not decode varint");a=r[i++],t+=o<28?(a&it)<<o:(a&it)*Math.pow(2,o),o+=7}while(a>=ur);return ge.bytes=i-n,t}var lr=Math.pow(2,7),fr=Math.pow(2,14),hr=Math.pow(2,21),mr=Math.pow(2,28),wr=Math.pow(2,35),xr=Math.pow(2,42),gr=Math.pow(2,49),br=Math.pow(2,56),yr=Math.pow(2,63),vr=function(r){return r<lr?1:r<fr?2:r<hr?3:r<mr?4:r<wr?5:r<xr?6:r<gr?7:r<br?8:r<yr?9:10},Er={encode:sr,decode:pr,encodingLength:vr},Ar=Er,Z=Ar;function Y(r,e=0){return[Z.decode(r,e),Z.decode.bytes]}function j(r,e,t=0){return Z.encode(r,e,t),e}function q(r){return Z.encodingLength(r)}function B(r,e){let t=e.byteLength,n=q(r),o=n+q(t),i=new Uint8Array(o+t);return j(r,i,0),j(t,i,n),i.set(e,o),new G(r,t,e,i)}function oe(r){let e=F(r),[t,n]=Y(e),[o,i]=Y(e.subarray(n)),a=e.subarray(n+i);if(a.byteLength!==o)throw new Error("Incorrect length");return new G(t,o,a,e)}function at(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Ye(r.bytes,t.bytes)}}var G=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function ct(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return Ir(t,be(r),e??x.encoder);default:return Ur(t,be(r),e??N.encoder)}}var dt=new WeakMap;function be(r){let e=dt.get(r);if(e==null){let t=new Map;return dt.set(r,t),t}return e}var L=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,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:t}=this;if(e!==_)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Pr)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}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:t}=this.multihash,n=B(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&at(e.multihash,n.multihash)}toString(e){return ct(this,e)}toJSON(){return{"/":ct(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 t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:i,bytes:a}=t;return new r(n,o,i,a??pt(n,o,i.bytes))}else if(t[Cr]===!0){let{version:n,multihash:o,code:i}=t,a=oe(o);return r.create(n,i,a)}else return null}static create(e,t,n){if(typeof t!="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(t!==_)throw new Error(`Version 0 CID must use dag-pb (code: ${_}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=pt(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,_,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=F(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let i=o.subarray(t.multihashSize-t.digestSize),a=new G(t.multihashCode,t.digestSize,i,o);return[t.version===0?r.createV0(a):r.createV1(t.codec,a),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[E,k]=Y(e.subarray(t));return t+=k,E},o=n(),i=_;if(o===18?(o=0,t=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let a=t,s=n(),u=n(),m=t+u,f=m-a;return{version:o,codec:i,multihashCode:s,digestSize:u,multihashSize:f,size:m}}static parse(e,t){let[n,o]=Sr(e,t),i=r.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return be(i).set(n,e),i}};function Sr(r,e){switch(r[0]){case"Q":{let t=e??x;return[x.prefix,t.decode(`${x.prefix}${r}`)]}case x.prefix:{let t=e??x;return[x.prefix,t.decode(r)]}case N.prefix:{let t=e??N;return[N.prefix,t.decode(r)]}case K.prefix:{let t=e??K;return[K.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function Ir(r,e,t){let{prefix:n}=t;if(n!==x.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let i=t.encode(r).slice(1);return e.set(n,i),i}else return o}function Ur(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let i=t.encode(r);return e.set(n,i),i}else return o}var _=112,Pr=18;function pt(r,e,t){let n=q(r),o=n+q(e),i=new Uint8Array(o+t.byteLength);return j(r,i,0),j(e,i,n),i.set(t,o),i}var Cr=Symbol.for("@ipld/js-cid/CID");function ut(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}var ye={};b(ye,{base10:()=>Tr});var Tr=V({prefix:"9",name:"base10",alphabet:"0123456789"});var ve={};b(ve,{base16:()=>$r,base16upper:()=>Fr});var $r=l({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Fr=l({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Ee={};b(Ee,{base2:()=>Nr});var Nr=l({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ae={};b(Ae,{base256emoji:()=>Lr});var lt=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}"),zr=lt.reduce((r,e,t)=>(r[t]=e,r),[]),kr=lt.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function Dr(r){return r.reduce((e,t)=>(e+=zr[t],e),"")}function Vr(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=kr[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var Lr=R({prefix:"\u{1F680}",name:"base256emoji",encode:Dr,decode:Vr});var Se={};b(Se,{base64:()=>Mr,base64pad:()=>Br,base64url:()=>Or,base64urlpad:()=>Rr});var Mr=l({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Br=l({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Or=l({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Rr=l({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ie={};b(Ie,{base8:()=>jr});var jr=l({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ue={};b(Ue,{identity:()=>qr});var qr=R({prefix:"\0",name:"identity",encode:r=>et(r),decode:r=>_e(r)});var ro=new TextEncoder,no=new TextDecoder;var Pe={};b(Pe,{identity:()=>Xr});var ft=0,Jr="identity",ht=F;function Hr(r){return B(ft,ht(r))}var Xr={code:ft,name:Jr,encode:ht,digest:Hr};var $e={};b($e,{sha256:()=>Qr,sha512:()=>Kr});function Te({name:r,code:e,encode:t}){return new Ce(r,e,t)}var Ce=class{name;code;encode;constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?B(this.code,t):t.then(n=>B(this.code,n))}else throw Error("Unknown type, must be binary type")}};function wt(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var Qr=Te({name:"sha2-256",code:18,encode:wt("SHA-256")}),Kr=Te({name:"sha2-512",code:19,encode:wt("SHA-512")});var ee={...Ue,...Ee,...Ie,...ye,...ve,...we,...xe,...me,...Se,...Ae},xo={...$e,...Pe};function J(r=0){return new Uint8Array(r)}function gt(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var xt=gt("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Fe=gt("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=J(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Zr={utf8:xt,"utf-8":xt,hex:ee.base16,latin1:Fe,ascii:Fe,binary:Fe,...ee},ie=Zr;function g(r,e="utf8"){let t=ie[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var Yr=Math.pow(2,7),_r=Math.pow(2,14),en=Math.pow(2,21),Ne=Math.pow(2,28),ze=Math.pow(2,35),ke=Math.pow(2,42),De=Math.pow(2,49),p=128,h=127;function T(r){if(r<Yr)return 1;if(r<_r)return 2;if(r<en)return 3;if(r<Ne)return 4;if(r<ze)return 5;if(r<ke)return 6;if(r<De)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function tn(r,e,t=0){switch(T(r)){case 8:e[t++]=r&255|p,r/=128;case 7:e[t++]=r&255|p,r/=128;case 6:e[t++]=r&255|p,r/=128;case 5:e[t++]=r&255|p,r/=128;case 4:e[t++]=r&255|p,r>>>=7;case 3:e[t++]=r&255|p,r>>>=7;case 2:e[t++]=r&255|p,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function rn(r,e,t=0){switch(T(r)){case 8:e.set(t++,r&255|p),r/=128;case 7:e.set(t++,r&255|p),r/=128;case 6:e.set(t++,r&255|p),r/=128;case 5:e.set(t++,r&255|p),r/=128;case 4:e.set(t++,r&255|p),r>>>=7;case 3:e.set(t++,r&255|p),r>>>=7;case 2:e.set(t++,r&255|p),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function nn(r,e){let t=r[e],n=0;if(n+=t&h,t<p||(t=r[e+1],n+=(t&h)<<7,t<p)||(t=r[e+2],n+=(t&h)<<14,t<p)||(t=r[e+3],n+=(t&h)<<21,t<p)||(t=r[e+4],n+=(t&h)*Ne,t<p)||(t=r[e+5],n+=(t&h)*ze,t<p)||(t=r[e+6],n+=(t&h)*ke,t<p)||(t=r[e+7],n+=(t&h)*De,t<p))return n;throw new RangeError("Could not decode varint")}function on(r,e){let t=r.get(e),n=0;if(n+=t&h,t<p||(t=r.get(e+1),n+=(t&h)<<7,t<p)||(t=r.get(e+2),n+=(t&h)<<14,t<p)||(t=r.get(e+3),n+=(t&h)<<21,t<p)||(t=r.get(e+4),n+=(t&h)*Ne,t<p)||(t=r.get(e+5),n+=(t&h)*ze,t<p)||(t=r.get(e+6),n+=(t&h)*ke,t<p)||(t=r.get(e+7),n+=(t&h)*De,t<p))return n;throw new RangeError("Could not decode varint")}function H(r,e,t=0){return e==null&&(e=J(T(r))),e instanceof Uint8Array?tn(r,e,t):rn(r,e,t)}function O(r,e=0){return r instanceof Uint8Array?nn(r,e):on(r,e)}function z(r,e){e==null&&(e=r.reduce((o,i)=>o+i.length,0));let t=J(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}var se=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,n=e();return n===void 0&&(this.index=t),n}parseWith(e){let t=e();if(this.index===this.input.length)return t}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 t=this.readChar();if(t===e)return t})}readSeparator(e,t,n){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,t,n,o){return this.readAtomically(()=>{let i=0,a=0,s=this.peekChar();if(s===void 0)return;let u=s==="0",m=2**(8*o)-1;for(;;){let f=this.readAtomically(()=>{let E=this.readChar();if(E===void 0)return;let k=Number.parseInt(E,e);if(!Number.isNaN(k))return k});if(f===void 0)break;if(i*=e,i+=f,i>m||(a+=1,t!==void 0&&a>t))return}if(a!==0)return!n&&u&&a>1?void 0:i})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;t<e.length;t++){let n=this.readSeparator(".",t,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[t]=n}return e})}readIPv6Addr(){let e=t=>{for(let n=0;n<t.length/2;n++){let o=n*2;if(n<t.length-3){let a=this.readSeparator(":",n,()=>this.readIPv4Addr());if(a!==void 0)return t[o]=a[0],t[o+1]=a[1],t[o+2]=a[2],t[o+3]=a[3],[o+4,!0]}let i=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(i===void 0)return[o,!1];t[o]=i>>8,t[o+1]=i&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,o]=e(t);if(n===16)return t;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let i=new Uint8Array(14),a=16-(n+2),[s]=e(i.subarray(0,a));return t.set(i.subarray(0,s),16-s),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var yt=45,sn=15,X=new se;function Ve(r){if(!(r.length>sn))return X.new(r).parseWith(()=>X.readIPv4Addr())}function Le(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>yt))return X.new(r).parseWith(()=>X.readIPv6Addr())}function ae(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>yt))return X.new(r).parseWith(()=>X.readIPAddr())}var Oo=parseInt("0xFFFF",16),Ro=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Me(r,e="utf8"){let t=ie[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function At(r){return!!Ve(r)}function St(r){return!!Le(r)}function ce(r){return!!ae(r)}var It=At,un=St,Be=function(r){let e=0;if(r=r.toString().trim(),It(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(un(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let i=It(t[n]),a;i&&(a=Be(t[n]),t[n]=g(a.slice(0,2),"base16")),a!=null&&++n<8&&t.splice(n,0,g(a.slice(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let i=[n,1];for(n=9-t.length;n>0;n--)i.push("0");t.splice.apply(t,i)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){let i=parseInt(t[n],16);o[e++]=i>>8&255,o[e++]=i&255}return o}throw new Error("invalid ip address")},Ut=function(r,e=0,t){e=~~e,t=t??r.length-e;let n=new DataView(r.buffer);if(t===4){let o=[];for(let i=0;i<t;i++)o.push(r[e+i]);return o.join(".")}if(t===16){let o=[];for(let i=0;i<t;i+=2)o.push(n.getUint16(e+i).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var Q={},Oe={},fn=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[481,-1,"http-path"],[777,-1,"memory"]];fn.forEach(r=>{let e=hn(...r);Oe[e.code]=e,Q[e.name]=e});function hn(r,e,t,n,o){return{code:r,size:e,name:t,resolvable:!!n,path:!!o}}function c(r){if(typeof r=="number"){if(Oe[r]!=null)return Oe[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(Q[r]!=null)return Q[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var Ui=c("ip4"),Pi=c("ip6"),Ci=c("ipcidr");function Ge(r,e){switch(c(r).code){case 4:case 41:return wn(e);case 42:return qe(e);case 6:case 273:case 33:case 132:return Tt(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return qe(e);case 421:return yn(e);case 444:return Ct(e);case 445:return Ct(e);case 466:return bn(e);case 481:return globalThis.encodeURIComponent(qe(e));default:return g(e,"base16")}}function We(r,e){switch(c(r).code){case 4:return Pt(e);case 41:return Pt(e);case 42:return je(e);case 6:case 273:case 33:case 132:return Je(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return je(e);case 421:return xn(e);case 444:return vn(e);case 445:return En(e);case 466:return gn(e);case 481:return je(globalThis.decodeURIComponent(e));default:return Me(e,"base16")}}var Re=Object.values(ee).map(r=>r.decoder),mn=function(){let r=Re[0].or(Re[1]);return Re.slice(2).forEach(e=>r=r.or(e)),r}();function Pt(r){if(!ce(r))throw new Error("invalid ip address");return Be(r)}function wn(r){let e=Ut(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!ce(e))throw new Error("invalid ip address");return e}function Je(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function Tt(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function je(r){let e=Me(r),t=Uint8Array.from(H(e.length));return z([t,e],t.length+e.length)}function qe(r){let e=O(r);if(r=r.slice(T(e)),r.length!==e)throw new Error("inconsistent lengths");return g(r)}function xn(r){let e;r[0]==="Q"||r[0]==="1"?e=oe(x.decode(`z${r}`)).bytes:e=L.parse(r).multihash.bytes;let t=Uint8Array.from(H(e.length));return z([t,e],t.length+e.length)}function gn(r){let e=mn.decode(r),t=Uint8Array.from(H(e.length));return z([t,e],t.length+e.length)}function bn(r){let e=O(r),t=r.slice(T(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+g(t,"base64url")}function yn(r){let e=O(r),t=r.slice(T(e));if(t.length!==e)throw new Error("inconsistent lengths");return g(t,"base58btc")}function vn(r){let e=r.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 t=N.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=Je(n);return z([t,o],t.length+o.length)}function En(r){let e=r.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 t=N.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=Je(n);return z([t,o],t.length+o.length)}function Ct(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=g(e,"base32"),o=Tt(t);return`${n}:${o}`}function $t(r){r=He(r);let e=[],t=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let i=0;i<o.length;i++){let a=o[i],s=c(a);if(s.size===0){e.push([s.code]),t.push([s.code]);continue}if(i++,i>=o.length)throw Nt("invalid address: "+r);if(s.path===!0){n=He(o.slice(i).join("/")),e.push([s.code,We(s.code,n)]),t.push([s.code,n]);break}let u=We(s.code,o[i]);e.push([s.code,u]),t.push([s.code,Ge(s.code,u)])}return{string:Ft(t),bytes:Qe(e),tuples:e,stringTuples:t,path:n}}function Xe(r){let e=[],t=[],n=null,o=0;for(;o<r.length;){let i=O(r,o),a=T(i),s=c(i),u=An(s,r.slice(o+a));if(u===0){e.push([i]),t.push([i]),o+=a;continue}let m=r.slice(o+a,o+a+u);if(o+=u+a,o>r.length)throw Nt("Invalid address Uint8Array: "+g(r,"base16"));e.push([i,m]);let f=Ge(i,m);if(t.push([i,f]),s.path===!0){n=f;break}}return{bytes:Uint8Array.from(r),string:Ft(t),tuples:e,stringTuples:t,path:n}}function Ft(r){let e=[];return r.map(t=>{let n=c(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),He(e.join("/"))}function Qe(r){return z(r.map(e=>{let t=c(e[0]),n=Uint8Array.from(H(t.code));return e.length>1&&e[1]!=null&&(n=z([n,e[1]])),n}))}function An(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=O(e instanceof Uint8Array?e:Uint8Array.from(e));return t+T(t)}}function He(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}function Nt(r){return new Error("Error parsing address: "+r)}var Sn=Symbol.for("nodejs.util.inspect.custom"),Ze=Symbol.for("@multiformats/js-multiaddr/multiaddr"),In=[c("dns").code,c("dns4").code,c("dns6").code,c("dnsaddr").code],Ke=class extends Error{constructor(e="No available resolver"){super(e),this.name="NoAvailableResolverError"}},de=class r{bytes;#t;#e;#r;#n;[Ze]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=Xe(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=$t(e)}else if(kt(e))t=Xe(e.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=t.bytes,this.#t=t.string,this.#e=t.tuples,this.#r=t.stringTuples,this.#n=t.path}toString(){return this.#t}toJSON(){return this.toString()}toOptions(){let e,t,n,o,i="",a=c("tcp"),s=c("udp"),u=c("ip4"),m=c("ip6"),f=c("dns6"),E=c("ip6zone");for(let[y,d]of this.stringTuples())y===E.code&&(i=`%${d??""}`),In.includes(y)&&(t=a.name,o=443,n=`${d??""}${i}`,e=y===f.code?6:4),(y===a.code||y===s.code)&&(t=c(y).name,o=parseInt(d??"")),(y===u.code||y===m.code)&&(t=c(y).name,n=`${d??""}${i}`,e=y===m.code?6:4);if(e==null||t==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:t,port:o}}protos(){return this.#e.map(([e])=>Object.assign({},c(e)))}protoCodes(){return this.#e.map(([e])=>e)}protoNames(){return this.#e.map(([e])=>c(e).name)}tuples(){return this.#e}stringTuples(){return this.#r}encapsulate(e){return e=new r(e),new r(this.toString()+e.toString())}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,o))}decapsulateCode(e){let t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new r(Qe(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,o])=>{n===Q.p2p.code&&e.push([n,o]),n===Q["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?g(x.decode(`z${n}`),"base58btc"):g(L.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(e){return ut(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(i=>i.resolvable);if(t==null)return[this];let n=zt.get(t.name);if(n==null)throw new Ke(`no available resolver for ${t.name}`);return(await n(this,e)).map(i=>te(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(e){let t=(e??this).protos();return!(t.length!==2||t[0].code!==4&&t[0].code!==41||t[1].code!==6&&t[1].code!==273)}[Sn](){return`Multiaddr(${this.#t})`}};var zt=new Map;function kt(r){return!!r?.[Ze]}function te(r){return new de(r)}var Un=[c("tcp").code,c("dns").code,c("dnsaddr").code,c("dns4").code,c("dns6").code];function Dt(r){return Mt("sni",r)?.[1]}function Vt(r){let e=Mt("tcp",r)?.[1];return e==null?"":`:${e}`}function Mt(r,e){let t;try{t=c(r).code}catch{return}for(let[n,o]of e)if(n===t&&o!=null)return[n,o]}function Lt(r){return r.some(([e,t])=>e===c("tls").code)}function I(r,e,t){let n=Bt[c(r).name];if(n==null)throw new Error(`Can't interpret protocol ${c(r).name}`);let o=n(e,t);return r===c("ip6").code?`[${o}]`:o}var Bt={ip4:(r,e)=>r,ip6:(r,e)=>e.length===0?r:`[${r}]`,tcp:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");return`tcp://${I(t[0],t[1]??"",e)}:${r}`},udp:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");return`udp://${I(t[0],t[1]??"",e)}:${r}`},dnsaddr:(r,e)=>r,dns4:(r,e)=>r,dns6:(r,e)=>r,dns:(r,e)=>r,ipfs:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");return`${I(t[0],t[1]??"",e)}`},p2p:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");return`${I(t[0],t[1]??"",e)}`},http:(r,e)=>{let t=Lt(e),n=Dt(e),o=Vt(e);if(t&&n!=null)return`https://${n}${o}`;let i=t?"https://":"http://",a=e.pop();if(a==null)throw new Error("Unexpected end of multiaddr");let s=I(a[0],a[1]??"",e);return s=s.replace("tcp://",""),`${i}${s}`},"http-path":(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");let n=I(t[0],t[1]??"",e),o=decodeURIComponent(r);return`${n}/${o}`},tls:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");return I(t[0],t[1]??"",e)},sni:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");return I(t[0],t[1]??"",e)},https:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");let n=I(t[0],t[1]??"",e);return n=n.replace("tcp://",""),`https://${n}`},ws:(r,e)=>{let t=Lt(e),n=Dt(e),o=Vt(e);if(t&&n!=null)return`wss://${n}${o}`;let i=t?"wss://":"ws://",a=e.pop();if(a==null)throw new Error("Unexpected end of multiaddr");let s=I(a[0],a[1]??"",e);return s=s.replace("tcp://",""),`${i}${s}`},wss:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");let n=I(t[0],t[1]??"",e);return n=n.replace("tcp://",""),`wss://${n}`}};function Pn(r,e){let n=te(r).stringTuples(),o=n.pop();if(o==null)throw new Error("Unexpected end of multiaddr");let i=c(o[0]),a=Bt[i.name];if(a==null)throw new Error(`No interpreter found for ${i.name}`);let s=a(o[1]??"",n);return e?.assumeHttp!==!1&&Un.includes(o[0])&&(s=s.replace(/^.*:\/\//,""),o[1]==="443"?s=`https://${s}`:s=`http://${s}`),(s.startsWith("http://")||s.startsWith("https://")||s.startsWith("ws://")||s.startsWith("wss://"))&&(s=new URL(s).toString(),s.endsWith("/")&&(s=s.substring(0,s.length-1))),s}return Gt(Cn);})();
"use strict";var MultiformatsMultiaddrToUri=(()=>{var Ee=Object.defineProperty;var rr=Object.getOwnPropertyDescriptor;var nr=Object.getOwnPropertyNames;var or=Object.prototype.hasOwnProperty;var g=(r,e)=>{for(var t in e)Ee(r,t,{get:e[t],enumerable:!0})},ir=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of nr(e))!or.call(r,o)&&o!==t&&Ee(r,o,{get:()=>e[o],enumerable:!(n=rr(e,o))||n.enumerable});return r};var sr=r=>ir(Ee({},"__esModule",{value:!0}),r);var mo={};g(mo,{multiaddrToUri:()=>ho});var Ie={};g(Ie,{base10:()=>fr});var wo=new Uint8Array(0);function lt(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function _(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function pt(r){return new TextEncoder().encode(r)}function ut(r){return new TextDecoder().decode(r)}function ar(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var i=r.charAt(o),s=i.charCodeAt(0);if(t[s]!==255)throw new TypeError(i+" is ambiguous");t[s]=o}var a=r.length,c=r.charAt(0),d=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function O(l){if(l instanceof Uint8Array||(ArrayBuffer.isView(l)?l=new Uint8Array(l.buffer,l.byteOffset,l.byteLength):Array.isArray(l)&&(l=Uint8Array.from(l))),!(l instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(l.length===0)return"";for(var w=0,L=0,v=0,I=l.length;v!==I&&l[v]===0;)v++,w++;for(var T=(I-v)*f+1>>>0,y=new Uint8Array(T);v!==I;){for(var P=l[v],N=0,D=T-1;(P!==0||N<L)&&D!==-1;D--,N++)P+=256*y[D]>>>0,y[D]=P%a>>>0,P=P/a>>>0;if(P!==0)throw new Error("Non-zero carry");L=N,v++}for(var A=T-L;A!==T&&y[A]===0;)A++;for(var pe=c.repeat(w);A<T;++A)pe+=r.charAt(y[A]);return pe}function R(l){if(typeof l!="string")throw new TypeError("Expected String");if(l.length===0)return new Uint8Array;var w=0;if(l[w]!==" "){for(var L=0,v=0;l[w]===c;)L++,w++;for(var I=(l.length-w)*d+1>>>0,T=new Uint8Array(I);l[w];){var y=t[l.charCodeAt(w)];if(y===255)return;for(var P=0,N=I-1;(y!==0||P<v)&&N!==-1;N--,P++)y+=a*T[N]>>>0,T[N]=y%256>>>0,y=y/256>>>0;if(y!==0)throw new Error("Non-zero carry");v=P,w++}if(l[w]!==" "){for(var D=I-v;D!==I&&T[D]===0;)D++;for(var A=new Uint8Array(L+(I-D)),pe=L;D!==I;)A[pe++]=T[D++];return A}}}function tr(l){var w=R(l);if(w)return w;throw new Error(`Non-${e} character`)}return{encode:O,decodeUnsafe:R,decode:tr}}var cr=ar,dr=cr,ht=dr;var Ce=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},ve=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let o=t.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 mt(this,e)}},De=class{decoders;constructor(e){this.decoders=e}or(e){return mt(this,e)}decode(e){let t=e[0],n=this.decoders[t];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 mt(r,e){return new De({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Se=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new Ce(e,t,n),this.decoder=new ve(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function W({name:r,prefix:e,encode:t,decode:n}){return new Se(r,e,t,n)}function B({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=ht(t,r);return W({prefix:e,name:r,encode:n,decode:i=>_(o(i))})}function lr(r,e,t,n){let o=r.length;for(;r[o-1]==="=";)--o;let i=new Uint8Array(o*t/8|0),s=0,a=0,c=0;for(let d=0;d<o;++d){let f=e[r[d]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|f,s+=t,s>=8&&(s-=8,i[c++]=255&a>>s)}if(s>=t||(255&a<<8-s)!==0)throw new SyntaxError("Unexpected end of data");return i}function pr(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,i="",s=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],s+=8;s>t;)s-=t,i+=e[o&a>>s];if(s!==0&&(i+=e[o&a<<t-s]),n)for(;(i.length*t&7)!==0;)i+="=";return i}function ur(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}function u({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let o=ur(n);return W({prefix:e,name:r,encode(i){return pr(i,n,t)},decode(i){return lr(i,o,t,r)}})}var fr=B({prefix:"9",name:"base10",alphabet:"0123456789"});var Te={};g(Te,{base16:()=>hr,base16upper:()=>mr});var hr=u({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),mr=u({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Pe={};g(Pe,{base2:()=>xr});var xr=u({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Oe={};g(Oe,{base256emoji:()=>Er});var xt=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}"),wr=xt.reduce((r,e,t)=>(r[t]=e,r),[]),gr=xt.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function br(r){return r.reduce((e,t)=>(e+=wr[t],e),"")}function yr(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=gr[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var Er=W({prefix:"\u{1F680}",name:"base256emoji",encode:br,decode:yr});var Ae={};g(Ae,{base32:()=>z,base32hex:()=>Sr,base32hexpad:()=>Tr,base32hexpadupper:()=>Pr,base32hexupper:()=>Ir,base32pad:()=>vr,base32padupper:()=>Dr,base32upper:()=>Cr,base32z:()=>Or});var z=u({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Cr=u({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),vr=u({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Dr=u({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Sr=u({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ir=u({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Tr=u({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Pr=u({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Or=u({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var _e={};g(_e,{base36:()=>K,base36upper:()=>Ar});var K=B({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Ar=B({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ue={};g(Ue,{base58btc:()=>E,base58flickr:()=>_r});var E=B({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),_r=B({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Be={};g(Be,{base64:()=>Ur,base64pad:()=>Nr,base64url:()=>Ne,base64urlpad:()=>Br});var Ur=u({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Nr=u({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ne=u({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Br=u({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var ze={};g(ze,{base8:()=>zr});var zr=u({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var $e={};g($e,{identity:()=>$r});var $r=W({prefix:"\0",name:"identity",encode:r=>ut(r),decode:r=>pt(r)});var No=new TextEncoder,Bo=new TextDecoder;var Re={};g(Re,{identity:()=>sn});var Lr=bt,wt=128,Vr=127,Mr=~Vr,kr=Math.pow(2,31);function bt(r,e,t){e=e||[],t=t||0;for(var n=t;r>=kr;)e[t++]=r&255|wt,r/=128;for(;r&Mr;)e[t++]=r&255|wt,r>>>=7;return e[t]=r|0,bt.bytes=t-n+1,e}var Wr=Fe,jr=128,gt=127;function Fe(r,n){var t=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw Fe.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&gt)<<o:(s&gt)*Math.pow(2,o),o+=7}while(s>=jr);return Fe.bytes=i-n,t}var qr=Math.pow(2,7),Hr=Math.pow(2,14),Gr=Math.pow(2,21),Xr=Math.pow(2,28),Jr=Math.pow(2,35),Qr=Math.pow(2,42),Kr=Math.pow(2,49),Zr=Math.pow(2,56),Yr=Math.pow(2,63),en=function(r){return r<qr?1:r<Hr?2:r<Gr?3:r<Xr?4:r<Jr?5:r<Qr?6:r<Kr?7:r<Zr?8:r<Yr?9:10},tn={encode:Lr,decode:Wr,encodingLength:en},rn=tn,Z=rn;function Y(r,e=0){return[Z.decode(r,e),Z.decode.bytes]}function j(r,e,t=0){return Z.encode(r,e,t),e}function q(r){return Z.encodingLength(r)}function V(r,e){let t=e.byteLength,n=q(r),o=n+q(t),i=new Uint8Array(o+t);return j(r,i,0),j(t,i,n),i.set(e,o),new H(r,t,e,i)}function yt(r){let e=_(r),[t,n]=Y(e),[o,i]=Y(e.subarray(n)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new H(t,o,s,e)}function Et(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&lt(r.bytes,t.bytes)}}var H=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};var Ct=0,nn="identity",vt=_;function on(r){return V(Ct,vt(r))}var sn={code:Ct,name:nn,encode:vt,digest:on};var Me={};g(Me,{sha256:()=>an,sha512:()=>cn});function Ve({name:r,code:e,encode:t}){return new Le(r,e,t)}var Le=class{name;code;encode;constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?V(this.code,t):t.then(n=>V(this.code,n))}else throw Error("Unknown type, must be binary type")}};function St(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var an=Ve({name:"sha2-256",code:18,encode:St("SHA-256")}),cn=Ve({name:"sha2-512",code:19,encode:St("SHA-512")});function It(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return ln(t,ke(r),e??E.encoder);default:return pn(t,ke(r),e??z.encoder)}}var Tt=new WeakMap;function ke(r){let e=Tt.get(r);if(e==null){let t=new Map;return Tt.set(r,t),t}return e}var $=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,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:t}=this;if(e!==te)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==un)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}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:t}=this.multihash,n=V(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&Et(e.multihash,n.multihash)}toString(e){return It(this,e)}toJSON(){return{"/":It(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 t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:i,bytes:s}=t;return new r(n,o,i,s??Pt(n,o,i.bytes))}else if(t[fn]===!0){let{version:n,multihash:o,code:i}=t,s=yt(o);return r.create(n,i,s)}else return null}static create(e,t,n){if(typeof t!="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(t!==te)throw new Error(`Version 0 CID must use dag-pb (code: ${te}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=Pt(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,te,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=_(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let i=o.subarray(t.multihashSize-t.digestSize),s=new H(t.multihashCode,t.digestSize,i,o);return[t.version===0?r.createV0(s):r.createV1(t.codec,s),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[O,R]=Y(e.subarray(t));return t+=R,O},o=n(),i=te;if(o===18?(o=0,t=0):i=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let s=t,a=n(),c=n(),d=t+c,f=d-s;return{version:o,codec:i,multihashCode:a,digestSize:c,multihashSize:f,size:d}}static parse(e,t){let[n,o]=dn(e,t),i=r.decode(o);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return ke(i).set(n,e),i}};function dn(r,e){switch(r[0]){case"Q":{let t=e??E;return[E.prefix,t.decode(`${E.prefix}${r}`)]}case E.prefix:{let t=e??E;return[E.prefix,t.decode(r)]}case z.prefix:{let t=e??z;return[z.prefix,t.decode(r)]}case K.prefix:{let t=e??K;return[K.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function ln(r,e,t){let{prefix:n}=t;if(n!==E.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let i=t.encode(r).slice(1);return e.set(n,i),i}else return o}function pn(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let i=t.encode(r);return e.set(n,i),i}else return o}var te=112,un=18;function Pt(r,e,t){let n=q(r),o=n+q(e),i=new Uint8Array(o+t.byteLength);return j(r,i,0),j(e,i,n),i.set(t,o),i}var fn=Symbol.for("@ipld/js-cid/CID");var re={...$e,...Pe,...ze,...Ie,...Te,...Ae,..._e,...Ue,...Be,...Oe},ri={...Me,...Re};function ne(r=0){return new Uint8Array(r)}function At(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Ot=At("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),We=At("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=ne(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),hn={utf8:Ot,"utf-8":Ot,hex:re.base16,latin1:We,ascii:We,binary:We,...re},fe=hn;function C(r,e="utf8"){let t=fe[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var m=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},U=class extends Error{static name="ValidationError";name="ValidationError"},oe=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},he=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function _t(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function F(r,e="utf8"){let t=fe[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}var mn=Math.pow(2,7),xn=Math.pow(2,14),wn=Math.pow(2,21),je=Math.pow(2,28),qe=Math.pow(2,35),He=Math.pow(2,42),Ge=Math.pow(2,49),p=128,x=127;function G(r){if(r<mn)return 1;if(r<xn)return 2;if(r<wn)return 3;if(r<je)return 4;if(r<qe)return 5;if(r<He)return 6;if(r<Ge)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Xe(r,e,t=0){switch(G(r)){case 8:e[t++]=r&255|p,r/=128;case 7:e[t++]=r&255|p,r/=128;case 6:e[t++]=r&255|p,r/=128;case 5:e[t++]=r&255|p,r/=128;case 4:e[t++]=r&255|p,r>>>=7;case 3:e[t++]=r&255|p,r>>>=7;case 2:e[t++]=r&255|p,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function gn(r,e){let t=r[e],n=0;if(n+=t&x,t<p||(t=r[e+1],n+=(t&x)<<7,t<p)||(t=r[e+2],n+=(t&x)<<14,t<p)||(t=r[e+3],n+=(t&x)<<21,t<p)||(t=r[e+4],n+=(t&x)*je,t<p)||(t=r[e+5],n+=(t&x)*qe,t<p)||(t=r[e+6],n+=(t&x)*He,t<p)||(t=r[e+7],n+=(t&x)*Ge,t<p))return n;throw new RangeError("Could not decode varint")}function bn(r,e){let t=r.get(e),n=0;if(n+=t&x,t<p||(t=r.get(e+1),n+=(t&x)<<7,t<p)||(t=r.get(e+2),n+=(t&x)<<14,t<p)||(t=r.get(e+3),n+=(t&x)<<21,t<p)||(t=r.get(e+4),n+=(t&x)*je,t<p)||(t=r.get(e+5),n+=(t&x)*qe,t<p)||(t=r.get(e+6),n+=(t&x)*He,t<p)||(t=r.get(e+7),n+=(t&x)*Ge,t<p))return n;throw new RangeError("Could not decode varint")}function Je(r,e=0){return r instanceof Uint8Array?gn(r,e):bn(r,e)}function ie(r,e){e==null&&(e=r.reduce((o,i)=>o+i.length,0));let t=ne(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return t}var me=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,n=e();return n===void 0&&(this.index=t),n}parseWith(e){let t=e();if(this.index===this.input.length)return t}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 t=this.readChar();if(t===e)return t})}readSeparator(e,t,n){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,t,n,o){return this.readAtomically(()=>{let i=0,s=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",d=2**(8*o)-1;for(;;){let f=this.readAtomically(()=>{let O=this.readChar();if(O===void 0)return;let R=Number.parseInt(O,e);if(!Number.isNaN(R))return R});if(f===void 0)break;if(i*=e,i+=f,i>d||(s+=1,t!==void 0&&s>t))return}if(s!==0)return!n&&c&&s>1?void 0:i})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;t<e.length;t++){let n=this.readSeparator(".",t,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[t]=n}return e})}readIPv6Addr(){let e=t=>{for(let n=0;n<t.length/2;n++){let o=n*2;if(n<t.length-3){let s=this.readSeparator(":",n,()=>this.readIPv4Addr());if(s!==void 0)return t[o]=s[0],t[o+1]=s[1],t[o+2]=s[2],t[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];t[o]=i>>8,t[o+1]=i&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,o]=e(t);if(n===16)return t;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 t.set(i.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var En=45,Cn=15,xe=new me;function Qe(r){if(!(r.length>Cn))return xe.new(r).parseWith(()=>xe.readIPv4Addr())}function Ke(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>En))return xe.new(r).parseWith(()=>xe.readIPv6Addr())}function we(r){return!!Qe(r)}function Nt(r){return!!Ke(r)}function Ye(r){return e=>C(e,r)}function et(r){return e=>F(e,r)}function X(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function M(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(e)}function Bt(r){let e=r.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 t=F(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=M(n);return ie([t,o],t.length+o.length)}function zt(r){let e=r.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 t=z.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=M(n);return ie([t,o],t.length+o.length)}function tt(r){let e=r.subarray(0,r.length-2),t=r.subarray(r.length-2),n=C(e,"base32"),o=X(t);return`${n}:${o}`}var rt=function(r){r=r.toString().trim();let e=new Uint8Array(4);return r.split(/\./g).forEach((t,n)=>{let o=parseInt(t,10);if(isNaN(o)||o<0||o>255)throw new m("Invalid byte value in IP address");e[n]=o}),e},$t=function(r){let e=0;r=r.toString().trim();let t=r.split(":",8),n;for(n=0;n<t.length;n++){let i=we(t[n]),s;i&&(s=rt(t[n]),t[n]=C(s.subarray(0,2),"base16")),s!=null&&++n<8&&t.splice(n,0,C(s.subarray(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let i=[n,1];for(n=9-t.length;n>0;n--)i.push("0");t.splice.apply(t,i)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){t[n]===""&&(t[n]="0");let i=parseInt(t[n],16);if(isNaN(i)||i<0||i>65535)throw new m("Invalid byte value in IP address");o[e++]=i>>8&255,o[e++]=i&255}return o},Ft=function(r){if(r.byteLength!==4)throw new m("IPv4 address was incorrect length");let e=[];for(let t=0;t<r.byteLength;t++)e.push(r[t]);return e.join(".")},Rt=function(r){if(r.byteLength!==16)throw new m("IPv6 address was incorrect length");let e=[];for(let n=0;n<r.byteLength;n+=2){let o=r[n],i=r[n+1],s=`${o.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}`;e.push(s)}let t=e.join(":");try{let n=new URL(`http://[${t}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new m(`Invalid IPv6 address "${t}"`)}};function Lt(r){try{let e=new URL(`http://[${r}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new m(`Invalid IPv6 address "${r}"`)}}var Ze=Object.values(re).map(r=>r.decoder),vn=function(){let r=Ze[0].or(Ze[1]);return Ze.slice(2).forEach(e=>r=r.or(e)),r}();function Vt(r){return vn.decode(r)}function Mt(r){return e=>r.encoder.encode(e)}function Dn(r){if(parseInt(r).toString()!==r)throw new U("Value must be an integer")}function Sn(r){if(r<0)throw new U("Value must be a positive integer, or zero")}function In(r){return e=>{if(e>r)throw new U(`Value must be smaller than or equal to ${r}`)}}function Tn(...r){return e=>{for(let t of r)t(e)}}var se=Tn(Dn,Sn,In(65535));var h=-1,nt=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(e){let t;if(typeof e=="string"?t=this.protocolsByName.get(e):t=this.protocolsByCode.get(e),t==null)throw new he(`Protocol ${e} was unknown`);return t}addProtocol(e){this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),e.aliases?.forEach(t=>{this.protocolsByName.set(t,e)})}removeProtocol(e){let t=this.protocolsByCode.get(e);t!=null&&(this.protocolsByCode.delete(t.code),this.protocolsByName.delete(t.name),t.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},b=new nt,ro=[{code:4,name:"ip4",size:32,valueToBytes:rt,bytesToValue:Ft,validate:r=>{if(!we(r))throw new U(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:M,bytesToValue:X,validate:se},{code:273,name:"udp",size:16,valueToBytes:M,bytesToValue:X,validate:se},{code:33,name:"dccp",size:16,valueToBytes:M,bytesToValue:X,validate:se},{code:41,name:"ip6",size:128,valueToBytes:$t,bytesToValue:Rt,stringToValue:Lt,validate:r=>{if(!Nt(r))throw new U(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:h},{code:43,name:"ipcidr",size:8,bytesToValue:Ye("base10"),valueToBytes:et("base10")},{code:53,name:"dns",size:h,resolvable:!0},{code:54,name:"dns4",size:h,resolvable:!0},{code:55,name:"dns6",size:h,resolvable:!0},{code:56,name:"dnsaddr",size:h,resolvable:!0},{code:132,name:"sctp",size:16,valueToBytes:M,bytesToValue:X,validate:se},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:h,path:!0,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:h,bytesToValue:Ye("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?et("base58btc")(r):$.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:tt,valueToBytes:Bt},{code:445,name:"onion3",size:296,bytesToValue:tt,valueToBytes:zt},{code:446,name:"garlic64",size:h},{code:447,name:"garlic32",size:h},{code:448,name:"tls"},{code:449,name:"sni",size:h},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:h,bytesToValue:Mt(Ne),valueToBytes:Vt},{code:480,name:"http"},{code:481,name:"http-path",size:h,stringToValue:r=>`/${decodeURIComponent(r)}`,valueToString:r=>encodeURIComponent(r.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:h}];ro.forEach(r=>{b.addProtocol(r)});function kt(r){let e=[],t=0;for(;t<r.length;){let n=Je(r,t),o=b.getProtocol(n),i=G(n),s=no(o,r,t+i),a=0;s>0&&o.size===h&&(a=G(s));let c=i+a+s,d={code:n,name:o.name,bytes:r.subarray(t,t+c)};if(s>0){let f=t+i+a,O=r.subarray(f,f+s);d.value=o.bytesToValue?.(O)??C(O)}e.push(d),t+=c}return e}function Wt(r){let e=0,t=[];for(let n of r){if(n.bytes==null){let o=b.getProtocol(n.code),i=G(n.code),s,a=0,c=0;n.value!=null&&(s=o.valueToBytes?.(n.value)??F(n.value),a=s.byteLength,o.size===h&&(c=G(a)));let d=new Uint8Array(i+c+a),f=0;Xe(n.code,d,f),f+=i,s!=null&&(o.size===h&&(Xe(a,d,f),f+=c),d.set(s,f)),n.bytes=d}t.push(n.bytes),e+=n.bytes.byteLength}return ie(t,e)}function jt(r){if(r.charAt(0)!=="/")throw new m('String multiaddr must start with "/"');let e=[],t="protocol",n="",o="";for(let i=1;i<r.length;i++){let s=r.charAt(i);s!=="/"&&(t==="protocol"?o+=r.charAt(i):n+=r.charAt(i));let a=i===r.length-1;if(s==="/"||a){let c=b.getProtocol(o);if(t==="protocol"){if(c.size==null||c.size===0){e.push({code:c.code,name:c.name}),n="",o="",t="protocol";continue}else if(a)throw new m(`Component ${o} was missing value`);t="value"}else if(t==="value"){let d={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new m(`Component ${o} was missing value`);d.value=c.stringToValue?.(n)??n}e.push(d),n="",o="",t="protocol"}}}if(o!==""&&n!=="")throw new m("Incomplete multiaddr");return e}function qt(r){return`/${r.flatMap(e=>{if(e.value==null)return e.name;let t=b.getProtocol(e.code);if(t==null)throw new m(`Unknown protocol code ${e.code}`);return[e.name,t.valueToString?.(e.value)??e.value]}).join("/")}`}function no(r,e,t){return r.size==null||r.size===0?0:r.size>0?r.size/8:Je(e,t)}var oo=Symbol.for("nodejs.util.inspect.custom"),dt=Symbol.for("@multiformats/multiaddr"),io=[53,54,55,56],ct=class extends Error{constructor(e="No available resolver"){super(e),this.name="NoAvailableResolverError"}};function so(r){if(r==null&&(r="/"),Gt(r))return r.getComponents();if(r instanceof Uint8Array)return kt(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),jt(r);if(Array.isArray(r))return r;throw new m("Must be a string, Uint8Array, Component[], or another Multiaddr")}var ye=class r{[dt]=!0;#e;#t;#r;constructor(e="/",t={}){this.#e=so(e),t.validate!==!1&&ao(this)}get bytes(){return this.#r==null&&(this.#r=Wt(this.#e)),this.#r}toString(){return this.#t==null&&(this.#t=qt(this.#e)),this.#t}toJSON(){return this.toString()}toOptions(){let e,t,n,o,i="";for(let{code:a,name:c,value:d}of this.#e)a===42&&(i=`%${d??""}`),io.includes(a)&&(t="tcp",o=443,n=`${d??""}${i}`,e=a===55?6:4),(a===6||a===273)&&(t=c==="tcp"?"tcp":"udp",o=parseInt(d??"")),(a===4||a===41)&&(t="tcp",n=`${d??""}${i}`,e=a===41?6:4);if(e==null||t==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:t,port:o}}getComponents(){return[...this.#e]}protos(){return this.#e.map(({code:e,value:t})=>{let n=b.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:t})=>{if(t==null)return[e];let n=b.getProtocol(e),o=[e];return t!=null&&o.push(n.valueToBytes?.(t)??F(t)),o})}stringTuples(){return this.#e.map(({code:e,value:t})=>t==null?[e]:[e,t])}encapsulate(e){let t=new r(e);return new r([...this.#e,...t.getComponents()],{validate:!1})}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new oe(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,o),{validate:!1})}decapsulateCode(e){let t;for(let n=this.#e.length-1;n>-1;n--)if(this.#e[n].code===e){t=n;break}return new r(this.#e.slice(0,t),{validate:!1})}getPeerId(){try{let e=[];this.#e.forEach(({code:n,value:o})=>{n===421&&e.push([n,o]),n===290&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?C(E.decode(`z${n}`),"base58btc"):C($.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){for(let e of this.#e)if(b.getProtocol(e.code).path)return e.value??null;return null}equals(e){return _t(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(i=>i.resolvable);if(t==null)return[this];let n=Ht.get(t.name);if(n==null)throw new ct(`no available resolver for ${t.name}`);return(await n(this,e)).map(i=>le(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)}[oo](){return`Multiaddr(${this.toString()})`}};function ao(r){r.getComponents().forEach(e=>{let t=b.getProtocol(e.code);e.value!=null&&t.validate?.(e.value)})}var fs=parseInt("0xFFFF",16),hs=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var Ht=new Map;function Gt(r){return!!r?.[dt]}function le(r){return new ye(r)}var fo=[6,53,56,54,55];function Qt(r){return Yt("sni",r)?.value}function Kt(r){let e=Yt("tcp",r)?.value;return e==null?"":`:${e}`}function Yt(r,e){return e.find(t=>t.name===r)}function Zt(r){return r.some(({code:e})=>e===448)}function S(r,e){let t=er[r.name];if(t==null)throw new Error(`Can't interpret protocol ${r.name}`);let n=t(r,e);return r.code===41?`[${n}]`:n}var er={ip4:(r,e)=>r.value,ip6:(r,e)=>e.length===0?r.value:`[${r.value}]`,tcp:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");return`tcp://${S(t,e)}:${r.value}`},udp:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");return`udp://${S(t,e)}:${r.value}`},dnsaddr:(r,e)=>r.value,dns4:(r,e)=>r.value,dns6:(r,e)=>r.value,dns:(r,e)=>r.value,ipfs:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");return`${S(t,e)}`},p2p:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");return`${S(t,e)}`},http:(r,e)=>{let t=Zt(e),n=Qt(e),o=Kt(e);if(t&&n!=null)return`https://${n}${o}`;let i=t?"https://":"http://",s=e.pop();if(s==null)throw new Error("Unexpected end of multiaddr");let a=S(s,e);return a=a?.replace("tcp://",""),`${i}${a}`},"http-path":(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");let n=S(t,e),o=decodeURIComponent(r.value??"");return`${n}${o}`},tls:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");return S(t,e)},sni:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");return S(t,e)},https:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");let n=S(t,e);return n=n?.replace("tcp://",""),`https://${n}`},ws:(r,e)=>{let t=Zt(e),n=Qt(e),o=Kt(e);if(t&&n!=null)return`wss://${n}${o}`;let i=t?"wss://":"ws://",s=e.pop();if(s==null)throw new Error("Unexpected end of multiaddr");let a=S(s,e);return a=a?.replace("tcp://",""),`${i}${a}`},wss:(r,e)=>{let t=e.pop();if(t==null)throw new Error("Unexpected end of multiaddr");let n=S(t,e);return n=n?.replace("tcp://",""),`wss://${n}`}};function ho(r,e){let n=le(r).getComponents(),o=n.pop();if(o==null)throw new Error("Unexpected end of multiaddr");let i=er[o.name];if(i==null)throw new Error(`No interpreter found for ${o.name}`);let s=i(o,n)??"";return e?.assumeHttp!==!1&&fo.includes(o.code)&&(s=s.replace(/^.*:\/\//,""),o.value==="443"?s=`https://${s}`:s=`http://${s}`),(s.startsWith("http://")||s.startsWith("https://")||s.startsWith("ws://")||s.startsWith("wss://"))&&(s=new URL(s).toString(),s.endsWith("/")&&(s=s.substring(0,s.length-1))),s}return sr(mo);})();
return MultiformatsMultiaddrToUri}));
//# sourceMappingURL=index.min.js.map

@@ -31,15 +31,15 @@ /**

*/
import { multiaddr, protocols } from '@multiformats/multiaddr';
import { CODE_TCP, CODE_DNS, CODE_DNS4, CODE_DNS6, CODE_DNSADDR, multiaddr, CODE_TLS, CODE_IP6 } from '@multiformats/multiaddr';
const ASSUME_HTTP_CODES = [
protocols('tcp').code,
protocols('dns').code,
protocols('dnsaddr').code,
protocols('dns4').code,
protocols('dns6').code
CODE_TCP,
CODE_DNS,
CODE_DNSADDR,
CODE_DNS4,
CODE_DNS6
];
function extractSNI(ma) {
return extractTuple('sni', ma)?.[1];
return extractTuple('sni', ma)?.value;
}
function extractPort(ma) {
const port = extractTuple('tcp', ma)?.[1];
const port = extractTuple('tcp', ma)?.value;
if (port == null) {

@@ -51,26 +51,14 @@ return '';

function extractTuple(name, ma) {
let code;
try {
code = protocols(name).code;
}
catch (e) {
// No support for protocol in multiaddr
return;
}
for (const [proto, value] of ma) {
if (proto === code && value != null) {
return [proto, value];
}
}
return ma.find(component => component.name === name);
}
function hasTLS(ma) {
return ma.some(([proto, _]) => proto === protocols('tls').code);
return ma.some(({ code }) => code === CODE_TLS);
}
function interpretNext(headProtoCode, headProtoVal, restMa) {
const interpreter = interpreters[protocols(headProtoCode).name];
function interpretNext(head, rest) {
const interpreter = interpreters[head.name];
if (interpreter == null) {
throw new Error(`Can't interpret protocol ${protocols(headProtoCode).name}`);
throw new Error(`Can't interpret protocol ${head.name}`);
}
const restVal = interpreter(headProtoVal, restMa);
if (headProtoCode === protocols('ip6').code) {
const restVal = interpreter(head, rest);
if (head.code === CODE_IP6) {
return `[${restVal}]`;

@@ -81,45 +69,45 @@ }

const interpreters = {
ip4: (value, restMa) => value,
ip6: (value, restMa) => {
if (restMa.length === 0) {
return value;
ip4: (head, rest) => head.value,
ip6: (head, rest) => {
if (rest.length === 0) {
return head.value;
}
return `[${value}]`;
return `[${head.value}]`;
},
tcp: (value, restMa) => {
const tailProto = restMa.pop();
if (tailProto == null) {
tcp: (head, rest) => {
const tail = rest.pop();
if (tail == null) {
throw new Error('Unexpected end of multiaddr');
}
return `tcp://${interpretNext(tailProto[0], tailProto[1] ?? '', restMa)}:${value}`;
return `tcp://${interpretNext(tail, rest)}:${head.value}`;
},
udp: (value, restMa) => {
const tailProto = restMa.pop();
if (tailProto == null) {
udp: (head, rest) => {
const tail = rest.pop();
if (tail == null) {
throw new Error('Unexpected end of multiaddr');
}
return `udp://${interpretNext(tailProto[0], tailProto[1] ?? '', restMa)}:${value}`;
return `udp://${interpretNext(tail, rest)}:${head.value}`;
},
dnsaddr: (value, restMa) => value,
dns4: (value, restMa) => value,
dns6: (value, restMa) => value,
dns: (value, restMa) => value,
ipfs: (value, restMa) => {
const tailProto = restMa.pop();
if (tailProto == null) {
dnsaddr: (head, rest) => head.value,
dns4: (head, rest) => head.value,
dns6: (head, rest) => head.value,
dns: (head, rest) => head.value,
ipfs: (head, rest) => {
const tail = rest.pop();
if (tail == null) {
throw new Error('Unexpected end of multiaddr');
}
return `${interpretNext(tailProto[0], tailProto[1] ?? '', restMa)}`;
return `${interpretNext(tail, rest)}`;
},
p2p: (value, restMa) => {
const tailProto = restMa.pop();
if (tailProto == null) {
p2p: (head, rest) => {
const tail = rest.pop();
if (tail == null) {
throw new Error('Unexpected end of multiaddr');
}
return `${interpretNext(tailProto[0], tailProto[1] ?? '', restMa)}`;
return `${interpretNext(tail, rest)}`;
},
http: (value, restMa) => {
const maHasTLS = hasTLS(restMa);
const sni = extractSNI(restMa);
const port = extractPort(restMa);
http: (head, rest) => {
const maHasTLS = hasTLS(rest);
const sni = extractSNI(rest);
const port = extractPort(rest);
if (maHasTLS && sni != null) {

@@ -129,52 +117,52 @@ return `https://${sni}${port}`;

const protocol = maHasTLS ? 'https://' : 'http://';
const tailProto = restMa.pop();
if (tailProto == null) {
const tail = rest.pop();
if (tail == null) {
throw new Error('Unexpected end of multiaddr');
}
let baseVal = interpretNext(tailProto[0], tailProto[1] ?? '', restMa);
let baseVal = interpretNext(tail, rest);
// We are reinterpreting the base as http, so we need to remove the tcp:// if it's there
baseVal = baseVal.replace('tcp://', '');
baseVal = baseVal?.replace('tcp://', '');
return `${protocol}${baseVal}`;
},
'http-path': (value, restMa) => {
const tailProto = restMa.pop();
if (tailProto == null) {
'http-path': (head, rest) => {
const tail = rest.pop();
if (tail == null) {
throw new Error('Unexpected end of multiaddr');
}
const baseVal = interpretNext(tailProto[0], tailProto[1] ?? '', restMa);
const decodedValue = decodeURIComponent(value);
return `${baseVal}/${decodedValue}`;
const baseVal = interpretNext(tail, rest);
const decodedValue = decodeURIComponent(head.value ?? '');
return `${baseVal}${decodedValue}`;
},
tls: (value, restMa) => {
tls: (head, rest) => {
// Noop, the parent context knows that it's tls. We don't need to do
// anything here
const tailProto = restMa.pop();
if (tailProto == null) {
const tail = rest.pop();
if (tail == null) {
throw new Error('Unexpected end of multiaddr');
}
return interpretNext(tailProto[0], tailProto[1] ?? '', restMa);
return interpretNext(tail, rest);
},
sni: (value, restMa) => {
sni: (head, rest) => {
// Noop, the parent context uses the sni information, we don't need to do
// anything here
const tailProto = restMa.pop();
if (tailProto == null) {
const tail = rest.pop();
if (tail == null) {
throw new Error('Unexpected end of multiaddr');
}
return interpretNext(tailProto[0], tailProto[1] ?? '', restMa);
return interpretNext(tail, rest);
},
https: (value, restMa) => {
const tailProto = restMa.pop();
if (tailProto == null) {
https: (head, rest) => {
const tail = rest.pop();
if (tail == null) {
throw new Error('Unexpected end of multiaddr');
}
let baseVal = interpretNext(tailProto[0], tailProto[1] ?? '', restMa);
let baseVal = interpretNext(tail, rest);
// We are reinterpreting the base as http, so we need to remove the tcp:// if it's there
baseVal = baseVal.replace('tcp://', '');
baseVal = baseVal?.replace('tcp://', '');
return `https://${baseVal}`;
},
ws: (value, restMa) => {
const maHasTLS = hasTLS(restMa);
const sni = extractSNI(restMa);
const port = extractPort(restMa);
ws: (head, rest) => {
const maHasTLS = hasTLS(rest);
const sni = extractSNI(rest);
const port = extractPort(rest);
if (maHasTLS && sni != null) {

@@ -184,19 +172,19 @@ return `wss://${sni}${port}`;

const protocol = maHasTLS ? 'wss://' : 'ws://';
const tailProto = restMa.pop();
if (tailProto == null) {
const tail = rest.pop();
if (tail == null) {
throw new Error('Unexpected end of multiaddr');
}
let baseVal = interpretNext(tailProto[0], tailProto[1] ?? '', restMa);
let baseVal = interpretNext(tail, rest);
// We are reinterpreting the base, so we need to remove the tcp:// if it's there
baseVal = baseVal.replace('tcp://', '');
baseVal = baseVal?.replace('tcp://', '');
return `${protocol}${baseVal}`;
},
wss: (value, restMa) => {
const tailProto = restMa.pop();
if (tailProto == null) {
wss: (head, rest) => {
const tail = rest.pop();
if (tail == null) {
throw new Error('Unexpected end of multiaddr');
}
let baseVal = interpretNext(tailProto[0], tailProto[1] ?? '', restMa);
let baseVal = interpretNext(tail, rest);
// We are reinterpreting the base as http, so we need to remove the tcp:// if it's there
baseVal = baseVal.replace('tcp://', '');
baseVal = baseVal?.replace('tcp://', '');
return `wss://${baseVal}`;

@@ -207,17 +195,16 @@ }

const ma = multiaddr(input);
const parts = ma.stringTuples();
const head = parts.pop();
const components = ma.getComponents();
const head = components.pop();
if (head == null) {
throw new Error('Unexpected end of multiaddr');
}
const protocol = protocols(head[0]);
const interpreter = interpreters[protocol.name];
const interpreter = interpreters[head.name];
if (interpreter == null) {
throw new Error(`No interpreter found for ${protocol.name}`);
throw new Error(`No interpreter found for ${head.name}`);
}
let uri = interpreter(head[1] ?? '', parts);
if (opts?.assumeHttp !== false && ASSUME_HTTP_CODES.includes(head[0])) {
let uri = interpreter(head, components) ?? '';
if (opts?.assumeHttp !== false && ASSUME_HTTP_CODES.includes(head.code)) {
// strip any declared protocol
uri = uri.replace(/^.*:\/\//, '');
if (head[1] === '443') {
if (head.value === '443') {
uri = `https://${uri}`;

@@ -224,0 +211,0 @@ }

{
"name": "@multiformats/multiaddr-to-uri",
"version": "11.0.0",
"version": "11.0.1",
"description": "Convert a Multiaddr to a URI",

@@ -5,0 +5,0 @@ "author": "Alan Shaw",

@@ -32,4 +32,4 @@ /**

import { multiaddr, protocols } from '@multiformats/multiaddr'
import type { Multiaddr, StringTuple } from '@multiformats/multiaddr'
import { CODE_TCP, CODE_DNS, CODE_DNS4, CODE_DNS6, CODE_DNSADDR, multiaddr, CODE_TLS, CODE_IP6 } from '@multiformats/multiaddr'
import type { Component, Multiaddr } from '@multiformats/multiaddr'

@@ -41,17 +41,19 @@ export interface MultiaddrToUriOpts {

const ASSUME_HTTP_CODES = [
protocols('tcp').code,
protocols('dns').code,
protocols('dnsaddr').code,
protocols('dns4').code,
protocols('dns6').code
CODE_TCP,
CODE_DNS,
CODE_DNSADDR,
CODE_DNS4,
CODE_DNS6
]
interface Interpreter { (value: string, ma: StringTuple[]): string }
interface Interpreter {
(head: Component, rest: Component[]): string | undefined
}
function extractSNI (ma: StringTuple[]): string | undefined {
return extractTuple('sni', ma)?.[1]
function extractSNI (ma: Component[]): string | undefined {
return extractTuple('sni', ma)?.value
}
function extractPort (ma: StringTuple[]): string {
const port = extractTuple('tcp', ma)?.[1]
function extractPort (ma: Component[]): string {
const port = extractTuple('tcp', ma)?.value

@@ -65,30 +67,17 @@ if (port == null) {

function extractTuple (name: string, ma: StringTuple[]): StringTuple | undefined {
let code: number
try {
code = protocols(name).code
} catch (e) {
// No support for protocol in multiaddr
return
}
for (const [proto, value] of ma) {
if (proto === code && value != null) {
return [proto, value]
}
}
function extractTuple (name: string, ma: Component[]): Component | undefined {
return ma.find(component => component.name === name)
}
function hasTLS (ma: StringTuple[]): boolean {
return ma.some(([proto, _]) => proto === protocols('tls').code)
function hasTLS (ma: Component[]): boolean {
return ma.some(({ code }) => code === CODE_TLS)
}
function interpretNext (headProtoCode: number, headProtoVal: string, restMa: StringTuple[]): string {
const interpreter = interpreters[protocols(headProtoCode).name]
function interpretNext (head: Component, rest: Component[]): string | undefined {
const interpreter = interpreters[head.name]
if (interpreter == null) {
throw new Error(`Can't interpret protocol ${protocols(headProtoCode).name}`)
throw new Error(`Can't interpret protocol ${head.name}`)
}
const restVal = interpreter(headProtoVal, restMa)
if (headProtoCode === protocols('ip6').code) {
const restVal = interpreter(head, rest)
if (head.code === CODE_IP6) {
return `[${restVal}]`

@@ -100,45 +89,45 @@ }

const interpreters: Record<string, Interpreter> = {
ip4: (value: string, restMa: StringTuple[]) => value,
ip6: (value: string, restMa: StringTuple[]) => {
if (restMa.length === 0) {
return value
ip4: (head, rest) => head.value,
ip6: (head, rest) => {
if (rest.length === 0) {
return head.value
}
return `[${value}]`
return `[${head.value}]`
},
tcp: (value: string, restMa: StringTuple[]) => {
const tailProto = restMa.pop()
if (tailProto == null) {
tcp: (head, rest) => {
const tail = rest.pop()
if (tail == null) {
throw new Error('Unexpected end of multiaddr')
}
return `tcp://${interpretNext(tailProto[0], tailProto[1] ?? '', restMa)}:${value}`
return `tcp://${interpretNext(tail, rest)}:${head.value}`
},
udp: (value: string, restMa: StringTuple[]) => {
const tailProto = restMa.pop()
if (tailProto == null) {
udp: (head, rest) => {
const tail = rest.pop()
if (tail == null) {
throw new Error('Unexpected end of multiaddr')
}
return `udp://${interpretNext(tailProto[0], tailProto[1] ?? '', restMa)}:${value}`
return `udp://${interpretNext(tail, rest)}:${head.value}`
},
dnsaddr: (value: string, restMa: StringTuple[]) => value,
dns4: (value: string, restMa: StringTuple[]) => value,
dns6: (value: string, restMa: StringTuple[]) => value,
dns: (value: string, restMa: StringTuple[]) => value,
ipfs: (value: string, restMa: StringTuple[]) => {
const tailProto = restMa.pop()
if (tailProto == null) {
dnsaddr: (head, rest) => head.value,
dns4: (head, rest) => head.value,
dns6: (head, rest) => head.value,
dns: (head, rest) => head.value,
ipfs: (head, rest) => {
const tail = rest.pop()
if (tail == null) {
throw new Error('Unexpected end of multiaddr')
}
return `${interpretNext(tailProto[0], tailProto[1] ?? '', restMa)}`
return `${interpretNext(tail, rest)}`
},
p2p: (value: string, restMa: StringTuple[]) => {
const tailProto = restMa.pop()
if (tailProto == null) {
p2p: (head, rest) => {
const tail = rest.pop()
if (tail == null) {
throw new Error('Unexpected end of multiaddr')
}
return `${interpretNext(tailProto[0], tailProto[1] ?? '', restMa)}`
return `${interpretNext(tail, rest)}`
},
http: (value: string, restMa: StringTuple[]) => {
const maHasTLS = hasTLS(restMa)
const sni = extractSNI(restMa)
const port = extractPort(restMa)
http: (head, rest) => {
const maHasTLS = hasTLS(rest)
const sni = extractSNI(rest)
const port = extractPort(rest)
if (maHasTLS && sni != null) {

@@ -148,52 +137,52 @@ return `https://${sni}${port}`

const protocol = maHasTLS ? 'https://' : 'http://'
const tailProto = restMa.pop()
if (tailProto == null) {
const tail = rest.pop()
if (tail == null) {
throw new Error('Unexpected end of multiaddr')
}
let baseVal = interpretNext(tailProto[0], tailProto[1] ?? '', restMa)
let baseVal = interpretNext(tail, rest)
// We are reinterpreting the base as http, so we need to remove the tcp:// if it's there
baseVal = baseVal.replace('tcp://', '')
baseVal = baseVal?.replace('tcp://', '')
return `${protocol}${baseVal}`
},
'http-path': (value: string, restMa: StringTuple[]) => {
const tailProto = restMa.pop()
if (tailProto == null) {
'http-path': (head, rest) => {
const tail = rest.pop()
if (tail == null) {
throw new Error('Unexpected end of multiaddr')
}
const baseVal = interpretNext(tailProto[0], tailProto[1] ?? '', restMa)
const decodedValue = decodeURIComponent(value)
return `${baseVal}/${decodedValue}`
const baseVal = interpretNext(tail, rest)
const decodedValue = decodeURIComponent(head.value ?? '')
return `${baseVal}${decodedValue}`
},
tls: (value: string, restMa: StringTuple[]) => {
tls: (head, rest) => {
// Noop, the parent context knows that it's tls. We don't need to do
// anything here
const tailProto = restMa.pop()
if (tailProto == null) {
const tail = rest.pop()
if (tail == null) {
throw new Error('Unexpected end of multiaddr')
}
return interpretNext(tailProto[0], tailProto[1] ?? '', restMa)
return interpretNext(tail, rest)
},
sni: (value: string, restMa: StringTuple[]) => {
sni: (head, rest) => {
// Noop, the parent context uses the sni information, we don't need to do
// anything here
const tailProto = restMa.pop()
if (tailProto == null) {
const tail = rest.pop()
if (tail == null) {
throw new Error('Unexpected end of multiaddr')
}
return interpretNext(tailProto[0], tailProto[1] ?? '', restMa)
return interpretNext(tail, rest)
},
https: (value: string, restMa: StringTuple[]) => {
const tailProto = restMa.pop()
if (tailProto == null) {
https: (head, rest) => {
const tail = rest.pop()
if (tail == null) {
throw new Error('Unexpected end of multiaddr')
}
let baseVal = interpretNext(tailProto[0], tailProto[1] ?? '', restMa)
let baseVal = interpretNext(tail, rest)
// We are reinterpreting the base as http, so we need to remove the tcp:// if it's there
baseVal = baseVal.replace('tcp://', '')
baseVal = baseVal?.replace('tcp://', '')
return `https://${baseVal}`
},
ws: (value: string, restMa: StringTuple[]) => {
const maHasTLS = hasTLS(restMa)
const sni = extractSNI(restMa)
const port = extractPort(restMa)
ws: (head, rest) => {
const maHasTLS = hasTLS(rest)
const sni = extractSNI(rest)
const port = extractPort(rest)
if (maHasTLS && sni != null) {

@@ -203,19 +192,19 @@ return `wss://${sni}${port}`

const protocol = maHasTLS ? 'wss://' : 'ws://'
const tailProto = restMa.pop()
if (tailProto == null) {
const tail = rest.pop()
if (tail == null) {
throw new Error('Unexpected end of multiaddr')
}
let baseVal = interpretNext(tailProto[0], tailProto[1] ?? '', restMa)
let baseVal = interpretNext(tail, rest)
// We are reinterpreting the base, so we need to remove the tcp:// if it's there
baseVal = baseVal.replace('tcp://', '')
baseVal = baseVal?.replace('tcp://', '')
return `${protocol}${baseVal}`
},
wss: (value: string, restMa: StringTuple[]) => {
const tailProto = restMa.pop()
if (tailProto == null) {
wss: (head, rest) => {
const tail = rest.pop()
if (tail == null) {
throw new Error('Unexpected end of multiaddr')
}
let baseVal = interpretNext(tailProto[0], tailProto[1] ?? '', restMa)
let baseVal = interpretNext(tail, rest)
// We are reinterpreting the base as http, so we need to remove the tcp:// if it's there
baseVal = baseVal.replace('tcp://', '')
baseVal = baseVal?.replace('tcp://', '')
return `wss://${baseVal}`

@@ -227,4 +216,4 @@ }

const ma = multiaddr(input)
const parts = ma.stringTuples()
const head = parts.pop()
const components = ma.getComponents()
const head = components.pop()
if (head == null) {

@@ -234,16 +223,15 @@ throw new Error('Unexpected end of multiaddr')

const protocol = protocols(head[0])
const interpreter = interpreters[protocol.name]
const interpreter = interpreters[head.name]
if (interpreter == null) {
throw new Error(`No interpreter found for ${protocol.name}`)
throw new Error(`No interpreter found for ${head.name}`)
}
let uri = interpreter(head[1] ?? '', parts)
let uri = interpreter(head, components) ?? ''
if (opts?.assumeHttp !== false && ASSUME_HTTP_CODES.includes(head[0])) {
if (opts?.assumeHttp !== false && ASSUME_HTTP_CODES.includes(head.code)) {
// strip any declared protocol
uri = uri.replace(/^.*:\/\//, '')
if (head[1] === '443') {
if (head.value === '443') {
uri = `https://${uri}`

@@ -250,0 +238,0 @@ } else {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet