@multiformats/multiaddr-to-uri
Advanced tools
| (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 Lt=Object.getOwnPropertyDescriptor;var Vt=Object.getOwnPropertyNames;var Mt=Object.prototype.hasOwnProperty;var b=(r,e)=>{for(var t in e)pe(r,t,{get:e[t],enumerable:!0})},Ot=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Vt(e))!Mt.call(r,o)&&o!==t&&pe(r,o,{get:()=>e[o],enumerable:!(n=Lt(e,o))||n.enumerable});return r};var jt=r=>Ot(pe({},"__esModule",{value:!0}),r);var Un={};b(Un,{multiaddrToUri:()=>Sn});var re=class extends Error{code;props;constructor(e,t,n){super(e),this.code=t,this.name=n?.name??"CodeError",this.props=n??{}}};var me={};b(me,{base58btc:()=>x,base58flickr:()=>Ht});var Cn=new Uint8Array(0);function We(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 Ke(r){return new TextEncoder().encode(r)}function Ye(r){return new TextDecoder().decode(r)}function qt(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,u=r.charAt(0),m=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function A(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,L=0,I=0,U=d.length;I!==U&&d[I]===0;)I++,w++;for(var P=(U-I)*l+1>>>0,E=new Uint8Array(P);I!==U;){for(var T=d[I],k=0,S=P-1;(T!==0||k<L)&&S!==-1;S--,k++)T+=256*E[S]>>>0,E[S]=T%a>>>0,T=T/a>>>0;if(T!==0)throw new Error("Non-zero carry");L=k,I++}for(var N=P-L;N!==P&&E[N]===0;)N++;for(var te=u.repeat(w);N<P;++N)te+=r.charAt(E[N]);return te}function R(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 L=0,I=0;d[w]===u;)L++,w++;for(var U=(d.length-w)*m+1>>>0,P=new Uint8Array(U);d[w];){var E=t[d.charCodeAt(w)];if(E===255)return;for(var T=0,k=U-1;(E!==0||T<I)&&k!==-1;k--,T++)E+=a*P[k]>>>0,P[k]=E%256>>>0,E=E/256>>>0;if(E!==0)throw new Error("Non-zero carry");I=T,w++}if(d[w]!==" "){for(var S=U-I;S!==U&&P[S]===0;)S++;for(var N=new Uint8Array(L+(U-S)),te=L;S!==U;)N[te++]=P[S++];return N}}}function v(d){var w=R(d);if(w)return w;throw new Error(`Non-${e} character`)}return{encode:A,decodeUnsafe:R,decode:v}}var _t=qt,Gt=_t,et=Gt;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")}},fe=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){if(this.name=e,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),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 tt(this,e)}},le=class{decoders;constructor(e){this.decoders=e}or(e){return tt(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 tt(r,e){return new le({...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 fe(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function j({name:r,prefix:e,encode:t,decode:n}){return new he(r,e,t,n)}function z({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=et(t,r);return j({prefix:e,name:r,encode:n,decode:i=>F(o(i))})}function Xt(r,e,t,n){let o={};for(let l=0;l<e.length;++l)o[e[l]]=l;let i=r.length;for(;r[i-1]==="=";)--i;let s=new Uint8Array(i*t/8|0),a=0,u=0,m=0;for(let l=0;l<i;++l){let A=o[r[l]];if(A===void 0)throw new SyntaxError(`Non-${n} character`);u=u<<t|A,a+=t,a>=8&&(a-=8,s[m++]=255&u>>a)}if(a>=t||255&u<<8-a)throw new SyntaxError("Unexpected end of data");return s}function Jt(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,i="",s=0,a=0;for(let u=0;u<r.length;++u)for(a=a<<8|r[u],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;)i+="=";return i}function f({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return j({prefix:e,name:r,encode(o){return Jt(o,n,t)},decode(o){return Xt(o,n,t,r)}})}var x=z({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ht=z({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var we={};b(we,{base32:()=>D,base32hex:()=>Yt,base32hexpad:()=>er,base32hexpadupper:()=>tr,base32hexupper:()=>Zt,base32pad:()=>Wt,base32padupper:()=>Kt,base32upper:()=>Qt,base32z:()=>rr});var D=f({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Qt=f({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Wt=f({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Kt=f({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Yt=f({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Zt=f({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),er=f({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),tr=f({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),rr=f({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var nr=ot,rt=128,or=127,ir=~or,sr=Math.pow(2,31);function ot(r,e,t){e=e||[],t=t||0;for(var n=t;r>=sr;)e[t++]=r&255|rt,r/=128;for(;r&ir;)e[t++]=r&255|rt,r>>>=7;return e[t]=r|0,ot.bytes=t-n+1,e}var ar=xe,cr=128,nt=127;function xe(r,n){var t=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw xe.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&nt)<<o:(s&nt)*Math.pow(2,o),o+=7}while(s>=cr);return xe.bytes=i-n,t}var dr=Math.pow(2,7),pr=Math.pow(2,14),ur=Math.pow(2,21),fr=Math.pow(2,28),lr=Math.pow(2,35),hr=Math.pow(2,42),mr=Math.pow(2,49),wr=Math.pow(2,56),xr=Math.pow(2,63),gr=function(r){return r<dr?1:r<pr?2:r<ur?3:r<fr?4:r<lr?5:r<hr?6:r<mr?7:r<wr?8:r<xr?9:10},br={encode:nr,decode:ar,encodingLength:gr},yr=br,K=yr;function Y(r,e=0){return[K.decode(r,e),K.decode.bytes]}function q(r,e,t=0){return K.encode(r,e,t),e}function _(r){return K.encodingLength(r)}function V(r,e){let t=e.byteLength,n=_(r),o=n+_(t),i=new Uint8Array(o+t);return q(r,i,0),q(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)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new G(t,o,s,e)}function it(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&We(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 st(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return Er(t,ge(r),e??x.encoder);default:return Ar(t,ge(r),e??D.encoder)}}var at=new WeakMap;function ge(r){let e=at.get(r);if(e==null){let t=new Map;return at.set(r,t),t}return e}var B=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!==Z)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Ir)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&&it(e.multihash,n.multihash)}toString(e){return st(this,e)}toJSON(){return{"/":st(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??ct(n,o,i.bytes))}else if(t[Sr]===!0){let{version:n,multihash:o,code:i}=t,s=oe(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!==Z)throw new Error(`Version 0 CID must use dag-pb (code: ${Z}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=ct(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Z,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),s=new G(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[A,R]=Y(e.subarray(t));return t+=R,A},o=n(),i=Z;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(),u=n(),m=t+u,l=m-s;return{version:o,codec:i,multihashCode:a,digestSize:u,multihashSize:l,size:m}}static parse(e,t){let[n,o]=vr(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 ge(i).set(n,e),i}};function vr(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 D.prefix:{let t=e??D;return[D.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function Er(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 Ar(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 Z=112,Ir=18;function ct(r,e,t){let n=_(r),o=n+_(e),i=new Uint8Array(o+t.byteLength);return q(r,i,0),q(e,i,n),i.set(t,o),i}var Sr=Symbol.for("@ipld/js-cid/CID");function dt(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 be={};b(be,{base10:()=>Ur});var Ur=z({prefix:"9",name:"base10",alphabet:"0123456789"});var ye={};b(ye,{base16:()=>Pr,base16upper:()=>Tr});var Pr=f({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Tr=f({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ve={};b(ve,{base2:()=>Cr});var Cr=f({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ee={};b(Ee,{base256emoji:()=>Rr});var pt=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}"),Nr=pt.reduce((r,e,t)=>(r[t]=e,r),[]),Fr=pt.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);function Dr(r){return r.reduce((e,t)=>(e+=Nr[t],e),"")}function $r(r){let e=[];for(let t of r){let n=Fr[t.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(n)}return new Uint8Array(e)}var Rr=j({prefix:"\u{1F680}",name:"base256emoji",encode:Dr,decode:$r});var Ae={};b(Ae,{base36:()=>kr,base36upper:()=>zr});var kr=z({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),zr=z({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ie={};b(Ie,{base64:()=>Br,base64pad:()=>Lr,base64url:()=>Vr,base64urlpad:()=>Mr});var Br=f({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Lr=f({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Vr=f({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Mr=f({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Se={};b(Se,{base8:()=>Or});var Or=f({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ue={};b(Ue,{identity:()=>jr});var jr=j({prefix:"\0",name:"identity",encode:r=>Ye(r),decode:r=>Ke(r)});var eo=new TextEncoder,to=new TextDecoder;var Pe={};b(Pe,{identity:()=>Jr});var ut=0,Gr="identity",ft=F;function Xr(r){return V(ut,ft(r))}var Jr={code:ut,name:Gr,encode:ft,digest:Xr};var Ne={};b(Ne,{sha256:()=>Hr,sha512:()=>Qr});function Ce({name:r,code:e,encode:t}){return new Te(r,e,t)}var Te=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 ht(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var Hr=Ce({name:"sha2-256",code:18,encode:ht("SHA-256")}),Qr=Ce({name:"sha2-512",code:19,encode:ht("SHA-512")});var ee={...Ue,...ve,...Se,...be,...ye,...we,...Ae,...me,...Ie,...Ee},mo={...Ne,...Pe};function M(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function J(r=0){return globalThis.Buffer?.allocUnsafe!=null?M(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}function wt(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var mt=wt("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Fe=wt("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}),Wr={utf8:mt,"utf-8":mt,hex:ee.base16,latin1:Fe,ascii:Fe,binary:Fe,...ee},ie=Wr;function g(r,e="utf8"){let t=ie[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):t.encoder.encode(r).substring(1)}var Kr=Math.pow(2,7),Yr=Math.pow(2,14),Zr=Math.pow(2,21),De=Math.pow(2,28),$e=Math.pow(2,35),Re=Math.pow(2,42),ke=Math.pow(2,49),p=128,h=127;function C(r){if(r<Kr)return 1;if(r<Yr)return 2;if(r<Zr)return 3;if(r<De)return 4;if(r<$e)return 5;if(r<Re)return 6;if(r<ke)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function en(r,e,t=0){switch(C(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 tn(r,e,t=0){switch(C(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 rn(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)*De,t<p)||(t=r[e+5],n+=(t&h)*$e,t<p)||(t=r[e+6],n+=(t&h)*Re,t<p)||(t=r[e+7],n+=(t&h)*ke,t<p))return n;throw new RangeError("Could not decode varint")}function nn(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)*De,t<p)||(t=r.get(e+5),n+=(t&h)*$e,t<p)||(t=r.get(e+6),n+=(t&h)*Re,t<p)||(t=r.get(e+7),n+=(t&h)*ke,t<p))return n;throw new RangeError("Could not decode varint")}function H(r,e,t=0){return e==null&&(e=J(C(r))),e instanceof Uint8Array?en(r,e,t):tn(r,e,t)}function O(r,e=0){return r instanceof Uint8Array?rn(r,e):nn(r,e)}function $(r,e){if(globalThis.Buffer!=null)return M(globalThis.Buffer.concat(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 M(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,s=0,a=this.peekChar();if(a===void 0)return;let u=a==="0",m=2**(8*o)-1;for(;;){let l=this.readAtomically(()=>{let A=this.readChar();if(A===void 0)return;let R=Number.parseInt(A,e);if(!Number.isNaN(R))return R});if(l===void 0)break;if(i*=e,i+=l,i>m||(s+=1,t!==void 0&&s>t))return}if(s!==0)return!n&&u&&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 gt=45,on=15,Q=new se;function ze(r){if(!(r.length>on))return Q.new(r).parseWith(()=>Q.readIPv4Addr())}function Be(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>gt))return Q.new(r).parseWith(()=>Q.readIPv6Addr())}function ae(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>gt))return Q.new(r).parseWith(()=>Q.readIPAddr())}var Lo=parseInt("0xFFFF",16),Vo=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Le(r,e="utf8"){let t=ie[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?M(globalThis.Buffer.from(r,"utf-8")):t.decoder.decode(`${t.prefix}${r}`)}function vt(r){return!!ze(r)}function Et(r){return!!Be(r)}function ce(r){return!!ae(r)}var At=vt,pn=Et,Ve=function(r){let e=0;if(r=r.toString().trim(),At(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(pn(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let i=At(t[n]),s;i&&(s=Ve(t[n]),t[n]=g(s.slice(0,2),"base16")),s!=null&&++n<8&&t.splice(n,0,g(s.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")},It=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 W={},Me={},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"],[777,-1,"memory"]];fn.forEach(r=>{let e=ln(...r);Me[e.code]=e,W[e.name]=e});function ln(r,e,t,n,o){return{code:r,size:e,name:t,resolvable:!!n,path:!!o}}function c(r){if(typeof r=="number"){if(Me[r]!=null)return Me[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(W[r]!=null)return W[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var Si=c("ip4"),Ui=c("ip6"),Pi=c("ipcidr");function je(r,e){switch(c(r).code){case 4:case 41:return mn(e);case 42:return Pt(e);case 6:case 273:case 33:case 132:return Ct(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Pt(e);case 421:return bn(e);case 444:return Tt(e);case 445:return Tt(e);case 466:return gn(e);default:return g(e,"base16")}}function qe(r,e){switch(c(r).code){case 4:return St(e);case 41:return St(e);case 42:return Ut(e);case 6:case 273:case 33:case 132:return _e(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Ut(e);case 421:return wn(e);case 444:return yn(e);case 445:return vn(e);case 466:return xn(e);default:return Le(e,"base16")}}var Oe=Object.values(ee).map(r=>r.decoder),hn=function(){let r=Oe[0].or(Oe[1]);return Oe.slice(2).forEach(e=>r=r.or(e)),r}();function St(r){if(!ce(r))throw new Error("invalid ip address");return Ve(r)}function mn(r){let e=It(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 _e(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function Ct(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function Ut(r){let e=Le(r),t=Uint8Array.from(H(e.length));return $([t,e],t.length+e.length)}function Pt(r){let e=O(r);if(r=r.slice(C(e)),r.length!==e)throw new Error("inconsistent lengths");return g(r)}function wn(r){let e;r[0]==="Q"||r[0]==="1"?e=oe(x.decode(`z${r}`)).bytes:e=B.parse(r).multihash.bytes;let t=Uint8Array.from(H(e.length));return $([t,e],t.length+e.length)}function xn(r){let e=hn.decode(r),t=Uint8Array.from(H(e.length));return $([t,e],t.length+e.length)}function gn(r){let e=O(r),t=r.slice(C(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+g(t,"base64url")}function bn(r){let e=O(r),t=r.slice(C(e));if(t.length!==e)throw new Error("inconsistent lengths");return g(t,"base58btc")}function yn(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=D.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=_e(n);return $([t,o],t.length+o.length)}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!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let t=D.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=_e(n);return $([t,o],t.length+o.length)}function Tt(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=g(e,"base32"),o=Ct(t);return`${n}:${o}`}function Nt(r){r=Ge(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 s=o[i],a=c(s);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(i++,i>=o.length)throw Dt("invalid address: "+r);if(a.path===!0){n=Ge(o.slice(i).join("/")),e.push([a.code,qe(a.code,n)]),t.push([a.code,n]);break}let u=qe(a.code,o[i]);e.push([a.code,u]),t.push([a.code,je(a.code,u)])}return{string:Ft(t),bytes:Je(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),s=C(i),a=c(i),u=En(a,r.slice(o+s));if(u===0){e.push([i]),t.push([i]),o+=s;continue}let m=r.slice(o+s,o+s+u);if(o+=u+s,o>r.length)throw Dt("Invalid address Uint8Array: "+g(r,"base16"));e.push([i,m]);let l=je(i,m);if(t.push([i,l]),a.path===!0){n=l;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}),Ge(e.join("/"))}function Je(r){return $(r.map(e=>{let t=c(e[0]),n=Uint8Array.from(H(t.code));return e.length>1&&e[1]!=null&&(n=$([n,e[1]])),n}))}function En(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+C(t)}}function Ge(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}function Dt(r){return new Error("Error parsing address: "+r)}var An=Symbol.for("nodejs.util.inspect.custom"),He=Symbol.for("@multiformats/js-multiaddr/multiaddr"),In=[c("dns").code,c("dns4").code,c("dns6").code,c("dnsaddr").code],de=class r{bytes;#t;#e;#r;#n;[He]=!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=Nt(e)}else if(Rt(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="",s=c("tcp"),a=c("udp"),u=c("ip4"),m=c("ip6"),l=c("dns6"),A=c("ip6zone");for(let[v,d]of this.stringTuples())v===A.code&&(i=`%${d??""}`),In.includes(v)&&(t=s.name,o=443,n=`${d??""}${i}`,e=v===l.code?6:4),(v===s.code||v===a.code)&&(t=c(v).name,o=parseInt(d??"")),(v===u.code||v===m.code)&&(t=c(v).name,n=`${d??""}${i}`,e=v===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(Je(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,o])=>{n===W.p2p.code&&e.push([n,o]),n===W["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(B.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(e){return dt(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(i=>i.resolvable);if(t==null)return[this];let n=$t.get(t.name);if(n==null)throw new re(`no available resolver for ${t.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await n(this,e)).map(i=>new r(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)}[An](){return`Multiaddr(${this.#t})`}};var $t=new Map;function Rt(r){return!!r?.[He]}function Qe(r){return new de(r)}function kt(r){let e;try{e=c("sni").code}catch{return null}for(let[t,n]of r)if(t===e&&n!==void 0)return n;return null}function zt(r){return r.some(([e,t])=>e===c("tls").code)}function y(r,e,t){let n=Bt[c(r).name];if(n===void 0)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===void 0)throw new Error("Unexpected end of multiaddr");return`tcp://${y(t[0],t[1]??"",e)}:${r}`},udp:(r,e)=>{let t=e.pop();if(t===void 0)throw new Error("Unexpected end of multiaddr");return`udp://${y(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===void 0)throw new Error("Unexpected end of multiaddr");return`${y(t[0],t[1]??"",e)}/ipfs/${r}`},p2p:(r,e)=>{let t=e.pop();if(t===void 0)throw new Error("Unexpected end of multiaddr");return`${y(t[0],t[1]??"",e)}/p2p/${r}`},http:(r,e)=>{let t=zt(e),n=kt(e);if(t&&n!==null)return`https://${n}`;let o=t?"https://":"http://",i=e.pop();if(i===void 0)throw new Error("Unexpected end of multiaddr");let s=y(i[0],i[1]??"",e);return s=s.replace("tcp://",""),`${o}${s}`},tls:(r,e)=>{let t=e.pop();if(t===void 0)throw new Error("Unexpected end of multiaddr");return y(t[0],t[1]??"",e)},sni:(r,e)=>{let t=e.pop();if(t===void 0)throw new Error("Unexpected end of multiaddr");return y(t[0],t[1]??"",e)},https:(r,e)=>{let t=e.pop();if(t===void 0)throw new Error("Unexpected end of multiaddr");let n=y(t[0],t[1]??"",e);return n=n.replace("tcp://",""),`https://${n}`},ws:(r,e)=>{let t=zt(e),n=kt(e);if(t&&n!==null)return`wss://${n}`;let o=t?"wss://":"ws://",i=e.pop();if(i===void 0)throw new Error("Unexpected end of multiaddr");let s=y(i[0],i[1]??"",e);return s=s.replace("tcp://",""),`${o}${s}`},wss:(r,e)=>{let t=e.pop();if(t===void 0)throw new Error("Unexpected end of multiaddr");let n=y(t[0],t[1]??"",e);return n=n.replace("tcp://",""),`wss://${n}`},"p2p-websocket-star":(r,e)=>{let t=e.pop();if(t===void 0)throw new Error("Unexpected end of multiaddr");return`${y(t[0],t[1]??"",e)}/p2p-websocket-star`},"p2p-webrtc-star":(r,e)=>{let t=e.pop();if(t===void 0)throw new Error("Unexpected end of multiaddr");return`${y(t[0],t[1]??"",e)}/p2p-webrtc-star`},"p2p-webrtc-direct":(r,e)=>{let t=e.pop();if(t===void 0)throw new Error("Unexpected end of multiaddr");return`${y(t[0],t[1]??"",e)}/p2p-webrtc-direct`}};function Sn(r,e){let n=Qe(r).stringTuples(),o=n.pop();if(o===void 0)throw new Error("Unexpected end of multiaddr");let i=c(o[0]),s=Bt[i.name];if(s==null)throw new Error(`No interpreter found for ${i.name}`);let a=s(o[1]??"",n);return e?.assumeHttp!==!1&&o[0]===c("tcp").code&&(a=a.replace("tcp://","http://"),(o[1]==="443"||o[1]==="80")&&(o[1]==="443"&&(a=a.replace("http://","https://")),a=a.substring(0,a.lastIndexOf(":")))),a}return jt(Un);})(); | ||
| "use strict";var MultiformatsMultiaddrToUri=(()=>{var pe=Object.defineProperty;var Bt=Object.getOwnPropertyDescriptor;var Vt=Object.getOwnPropertyNames;var Mt=Object.prototype.hasOwnProperty;var b=(r,e)=>{for(var t in e)pe(r,t,{get:e[t],enumerable:!0})},Ot=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Vt(e))!Mt.call(r,o)&&o!==t&&pe(r,o,{get:()=>e[o],enumerable:!(n=Bt(e,o))||n.enumerable});return r};var jt=r=>Ot(pe({},"__esModule",{value:!0}),r);var Pn={};b(Pn,{multiaddrToUri:()=>Un});var re=class extends Error{code;props;constructor(e,t,n){super(e),this.code=t,this.name=n?.name??"CodeError",this.props=n??{}}};var me={};b(me,{base58btc:()=>g,base58flickr:()=>Jt});var Nn=new Uint8Array(0);function Qe(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 Ke(r){return new TextEncoder().encode(r)}function Ye(r){return new TextDecoder().decode(r)}function qt(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,u=r.charAt(0),m=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function A(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,B=0,S=0,U=d.length;S!==U&&d[S]===0;)S++,w++;for(var P=(U-S)*l+1>>>0,E=new Uint8Array(P);S!==U;){for(var T=d[S],k=0,I=P-1;(T!==0||k<B)&&I!==-1;I--,k++)T+=256*E[I]>>>0,E[I]=T%a>>>0,T=T/a>>>0;if(T!==0)throw new Error("Non-zero carry");B=k,S++}for(var N=P-B;N!==P&&E[N]===0;)N++;for(var te=u.repeat(w);N<P;++N)te+=r.charAt(E[N]);return te}function R(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 B=0,S=0;d[w]===u;)B++,w++;for(var U=(d.length-w)*m+1>>>0,P=new Uint8Array(U);d[w];){var E=t[d.charCodeAt(w)];if(E===255)return;for(var T=0,k=U-1;(E!==0||T<S)&&k!==-1;k--,T++)E+=a*P[k]>>>0,P[k]=E%256>>>0,E=E/256>>>0;if(E!==0)throw new Error("Non-zero carry");S=T,w++}if(d[w]!==" "){for(var I=U-S;I!==U&&P[I]===0;)I++;for(var N=new Uint8Array(B+(U-I)),te=B;I!==U;)N[te++]=P[I++];return N}}}function v(d){var w=R(d);if(w)return w;throw new Error(`Non-${e} character`)}return{encode:A,decodeUnsafe:R,decode:v}}var _t=qt,Gt=_t,et=Gt;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")}},fe=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){if(this.name=e,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),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 tt(this,e)}},le=class{decoders;constructor(e){this.decoders=e}or(e){return tt(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 tt(r,e){return new le({...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 fe(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function j({name:r,prefix:e,encode:t,decode:n}){return new he(r,e,t,n)}function L({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=et(t,r);return j({prefix:e,name:r,encode:n,decode:i=>F(o(i))})}function Xt(r,e,t,n){let o={};for(let l=0;l<e.length;++l)o[e[l]]=l;let i=r.length;for(;r[i-1]==="=";)--i;let s=new Uint8Array(i*t/8|0),a=0,u=0,m=0;for(let l=0;l<i;++l){let A=o[r[l]];if(A===void 0)throw new SyntaxError(`Non-${n} character`);u=u<<t|A,a+=t,a>=8&&(a-=8,s[m++]=255&u>>a)}if(a>=t||255&u<<8-a)throw new SyntaxError("Unexpected end of data");return s}function Ht(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,i="",s=0,a=0;for(let u=0;u<r.length;++u)for(a=a<<8|r[u],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;)i+="=";return i}function f({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return j({prefix:e,name:r,encode(o){return Ht(o,n,t)},decode(o){return Xt(o,n,t,r)}})}var g=L({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Jt=L({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var we={};b(we,{base32:()=>$,base32hex:()=>Yt,base32hexpad:()=>er,base32hexpadupper:()=>tr,base32hexupper:()=>Zt,base32pad:()=>Qt,base32padupper:()=>Kt,base32upper:()=>Wt,base32z:()=>rr});var $=f({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Wt=f({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Qt=f({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Kt=f({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Yt=f({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Zt=f({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),er=f({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),tr=f({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),rr=f({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var nr=ot,rt=128,or=127,ir=~or,sr=Math.pow(2,31);function ot(r,e,t){e=e||[],t=t||0;for(var n=t;r>=sr;)e[t++]=r&255|rt,r/=128;for(;r&ir;)e[t++]=r&255|rt,r>>>=7;return e[t]=r|0,ot.bytes=t-n+1,e}var ar=ge,cr=128,nt=127;function ge(r,n){var t=0,n=n||0,o=0,i=n,s,a=r.length;do{if(i>=a)throw ge.bytes=0,new RangeError("Could not decode varint");s=r[i++],t+=o<28?(s&nt)<<o:(s&nt)*Math.pow(2,o),o+=7}while(s>=cr);return ge.bytes=i-n,t}var dr=Math.pow(2,7),pr=Math.pow(2,14),ur=Math.pow(2,21),fr=Math.pow(2,28),lr=Math.pow(2,35),hr=Math.pow(2,42),mr=Math.pow(2,49),wr=Math.pow(2,56),gr=Math.pow(2,63),xr=function(r){return r<dr?1:r<pr?2:r<ur?3:r<fr?4:r<lr?5:r<hr?6:r<mr?7:r<wr?8:r<gr?9:10},br={encode:nr,decode:ar,encodingLength:xr},yr=br,K=yr;function Y(r,e=0){return[K.decode(r,e),K.decode.bytes]}function q(r,e,t=0){return K.encode(r,e,t),e}function _(r){return K.encodingLength(r)}function V(r,e){let t=e.byteLength,n=_(r),o=n+_(t),i=new Uint8Array(o+t);return q(r,i,0),q(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)),s=e.subarray(n+i);if(s.byteLength!==o)throw new Error("Incorrect length");return new G(t,o,s,e)}function it(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Qe(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 st(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return Er(t,xe(r),e??g.encoder);default:return Ar(t,xe(r),e??$.encoder)}}var at=new WeakMap;function xe(r){let e=at.get(r);if(e==null){let t=new Map;return at.set(r,t),t}return e}var z=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!==Z)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Sr)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&&it(e.multihash,n.multihash)}toString(e){return st(this,e)}toJSON(){return{"/":st(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??ct(n,o,i.bytes))}else if(t[Ir]===!0){let{version:n,multihash:o,code:i}=t,s=oe(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!==Z)throw new Error(`Version 0 CID must use dag-pb (code: ${Z}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=ct(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Z,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),s=new G(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[A,R]=Y(e.subarray(t));return t+=R,A},o=n(),i=Z;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(),u=n(),m=t+u,l=m-s;return{version:o,codec:i,multihashCode:a,digestSize:u,multihashSize:l,size:m}}static parse(e,t){let[n,o]=vr(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 xe(i).set(n,e),i}};function vr(r,e){switch(r[0]){case"Q":{let t=e??g;return[g.prefix,t.decode(`${g.prefix}${r}`)]}case g.prefix:{let t=e??g;return[g.prefix,t.decode(r)]}case $.prefix:{let t=e??$;return[$.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function Er(r,e,t){let{prefix:n}=t;if(n!==g.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 Ar(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 Z=112,Sr=18;function ct(r,e,t){let n=_(r),o=n+_(e),i=new Uint8Array(o+t.byteLength);return q(r,i,0),q(e,i,n),i.set(t,o),i}var Ir=Symbol.for("@ipld/js-cid/CID");function dt(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 be={};b(be,{base10:()=>Ur});var Ur=L({prefix:"9",name:"base10",alphabet:"0123456789"});var ye={};b(ye,{base16:()=>Pr,base16upper:()=>Tr});var Pr=f({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Tr=f({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ve={};b(ve,{base2:()=>Cr});var Cr=f({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Ee={};b(Ee,{base256emoji:()=>Rr});var pt=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}"),Nr=pt.reduce((r,e,t)=>(r[t]=e,r),[]),Fr=pt.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);function $r(r){return r.reduce((e,t)=>(e+=Nr[t],e),"")}function Dr(r){let e=[];for(let t of r){let n=Fr[t.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(n)}return new Uint8Array(e)}var Rr=j({prefix:"\u{1F680}",name:"base256emoji",encode:$r,decode:Dr});var Ae={};b(Ae,{base36:()=>kr,base36upper:()=>Lr});var kr=L({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Lr=L({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Se={};b(Se,{base64:()=>zr,base64pad:()=>Br,base64url:()=>Vr,base64urlpad:()=>Mr});var zr=f({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Br=f({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Vr=f({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Mr=f({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ie={};b(Ie,{base8:()=>Or});var Or=f({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ue={};b(Ue,{identity:()=>jr});var jr=j({prefix:"\0",name:"identity",encode:r=>Ye(r),decode:r=>Ke(r)});var to=new TextEncoder,ro=new TextDecoder;var Pe={};b(Pe,{identity:()=>Hr});var ut=0,Gr="identity",ft=F;function Xr(r){return V(ut,ft(r))}var Hr={code:ut,name:Gr,encode:ft,digest:Xr};var Ne={};b(Ne,{sha256:()=>Jr,sha512:()=>Wr});function Ce({name:r,code:e,encode:t}){return new Te(r,e,t)}var Te=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 ht(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var Jr=Ce({name:"sha2-256",code:18,encode:ht("SHA-256")}),Wr=Ce({name:"sha2-512",code:19,encode:ht("SHA-512")});var ee={...Ue,...ve,...Ie,...be,...ye,...we,...Ae,...me,...Se,...Ee},wo={...Ne,...Pe};function M(r){return globalThis.Buffer!=null?new Uint8Array(r.buffer,r.byteOffset,r.byteLength):r}function H(r=0){return globalThis.Buffer?.allocUnsafe!=null?M(globalThis.Buffer.allocUnsafe(r)):new Uint8Array(r)}function wt(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var mt=wt("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Fe=wt("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=H(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Qr={utf8:mt,"utf-8":mt,hex:ee.base16,latin1:Fe,ascii:Fe,binary:Fe,...ee},ie=Qr;function x(r,e="utf8"){let t=ie[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):t.encoder.encode(r).substring(1)}var Kr=Math.pow(2,7),Yr=Math.pow(2,14),Zr=Math.pow(2,21),$e=Math.pow(2,28),De=Math.pow(2,35),Re=Math.pow(2,42),ke=Math.pow(2,49),p=128,h=127;function C(r){if(r<Kr)return 1;if(r<Yr)return 2;if(r<Zr)return 3;if(r<$e)return 4;if(r<De)return 5;if(r<Re)return 6;if(r<ke)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function en(r,e,t=0){switch(C(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 tn(r,e,t=0){switch(C(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 rn(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)*$e,t<p)||(t=r[e+5],n+=(t&h)*De,t<p)||(t=r[e+6],n+=(t&h)*Re,t<p)||(t=r[e+7],n+=(t&h)*ke,t<p))return n;throw new RangeError("Could not decode varint")}function nn(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)*$e,t<p)||(t=r.get(e+5),n+=(t&h)*De,t<p)||(t=r.get(e+6),n+=(t&h)*Re,t<p)||(t=r.get(e+7),n+=(t&h)*ke,t<p))return n;throw new RangeError("Could not decode varint")}function J(r,e,t=0){return e==null&&(e=H(C(r))),e instanceof Uint8Array?en(r,e,t):tn(r,e,t)}function O(r,e=0){return r instanceof Uint8Array?rn(r,e):nn(r,e)}function D(r,e){if(globalThis.Buffer!=null)return M(globalThis.Buffer.concat(r,e));e==null&&(e=r.reduce((o,i)=>o+i.length,0));let t=H(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return M(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,s=0,a=this.peekChar();if(a===void 0)return;let u=a==="0",m=2**(8*o)-1;for(;;){let l=this.readAtomically(()=>{let A=this.readChar();if(A===void 0)return;let R=Number.parseInt(A,e);if(!Number.isNaN(R))return R});if(l===void 0)break;if(i*=e,i+=l,i>m||(s+=1,t!==void 0&&s>t))return}if(s!==0)return!n&&u&&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 xt=45,on=15,W=new se;function Le(r){if(!(r.length>on))return W.new(r).parseWith(()=>W.readIPv4Addr())}function ze(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>xt))return W.new(r).parseWith(()=>W.readIPv6Addr())}function ae(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>xt))return W.new(r).parseWith(()=>W.readIPAddr())}var Vo=parseInt("0xFFFF",16),Mo=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Be(r,e="utf8"){let t=ie[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?M(globalThis.Buffer.from(r,"utf-8")):t.decoder.decode(`${t.prefix}${r}`)}function vt(r){return!!Le(r)}function Et(r){return!!ze(r)}function ce(r){return!!ae(r)}var At=vt,pn=Et,Ve=function(r){let e=0;if(r=r.toString().trim(),At(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(pn(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let i=At(t[n]),s;i&&(s=Ve(t[n]),t[n]=x(s.slice(0,2),"base16")),s!=null&&++n<8&&t.splice(n,0,x(s.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")},St=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={},Me={},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"],[777,-1,"memory"]];fn.forEach(r=>{let e=ln(...r);Me[e.code]=e,Q[e.name]=e});function ln(r,e,t,n,o){return{code:r,size:e,name:t,resolvable:!!n,path:!!o}}function c(r){if(typeof r=="number"){if(Me[r]!=null)return Me[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"),Ti=c("ipcidr");function je(r,e){switch(c(r).code){case 4:case 41:return mn(e);case 42:return Pt(e);case 6:case 273:case 33:case 132:return Ct(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Pt(e);case 421:return bn(e);case 444:return Tt(e);case 445:return Tt(e);case 466:return xn(e);default:return x(e,"base16")}}function qe(r,e){switch(c(r).code){case 4:return It(e);case 41:return It(e);case 42:return Ut(e);case 6:case 273:case 33:case 132:return _e(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Ut(e);case 421:return wn(e);case 444:return yn(e);case 445:return vn(e);case 466:return gn(e);default:return Be(e,"base16")}}var Oe=Object.values(ee).map(r=>r.decoder),hn=function(){let r=Oe[0].or(Oe[1]);return Oe.slice(2).forEach(e=>r=r.or(e)),r}();function It(r){if(!ce(r))throw new Error("invalid ip address");return Ve(r)}function mn(r){let e=St(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 _e(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function Ct(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function Ut(r){let e=Be(r),t=Uint8Array.from(J(e.length));return D([t,e],t.length+e.length)}function Pt(r){let e=O(r);if(r=r.slice(C(e)),r.length!==e)throw new Error("inconsistent lengths");return x(r)}function wn(r){let e;r[0]==="Q"||r[0]==="1"?e=oe(g.decode(`z${r}`)).bytes:e=z.parse(r).multihash.bytes;let t=Uint8Array.from(J(e.length));return D([t,e],t.length+e.length)}function gn(r){let e=hn.decode(r),t=Uint8Array.from(J(e.length));return D([t,e],t.length+e.length)}function xn(r){let e=O(r),t=r.slice(C(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+x(t,"base64url")}function bn(r){let e=O(r),t=r.slice(C(e));if(t.length!==e)throw new Error("inconsistent lengths");return x(t,"base58btc")}function yn(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=$.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=_e(n);return D([t,o],t.length+o.length)}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!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let t=$.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=_e(n);return D([t,o],t.length+o.length)}function Tt(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=x(e,"base32"),o=Ct(t);return`${n}:${o}`}function Nt(r){r=Ge(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 s=o[i],a=c(s);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(i++,i>=o.length)throw $t("invalid address: "+r);if(a.path===!0){n=Ge(o.slice(i).join("/")),e.push([a.code,qe(a.code,n)]),t.push([a.code,n]);break}let u=qe(a.code,o[i]);e.push([a.code,u]),t.push([a.code,je(a.code,u)])}return{string:Ft(t),bytes:He(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),s=C(i),a=c(i),u=En(a,r.slice(o+s));if(u===0){e.push([i]),t.push([i]),o+=s;continue}let m=r.slice(o+s,o+s+u);if(o+=u+s,o>r.length)throw $t("Invalid address Uint8Array: "+x(r,"base16"));e.push([i,m]);let l=je(i,m);if(t.push([i,l]),a.path===!0){n=l;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}),Ge(e.join("/"))}function He(r){return D(r.map(e=>{let t=c(e[0]),n=Uint8Array.from(J(t.code));return e.length>1&&e[1]!=null&&(n=D([n,e[1]])),n}))}function En(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+C(t)}}function Ge(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}function $t(r){return new Error("Error parsing address: "+r)}var An=Symbol.for("nodejs.util.inspect.custom"),Je=Symbol.for("@multiformats/js-multiaddr/multiaddr"),Sn=[c("dns").code,c("dns4").code,c("dns6").code,c("dnsaddr").code],de=class r{bytes;#t;#e;#r;#n;[Je]=!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=Nt(e)}else if(Rt(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="",s=c("tcp"),a=c("udp"),u=c("ip4"),m=c("ip6"),l=c("dns6"),A=c("ip6zone");for(let[v,d]of this.stringTuples())v===A.code&&(i=`%${d??""}`),Sn.includes(v)&&(t=s.name,o=443,n=`${d??""}${i}`,e=v===l.code?6:4),(v===s.code||v===a.code)&&(t=c(v).name,o=parseInt(d??"")),(v===u.code||v===m.code)&&(t=c(v).name,n=`${d??""}${i}`,e=v===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(He(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"?x(g.decode(`z${n}`),"base58btc"):x(z.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(e){return dt(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(i=>i.resolvable);if(t==null)return[this];let n=Dt.get(t.name);if(n==null)throw new re(`no available resolver for ${t.name}`,"ERR_NO_AVAILABLE_RESOLVER");return(await n(this,e)).map(i=>new r(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)}[An](){return`Multiaddr(${this.#t})`}};var Dt=new Map;function Rt(r){return!!r?.[Je]}function We(r){return new de(r)}var In=[c("tcp").code,c("dns").code,c("dnsaddr").code,c("dns4").code,c("dns6").code];function kt(r){let e;try{e=c("sni").code}catch{return null}for(let[t,n]of r)if(t===e&&n!==void 0)return n;return null}function Lt(r){return r.some(([e,t])=>e===c("tls").code)}function y(r,e,t){let n=zt[c(r).name];if(n===void 0)throw new Error(`Can't interpret protocol ${c(r).name}`);let o=n(e,t);return r===c("ip6").code?`[${o}]`:o}var zt={ip4:(r,e)=>r,ip6:(r,e)=>e.length===0?r:`[${r}]`,tcp:(r,e)=>{let t=e.pop();if(t===void 0)throw new Error("Unexpected end of multiaddr");return`tcp://${y(t[0],t[1]??"",e)}:${r}`},udp:(r,e)=>{let t=e.pop();if(t===void 0)throw new Error("Unexpected end of multiaddr");return`udp://${y(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===void 0)throw new Error("Unexpected end of multiaddr");return`${y(t[0],t[1]??"",e)}/ipfs/${r}`},p2p:(r,e)=>{let t=e.pop();if(t===void 0)throw new Error("Unexpected end of multiaddr");return`${y(t[0],t[1]??"",e)}/p2p/${r}`},http:(r,e)=>{let t=Lt(e),n=kt(e);if(t&&n!==null)return`https://${n}`;let o=t?"https://":"http://",i=e.pop();if(i===void 0)throw new Error("Unexpected end of multiaddr");let s=y(i[0],i[1]??"",e);return s=s.replace("tcp://",""),`${o}${s}`},tls:(r,e)=>{let t=e.pop();if(t===void 0)throw new Error("Unexpected end of multiaddr");return y(t[0],t[1]??"",e)},sni:(r,e)=>{let t=e.pop();if(t===void 0)throw new Error("Unexpected end of multiaddr");return y(t[0],t[1]??"",e)},https:(r,e)=>{let t=e.pop();if(t===void 0)throw new Error("Unexpected end of multiaddr");let n=y(t[0],t[1]??"",e);return n=n.replace("tcp://",""),`https://${n}`},ws:(r,e)=>{let t=Lt(e),n=kt(e);if(t&&n!==null)return`wss://${n}`;let o=t?"wss://":"ws://",i=e.pop();if(i===void 0)throw new Error("Unexpected end of multiaddr");let s=y(i[0],i[1]??"",e);return s=s.replace("tcp://",""),`${o}${s}`},wss:(r,e)=>{let t=e.pop();if(t===void 0)throw new Error("Unexpected end of multiaddr");let n=y(t[0],t[1]??"",e);return n=n.replace("tcp://",""),`wss://${n}`},"p2p-websocket-star":(r,e)=>{let t=e.pop();if(t===void 0)throw new Error("Unexpected end of multiaddr");return`${y(t[0],t[1]??"",e)}/p2p-websocket-star`},"p2p-webrtc-star":(r,e)=>{let t=e.pop();if(t===void 0)throw new Error("Unexpected end of multiaddr");return`${y(t[0],t[1]??"",e)}/p2p-webrtc-star`},"p2p-webrtc-direct":(r,e)=>{let t=e.pop();if(t===void 0)throw new Error("Unexpected end of multiaddr");return`${y(t[0],t[1]??"",e)}/p2p-webrtc-direct`}};function Un(r,e){let n=We(r).stringTuples(),o=n.pop();if(o===void 0)throw new Error("Unexpected end of multiaddr");let i=c(o[0]),s=zt[i.name];if(s==null)throw new Error(`No interpreter found for ${i.name}`);let a=s(o[1]??"",n);return e?.assumeHttp!==!1&&In.includes(o[0])&&(a=a.replace(/^.*:\/\//,""),o[1]==="443"?a=`https://${a}`:a=`http://${a}`),(a.startsWith("http://")||a.startsWith("https://"))&&(a=new URL(a).toString(),a.endsWith("/")&&(a=a.substring(0,a.length-1))),a}return jt(Pn);})(); | ||
| return MultiformatsMultiaddrToUri})); |
+23
-9
@@ -32,2 +32,9 @@ /** | ||
| import { multiaddr, protocols } from '@multiformats/multiaddr'; | ||
| const ASSUME_HTTP_CODES = [ | ||
| protocols('tcp').code, | ||
| protocols('dns').code, | ||
| protocols('dnsaddr').code, | ||
| protocols('dns4').code, | ||
| protocols('dns6').code | ||
| ]; | ||
| function extractSNI(ma) { | ||
@@ -208,15 +215,22 @@ let sniProtoCode; | ||
| let uri = interpreter(head[1] ?? '', parts); | ||
| if (opts?.assumeHttp !== false && head[0] === protocols('tcp').code) { | ||
| // If rightmost proto is tcp, we assume http here | ||
| uri = uri.replace('tcp://', 'http://'); | ||
| if (head[1] === '443' || head[1] === '80') { | ||
| if (head[1] === '443') { | ||
| uri = uri.replace('http://', 'https://'); | ||
| } | ||
| // Drop the port | ||
| uri = uri.substring(0, uri.lastIndexOf(':')); | ||
| if (opts?.assumeHttp !== false && ASSUME_HTTP_CODES.includes(head[0])) { | ||
| // strip any declared protocol | ||
| uri = uri.replace(/^.*:\/\//, ''); | ||
| if (head[1] === '443') { | ||
| uri = `https://${uri}`; | ||
| } | ||
| else { | ||
| uri = `http://${uri}`; | ||
| } | ||
| } | ||
| if (uri.startsWith('http://') || uri.startsWith('https://')) { | ||
| // this will strip default ports while keeping paths intact | ||
| uri = new URL(uri).toString(); | ||
| // strip trailing slash, e.g. http://127.0.0.1/ -> http://127.0.0.1 | ||
| if (uri.endsWith('/')) { | ||
| uri = uri.substring(0, uri.length - 1); | ||
| } | ||
| } | ||
| return uri; | ||
| } | ||
| //# sourceMappingURL=index.js.map |
+1
-1
| { | ||
| "name": "@multiformats/multiaddr-to-uri", | ||
| "version": "9.0.8", | ||
| "version": "10.0.0", | ||
| "description": "Convert a Multiaddr to a URI", | ||
@@ -5,0 +5,0 @@ "author": "Alan Shaw", |
+27
-9
@@ -39,2 +39,10 @@ /** | ||
| const ASSUME_HTTP_CODES = [ | ||
| protocols('tcp').code, | ||
| protocols('dns').code, | ||
| protocols('dnsaddr').code, | ||
| protocols('dns4').code, | ||
| protocols('dns6').code | ||
| ] | ||
| interface Interpreter { (value: string, ma: StringTuple[]): string } | ||
@@ -223,15 +231,25 @@ | ||
| let uri = interpreter(head[1] ?? '', parts) | ||
| if (opts?.assumeHttp !== false && head[0] === protocols('tcp').code) { | ||
| // If rightmost proto is tcp, we assume http here | ||
| uri = uri.replace('tcp://', 'http://') | ||
| if (head[1] === '443' || head[1] === '80') { | ||
| if (head[1] === '443') { | ||
| uri = uri.replace('http://', 'https://') | ||
| } | ||
| // Drop the port | ||
| uri = uri.substring(0, uri.lastIndexOf(':')) | ||
| if (opts?.assumeHttp !== false && ASSUME_HTTP_CODES.includes(head[0])) { | ||
| // strip any declared protocol | ||
| uri = uri.replace(/^.*:\/\//, '') | ||
| if (head[1] === '443') { | ||
| uri = `https://${uri}` | ||
| } else { | ||
| uri = `http://${uri}` | ||
| } | ||
| } | ||
| if (uri.startsWith('http://') || uri.startsWith('https://')) { | ||
| // this will strip default ports while keeping paths intact | ||
| uri = new URL(uri).toString() | ||
| // strip trailing slash, e.g. http://127.0.0.1/ -> http://127.0.0.1 | ||
| if (uri.endsWith('/')) { | ||
| uri = uri.substring(0, uri.length - 1) | ||
| } | ||
| } | ||
| return uri | ||
| } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
68708
1.82%643
4.38%