@libp2p/memory 1.0.4-d72b51184 → 1.0.5-d8f003e6e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +1 -1
- package/package.json +4 -4
package/dist/index.min.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PMemory = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var Libp2PMemory=(()=>{var Ot=Object.defineProperty;var Nr=Object.getOwnPropertyDescriptor;var kr=Object.getOwnPropertyNames;var Fr=Object.prototype.hasOwnProperty;var k=(r,t)=>{for(var e in t)Ot(r,e,{get:t[e],enumerable:!0})},Lr=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of kr(t))!Fr.call(r,o)&&o!==e&&Ot(r,o,{get:()=>t[o],enumerable:!(n=Nr(t,o))||n.enumerable});return r};var zr=r=>Lr(Ot({},"__esModule",{value:!0}),r);var ko={};k(ko,{memory:()=>No});var $e=Symbol.for("@libp2p/transport");var ze;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(ze||(ze={}));var H=class extends Error{static name="ConnectionFailedError";constructor(t="Connection failed"){super(t),this.name="ConnectionFailedError"}};var gt=class extends Error{static name="ListenError";constructor(t="Listen error"){super(t),this.name="ListenError"}};var Ve=(r,...t)=>{try{[...t]}catch{}};var wt=class extends EventTarget{#t=new Map;constructor(){super(),Ve(1/0,this)}listenerCount(t){let e=this.#t.get(t);return e==null?0:e.length}addEventListener(t,e,n){super.addEventListener(t,e,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:e,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,e,n){super.removeEventListener(t.toString(),e??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:s})=>s!==e),this.#t.set(t,o))}dispatchEvent(t){let e=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),e}safeDispatchEvent(t,e={}){return this.dispatchEvent(new CustomEvent(t,e))}};var Be=Symbol.for("@libp2p/service-capabilities"),Oo=Symbol.for("@libp2p/service-dependencies");var bt=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",v=2**(8*o)-1;for(;;){let g=this.readAtomically(()=>{let I=this.readChar();if(I===void 0)return;let M=Number.parseInt(I,t);if(!Number.isNaN(M))return M});if(g===void 0)break;if(s*=t,s+=g,s>v||(i+=1,e!==void 0&&i>e))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let n=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;n<e.length/2;n++){let o=n*2;if(n<e.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return e[o]=i[0],e[o+1]=i[1],e[o+2]=i[2],e[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];e[o]=s>>8,e[o+1]=s&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,o]=t(e);if(n===16)return e;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=t(s.subarray(0,i));return e.set(s.subarray(0,a),16-a),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Oe=45,$r=15,X=new bt;function Rt(r){if(!(r.length>$r))return X.new(r).parseWith(()=>X.readIPv4Addr())}function _t(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Oe))return X.new(r).parseWith(()=>X.readIPv6Addr())}function yt(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>Oe)return;let e=X.new(r).parseWith(()=>X.readIPAddr());if(e)return t&&e.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,e[0],e[1],e[2],e[3]]):e}function vt(r){return!!Rt(r)}function Et(r){return!!_t(r)}function It(r){return!!yt(r)}var Qt={};k(Qt,{base58btc:()=>P,base58flickr:()=>jr});var ms=new Uint8Array(0);function Re(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function V(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 je(r){return new TextDecoder().decode(r)}function Vr(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var a=r.length,c=r.charAt(0),v=Math.log(a)/Math.log(256),g=Math.log(256)/Math.log(a);function I(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 y=0,p=0,E=0,U=d.length;E!==U&&d[E]===0;)E++,y++;for(var A=(U-E)*g+1>>>0,N=new Uint8Array(A);E!==U;){for(var F=d[E],_=0,L=A-1;(F!==0||_<p)&&L!==-1;L--,_++)F+=256*N[L]>>>0,N[L]=F%a>>>0,F=F/a>>>0;if(F!==0)throw new Error("Non-zero carry");p=_,E++}for(var $=A-p;$!==A&&N[$]===0;)$++;for(var xt=c.repeat(y);$<A;++$)xt+=r.charAt(N[$]);return xt}function M(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var y=0;if(d[y]!==" "){for(var p=0,E=0;d[y]===c;)p++,y++;for(var U=(d.length-y)*v+1>>>0,A=new Uint8Array(U);d[y];){var N=e[d.charCodeAt(y)];if(N===255)return;for(var F=0,_=U-1;(N!==0||F<E)&&_!==-1;_--,F++)N+=a*A[_]>>>0,A[_]=N%256>>>0,N=N/256>>>0;if(N!==0)throw new Error("Non-zero carry");E=F,y++}if(d[y]!==" "){for(var L=U-E;L!==U&&A[L]===0;)L++;for(var $=new Uint8Array(p+(U-L)),xt=p;L!==U;)$[xt++]=A[L++];return $}}}function S(d){var y=M(d);if(y)return y;throw new Error(`Non-${t} character`)}return{encode:I,decodeUnsafe:M,decode:S}}var Br=Vr,Or=Br,We=Or;var jt=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},qt=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Ge(this,t)}},Wt=class{decoders;constructor(t){this.decoders=t}or(t){return Ge(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Ge(r,t){return new Wt({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Gt=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new jt(t,e,n),this.decoder=new qt(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function K({name:r,prefix:t,encode:e,decode:n}){return new Gt(r,t,e,n)}function j({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=We(e,r);return K({prefix:t,name:r,encode:n,decode:s=>V(o(s))})}function Rr(r,t,e,n){let o={};for(let g=0;g<t.length;++g)o[t[g]]=g;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*e/8|0),a=0,c=0,v=0;for(let g=0;g<s;++g){let I=o[r[g]];if(I===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<e|I,a+=e,a>=8&&(a-=8,i[v++]=255&c>>a)}if(a>=e||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return i}function _r(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;s.length*e&7;)s+="=";return s}function b({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return K({prefix:t,name:r,encode(o){return _r(o,n,e)},decode(o){return Rr(o,n,e,r)}})}var P=j({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),jr=j({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ht={};k(Ht,{base64:()=>qr,base64pad:()=>Wr,base64url:()=>Jt,base64urlpad:()=>Gr});var qr=b({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Wr=b({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Jt=b({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Gr=b({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Qr=r=>r.toString().split("/").slice(1),Z=r=>({match:t=>t.length<1?!1:r(t[0])?t.slice(1):!1,pattern:"fn"}),u=r=>({match:t=>Z(e=>e===r).match(t),pattern:r}),G=()=>({match:r=>Z(t=>typeof t=="string").match(r),pattern:"{string}"}),ct=()=>({match:r=>Z(t=>!isNaN(parseInt(t))).match(r),pattern:"{number}"}),m=()=>({match:r=>{if(r.length<2||r[0]!=="p2p"&&r[0]!=="ipfs")return!1;if(r[1].startsWith("Q")||r[1].startsWith("1"))try{P.decode(`z${r[1]}`)}catch{return!1}else return!1;return r.slice(2)},pattern:"/p2p/{peerid}"}),ut=()=>({match:r=>{if(r.length<2||r[0]!=="certhash")return!1;try{Jt.decode(r[1])}catch{return!1}return r.slice(2)},pattern:"/certhash/{certhash}"}),f=r=>({match:t=>{let e=r.match(t);return e===!1?t:e},pattern:`optional(${r.pattern})`}),C=(...r)=>({match:t=>{let e;for(let n of r){let o=n.match(t);o!==!1&&(e==null||o.length<e.length)&&(e=o)}return e??!1},pattern:`or(${r.map(t=>t.pattern).join(", ")})`}),l=(...r)=>({match:t=>{for(let e of r){let n=e.match(t);if(n===!1)return!1;t=n}return t},pattern:`and(${r.map(t=>t.pattern).join(", ")})`});function w(...r){function t(o){let s=Qr(o);for(let i of r){let a=i.match(s);if(a===!1)return!1;s=a}return s}function e(o){return t(o)!==!1}function n(o){let s=t(o);return s===!1?!1:s.length===0}return{matchers:r,matches:e,exactMatch:n}}var St=l(u("dns4"),G()),Pt=l(u("dns6"),G()),Ct=l(u("dnsaddr"),G()),Kt=l(u("dns"),G()),Cs=w(St,f(m())),Ts=w(Pt,f(m())),Us=w(Ct,f(m())),Ds=w(C(Kt,Ct,St,Pt),f(m())),Qe=l(u("ip4"),Z(vt)),Je=l(u("ip6"),Z(Et)),Zt=C(Qe,Je),B=C(Zt,Kt,St,Pt,Ct),Ms=w(C(Zt,l(C(Kt,Ct,St,Pt),f(m())))),Ns=w(Qe),ks=w(Je),Fs=w(Zt),Yt=l(B,u("tcp"),ct()),lt=l(B,u("udp"),ct()),Ls=w(l(Yt,f(m()))),zs=w(lt),te=l(lt,u("quic"),f(m())),Tt=l(lt,u("quic-v1"),f(m())),Jr=C(te,Tt),$s=w(te),Vs=w(Tt),Xt=C(B,Yt,lt,te,Tt),He=C(l(Xt,u("ws"),f(m()))),Bs=w(He),Xe=C(l(Xt,u("wss"),f(m())),l(Xt,u("tls"),f(l(u("sni"),G())),u("ws"),f(m()))),Os=w(Xe),Ke=l(lt,u("webrtc-direct"),f(ut()),f(ut()),f(m())),Rs=w(Ke),Ze=l(Tt,u("webtransport"),f(ut()),f(ut()),f(m())),_s=w(Ze),At=C(He,Xe,l(Yt,f(m())),l(Jr,f(m())),l(B,f(m())),Ke,Ze,m()),js=w(At),Hr=l(At,u("p2p-circuit"),m()),qs=w(Hr),Xr=C(l(At,u("p2p-circuit"),u("webrtc"),f(m())),l(At,u("webrtc"),f(m())),l(u("webrtc"),f(m()))),Ws=w(Xr),Kr=C(l(B,u("tcp"),ct(),u("http"),f(m())),l(B,u("http"),f(m()))),Gs=w(Kr),Zr=C(l(B,u("tcp"),C(l(u("443"),u("http")),l(ct(),u("https"))),f(m())),l(B,u("tls"),u("http"),f(m())),l(B,u("https"),f(m()))),Qs=w(Zr),Yr=C(l(u("memory"),G(),f(m()))),Ye=w(Yr);var ee={};k(ee,{base32:()=>O,base32hex:()=>nn,base32hexpad:()=>sn,base32hexpadupper:()=>an,base32hexupper:()=>on,base32pad:()=>en,base32padupper:()=>rn,base32upper:()=>tn,base32z:()=>cn});var O=b({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),tn=b({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),en=b({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),rn=b({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),nn=b({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),on=b({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),sn=b({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),an=b({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),cn=b({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var re={};k(re,{base36:()=>pt,base36upper:()=>un});var pt=j({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),un=j({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ln=rr,tr=128,pn=127,dn=~pn,fn=Math.pow(2,31);function rr(r,t,e){t=t||[],e=e||0;for(var n=e;r>=fn;)t[e++]=r&255|tr,r/=128;for(;r&dn;)t[e++]=r&255|tr,r>>>=7;return t[e]=r|0,rr.bytes=e-n+1,t}var hn=ne,mn=128,er=127;function ne(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw ne.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&er)<<o:(i&er)*Math.pow(2,o),o+=7}while(i>=mn);return ne.bytes=s-n,e}var xn=Math.pow(2,7),gn=Math.pow(2,14),wn=Math.pow(2,21),bn=Math.pow(2,28),yn=Math.pow(2,35),vn=Math.pow(2,42),En=Math.pow(2,49),In=Math.pow(2,56),An=Math.pow(2,63),Sn=function(r){return r<xn?1:r<gn?2:r<wn?3:r<bn?4:r<yn?5:r<vn?6:r<En?7:r<In?8:r<An?9:10},Pn={encode:ln,decode:hn,encodingLength:Sn},Cn=Pn,dt=Cn;function ft(r,t=0){return[dt.decode(r,t),dt.decode.bytes]}function Y(r,t,e=0){return dt.encode(r,t,e),t}function tt(r){return dt.encodingLength(r)}function Q(r,t){let e=t.byteLength,n=tt(r),o=n+tt(e),s=new Uint8Array(o+e);return Y(r,s,0),Y(e,s,n),s.set(t,o),new et(r,e,t,s)}function Dt(r){let t=V(r),[e,n]=ft(t),[o,s]=ft(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new et(e,o,i,t)}function nr(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Re(r.bytes,e.bytes)}}var et=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function or(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Un(e,oe(r),t??P.encoder);default:return Dn(e,oe(r),t??O.encoder)}}var sr=new WeakMap;function oe(r){let t=sr.get(r);if(t==null){let e=new Map;return sr.set(r,e),e}return t}var q=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==ht)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Mn)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=Q(t,e);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(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&nr(t.multihash,n.multihash)}toString(t){return or(this,t)}toJSON(){return{"/":or(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:s,bytes:i}=e;return new r(n,o,s,i??ir(n,o,s.bytes))}else if(e[Nn]===!0){let{version:n,multihash:o,code:s}=e,i=Dt(o);return r.create(n,s,i)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==ht)throw new Error(`Version 0 CID must use dag-pb (code: ${ht}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=ir(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,ht,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=V(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new et(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[I,M]=ft(t.subarray(e));return e+=M,I},o=n(),s=ht;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),c=n(),v=e+c,g=v-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:g,size:v}}static parse(t,e){let[n,o]=Tn(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return oe(s).set(n,t),s}};function Tn(r,t){switch(r[0]){case"Q":{let e=t??P;return[P.prefix,e.decode(`${P.prefix}${r}`)]}case P.prefix:{let e=t??P;return[P.prefix,e.decode(r)]}case O.prefix:{let e=t??O;return[O.prefix,e.decode(r)]}case pt.prefix:{let e=t??pt;return[pt.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function Un(r,t,e){let{prefix:n}=e;if(n!==P.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function Dn(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var ht=112,Mn=18;function ir(r,t,e){let n=tt(r),o=n+tt(t),s=new Uint8Array(o+e.byteLength);return Y(r,s,0),Y(t,s,n),s.set(e,o),s}var Nn=Symbol.for("@ipld/js-cid/CID");function ar(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}var se={};k(se,{base10:()=>kn});var kn=j({prefix:"9",name:"base10",alphabet:"0123456789"});var ie={};k(ie,{base16:()=>Fn,base16upper:()=>Ln});var Fn=b({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Ln=b({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ae={};k(ae,{base2:()=>zn});var zn=b({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ce={};k(ce,{base256emoji:()=>Rn});var cr=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}"),$n=cr.reduce((r,t,e)=>(r[e]=t,r),[]),Vn=cr.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Bn(r){return r.reduce((t,e)=>(t+=$n[e],t),"")}function On(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=Vn[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var Rn=K({prefix:"\u{1F680}",name:"base256emoji",encode:Bn,decode:On});var ue={};k(ue,{base8:()=>_n});var _n=b({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var le={};k(le,{identity:()=>jn});var jn=K({prefix:"\0",name:"identity",encode:r=>je(r),decode:r=>_e(r)});var hi=new TextEncoder,mi=new TextDecoder;var pe={};k(pe,{identity:()=>Jn});var ur=0,Gn="identity",lr=V;function Qn(r){return Q(ur,lr(r))}var Jn={code:ur,name:Gn,encode:lr,digest:Qn};var he={};k(he,{sha256:()=>Hn,sha512:()=>Xn});function fe({name:r,code:t,encode:e}){return new de(r,t,e)}var de=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?Q(this.code,e):e.then(n=>Q(this.code,n))}else throw Error("Unknown type, must be binary type")}};function dr(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Hn=fe({name:"sha2-256",code:18,encode:dr("SHA-256")}),Xn=fe({name:"sha2-512",code:19,encode:dr("SHA-512")});var mt={...le,...ae,...ue,...se,...ie,...ee,...re,...Qt,...Ht,...ce},Ti={...he,...pe};function nt(r=0){return new Uint8Array(r)}function hr(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var fr=hr("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),me=hr("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=nt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Kn={utf8:fr,"utf-8":fr,hex:mt.base16,latin1:me,ascii:me,binary:me,...mt},Mt=Kn;function D(r,t="utf8"){let e=Mt[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Zn=Math.pow(2,7),Yn=Math.pow(2,14),to=Math.pow(2,21),xe=Math.pow(2,28),ge=Math.pow(2,35),we=Math.pow(2,42),be=Math.pow(2,49),h=128,T=127;function z(r){if(r<Zn)return 1;if(r<Yn)return 2;if(r<to)return 3;if(r<xe)return 4;if(r<ge)return 5;if(r<we)return 6;if(r<be)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function eo(r,t,e=0){switch(z(r)){case 8:t[e++]=r&255|h,r/=128;case 7:t[e++]=r&255|h,r/=128;case 6:t[e++]=r&255|h,r/=128;case 5:t[e++]=r&255|h,r/=128;case 4:t[e++]=r&255|h,r>>>=7;case 3:t[e++]=r&255|h,r>>>=7;case 2:t[e++]=r&255|h,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function ro(r,t,e=0){switch(z(r)){case 8:t.set(e++,r&255|h),r/=128;case 7:t.set(e++,r&255|h),r/=128;case 6:t.set(e++,r&255|h),r/=128;case 5:t.set(e++,r&255|h),r/=128;case 4:t.set(e++,r&255|h),r>>>=7;case 3:t.set(e++,r&255|h),r>>>=7;case 2:t.set(e++,r&255|h),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function no(r,t){let e=r[t],n=0;if(n+=e&T,e<h||(e=r[t+1],n+=(e&T)<<7,e<h)||(e=r[t+2],n+=(e&T)<<14,e<h)||(e=r[t+3],n+=(e&T)<<21,e<h)||(e=r[t+4],n+=(e&T)*xe,e<h)||(e=r[t+5],n+=(e&T)*ge,e<h)||(e=r[t+6],n+=(e&T)*we,e<h)||(e=r[t+7],n+=(e&T)*be,e<h))return n;throw new RangeError("Could not decode varint")}function oo(r,t){let e=r.get(t),n=0;if(n+=e&T,e<h||(e=r.get(t+1),n+=(e&T)<<7,e<h)||(e=r.get(t+2),n+=(e&T)<<14,e<h)||(e=r.get(t+3),n+=(e&T)<<21,e<h)||(e=r.get(t+4),n+=(e&T)*xe,e<h)||(e=r.get(t+5),n+=(e&T)*ge,e<h)||(e=r.get(t+6),n+=(e&T)*we,e<h)||(e=r.get(t+7),n+=(e&T)*be,e<h))return n;throw new RangeError("Could not decode varint")}function ot(r,t,e=0){return t==null&&(t=nt(z(r))),t instanceof Uint8Array?eo(r,t,e):ro(r,t,e)}function J(r,t=0){return r instanceof Uint8Array?no(r,t):oo(r,t)}function R(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=nt(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var Ji=parseInt("0xFFFF",16),Hi=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Nt(r,t="utf8"){let e=Mt[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}var wr=vt,uo=Et,ye=function(r){let t=0;if(r=r.toString().trim(),wr(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(uo(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=wr(e[n]),i;s&&(i=ye(e[n]),e[n]=D(i.slice(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,D(i.slice(2,4),"base16"))}if(e[0]==="")for(;e.length<8;)e.unshift("0");else if(e[e.length-1]==="")for(;e.length<8;)e.push("0");else if(e.length<8){for(n=0;n<e.length&&e[n]!=="";n++);let s=[n,1];for(n=9-e.length;n>0;n--)s.push("0");e.splice.apply(e,s)}let o=new Uint8Array(t+16);for(n=0;n<e.length;n++){let s=parseInt(e[n],16);o[t++]=s>>8&255,o[t++]=s&255}return o}throw new Error("invalid ip address")},br=function(r,t=0,e){t=~~t,e=e??r.length-t;let n=new DataView(r.buffer);if(e===4){let o=[];for(let s=0;s<e;s++)o.push(r[t+s]);return o.join(".")}if(e===16){let o=[];for(let s=0;s<e;s+=2)o.push(n.getUint16(t+s).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var st={},ve={},po=[[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"]];po.forEach(r=>{let t=fo(...r);ve[t.code]=t,st[t.name]=t});function fo(r,t,e,n,o){return{code:r,size:t,name:e,resolvable:!!n,path:!!o}}function x(r){if(typeof r=="number"){if(ve[r]!=null)return ve[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(st[r]!=null)return st[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var Na=x("ip4"),ka=x("ip6"),Fa=x("ipcidr");function Se(r,t){switch(x(r).code){case 4:case 41:return mo(t);case 42:return Ae(t);case 43:return D(t,"base10");case 6:case 273:case 33:case 132:return Er(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Ae(t);case 421:return bo(t);case 444:return vr(t);case 445:return vr(t);case 466:return wo(t);case 481:return globalThis.encodeURIComponent(Ae(t));default:return D(t,"base16")}}function Pe(r,t){switch(x(r).code){case 4:return yr(t);case 41:return yr(t);case 42:return Ie(t);case 43:return Nt(t,"base10");case 6:case 273:case 33:case 132:return Ce(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Ie(t);case 421:return xo(t);case 444:return yo(t);case 445:return vo(t);case 466:return go(t);case 481:return Ie(globalThis.decodeURIComponent(t));default:return Nt(t,"base16")}}var Ee=Object.values(mt).map(r=>r.decoder),ho=function(){let r=Ee[0].or(Ee[1]);return Ee.slice(2).forEach(t=>r=r.or(t)),r}();function yr(r){if(!It(r))throw new Error("invalid ip address");return ye(r)}function mo(r){let t=br(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!It(t))throw new Error("invalid ip address");return t}function Ce(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function Er(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function Ie(r){let t=Nt(r),e=Uint8Array.from(ot(t.length));return R([e,t],e.length+t.length)}function Ae(r){let t=J(r);if(r=r.slice(z(t)),r.length!==t)throw new Error("inconsistent lengths");return D(r)}function xo(r){let t;r[0]==="Q"||r[0]==="1"?t=Dt(P.decode(`z${r}`)).bytes:t=q.parse(r).multihash.bytes;let e=Uint8Array.from(ot(t.length));return R([e,t],e.length+t.length)}function go(r){let t=ho.decode(r),e=Uint8Array.from(ot(t.length));return R([e,t],e.length+t.length)}function wo(r){let t=J(r),e=r.slice(z(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+D(e,"base64url")}function bo(r){let t=J(r),e=r.slice(z(t));if(e.length!==t)throw new Error("inconsistent lengths");return D(e,"base58btc")}function yo(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let e=O.decode("b"+t[0]),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Ce(n);return R([e,o],e.length+o.length)}function vo(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let e=O.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Ce(n);return R([e,o],e.length+o.length)}function vr(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=D(t,"base32"),o=Er(e);return`${n}:${o}`}function Ir(r){r=Te(r);let t=[],e=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let s=0;s<o.length;s++){let i=o[s],a=x(i);if(a.size===0){t.push([a.code]),e.push([a.code]);continue}if(s++,s>=o.length)throw Sr("invalid address: "+r);if(a.path===!0){n=Te(o.slice(s).join("/")),t.push([a.code,Pe(a.code,n)]),e.push([a.code,n]);break}let c=Pe(a.code,o[s]);t.push([a.code,c]),e.push([a.code,Se(a.code,c)])}return{string:Ar(e),bytes:De(t),tuples:t,stringTuples:e,path:n}}function Ue(r){let t=[],e=[],n=null,o=0;for(;o<r.length;){let s=J(r,o),i=z(s),a=x(s),c=Eo(a,r.slice(o+i));if(c===0){t.push([s]),e.push([s]),o+=i;continue}let v=r.slice(o+i,o+i+c);if(o+=c+i,o>r.length)throw Sr("Invalid address Uint8Array: "+D(r,"base16"));t.push([s,v]);let g=Se(s,v);if(e.push([s,g]),a.path===!0){n=g;break}}return{bytes:Uint8Array.from(r),string:Ar(e),tuples:t,stringTuples:e,path:n}}function Ar(r){let t=[];return r.map(e=>{let n=x(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),Te(t.join("/"))}function De(r){return R(r.map(t=>{let e=x(t[0]),n=Uint8Array.from(ot(e.code));return t.length>1&&t[1]!=null&&(n=R([n,t[1]])),n}))}function Eo(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=J(t instanceof Uint8Array?t:Uint8Array.from(t));return e+z(e)}}function Te(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}function Sr(r){return new Error("Error parsing address: "+r)}var Io=Symbol.for("nodejs.util.inspect.custom"),Ne=Symbol.for("@multiformats/js-multiaddr/multiaddr"),Ao=[x("dns").code,x("dns4").code,x("dns6").code,x("dnsaddr").code],Me=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}},kt=class r{bytes;#t;#e;#r;#n;[Ne]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=Ue(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=Ir(t)}else if(Cr(t))e=Ue(t.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=e.bytes,this.#t=e.string,this.#e=e.tuples,this.#r=e.stringTuples,this.#n=e.path}toString(){return this.#t}toJSON(){return this.toString()}toOptions(){let t,e,n,o,s="",i=x("tcp"),a=x("udp"),c=x("ip4"),v=x("ip6"),g=x("dns6"),I=x("ip6zone");for(let[S,d]of this.stringTuples())S===I.code&&(s=`%${d??""}`),Ao.includes(S)&&(e=i.name,o=443,n=`${d??""}${s}`,t=S===g.code?6:4),(S===i.code||S===a.code)&&(e=x(S).name,o=parseInt(d??"")),(S===c.code||S===v.code)&&(e=x(S).name,n=`${d??""}${s}`,t=S===v.code?6:4);if(t==null||e==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:t,host:n,transport:e,port:o}}protos(){return this.#e.map(([t])=>Object.assign({},x(t)))}protoCodes(){return this.#e.map(([t])=>t)}protoNames(){return this.#e.map(([t])=>x(t).name)}tuples(){return this.#e.map(([t,e])=>e==null?[t]:[t,e])}stringTuples(){return this.#r.map(([t,e])=>e==null?[t]:[t,e])}encapsulate(t){return t=new r(t),new r(this.toString()+t.toString())}decapsulate(t){let e=t.toString(),n=this.toString(),o=n.lastIndexOf(e);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new r(n.slice(0,o))}decapsulateCode(t){let e=this.tuples();for(let n=e.length-1;n>=0;n--)if(e[n][0]===t)return new r(De(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,o])=>{n===st.p2p.code&&t.push([n,o]),n===st["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?D(P.decode(`z${n}`),"base58btc"):D(q.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(t){return ar(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(s=>s.resolvable);if(e==null)return[this];let n=Pr.get(e.name);if(n==null)throw new Me(`no available resolver for ${e.name}`);return(await n(this,t)).map(s=>W(s))}nodeAddress(){let t=this.toOptions();if(t.transport!=="tcp"&&t.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${t.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:t.family,address:t.host,port:t.port}}isThinWaistAddress(t){let e=(t??this).protos();return!(e.length!==2||e[0].code!==4&&e[0].code!==41||e[1].code!==6&&e[1].code!==273)}[Io](){return`Multiaddr(${this.#t})`}};var Pr=new Map;function Cr(r){return!!r?.[Ne]}function W(r){return new kt(r)}var Tr=()=>{let r=new Error("Delay aborted");return r.name="AbortError",r},So=new WeakMap;function Po({clearTimeout:r,setTimeout:t}={}){return(e,{value:n,signal:o}={})=>{if(o?.aborted)return Promise.reject(Tr());let s,i,a,c=r??clearTimeout,v=()=>{c(s),a(Tr())},g=()=>{o&&o.removeEventListener("abort",v)},I=new Promise((M,S)=>{i=()=>{g(),M(n)},a=S,s=(t??setTimeout)(i,e)});return o&&o.addEventListener("abort",v,{once:!0}),So.set(I,()=>{c(s),s=null,i()}),I}}var Co=Po(),Ft=Co;function To(r){let[t,e]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>t.next(),push:o=>{n.push(o)},next:()=>n.length>0?{done:!1,value:n.shift()}:t.next(),[e](){return this}}}var Ur=To;function Uo(r){return r[Symbol.asyncIterator]!=null}function Do(r,t){let e=0;if(Uo(r))return async function*(){for await(let c of r)yield t(c,e++)}();let n=Ur(r),{value:o,done:s}=n.next();if(s===!0)return function*(){}();let i=t(o,e++);if(typeof i.then=="function")return async function*(){yield await i;for await(let c of n)yield t(c,e++)}();let a=t;return function*(){yield i;for(let c of n)yield a(c,e++)}()}var ke=Do;function Lt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var zt=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||t-1&t)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},it=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new zt(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new zt(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var Fe=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function Le(r={}){return Mo(e=>{let n=e.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function Mo(r,t){t=t??{};let e=t.onEnd,n=new it,o,s,i,a=Lt(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((p,E)=>{s=U=>{s=null,n.push(U);try{p(r(n))}catch(A){E(A)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Lt()})}},v=p=>s!=null?s(p):(n.push(p),o),g=p=>(n=new it,s!=null?s({error:p}):(n.push({error:p}),o)),I=p=>{if(i)return o;if(t?.objectMode!==!0&&p?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return v({done:!1,value:p})},M=p=>i?o:(i=!0,p!=null?g(p):v({done:!0})),S=()=>(n=new it,M(),{done:!0}),d=p=>(M(p),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:S,throw:d,push:I,end:M,get readableLength(){return n.size},onEmpty:async p=>{let E=p?.signal;if(E?.throwIfAborted(),n.isEmpty())return;let U,A;E!=null&&(U=new Promise((N,F)=>{A=()=>{F(new Fe)},E.addEventListener("abort",A)}));try{await Promise.race([a.promise,U])}finally{A!=null&&E!=null&&E?.removeEventListener("abort",A)}}},e==null)return o;let y=o;return o={[Symbol.asyncIterator](){return this},next(){return y.next()},throw(p){return y.throw(p),e!=null&&(e(p),e=void 0),{done:!0}},return(){return y.return(),e!=null&&(e(),e=void 0),{done:!0}},push:I,end(p){return y.end(p),e!=null&&(e(p),e=void 0),o},get readableLength(){return y.readableLength},onEmpty:p=>y.onEmpty(p)},o}var at=new Map,$t=class{components;init;connections;latency;constructor(t,e){this.components=t,this.init=e,this.connections=new Set,this.latency=e.latency??0}async dial(t){let e=Le(),n=Le(),o=this,s={source:async function*(){yield*ke(n,async a=>(o.latency>0&&await Ft(o.latency),a))}(),sink:async a=>{for await(let c of a)e.push(c)},close:async()=>{e.end(),this.connections.delete(s),s.timeline.close=Date.now(),n.end(),this.connections.delete(i),i.timeline.close=Date.now()},abort:a=>{e.end(a),this.connections.delete(s),s.timeline.close=Date.now(),n.end(a),this.connections.delete(i),i.timeline.close=Date.now()},timeline:{open:Date.now()},remoteAddr:W(`${this.init.address}/p2p/${this.components.peerId}`),log:this.components.logger.forComponent("libp2p:memory:outgoing:1")},i={source:async function*(){yield*ke(e,async a=>(o.latency>0&&await Ft(o.latency),a))}(),sink:async a=>{for await(let c of a)n.push(c)},close:async()=>{n.end(),this.connections.delete(i),i.timeline.close=Date.now(),e.end(),this.connections.delete(s),s.timeline.close=Date.now()},abort:a=>{n.end(a),this.connections.delete(i),i.timeline.close=Date.now(),e.end(a),this.connections.delete(s),s.timeline.close=Date.now()},timeline:{open:Date.now()},remoteAddr:W(`${this.init.address}-outgoing/p2p/${t}`),log:this.components.logger.forComponent("libp2p:memory:outgoing:1")};return this.connections.add(s),this.connections.add(i),await Ft(this.latency),this.init.onConnection(i),s}close(){[...this.connections].forEach(t=>{t.abort(new H("Memory Connection closed"))})}};var Dr="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";var Mr=(r=21)=>{let t="",e=crypto.getRandomValues(new Uint8Array(r|=0));for(;r--;)t+=Dr[e[r]&63];return t};var Vt=class extends wt{listenAddr;connection;components;init;constructor(t,e){super(),this.components=t,this.init=e}async listen(t){let[[,e]]=t.stringTuples(),n=`/memory/${e??Mr()}`;if(e!=null&&at.has(n))throw new gt(`Memory address ${n} already in use`);this.connection=new $t(this.components,{...this.init,onConnection:this.onConnection.bind(this),address:n}),this.listenAddr=W(n),at.set(n,this.connection),queueMicrotask(()=>{this.safeDispatchEvent("listening")})}onConnection(t){let e;this.init.inboundUpgradeTimeout!=null&&(e=AbortSignal.timeout(this.init.inboundUpgradeTimeout)),this.init.upgrader.upgradeInbound(t,{...this.init.upgraderOptions,signal:e}).catch(n=>{t.abort(n)})}getAddrs(){return this.listenAddr==null?[]:[this.listenAddr]}async close(){this.connection?.close(),this.listenAddr!=null&&at.delete(this.listenAddr.toString()),queueMicrotask(()=>{this.safeDispatchEvent("close")})}};var Bt=class{components;init;constructor(t,e={}){this.components=t,this.init=e}[$e]=!0;[Symbol.toStringTag]="@libp2p/memory";[Be]=["@libp2p/transport"];async dial(t,e){e.signal?.throwIfAborted();let n=at.get(`${t.getPeerId()==null?t:t.decapsulate("/p2p")}`);if(n==null)throw new H(`No memory listener found at ${t}`);let o=await n.dial(this.components.peerId);try{return e.signal?.throwIfAborted(),await e.upgrader.upgradeOutbound(o,{...e,...this.init.upgraderOptions})}catch(s){throw o.abort(s),s}}createListener(t){return new Vt(this.components,{...t,...this.init})}listenFilter(t){return t.filter(e=>Ye.exactMatch(e))}dialFilter(t){return this.listenFilter(t)}};function No(r){return t=>new Bt(t,r)}return zr(ko);})();
|
|
2
|
+
"use strict";var Libp2PMemory=(()=>{var Rt=Object.defineProperty;var Nr=Object.getOwnPropertyDescriptor;var Mr=Object.getOwnPropertyNames;var kr=Object.prototype.hasOwnProperty;var k=(r,t)=>{for(var e in t)Rt(r,e,{get:t[e],enumerable:!0})},Fr=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Mr(t))!kr.call(r,o)&&o!==e&&Rt(r,o,{get:()=>t[o],enumerable:!(n=Nr(t,o))||n.enumerable});return r};var Lr=r=>Fr(Rt({},"__esModule",{value:!0}),r);var Mo={};k(Mo,{memory:()=>No});var Ve=Symbol.for("@libp2p/transport");var $e;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})($e||($e={}));var H=class extends Error{static name="ConnectionFailedError";constructor(t="Connection failed"){super(t),this.name="ConnectionFailedError"}};var wt=class extends Error{static name="ListenError";constructor(t="Listen error"){super(t),this.name="ListenError"}};var gt=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let e=this.#t.get(t);return e==null?0:e.length}addEventListener(t,e,n){super.addEventListener(t,e,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:e,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,e,n){super.removeEventListener(t.toString(),e??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:s})=>s!==e),this.#t.set(t,o))}dispatchEvent(t){let e=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),e}safeDispatchEvent(t,e={}){return this.dispatchEvent(new CustomEvent(t,e))}};var Be=Symbol.for("@libp2p/service-capabilities"),$o=Symbol.for("@libp2p/service-dependencies");var bt=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let e=this.index,n=t();return n===void 0&&(this.index=e),n}parseWith(t){let e=t();if(this.index===this.input.length)return e}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let e=this.readChar();if(e===t)return e})}readSeparator(t,e,n){return this.readAtomically(()=>{if(!(e>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,e,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let c=a==="0",v=2**(8*o)-1;for(;;){let w=this.readAtomically(()=>{let I=this.readChar();if(I===void 0)return;let N=Number.parseInt(I,t);if(!Number.isNaN(N))return N});if(w===void 0)break;if(s*=t,s+=w,s>v||(i+=1,e!==void 0&&i>e))return}if(i!==0)return!n&&c&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let e=0;e<t.length;e++){let n=this.readSeparator(".",e,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[e]=n}return t})}readIPv6Addr(){let t=e=>{for(let n=0;n<e.length/2;n++){let o=n*2;if(n<e.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return e[o]=i[0],e[o+1]=i[1],e[o+2]=i[2],e[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];e[o]=s>>8,e[o+1]=s&255}return[e.length,!1]};return this.readAtomically(()=>{let e=new Uint8Array(16),[n,o]=t(e);if(n===16)return e;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=t(s.subarray(0,i));return e.set(s.subarray(0,a),16-a),e})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Oe=45,zr=15,X=new bt;function _t(r){if(!(r.length>zr))return X.new(r).parseWith(()=>X.readIPv4Addr())}function jt(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>Oe))return X.new(r).parseWith(()=>X.readIPv6Addr())}function yt(r,t=!1){if(r.includes("%")&&(r=r.split("%")[0]),r.length>Oe)return;let e=X.new(r).parseWith(()=>X.readIPAddr());if(e)return t&&e.length===4?Uint8Array.from([0,0,0,0,0,0,0,0,0,0,255,255,e[0],e[1],e[2],e[3]]):e}function vt(r){return!!_t(r)}function Et(r){return!!jt(r)}function It(r){return!!yt(r)}var Jt={};k(Jt,{base58btc:()=>P,base58flickr:()=>_r});var ps=new Uint8Array(0);function Re(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function V(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 je(r){return new TextDecoder().decode(r)}function $r(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var a=r.length,c=r.charAt(0),v=Math.log(a)/Math.log(256),w=Math.log(256)/Math.log(a);function I(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 y=0,p=0,E=0,U=d.length;E!==U&&d[E]===0;)E++,y++;for(var A=(U-E)*w+1>>>0,M=new Uint8Array(A);E!==U;){for(var F=d[E],_=0,L=A-1;(F!==0||_<p)&&L!==-1;L--,_++)F+=256*M[L]>>>0,M[L]=F%a>>>0,F=F/a>>>0;if(F!==0)throw new Error("Non-zero carry");p=_,E++}for(var $=A-p;$!==A&&M[$]===0;)$++;for(var xt=c.repeat(y);$<A;++$)xt+=r.charAt(M[$]);return xt}function N(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var y=0;if(d[y]!==" "){for(var p=0,E=0;d[y]===c;)p++,y++;for(var U=(d.length-y)*v+1>>>0,A=new Uint8Array(U);d[y];){var M=e[d.charCodeAt(y)];if(M===255)return;for(var F=0,_=U-1;(M!==0||F<E)&&_!==-1;_--,F++)M+=a*A[_]>>>0,A[_]=M%256>>>0,M=M/256>>>0;if(M!==0)throw new Error("Non-zero carry");E=F,y++}if(d[y]!==" "){for(var L=U-E;L!==U&&A[L]===0;)L++;for(var $=new Uint8Array(p+(U-L)),xt=p;L!==U;)$[xt++]=A[L++];return $}}}function S(d){var y=N(d);if(y)return y;throw new Error(`Non-${t} character`)}return{encode:I,decodeUnsafe:N,decode:S}}var Vr=$r,Br=Vr,We=Br;var qt=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Wt=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Ge(this,t)}},Gt=class{decoders;constructor(t){this.decoders=t}or(t){return Ge(this,t)}decode(t){let e=t[0],n=this.decoders[e];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Ge(r,t){return new Gt({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Qt=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new qt(t,e,n),this.decoder=new Wt(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function K({name:r,prefix:t,encode:e,decode:n}){return new Qt(r,t,e,n)}function j({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=We(e,r);return K({prefix:t,name:r,encode:n,decode:s=>V(o(s))})}function Or(r,t,e,n){let o={};for(let w=0;w<t.length;++w)o[t[w]]=w;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*e/8|0),a=0,c=0,v=0;for(let w=0;w<s;++w){let I=o[r[w]];if(I===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<e|I,a+=e,a>=8&&(a-=8,i[v++]=255&c>>a)}if(a>=e||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return i}function Rr(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;s.length*e&7;)s+="=";return s}function b({name:r,prefix:t,bitsPerChar:e,alphabet:n}){return K({prefix:t,name:r,encode(o){return Rr(o,n,e)},decode(o){return Or(o,n,e,r)}})}var P=j({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),_r=j({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Xt={};k(Xt,{base64:()=>jr,base64pad:()=>qr,base64url:()=>Ht,base64urlpad:()=>Wr});var jr=b({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),qr=b({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ht=b({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Wr=b({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Gr=r=>r.toString().split("/").slice(1),Z=r=>({match:t=>t.length<1?!1:r(t[0])?t.slice(1):!1,pattern:"fn"}),u=r=>({match:t=>Z(e=>e===r).match(t),pattern:r}),G=()=>({match:r=>Z(t=>typeof t=="string").match(r),pattern:"{string}"}),ct=()=>({match:r=>Z(t=>!isNaN(parseInt(t))).match(r),pattern:"{number}"}),m=()=>({match:r=>{if(r.length<2||r[0]!=="p2p"&&r[0]!=="ipfs")return!1;if(r[1].startsWith("Q")||r[1].startsWith("1"))try{P.decode(`z${r[1]}`)}catch{return!1}else return!1;return r.slice(2)},pattern:"/p2p/{peerid}"}),ut=()=>({match:r=>{if(r.length<2||r[0]!=="certhash")return!1;try{Ht.decode(r[1])}catch{return!1}return r.slice(2)},pattern:"/certhash/{certhash}"}),f=r=>({match:t=>{let e=r.match(t);return e===!1?t:e},pattern:`optional(${r.pattern})`}),C=(...r)=>({match:t=>{let e;for(let n of r){let o=n.match(t);o!==!1&&(e==null||o.length<e.length)&&(e=o)}return e??!1},pattern:`or(${r.map(t=>t.pattern).join(", ")})`}),l=(...r)=>({match:t=>{for(let e of r){let n=e.match(t);if(n===!1)return!1;t=n}return t},pattern:`and(${r.map(t=>t.pattern).join(", ")})`});function g(...r){function t(o){let s=Gr(o);for(let i of r){let a=i.match(s);if(a===!1)return!1;s=a}return s}function e(o){return t(o)!==!1}function n(o){let s=t(o);return s===!1?!1:s.length===0}return{matchers:r,matches:e,exactMatch:n}}var St=l(u("dns4"),G()),Pt=l(u("dns6"),G()),Ct=l(u("dnsaddr"),G()),Zt=l(u("dns"),G()),Is=g(St,f(m())),As=g(Pt,f(m())),Ss=g(Ct,f(m())),Ps=g(C(Zt,Ct,St,Pt),f(m())),Qe=l(u("ip4"),Z(vt)),Je=l(u("ip6"),Z(Et)),Yt=C(Qe,Je),B=C(Yt,Zt,St,Pt,Ct),Cs=g(C(Yt,l(C(Zt,Ct,St,Pt),f(m())))),Ts=g(Qe),Us=g(Je),Ds=g(Yt),te=l(B,u("tcp"),ct()),lt=l(B,u("udp"),ct()),Ns=g(l(te,f(m()))),Ms=g(lt),ee=l(lt,u("quic"),f(m())),Tt=l(lt,u("quic-v1"),f(m())),Qr=C(ee,Tt),ks=g(ee),Fs=g(Tt),Kt=C(B,te,lt,ee,Tt),He=C(l(Kt,u("ws"),f(m()))),Ls=g(He),Xe=C(l(Kt,u("wss"),f(m())),l(Kt,u("tls"),f(l(u("sni"),G())),u("ws"),f(m()))),zs=g(Xe),Ke=l(lt,u("webrtc-direct"),f(ut()),f(ut()),f(m())),$s=g(Ke),Ze=l(Tt,u("webtransport"),f(ut()),f(ut()),f(m())),Vs=g(Ze),At=C(He,Xe,l(te,f(m())),l(Qr,f(m())),l(B,f(m())),Ke,Ze,m()),Bs=g(At),Jr=l(At,u("p2p-circuit"),m()),Os=g(Jr),Hr=C(l(At,u("p2p-circuit"),u("webrtc"),f(m())),l(At,u("webrtc"),f(m())),l(u("webrtc"),f(m()))),Rs=g(Hr),Xr=C(l(B,u("tcp"),ct(),u("http"),f(m())),l(B,u("http"),f(m()))),_s=g(Xr),Kr=C(l(B,u("tcp"),C(l(u("443"),u("http")),l(ct(),u("https"))),f(m())),l(B,u("tls"),u("http"),f(m())),l(B,u("https"),f(m()))),js=g(Kr),Zr=C(l(u("memory"),G(),f(m()))),Ye=g(Zr);var re={};k(re,{base32:()=>O,base32hex:()=>rn,base32hexpad:()=>on,base32hexpadupper:()=>sn,base32hexupper:()=>nn,base32pad:()=>tn,base32padupper:()=>en,base32upper:()=>Yr,base32z:()=>an});var O=b({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Yr=b({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),tn=b({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),en=b({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),rn=b({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),nn=b({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),on=b({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),sn=b({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),an=b({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ne={};k(ne,{base36:()=>pt,base36upper:()=>cn});var pt=j({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),cn=j({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var un=rr,tr=128,ln=127,pn=~ln,dn=Math.pow(2,31);function rr(r,t,e){t=t||[],e=e||0;for(var n=e;r>=dn;)t[e++]=r&255|tr,r/=128;for(;r&pn;)t[e++]=r&255|tr,r>>>=7;return t[e]=r|0,rr.bytes=e-n+1,t}var fn=oe,hn=128,er=127;function oe(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw oe.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&er)<<o:(i&er)*Math.pow(2,o),o+=7}while(i>=hn);return oe.bytes=s-n,e}var mn=Math.pow(2,7),xn=Math.pow(2,14),wn=Math.pow(2,21),gn=Math.pow(2,28),bn=Math.pow(2,35),yn=Math.pow(2,42),vn=Math.pow(2,49),En=Math.pow(2,56),In=Math.pow(2,63),An=function(r){return r<mn?1:r<xn?2:r<wn?3:r<gn?4:r<bn?5:r<yn?6:r<vn?7:r<En?8:r<In?9:10},Sn={encode:un,decode:fn,encodingLength:An},Pn=Sn,dt=Pn;function ft(r,t=0){return[dt.decode(r,t),dt.decode.bytes]}function Y(r,t,e=0){return dt.encode(r,t,e),t}function tt(r){return dt.encodingLength(r)}function Q(r,t){let e=t.byteLength,n=tt(r),o=n+tt(e),s=new Uint8Array(o+e);return Y(r,s,0),Y(e,s,n),s.set(t,o),new et(r,e,t,s)}function Dt(r){let t=V(r),[e,n]=ft(t),[o,s]=ft(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new et(e,o,i,t)}function nr(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Re(r.bytes,e.bytes)}}var et=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function or(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Tn(e,se(r),t??P.encoder);default:return Un(e,se(r),t??O.encoder)}}var sr=new WeakMap;function se(r){let t=sr.get(r);if(t==null){let e=new Map;return sr.set(r,e),e}return t}var q=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:e}=this;if(t!==ht)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Dn)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:e}=this.multihash,n=Q(t,e);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(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&nr(t.multihash,n.multihash)}toString(t){return or(this,t)}toJSON(){return{"/":or(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:s,bytes:i}=e;return new r(n,o,s,i??ir(n,o,s.bytes))}else if(e[Nn]===!0){let{version:n,multihash:o,code:s}=e,i=Dt(o);return r.create(n,s,i)}else return null}static create(t,e,n){if(typeof e!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(e!==ht)throw new Error(`Version 0 CID must use dag-pb (code: ${ht}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=ir(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,ht,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=V(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new et(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[I,N]=ft(t.subarray(e));return e+=N,I},o=n(),s=ht;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),c=n(),v=e+c,w=v-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:w,size:v}}static parse(t,e){let[n,o]=Cn(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return se(s).set(n,t),s}};function Cn(r,t){switch(r[0]){case"Q":{let e=t??P;return[P.prefix,e.decode(`${P.prefix}${r}`)]}case P.prefix:{let e=t??P;return[P.prefix,e.decode(r)]}case O.prefix:{let e=t??O;return[O.prefix,e.decode(r)]}case pt.prefix:{let e=t??pt;return[pt.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function Tn(r,t,e){let{prefix:n}=e;if(n!==P.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function Un(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var ht=112,Dn=18;function ir(r,t,e){let n=tt(r),o=n+tt(t),s=new Uint8Array(o+e.byteLength);return Y(r,s,0),Y(t,s,n),s.set(e,o),s}var Nn=Symbol.for("@ipld/js-cid/CID");function ar(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}var ie={};k(ie,{base10:()=>Mn});var Mn=j({prefix:"9",name:"base10",alphabet:"0123456789"});var ae={};k(ae,{base16:()=>kn,base16upper:()=>Fn});var kn=b({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Fn=b({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ce={};k(ce,{base2:()=>Ln});var Ln=b({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ue={};k(ue,{base256emoji:()=>On});var cr=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}"),zn=cr.reduce((r,t,e)=>(r[e]=t,r),[]),$n=cr.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Vn(r){return r.reduce((t,e)=>(t+=zn[e],t),"")}function Bn(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=$n[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var On=K({prefix:"\u{1F680}",name:"base256emoji",encode:Vn,decode:Bn});var le={};k(le,{base8:()=>Rn});var Rn=b({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var pe={};k(pe,{identity:()=>_n});var _n=K({prefix:"\0",name:"identity",encode:r=>je(r),decode:r=>_e(r)});var li=new TextEncoder,pi=new TextDecoder;var de={};k(de,{identity:()=>Qn});var ur=0,Wn="identity",lr=V;function Gn(r){return Q(ur,lr(r))}var Qn={code:ur,name:Wn,encode:lr,digest:Gn};var me={};k(me,{sha256:()=>Jn,sha512:()=>Hn});function he({name:r,code:t,encode:e}){return new fe(r,t,e)}var fe=class{name;code;encode;constructor(t,e,n){this.name=t,this.code=e,this.encode=n}digest(t){if(t instanceof Uint8Array){let e=this.encode(t);return e instanceof Uint8Array?Q(this.code,e):e.then(n=>Q(this.code,n))}else throw Error("Unknown type, must be binary type")}};function dr(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Jn=he({name:"sha2-256",code:18,encode:dr("SHA-256")}),Hn=he({name:"sha2-512",code:19,encode:dr("SHA-512")});var mt={...pe,...ce,...le,...ie,...ae,...re,...ne,...Jt,...Xt,...ue},Ai={...me,...de};function nt(r=0){return new Uint8Array(r)}function hr(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var fr=hr("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),xe=hr("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=nt(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Xn={utf8:fr,"utf-8":fr,hex:mt.base16,latin1:xe,ascii:xe,binary:xe,...mt},Nt=Xn;function D(r,t="utf8"){let e=Nt[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Kn=Math.pow(2,7),Zn=Math.pow(2,14),Yn=Math.pow(2,21),we=Math.pow(2,28),ge=Math.pow(2,35),be=Math.pow(2,42),ye=Math.pow(2,49),h=128,T=127;function z(r){if(r<Kn)return 1;if(r<Zn)return 2;if(r<Yn)return 3;if(r<we)return 4;if(r<ge)return 5;if(r<be)return 6;if(r<ye)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function to(r,t,e=0){switch(z(r)){case 8:t[e++]=r&255|h,r/=128;case 7:t[e++]=r&255|h,r/=128;case 6:t[e++]=r&255|h,r/=128;case 5:t[e++]=r&255|h,r/=128;case 4:t[e++]=r&255|h,r>>>=7;case 3:t[e++]=r&255|h,r>>>=7;case 2:t[e++]=r&255|h,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function eo(r,t,e=0){switch(z(r)){case 8:t.set(e++,r&255|h),r/=128;case 7:t.set(e++,r&255|h),r/=128;case 6:t.set(e++,r&255|h),r/=128;case 5:t.set(e++,r&255|h),r/=128;case 4:t.set(e++,r&255|h),r>>>=7;case 3:t.set(e++,r&255|h),r>>>=7;case 2:t.set(e++,r&255|h),r>>>=7;case 1:{t.set(e++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return t}function ro(r,t){let e=r[t],n=0;if(n+=e&T,e<h||(e=r[t+1],n+=(e&T)<<7,e<h)||(e=r[t+2],n+=(e&T)<<14,e<h)||(e=r[t+3],n+=(e&T)<<21,e<h)||(e=r[t+4],n+=(e&T)*we,e<h)||(e=r[t+5],n+=(e&T)*ge,e<h)||(e=r[t+6],n+=(e&T)*be,e<h)||(e=r[t+7],n+=(e&T)*ye,e<h))return n;throw new RangeError("Could not decode varint")}function no(r,t){let e=r.get(t),n=0;if(n+=e&T,e<h||(e=r.get(t+1),n+=(e&T)<<7,e<h)||(e=r.get(t+2),n+=(e&T)<<14,e<h)||(e=r.get(t+3),n+=(e&T)<<21,e<h)||(e=r.get(t+4),n+=(e&T)*we,e<h)||(e=r.get(t+5),n+=(e&T)*ge,e<h)||(e=r.get(t+6),n+=(e&T)*be,e<h)||(e=r.get(t+7),n+=(e&T)*ye,e<h))return n;throw new RangeError("Could not decode varint")}function ot(r,t,e=0){return t==null&&(t=nt(z(r))),t instanceof Uint8Array?to(r,t,e):eo(r,t,e)}function J(r,t=0){return r instanceof Uint8Array?ro(r,t):no(r,t)}function R(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=nt(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var qi=parseInt("0xFFFF",16),Wi=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);function Mt(r,t="utf8"){let e=Nt[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}var gr=vt,co=Et,ve=function(r){let t=0;if(r=r.toString().trim(),gr(r)){let e=new Uint8Array(t+4);return r.split(/\./g).forEach(n=>{e[t++]=parseInt(n,10)&255}),e}if(co(r)){let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=gr(e[n]),i;s&&(i=ve(e[n]),e[n]=D(i.slice(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,D(i.slice(2,4),"base16"))}if(e[0]==="")for(;e.length<8;)e.unshift("0");else if(e[e.length-1]==="")for(;e.length<8;)e.push("0");else if(e.length<8){for(n=0;n<e.length&&e[n]!=="";n++);let s=[n,1];for(n=9-e.length;n>0;n--)s.push("0");e.splice.apply(e,s)}let o=new Uint8Array(t+16);for(n=0;n<e.length;n++){let s=parseInt(e[n],16);o[t++]=s>>8&255,o[t++]=s&255}return o}throw new Error("invalid ip address")},br=function(r,t=0,e){t=~~t,e=e??r.length-t;let n=new DataView(r.buffer);if(e===4){let o=[];for(let s=0;s<e;s++)o.push(r[t+s]);return o.join(".")}if(e===16){let o=[];for(let s=0;s<e;s+=2)o.push(n.getUint16(t+s).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var st={},Ee={},lo=[[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"]];lo.forEach(r=>{let t=po(...r);Ee[t.code]=t,st[t.name]=t});function po(r,t,e,n,o){return{code:r,size:t,name:e,resolvable:!!n,path:!!o}}function x(r){if(typeof r=="number"){if(Ee[r]!=null)return Ee[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(st[r]!=null)return st[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var Ta=x("ip4"),Ua=x("ip6"),Da=x("ipcidr");function Pe(r,t){switch(x(r).code){case 4:case 41:return ho(t);case 42:return Se(t);case 43:return D(t,"base10");case 6:case 273:case 33:case 132:return Er(t).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Se(t);case 421:return go(t);case 444:return vr(t);case 445:return vr(t);case 466:return wo(t);case 481:return globalThis.encodeURIComponent(Se(t));default:return D(t,"base16")}}function Ce(r,t){switch(x(r).code){case 4:return yr(t);case 41:return yr(t);case 42:return Ae(t);case 43:return Mt(t,"base10");case 6:case 273:case 33:case 132:return Te(parseInt(t,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return Ae(t);case 421:return mo(t);case 444:return bo(t);case 445:return yo(t);case 466:return xo(t);case 481:return Ae(globalThis.decodeURIComponent(t));default:return Mt(t,"base16")}}var Ie=Object.values(mt).map(r=>r.decoder),fo=function(){let r=Ie[0].or(Ie[1]);return Ie.slice(2).forEach(t=>r=r.or(t)),r}();function yr(r){if(!It(r))throw new Error("invalid ip address");return ve(r)}function ho(r){let t=br(r,0,r.length);if(t==null)throw new Error("ipBuff is required");if(!It(t))throw new Error("invalid ip address");return t}function Te(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,r),new Uint8Array(t)}function Er(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function Ae(r){let t=Mt(r),e=Uint8Array.from(ot(t.length));return R([e,t],e.length+t.length)}function Se(r){let t=J(r);if(r=r.slice(z(t)),r.length!==t)throw new Error("inconsistent lengths");return D(r)}function mo(r){let t;r[0]==="Q"||r[0]==="1"?t=Dt(P.decode(`z${r}`)).bytes:t=q.parse(r).multihash.bytes;let e=Uint8Array.from(ot(t.length));return R([e,t],e.length+t.length)}function xo(r){let t=fo.decode(r),e=Uint8Array.from(ot(t.length));return R([e,t],e.length+t.length)}function wo(r){let t=J(r),e=r.slice(z(t));if(e.length!==t)throw new Error("inconsistent lengths");return"u"+D(e,"base64url")}function go(r){let t=J(r),e=r.slice(z(t));if(e.length!==t)throw new Error("inconsistent lengths");return D(e,"base58btc")}function bo(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let e=O.decode("b"+t[0]),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Te(n);return R([e,o],e.length+o.length)}function yo(r){let t=r.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let e=O.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=Te(n);return R([e,o],e.length+o.length)}function vr(r){let t=r.slice(0,r.length-2),e=r.slice(r.length-2),n=D(t,"base32"),o=Er(e);return`${n}:${o}`}function Ir(r){r=Ue(r);let t=[],e=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let s=0;s<o.length;s++){let i=o[s],a=x(i);if(a.size===0){t.push([a.code]),e.push([a.code]);continue}if(s++,s>=o.length)throw new kt("invalid address: "+r);if(a.path===!0){n=Ue(o.slice(s).join("/")),t.push([a.code,Ce(a.code,n)]),e.push([a.code,n]);break}let c=Ce(a.code,o[s]);t.push([a.code,c]),e.push([a.code,Pe(a.code,c)])}return{string:Ar(e),bytes:Ne(t),tuples:t,stringTuples:e,path:n}}function De(r){let t=[],e=[],n=null,o=0;for(;o<r.length;){let s=J(r,o),i=z(s),a=x(s),c=vo(a,r.slice(o+i));if(c===0){t.push([s]),e.push([s]),o+=i;continue}let v=r.slice(o+i,o+i+c);if(o+=c+i,o>r.length)throw new kt("Invalid address Uint8Array: "+D(r,"base16"));t.push([s,v]);let w=Pe(s,v);if(e.push([s,w]),a.path===!0){n=w;break}}return{bytes:Uint8Array.from(r),string:Ar(e),tuples:t,stringTuples:e,path:n}}function Ar(r){let t=[];return r.map(e=>{let n=x(e[0]);return t.push(n.name),e.length>1&&e[1]!=null&&t.push(e[1]),null}),Ue(t.join("/"))}function Ne(r){return R(r.map(t=>{let e=x(t[0]),n=Uint8Array.from(ot(e.code));return t.length>1&&t[1]!=null&&(n=R([n,t[1]])),n}))}function vo(r,t){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let e=J(t instanceof Uint8Array?t:Uint8Array.from(t));return e+z(e)}}function Ue(r){return"/"+r.trim().split("/").filter(t=>t).join("/")}var kt=class extends Error{static name="ParseError";name="ParseError";constructor(t){super(`Error parsing address: ${t}`)}};var Eo=Symbol.for("nodejs.util.inspect.custom"),ke=Symbol.for("@multiformats/js-multiaddr/multiaddr"),Io=[x("dns").code,x("dns4").code,x("dns6").code,x("dnsaddr").code],Me=class extends Error{constructor(t="No available resolver"){super(t),this.name="NoAvailableResolverError"}},Ft=class r{bytes;#t;#e;#r;#n;[ke]=!0;constructor(t){t==null&&(t="");let e;if(t instanceof Uint8Array)e=De(t);else if(typeof t=="string"){if(t.length>0&&t.charAt(0)!=="/")throw new Error(`multiaddr "${t}" must start with a "/"`);e=Ir(t)}else if(Pr(t))e=De(t.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=e.bytes,this.#t=e.string,this.#e=e.tuples,this.#r=e.stringTuples,this.#n=e.path}toString(){return this.#t}toJSON(){return this.toString()}toOptions(){let t,e,n,o,s="",i=x("tcp"),a=x("udp"),c=x("ip4"),v=x("ip6"),w=x("dns6"),I=x("ip6zone");for(let[S,d]of this.stringTuples())S===I.code&&(s=`%${d??""}`),Io.includes(S)&&(e=i.name==="tcp"?"tcp":"udp",o=443,n=`${d??""}${s}`,t=S===w.code?6:4),(S===i.code||S===a.code)&&(e=x(S).name==="tcp"?"tcp":"udp",o=parseInt(d??"")),(S===c.code||S===v.code)&&(e=x(S).name==="tcp"?"tcp":"udp",n=`${d??""}${s}`,t=S===v.code?6:4);if(t==null||e==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:t,host:n,transport:e,port:o}}protos(){return this.#e.map(([t])=>Object.assign({},x(t)))}protoCodes(){return this.#e.map(([t])=>t)}protoNames(){return this.#e.map(([t])=>x(t).name)}tuples(){return this.#e.map(([t,e])=>e==null?[t]:[t,e])}stringTuples(){return this.#r.map(([t,e])=>e==null?[t]:[t,e])}encapsulate(t){return t=new r(t),new r(this.toString()+t.toString())}decapsulate(t){let e=t.toString(),n=this.toString(),o=n.lastIndexOf(e);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${t.toString()}`);return new r(n.slice(0,o))}decapsulateCode(t){let e=this.tuples();for(let n=e.length-1;n>=0;n--)if(e[n][0]===t)return new r(Ne(e.slice(0,n)));return this}getPeerId(){try{let t=[];this.stringTuples().forEach(([n,o])=>{n===st.p2p.code&&t.push([n,o]),n===st["p2p-circuit"].code&&(t=[])});let e=t.pop();if(e?.[1]!=null){let n=e[1];return n[0]==="Q"||n[0]==="1"?D(P.decode(`z${n}`),"base58btc"):D(q.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(t){return ar(this.bytes,t.bytes)}async resolve(t){let e=this.protos().find(s=>s.resolvable);if(e==null)return[this];let n=Sr.get(e.name);if(n==null)throw new Me(`no available resolver for ${e.name}`);return(await n(this,t)).map(s=>W(s))}nodeAddress(){let t=this.toOptions();if(t.transport!=="tcp"&&t.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${t.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:t.family,address:t.host,port:t.port}}isThinWaistAddress(t){let e=(t??this).protos();return!(e.length!==2||e[0].code!==4&&e[0].code!==41||e[1].code!==6&&e[1].code!==273)}[Eo](){return`Multiaddr(${this.#t})`}};var Sr=new Map;function Pr(r){return!!r?.[ke]}function W(r){return new Ft(r)}var Cr=()=>{let r=new Error("Delay aborted");return r.name="AbortError",r},Ao=new WeakMap;function So({clearTimeout:r,setTimeout:t}={}){return(e,{value:n,signal:o}={})=>{if(o?.aborted)return Promise.reject(Cr());let s,i,a,c=r??clearTimeout,v=()=>{c(s),a(Cr())},w=()=>{o&&o.removeEventListener("abort",v)},I=new Promise((N,S)=>{i=()=>{w(),N(n)},a=S,s=(t??setTimeout)(i,e)});return o&&o.addEventListener("abort",v,{once:!0}),Ao.set(I,()=>{c(s),s=null,i()}),I}}var Po=So(),Lt=Po;function Co(r){let[t,e]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>t.next(),push:o=>{n.push(o)},next:()=>n.length>0?{done:!1,value:n.shift()}:t.next(),[e](){return this}}}var Tr=Co;function To(r){return r[Symbol.asyncIterator]!=null}function Uo(r,t){let e=0;if(To(r))return async function*(){for await(let c of r)yield t(c,e++)}();let n=Tr(r),{value:o,done:s}=n.next();if(s===!0)return function*(){}();let i=t(o,e++);if(typeof i.then=="function")return async function*(){yield await i;for await(let c of n)yield t(c,e++)}();let a=t;return function*(){yield i;for(let c of n)yield a(c,e++)}()}var Fe=Uo;function zt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}var $t=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||t-1&t)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},it=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new $t(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let e=this.head;this.head=e.next=new $t(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var Le=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function ze(r={}){return Do(e=>{let n=e.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function Do(r,t){t=t??{};let e=t.onEnd,n=new it,o,s,i,a=zt(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((p,E)=>{s=U=>{s=null,n.push(U);try{p(r(n))}catch(A){E(A)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=zt()})}},v=p=>s!=null?s(p):(n.push(p),o),w=p=>(n=new it,s!=null?s({error:p}):(n.push({error:p}),o)),I=p=>{if(i)return o;if(t?.objectMode!==!0&&p?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return v({done:!1,value:p})},N=p=>i?o:(i=!0,p!=null?w(p):v({done:!0})),S=()=>(n=new it,N(),{done:!0}),d=p=>(N(p),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:S,throw:d,push:I,end:N,get readableLength(){return n.size},onEmpty:async p=>{let E=p?.signal;if(E?.throwIfAborted(),n.isEmpty())return;let U,A;E!=null&&(U=new Promise((M,F)=>{A=()=>{F(new Le)},E.addEventListener("abort",A)}));try{await Promise.race([a.promise,U])}finally{A!=null&&E!=null&&E?.removeEventListener("abort",A)}}},e==null)return o;let y=o;return o={[Symbol.asyncIterator](){return this},next(){return y.next()},throw(p){return y.throw(p),e!=null&&(e(p),e=void 0),{done:!0}},return(){return y.return(),e!=null&&(e(),e=void 0),{done:!0}},push:I,end(p){return y.end(p),e!=null&&(e(p),e=void 0),o},get readableLength(){return y.readableLength},onEmpty:p=>y.onEmpty(p)},o}var at=new Map,Vt=class{components;init;connections;latency;constructor(t,e){this.components=t,this.init=e,this.connections=new Set,this.latency=e.latency??0}async dial(t){let e=ze(),n=ze(),o=this,s={source:async function*(){yield*Fe(n,async a=>(o.latency>0&&await Lt(o.latency),a))}(),sink:async a=>{for await(let c of a)e.push(c)},close:async()=>{e.end(),this.connections.delete(s),s.timeline.close=Date.now(),n.end(),this.connections.delete(i),i.timeline.close=Date.now()},abort:a=>{e.end(a),this.connections.delete(s),s.timeline.close=Date.now(),n.end(a),this.connections.delete(i),i.timeline.close=Date.now()},timeline:{open:Date.now()},remoteAddr:W(`${this.init.address}/p2p/${this.components.peerId}`),log:this.components.logger.forComponent("libp2p:memory:outgoing:1")},i={source:async function*(){yield*Fe(e,async a=>(o.latency>0&&await Lt(o.latency),a))}(),sink:async a=>{for await(let c of a)n.push(c)},close:async()=>{n.end(),this.connections.delete(i),i.timeline.close=Date.now(),e.end(),this.connections.delete(s),s.timeline.close=Date.now()},abort:a=>{n.end(a),this.connections.delete(i),i.timeline.close=Date.now(),e.end(a),this.connections.delete(s),s.timeline.close=Date.now()},timeline:{open:Date.now()},remoteAddr:W(`${this.init.address}-outgoing/p2p/${t}`),log:this.components.logger.forComponent("libp2p:memory:outgoing:1")};return this.connections.add(s),this.connections.add(i),await Lt(this.latency),this.init.onConnection(i),s}close(){[...this.connections].forEach(t=>{t.abort(new H("Memory Connection closed"))})}};var Ur="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";var Dr=(r=21)=>{let t="",e=crypto.getRandomValues(new Uint8Array(r|=0));for(;r--;)t+=Ur[e[r]&63];return t};var Bt=class extends gt{listenAddr;connection;components;init;constructor(t,e){super(),this.components=t,this.init=e}async listen(t){let[[,e]]=t.stringTuples(),n=`/memory/${e??Dr()}`;if(e!=null&&at.has(n))throw new wt(`Memory address ${n} already in use`);this.connection=new Vt(this.components,{...this.init,onConnection:this.onConnection.bind(this),address:n}),this.listenAddr=W(n),at.set(n,this.connection),queueMicrotask(()=>{this.safeDispatchEvent("listening")})}onConnection(t){let e;this.init.inboundUpgradeTimeout!=null&&(e=AbortSignal.timeout(this.init.inboundUpgradeTimeout)),this.init.upgrader.upgradeInbound(t,{...this.init.upgraderOptions,signal:e}).catch(n=>{t.abort(n)})}getAddrs(){return this.listenAddr==null?[]:[this.listenAddr]}async close(){this.connection?.close(),this.listenAddr!=null&&at.delete(this.listenAddr.toString()),queueMicrotask(()=>{this.safeDispatchEvent("close")})}};var Ot=class{components;init;constructor(t,e={}){this.components=t,this.init=e}[Ve]=!0;[Symbol.toStringTag]="@libp2p/memory";[Be]=["@libp2p/transport"];async dial(t,e){e.signal?.throwIfAborted();let n=at.get(`${t.getPeerId()==null?t:t.decapsulate("/p2p")}`);if(n==null)throw new H(`No memory listener found at ${t}`);let o=await n.dial(this.components.peerId);try{return e.signal?.throwIfAborted(),await e.upgrader.upgradeOutbound(o,{...e,...this.init.upgraderOptions})}catch(s){throw o.abort(s),s}}createListener(t){return new Bt(this.components,{...t,...this.init})}listenFilter(t){return t.filter(e=>Ye.exactMatch(e))}dialFilter(t){return this.listenFilter(t)}};function No(r){return t=>new Ot(t,r)}return Lr(Mo);})();
|
|
3
3
|
return Libp2PMemory}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/memory",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5-d8f003e6e",
|
|
4
4
|
"description": "A memory transport for libp2p",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/transport-memory#readme",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"test:electron-main": "aegir test -t electron-main"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@libp2p/interface": "2.
|
|
54
|
+
"@libp2p/interface": "2.5.0-d8f003e6e",
|
|
55
55
|
"@multiformats/multiaddr": "^12.3.3",
|
|
56
56
|
"@multiformats/multiaddr-matcher": "^1.6.0",
|
|
57
57
|
"@types/sinon": "^17.0.3",
|
|
@@ -62,8 +62,8 @@
|
|
|
62
62
|
"uint8arraylist": "^2.4.8"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@libp2p/logger": "5.1.
|
|
66
|
-
"@libp2p/peer-id": "5.0.
|
|
65
|
+
"@libp2p/logger": "5.1.8-d8f003e6e",
|
|
66
|
+
"@libp2p/peer-id": "5.0.12-d8f003e6e",
|
|
67
67
|
"aegir": "^45.0.5",
|
|
68
68
|
"sinon": "^19.0.2",
|
|
69
69
|
"sinon-ts": "^2.0.0"
|