@helia/delegated-routing-client 0.0.0-1361bfa5
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/README.md +72 -0
- package/dist/index.min.js +4 -0
- package/dist/index.min.js.map +7 -0
- package/dist/src/delegated-routing-router.d.ts +18 -0
- package/dist/src/delegated-routing-router.d.ts.map +1 -0
- package/dist/src/delegated-routing-router.js +78 -0
- package/dist/src/delegated-routing-router.js.map +1 -0
- package/dist/src/index.d.ts +10 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +10 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/utils/delegated-http-routing-defaults.browser.d.ts +3 -0
- package/dist/src/utils/delegated-http-routing-defaults.browser.d.ts.map +1 -0
- package/dist/src/utils/delegated-http-routing-defaults.browser.js +8 -0
- package/dist/src/utils/delegated-http-routing-defaults.browser.js.map +1 -0
- package/dist/src/utils/delegated-http-routing-defaults.d.ts +3 -0
- package/dist/src/utils/delegated-http-routing-defaults.d.ts.map +1 -0
- package/dist/src/utils/delegated-http-routing-defaults.js +9 -0
- package/dist/src/utils/delegated-http-routing-defaults.js.map +1 -0
- package/package.json +70 -0
- package/src/delegated-routing-router.ts +98 -0
- package/src/index.ts +14 -0
- package/src/utils/delegated-http-routing-defaults.browser.ts +9 -0
- package/src/utils/delegated-http-routing-defaults.ts +10 -0
package/README.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://github.com/ipfs/helia" title="Helia">
|
|
3
|
+
<img src="https://raw.githubusercontent.com/ipfs/helia/main/assets/helia.png" alt="Helia logo" width="300" />
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
# @helia/delegated-routing-client
|
|
8
|
+
|
|
9
|
+
[](https://ipfs.tech)
|
|
10
|
+
[](https://discuss.ipfs.tech)
|
|
11
|
+
[](https://codecov.io/gh/ipfs/helia)
|
|
12
|
+
[](https://github.com/ipfs/helia/actions/workflows/main.yml?query=branch%3Amain)
|
|
13
|
+
|
|
14
|
+
> Use HTTP Delegated Routers with Helia
|
|
15
|
+
|
|
16
|
+
# About
|
|
17
|
+
|
|
18
|
+
<!--
|
|
19
|
+
|
|
20
|
+
!IMPORTANT!
|
|
21
|
+
|
|
22
|
+
Everything in this README between "# About" and "# Install" is automatically
|
|
23
|
+
generated and will be overwritten the next time the doc generator is run.
|
|
24
|
+
|
|
25
|
+
To make changes to this section, please update the @packageDocumentation section
|
|
26
|
+
of src/index.js or src/index.ts
|
|
27
|
+
|
|
28
|
+
To experiment with formatting, please run "npm run docs" from the root of this
|
|
29
|
+
repo and examine the changes made.
|
|
30
|
+
|
|
31
|
+
-->
|
|
32
|
+
|
|
33
|
+
Abstraction layer over different content and peer routing mechanisms.
|
|
34
|
+
|
|
35
|
+
# Install
|
|
36
|
+
|
|
37
|
+
```console
|
|
38
|
+
$ npm i @helia/delegated-routing-client
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Browser `<script>` tag
|
|
42
|
+
|
|
43
|
+
Loading this module through a script tag will make its exports available as `HeliaDelegatedRoutingClient` in the global namespace.
|
|
44
|
+
|
|
45
|
+
```html
|
|
46
|
+
<script src="https://unpkg.com/@helia/delegated-routing-client/dist/index.min.js"></script>
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
> Routers for Helia
|
|
50
|
+
|
|
51
|
+
# API Docs
|
|
52
|
+
|
|
53
|
+
- <https://ipfs.github.io/helia/modules/_helia_delegated-routing-client.html>
|
|
54
|
+
|
|
55
|
+
# License
|
|
56
|
+
|
|
57
|
+
Licensed under either of
|
|
58
|
+
|
|
59
|
+
- Apache 2.0, ([LICENSE-APACHE](https://github.com/ipfs/helia/blob/main/packages/delegated-routing-client/LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
|
|
60
|
+
- MIT ([LICENSE-MIT](https://github.com/ipfs/helia/blob/main/packages/delegated-routing-client/LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
|
|
61
|
+
|
|
62
|
+
# Contribute
|
|
63
|
+
|
|
64
|
+
Contributions welcome! Please check out [the issues](https://github.com/ipfs/helia/issues).
|
|
65
|
+
|
|
66
|
+
Also see our [contributing document](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md) for more information on how we work, and about contributing in general.
|
|
67
|
+
|
|
68
|
+
Please be aware that all interactions related to this repo are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).
|
|
69
|
+
|
|
70
|
+
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
|
|
71
|
+
|
|
72
|
+
[](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.HeliaDelegatedRoutingClient = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
+
"use strict";var HeliaDelegatedRoutingClient=(()=>{var Me=Object.defineProperty;var Cr=Object.getOwnPropertyDescriptor;var Ir=Object.getOwnPropertyNames;var Tr=Object.prototype.hasOwnProperty;var A=(r,e)=>{for(var t in e)Me(r,t,{get:e[t],enumerable:!0})},Ar=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Ir(e))!Tr.call(r,o)&&o!==t&&Me(r,o,{get:()=>e[o],enumerable:!(n=Cr(e,o))||n.enumerable});return r};var Pr=r=>Ar(Me({},"__esModule",{value:!0}),r);var ss={};A(ss,{delegatedHTTPRouter:()=>os,delegatedHTTPRoutingDefaults:()=>Pt});var B=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var we=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var _=class extends Error{static name="NotFoundError";constructor(e="Not found"){super(e),this.name="NotFoundError"}};function Sr(r){return typeof r?.handleEvent=="function"}function Dr(r){return(r!==!0&&r!==!1&&r?.once)??!1}var xe=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){let o=Dr(n);super.addEventListener(e,i=>{if(o){let c=this.#e.get(i.type);c!=null&&(c=c.filter(({callback:a})=>a!==t),this.#e.set(i.type,c))}Sr(t)?t.handleEvent(i):t(i)},n);let s=this.#e.get(e);s==null&&(s=[],this.#e.set(e,s)),s.push({callback:t,once:o})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:s})=>s!==t),this.#e.set(e,o))}safeDispatchEvent(e,t={}){return this.dispatchEvent(new CustomEvent(e,t))}};function O(r=0){return new Uint8Array(r)}function U(r=0){return new Uint8Array(r)}function Lr(r){return r?.buffer instanceof ArrayBuffer}function qe(r){if(Lr(r))return r;let e=r.slice();return new Uint8Array(e.buffer,0,e.byteLength)}function V(r,e){e==null&&(e=r.reduce((o,s)=>o+s.length,0));let t=U(e),n=0;for(let o of r)t.set(o,n),n+=o.length;return qe(t)}function G(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 Lt=Symbol.for("@achingbrain/uint8arraylist");function St(r,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let t=0;for(let n of r){let o=t+n.byteLength;if(e<o)return{buf:n,index:e-t};t=o}throw new RangeError("index is out of bounds")}function Y(r){return!!r?.[Lt]}var Dt=class r{bufs;length;[Lt]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let t=0;for(let n of e)if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.push(n);else if(Y(n)){t+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}prepend(...e){this.prependAll(e)}prependAll(e){let t=0;for(let n of e.reverse())if(n instanceof Uint8Array)t+=n.byteLength,this.bufs.unshift(n);else if(Y(n))t+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=t}get(e){let t=St(this.bufs,e);return t.buf[t.index]}set(e,t){let n=St(this.bufs,e);n.buf[n.index]=t}write(e,t=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(t+n,e[n]);else if(Y(e))for(let n=0;n<e.length;n++)this.set(t+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,t){let{bufs:n,length:o}=this._subList(e,t);return V(n,o)}subarray(e,t){let{bufs:n,length:o}=this._subList(e,t);return n.length===1?n[0]:V(n,o)}sublist(e,t){let{bufs:n,length:o}=this._subList(e,t),s=new r;return s.length=o,s.bufs=n,s}_subList(e,t){if(e=e??0,t=t??this.length,e<0&&(e=this.length+e),t<0&&(t=this.length+t),e<0||t>this.length)throw new RangeError("index is out of bounds");if(e===t)return{bufs:[],length:0};if(e===0&&t===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],c=o,a=c+i.byteLength;if(o=a,e>=a)continue;let u=e>=c&&e<a,l=t>c&&t<=a;if(u&&l){if(e===c&&t===a){n.push(i);break}let h=e-c;n.push(i.subarray(h,h+(t-e)));break}if(u){if(e===0){n.push(i);continue}n.push(i.subarray(e-c));continue}if(l){if(t===a){n.push(i);break}n.push(i.subarray(0,t-c));break}n.push(i)}return{bufs:n,length:t-e}}indexOf(e,t=0){if(!Y(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(t=Number(t??0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),e.length===0)return t>this.length?this.length:t;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let h=0;h<s;h++)i[h]=-1;for(let h=0;h<o;h++)i[n[h]]=h;let c=i,a=this.byteLength-n.byteLength,u=n.byteLength-1,l;for(let h=t;h<=a;h+=l){l=0;for(let f=u;f>=0;f--){let m=this.get(h+f);if(n[f]!==m){l=Math.max(1,f-c[m]);break}}if(l===0)return h}return-1}getInt8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getInt8(0)}setInt8(e,t){let n=U(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,t),this.write(n,e)}getInt16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,t)}setInt16(e,t,n){let o=O(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,t,n),this.write(o,e)}getInt32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,t)}setInt32(e,t,n){let o=O(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,t,n),this.write(o,e)}getBigInt64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,t)}setBigInt64(e,t,n){let o=O(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,t,n),this.write(o,e)}getUint8(e){let t=this.subarray(e,e+1);return new DataView(t.buffer,t.byteOffset,t.byteLength).getUint8(0)}setUint8(e,t){let n=U(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,t),this.write(n,e)}getUint16(e,t){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,t)}setUint16(e,t,n){let o=O(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,t,n),this.write(o,e)}getUint32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,t)}setUint32(e,t,n){let o=O(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,t,n),this.write(o,e)}getBigUint64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,t)}setBigUint64(e,t,n){let o=O(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,t,n),this.write(o,e)}getFloat32(e,t){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,t)}setFloat32(e,t,n){let o=O(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,t,n),this.write(o,e)}getFloat64(e,t){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,t)}setFloat64(e,t,n){let o=O(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,t,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof r)||e.bufs.length!==this.bufs.length)return!1;for(let t=0;t<this.bufs.length;t++)if(!G(this.bufs[t],e.bufs[t]))return!1;return!0}static fromUint8Arrays(e,t){let n=new r;return n.bufs=e,t==null&&(t=e.reduce((o,s)=>o+s.byteLength,0)),n.length=t,n}};var Ge={};A(Ge,{base10:()=>zr});var ws=new Uint8Array(0);function Nt(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 z(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return W(r);if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return W(new Uint8Array(r.buffer,r.byteOffset,r.byteLength));throw new Error("Unknown type, must be binary type")}function Ot(r){return new TextEncoder().encode(r)}function Ut(r){return new TextDecoder().decode(r)}function Nr(r){return r?.buffer instanceof ArrayBuffer}function W(r){return Nr(r)?r:r.slice()}function Or(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 s=r.charAt(o),i=s.charCodeAt(0);if(t[i]!==255)throw new TypeError(s+" is ambiguous");t[i]=o}var c=r.length,a=r.charAt(0),u=Math.log(c)/Math.log(256),l=Math.log(256)/Math.log(c);function h(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 g=0,p=0,w=0,I=d.length;w!==I&&d[w]===0;)w++,g++;for(var E=(I-w)*l+1>>>0,T=new Uint8Array(E);w!==I;){for(var S=d[w],q=0,N=E-1;(S!==0||q<p)&&N!==-1;N--,q++)S+=256*T[N]>>>0,T[N]=S%c>>>0,S=S/c>>>0;if(S!==0)throw new Error("Non-zero carry");p=q,w++}for(var R=E-p;R!==E&&T[R]===0;)R++;for(var ye=a.repeat(g);R<E;++R)ye+=r.charAt(T[R]);return ye}function f(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var g=0;if(d[g]!==" "){for(var p=0,w=0;d[g]===a;)p++,g++;for(var I=(d.length-g)*u+1>>>0,E=new Uint8Array(I);d[g];){var T=t[d.charCodeAt(g)];if(T===255)return;for(var S=0,q=I-1;(T!==0||S<w)&&q!==-1;q--,S++)T+=c*E[q]>>>0,E[q]=T%256>>>0,T=T/256>>>0;if(T!==0)throw new Error("Non-zero carry");w=S,g++}if(d[g]!==" "){for(var N=I-w;N!==I&&E[N]===0;)N++;for(var R=new Uint8Array(p+(I-N)),ye=p;N!==I;)R[ye++]=E[N++];return R}}}function m(d){var g=f(d);if(g)return g;throw new Error(`Non-${e} character`)}return{encode:h,decodeUnsafe:f,decode:m}}var Ur=Or,Rr=Ur,Bt=Rr;var $e=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")}},je=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let o=t.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return _t(this,e)}},ke=class{decoders;constructor(e){this.decoders=e}or(e){return _t(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 _t(r,e){return new ke({...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 $e(e,t,n),this.decoder=new je(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Z({name:r,prefix:e,encode:t,decode:n}){return new He(r,e,t,n)}function $({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=Bt(t,r);return Z({prefix:e,name:r,encode:n,decode:s=>z(o(s))})}function Br(r,e,t,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*t/8|0),i=0,c=0,a=0;for(let u=0;u<o;++u){let l=e[r[u]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<t|l,i+=t,i>=8&&(i-=8,s[a++]=255&c>>i)}if(i>=t||(255&c<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function _r(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,c=0;for(let a=0;a<r.length;++a)for(c=c<<8|r[a],i+=8;i>t;)i-=t,s+=e[o&c>>i];if(i!==0&&(s+=e[o&c<<t-i]),n)for(;(s.length*t&7)!==0;)s+="=";return s}function Vr(r){let e={};for(let t=0;t<r.length;++t)e[r[t]]=t;return e}function y({name:r,prefix:e,bitsPerChar:t,alphabet:n}){let o=Vr(n);return Z({prefix:e,name:r,encode(s){return _r(s,n,t)},decode(s){return Br(s,o,t,r)}})}var zr=$({prefix:"9",name:"base10",alphabet:"0123456789"});var We={};A(We,{base16:()=>Fr,base16upper:()=>Mr});var Fr=y({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Mr=y({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Qe={};A(Qe,{base2:()=>qr});var qr=y({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Je={};A(Je,{base256emoji:()=>Gr});var Vt=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}"),$r=Vt.reduce((r,e,t)=>(r[t]=e,r),[]),jr=Vt.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function kr(r){return r.reduce((e,t)=>(e+=$r[t],e),"")}function Hr(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=jr[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var Gr=Z({prefix:"\u{1F680}",name:"base256emoji",encode:kr,decode:Hr});var Xe={};A(Xe,{base32:()=>j,base32hex:()=>Xr,base32hexpad:()=>Yr,base32hexpadupper:()=>Zr,base32hexupper:()=>Kr,base32pad:()=>Qr,base32padupper:()=>Jr,base32upper:()=>Wr,base32z:()=>en});var j=y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Wr=y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Qr=y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Jr=y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Xr=y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Kr=y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Yr=y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Zr=y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),en=y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ke={};A(Ke,{base36:()=>le,base36upper:()=>tn});var le=$({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),tn=$({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ye={};A(Ye,{base58btc:()=>D,base58flickr:()=>rn});var D=$({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),rn=$({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var et={};A(et,{base64:()=>nn,base64pad:()=>on,base64url:()=>Ze,base64urlpad:()=>sn});var nn=y({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),on=y({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Ze=y({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),sn=y({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var tt={};A(tt,{base8:()=>an});var an=y({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var rt={};A(rt,{identity:()=>cn});var cn=Z({prefix:"\0",name:"identity",encode:r=>Ut(r),decode:r=>Ot(r)});var Bs=new TextEncoder,_s=new TextDecoder;var ot={};A(ot,{identity:()=>Nn});var hn=Mt,zt=128,fn=127,dn=~fn,pn=Math.pow(2,31);function Mt(r,e,t){e=e||[],t=t||0;for(var n=t;r>=pn;)e[t++]=r&255|zt,r/=128;for(;r&dn;)e[t++]=r&255|zt,r>>>=7;return e[t]=r|0,Mt.bytes=t-n+1,e}var mn=nt,gn=128,Ft=127;function nt(r,n){var t=0,n=n||0,o=0,s=n,i,c=r.length;do{if(s>=c)throw nt.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&Ft)<<o:(i&Ft)*Math.pow(2,o),o+=7}while(i>=gn);return nt.bytes=s-n,t}var bn=Math.pow(2,7),yn=Math.pow(2,14),wn=Math.pow(2,21),xn=Math.pow(2,28),En=Math.pow(2,35),vn=Math.pow(2,42),Cn=Math.pow(2,49),In=Math.pow(2,56),Tn=Math.pow(2,63),An=function(r){return r<bn?1:r<yn?2:r<wn?3:r<xn?4:r<En?5:r<vn?6:r<Cn?7:r<In?8:r<Tn?9:10},Pn={encode:hn,decode:mn,encodingLength:An},Sn=Pn,he=Sn;function fe(r,e=0){return[he.decode(r,e),he.decode.bytes]}function ee(r,e,t=0){return he.encode(r,e,t),e}function te(r){return he.encodingLength(r)}function ne(r,e){let t=e.byteLength,n=te(r),o=n+te(t),s=new Uint8Array(o+t);return ee(r,s,0),ee(t,s,n),s.set(e,o),new re(r,t,e,s)}function Q(r){let e=z(r),[t,n]=fe(e),[o,s]=fe(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new re(t,o,i,e)}function qt(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Nt(r.bytes,t.bytes)}}var re=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=W(n),this.bytes=W(o)}};var $t=0,Dn="identity",jt=z;function Ln(r,e){if(e?.truncate!=null&&e.truncate!==r.byteLength){if(e.truncate<0||e.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e.truncate)}return ne($t,jt(r))}var Nn={code:$t,name:Dn,encode:jt,digest:Ln};var at={};A(at,{sha256:()=>Un,sha512:()=>Rn});var On=20;function it({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:o}){return new st(r,e,t,n,o)}var st=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,o,s){this.name=e,this.code=t,this.encode=n,this.minDigestLength=o??On,this.maxDigestLength=s}digest(e,t){if(t?.truncate!=null){if(t.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&t.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?kt(n,this.code,t?.truncate):n.then(o=>kt(o,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function kt(r,e,t){if(t!=null&&t!==r.byteLength){if(t>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t)}return ne(e,r)}function Gt(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var Un=it({name:"sha2-256",code:18,encode:Gt("SHA-256")}),Rn=it({name:"sha2-512",code:19,encode:Gt("SHA-512")});function Wt(r,e){let{bytes:t,version:n}=r;return n===0?_n(t,ct(r),e??D.encoder):Vn(t,ct(r),e??j.encoder)}var Qt=new WeakMap;function ct(r){let e=Qt.get(r);if(e==null){let t=new Map;return Qt.set(r,t),t}return e}var P=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=W(o),this["/"]=this.bytes}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!==de)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==zn)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=ne(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&&qt(e.multihash,n.multihash)}toString(e){return Wt(this,e)}toJSON(){return{"/":Wt(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:s,bytes:i}=t;return new r(n,o,s,i??Jt(n,o,s.bytes))}else if(t[Fn]===!0){let{version:n,multihash:o,code:s}=t,i=Q(o);return r.create(n,s,i)}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!==de)throw new Error(`Version 0 CID must use dag-pb (code: ${de}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=Jt(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,de,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=z(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let s=o.subarray(t.multihashSize-t.digestSize),i=new re(t.multihashCode,t.digestSize,s,o);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[h,f]=fe(e.subarray(t));return t+=f,h},o=n(),s=de;if(o===18?(o=0,t=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=t,c=n(),a=n(),u=t+a,l=u-i;return{version:o,codec:s,multihashCode:c,digestSize:a,multihashSize:l,size:u}}static parse(e,t){let[n,o]=Bn(e,t),s=r.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return ct(s).set(n,e),s}};function Bn(r,e){switch(r[0]){case"Q":{let t=e??D;return[D.prefix,t.decode(`${D.prefix}${r}`)]}case D.prefix:{let t=e??D;return[D.prefix,t.decode(r)]}case j.prefix:{let t=e??j;return[j.prefix,t.decode(r)]}case le.prefix:{let t=e??le;return[le.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function _n(r,e,t){let{prefix:n}=t;if(n!==D.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let s=t.encode(r).slice(1);return e.set(n,s),s}else return o}function Vn(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let s=t.encode(r);return e.set(n,s),s}else return o}var de=112,zn=18;function Jt(r,e,t){let n=te(r),o=n+te(e),s=new Uint8Array(o+t.byteLength);return ee(r,s,0),ee(e,s,n),s.set(t,o),s}var Fn=Symbol.for("@ipld/js-cid/CID");var pe={...rt,...Qe,...tt,...Ge,...We,...Xe,...Ke,...Ye,...et,...Je},oi={...at,...ot};function Kt(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var Xt=Kt("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),ut=Kt("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=U(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Mn={utf8:Xt,"utf-8":Xt,hex:pe.base16,latin1:ut,ascii:ut,binary:ut,...pe},ve=Mn;function k(r,e="utf8"){let t=ve[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}var Ce=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 s=0,i=0,c=this.peekChar();if(c===void 0)return;let a=c==="0",u=2**(8*o)-1;for(;;){let l=this.readAtomically(()=>{let h=this.readChar();if(h===void 0)return;let f=Number.parseInt(h,e);if(!Number.isNaN(f))return f});if(l===void 0)break;if(s*=e,s+=l,s>u||(i+=1,t!==void 0&&i>t))return}if(i!==0)return!n&&a&&i>1?void 0:s})}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 i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return t[o]=i[0],t[o+1]=i[1],t[o+2]=i[2],t[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];t[o]=s>>8,t[o+1]=s&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 s=new Uint8Array(14),i=16-(n+2),[c]=e(s.subarray(0,i));return t.set(s.subarray(0,c),16-c),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var qn=45,$n=15,Ie=new Ce;function Yt(r){if(!(r.length>$n))return Ie.new(r).parseWith(()=>Ie.readIPv4Addr())}function Zt(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>qn))return Ie.new(r).parseWith(()=>Ie.readIPv6Addr())}function Te(r){return!!Yt(r)}function er(r){return!!Zt(r)}var jn=Math.pow(2,7),kn=Math.pow(2,14),Hn=Math.pow(2,21),lt=Math.pow(2,28),ht=Math.pow(2,35),ft=Math.pow(2,42),dt=Math.pow(2,49),b=128,C=127;function oe(r){if(r<jn)return 1;if(r<kn)return 2;if(r<Hn)return 3;if(r<lt)return 4;if(r<ht)return 5;if(r<ft)return 6;if(r<dt)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function pt(r,e,t=0){switch(oe(r)){case 8:e[t++]=r&255|b,r/=128;case 7:e[t++]=r&255|b,r/=128;case 6:e[t++]=r&255|b,r/=128;case 5:e[t++]=r&255|b,r/=128;case 4:e[t++]=r&255|b,r>>>=7;case 3:e[t++]=r&255|b,r>>>=7;case 2:e[t++]=r&255|b,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function Gn(r,e){let t=r[e],n=0;if(n+=t&C,t<b||(t=r[e+1],n+=(t&C)<<7,t<b)||(t=r[e+2],n+=(t&C)<<14,t<b)||(t=r[e+3],n+=(t&C)<<21,t<b)||(t=r[e+4],n+=(t&C)*lt,t<b)||(t=r[e+5],n+=(t&C)*ht,t<b)||(t=r[e+6],n+=(t&C)*ft,t<b)||(t=r[e+7],n+=(t&C)*dt,t<b))return n;throw new RangeError("Could not decode varint")}function Wn(r,e){let t=r.get(e),n=0;if(n+=t&C,t<b||(t=r.get(e+1),n+=(t&C)<<7,t<b)||(t=r.get(e+2),n+=(t&C)<<14,t<b)||(t=r.get(e+3),n+=(t&C)<<21,t<b)||(t=r.get(e+4),n+=(t&C)*lt,t<b)||(t=r.get(e+5),n+=(t&C)*ht,t<b)||(t=r.get(e+6),n+=(t&C)*ft,t<b)||(t=r.get(e+7),n+=(t&C)*dt,t<b))return n;throw new RangeError("Could not decode varint")}function mt(r,e=0){return r instanceof Uint8Array?Gn(r,e):Wn(r,e)}function Jn(r){return r.buffer instanceof ArrayBuffer}function me(r){return Jn(r)?r:r.slice()}function H(r,e="utf8"){let t=ve[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var v=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},F=class extends Error{static name="ValidationError";name="ValidationError"},Ae=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Pe=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function bt(r){return e=>H(e,r)}function yt(r){return e=>k(e,r)}function se(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function X(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(e)}function tr(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=k(e[0],"base32"),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=X(n);return V([t,o],t.length+o.length)}function rr(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=j.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=X(n);return V([t,o],t.length+o.length)}function wt(r){let e=r.subarray(0,r.length-2),t=r.subarray(r.length-2),n=H(e,"base32"),o=se(t);return`${n}:${o}`}var xt=function(r){r=r.toString().trim();let e=new Uint8Array(4);return r.split(/\./g).forEach((t,n)=>{let o=parseInt(t,10);if(isNaN(o)||o<0||o>255)throw new v("Invalid byte value in IP address");e[n]=o}),e},nr=function(r){let e=0;r=r.toString().trim();let t=r.split(":",8),n;for(n=0;n<t.length;n++){let s=Te(t[n]),i;s&&(i=xt(t[n]),t[n]=H(i.subarray(0,2),"base16")),i!=null&&++n<8&&t.splice(n,0,H(i.subarray(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let s=[n,1];for(n=9-t.length;n>0;n--)s.push("0");t.splice.apply(t,s)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){t[n]===""&&(t[n]="0");let s=parseInt(t[n],16);if(isNaN(s)||s<0||s>65535)throw new v("Invalid byte value in IP address");o[e++]=s>>8&255,o[e++]=s&255}return o},or=function(r){if(r.byteLength!==4)throw new v("IPv4 address was incorrect length");let e=[];for(let t=0;t<r.byteLength;t++)e.push(r[t]);return e.join(".")},sr=function(r){if(r.byteLength!==16)throw new v("IPv6 address was incorrect length");let e=[];for(let n=0;n<r.byteLength;n+=2){let o=r[n],s=r[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;e.push(i)}let t=e.join(":");try{let n=new URL(`http://[${t}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new v(`Invalid IPv6 address "${t}"`)}};function ir(r){try{let e=new URL(`http://[${r}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new v(`Invalid IPv6 address "${r}"`)}}var gt=Object.values(pe).map(r=>r.decoder),Xn=(function(){let r=gt[0].or(gt[1]);return gt.slice(2).forEach(e=>r=r.or(e)),r})();function ar(r){return Xn.decode(r)}function cr(r){return e=>r.encoder.encode(e)}function Kn(r){if(parseInt(r).toString()!==r)throw new F("Value must be an integer")}function Yn(r){if(r<0)throw new F("Value must be a positive integer, or zero")}function Zn(r){return e=>{if(e>r)throw new F(`Value must be smaller than or equal to ${r}`)}}function eo(...r){return e=>{for(let t of r)t(e)}}var ge=eo(Kn,Yn,Zn(65535));var x=-1,Et=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(e){let t;if(typeof e=="string"?t=this.protocolsByName.get(e):t=this.protocolsByCode.get(e),t==null)throw new Pe(`Protocol ${e} was unknown`);return t}addProtocol(e){this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),e.aliases?.forEach(t=>{this.protocolsByName.set(t,e)})}removeProtocol(e){let t=this.protocolsByCode.get(e);t!=null&&(this.protocolsByCode.delete(t.code),this.protocolsByName.delete(t.name),t.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},M=new Et,$o=[{code:4,name:"ip4",size:32,valueToBytes:xt,bytesToValue:or,validate:r=>{if(!Te(r))throw new F(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:X,bytesToValue:se,validate:ge},{code:273,name:"udp",size:16,valueToBytes:X,bytesToValue:se,validate:ge},{code:33,name:"dccp",size:16,valueToBytes:X,bytesToValue:se,validate:ge},{code:41,name:"ip6",size:128,valueToBytes:nr,bytesToValue:sr,stringToValue:ir,validate:r=>{if(!er(r))throw new F(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:x},{code:43,name:"ipcidr",size:8,bytesToValue:bt("base10"),valueToBytes:yt("base10")},{code:53,name:"dns",size:x},{code:54,name:"dns4",size:x},{code:55,name:"dns6",size:x},{code:56,name:"dnsaddr",size:x},{code:132,name:"sctp",size:16,valueToBytes:X,bytesToValue:se,validate:ge},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:x,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:x,bytesToValue:bt("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?yt("base58btc")(r):P.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:wt,valueToBytes:tr},{code:445,name:"onion3",size:296,bytesToValue:wt,valueToBytes:rr},{code:446,name:"garlic64",size:x},{code:447,name:"garlic32",size:x},{code:448,name:"tls"},{code:449,name:"sni",size:x},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:x,bytesToValue:cr(Ze),valueToBytes:ar},{code:480,name:"http"},{code:481,name:"http-path",size:x,stringToValue:r=>`/${decodeURIComponent(r)}`,valueToString:r=>encodeURIComponent(r.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:x}];$o.forEach(r=>{M.addProtocol(r)});function ur(r){let e=[],t=0;for(;t<r.length;){let n=mt(r,t),o=M.getProtocol(n),s=oe(n),i=jo(o,r,t+s),c=0;i>0&&o.size===x&&(c=oe(i));let a=s+c+i,u={code:n,name:o.name,bytes:me(r.subarray(t,t+a))};if(i>0){let l=t+s+c,h=r.subarray(l,l+i);u.value=o.bytesToValue?.(h)??H(h)}e.push(u),t+=a}return e}function lr(r){let e=0,t=[];for(let n of r){if(n.bytes==null){let o=M.getProtocol(n.code),s=oe(n.code),i,c=0,a=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??k(n.value),c=i.byteLength,o.size===x&&(a=oe(c)));let u=new Uint8Array(s+a+c),l=0;pt(n.code,u,l),l+=s,i!=null&&(o.size===x&&(pt(c,u,l),l+=a),u.set(i,l)),n.bytes=u}t.push(n.bytes),e+=n.bytes.byteLength}return V(t,e)}function hr(r){if(r.charAt(0)!=="/")throw new v('String multiaddr must start with "/"');let e=[],t="protocol",n="",o="";for(let s=1;s<r.length;s++){let i=r.charAt(s);i!=="/"&&(t==="protocol"?o+=r.charAt(s):n+=r.charAt(s));let c=s===r.length-1;if(i==="/"||c){let a=M.getProtocol(o);if(t==="protocol"){if(a.size==null||a.size===0){e.push({code:a.code,name:a.name}),n="",o="",t="protocol";continue}else if(c)throw new v(`Component ${o} was missing value`);t="value"}else if(t==="value"){let u={code:a.code,name:a.name};if(a.size!=null&&a.size!==0){if(n==="")throw new v(`Component ${o} was missing value`);u.value=a.stringToValue?.(n)??n}e.push(u),n="",o="",t="protocol"}}}if(o!==""&&n!=="")throw new v("Incomplete multiaddr");return e}function fr(r){return`/${r.flatMap(e=>{if(e.value==null)return e.name;let t=M.getProtocol(e.code);if(t==null)throw new v(`Unknown protocol code ${e.code}`);return[e.name,t.valueToString?.(e.value)??e.value]}).join("/")}`}function jo(r,e,t){return r.size==null||r.size===0?0:r.size>0?r.size/8:mt(e,t)}var ko=Symbol.for("nodejs.util.inspect.custom"),vt=Symbol.for("@multiformats/multiaddr");function Ho(r){if(r==null&&(r="/"),dr(r))return r.getComponents();if(r instanceof Uint8Array)return ur(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),hr(r);if(Array.isArray(r))return r;throw new v("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Se=class r{[vt]=!0;#e;#r;#t;constructor(e="/",t={}){this.#e=Ho(e),t.validate!==!1&&Go(this)}get bytes(){return this.#t==null&&(this.#t=lr(this.#e)),this.#t}toString(){return this.#r==null&&(this.#r=fr(this.#e)),this.#r}toJSON(){return this.toString()}getComponents(){return[...this.#e.map(e=>({...e}))]}encapsulate(e){let t=new r(e);return new r([...this.#e,...t.getComponents()],{validate:!1})}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new Ae(`Address ${this.toString()} does not contain subaddress: ${t}`);return new r(n.slice(0,o),{validate:!1})}decapsulateCode(e){let t;for(let n=this.#e.length-1;n>-1;n--)if(this.#e[n].code===e){t=n;break}return new r(this.#e.slice(0,t),{validate:!1})}equals(e){return G(this.bytes,e.bytes)}[ko](){return`Multiaddr(${this.toString()})`}};function Go(r){r.getComponents().forEach(e=>{let t=M.getProtocol(e.code);e.value!=null&&t.validate?.(e.value)})}function dr(r){return!!r?.[vt]}function pr(r){return new Se(r)}function ie(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var De=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},ae=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new De(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let t=this.head;this.head=t.next=new De(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let t=this.tail.next;this.tail.next=null,this.tail=t,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var Ct=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function mr(r={}){return Wo(t=>{let n=t.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function Wo(r,e){e=e??{};let t=e.onEnd,n=new ae,o,s,i,c=ie(),a=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((p,w)=>{s=I=>{s=null,n.push(I);try{p(r(n))}catch(E){w(E)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{c.resolve(),c=ie()})}},u=p=>s!=null?s(p):(n.push(p),o),l=p=>(n=new ae,s!=null?s({error:p}):(n.push({error:p}),o)),h=p=>{if(i)return o;if(e?.objectMode!==!0&&p?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:p})},f=p=>i?o:(i=!0,p!=null?l(p):u({done:!0})),m=()=>(n=new ae,f(),{done:!0}),d=p=>(f(p),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:a,return:m,throw:d,push:h,end:f,get readableLength(){return n.size},onEmpty:async p=>{let w=p?.signal;if(w?.throwIfAborted(),n.isEmpty())return;let I,E;w!=null&&(I=new Promise((T,S)=>{E=()=>{S(new Ct)},w.addEventListener("abort",E)}));try{await Promise.race([c.promise,I])}finally{E!=null&&w!=null&&w?.removeEventListener("abort",E)}}},t==null)return o;let g=o;return o={[Symbol.asyncIterator](){return this},next(){return g.next()},throw(p){return g.throw(p),t!=null&&(t(p),t=void 0),{done:!0}},return(){return g.return(),t!=null&&(t(),t=void 0),{done:!0}},push:h,end(p){return g.end(p),t!=null&&(t(p),t=void 0),o},get readableLength(){return g.readableLength},onEmpty:p=>g.onEmpty(p)},o}var It=class r extends Error{name="TimeoutError";constructor(e,t){super(e,t),Error.captureStackTrace?.(this,r)}},gr=r=>r.reason??new DOMException("This operation was aborted.","AbortError");function Tt(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=e,c,a,l=new Promise((h,f)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(i?.aborted){f(gr(i));return}if(i&&(a=()=>{f(gr(i))},i.addEventListener("abort",a,{once:!0})),r.then(h,f),t===Number.POSITIVE_INFINITY)return;let m=new It;c=s.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(d){f(d)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?h():o instanceof Error?f(o):(m.message=o??`Promise timed out after ${t} milliseconds`,f(m))},t)}).finally(()=>{l.clear(),a&&i&&i.removeEventListener("abort",a)});return l.clear=()=>{s.clearTimeout.call(void 0,c),c=void 0},l}var Qo=r=>{let e=r.addEventListener||r.on||r.addListener,t=r.removeEventListener||r.off||r.removeListener;if(!e||!t)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(r),removeListener:t.bind(r)}};function Jo(r,e,t){let n,o=new Promise((s,i)=>{if(t={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...t},!(t.count>=0&&(t.count===Number.POSITIVE_INFINITY||Number.isInteger(t.count))))throw new TypeError("The `count` option should be at least 0 or more");t.signal?.throwIfAborted();let c=[e].flat(),a=[],{addListener:u,removeListener:l}=Qo(r),h=async(...m)=>{let d=t.multiArgs?m:m[0];if(t.filter)try{if(!await t.filter(d))return}catch(g){n(),i(g);return}a.push(d),t.count===a.length&&(n(),s(a))},f=(...m)=>{n(),i(t.rejectionMultiArgs?m:m[0])};n=()=>{for(let m of c)l(m,h);for(let m of t.rejectionEvents)c.includes(m)||l(m,f)};for(let m of c)u(m,h);for(let m of t.rejectionEvents)c.includes(m)||u(m,f);t.signal&&t.signal.addEventListener("abort",()=>{f(t.signal.reason)},{once:!0}),t.resolveImmediately&&s(a)});if(o.cancel=n,typeof t.timeout=="number"){let s=Tt(o,{milliseconds:t.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function Le(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=Jo(r,e,t),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function At(r,e){let t,n=function(){let o=function(){t=void 0,r()};clearTimeout(t),t=setTimeout(o,e)};return n.start=()=>{},n.stop=()=>{clearTimeout(t)},n}var Ne=class extends Error{static name="QueueFullError";constructor(e="The queue was full"){super(e),this.name="QueueFullError"}};function Xo(r){return r.reason}async function br(r,e,t){if(e==null)return r;let n=t?.translateError??Xo;if(e.aborted)return r.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([r,new Promise((s,i)=>{o=()=>{i(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var Oe=class{deferred;signal;onProgress;constructor(e){this.signal=e?.signal,this.onProgress=e?.onProgress,this.deferred=ie(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new B)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function Ko(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Ue=class{id;fn;options;recipients;status;timeline;controller;dispatchingProgress;constructor(e,t){this.id=Ko(),this.status="queued",this.fn=e,this.options=t,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.dispatchingProgress=!1,this.onAbort=this.onAbort.bind(this)}abort(e){this.controller.abort(e)}onAbort(){this.recipients.reduce((t,n)=>t&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new B),this.cleanup())}async join(e){let t=new Oe(e);return this.recipients.push(t),e?.signal?.addEventListener("abort",this.onAbort),t.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let e=await br(this.fn({...this.options??{},signal:this.controller.signal,onProgress:t=>{if(!this.dispatchingProgress){this.dispatchingProgress=!0;try{this.recipients.forEach(n=>{n.onProgress?.(t)})}finally{this.dispatchingProgress=!1}}}}),this.controller.signal);this.recipients.forEach(t=>{t.deferred.resolve(e)}),this.status="complete"}catch(e){this.recipients.forEach(t=>{t.deferred.reject(e)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(e=>{e.cleanup(),e.signal?.removeEventListener("abort",this.onAbort)})}};var Re=class extends xe{concurrency;maxSize;queue;pending;sort;paused;constructor(e={}){super(),this.concurrency=e.concurrency??Number.POSITIVE_INFINITY,this.maxSize=e.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.paused=!1,e.metricName!=null&&e.metrics?.registerMetricGroup(e.metricName,{calculate:()=>({size:this.queue.length,running:this.pending,queued:this.queue.length-this.pending})}),this.sort=e.sort,this.queue=[],this.emitEmpty=At(this.emitEmpty.bind(this),1),this.emitIdle=At(this.emitIdle.bind(this),1)}emitEmpty(){this.size===0&&this.safeDispatchEvent("empty")}emitIdle(){this.running===0&&this.safeDispatchEvent("idle")}pause(){this.paused=!0}resume(){this.paused&&(this.paused=!1,this.tryToStartAnother())}tryToStartAnother(){if(this.paused)return!1;if(this.size===0)return this.emitEmpty(),this.running===0&&this.emitIdle(),!1;if(this.pending<this.concurrency){let e;for(let t of this.queue)if(t.status==="queued"){e=t;break}return e==null?!1:(this.safeDispatchEvent("active"),this.pending++,e.run().finally(()=>{for(let t=0;t<this.queue.length;t++)if(this.queue[t]===e){this.queue.splice(t,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(e){this.queue.push(e),this.sort!=null&&this.queue.sort(this.sort)}async add(e,t){if(t?.signal?.throwIfAborted(),this.size===this.maxSize)throw new Ne;let n=new Ue(e,t);this.enqueue(n),this.safeDispatchEvent("add");let o=n.join(t).then(s=>(this.safeDispatchEvent("completed",{detail:s}),this.safeDispatchEvent("success",{detail:{job:n,result:s}}),s)).catch(s=>{if(n.status==="queued"){for(let i=0;i<this.queue.length;i++)if(this.queue[i]===n){this.queue.splice(i,1);break}}throw this.safeDispatchEvent("failure",{detail:{job:n,error:s}}),s});return this.tryToStartAnother(),o}clear(){this.queue.splice(0,this.queue.length)}abort(){this.queue.forEach(e=>{e.abort(new B)}),this.clear()}async onEmpty(e){this.size!==0&&await Le(this,"empty",e)}async onSizeLessThan(e,t){this.size<e||await Le(this,"next",{...t,filter:()=>this.size<e})}async onIdle(e){this.pending===0&&this.size===0||await Le(this,"idle",e)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(e){e?.signal?.throwIfAborted();let t=mr({objectMode:!0}),n=a=>{a!=null?this.abort():this.clear(),t.end(a)},o=a=>{a.detail!=null&&t.push(a.detail)},s=a=>{n(a.detail.error)},i=()=>{n()},c=()=>{n(new B("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",s),this.addEventListener("idle",i),e?.signal?.addEventListener("abort",c);try{yield*t}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",s),this.removeEventListener("idle",i),e?.signal?.removeEventListener("abort",c),n()}}};function ce(r){let e=new globalThis.AbortController;function t(){let s=r.filter(i=>i?.aborted===!0).map(i=>i?.reason).pop();e.abort(s);for(let i of r)i?.removeEventListener!=null&&i.removeEventListener("abort",t)}for(let s of r){if(s?.aborted===!0){t();break}s?.addEventListener!=null&&s.addEventListener("abort",t)}function n(){for(let s of r)s?.removeEventListener!=null&&s.removeEventListener("abort",t)}let o=e.signal;return o.clear=n,o}async function*be(r,e={}){let t=r.getReader();try{for(;;){let n=await t.read();if(n.done)return;yield n.value}}finally{e.preventCancel!==!0&&await t.cancel(),t.releaseLock()}}var Be=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MESSAGE_LENGTH"};async function*ue(r,e={}){let t=/\r?\n/,n=new TextDecoder("utf8"),o="";for await(let s of r){if(typeof s=="string"&&(s=new TextEncoder().encode(s)),Y(s)&&(s=s.subarray()),o+=n.decode(s,{stream:!0}),o.length>(e?.maxMessageLength??o.length))throw new Be("Incoming message too long");let i=o.split(t);o=i.pop()??"";for(let c=0;c<i.length;c++)yield JSON.parse(i[c])}o+=n.decode(),o!==""&&(yield JSON.parse(o))}var K=class extends Error{static name="InvalidRequestError";constructor(e="Invalid request"){super(e),this.name="InvalidRequestError"}},L=class extends Error{static name="BadResponseError";constructor(e="Bad response"){super(e),this.name="BadResponseError"}};var _e={concurrentRequests:4,timeout:3e4,cacheTTL:300*1e3,cacheName:"delegated-routing-v1-cache"},Ve=class{url;started;httpQueue;shutDownController;timeout;filterAddrs;filterProtocols;inFlightRequests;cacheName;cache;cacheTTL;log;constructor(e,t){this.log=e.logger.forComponent("delegated-routing-v1-http-api-client"),this.started=!1,this.shutDownController=new AbortController,this.shutDownController.signal,this.httpQueue=new Re({concurrency:t.concurrentRequests??_e.concurrentRequests}),this.inFlightRequests=new Map,this.url=t.url instanceof URL?t.url:new URL(t.url),this.timeout=t.timeout??_e.timeout,this.filterAddrs=t.filterAddrs,this.filterProtocols=t.filterProtocols,this.cacheName=t.cacheName??_e.cacheName,this.cacheTTL=t.cacheTTL??_e.cacheTTL}isStarted(){return this.started}async start(){this.started||(this.started=!0,this.cacheTTL>0&&(this.cache=await globalThis.caches?.open(this.cacheName),this.cache!=null&&this.log("cache enabled with ttl %d",this.cacheTTL)))}async stop(){this.httpQueue.clear(),this.shutDownController.abort(),await globalThis.caches?.delete(this.cacheName),this.started=!1}async*getProviders(e,t={}){this.log("getProviders starts: %c",e);let n=AbortSignal.timeout(this.timeout),o=ce([this.shutDownController.signal,n,t.signal]);let s=Promise.withResolvers(),i=Promise.withResolvers(),c=0;this.httpQueue.add(async()=>(s.resolve(),i.promise));try{await s.promise;let a=new URL(`${this.url}routing/v1/providers/${e}`);this.#r(a,t.filterAddrs,t.filterProtocols);let u=await this.#t(a.toString(),{headers:{accept:"application/x-ndjson, application/json;q=0.8"},signal:o});if(!u.ok){if(u.status===404)return;throw u.status===422?new K("Request does not conform to schema or semantic constraints"):new L(`Unexpected status code: ${u.status}`)}let l=u.headers.get("Content-Type");if(l==null)throw new L("No Content-Type header received");if(u.body==null){if(l!=="application/x-ndjson")throw new L("Routing response had no body");return}if(l.startsWith("application/json")){let f=(await u.json()).Providers??[];for(let m of f){let d=this.#e(m);d!=null&&(c++,yield d)}}else if(l.includes("application/x-ndjson"))for await(let h of ue(be(u.body))){let f=this.#e(h);f!=null&&(c++,yield f)}else throw new L(`Unsupported Content-Type: ${l}`)}finally{o.clear(),i.resolve(),this.log("getProviders finished found %d providers for %c",c,e)}}async*getPeers(e,t={}){this.log("getPeers starts: %c",e);let n=AbortSignal.timeout(this.timeout),o=ce([this.shutDownController.signal,n,t.signal]);let s=Promise.withResolvers(),i=Promise.withResolvers();this.httpQueue.add(async()=>(s.resolve(),i.promise));try{await s.promise;let c=new URL(`${this.url}routing/v1/peers/${e}`);this.#r(c,t.filterAddrs,t.filterProtocols);let a=await this.#t(c.toString(),{headers:{Accept:"application/x-ndjson"},signal:o});if(a.status===404)return;if(a.status===422)throw new K("Request does not conform to schema or semantic constraints");if(a.body==null)throw new L("Routing response had no body");if(a.headers.get("Content-Type")?.startsWith("application/json")){let h=(await a.json()).Peers??[];for(let f of h){let m=this.#e(f);m!=null&&(yield m)}}else for await(let l of ue(be(a.body))){let h=this.#e(l);h!=null&&(yield h)}}catch(c){this.log.error("getPeers errored - %e",c)}finally{o.clear(),i.resolve(),this.log("getPeers finished: %c",e)}}async*getClosestPeers(e,t={}){let n;if(P.asCID(e)===e||e instanceof P)n=e.toV1().toString();else throw new we("Key must be CID");this.log("getClosestPeers starts: %s",n);let o=AbortSignal.timeout(this.timeout),s=ce([this.shutDownController.signal,o,t.signal]);let i=Promise.withResolvers(),c=Promise.withResolvers();this.httpQueue.add(async()=>(i.resolve(),c.promise));try{await i.promise;let a=new URL(`${this.url}routing/v1/dht/closest/peers/${n}`);this.#r(a,t.filterAddrs,t.filterProtocols);let u=await this.#t(a.toString(),{headers:{Accept:"application/x-ndjson"},signal:s});if(u.status===404)return;if(u.status===422)throw new K("Request does not conform to schema or semantic constraints");if(u.body==null)throw new L("Routing response had no body");if(u.headers.get("Content-Type")?.startsWith("application/json")){let f=(await u.json()).Peers??[];for(let m of f){let d=this.#e(m);d!=null&&(yield d)}}else for await(let h of ue(be(u.body))){let f=this.#e(h);f!=null&&(yield f)}}catch(a){this.log.error("getClosestPeers errored - %e",a)}finally{s.clear(),c.resolve(),this.log("getClosestPeers finished: %s",n)}}async getIPNS(e,t={}){this.log("getIPNS starts: %c",e);let n=AbortSignal.timeout(this.timeout),o=ce([this.shutDownController.signal,n,t.signal]);let s=Promise.withResolvers(),i=Promise.withResolvers();this.httpQueue.add(async()=>(s.resolve(),i.promise));let c=`${this.url}routing/v1/ipns/${e}`;try{await s.promise;let a=await this.#t(c,{headers:{Accept:"application/vnd.ipfs.ipns-record"},signal:o});if(this.log("getIPNS GET %s %d",c,a.status),a.status===404)throw new _("No matching records found");if(a.status===422)throw new K("Request does not conform to schema or semantic constraints");if(!a.ok)throw new L(`Unexpected status code: ${a.status}`);let u=a.headers.get("Content-Type");if(u==null||!u.includes("application/vnd.ipfs.ipns-record"))throw new _("No matching records found");if(a.body==null)throw new L("GET ipns response had no body");let l=await a.arrayBuffer();return new Uint8Array(l,0,l.byteLength)}catch(a){throw this.log.error("getIPNS GET %s error - %e",c,a),a}finally{o.clear(),i.resolve(),this.log("getIPNS finished: %c",e)}}async putIPNS(e,t,n={}){this.log("putIPNS starts: %c",e);let o=AbortSignal.timeout(this.timeout),s=ce([this.shutDownController.signal,o,n.signal]);let i=Promise.withResolvers(),c=Promise.withResolvers();this.httpQueue.add(async()=>(i.resolve(),c.promise));let a=`${this.url}routing/v1/ipns/${e}`;try{await i.promise;let u=await this.#t(a,{method:"PUT",headers:{"Content-Type":"application/vnd.ipfs.ipns-record"},body:me(t),signal:s});if(this.log("putIPNS PUT %s %d",a,u.status),u.status!==200)throw new L("PUT ipns response had status other than 200")}catch(u){throw this.log.error("putIPNS PUT %s error - %e",a,u.stack),u}finally{s.clear(),c.resolve(),this.log("putIPNS finished: %c",e)}}#e(e){try{let t=[],n=e.Addrs?.map(pr)??[];return e.Protocols!=null&&t.push(...e.Protocols),e.Protocol!=null&&(t.push(e.Protocol),delete e.Protocol),{...e,Schema:"peer",ID:P.createV1(114,Yo(e.ID)),Addrs:n,Protocols:t}}catch(t){this.log.error("could not conform record to peer schema - %e",t)}}#r(e,t,n){if(t!=null||this.filterAddrs!=null){let o=t?.join(",")??this.filterAddrs?.join(",")??"";o!==""&&e.searchParams.set("filter-addrs",o)}if(n!=null||this.filterProtocols!=null){let o=n?.join(",")??this.filterProtocols?.join(",")??"";o!==""&&e.searchParams.set("filter-protocols",o)}}async#t(e,t){let n=t.method??"GET",o=`${n}-${e}`;if(n==="GET"){let a=await this.cache?.match(e);if(a!=null){if(parseInt(a.headers.get("x-cache-expires")??"0",10)>Date.now())return this.log("returning cached response for %s",o),this.logResponse(a),a;this.log("evicting cached response for %s",o),await this.cache?.delete(e)}else this.cache!=null&&this.log("cache miss for %s",o)}let s=this.inFlightRequests.get(o);if(s!=null){let a=await s;return this.log("deduplicating outgoing request for %s",o),a.clone()}this.log("outgoing request:"),this.logRequest(e,t);let i=fetch(e,t).then(async a=>{if(this.log("incoming response:"),this.logResponse(a),this.cache!=null&&a.ok&&n==="GET"){let u=Date.now()+this.cacheTTL,l=new Headers(a.headers);l.set("x-cache-expires",u.toString());let h=new Response(a.clone().body,{status:a.status,statusText:a.statusText,headers:l});await this.cache.put(e,h)}return a}).finally(()=>{this.inFlightRequests.delete(o)});return this.inFlightRequests.set(o,i),await i}toString(){return`DefaultDelegatedRoutingV1HttpApiClient(${this.url})`}logRequest(e,t){let n=new Headers(t.headers);this.log("%s %s HTTP/1.1",t.method??"GET",e);for(let[o,s]of n.entries())this.log("%s: %s",o,s)}logResponse(e){this.log("HTTP/1.1 %d %s",e.status,e.statusText);for(let[t,n]of e.headers.entries())this.log("%s: %s",t,n)}};function Yo(r){let e=D.baseDecode(r);return Q(e)}function Zo(r){return r[Symbol.asyncIterator]!=null}function es(r){if(Zo(r))return(async()=>{for await(let e of r)return e})();for(let e of r)return e}var yr=es;function ts(r){let[e,t]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>e.next(),push:o=>{n.push(o)},next:()=>n.length>0?{done:!1,value:n.shift()}:e.next(),[t](){return this}}}var wr=ts;function rs(r){return r[Symbol.asyncIterator]!=null}function ns(r,e){let t=0;if(rs(r))return(async function*(){for await(let a of r)yield e(a,t++)})();let n=wr(r),{value:o,done:s}=n.next();if(s===!0)return(function*(){})();let i=e(o,t++);if(typeof i.then=="function")return(async function*(){yield await i;for(let a of n)yield e(a,t++)})();let c=e;return(function*(){yield i;for(let a of n)yield c(a,t++)})()}var xr=ns;function Er(r){return e=>new Ve(e,r)}var ze=k("/ipns/");function vr(r){return G(r.subarray(0,ze.byteLength),ze)}var Fe=class{name="delegated-http-router";client;constructor(e,t){this.client=Er(t)(e)}async provide(e,t){}async cancelReprovide(e,t){}async*findProviders(e,t){yield*xr(this.client.getProviders(e,t),n=>({id:n.ID,multiaddrs:n.Addrs,protocols:n.Protocols,routing:"delegated-http-routing"}))}async put(e,t,n){if(!vr(e))return;let o=Q(e.slice(ze.length)),s=P.createV1(114,o);await this.client.putIPNS(s,t,n)}async get(e,t){if(!vr(e))throw new _("Not found");let n=Q(e.slice(ze.length)),o=P.createV1(114,n);try{return await this.client.getIPNS(o,t)}catch(s){throw s.name==="BadResponseError"?new _("Not found"):s}}async findPeer(e,t){let n=await yr(this.client.getPeers(e,t));if(n!=null)return{id:n.ID,multiaddrs:n.Addrs??[]};throw new _("Not found")}async*getClosestPeers(e,t){}toString(){return`DelegatedHTTPRouter(${this.client.url})`}};function Pt(r){return{url:"https://delegated-ipfs.dev",filterProtocols:["unknown","transport-bitswap","transport-ipfs-gateway-http"],filterAddrs:["https","webtransport","webrtc","webrtc-direct","wss","tls"]}}function os(r){return e=>new Fe(e,Pt(r))}return Pr(ss);})();
|
|
3
|
+
return HeliaDelegatedRoutingClient}));
|
|
4
|
+
//# sourceMappingURL=index.min.js.map
|