@helia/trustless-gateway-client 0.0.0-9114743f
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 +71 -0
- package/dist/index.min.js +33 -0
- package/dist/index.min.js.map +7 -0
- package/dist/src/broker.d.ts +44 -0
- package/dist/src/broker.d.ts.map +1 -0
- package/dist/src/broker.js +75 -0
- package/dist/src/broker.js.map +1 -0
- package/dist/src/index.d.ts +64 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +19 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/session.d.ts +30 -0
- package/dist/src/session.d.ts.map +1 -0
- package/dist/src/session.js +89 -0
- package/dist/src/session.js.map +1 -0
- package/dist/src/trustless-gateway.d.ts +64 -0
- package/dist/src/trustless-gateway.d.ts.map +1 -0
- package/dist/src/trustless-gateway.js +217 -0
- package/dist/src/trustless-gateway.js.map +1 -0
- package/dist/src/utils.d.ts +27 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/utils.js +106 -0
- package/dist/src/utils.js.map +1 -0
- package/package.json +78 -0
- package/src/broker.ts +112 -0
- package/src/index.ts +81 -0
- package/src/session.ts +119 -0
- package/src/trustless-gateway.ts +279 -0
- package/src/utils.ts +141 -0
package/README.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
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/trustless-gateway-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 Trustless HTTP Gateways 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
|
+
A Trustless Gateway is an HTTP endpoint that can be used to download blocks
|
|
34
|
+
or CAR files in a verifiable way.
|
|
35
|
+
|
|
36
|
+
# Install
|
|
37
|
+
|
|
38
|
+
```console
|
|
39
|
+
$ npm i @helia/trustless-gateway-client
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Browser `<script>` tag
|
|
43
|
+
|
|
44
|
+
Loading this module through a script tag will make its exports available as `HeliaTrustlessGatewayClient` in the global namespace.
|
|
45
|
+
|
|
46
|
+
```html
|
|
47
|
+
<script src="https://unpkg.com/@helia/trustless-gateway-client/dist/index.min.js"></script>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
# API Docs
|
|
51
|
+
|
|
52
|
+
- <https://ipfs.github.io/helia/modules/_helia_trustless-gateway-client.html>
|
|
53
|
+
|
|
54
|
+
# License
|
|
55
|
+
|
|
56
|
+
Licensed under either of
|
|
57
|
+
|
|
58
|
+
- Apache 2.0, ([LICENSE-APACHE](https://github.com/ipfs/helia/blob/main/packages/trustless-gateway-client/LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
|
|
59
|
+
- MIT ([LICENSE-MIT](https://github.com/ipfs/helia/blob/main/packages/trustless-gateway-client/LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
|
|
60
|
+
|
|
61
|
+
# Contribute
|
|
62
|
+
|
|
63
|
+
Contributions welcome! Please check out [the issues](https://github.com/ipfs/helia/issues).
|
|
64
|
+
|
|
65
|
+
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.
|
|
66
|
+
|
|
67
|
+
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).
|
|
68
|
+
|
|
69
|
+
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.
|
|
70
|
+
|
|
71
|
+
[](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.HeliaTrustlessGatewayClient = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
+
"use strict";var HeliaTrustlessGatewayClient=(()=>{var ss=Object.create;var ae=Object.defineProperty;var is=Object.getOwnPropertyDescriptor;var as=Object.getOwnPropertyNames;var cs=Object.getPrototypeOf,ls=Object.prototype.hasOwnProperty;var ce=(r,t)=>()=>{try{return t||r((t={exports:{}}).exports,t),t.exports}catch(e){throw t=0,e}},M=(r,t)=>{for(var e in t)ae(r,e,{get:t[e],enumerable:!0})},In=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of as(t))!ls.call(r,o)&&o!==e&&ae(r,o,{get:()=>t[o],enumerable:!(n=is(t,o))||n.enumerable});return r};var Sn=(r,t,e)=>(e=r!=null?ss(cs(r)):{},In(t||!r||!r.__esModule?ae(e,"default",{value:r,enumerable:!0}):e,r)),us=r=>In(ae({},"__esModule",{value:!0}),r);var to=ce((tu,Zn)=>{Zn.exports=function(r){if(!r)throw Error("hashlru must have a max value, of type number, greater than 0");var t=0,e=Object.create(null),n=Object.create(null);function o(s,i){e[s]=i,t++,t>=r&&(t=0,n=e,e=Object.create(null))}return{has:function(s){return e[s]!==void 0||n[s]!==void 0},remove:function(s){e[s]!==void 0&&(e[s]=void 0),n[s]!==void 0&&(n[s]=void 0)},get:function(s){var i=e[s];if(i!==void 0)return i;if((i=n[s])!==void 0)return o(s,i),i},set:function(s,i){e[s]!==void 0?e[s]=i:o(s,i)},clear:function(){e=Object.create(null),n=Object.create(null)}}}});var Ur=ce(Lt=>{"use strict";Object.defineProperty(Lt,"__esModule",{value:!0});Lt.Netmask4Impl=void 0;Lt.ip2long=Ft;Lt.long2ip=Y;function Y(r){let t=(r&-16777216)>>>24,e=(r&255<<16)>>>16,n=(r&65280)>>>8,o=r&255;return[t,e,n,o].join(".")}var da=48,pa=97,ma=65;function ga(r){let t=0,e=10,n="9",o=0;r.length>1&&r[o]==="0"&&(r[o+1]==="x"||r[o+1]==="X"?(o+=2,e=16):"0"<=r[o+1]&&r[o+1]<="9"&&(o++,e=8,n="7"));let s=o;for(;o<r.length;){if("0"<=r[o]&&r[o]<=n)t=t*e+(r.charCodeAt(o)-da)>>>0;else if(e===16)if("a"<=r[o]&&r[o]<="f")t=t*e+(10+r.charCodeAt(o)-pa)>>>0;else if("A"<=r[o]&&r[o]<="F")t=t*e+(10+r.charCodeAt(o)-ma)>>>0;else break;else break;if(t>4294967295)throw new Error("too large");o++}if(o===s)throw new Error("empty octet");return[t,o]}function Ft(r){let t=[];for(let e=0;e<=3&&r.length!==0;e++){if(e>0){if(r[0]!==".")throw new Error("Invalid IP");r=r.substring(1)}let[n,o]=ga(r);r=r.substring(o),t.push(n)}if(r.length!==0)throw new Error("Invalid IP");switch(t.length){case 1:if(t[0]>4294967295)throw new Error("Invalid IP");return t[0]>>>0;case 2:if(t[0]>255||t[1]>16777215)throw new Error("Invalid IP");return(t[0]<<24|t[1])>>>0;case 3:if(t[0]>255||t[1]>255||t[2]>65535)throw new Error("Invalid IP");return(t[0]<<24|t[1]<<16|t[2])>>>0;case 4:if(t[0]>255||t[1]>255||t[2]>255||t[3]>255)throw new Error("Invalid IP");return(t[0]<<24|t[1]<<16|t[2]<<8|t[3])>>>0;default:throw new Error("Invalid IP")}}var $r=class r{constructor(t,e){if(typeof t!="string")throw new Error("Missing `net' parameter");let n=e;if(!n){let o=t.split("/",2);t=o[0],n=o[1]}if(n||(n=32),typeof n=="string"&&n.indexOf(".")>-1){try{this.maskLong=Ft(n)}catch{throw new Error("Invalid mask: "+n)}this.bitmask=NaN;for(let o=32;o>=0;o--)if(this.maskLong===4294967295<<32-o>>>0){this.bitmask=o;break}}else if(n||n===0)this.bitmask=parseInt(n,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(Ft(t)&this.maskLong)>>>0}catch{throw new Error("Invalid net address: "+t)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+n);this.size=Math.pow(2,32-this.bitmask),this.base=Y(this.netLong),this.mask=Y(this.maskLong),this.hostmask=Y(~this.maskLong),this.first=this.bitmask<=30?Y(this.netLong+1):this.base,this.last=this.bitmask<=30?Y(this.netLong+this.size-2):Y(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?Y(this.netLong+this.size-1):void 0}contains(t){return typeof t=="string"&&(t.indexOf("/")>0||t.split(".").length!==4)&&(t=new r(t)),t instanceof r?this.contains(t.base)&&this.contains(t.broadcast||t.last):(Ft(t)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0}next(t=1){return new r(Y(this.netLong+this.size*t),this.mask)}forEach(t){let e=Ft(this.first),n=Ft(this.last),o=0;for(;e<=n;)t(Y(e),e,o),o++,e++}toString(){return this.base+"/"+this.bitmask}};Lt.Netmask4Impl=$r});var go=ce(Nt=>{"use strict";Object.defineProperty(Nt,"__esModule",{value:!0});Nt.Netmask6Impl=void 0;Nt.ip6bigint=Mr;Nt.bigint2ip6=wt;var ya=Ur(),Rr=(1n<<128n)-1n;function Mr(r){let t=r.indexOf("%");t!==-1&&(r=r.substring(0,t));let e=r.lastIndexOf(":");if(e!==-1&&r.indexOf(".",e)!==-1){let n=r.substring(e+1),o=(0,ya.ip2long)(n),s=r.substring(0,e+1)+"0:0";return mo(s)&~0xffffffffn|BigInt(o)}return mo(r)}function mo(r){let t=r.indexOf("::"),e;if(t!==-1){let o=r.substring(0,t),s=r.substring(t+2),i=o===""?[]:o.split(":"),a=s===""?[]:s.split(":"),c=8-i.length-a.length;if(c<0)throw new Error("Invalid IPv6: too many groups");e=[...i,...Array(c).fill("0"),...a]}else e=r.split(":");if(e.length!==8)throw new Error("Invalid IPv6: expected 8 groups, got "+e.length);let n=0n;for(let o=0;o<8;o++){let s=e[o];if(s.length===0||s.length>4)throw new Error('Invalid IPv6: bad group "'+s+'"');let i=parseInt(s,16);if(isNaN(i)||i<0||i>65535)throw new Error('Invalid IPv6: bad group "'+s+'"');n=n<<16n|BigInt(i)}return n}function wt(r){if(r<0n||r>Rr)throw new Error("Invalid IPv6 address value");let t=[];for(let i=0;i<8;i++)t.unshift(Number(r&0xffffn)),r>>=16n;let e=-1,n=0,o=-1,s=0;for(let i=0;i<8;i++)t[i]===0?o===-1?(o=i,s=1):s++:(s>n&&s>=2&&(e=o,n=s),o=-1,s=0);if(s>n&&s>=2&&(e=o,n=s),e!==-1&&e+n===8&&e>0)return t.slice(0,e).map(a=>a.toString(16)).join(":")+"::";if(e===0)return"::"+t.slice(n).map(a=>a.toString(16)).join(":");if(e>0){let i=t.slice(0,e).map(c=>c.toString(16)),a=t.slice(e+n).map(c=>c.toString(16));return i.join(":")+"::"+a.join(":")}else return t.map(i=>i.toString(16)).join(":")}var Br=class r{constructor(t,e){if(typeof t!="string")throw new Error("Missing `net' parameter");let n=e;if(n==null){let o=t.indexOf("/");o!==-1?(n=parseInt(t.substring(o+1),10),t=t.substring(0,o)):n=128}if(isNaN(n)||n<0||n>128)throw new Error("Invalid mask for IPv6: "+n);this.bitmask=n,this.bitmask===0?this.maskBigint=0n:this.maskBigint=Rr>>BigInt(128-this.bitmask)<<BigInt(128-this.bitmask);try{this.netBigint=Mr(t)&this.maskBigint}catch{throw new Error("Invalid IPv6 net address: "+t)}this.size=Number(1n<<BigInt(128-this.bitmask)),this.base=wt(this.netBigint),this.mask=wt(this.maskBigint),this.hostmask=wt(~this.maskBigint&Rr),this.first=this.base,this.last=wt(this.netBigint+(1n<<BigInt(128-this.bitmask))-1n),this.broadcast=void 0}contains(t){return typeof t=="string"&&t.indexOf("/")>0&&(t=new r(t)),t instanceof r?this.contains(t.base)&&this.contains(t.last):(Mr(t)&this.maskBigint)===this.netBigint}next(t=1){let e=1n<<BigInt(128-this.bitmask);return new r(wt(this.netBigint+e*BigInt(t)),this.bitmask)}forEach(t){let e=this.netBigint,n=1n<<BigInt(128-this.bitmask),o=this.netBigint+n-1n,s=0;for(;e<=o;)t(wt(e),Number(e),s),s++,e++}toString(){return this.base+"/"+this.bitmask}};Nt.Netmask6Impl=Br});var yo=ce(ct=>{"use strict";Object.defineProperty(ct,"__esModule",{value:!0});ct.long2ip=ct.ip2long=ct.Netmask=void 0;var Ce=Ur();Object.defineProperty(ct,"ip2long",{enumerable:!0,get:function(){return Ce.ip2long}});Object.defineProperty(ct,"long2ip",{enumerable:!0,get:function(){return Ce.long2ip}});var wa=go(),zr=class r{constructor(t,e){if(typeof t!="string")throw new Error("Missing `net' parameter");(t.indexOf("/")!==-1?t.substring(0,t.indexOf("/")):t).indexOf(":")!==-1?this._impl=new wa.Netmask6Impl(t,e):this._impl=new Ce.Netmask4Impl(t,e),this.base=this._impl.base,this.mask=this._impl.mask,this.hostmask=this._impl.hostmask,this.bitmask=this._impl.bitmask,this.size=this._impl.size,this.first=this._impl.first,this.last=this._impl.last,this.broadcast=this._impl.broadcast,this._impl instanceof Ce.Netmask4Impl?(this.maskLong=this._impl.maskLong,this.netLong=this._impl.netLong):(this.maskLong=0,this.netLong=0)}contains(t){return typeof t=="string"&&(t.indexOf("/")>0?t=new r(t):t.indexOf(":")===-1&&t.split(".").length!==4&&(t=new r(t))),t instanceof r?this.contains(t.base)&&this.contains(t.broadcast||t.last):this._impl.contains(t)}next(t=1){let e=this._impl.next(t);return new r(e.base,e.bitmask)}forEach(t){this._impl.forEach(t)}toString(){return this._impl.toString()}};ct.Netmask=zr});var Ic={};M(Ic,{DEFAULT_ALLOW_INSECURE:()=>se,DEFAULT_ALLOW_LOCAL:()=>ie,DEFAULT_MAX_SIZE:()=>_n,trustlessGatewayBlockBroker:()=>Cc});function B(r=0){return new Uint8Array(r)}function J(r=0){return new Uint8Array(r)}var fs=Math.pow(2,7),hs=Math.pow(2,14),ds=Math.pow(2,21),Qe=Math.pow(2,28),Xe=Math.pow(2,35),Je=Math.pow(2,42),Ye=Math.pow(2,49),I=128,L=127;function Et(r){if(r<fs)return 1;if(r<hs)return 2;if(r<ds)return 3;if(r<Qe)return 4;if(r<Xe)return 5;if(r<Je)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 Ze(r,t,e=0){switch(Et(r)){case 8:t[e++]=r&255|I,r/=128;case 7:t[e++]=r&255|I,r/=128;case 6:t[e++]=r&255|I,r/=128;case 5:t[e++]=r&255|I,r/=128;case 4:t[e++]=r&255|I,r>>>=7;case 3:t[e++]=r&255|I,r>>>=7;case 2:t[e++]=r&255|I,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function ps(r,t){let e=r[t],n=0;if(n+=e&L,e<I||(e=r[t+1],n+=(e&L)<<7,e<I)||(e=r[t+2],n+=(e&L)<<14,e<I)||(e=r[t+3],n+=(e&L)<<21,e<I)||(e=r[t+4],n+=(e&L)*Qe,e<I)||(e=r[t+5],n+=(e&L)*Xe,e<I)||(e=r[t+6],n+=(e&L)*Je,e<I)||(e=r[t+7],n+=(e&L)*Ye,e<I))return n;throw new RangeError("Could not decode varint")}function ms(r,t){let e=r.get(t),n=0;if(n+=e&L,e<I||(e=r.get(t+1),n+=(e&L)<<7,e<I)||(e=r.get(t+2),n+=(e&L)<<14,e<I)||(e=r.get(t+3),n+=(e&L)<<21,e<I)||(e=r.get(t+4),n+=(e&L)*Qe,e<I)||(e=r.get(t+5),n+=(e&L)*Xe,e<I)||(e=r.get(t+6),n+=(e&L)*Je,e<I)||(e=r.get(t+7),n+=(e&L)*Ye,e<I))return n;throw new RangeError("Could not decode varint")}function tr(r,t=0){return r instanceof Uint8Array?ps(r,t):ms(r,t)}function ys(r){return r.buffer instanceof ArrayBuffer}function er(r){return ys(r)?r:r.slice()}var ir={};M(ir,{base10:()=>Is});var Tc=new Uint8Array(0);function An(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 tt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return ht(r);if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return ht(new Uint8Array(r.buffer,r.byteOffset,r.byteLength));throw new Error("Unknown type, must be binary type")}function Pn(r){return new TextEncoder().encode(r)}function Dn(r){return new TextDecoder().decode(r)}function ws(r){return r?.buffer instanceof ArrayBuffer}function ht(r){return ws(r)?r:r.slice()}function bs(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),h=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function f(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var x=0,p=0,w=0,C=g.length;w!==C&&g[w]===0;)w++,x++;for(var S=(C-w)*u+1>>>0,O=new Uint8Array(S);w!==C;){for(var k=g[w],Z=0,$=S-1;(k!==0||Z<p)&&$!==-1;$--,Z++)k+=256*O[$]>>>0,O[$]=k%a>>>0,k=k/a>>>0;if(k!==0)throw new Error("Non-zero carry");p=Z,w++}for(var V=S-p;V!==S&&O[V]===0;)V++;for(var ft=c.repeat(x);V<S;++V)ft+=r.charAt(O[V]);return ft}function l(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var x=0;if(g[x]!==" "){for(var p=0,w=0;g[x]===c;)p++,x++;for(var C=(g.length-x)*h+1>>>0,S=new Uint8Array(C);g[x];){var O=e[g.charCodeAt(x)];if(O===255)return;for(var k=0,Z=C-1;(O!==0||k<w)&&Z!==-1;Z--,k++)O+=a*S[Z]>>>0,S[Z]=O%256>>>0,O=O/256>>>0;if(O!==0)throw new Error("Non-zero carry");w=k,x++}if(g[x]!==" "){for(var $=C-w;$!==C&&S[$]===0;)$++;for(var V=new Uint8Array(p+(C-$)),ft=p;$!==C;)V[ft++]=S[$++];return V}}}function m(g){var x=l(g);if(x)return x;throw new Error(`Non-${t} character`)}return{encode:f,decodeUnsafe:l,decode:m}}var xs=bs,Es=xs,kn=Es;var rr=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")}},nr=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 Fn(this,t)}},or=class{decoders;constructor(t){this.decoders=t}or(t){return Fn(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 Fn(r,t){return new or({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var sr=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 rr(t,e,n),this.decoder=new nr(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function vt({name:r,prefix:t,encode:e,decode:n}){return new sr(r,t,e,n)}function it({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=kn(e,r);return vt({prefix:t,name:r,encode:n,decode:s=>tt(o(s))})}function vs(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,a=0,c=0;for(let h=0;h<o;++h){let u=t[r[h]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|u,i+=e,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function _s(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)!==0;)s+="=";return s}function Cs(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function A({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=Cs(n);return vt({prefix:t,name:r,encode(s){return _s(s,n,e)},decode(s){return vs(s,o,e,r)}})}var Is=it({prefix:"9",name:"base10",alphabet:"0123456789"});var ar={};M(ar,{base16:()=>Ss,base16upper:()=>As});var Ss=A({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),As=A({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var cr={};M(cr,{base2:()=>Ps});var Ps=A({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var lr={};M(lr,{base256emoji:()=>Ls});var Ln=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}"),Ds=Ln.reduce((r,t,e)=>(r[e]=t,r),[]),Ts=Ln.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function ks(r){return r.reduce((t,e)=>(t+=Ds[e],t),"")}function Fs(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=Ts[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var Ls=vt({prefix:"\u{1F680}",name:"base256emoji",encode:ks,decode:Fs});var ur={};M(ur,{base32:()=>q,base32hex:()=>Us,base32hexpad:()=>Ms,base32hexpadupper:()=>Bs,base32hexupper:()=>Rs,base32pad:()=>Os,base32padupper:()=>$s,base32upper:()=>Ns,base32z:()=>zs});var q=A({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ns=A({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Os=A({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),$s=A({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Us=A({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Rs=A({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ms=A({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Bs=A({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),zs=A({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var fr={};M(fr,{base36:()=>Bt,base36upper:()=>Vs});var Bt=it({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Vs=it({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var hr={};M(hr,{base58btc:()=>z,base58flickr:()=>qs});var z=it({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),qs=it({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var pr={};M(pr,{base64:()=>dt,base64pad:()=>js,base64url:()=>dr,base64urlpad:()=>Ws});var dt=A({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),js=A({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),dr=A({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Ws=A({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var mr={};M(mr,{base8:()=>Hs});var Hs=A({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var gr={};M(gr,{identity:()=>Ks});var Ks=vt({prefix:"\0",name:"identity",encode:r=>Dn(r),decode:r=>Pn(r)});var Hc=new TextEncoder,Kc=new TextDecoder;var xr={};M(xr,{identity:()=>br});var Qs=Un,On=128,Xs=127,Js=~Xs,Ys=Math.pow(2,31);function Un(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Ys;)t[e++]=r&255|On,r/=128;for(;r&Js;)t[e++]=r&255|On,r>>>=7;return t[e]=r|0,Un.bytes=e-n+1,t}var Zs=yr,ti=128,$n=127;function yr(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw yr.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&$n)<<o:(i&$n)*Math.pow(2,o),o+=7}while(i>=ti);return yr.bytes=s-n,e}var ei=Math.pow(2,7),ri=Math.pow(2,14),ni=Math.pow(2,21),oi=Math.pow(2,28),si=Math.pow(2,35),ii=Math.pow(2,42),ai=Math.pow(2,49),ci=Math.pow(2,56),li=Math.pow(2,63),ui=function(r){return r<ei?1:r<ri?2:r<ni?3:r<oi?4:r<si?5:r<ii?6:r<ai?7:r<ci?8:r<li?9:10},fi={encode:Qs,decode:Zs,encodingLength:ui},hi=fi,zt=hi;function Vt(r,t=0){return[zt.decode(r,t),zt.decode.bytes]}function _t(r,t,e=0){return zt.encode(r,t,e),t}function Ct(r){return zt.encodingLength(r)}function St(r,t){let e=t.byteLength,n=Ct(r),o=n+Ct(e),s=new Uint8Array(o+e);return _t(r,s,0),_t(e,s,n),s.set(t,o),new It(r,e,t,s)}function wr(r){let t=tt(r),[e,n]=Vt(t),[o,s]=Vt(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new It(e,o,i,t)}function Rn(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&An(r.bytes,e.bytes)}}var It=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=ht(n),this.bytes=ht(o)}};var Mn=0,di="identity",Bn=tt;function pi(r,t){if(t?.truncate!=null&&t.truncate!==r.byteLength){if(t.truncate<0||t.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t.truncate)}return St(Mn,Bn(r))}var br={code:Mn,name:di,encode:Bn,digest:pi};var _r={};M(_r,{sha256:()=>gi,sha512:()=>yi});var mi=20;function vr({name:r,code:t,encode:e,minDigestLength:n,maxDigestLength:o}){return new Er(r,t,e,n,o)}var Er=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,e,n,o,s){this.name=t,this.code=e,this.encode=n,this.minDigestLength=o??mi,this.maxDigestLength=s}digest(t,e){if(e?.truncate!=null){if(e.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&e.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?zn(n,this.code,e?.truncate):n.then(o=>zn(o,this.code,e?.truncate))}else throw Error("Unknown type, must be binary type")}};function zn(r,t,e){if(e!=null&&e!==r.byteLength){if(e>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e)}return St(t,r)}function qn(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var gi=vr({name:"sha2-256",code:18,encode:qn("SHA-256")}),yi=vr({name:"sha2-512",code:19,encode:qn("SHA-512")});function jn(r,t){let{bytes:e,version:n}=r;return n===0?bi(e,Cr(r),t??z.encoder):xi(e,Cr(r),t??q.encoder)}var Wn=new WeakMap;function Cr(r){let t=Wn.get(r);if(t==null){let e=new Map;return Wn.set(r,e),e}return t}var j=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,this.version=t,this.multihash=n,this.bytes=ht(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:t,multihash:e}=this;if(t!==qt)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Ei)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=St(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&&Rn(t.multihash,n.multihash)}toString(t){return jn(this,t)}toJSON(){return{"/":jn(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??Hn(n,o,s.bytes))}else if(e[vi]===!0){let{version:n,multihash:o,code:s}=e,i=wr(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!==qt)throw new Error(`Version 0 CID must use dag-pb (code: ${qt}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=Hn(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,qt,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=tt(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 It(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[f,l]=Vt(t.subarray(e));return e+=l,f},o=n(),s=qt;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(),h=e+c,u=h-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:u,size:h}}static parse(t,e){let[n,o]=wi(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 Cr(s).set(n,t),s}};function wi(r,t){switch(r[0]){case"Q":{let e=t??z;return[z.prefix,e.decode(`${z.prefix}${r}`)]}case z.prefix:{let e=t??z;return[z.prefix,e.decode(r)]}case q.prefix:{let e=t??q;return[q.prefix,e.decode(r)]}case Bt.prefix:{let e=t??Bt;return[Bt.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 bi(r,t,e){let{prefix:n}=e;if(n!==z.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 xi(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 qt=112,Ei=18;function Hn(r,t,e){let n=Ct(r),o=n+Ct(t),s=new Uint8Array(o+e.byteLength);return _t(r,s,0),_t(t,s,n),s.set(e,o),s}var vi=Symbol.for("@ipld/js-cid/CID");var jt={...gr,...cr,...mr,...ir,...ar,...ur,...fr,...hr,...pr,...lr},ml={..._r,...xr};function Gn(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Kn=Gn("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Ir=Gn("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=J(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),_i={utf8:Kn,"utf-8":Kn,hex:jt.base16,latin1:Ir,ascii:Ir,binary:Ir,...jt},ue=_i;function P(r,t="utf8"){let e=ue[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function W(r,t="utf8"){let e=ue[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var et="/",Qn=new TextEncoder().encode(et),fe=Qn[0],at=class r{_buf;constructor(t,e){if(typeof t=="string")this._buf=P(t);else if(t instanceof Uint8Array)this._buf=t;else throw new Error("Invalid key, should be String of Uint8Array");if(e==null&&(e=!0),e&&this.clean(),this._buf.byteLength===0||this._buf[0]!==fe)throw new Error("Invalid key")}toString(t="utf8"){return W(this._buf,t)}uint8Array(){return this._buf}get[Symbol.toStringTag](){return`Key(${this.toString()})`}static withNamespaces(t){return new r(t.join(et))}static random(){return new r(Math.random().toString().substring(2))}static asKey(t){return t instanceof Uint8Array||typeof t=="string"?new r(t):typeof t.uint8Array=="function"?new r(t.uint8Array()):null}clean(){if((this._buf==null||this._buf.byteLength===0)&&(this._buf=Qn),this._buf[0]!==fe){let t=new Uint8Array(this._buf.byteLength+1);t.fill(fe,0,1),t.set(this._buf,1),this._buf=t}for(;this._buf.byteLength>1&&this._buf[this._buf.byteLength-1]===fe;)this._buf=this._buf.subarray(0,-1)}less(t){let e=this.list(),n=t.list();for(let o=0;o<e.length;o++){if(n.length<o+1)return!1;let s=e[o],i=n[o];if(s<i)return!0;if(s>i)return!1}return e.length<n.length}reverse(){return r.withNamespaces(this.list().slice().reverse())}namespaces(){return this.list()}baseNamespace(){let t=this.namespaces();return t[t.length-1]}list(){return this.toString().split(et).slice(1)}type(){return Ci(this.baseNamespace())}name(){return Ii(this.baseNamespace())}instance(t){return new r(this.toString()+":"+t)}path(){let t=this.parent().toString();return t.endsWith(et)||(t+=et),t+=this.type(),new r(t)}parent(){let t=this.list();return t.length===1?new r(et):new r(t.slice(0,-1).join(et))}child(t){return this.toString()===et?t:t.toString()===et?this:new r(this.toString()+t.toString(),!1)}isAncestorOf(t){return t.toString()===this.toString()?!1:t.toString().startsWith(this.toString())}isDecendantOf(t){return t.toString()===this.toString()?!1:this.toString().startsWith(t.toString())}isTopLevel(){return this.list().length===1}concat(...t){return r.withNamespaces([...this.namespaces(),...Si(t.map(e=>e.namespaces()))])}};function Ci(r){let t=r.split(":");return t.length<2?"":t.slice(0,-1).join(":")}function Ii(r){let t=r.split(":");return t[t.length-1]}function Si(r){return[].concat(...r)}function Ai(r){return r?.buffer instanceof ArrayBuffer}function Sr(r){if(Ai(r))return r;let t=r.slice();return new Uint8Array(t.buffer,0,t.byteLength)}function rt(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=J(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return Sr(e)}function pt(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 Jn=Symbol.for("@achingbrain/uint8arraylist");function Xn(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function he(r){return!!r?.[Jn]}var de=class r{bufs;length;[Jn]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(he(n)){e+=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+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(he(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=Xn(this.bufs,t);return e.buf[e.index]}set(t,e){let n=Xn(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(he(t))for(let n=0;n<t.length;n++)this.set(e+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,e){let{bufs:n,length:o}=this._subList(t,e);return rt(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:rt(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=n,s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===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],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let h=t>=a&&t<c,u=e>a&&e<=c;if(h&&u){if(t===a&&e===c){n.push(i);break}let f=t-a;n.push(i.subarray(f,f+(e-t)));break}if(h){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(u){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!he(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;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 f=0;f<s;f++)i[f]=-1;for(let f=0;f<o;f++)i[n[f]]=f;let a=i,c=this.byteLength-n.byteLength,h=n.byteLength-1,u;for(let f=e;f<=c;f+=u){u=0;for(let l=h;l>=0;l--){let m=this.get(f+l);if(n[l]!==m){u=Math.max(1,l-a[m]);break}}if(u===0)return f}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=J(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=B(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=B(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=B(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=J(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=B(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=B(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=B(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=B(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=B(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!pt(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};var H=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var pe=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}};function Pi(r){return typeof r?.handleEvent=="function"}function Di(r){return(r!==!0&&r!==!1&&r?.once)??!1}var Pt=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){let o=Di(n);super.addEventListener(t,i=>{if(o){let a=this.#t.get(i.type);a!=null&&(a=a.filter(({callback:c})=>c!==e),this.#t.set(i.type,a))}Pi(e)?e.handleEvent(i):e(i)},n);let s=this.#t.get(t);s==null&&(s=[],this.#t.set(t,s)),s.push({callback:e,once:o})}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))}safeDispatchEvent(t,e={}){return this.dispatchEvent(new CustomEvent(t,e))}};var U=class extends Event{type;detail;constructor(t,e){super(t),this.type=t,this.detail=e}};var Ar=class r extends Error{name="TimeoutError";constructor(t,e){super(t,e),Error.captureStackTrace?.(this,r)}},Yn=r=>r.reason??new DOMException("This operation was aborted.","AbortError");function Pr(r,t){let{milliseconds:e,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=t,a,c,u=new Promise((f,l)=>{if(typeof e!="number"||Math.sign(e)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${e}\``);if(i?.aborted){l(Yn(i));return}if(i&&(c=()=>{l(Yn(i))},i.addEventListener("abort",c,{once:!0})),r.then(f,l),e===Number.POSITIVE_INFINITY)return;let m=new Ar;a=s.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(g){l(g)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?f():o instanceof Error?l(o):(m.message=o??`Promise timed out after ${e} milliseconds`,l(m))},e)}).finally(()=>{u.clear(),c&&i&&i.removeEventListener("abort",c)});return u.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},u}var Fi=Sn(to(),1);var Dt;(function(r){r[r.A=1]="A",r[r.CNAME=5]="CNAME",r[r.TXT=16]="TXT",r[r.AAAA=28]="AAAA"})(Dt||(Dt={}));function me(r,t){if(typeof r=="string")return Li(r);if(typeof r=="number")return $i(r,t);throw new Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(r)}`)}function Li(r){if(typeof r!="string"||r.length===0||r.length>100)throw new Error(`Value provided to ms.parse() must be a string with length between 1 and 99. value=${JSON.stringify(r)}`);let t=/^(?<value>-?\d*\.?\d+) *(?<unit>milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.exec(r);if(!t?.groups)return NaN;let{value:e,unit:n="ms"}=t.groups,o=parseFloat(e),s=n.toLowerCase();switch(s){case"years":case"year":case"yrs":case"yr":case"y":return o*315576e5;case"months":case"month":case"mo":return o*26298e5;case"weeks":case"week":case"w":return o*6048e5;case"days":case"day":case"d":return o*864e5;case"hours":case"hour":case"hrs":case"hr":case"h":return o*36e5;case"minutes":case"minute":case"mins":case"min":case"m":return o*6e4;case"seconds":case"second":case"secs":case"sec":case"s":return o*1e3;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return o;default:throw new Error(`Unknown unit "${s}" provided to ms.parse(). value=${JSON.stringify(r)}`)}}function Ni(r){let t=Math.abs(r);return t>=315576e5?`${Math.round(r/315576e5)}y`:t>=26298e5?`${Math.round(r/26298e5)}mo`:t>=6048e5?`${Math.round(r/6048e5)}w`:t>=864e5?`${Math.round(r/864e5)}d`:t>=36e5?`${Math.round(r/36e5)}h`:t>=6e4?`${Math.round(r/6e4)}m`:t>=1e3?`${Math.round(r/1e3)}s`:`${r}ms`}function Oi(r){let t=Math.abs(r);return t>=315576e5?mt(r,t,315576e5,"year"):t>=26298e5?mt(r,t,26298e5,"month"):t>=6048e5?mt(r,t,6048e5,"week"):t>=864e5?mt(r,t,864e5,"day"):t>=36e5?mt(r,t,36e5,"hour"):t>=6e4?mt(r,t,6e4,"minute"):t>=1e3?mt(r,t,1e3,"second"):`${r} ms`}function $i(r,t){if(typeof r!="number"||!Number.isFinite(r))throw new Error("Value provided to ms.format() must be of type number.");return t?.long?Oi(r):Ni(r)}function mt(r,t,e,n){let o=t>=e*1.5;return`${Math.round(r/e)} ${n}${o?"s":""}`}function Dr(r){e.debug=e,e.default=e,e.coerce=c,e.disable=s,e.enable=o,e.enabled=i,e.humanize=me,e.destroy=h,Object.keys(r).forEach(u=>{e[u]=r[u]}),e.names=[],e.skips=[],e.formatters={};function t(u){let f=0;for(let l=0;l<u.length;l++)f=(f<<5)-f+u.charCodeAt(l),f|=0;return e.colors[Math.abs(f)%e.colors.length]}e.selectColor=t;function e(u,f){let l,m=null,g,x;function p(...w){if(!p.enabled)return;let C=p,S=Number(new Date),O=S-(l||S);C.diff=O,C.prev=l,C.curr=S,l=S,w[0]=e.coerce(w[0]),typeof w[0]!="string"&&w.unshift("%O");let k=0;w[0]=w[0].replace(/%([a-zA-Z%])/g,($,V)=>{if($==="%%")return"%";k++;let ft=e.formatters[V];if(typeof ft=="function"){let os=w[k];$=ft.call(C,os),w.splice(k,1),k--}return $}),e.formatArgs.call(C,w),f?.onLog!=null&&f.onLog(...w),(C.log||e.log).apply(C,w)}return p.namespace=u,p.useColors=e.useColors(),p.color=e.selectColor(u),p.extend=n,p.destroy=e.destroy,Object.defineProperty(p,"enabled",{enumerable:!0,configurable:!1,get:()=>m!==null?m:(g!==e.namespaces&&(g=e.namespaces,x=e.enabled(u)),x),set:w=>{m=w}}),typeof e.init=="function"&&e.init(p),p}function n(u,f){let l=e(this.namespace+(typeof f>"u"?":":f)+u);return l.log=this.log,l}function o(u){e.save(u),e.namespaces=u,e.names=[],e.skips=[];let f,l=(typeof u=="string"?u:"").split(/[\s,]+/),m=l.length;for(f=0;f<m;f++)l[f]&&(u=l[f].replace(/\*/g,".*?"),u[0]==="-"?e.skips.push(new RegExp("^"+u.substr(1)+"$")):e.names.push(new RegExp("^"+u+"$")))}function s(){let u=[...e.names.map(a),...e.skips.map(a).map(f=>"-"+f)].join(",");return e.enable(""),u}function i(u){if(u[u.length-1]==="*")return!0;let f,l;for(f=0,l=e.skips.length;f<l;f++)if(e.skips[f].test(u))return!1;for(f=0,l=e.names.length;f<l;f++)if(e.names[f].test(u))return!0;return!1}function a(u){return u.toString().substring(2,u.toString().length-2).replace(/\.\*\?$/,"*")}function c(u){return u instanceof Error?u.stack??u.message:u}function h(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return e.setupFormatters(e.formatters),e.enable(e.load()),e}var ge=qi(),Ui=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function Ri(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/(edge|trident)\/(\d+)/)!=null?!1:typeof document<"u"&&document.documentElement?.style?.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/firefox\/(\d+)/)!=null&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent?.toLowerCase().match(/applewebkit\/(\d+)/)}function Mi(r){if(r[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+r[0]+(this.useColors?"%c ":" ")+"+"+me(this.diff),!this.useColors)return;let t="color: "+this.color;r.splice(1,0,t,"color: inherit");let e=0,n=0;r[0].replace(/%[a-zA-Z%]/g,o=>{o!=="%%"&&(e++,o==="%c"&&(n=e))}),r.splice(n,0,t)}var Bi=console.debug??console.log??(()=>{});function zi(r){try{r?ge?.setItem("debug",r):ge?.removeItem("debug")}catch{}}function Vi(){let r;try{r=ge?.getItem("debug")}catch{}return!r&&typeof globalThis.process<"u"&&"env"in globalThis.process&&(r=globalThis.process.env.DEBUG),r}function qi(){try{return localStorage}catch{}}function ji(r){r.j=function(t){try{return JSON.stringify(t)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}}var eo=Dr({formatArgs:Mi,save:zi,load:Vi,useColors:Ri,setupFormatters:ji,colors:Ui,storage:ge,log:Bi});var R=eo;R.formatters.b=r=>r==null?"undefined":z.baseEncode(r);R.formatters.t=r=>r==null?"undefined":q.baseEncode(r);R.formatters.m=r=>r==null?"undefined":dt.baseEncode(r);R.formatters.p=r=>r==null?"undefined":r.toString();R.formatters.c=r=>r==null?"undefined":r.toString();R.formatters.k=r=>r==null?"undefined":r.toString();R.formatters.a=r=>r==null?"undefined":r.toString();function ro(r,t=""){let e=no(r.message),n=no(r.stack);return e!=null&&n!=null?n.includes(e)?`${n.split(`
|
|
3
|
+
`).join(`
|
|
4
|
+
${t}`)}`:`${e}
|
|
5
|
+
${t}${n.split(`
|
|
6
|
+
`).join(`
|
|
7
|
+
${t}`)}`:n!=null?`${n.split(`
|
|
8
|
+
`).join(`
|
|
9
|
+
${t}`)}`:e!=null?`${e}`:`${r.toString()}`}function Hi(r){return r instanceof AggregateError||r?.name==="AggregateError"&&Array.isArray(r.errors)}function oo(r,t=""){if(Hi(r)){let e=ro(r,t);return r.errors.length>0?(t=`${t} `,e+=`
|
|
10
|
+
${t}${r.errors.map(n=>`${oo(n,`${t}`)}`).join(`
|
|
11
|
+
${t}`)}`):e+=`
|
|
12
|
+
${t}[Error list was empty]`,e.trim()}return ro(r,t)}R.formatters.e=r=>r==null?"undefined":oo(r);function Ki(r){let t=()=>{};return t.enabled=!1,t.color="",t.diff=0,t.log=()=>{},t.namespace=r,t.destroy=()=>!0,t.extend=()=>t,t.useColors=()=>!1,t}function Ht(r,t){let e=Ki(`${r}:trace`);return R.enabled(`${r}:trace`)&&R.names.map(n=>n.toString()).find(n=>n.includes(":trace"))!=null&&(e=R(`${r}:trace`,t)),Object.assign(R(r,t),{error:R(`${r}:error`,t),trace:e,newScope:n=>Ht(`${r}:${n}`,t)})}function no(r){if(r!=null&&(r=r.trim(),r.length!==0))return r}function nt(){let r={};return r.promise=new Promise((t,e)=>{r.resolve=t,r.reject=e}),r}function Qi(r){return r.reason}async function Kt(r,t,e){if(t==null)return r;let n=e?.translateError??Qi;if(t.aborted)return r.catch(()=>{}),Promise.reject(n(t));let o;try{return await Promise.race([r,new Promise((s,i)=>{o=()=>{i(n(t))},t.addEventListener("abort",o)})])}finally{o!=null&&t.removeEventListener("abort",o)}}var af=Ht("blockstore:core:tiered");var ao="SHARDING";var ye=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)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}},Tt=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new ye(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 ye(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 kr=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function Fr(r={}){return ea(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 ea(r,t){t=t??{};let e=t.onEnd,n=new Tt,o,s,i,a=nt(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((p,w)=>{s=C=>{s=null,n.push(C);try{p(r(n))}catch(S){w(S)}return o}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=nt()})}},h=p=>s!=null?s(p):(n.push(p),o),u=p=>(n=new Tt,s!=null?s({error:p}):(n.push({error:p}),o)),f=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 h({done:!1,value:p})},l=p=>i?o:(i=!0,p!=null?u(p):h({done:!0})),m=()=>(n=new Tt,l(),{done:!0}),g=p=>(l(p),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:m,throw:g,push:f,end:l,get readableLength(){return n.size},onEmpty:async p=>{let w=p?.signal;if(w?.throwIfAborted(),n.isEmpty())return;let C,S;w!=null&&(C=new Promise((O,k)=>{S=()=>{k(new kr)},w.addEventListener("abort",S)}));try{await Promise.race([a.promise,C])}finally{S!=null&&w!=null&&w?.removeEventListener("abort",S)}}},e==null)return o;let x=o;return o={[Symbol.asyncIterator](){return this},next(){return x.next()},throw(p){return x.throw(p),e!=null&&(e(p),e=void 0),{done:!0}},return(){return x.return(),e!=null&&(e(),e=void 0),{done:!0}},push:f,end(p){return x.end(p),e!=null&&(e(p),e=void 0),o},get readableLength(){return x.readableLength},onEmpty:p=>x.onEmpty(p)},o}var Zf=new at(ao);var dh=Ht("datastore:core:tiered");var Lr={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},lo={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},uo=new globalThis.TextEncoder;function oa(r,t){let e=Lr[t],n=lo[t];for(let o=0;o<r.length;o++)n^=BigInt(r[o]),n=BigInt.asUintN(t,n*e);return n}function sa(r,t,e){if(e.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=Lr[t],o=lo[t],s=r;for(;s.length>0;){let i=uo.encodeInto(s,e);s=s.slice(i.read);for(let a=0;a<i.written;a++)o^=BigInt(e[a]),o=BigInt.asUintN(t,o*n)}return o}function Nr(r,{size:t=32,utf8Buffer:e}={}){if(!Lr[t])throw new Error("The `size` option must be one of 32, 64, 128, 256, 512, or 1024");if(typeof r=="string"){if(e)return sa(r,t,e);r=uo.encode(r)}return oa(r,t)}var Qt={hash:r=>Number(Nr(r,{size:32})),hashV:(r,t)=>ia(Qt.hash(r,t))};function ia(r){let t=r.toString(16);return t.length%2===1&&(t=`0${t}`),P(t,"base16")}var Or=64,K=class{fp;h;seed;constructor(t,e,n,o=2){if(o>Or)throw new TypeError("Invalid Fingerprint Size");let s=e.hashV(t,n),i=B(o);for(let a=0;a<i.length;a++)i[a]=s[a];i.length===0&&(i[0]=7),this.fp=i,this.h=e,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(t){return t?.fp instanceof Uint8Array?pt(this.fp,t.fp):!1}};function gt(r,t){return Math.floor(Math.random()*(t-r))+r}var yt=class{contents;constructor(t){this.contents=new Array(t).fill(null)}has(t){if(!(t instanceof K))throw new TypeError("Invalid Fingerprint");return this.contents.some(e=>t.equals(e))}add(t){if(!(t instanceof K))throw new TypeError("Invalid Fingerprint");for(let e=0;e<this.contents.length;e++)if(this.contents[e]==null)return this.contents[e]=t,!0;return!0}swap(t){if(!(t instanceof K))throw new TypeError("Invalid Fingerprint");let e=gt(0,this.contents.length-1),n=this.contents[e];return this.contents[e]=t,n}remove(t){if(!(t instanceof K))throw new TypeError("Invalid Fingerprint");let e=this.contents.findIndex(n=>t.equals(n));return e>-1?(this.contents[e]=null,!0):!1}};var aa=500,Xt=class{bucketSize;filterSize;fingerprintSize;buckets;count;hash;seed;constructor(t){this.filterSize=t.filterSize,this.bucketSize=t.bucketSize??4,this.fingerprintSize=t.fingerprintSize??2,this.count=0,this.buckets=[],this.hash=t.hash??Qt,this.seed=t.seed??gt(0,Math.pow(2,10))}add(t){typeof t=="string"&&(t=P(t));let e=new K(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=(n^e.hash())%this.filterSize;if(this.buckets[n]==null&&(this.buckets[n]=new yt(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new yt(this.bucketSize)),this.buckets[n].add(e)||this.buckets[o].add(e))return this.count++,!0;let s=[n,o],i=s[gt(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new yt(this.bucketSize));for(let a=0;a<aa;a++){let c=this.buckets[i].swap(e);if(c!=null&&(i=(i^c.hash())%this.filterSize,this.buckets[i]==null&&(this.buckets[i]=new yt(this.bucketSize)),this.buckets[i].add(c)))return this.count++,!0}return!1}has(t){typeof t=="string"&&(t=P(t));let e=new K(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=this.buckets[n]?.has(e)??!1;if(o)return o;let s=(n^e.hash())%this.filterSize;return this.buckets[s]?.has(e)??!1}remove(t){typeof t=="string"&&(t=P(t));let e=new K(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=this.buckets[n]?.remove(e)??!1;if(o)return this.count--,o;let s=(n^e.hash())%this.filterSize,i=this.buckets[s]?.remove(e)??!1;return i&&this.count--,i}get reliable(){return Math.floor(100*(this.count/this.filterSize))<=90}},ca={1:.5,2:.84,4:.95,8:.98};function la(r=.001){return r>.002?2:r>1e-5?4:8}function fo(r,t=.001){let e=la(t),n=ca[e],o=Math.round(r/n),s=Math.min(Math.ceil(Math.log2(1/t)+Math.log2(2*e)),Or);return{filterSize:o,bucketSize:e,fingerprintSize:s}}var we=class{filterSize;bucketSize;fingerprintSize;scale;filterSeries;hash;seed;constructor(t){this.bucketSize=t.bucketSize??4,this.filterSize=t.filterSize??(1<<18)/this.bucketSize,this.fingerprintSize=t.fingerprintSize??2,this.scale=t.scale??2,this.hash=t.hash??Qt,this.seed=t.seed??gt(0,Math.pow(2,10)),this.filterSeries=[new Xt({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(t){if(typeof t=="string"&&(t=P(t)),this.has(t))return!0;let e=this.filterSeries.find(n=>n.reliable);if(e==null){let n=this.filterSize*Math.pow(this.scale,this.filterSeries.length);e=new Xt({filterSize:n,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed}),this.filterSeries.push(e)}return e.add(t)}has(t){typeof t=="string"&&(t=P(t));for(let e=0;e<this.filterSeries.length;e++)if(this.filterSeries[e].has(t))return!0;return!1}remove(t){typeof t=="string"&&(t=P(t));for(let e=0;e<this.filterSeries.length;e++)if(this.filterSeries[e].remove(t))return!0;return!1}get count(){return this.filterSeries.reduce((t,e)=>t+e.count,0)}};function be(r,t=.001,e){return new we({...fo(r,t),...e??{}})}function ua(r){let t=r.getComponents(),e={},n=0;return t[n]?.name==="ip6zone"&&(e.zone=`${t[n].value}`,n++),t[n]?.name==="ip4"||t[n]?.name==="ip6"||t[n]?.name==="dns"||t[n]?.name==="dns4"||t[n]?.name==="dns6"?(e.type=t[n].name,e.host=t[n].value,n++):t[n]?.name==="dnsaddr"&&(e.type=t[n].name,e.host=`_dnsaddr.${t[n].value}`,n++),(t[n]?.name==="tcp"||t[n]?.name==="udp")&&(e.protocol=t[n].name==="tcp"?"tcp":"udp",e.port=parseInt(`${t[n].value}`),n++),t[n]?.name==="ipcidr"&&(e.type==="ip4"?e.cidr=parseInt(`${t[n].value}`):e.type==="ip6"&&(e.cidr=`${t[n].value}`),n++),e.type==null||e.host==null?null:(t[n]?.name==="tls"&&t[n+1]?.name==="sni"&&(e.sni=t[n+1].value,n+=2),e)}function xe(r){let t=ua(r);if(t==null)throw new pe(`Multiaddr ${r} was not an IPv4, IPv6, DNS, DNS4, DNS6 or DNSADDR address`);return t}var Ee=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",h=2**(8*o)-1;for(;;){let u=this.readAtomically(()=>{let f=this.readChar();if(f===void 0)return;let l=Number.parseInt(f,t);if(!Number.isNaN(l))return l});if(u===void 0)break;if(s*=t,s+=u,s>h||(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 fa=45,ha=15,ve=new Ee;function ho(r){if(!(r.length>ha))return ve.new(r).parseWith(()=>ve.readIPv4Addr())}function po(r){if(r.includes("%")&&(r=r.split("%")[0]),!(r.length>fa))return ve.new(r).parseWith(()=>ve.readIPv6Addr())}function kt(r){return!!ho(r)}function _e(r){return!!po(r)}var wo=Sn(yo(),1),ba=["0.0.0.0/8","10.0.0.0/8","100.64.0.0/10","127.0.0.0/8","169.254.0.0/16","172.16.0.0/12","192.0.0.0/24","192.0.0.0/29","192.0.0.8/32","192.0.0.9/32","192.0.0.10/32","192.0.0.170/32","192.0.0.171/32","192.0.2.0/24","192.31.196.0/24","192.52.193.0/24","192.88.99.0/24","192.168.0.0/16","192.175.48.0/24","198.18.0.0/15","198.51.100.0/24","203.0.113.0/24","240.0.0.0/4","255.255.255.255/32"],xa=ba.map(r=>new wo.Netmask(r));function Vr(r){for(let t of xa)if(t.contains(r))return!0;return!1}function Ea(r){return/^::ffff:([0-9a-fA-F]{1,4}):([0-9a-fA-F]{1,4})$/.test(r)}function va(r){let t=r.split(":");if(t.length<2)return!1;let e=t[t.length-1].padStart(4,"0"),n=t[t.length-2].padStart(4,"0"),o=`${parseInt(n.substring(0,2),16)}.${parseInt(n.substring(2),16)}.${parseInt(e.substring(0,2),16)}.${parseInt(e.substring(2),16)}`;return Vr(o)}function _a(r){return/^::ffff:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)}function Ca(r){let t=r.split(":"),e=t[t.length-1];return Vr(e)}function Ia(r){return/^::$/.test(r)||/^::1$/.test(r)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(r)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(r)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(r)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(r)||/^ff([0-9a-fA-F]{2,2}):/i.test(r)}function bo(r){if(kt(r))return Vr(r);if(Ea(r))return va(r);if(_a(r))return Ca(r);if(_e(r))return Ia(r)}function xo(r){try{let t=xe(r);switch(t.type){case"ip4":case"ip6":return bo(t.host)??!1;default:return t.host==="localhost"}}catch{return!1}}var F=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},ot=class extends Error{static name="ValidationError";name="ValidationError"},Ie=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Se=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function jr(r){return t=>W(t,r)}function Wr(r){return t=>P(t,r)}function Ot(r){return new DataView(r.buffer).getUint16(r.byteOffset).toString()}function bt(r){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof r=="string"?parseInt(r):r),new Uint8Array(t)}function Eo(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=P(t[0],"base32"),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=bt(n);return rt([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=q.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=bt(n);return rt([e,o],e.length+o.length)}function Hr(r){let t=r.subarray(0,r.length-2),e=r.subarray(r.length-2),n=W(t,"base32"),o=Ot(e);return`${n}:${o}`}var Kr=function(r){r=r.toString().trim();let t=new Uint8Array(4);return r.split(/\./g).forEach((e,n)=>{let o=parseInt(e,10);if(isNaN(o)||o<0||o>255)throw new F("Invalid byte value in IP address");t[n]=o}),t},_o=function(r){let t=0;r=r.toString().trim();let e=r.split(":",8),n;for(n=0;n<e.length;n++){let s=kt(e[n]),i;s&&(i=Kr(e[n]),e[n]=W(i.subarray(0,2),"base16")),i!=null&&++n<8&&e.splice(n,0,W(i.subarray(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++){e[n]===""&&(e[n]="0");let s=parseInt(e[n],16);if(isNaN(s)||s<0||s>65535)throw new F("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},Co=function(r){if(r.byteLength!==4)throw new F("IPv4 address was incorrect length");let t=[];for(let e=0;e<r.byteLength;e++)t.push(r[e]);return t.join(".")},Io=function(r){if(r.byteLength!==16)throw new F("IPv6 address was incorrect length");let t=[];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")}`;t.push(i)}let e=t.join(":");try{let n=new URL(`http://[${e}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new F(`Invalid IPv6 address "${e}"`)}};function So(r){try{let t=new URL(`http://[${r}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new F(`Invalid IPv6 address "${r}"`)}}var qr=Object.values(jt).map(r=>r.decoder),Sa=(function(){let r=qr[0].or(qr[1]);return qr.slice(2).forEach(t=>r=r.or(t)),r})();function Ao(r){return Sa.decode(r)}function Po(r){return t=>r.encoder.encode(t)}function Aa(r){if(parseInt(r).toString()!==r)throw new ot("Value must be an integer")}function Pa(r){if(r<0)throw new ot("Value must be a positive integer, or zero")}function Da(r){return t=>{if(t>r)throw new ot(`Value must be smaller than or equal to ${r}`)}}function Ta(...r){return t=>{for(let e of r)e(t)}}var Jt=Ta(Aa,Pa,Da(65535));var T=-1,Gr=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(t){let e;if(typeof t=="string"?e=this.protocolsByName.get(t):e=this.protocolsByCode.get(t),e==null)throw new Se(`Protocol ${t} was unknown`);return e}addProtocol(t){this.protocolsByCode.set(t.code,t),this.protocolsByName.set(t.name,t),t.aliases?.forEach(e=>{this.protocolsByName.set(e,t)})}removeProtocol(t){let e=this.protocolsByCode.get(t);e!=null&&(this.protocolsByCode.delete(e.code),this.protocolsByName.delete(e.name),e.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},st=new Gr,ja=[{code:4,name:"ip4",size:32,valueToBytes:Kr,bytesToValue:Co,validate:r=>{if(!kt(r))throw new ot(`Invalid IPv4 address "${r}"`)}},{code:6,name:"tcp",size:16,valueToBytes:bt,bytesToValue:Ot,validate:Jt},{code:273,name:"udp",size:16,valueToBytes:bt,bytesToValue:Ot,validate:Jt},{code:33,name:"dccp",size:16,valueToBytes:bt,bytesToValue:Ot,validate:Jt},{code:41,name:"ip6",size:128,valueToBytes:_o,bytesToValue:Io,stringToValue:So,validate:r=>{if(!_e(r))throw new ot(`Invalid IPv6 address "${r}"`)}},{code:42,name:"ip6zone",size:T},{code:43,name:"ipcidr",size:8,bytesToValue:jr("base10"),valueToBytes:Wr("base10")},{code:53,name:"dns",size:T},{code:54,name:"dns4",size:T},{code:55,name:"dns6",size:T},{code:56,name:"dnsaddr",size:T},{code:132,name:"sctp",size:16,valueToBytes:bt,bytesToValue:Ot,validate:Jt},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:T,stringToValue:r=>decodeURIComponent(r),valueToString:r=>encodeURIComponent(r)},{code:421,name:"p2p",aliases:["ipfs"],size:T,bytesToValue:jr("base58btc"),valueToBytes:r=>r.startsWith("Q")||r.startsWith("1")?Wr("base58btc")(r):j.parse(r).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Hr,valueToBytes:Eo},{code:445,name:"onion3",size:296,bytesToValue:Hr,valueToBytes:vo},{code:446,name:"garlic64",size:T},{code:447,name:"garlic32",size:T},{code:448,name:"tls"},{code:449,name:"sni",size:T},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:T,bytesToValue:Po(dr),valueToBytes:Ao},{code:480,name:"http"},{code:481,name:"http-path",size:T,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:T}];ja.forEach(r=>{st.addProtocol(r)});function Do(r){let t=[],e=0;for(;e<r.length;){let n=tr(r,e),o=st.getProtocol(n),s=Et(n),i=Wa(o,r,e+s),a=0;i>0&&o.size===T&&(a=Et(i));let c=s+a+i,h={code:n,name:o.name,bytes:er(r.subarray(e,e+c))};if(i>0){let u=e+s+a,f=r.subarray(u,u+i);h.value=o.bytesToValue?.(f)??W(f)}t.push(h),e+=c}return t}function To(r){let t=0,e=[];for(let n of r){if(n.bytes==null){let o=st.getProtocol(n.code),s=Et(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??P(n.value),a=i.byteLength,o.size===T&&(c=Et(a)));let h=new Uint8Array(s+c+a),u=0;Ze(n.code,h,u),u+=s,i!=null&&(o.size===T&&(Ze(a,h,u),u+=c),h.set(i,u)),n.bytes=h}e.push(n.bytes),t+=n.bytes.byteLength}return rt(e,t)}function ko(r){if(r.charAt(0)!=="/")throw new F('String multiaddr must start with "/"');let t=[],e="protocol",n="",o="";for(let s=1;s<r.length;s++){let i=r.charAt(s);i!=="/"&&(e==="protocol"?o+=r.charAt(s):n+=r.charAt(s));let a=s===r.length-1;if(i==="/"||a){let c=st.getProtocol(o);if(e==="protocol"){if(c.size==null||c.size===0){t.push({code:c.code,name:c.name}),n="",o="",e="protocol";continue}else if(a)throw new F(`Component ${o} was missing value`);e="value"}else if(e==="value"){let h={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new F(`Component ${o} was missing value`);h.value=c.stringToValue?.(n)??n}t.push(h),n="",o="",e="protocol"}}}if(o!==""&&n!=="")throw new F("Incomplete multiaddr");return t}function Fo(r){return`/${r.flatMap(t=>{if(t.value==null)return t.name;let e=st.getProtocol(t.code);if(e==null)throw new F(`Unknown protocol code ${t.code}`);return[t.name,e.valueToString?.(t.value)??t.value]}).join("/")}`}function Wa(r,t,e){return r.size==null||r.size===0?0:r.size>0?r.size/8:tr(t,e)}var Ha=Symbol.for("nodejs.util.inspect.custom"),an=Symbol.for("@multiformats/multiaddr");function Ka(r){if(r==null&&(r="/"),Lo(r))return r.getComponents();if(r instanceof Uint8Array)return Do(r);if(typeof r=="string")return r=r.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),r===""&&(r="/"),ko(r);if(Array.isArray(r))return r;throw new F("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Fe=class r{[an]=!0;#t;#e;#r;constructor(t="/",e={}){this.#t=Ka(t),e.validate!==!1&&Ga(this)}get bytes(){return this.#r==null&&(this.#r=To(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=Fo(this.#t)),this.#e}toJSON(){return this.toString()}getComponents(){return[...this.#t.map(t=>({...t}))]}encapsulate(t){let e=new r(t);return new r([...this.#t,...e.getComponents()],{validate:!1})}decapsulate(t){let e=t.toString(),n=this.toString(),o=n.lastIndexOf(e);if(o<0)throw new Ie(`Address ${this.toString()} does not contain subaddress: ${e}`);return new r(n.slice(0,o),{validate:!1})}decapsulateCode(t){let e;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===t){e=n;break}return new r(this.#t.slice(0,e),{validate:!1})}equals(t){return pt(this.bytes,t.bytes)}[Ha](){return`Multiaddr(${this.toString()})`}};function Ga(r){r.getComponents().forEach(t=>{let e=st.getProtocol(t.code);t.value!=null&&e.validate?.(t.value)})}function Lo(r){return!!r?.[an]}function Le(r){return new Fe(r)}var v=r=>({match:t=>{let e=t[0];return e==null||e.code!==r||e.value!=null?!1:t.slice(1)}}),d=(r,t)=>({match:e=>{let n=e[0];return n?.code!==r||n.value==null||t!=null&&n.value!==t?!1:e.slice(1)}}),No=r=>({match:t=>r.match(t)===!1?t:!1}),y=r=>({match:t=>{let e=r.match(t);return e===!1?t:e}}),N=(...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}}),b=(...r)=>({match:t=>{for(let e of r){let n=e.match(t);if(n===!1)return!1;t=n}return t}});function _(...r){function t(o){if(o==null)return!1;let s=o.getComponents();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 Qa=d(421),Ep=_(Qa),Oe=d(54),$e=d(55),Ue=d(56),ln=d(53),vp=_(Oe,y(d(421))),_p=_($e,y(d(421))),Cp=_(Ue,y(d(421))),Oo=_(N(ln,Ue,Oe,$e),y(d(421))),$o=b(d(4),y(d(43))),Uo=b(y(d(42)),d(41),y(d(43))),un=N($o,Uo),Rt=N(un,ln,Oe,$e,Ue),Ip=_(N(un,b(N(ln,Ue,Oe,$e),y(d(421))))),Sp=_($o),Ap=_(Uo),Pp=_(un),fn=b(Rt,d(6)),ne=b(Rt,d(273)),Dp=_(b(fn,y(d(421)))),Tp=_(ne),hn=b(ne,v(460),y(d(421))),Re=b(ne,v(461),y(d(421))),Xa=N(hn,Re),kp=_(hn),Fp=_(Re),cn=N(Rt,fn,ne,hn,Re),Ro=N(b(cn,v(477),y(d(421)))),Lp=_(Ro),Mo=N(b(cn,v(478),y(d(421))),b(cn,v(448),y(d(449)),v(477),y(d(421)))),Np=_(Mo),Bo=b(ne,v(280),y(d(466)),y(d(466)),y(d(421))),Op=_(Bo),zo=b(Re,v(465),y(d(466)),y(d(466)),y(d(421))),$p=_(zo),Ne=N(Ro,Mo,b(fn,y(d(421))),b(Xa,y(d(421))),b(Rt,y(d(421))),Bo,zo,d(421)),Up=_(Ne),Ja=b(y(Ne),v(290),No(v(281)),y(d(421))),Rp=_(Ja),Ya=N(b(Ne,v(290),v(281),y(d(421))),b(Ne,v(281),y(d(421))),b(v(281),y(d(421)))),Mp=_(Ya),Za=b(Rt,N(b(d(6,"80")),b(d(6),v(480)),v(480)),y(d(481)),y(d(421))),Vo=_(Za),tc=b(Rt,N(b(d(6,"443")),b(d(6,"443"),v(480)),b(d(6),v(443)),b(d(6),v(448),v(480)),b(v(448),v(480)),v(448),v(443)),y(d(481)),y(d(421))),qo=_(tc),ec=N(b(d(777),y(d(421)))),Bp=_(ec),rc=N(b(d(400),y(d(421)))),zp=_(rc);var nc=r=>{let t=r.addEventListener||r.on||r.addListener,e=r.removeEventListener||r.off||r.removeListener;if(!t||!e)throw new TypeError("Emitter is not compatible");return{addListener:t.bind(r),removeListener:e.bind(r)}};function oc(r,t,e){let n,o=new Promise((s,i)=>{if(e={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...e},!(e.count>=0&&(e.count===Number.POSITIVE_INFINITY||Number.isInteger(e.count))))throw new TypeError("The `count` option should be at least 0 or more");e.signal?.throwIfAborted();let a=[t].flat(),c=[],{addListener:h,removeListener:u}=nc(r),f=async(...m)=>{let g=e.multiArgs?m:m[0];if(e.filter)try{if(!await e.filter(g))return}catch(x){n(),i(x);return}c.push(g),e.count===c.length&&(n(),s(c))},l=(...m)=>{n(),i(e.rejectionMultiArgs?m:m[0])};n=()=>{for(let m of a)u(m,f);for(let m of e.rejectionEvents)a.includes(m)||u(m,l)};for(let m of a)h(m,f);for(let m of e.rejectionEvents)a.includes(m)||h(m,l);e.signal&&e.signal.addEventListener("abort",()=>{l(e.signal.reason)},{once:!0}),e.resolveImmediately&&s(c)});if(o.cancel=n,typeof e.timeout=="number"){let s=Pr(o,{milliseconds:e.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function Me(r,t,e){typeof e=="function"&&(e={filter:e}),e={...e,count:1,resolveImmediately:!1};let n=oc(r,t,e),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function dn(r,t){let e,n=function(){let o=function(){e=void 0,r()};clearTimeout(e),e=setTimeout(o,t)};return n.start=()=>{},n.stop=()=>{clearTimeout(e)},n}var Be=class extends Error{static name="QueueFullError";constructor(t="The queue was full"){super(t),this.name="QueueFullError"}};var ze=class{deferred;signal;onProgress;constructor(t){this.signal=t?.signal,this.onProgress=t?.onProgress,this.deferred=nt(),this.onAbort=this.onAbort.bind(this),this.signal?.addEventListener("abort",this.onAbort)}onAbort(){this.deferred.reject(this.signal?.reason??new H)}cleanup(){this.signal?.removeEventListener("abort",this.onAbort)}};function sc(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var Ve=class{id;fn;options;recipients;status;timeline;controller;dispatchingProgress;constructor(t,e){this.id=sc(),this.status="queued",this.fn=t,this.options=e,this.recipients=[],this.timeline={created:Date.now()},this.controller=new AbortController,this.controller.signal,this.dispatchingProgress=!1,this.onAbort=this.onAbort.bind(this)}abort(t){this.controller.abort(t)}onAbort(){this.recipients.reduce((e,n)=>e&&n.signal?.aborted===!0,!0)&&(this.controller.abort(new H),this.cleanup())}async join(t){let e=new ze(t);return this.recipients.push(e),t?.signal?.addEventListener("abort",this.onAbort),e.deferred.promise}async run(){this.status="running",this.timeline.started=Date.now();try{this.controller.signal.throwIfAborted();let t=await Kt(this.fn({...this.options??{},signal:this.controller.signal,onProgress:e=>{if(!this.dispatchingProgress){this.dispatchingProgress=!0;try{this.recipients.forEach(n=>{n.onProgress?.(e)})}finally{this.dispatchingProgress=!1}}}}),this.controller.signal);this.recipients.forEach(e=>{e.deferred.resolve(t)}),this.status="complete"}catch(t){this.recipients.forEach(e=>{e.deferred.reject(t)}),this.status="errored"}finally{this.timeline.finished=Date.now(),this.cleanup()}}cleanup(){this.recipients.forEach(t=>{t.cleanup(),t.signal?.removeEventListener("abort",this.onAbort)})}};var qe=class extends Pt{concurrency;maxSize;queue;pending;sort;paused;constructor(t={}){super(),this.concurrency=t.concurrency??Number.POSITIVE_INFINITY,this.maxSize=t.maxSize??Number.POSITIVE_INFINITY,this.pending=0,this.paused=!1,t.metricName!=null&&t.metrics?.registerMetricGroup(t.metricName,{calculate:()=>({size:this.queue.length,running:this.pending,queued:this.queue.length-this.pending})}),this.sort=t.sort,this.queue=[],this.emitEmpty=dn(this.emitEmpty.bind(this),1),this.emitIdle=dn(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 t;for(let e of this.queue)if(e.status==="queued"){t=e;break}return t==null?!1:(this.safeDispatchEvent("active"),this.pending++,t.run().finally(()=>{for(let e=0;e<this.queue.length;e++)if(this.queue[e]===t){this.queue.splice(e,1);break}this.pending--,this.tryToStartAnother(),this.safeDispatchEvent("next")}),!0)}return!1}enqueue(t){this.queue.push(t),this.sort!=null&&this.queue.sort(this.sort)}async add(t,e){if(e?.signal?.throwIfAborted(),this.size===this.maxSize)throw new Be;let n=new Ve(t,e);this.enqueue(n),this.safeDispatchEvent("add");let o=n.join(e).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(t=>{t.abort(new H)}),this.clear()}async onEmpty(t){this.size!==0&&await Me(this,"empty",t)}async onSizeLessThan(t,e){this.size<t||await Me(this,"next",{...e,filter:()=>this.size<t})}async onIdle(t){this.pending===0&&this.size===0||await Me(this,"idle",t)}get size(){return this.queue.length}get queued(){return this.queue.length-this.pending}get running(){return this.pending}async*toGenerator(t){t?.signal?.throwIfAborted();let e=Fr({objectMode:!0}),n=c=>{c!=null?this.abort():this.clear(),e.end(c)},o=c=>{c.detail!=null&&e.push(c.detail)},s=c=>{n(c.detail.error)},i=()=>{n()},a=()=>{n(new H("Queue aborted"))};this.addEventListener("completed",o),this.addEventListener("failure",s),this.addEventListener("idle",i),t?.signal?.addEventListener("abort",a);try{yield*e}finally{this.removeEventListener("completed",o),this.removeEventListener("failure",s),this.removeEventListener("idle",i),t?.signal?.removeEventListener("abort",a),n()}}};var je=class extends Error{static name="InsufficientProvidersError";constructor(t="Insufficient providers found"){super(t),this.name="InsufficientProvidersError"}};var oe=class extends Pt{initialPeerSearchComplete;requests;logName;log;logger;minProviders;maxProviders;providers;evictionFilter;initialProviders;cidPeerFilterSize;constructor(t,e){super(),this.logName=e.name,this.logger=t.logger,this.log=t.logger.forComponent(this.logName),this.requests=new Map,this.minProviders=e.minProviders??1,this.maxProviders=e.maxProviders??5,this.cidPeerFilterSize=e.cidPeerFilterSize??100,this.providers=[],this.evictionFilter=be(this.maxProviders),this.initialProviders=[...e.providers??[]]}async retrieve(t,e={}){let n=dt.encode(t.multihash.bytes),o=this.requests.get(n);if(o!=null)return this.log("join existing request for %c",t),o.observers++,o.promise;let s=nt(),i={promise:s.promise,observers:1,queryFilter:be(this.cidPeerFilterSize)};this.requests.set(n,i);let a=!1;this.initialPeerSearchComplete==null&&(a=!0,this.log=this.logger.forComponent(`${this.logName}:${t}`),this.initialPeerSearchComplete=this.findProviders(t,this.minProviders,e));let c=!1,h=new qe({concurrency:this.maxProviders});h.addEventListener("failure",l=>{this.log.error("error querying provider %s, evicting from session - %e",l.detail.job.options.provider,l.detail.error),this.evict(l.detail.job.options.provider)}),h.addEventListener("success",l=>{c=!0,s.resolve(l.detail.result)}),h.addEventListener("idle",()=>{if(c){this.log.trace("session idle, found block");return}if(e.signal?.aborted===!0){this.log.trace("session idle, signal aborted");return}Promise.resolve().then(async()=>{this.log("no session peers had block for for %c, finding new providers",t);for(let l=0;l<this.minProviders&&this.providers.length!==0;l++){let m=this.providers[Math.floor(Math.random()*this.providers.length)];this.evict(m)}await this.findProviders(t,this.minProviders,e),this.log("found new providers re-retrieving %c",t),this.requests.delete(n),s.resolve(await this.retrieve(t,e))}).catch(l=>{this.log.error("could not find new providers for %c - %e",t,l),s.reject(l)})});let u=l=>{let m=this.toFilterKey(l.detail);i.queryFilter.has(m)||(i.queryFilter.add(m),this.emitFoundProviderProgressEvent(t,l.detail,e),h.add(async()=>this.queryProvider(t,l.detail,e),{provider:l.detail}).catch(g=>{e.signal?.aborted!==!0&&this.log.error("error retrieving session block for %c - %e",t,g)}))};if(this.addEventListener("provider",u),a)try{await Kt(this.initialPeerSearchComplete,e.signal),a&&this.log("found initial session peers for %c",t)}catch(l){throw a&&this.log("failed to find initial session peers for %c - %e",t,l),this.requests.delete(n),i.observers>1&&s.reject(l),l}Promise.all([...this.providers].filter(l=>{let m=this.toFilterKey(l),g=i.queryFilter.has(m);return g||i.queryFilter.add(this.toFilterKey(l)),!g}).map(async l=>h.add(async()=>this.queryProvider(t,l,e),{provider:l}))).catch(l=>{e.signal?.aborted!==!0&&this.log.error("error retrieving session block for %c - %e",t,l)});let f=()=>{s.reject(new H(e.signal?.reason??"Session aborted")),h.abort()};e.signal?.addEventListener("abort",f);try{return await s.promise}finally{this.removeEventListener("provider",u),e.signal?.removeEventListener("abort",f),h.clear(),this.requests.delete(n)}}evict(t){this.evictionFilter.add(this.toFilterKey(t));let e=this.providers.findIndex(n=>this.equals(n,t));e!==-1&&this.providers.splice(e,1)}isEvicted(t){return this.evictionFilter.has(this.toFilterKey(t))}hasProvider(t){return!!(this.providers.find(e=>this.equals(e,t))!=null||this.isEvicted(t))}async addPeer(t,e){let n=await this.convertToProvider(t,"manually-added",e);n==null||this.hasProvider(n)||(this.providers.push(n),this.safeDispatchEvent("provider",{detail:n}))}async findProviders(t,e,n){let o=nt(),s=0;return Promise.resolve().then(async()=>{this.log("finding %d-%d new provider(s) for %c - %d initial providers",e,this.maxProviders,t,this.initialProviders.length);let i=this,a=async function*(){for(;i.initialProviders.length>0;){let h=i.initialProviders.pop();if(h==null)continue;let u=await i.convertToProvider(h,"manual",n);u!=null&&(yield u)}},c=async function*(){yield*a(),yield*i.findNewProviders(t,n)};for await(let h of c()){if(this.providers.length===this.maxProviders||n.signal?.aborted===!0)break;if(!this.hasProvider(h)&&(this.log("found %d providers, %d in session",s,this.providers.length),this.providers.push(h),this.safeDispatchEvent("provider",{detail:h}),s++,this.providers.length===e&&(this.log("session is ready with %d peer(s), new peers present",this.providers.length),o.resolve()),this.providers.length===this.maxProviders)){this.log("found max session peers %d",this.providers.length);break}}if(this.log("found %d new session peers while trying to find %d, %d in session",s,e,this.providers.length),this.providers.length<e)throw new je(`Found ${s} of ${e} ${this.name} providers for ${t}, ${this.providers.length} in session after evictions`)}).catch(i=>{this.log.error("error searching routing for potential session peers for %c - %e",t,i),o.reject(i)}),o.promise}};function pn(r){return r==null?!1:j.asCID(r)!=null}var lc=[6,53,56,54,55];function jo(r){return Ko("sni",r)?.value}function Wo(r){let t=Ko("tcp",r)?.value;return t==null?"":`:${t}`}function Ko(r,t){return t.find(e=>e.name===r)}function Ho(r){return r.some(({code:t})=>t===448)}function Q(r,t){let e=Go[r.name];if(e==null)throw new Error(`Can't interpret protocol ${r.name}`);let n=e(r,t);return r.code===41?`[${n}]`:n}var Go={ip4:(r,t)=>r.value,ip6:(r,t)=>t.length===0?r.value:`[${r.value}]`,tcp:(r,t)=>{let e=t.pop();if(e==null)throw new Error("Unexpected end of multiaddr");return`tcp://${Q(e,t)}:${r.value}`},udp:(r,t)=>{let e=t.pop();if(e==null)throw new Error("Unexpected end of multiaddr");return`udp://${Q(e,t)}:${r.value}`},dnsaddr:(r,t)=>r.value,dns4:(r,t)=>r.value,dns6:(r,t)=>r.value,dns:(r,t)=>r.value,ipfs:(r,t)=>{let e=t.pop();if(e==null)throw new Error("Unexpected end of multiaddr");return`${Q(e,t)}`},p2p:(r,t)=>{let e=t.pop();if(e==null)throw new Error("Unexpected end of multiaddr");return`${Q(e,t)}`},http:(r,t)=>{let e=Ho(t),n=jo(t),o=Wo(t);if(e&&n!=null)return`https://${n}${o}`;let s=e?"https://":"http://",i=t.pop();if(i==null)throw new Error("Unexpected end of multiaddr");let a=Q(i,t);return a=a?.replace("tcp://",""),`${s}${a}`},"http-path":(r,t)=>{let e=t.pop();if(e==null)throw new Error("Unexpected end of multiaddr");let n=Q(e,t),o=decodeURIComponent(r.value??"");return`${n}${o}`},tls:(r,t)=>{let e=t.pop();if(e==null)throw new Error("Unexpected end of multiaddr");return Q(e,t)},sni:(r,t)=>{let e=t.pop();if(e==null)throw new Error("Unexpected end of multiaddr");return Q(e,t)},https:(r,t)=>{let e=t.pop();if(e==null)throw new Error("Unexpected end of multiaddr");let n=Q(e,t);return n=n?.replace("tcp://",""),`https://${n}`},ws:(r,t)=>{let e=Ho(t),n=jo(t),o=Wo(t);if(e&&n!=null)return`wss://${n}${o}`;let s=e?"wss://":"ws://",i=t.pop();if(i==null)throw new Error("Unexpected end of multiaddr");let a=Q(i,t);return a=a?.replace("tcp://",""),`${s}${a}`},wss:(r,t)=>{let e=t.pop();if(e==null)throw new Error("Unexpected end of multiaddr");let n=Q(e,t);return n=n?.replace("tcp://",""),`wss://${n}`}};function We(r,t){let n=Le(r).getComponents(),o=n.pop();if(o==null)throw new Error("Unexpected end of multiaddr");let s=Go[o.name];if(s==null)throw new Error(`No interpreter found for ${o.name}`);let i=s(o,n)??"";return t?.assumeHttp!==!1&&lc.includes(o.code)&&(i=i.replace(/^.*:\/\//,""),o.value==="443"?i=`https://${i}`:i=`http://${i}`),(i.startsWith("http://")||i.startsWith("https://")||i.startsWith("ws://")||i.startsWith("wss://"))&&(i=new URL(i).toString(),i.endsWith("/")&&(i=i.substring(0,i.length-1))),i}var Qo="[a-fA-F\\d:]",ut=r=>r&&r.includeBoundaries?`(?:(?<=\\s|^)(?=${Qo})|(?<=${Qo})(?=\\s|$))`:"",X="(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}",D="[a-fA-F\\d]{1,4}",He=`
|
|
13
|
+
(?:
|
|
14
|
+
(?:${D}:){7}(?:${D}|:)| // 1:2:3:4:5:6:7:: 1:2:3:4:5:6:7:8
|
|
15
|
+
(?:${D}:){6}(?:${X}|:${D}|:)| // 1:2:3:4:5:6:: 1:2:3:4:5:6::8 1:2:3:4:5:6::8 1:2:3:4:5:6::1.2.3.4
|
|
16
|
+
(?:${D}:){5}(?::${X}|(?::${D}){1,2}|:)| // 1:2:3:4:5:: 1:2:3:4:5::7:8 1:2:3:4:5::8 1:2:3:4:5::7:1.2.3.4
|
|
17
|
+
(?:${D}:){4}(?:(?::${D}){0,1}:${X}|(?::${D}){1,3}|:)| // 1:2:3:4:: 1:2:3:4::6:7:8 1:2:3:4::8 1:2:3:4::6:7:1.2.3.4
|
|
18
|
+
(?:${D}:){3}(?:(?::${D}){0,2}:${X}|(?::${D}){1,4}|:)| // 1:2:3:: 1:2:3::5:6:7:8 1:2:3::8 1:2:3::5:6:7:1.2.3.4
|
|
19
|
+
(?:${D}:){2}(?:(?::${D}){0,3}:${X}|(?::${D}){1,5}|:)| // 1:2:: 1:2::4:5:6:7:8 1:2::8 1:2::4:5:6:7:1.2.3.4
|
|
20
|
+
(?:${D}:){1}(?:(?::${D}){0,4}:${X}|(?::${D}){1,6}|:)| // 1:: 1::3:4:5:6:7:8 1::8 1::3:4:5:6:7:1.2.3.4
|
|
21
|
+
(?::(?:(?::${D}){0,5}:${X}|(?::${D}){1,7}|:)) // ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 ::1.2.3.4
|
|
22
|
+
)(?:%[0-9a-zA-Z]{1,})? // %eth0 %1
|
|
23
|
+
`.replace(/\s*\/\/.*$/gm,"").replace(/\n/g,"").trim(),uc=new RegExp(`(?:^${X}$)|(?:^${He}$)`),fc=new RegExp(`^${X}$`),hc=new RegExp(`^${He}$`),mn=r=>r&&r.exact?uc:new RegExp(`(?:${ut(r)}${X}${ut(r)})|(?:${ut(r)}${He}${ut(r)})`,"g");mn.v4=r=>r&&r.exact?fc:new RegExp(`${ut(r)}${X}${ut(r)}`,"g");mn.v6=r=>r&&r.exact?hc:new RegExp(`${ut(r)}${He}${ut(r)}`,"g");var gn=mn;function yn(r){let t=(...e)=>r(...e);return Object.defineProperty(t,"name",{value:`functionTimeout(${r.name||"<anonymous>"})`,configurable:!0}),t}function Xo(){return!1}var{toString:dc}=Object.prototype;function wn(r){return dc.call(r)==="[object RegExp]"}var Jo={global:"g",ignoreCase:"i",multiline:"m",dotAll:"s",sticky:"y",unicode:"u"};function bn(r,t={}){if(!wn(r))throw new TypeError("Expected a RegExp instance");let e=Object.keys(Jo).map(o=>(typeof t[o]=="boolean"?t[o]:r[o])?Jo[o]:"").join(""),n=new RegExp(t.source||r.source,e);return n.lastIndex=typeof t.lastIndex=="number"?t.lastIndex:r.lastIndex,n}function xn(r,t,{timeout:e}={}){try{return yn(()=>bn(r).test(t),{timeout:e})()}catch(n){if(Xo(n))return!1;throw n}}var pc=15,mc=45,Yo={timeout:400};function En(r){return r.length>mc?!1:xn(gn.v6({exact:!0}),r,Yo)}function Zo(r){return r.length>pc?!1:xn(gn.v4({exact:!0}),r,Yo)}var ts={http:"80",https:"443",ws:"80",wss:"443"},gc=["http","https","ws","wss"];function es(r,t){t=t??{};let e=t.defaultDnsType??"dns",{scheme:n,hostname:o,port:s,path:i}=yc(r),a=[wc(o,e),bc(s,n),xc(n)];i!=null&&a.push(Ec(i));let c="/"+a.filter(h=>!!h).reduce((h,u)=>h.concat(u),[]).join("/");return Le(c)}function yc(r){let[t]=r.split(":");gc.includes(t)||(r="http"+r.substring(t.length));let{protocol:e,hostname:n,port:o,pathname:s,search:i}=new URL(r);if(o==null||o===""){let c=vc(t);c!=null&&(o=c),c==null&&e==="http:"&&(o="80")}let a;return s!=null&&s!==""&&s!=="/"&&(s.startsWith("/")&&(s=s.substring(1)),a=s),i!=null&&i!==""&&(a=a??"",a+=i),{scheme:t,hostname:n,port:o,path:a}}function wc(r,t){if(!(r==null||r==="")){if(Zo(r))return["ip4",r];if(En(r))return["ip6",r];if(r[0]==="["){let e=r.substring(1,r.length-1);if(En(e))return["ip6",e]}return[t,r]}}function bc(r,t){if(!(r==null||r===""))return t==="udp"?["udp",r]:["tcp",r]}function xc(r){if(r.match(/^tcp$|^udp$/)==null)return r==="https"?["/tls/http"]:r==="wss"?["/tls/ws"]:[r]}function Ec(r){if(!(r==null||r===""))return["http-path",encodeURIComponent(r)]}function vc(r){if(!(r==null||r===""||ts[r]==null))return ts[r]}function vn(r,t,e){return r.filter(n=>{let o=qo.exactMatch(n),s=Vo.exactMatch(n);if(!o&&!s)return!1;if(o||t&&s)return e||Oo.matches(n)?!0:xo(n)===!1;if(!t&&e){let{host:i}=xe(n);if(i==="127.0.0.1"||i==="localhost"||i.endsWith(".localhost"))return!0}return!1})}async function*Ke(r,t,e,n,o,s={}){for await(let i of t.findProviders(r,s)){let a=vn(i.multiaddrs,n,o);if(a.length===0)continue;let c=new URL(We(a[0]));yield new Mt(c,{logger:e,transformRequestInit:s.transformRequestInit,routing:i.routing})}}async function rs(r,t,e){let{signal:n,log:o}=e??{},s=r.headers.get("content-length");if(s!=null){let c=parseInt(s,10);if(c>t)throw o?.error("content-length header (%d) is greater than the limit (%d)",c,t),r.body!=null&&await r.body.cancel().catch(h=>{o?.error("error cancelling response body after content-length check - %e",h)}),new Error(`Content-Length header (${c}) is greater than the limit (${t}).`)}let i=r.body?.getReader();if(i==null)throw new Error("Response body is not readable");let a=new de;try{for(;;){if(n?.aborted===!0)throw new Error("Response body read was aborted.");let{done:c,value:h}=await i.read();if(c)break;if(a.append(h),a.byteLength>t)throw new Error(`Response body is greater than the limit (${t}), received ${a.byteLength} bytes.`)}}finally{i.cancel().catch(c=>{o?.error("error cancelling reader - %e",c)}).finally(()=>{i.releaseLock()})}return a.subarray()}var _c=2336,Mt=class{url;peer;#t=0;#e=0;#r=0;#o=0;#n=new Map;log;transformRequestInit;routing;constructor(t,{logger:e,transformRequestInit:n,routing:o}){this.url=t instanceof URL?t:new URL(t),this.transformRequestInit=n,this.log=e.forComponent(`helia:trustless-gateway-block-broker:${this.url.host}`),this.routing=o,this.peer=j.createV1(_c,br.digest(P(this.url.toString())))}#s(t){let e=t.multihash.bytes;return dt.encode(e)}async getRawBlock(t,e={}){let n=new URL(this.url.toString());n.pathname=`/ipfs/${t.toString()}`;let o=e.maxSize??_n;if(n.search="?format=raw",e.signal?.aborted===!0)throw new Error(`Signal to fetch raw block for CID ${t} from gateway ${this.url} was aborted prior to fetch`);let s=this.#s(t),i=new AbortController,a=()=>{i.abort()};e.signal?.addEventListener("abort",a);try{let c=this.#n.get(s);if(c==null){this.#t++;let h={signal:i.signal,headers:{Accept:"application/vnd.ipld.raw"},cache:"force-cache"},u=this.transformRequestInit!=null?await this.transformRequestInit(h):h,f=new Headers(u.headers);this.log(`sending request
|
|
24
|
+
%s %s HTTP/1.1
|
|
25
|
+
%s
|
|
26
|
+
`,u.method??"GET",n,[...f.entries()].map(([l,m])=>`${l}: ${m}`).join(`
|
|
27
|
+
`)),e.onProgress?.(new U("helia:block-broker:connect",{broker:"trustless-gateway",type:"connect",provider:this.peer,cid:t})),c=fetch(n.toString(),u).then(async l=>{if(this.log(`received response
|
|
28
|
+
HTTP/1.1 %d %s
|
|
29
|
+
%s
|
|
30
|
+
`,l.status,l.statusText,[...l.headers.entries()].map(([g,x])=>`${g}: ${x}`).join(`
|
|
31
|
+
`)),!l.ok)throw this.#e++,new Error(`Unable to fetch raw block for CID ${t} from gateway ${this.url}, received ${l.status} ${l.statusText}`);e.onProgress?.(new U("helia:block-broker:connected",{broker:"trustless-gateway",type:"connected",provider:this.peer,address:es(n.toString()),cid:t})),e.onProgress?.(new U("helia:block-broker:request-block",{broker:"trustless-gateway",type:"request-block",provider:this.peer,cid:t}));let m=await rs(l,o,{signal:i.signal,log:this.log});return e.onProgress?.(new U("helia:block-broker:receive-block",{broker:"trustless-gateway",type:"receive-block",provider:this.peer,cid:t})),this.#o++,m}),this.#n.set(s,c)}return await c}catch(c){throw e.signal?.aborted===!0?new Error(`Fetching raw block for CID ${t} from gateway ${this.url} was aborted`):(this.#e++,new Error(`Unable to fetch raw block for CID ${t} - ${c.message}`))}finally{e.signal?.removeEventListener("abort",a),this.#n.delete(s)}}reliability(){return this.#t===0?1:this.#r>0?-1/0:this.#o/(this.#t+this.#e*3)}incrementInvalidBlocks(){this.#r++}getStats(){return{attempts:this.#t,errors:this.#e,invalidBlocks:this.#r,successes:this.#o,pendingResponses:this.#n.size}}toString(){return`TrustlessGateway(${this.url})`}};var Cn=class extends oe{name="trustless-gateway-session";routing;allowInsecure;allowLocal;transformRequestInit;constructor(t,e){super(t,{...e,name:"helia:trustless-gateway:session"}),this.routing=t.routing,this.allowInsecure=e.allowInsecure??se,this.allowLocal=e.allowLocal??ie,this.transformRequestInit=e.transformRequestInit}async queryProvider(t,e,n){this.log("fetching BLOCK for %c from %s",t,e.url),n?.onProgress?.(new U("helia:block-brokers:query-provider:start",{blockBroker:"trustless-gateway",provider:e.url,transport:"http",cid:t}));let o;try{o=await e.getRawBlock(t,n),this.log.trace("got block for %c from %s",t,e.url)}finally{n?.onProgress?.(new U("helia:block-brokers:query-provider:end",{blockBroker:"trustless-gateway",provider:e.url,transport:"http",cid:t}))}return await n.validateFn?.(o),o}async*findNewProviders(t,e={}){yield*Ke(t,this.routing,this.logger,this.allowInsecure,this.allowLocal,{...e,transformRequestInit:this.transformRequestInit})}toFilterKey(t){return t.url.toString()}equals(t,e){return t.url.toString()===e.url.toString()}async convertToProvider(t,e,n){if(n?.signal?.throwIfAborted(),pn(t))return;let o=vn(Array.isArray(t)?t:[t],this.allowInsecure,this.allowLocal);if(o.length===0)return;let s=We(o[0]);return new Mt(s,{logger:this.logger,transformRequestInit:this.transformRequestInit,routing:e})}emitFoundProviderProgressEvent(t,e,n){n?.onProgress?.(new U("trustless-gateway:found-provider",{type:"trustless-gateway",cid:t,url:e.url.toJSON(),routing:e.routing}))}};function ns(r,t){return new Cn(r,t)}var Ge=class{name="trustless-gateway";allowInsecure;allowLocal;transformRequestInit;routing;log;logger;constructor(t,e={}){this.log=t.logger.forComponent("helia:trustless-gateway-block-broker"),this.logger=t.logger,this.routing=t.routing,this.allowInsecure=e.allowInsecure??se,this.allowLocal=e.allowLocal??ie,this.transformRequestInit=e.transformRequestInit}async retrieve(t,e={}){let n=[];for await(let o of Ke(t,this.routing,this.logger,this.allowInsecure,this.allowLocal,{...e,transformRequestInit:this.transformRequestInit})){this.log("getting block for %c from %s",t,o.url);try{let s=await o.getRawBlock(t,e);this.log.trace("got block for %c from %s",t,o.url);try{await e.validateFn?.(s)}catch(i){this.log.error("failed to validate block for %c from %s - %e",t,o.url,i);continue}return s}catch(s){if(this.log.error("failed to get block for %c from %s - %e",t,o.url,s),s instanceof Error?n.push(s):n.push(new Error(`Unable to fetch raw block for CID ${t} from gateway ${o.url}`)),e.signal?.aborted===!0){this.log.trace("request aborted while fetching raw block for CID %c from gateway %s",t,o.url);break}}}throw n.length>0?new AggregateError(n,`Unable to fetch raw block for CID ${t} from any gateway`):new Error(`Unable to fetch raw block for CID ${t} from any gateway`)}createSession(t={}){return ns({logger:this.logger,routing:this.routing},{...t,allowLocal:this.allowLocal,allowInsecure:this.allowInsecure,transformRequestInit:this.transformRequestInit})}};var se=!1,ie=!1,_n=2097152;function Cc(r={}){return t=>new Ge(t,r)}return us(Ic);})();
|
|
32
|
+
return HeliaTrustlessGatewayClient}));
|
|
33
|
+
//# sourceMappingURL=index.min.js.map
|