@ohos-ports/chainsafe-libp2p-quic 0.0.0-stage → 2.1.5-beta.0
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/LICENSE +19 -0
- package/README.md +61 -2
- package/dist/index.min.js +16 -0
- package/dist/index.min.js.map +7 -0
- package/dist/src/connection.d.ts +23 -0
- package/dist/src/connection.d.ts.map +1 -0
- package/dist/src/connection.js +40 -0
- package/dist/src/connection.js.map +1 -0
- package/dist/src/filter.d.ts +7 -0
- package/dist/src/filter.d.ts.map +1 -0
- package/dist/src/filter.js +14 -0
- package/dist/src/filter.js.map +1 -0
- package/dist/src/index.d.ts +55 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +58 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/listener.d.ts +47 -0
- package/dist/src/listener.d.ts.map +1 -0
- package/dist/src/listener.js +190 -0
- package/dist/src/listener.js.map +1 -0
- package/dist/src/napi.d.ts +9 -0
- package/dist/src/napi.d.ts.map +1 -0
- package/dist/src/napi.js +669 -0
- package/dist/src/napi.js.map +1 -0
- package/dist/src/stream-muxer.d.ts +18 -0
- package/dist/src/stream-muxer.d.ts.map +1 -0
- package/dist/src/stream-muxer.js +129 -0
- package/dist/src/stream-muxer.js.map +1 -0
- package/dist/src/stream.d.ts +21 -0
- package/dist/src/stream.d.ts.map +1 -0
- package/dist/src/stream.js +80 -0
- package/dist/src/stream.js.map +1 -0
- package/dist/src/transport.browser.d.ts +13 -0
- package/dist/src/transport.browser.d.ts.map +1 -0
- package/dist/src/transport.browser.js +20 -0
- package/dist/src/transport.browser.js.map +1 -0
- package/dist/src/transport.d.ts +27 -0
- package/dist/src/transport.d.ts.map +1 -0
- package/dist/src/transport.js +157 -0
- package/dist/src/transport.js.map +1 -0
- package/dist/src/utils.d.ts +10 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/utils.js +42 -0
- package/dist/src/utils.js.map +1 -0
- package/dist/test/browser.d.ts +2 -0
- package/dist/test/browser.d.ts.map +1 -0
- package/dist/test/browser.js +23 -0
- package/dist/test/browser.js.map +1 -0
- package/dist/test/compliance.spec.d.ts +2 -0
- package/dist/test/compliance.spec.d.ts.map +1 -0
- package/dist/test/compliance.spec.js +65 -0
- package/dist/test/compliance.spec.js.map +1 -0
- package/dist/test/sanity.spec.d.ts +2 -0
- package/dist/test/sanity.spec.d.ts.map +1 -0
- package/dist/test/sanity.spec.js +92 -0
- package/dist/test/sanity.spec.js.map +1 -0
- package/dist/test/transport.spec.d.ts +2 -0
- package/dist/test/transport.spec.d.ts.map +1 -0
- package/dist/test/transport.spec.js +171 -0
- package/dist/test/transport.spec.js.map +1 -0
- package/dist/test/util.d.ts +3 -0
- package/dist/test/util.d.ts.map +1 -0
- package/dist/test/util.js +9 -0
- package/dist/test/util.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +101 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
|
11
|
+
all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,62 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @chainsafe/libp2p-quic
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](http://libp2p.io/)
|
|
4
|
+
[](https://github.com/chainsafe/js-libp2p-quic/actions/workflows/CI.yml?query=branch%3Amain)
|
|
5
|
+
|
|
6
|
+
> A QUIC transport for libp2p
|
|
7
|
+
|
|
8
|
+
# About
|
|
9
|
+
|
|
10
|
+
<!--
|
|
11
|
+
|
|
12
|
+
!IMPORTANT!
|
|
13
|
+
|
|
14
|
+
Everything in this README between "# About" and "# Install" is automatically
|
|
15
|
+
generated and will be overwritten the next time the doc generator is run.
|
|
16
|
+
|
|
17
|
+
To make changes to this section, please update the @packageDocumentation section
|
|
18
|
+
of src/index.js or src/index.ts
|
|
19
|
+
|
|
20
|
+
To experiment with formatting, please run "npm run docs" from the root of this
|
|
21
|
+
repo and examine the changes made.
|
|
22
|
+
|
|
23
|
+
-->
|
|
24
|
+
|
|
25
|
+
A [libp2p transport](https://docs.libp2p.io/concepts/transports/overview/) based on the QUIC networking stack.
|
|
26
|
+
|
|
27
|
+
## Example
|
|
28
|
+
|
|
29
|
+
```TypeScript
|
|
30
|
+
import { createLibp2p } from 'libp2p'
|
|
31
|
+
import { quic } from '@chainsafe/libp2p-quic'
|
|
32
|
+
import { multiaddr } from '@multiformats/multiaddr'
|
|
33
|
+
|
|
34
|
+
const node = await createLibp2p({
|
|
35
|
+
transports: [
|
|
36
|
+
quic()
|
|
37
|
+
]
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
const ma = multiaddr('/ip4/123.123.123.123/udp/1234/quic-v1')
|
|
41
|
+
|
|
42
|
+
// dial a TCP connection, timing out after 10 seconds
|
|
43
|
+
const connection = await node.dial(ma, {
|
|
44
|
+
signal: AbortSignal.timeout(10_000)
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
// use connection...
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
# Install
|
|
51
|
+
|
|
52
|
+
```console
|
|
53
|
+
$ npm i @chainsafe/libp2p-quic
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
# API Docs
|
|
57
|
+
|
|
58
|
+
- <https://chainsafe.github.io/js-libp2p-quic>
|
|
59
|
+
|
|
60
|
+
# License
|
|
61
|
+
|
|
62
|
+
MIT ([LICENSE](https://github.com/ChainSafe/js-libp2p-quic/blob/main/LICENSE) / <http://opensource.org/licenses/MIT>)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.ChainsafeLibp2PQuic = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
+
var gc=Object.defineProperty;var ge=(t,e)=>{for(var r in e)gc(t,r,{get:e[r],enumerable:!0})};import{setMaxListeners as yc}from"node:events";var Cr=(t,...e)=>{try{yc(t,...e)}catch{}};var qe=class extends EventTarget{#e=new Map;constructor(){super(),Cr(1/0,this)}listenerCount(e){let r=this.#e.get(e);return r==null?0:r.length}addEventListener(e,r,n){super.addEventListener(e,r,n);let o=this.#e.get(e);o==null&&(o=[],this.#e.set(e,o)),o.push({callback:r,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,r,n){super.removeEventListener(e.toString(),r??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:s})=>s!==r),this.#e.set(e,o))}dispatchEvent(e){let r=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:o})=>!o),this.#e.set(e.type,n)),r}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};var Nn={};ge(Nn,{base58btc:()=>_e,base58flickr:()=>Ac});var ph=new Uint8Array(0);function Ms(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function ye(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}function Hs(t){return new TextEncoder().encode(t)}function Fs(t){return new TextDecoder().decode(t)}function xc(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<t.length;o++){var s=t.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=t.length,c=t.charAt(0),u=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function f(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var w=0,y=0,S=0,P=h.length;S!==P&&h[S]===0;)S++,w++;for(var O=(P-S)*l+1>>>0,B=new Uint8Array(O);S!==P;){for(var K=h[S],F=0,M=O-1;(K!==0||F<y)&&M!==-1;M--,F++)K+=256*B[M]>>>0,B[M]=K%a>>>0,K=K/a>>>0;if(K!==0)throw new Error("Non-zero carry");y=F,S++}for(var $=O-y;$!==O&&B[$]===0;)$++;for(var N=c.repeat(w);$<O;++$)N+=t.charAt(B[$]);return N}function x(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;var w=0;if(h[w]!==" "){for(var y=0,S=0;h[w]===c;)y++,w++;for(var P=(h.length-w)*u+1>>>0,O=new Uint8Array(P);h[w];){var B=r[h.charCodeAt(w)];if(B===255)return;for(var K=0,F=P-1;(B!==0||K<S)&&F!==-1;F--,K++)B+=a*O[F]>>>0,O[F]=B%256>>>0,B=B/256>>>0;if(B!==0)throw new Error("Non-zero carry");S=K,w++}if(h[w]!==" "){for(var M=P-S;M!==P&&O[M]===0;)M++;for(var $=new Uint8Array(y+(P-M)),N=y;M!==P;)$[N++]=O[M++];return $}}}function g(h){var w=x(h);if(w)return w;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:x,decode:g}}var wc=xc,Ec=wc,js=Ec;var Dn=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Rn=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return zs(this,e)}},Bn=class{decoders;constructor(e){this.decoders=e}or(e){return zs(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function zs(t,e){return new Bn({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var Pn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Dn(e,r,n),this.decoder=new Rn(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function lt({name:t,prefix:e,encode:r,decode:n}){return new Pn(t,e,r,n)}function Me({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=js(r,t);return lt({prefix:e,name:t,encode:n,decode:s=>ye(o(s))})}function vc(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let l=e[t[u]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|l,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Sc(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],i+=8;i>r;)i-=r,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function Cc(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function Q({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=Cc(n);return lt({prefix:e,name:t,encode(s){return Sc(s,n,r)},decode(s){return vc(s,o,r,t)}})}var _e=Me({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ac=Me({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ln={};ge(Ln,{base32:()=>He,base32hex:()=>Rc,base32hexpad:()=>Pc,base32hexpadupper:()=>Nc,base32hexupper:()=>Bc,base32pad:()=>Ic,base32padupper:()=>Dc,base32upper:()=>_c,base32z:()=>Lc});var He=Q({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),_c=Q({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ic=Q({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Dc=Q({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Rc=Q({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Bc=Q({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Pc=Q({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Nc=Q({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Lc=Q({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var On={};ge(On,{base36:()=>qt,base36upper:()=>Oc});var qt=Me({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Oc=Me({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Tc=Ys,Ws=128,kc=127,Kc=~kc,Uc=Math.pow(2,31);function Ys(t,e,r){e=e||[],r=r||0;for(var n=r;t>=Uc;)e[r++]=t&255|Ws,t/=128;for(;t&Kc;)e[r++]=t&255|Ws,t>>>=7;return e[r]=t|0,Ys.bytes=r-n+1,e}var Vc=Tn,qc=128,Gs=127;function Tn(t,n){var r=0,n=n||0,o=0,s=n,i,a=t.length;do{if(s>=a)throw Tn.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&Gs)<<o:(i&Gs)*Math.pow(2,o),o+=7}while(i>=qc);return Tn.bytes=s-n,r}var Mc=Math.pow(2,7),Hc=Math.pow(2,14),Fc=Math.pow(2,21),$c=Math.pow(2,28),jc=Math.pow(2,35),zc=Math.pow(2,42),Wc=Math.pow(2,49),Gc=Math.pow(2,56),Yc=Math.pow(2,63),Zc=function(t){return t<Mc?1:t<Hc?2:t<Fc?3:t<$c?4:t<jc?5:t<zc?6:t<Wc?7:t<Gc?8:t<Yc?9:10},Qc={encode:Tc,decode:Vc,encodingLength:Zc},Xc=Qc,Mt=Xc;function Ht(t,e=0){return[Mt.decode(t,e),Mt.decode.bytes]}function ht(t,e,r=0){return Mt.encode(t,e,r),e}function dt(t){return Mt.encodingLength(t)}function Ge(t,e){let r=e.byteLength,n=dt(t),o=n+dt(r),s=new Uint8Array(o+r);return ht(t,s,0),ht(r,s,n),s.set(e,o),new pt(t,r,e,s)}function Zs(t){let e=ye(t),[r,n]=Ht(e),[o,s]=Ht(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new pt(r,o,i,e)}function Qs(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&Ms(t.bytes,r.bytes)}}var pt=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};function Xs(t,e){let{bytes:r,version:n}=t;switch(n){case 0:return eu(r,kn(t),e??_e.encoder);default:return tu(r,kn(t),e??He.encoder)}}var Js=new WeakMap;function kn(t){let e=Js.get(t);if(e==null){let r=new Map;return Js.set(t,r),r}return e}var mt=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==$t)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==ru)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:r}=this.multihash,n=Ge(e,r);return t.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&Qs(e.multihash,n.multihash)}toString(e){return Xs(this,e)}toJSON(){return{"/":Xs(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new t(n,o,s,i??ei(n,o,s.bytes))}else if(r[nu]===!0){let{version:n,multihash:o,code:s}=r,i=Zs(o);return t.create(n,s,i)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==$t)throw new Error(`Version 0 CID must use dag-pb (code: ${$t}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=ei(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,$t,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,o=ye(e.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new pt(r.multihashCode,r.digestSize,s,o);return[r.version===0?t.createV0(i):t.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[f,x]=Ht(e.subarray(r));return r+=x,f},o=n(),s=$t;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),u=r+c,l=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(e,r){let[n,o]=Jc(e,r),s=t.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return kn(s).set(n,e),s}};function Jc(t,e){switch(t[0]){case"Q":{let r=e??_e;return[_e.prefix,r.decode(`${_e.prefix}${t}`)]}case _e.prefix:{let r=e??_e;return[_e.prefix,r.decode(t)]}case He.prefix:{let r=e??He;return[He.prefix,r.decode(t)]}case qt.prefix:{let r=e??qt;return[qt.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function eu(t,e,r){let{prefix:n}=r;if(n!==_e.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let s=r.encode(t).slice(1);return e.set(n,s),s}else return o}function tu(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let s=r.encode(t);return e.set(n,s),s}else return o}var $t=112,ru=18;function ei(t,e,r){let n=dt(t),o=n+dt(e),s=new Uint8Array(o+r.byteLength);return ht(t,s,0),ht(e,s,n),s.set(r,o),s}var nu=Symbol.for("@ipld/js-cid/CID");var Kn={};ge(Kn,{identity:()=>iu});var ti=0,ou="identity",ri=ye;function su(t){return Ge(ti,ri(t))}var iu={code:ti,name:ou,encode:ri,digest:su};function he(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}import{Buffer as ni}from"node:buffer";function Ye(t){return new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}function Oe(t=0){return Ye(ni.alloc(t))}function xe(t=0){return Ye(ni.allocUnsafe(t))}import{Buffer as au}from"node:buffer";function Ie(t,e){return Ye(au.concat(t,e))}var si=Symbol.for("@achingbrain/uint8arraylist");function oi(t,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let r=0;for(let n of t){let o=r+n.byteLength;if(e<o)return{buf:n,index:e-r};r=o}throw new RangeError("index is out of bounds")}function _r(t){return!!t?.[si]}var ee=class t{bufs;length;[si]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let r=0;for(let n of e)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(_r(n))r+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...e){this.prependAll(e)}prependAll(e){let r=0;for(let n of e.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(_r(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(e){let r=oi(this.bufs,e);return r.buf[r.index]}set(e,r){let n=oi(this.bufs,e);n.buf[n.index]=r}write(e,r=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(r+n,e[n]);else if(_r(e))for(let n=0;n<e.length;n++)this.set(r+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,r){let{bufs:n,length:o}=this._subList(e,r);return Ie(n,o)}subarray(e,r){let{bufs:n,length:o}=this._subList(e,r);return n.length===1?n[0]:Ie(n,o)}sublist(e,r){let{bufs:n,length:o}=this._subList(e,r),s=new t;return s.length=o,s.bufs=[...n],s}_subList(e,r){if(e=e??0,r=r??this.length,e<0&&(e=this.length+e),r<0&&(r=this.length+r),e<0||r>this.length)throw new RangeError("index is out of bounds");if(e===r)return{bufs:[],length:0};if(e===0&&r===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,e>=c)continue;let u=e>=a&&e<c,l=r>a&&r<=c;if(u&&l){if(e===a&&r===c){n.push(i);break}let f=e-a;n.push(i.subarray(f,f+(r-e)));break}if(u){if(e===0){n.push(i);continue}n.push(i.subarray(e-a));continue}if(l){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-e}}indexOf(e,r=0){if(!_r(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),e.length===0)return r>this.length?this.length:r;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,u=n.byteLength-1,l;for(let f=r;f<=c;f+=l){l=0;for(let x=u;x>=0;x--){let g=this.get(f+x);if(n[x]!==g){l=Math.max(1,x-a[g]);break}}if(l===0)return f}return-1}getInt8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(e,r){let n=xe(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,e)}getInt16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(e,r,n){let o=Oe(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,e)}getInt32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(e,r,n){let o=Oe(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,e)}getBigInt64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(e,r,n){let o=Oe(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,e)}getUint8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(e,r){let n=xe(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,e)}getUint16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(e,r,n){let o=Oe(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,e)}getUint32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(e,r,n){let o=Oe(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,e)}getBigUint64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(e,r,n){let o=Oe(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,e)}getFloat32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(e,r,n){let o=Oe(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,e)}getFloat64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(e,r,n){let o=Oe(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,e)}equals(e){if(e==null||!(e instanceof t)||e.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!he(this.bufs[r],e.bufs[r]))return!1;return!0}static fromUint8Arrays(e,r){let n=new t;return n.bufs=e,r==null&&(r=e.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};import{Buffer as Iu}from"node:buffer";var Un={};ge(Un,{base10:()=>cu});var cu=Me({prefix:"9",name:"base10",alphabet:"0123456789"});var Vn={};ge(Vn,{base16:()=>uu,base16upper:()=>fu});var uu=Q({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),fu=Q({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var qn={};ge(qn,{base2:()=>lu});var lu=Q({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Mn={};ge(Mn,{base256emoji:()=>bu});var ii=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}"),hu=ii.reduce((t,e,r)=>(t[r]=e,t),[]),du=ii.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function pu(t){return t.reduce((e,r)=>(e+=hu[r],e),"")}function mu(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=du[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(o)}return new Uint8Array(e)}var bu=lt({prefix:"\u{1F680}",name:"base256emoji",encode:pu,decode:mu});var Fn={};ge(Fn,{base64:()=>gu,base64pad:()=>yu,base64url:()=>Hn,base64urlpad:()=>xu});var gu=Q({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),yu=Q({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Hn=Q({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),xu=Q({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var $n={};ge($n,{base8:()=>wu});var wu=Q({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var jn={};ge(jn,{identity:()=>Eu});var Eu=lt({prefix:"\0",name:"identity",encode:t=>Fs(t),decode:t=>Hs(t)});var Xh=new TextEncoder,Jh=new TextDecoder;var Gn={};ge(Gn,{sha256:()=>Cu,sha512:()=>Au});import ci from"crypto";function Wn({name:t,code:e,encode:r}){return new zn(t,e,r)}var zn=class{name;code;encode;constructor(e,r,n){this.name=e,this.code=r,this.encode=n}digest(e){if(e instanceof Uint8Array){let r=this.encode(e);return r instanceof Uint8Array?Ge(this.code,r):r.then(n=>Ge(this.code,n))}else throw Error("Unknown type, must be binary type")}};var Cu=Wn({name:"sha2-256",code:18,encode:t=>ye(ci.createHash("sha256").update(t).digest())}),Au=Wn({name:"sha2-512",code:19,encode:t=>ye(ci.createHash("sha512").update(t).digest())});var jt={...jn,...qn,...$n,...Un,...Vn,...Ln,...On,...Nn,...Fn,...Mn},dd={...Gn,...Kn};function fi(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var ui=fi("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Yn=fi("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=xe(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),_u={utf8:ui,"utf-8":ui,hex:jt.base16,latin1:Yn,ascii:Yn,binary:Yn,...jt},Ir=_u;function le(t,e="utf8"){let r=Ir[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?Ye(Iu.from(t,"utf-8")):r.decoder.decode(`${r.prefix}${t}`)}import{Buffer as Du}from"node:buffer";function X(t,e="utf8"){let r=Ir[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?Du.from(t.buffer,t.byteOffset,t.byteLength).toString("utf8"):r.encoder.encode(t).substring(1)}var Ru=Math.pow(2,7),Bu=Math.pow(2,14),Pu=Math.pow(2,21),Zn=Math.pow(2,28),Qn=Math.pow(2,35),Xn=Math.pow(2,42),Jn=Math.pow(2,49),G=128,ie=127;function De(t){if(t<Ru)return 1;if(t<Bu)return 2;if(t<Pu)return 3;if(t<Zn)return 4;if(t<Qn)return 5;if(t<Xn)return 6;if(t<Jn)return 7;if(Number.MAX_SAFE_INTEGER!=null&&t>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function zt(t,e,r=0){switch(De(t)){case 8:e[r++]=t&255|G,t/=128;case 7:e[r++]=t&255|G,t/=128;case 6:e[r++]=t&255|G,t/=128;case 5:e[r++]=t&255|G,t/=128;case 4:e[r++]=t&255|G,t>>>=7;case 3:e[r++]=t&255|G,t>>>=7;case 2:e[r++]=t&255|G,t>>>=7;case 1:{e[r++]=t&255,t>>>=7;break}default:throw new Error("unreachable")}return e}function eo(t,e){let r=t[e],n=0;if(n+=r&ie,r<G||(r=t[e+1],n+=(r&ie)<<7,r<G)||(r=t[e+2],n+=(r&ie)<<14,r<G)||(r=t[e+3],n+=(r&ie)<<21,r<G)||(r=t[e+4],n+=(r&ie)*Zn,r<G)||(r=t[e+5],n+=(r&ie)*Qn,r<G)||(r=t[e+6],n+=(r&ie)*Xn,r<G)||(r=t[e+7],n+=(r&ie)*Jn,r<G))return n;throw new RangeError("Could not decode varint")}function Nu(t,e){let r=t.get(e),n=0;if(n+=r&ie,r<G||(r=t.get(e+1),n+=(r&ie)<<7,r<G)||(r=t.get(e+2),n+=(r&ie)<<14,r<G)||(r=t.get(e+3),n+=(r&ie)<<21,r<G)||(r=t.get(e+4),n+=(r&ie)*Zn,r<G)||(r=t.get(e+5),n+=(r&ie)*Qn,r<G)||(r=t.get(e+6),n+=(r&ie)*Xn,r<G)||(r=t.get(e+7),n+=(r&ie)*Jn,r<G))return n;throw new RangeError("Could not decode varint")}function to(t,e=0){return t instanceof Uint8Array?eo(t,e):Nu(t,e)}var ro=new Float32Array([-0]),Fe=new Uint8Array(ro.buffer);function li(t,e,r){ro[0]=t,e[r]=Fe[0],e[r+1]=Fe[1],e[r+2]=Fe[2],e[r+3]=Fe[3]}function hi(t,e){return Fe[0]=t[e],Fe[1]=t[e+1],Fe[2]=t[e+2],Fe[3]=t[e+3],ro[0]}var no=new Float64Array([-0]),ae=new Uint8Array(no.buffer);function di(t,e,r){no[0]=t,e[r]=ae[0],e[r+1]=ae[1],e[r+2]=ae[2],e[r+3]=ae[3],e[r+4]=ae[4],e[r+5]=ae[5],e[r+6]=ae[6],e[r+7]=ae[7]}function pi(t,e){return ae[0]=t[e],ae[1]=t[e+1],ae[2]=t[e+2],ae[3]=t[e+3],ae[4]=t[e+4],ae[5]=t[e+5],ae[6]=t[e+6],ae[7]=t[e+7],no[0]}var Ou=BigInt(Number.MAX_SAFE_INTEGER),Tu=BigInt(Number.MIN_SAFE_INTEGER),de=class t{lo;hi;constructor(e,r){this.lo=e|0,this.hi=r|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?e<16384?e<128?1:2:e<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return Ze;if(e<Ou&&e>Tu)return this.fromNumber(Number(e));let r=e<0n;r&&(e=-e);let n=e>>32n,o=e-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>mi&&(o=0n,++n>mi&&(n=0n))),new t(Number(o),Number(n))}static fromNumber(e){if(e===0)return Ze;let r=e<0;r&&(e=-e);let n=e>>>0,o=(e-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new t(n,o)}static from(e){return typeof e=="number"?t.fromNumber(e):typeof e=="bigint"?t.fromBigInt(e):typeof e=="string"?t.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new t(e.low>>>0,e.high>>>0):Ze}},Ze=new de(0,0);Ze.toBigInt=function(){return 0n};Ze.zzEncode=Ze.zzDecode=function(){return this};Ze.length=function(){return 1};var mi=4294967296n;function bi(t){let e=0,r=0;for(let n=0;n<t.length;++n)r=t.charCodeAt(n),r<128?e+=1:r<2048?e+=2:(r&64512)===55296&&(t.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function gi(t,e,r){if(r-e<1)return"";let o,s=[],i=0,a;for(;e<r;)a=t[e++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|t[e++]&63:a>239&&a<365?(a=((a&7)<<18|(t[e++]&63)<<12|(t[e++]&63)<<6|t[e++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(t[e++]&63)<<6|t[e++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function oo(t,e,r){let n=r,o,s;for(let i=0;i<t.length;++i)o=t.charCodeAt(i),o<128?e[r++]=o:o<2048?(e[r++]=o>>6|192,e[r++]=o&63|128):(o&64512)===55296&&((s=t.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,e[r++]=o>>18|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128,e[r++]=o&63|128):(e[r++]=o>>12|224,e[r++]=o>>6&63|128,e[r++]=o&63|128);return r-n}function we(t,e){return RangeError(`index out of range: ${t.pos} + ${e??1} > ${t.len}`)}function Dr(t,e){return(t[e-4]|t[e-3]<<8|t[e-2]<<16|t[e-1]<<24)>>>0}var so=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,we(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw we(this,4);return Dr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw we(this,4);return Dr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw we(this,4);let e=hi(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw we(this,4);let e=pi(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),r=this.pos,n=this.pos+e;if(n>this.len)throw we(this,e);return this.pos+=e,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let e=this.bytes();return gi(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw we(this,e);this.pos+=e}else do if(this.pos>=this.len)throw we(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new de(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw we(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,e}if(this.len-this.pos>4){for(;r<5;++r)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;r<5;++r){if(this.pos>=this.len)throw we(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw we(this,8);let e=Dr(this.buf,this.pos+=4),r=Dr(this.buf,this.pos+=4);return new de(e,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=eo(this.buf,this.pos);return this.pos+=De(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function io(t){return new so(t instanceof Uint8Array?t:t.subarray())}function Qe(t,e,r){let n=io(t);return e.decode(n,void 0,r)}function ao(t){let e=t??8192,r=e>>>1,n,o=e;return function(i){if(i<1||i>r)return xe(i);o+i>e&&(n=xe(e),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Xe=class{fn;len;next;val;constructor(e,r,n){this.fn=e,this.len=r,this.next=void 0,this.val=n}};function co(){}var fo=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},ku=ao();function Ku(t){return globalThis.Buffer!=null?xe(t):ku(t)}var Gt=class{len;head;tail;states;constructor(){this.len=0,this.head=new Xe(co,0,0),this.tail=this.head,this.states=null}_push(e,r,n){return this.tail=this.tail.next=new Xe(e,r,n),this.len+=r,this}uint32(e){return this.len+=(this.tail=this.tail.next=new lo((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(Rr,10,de.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let r=de.fromBigInt(e);return this._push(Rr,r.length(),r)}uint64Number(e){return this._push(zt,De(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let r=de.fromBigInt(e).zzEncode();return this._push(Rr,r.length(),r)}sint64Number(e){let r=de.fromNumber(e).zzEncode();return this._push(Rr,r.length(),r)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(uo,1,e?1:0)}fixed32(e){return this._push(Wt,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let r=de.fromBigInt(e);return this._push(Wt,4,r.lo)._push(Wt,4,r.hi)}fixed64Number(e){let r=de.fromNumber(e);return this._push(Wt,4,r.lo)._push(Wt,4,r.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(li,4,e)}double(e){return this._push(di,8,e)}bytes(e){let r=e.length>>>0;return r===0?this._push(uo,1,0):this.uint32(r)._push(Vu,r,e)}string(e){let r=bi(e);return r!==0?this.uint32(r)._push(oo,r,e):this._push(uo,1,0)}fork(){return this.states=new fo(this),this.head=this.tail=new Xe(co,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new Xe(co,0,0),this.len=0),this}ldelim(){let e=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=r,this.len+=n),this}finish(){let e=this.head.next,r=Ku(this.len),n=0;for(;e!=null;)e.fn(e.val,r,n),n+=e.len,e=e.next;return r}};function uo(t,e,r){e[r]=t&255}function Uu(t,e,r){for(;t>127;)e[r++]=t&127|128,t>>>=7;e[r]=t}var lo=class extends Xe{next;constructor(e,r){super(Uu,e,r),this.next=void 0}};function Rr(t,e,r){for(;t.hi!==0;)e[r++]=t.lo&127|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;t.lo>127;)e[r++]=t.lo&127|128,t.lo=t.lo>>>7;e[r++]=t.lo}function Wt(t,e,r){e[r]=t&255,e[r+1]=t>>>8&255,e[r+2]=t>>>16&255,e[r+3]=t>>>24}function Vu(t,e,r){e.set(t,r)}globalThis.Buffer!=null&&(Gt.prototype.bytes=function(t){let e=t.length>>>0;return this.uint32(e),e>0&&this._push(qu,e,t),this},Gt.prototype.string=function(t){let e=globalThis.Buffer.byteLength(t);return this.uint32(e),e>0&&this._push(Mu,e,t),this});function qu(t,e,r){e.set(t,r)}function Mu(t,e,r){t.length<40?oo(t,e,r):e.utf8Write!=null?e.utf8Write(t,r):e.set(le(t),r)}function ho(){return new Gt}function Je(t,e){let r=ho();return e.encode(t,r,{lengthDelimited:!1}),r.finish()}var bt;(function(t){t[t.VARINT=0]="VARINT",t[t.BIT64=1]="BIT64",t[t.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",t[t.START_GROUP=3]="START_GROUP",t[t.END_GROUP=4]="END_GROUP",t[t.BIT32=5]="BIT32"})(bt||(bt={}));function Br(t,e,r,n){return{name:t,type:e,encode:r,decode:n}}function Yt(t){function e(o){if(t[o.toString()]==null)throw new Error("Invalid enum value");return t[o]}let r=function(s,i){let a=e(s);i.int32(a)},n=function(s){let i=s.int32();return e(i)};return Br("enum",bt.VARINT,r,n)}function et(t,e){return Br("message",bt.LENGTH_DELIMITED,t,e)}var Re;(function(t){t.RSA="RSA",t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.ECDSA="ECDSA"})(Re||(Re={}));var po;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.secp256k1=2]="secp256k1",t[t.ECDSA=3]="ECDSA"})(po||(po={}));(function(t){t.codec=()=>Yt(po)})(Re||(Re={}));var mo;(function(t){let e;t.codec=()=>(e==null&&(e=et((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),Re.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{s.Type=Re.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return s})),e),t.encode=r=>Je(r,t.codec()),t.decode=(r,n)=>Qe(r,t.codec(),n)})(mo||(mo={}));var Pr;(function(t){let e;t.codec=()=>(e==null&&(e=et((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),Re.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{s.Type=Re.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return s})),e),t.encode=r=>Je(r,t.codec()),t.decode=(r,n)=>Qe(r,t.codec(),n)})(Pr||(Pr={}));function xi(t){return Pr.encode({Type:Re[t.type],Data:t.raw})}var Nr=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var Be=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},Lr=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var Or=class extends Error{static name="StreamResetError";constructor(e="The stream has been reset"){super(e),this.name="StreamResetError"}};var $e=class extends Error{static name="StreamStateError";constructor(e="The stream is in an invalid state"){super(e),this.name="StreamStateError"}},Zt=class extends Error{static name="StreamBufferError";constructor(e="The stream buffer was full"){super(e),this.name="StreamBufferError"}};var Tr=class extends Error{static name="InvalidCIDError";constructor(e="Invalid CID"){super(e),this.name="InvalidCIDError"}},kr=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var Qt=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var Kr=class extends Event{data;constructor(e,r){super("message",r),this.data=e}},gt=class extends Event{error;local;constructor(e,r,n){super("close",n),this.error=r,this.local=e}},Ur=class extends gt{constructor(e,r){super(!0,e,r)}},Vr=class extends gt{constructor(e,r){super(!1,e,r)}};var bo=Symbol.for("@libp2p/peer-id");var Ei=Symbol.for("@libp2p/transport");var wi;(function(t){t[t.FATAL_ALL=0]="FATAL_ALL",t[t.NO_FATAL=1]="NO_FATAL"})(wi||(wi={}));var vi=Symbol.for("@libp2p/service-capabilities"),up=Symbol.for("@libp2p/service-dependencies");var Tp=new Uint8Array(0);function Si(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function Ee(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}function Fu(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<t.length;o++){var s=t.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=t.length,c=t.charAt(0),u=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function f(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var w=0,y=0,S=0,P=h.length;S!==P&&h[S]===0;)S++,w++;for(var O=(P-S)*l+1>>>0,B=new Uint8Array(O);S!==P;){for(var K=h[S],F=0,M=O-1;(K!==0||F<y)&&M!==-1;M--,F++)K+=256*B[M]>>>0,B[M]=K%a>>>0,K=K/a>>>0;if(K!==0)throw new Error("Non-zero carry");y=F,S++}for(var $=O-y;$!==O&&B[$]===0;)$++;for(var N=c.repeat(w);$<O;++$)N+=t.charAt(B[$]);return N}function x(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;var w=0;if(h[w]!==" "){for(var y=0,S=0;h[w]===c;)y++,w++;for(var P=(h.length-w)*u+1>>>0,O=new Uint8Array(P);h[w];){var B=r[h.charCodeAt(w)];if(B===255)return;for(var K=0,F=P-1;(B!==0||K<S)&&F!==-1;F--,K++)B+=a*O[F]>>>0,O[F]=B%256>>>0,B=B/256>>>0;if(B!==0)throw new Error("Non-zero carry");S=K,w++}if(h[w]!==" "){for(var M=P-S;M!==P&&O[M]===0;)M++;for(var $=new Uint8Array(y+(P-M)),N=y;M!==P;)$[N++]=O[M++];return $}}}function g(h){var w=x(h);if(w)return w;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:x,decode:g}}var $u=Fu,ju=$u,Ci=ju;var go=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},yo=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Ai(this,e)}},xo=class{decoders;constructor(e){this.decoders=e}or(e){return Ai(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Ai(t,e){return new xo({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var wo=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new go(e,r,n),this.decoder=new yo(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function _i({name:t,prefix:e,encode:r,decode:n}){return new wo(t,e,r,n)}function yt({name:t,prefix:e,alphabet:r}){let{encode:n,decode:o}=Ci(r,t);return _i({prefix:e,name:t,encode:n,decode:s=>Ee(o(s))})}function zu(t,e,r,n){let o=t.length;for(;t[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,c=0;for(let u=0;u<o;++u){let l=e[t[u]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|l,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Wu(t,e,r){let n=e[e.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],i+=8;i>r;)i-=r,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function Gu(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function Pe({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let o=Gu(n);return _i({prefix:e,name:t,encode(s){return Wu(s,n,r)},decode(s){return zu(s,o,r,t)}})}var te=yt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Hp=yt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Xt=Pe({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),jp=Pe({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),zp=Pe({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Wp=Pe({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Gp=Pe({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Yp=Pe({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Zp=Pe({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Qp=Pe({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Xp=Pe({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var qr=yt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),tm=yt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Yu=Ri,Ii=128,Zu=127,Qu=~Zu,Xu=Math.pow(2,31);function Ri(t,e,r){e=e||[],r=r||0;for(var n=r;t>=Xu;)e[r++]=t&255|Ii,t/=128;for(;t&Qu;)e[r++]=t&255|Ii,t>>>=7;return e[r]=t|0,Ri.bytes=r-n+1,e}var Ju=Eo,ef=128,Di=127;function Eo(t,n){var r=0,n=n||0,o=0,s=n,i,a=t.length;do{if(s>=a)throw Eo.bytes=0,new RangeError("Could not decode varint");i=t[s++],r+=o<28?(i&Di)<<o:(i&Di)*Math.pow(2,o),o+=7}while(i>=ef);return Eo.bytes=s-n,r}var tf=Math.pow(2,7),rf=Math.pow(2,14),nf=Math.pow(2,21),of=Math.pow(2,28),sf=Math.pow(2,35),af=Math.pow(2,42),cf=Math.pow(2,49),uf=Math.pow(2,56),ff=Math.pow(2,63),lf=function(t){return t<tf?1:t<rf?2:t<nf?3:t<of?4:t<sf?5:t<af?6:t<cf?7:t<uf?8:t<ff?9:10},hf={encode:Yu,decode:Ju,encodingLength:lf},df=hf,Jt=df;function er(t,e=0){return[Jt.decode(t,e),Jt.decode.bytes]}function xt(t,e,r=0){return Jt.encode(t,e,r),e}function wt(t){return Jt.encodingLength(t)}function vt(t,e){let r=e.byteLength,n=wt(t),o=n+wt(r),s=new Uint8Array(o+r);return xt(t,s,0),xt(r,s,n),s.set(e,o),new Et(t,r,e,s)}function tr(t){let e=Ee(t),[r,n]=er(e),[o,s]=er(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Et(r,o,i,e)}function Pi(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&Si(t.bytes,r.bytes)}}var Et=class{code;size;digest;bytes;constructor(e,r,n,o){this.code=e,this.size=r,this.digest=n,this.bytes=o}};function Ni(t,e){let{bytes:r,version:n}=t;switch(n){case 0:return mf(r,vo(t),e??te.encoder);default:return bf(r,vo(t),e??Xt.encoder)}}var Li=new WeakMap;function vo(t){let e=Li.get(t);if(e==null){let r=new Map;return Li.set(t,r),r}return e}var pe=class t{code;version;multihash;bytes;"/";constructor(e,r,n,o){this.code=r,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:r}=this;if(e!==rr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==gf)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:r}=this.multihash,n=vt(e,r);return t.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&Pi(e.multihash,n.multihash)}toString(e){return Ni(this,e)}toJSON(){return{"/":Ni(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new t(n,o,s,i??Oi(n,o,s.bytes))}else if(r[yf]===!0){let{version:n,multihash:o,code:s}=r,i=tr(o);return t.create(n,s,i)}else return null}static create(e,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(r!==rr)throw new Error(`Version 0 CID must use dag-pb (code: ${rr}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let o=Oi(e,r,n.bytes);return new t(e,r,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,rr,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,o=Ee(e.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new Et(r.multihashCode,r.digestSize,s,o);return[r.version===0?t.createV0(i):t.createV1(r.codec,i),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[f,x]=er(e.subarray(r));return r+=x,f},o=n(),s=rr;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),u=r+c,l=u-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:l,size:u}}static parse(e,r){let[n,o]=pf(e,r),s=t.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return vo(s).set(n,e),s}};function pf(t,e){switch(t[0]){case"Q":{let r=e??te;return[te.prefix,r.decode(`${te.prefix}${t}`)]}case te.prefix:{let r=e??te;return[te.prefix,r.decode(t)]}case Xt.prefix:{let r=e??Xt;return[Xt.prefix,r.decode(t)]}case qr.prefix:{let r=e??qr;return[qr.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function mf(t,e,r){let{prefix:n}=r;if(n!==te.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=e.get(n);if(o==null){let s=r.encode(t).slice(1);return e.set(n,s),s}else return o}function bf(t,e,r){let{prefix:n}=r,o=e.get(n);if(o==null){let s=r.encode(t);return e.set(n,s),s}else return o}var rr=112,gf=18;function Oi(t,e,r){let n=wt(t),o=n+wt(e),s=new Uint8Array(o+r.byteLength);return xt(t,s,0),xt(e,s,n),s.set(r,o),s}var yf=Symbol.for("@ipld/js-cid/CID");var Ti=0,xf="identity",ki=Ee;function wf(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return vt(Ti,ki(t))}var Ne={code:Ti,name:xf,encode:ki,digest:wf};var Ef=parseInt("11111",2),So=parseInt("10000000",2),vf=parseInt("01111111",2),Ki={0:nr,1:nr,2:Sf,3:_f,4:If,5:Af,6:Cf,16:nr,22:nr,48:nr};function Co(t,e={offset:0}){let r=t[e.offset]&Ef;if(e.offset++,Ki[r]!=null)return Ki[r](t,e);throw new Error("No decoder for tag "+r)}function or(t,e){let r=0;if((t[e.offset]&So)===So){let n=t[e.offset]&vf,o="0x";e.offset++;for(let s=0;s<n;s++,e.offset++)o+=t[e.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=t[e.offset],e.offset++;return r}function nr(t,e){or(t,e);let r=[];for(;!(e.offset>=t.byteLength);){let n=Co(t,e);if(n===null)break;r.push(n)}return r}function Sf(t,e){let r=or(t,e),n=e.offset,o=e.offset+r,s=[];for(let i=n;i<o;i++)i===n&&t[i]===0||s.push(t[i]);return e.offset+=r,Uint8Array.from(s)}function Cf(t,e){let r=or(t,e),n=e.offset+r,o=t[e.offset];e.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;e.offset<n;){let u=t[e.offset];if(e.offset++,c.push(u&127),u<128){c.reverse();let l=0;for(let f=0;f<c.length;f++)l+=c[f]<<f*7;a+=`.${l}`,c=[]}}return a}function Af(t,e){return e.offset++,null}function _f(t,e){let r=or(t,e),n=t[e.offset];e.offset++;let o=t.subarray(e.offset,e.offset+r-1);if(e.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function If(t,e){let r=or(t,e),n=t.subarray(e.offset,e.offset+r);return e.offset+=r,n}function Df(t){let e=t.toString(16);e.length%2===1&&(e="0"+e);let r=new ee;for(let n=0;n<e.length;n+=2)r.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return r}function Ao(t){if(t.byteLength<128)return Uint8Array.from([t.byteLength]);let e=Df(t.byteLength);return new ee(Uint8Array.from([e.byteLength|So]),e)}function Ui(t){let e=new ee,r=128;return(t.subarray()[0]&r)===r&&e.append(Uint8Array.from([0])),e.append(t),new ee(Uint8Array.from([2]),Ao(e),e)}function Vi(t){let e=Uint8Array.from([0]),r=new ee(e,t);return new ee(Uint8Array.from([3]),Ao(r),r)}function Hr(t,e=48){let r=new ee;for(let n of t)r.append(n);return new ee(Uint8Array.from([e]),Ao(r),r)}async function qi(t,e,r,n){let o=await crypto.subtle.importKey("jwk",t,{name:"ECDSA",namedCurve:t.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,e,r.subarray());return n?.signal?.throwIfAborted(),s}var Rf=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Bf=Uint8Array.from([6,5,43,129,4,0,34]),Pf=Uint8Array.from([6,5,43,129,4,0,35]),Nf={ext:!0,kty:"EC",crv:"P-256"},Lf={ext:!0,kty:"EC",crv:"P-384"},Of={ext:!0,kty:"EC",crv:"P-521"},_o=32,Io=48,Do=66;function Mi(t){let e=Co(t);return Hi(e)}function Hi(t){let e=t[1][1][0],r=1,n,o;if(e.byteLength===_o*2+1)return n=X(e.subarray(r,r+_o),"base64url"),o=X(e.subarray(r+_o),"base64url"),new St({...Nf,key_ops:["verify"],x:n,y:o});if(e.byteLength===Io*2+1)return n=X(e.subarray(r,r+Io),"base64url"),o=X(e.subarray(r+Io),"base64url"),new St({...Lf,key_ops:["verify"],x:n,y:o});if(e.byteLength===Do*2+1)return n=X(e.subarray(r,r+Do),"base64url"),o=X(e.subarray(r+Do),"base64url"),new St({...Of,key_ops:["verify"],x:n,y:o});throw new Be(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function Fi(t){return Hr([Ui(Uint8Array.from([1])),Hr([Tf(t.crv)],160),Hr([Vi(new ee(Uint8Array.from([4]),le(t.x??"","base64url"),le(t.y??"","base64url")))],161)]).subarray()}function Tf(t){if(t==="P-256")return Rf;if(t==="P-384")return Bf;if(t==="P-521")return Pf;throw new Be(`Invalid curve ${t}`)}var St=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=Fi(this.jwk)),this._raw}toMultihash(){return Ne.digest(Ct(this))}toCID(){return pe.createV1(114,this.toMultihash())}toString(){return te.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:he(this.raw,e.raw)}async verify(e,r,n){return qi(this.jwk,r,e,n)}};import Ro from"crypto";var qm=Ro.generateKeyPairSync,sr=32;var kf=64;function $i(t,e,r){if(t.byteLength!==sr)throw new TypeError('"key" must be 32 bytes in length.');if(!(t instanceof Uint8Array))throw new TypeError('"key" must be a node.js Buffer, or Uint8Array.');if(e.byteLength!==kf)throw new TypeError('"sig" must be 64 bytes in length.');if(!(e instanceof Uint8Array))throw new TypeError('"sig" must be a node.js Buffer, or Uint8Array.');let n=Ro.createPublicKey({format:"jwk",key:{crv:"Ed25519",x:X(t,"base64url"),kty:"OKP"}});return Ro.verify(null,r instanceof Uint8Array?r:r.subarray(),n,e)}function zi(t){return t==null?!1:typeof t.then=="function"&&typeof t.catch=="function"&&typeof t.finally=="function"}var Fr=class{type="Ed25519";raw;constructor(e){this.raw=Bo(e,sr)}toMultihash(){return Ne.digest(Ct(this))}toCID(){return pe.createV1(114,this.toMultihash())}toString(){return te.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:he(this.raw,e.raw)}verify(e,r,n){n?.signal?.throwIfAborted();let o=$i(this.raw,r,e);return zi(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Wi(t){return t=Bo(t,sr),new Fr(t)}function Bo(t,e){if(t=Uint8Array.from(t??[]),t.length!==e)throw new Be(`Key must be a Uint8Array of length ${e}, got ${t.length}`);return t}var me;(function(t){t.RSA="RSA",t.Ed25519="Ed25519",t.secp256k1="secp256k1",t.ECDSA="ECDSA"})(me||(me={}));var Po;(function(t){t[t.RSA=0]="RSA",t[t.Ed25519=1]="Ed25519",t[t.secp256k1=2]="secp256k1",t[t.ECDSA=3]="ECDSA"})(Po||(Po={}));(function(t){t.codec=()=>Yt(Po)})(me||(me={}));var ir;(function(t){let e;t.codec=()=>(e==null&&(e=et((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),me.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{s.Type=me.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return s})),e),t.encode=r=>Je(r,t.codec()),t.decode=(r,n)=>Qe(r,t.codec(),n)})(ir||(ir={}));var No;(function(t){let e;t.codec=()=>(e==null&&(e=et((r,n,o={})=>{o.lengthDelimited!==!1&&n.fork(),r.Type!=null&&(n.uint32(8),me.codec().encode(r.Type,n)),r.Data!=null&&(n.uint32(18),n.bytes(r.Data)),o.lengthDelimited!==!1&&n.ldelim()},(r,n,o={})=>{let s={},i=n==null?r.len:r.pos+n;for(;r.pos<i;){let a=r.uint32();switch(a>>>3){case 1:{s.Type=me.codec().decode(r);break}case 2:{s.Data=r.bytes();break}default:{r.skipType(a&7);break}}}return s})),e),t.encode=r=>Je(r,t.codec()),t.decode=(r,n)=>Qe(r,t.codec(),n)})(No||(No={}));function ar(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Le(t,e=""){if(!Number.isSafeInteger(t)||t<0){let r=e&&`"${e}" `;throw new Error(`${r}expected integer >= 0, got ${t}`)}}function H(t,e,r=""){let n=ar(t),o=t?.length,s=e!==void 0;if(!n||s&&o!==e){let i=r&&`"${r}" `,a=s?` of length ${e}`:"",c=n?`length=${o}`:`type=${typeof t}`;throw new Error(i+"expected Uint8Array"+a+", got "+c)}return t}function $r(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash must wrapped by utils.createHasher");Le(t.outputLen),Le(t.blockLen)}function At(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function Yi(t,e){H(t,void 0,"digestInto() output");let r=e.outputLen;if(t.length<r)throw new Error('"digestInto() output" expected to be of length >='+r)}function tt(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function jr(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function ve(t,e){return t<<32-e|t>>>e}var Zi=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Vf=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function rt(t){if(H(t),Zi)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=Vf[t[r]];return e}var Te={_0:48,_9:57,A:65,F:70,a:97,f:102};function Gi(t){if(t>=Te._0&&t<=Te._9)return t-Te._0;if(t>=Te.A&&t<=Te.F)return t-(Te.A-10);if(t>=Te.a&&t<=Te.f)return t-(Te.a-10)}function nt(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);if(Zi)return Uint8Array.fromHex(t);let e=t.length,r=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=Gi(t.charCodeAt(s)),a=Gi(t.charCodeAt(s+1));if(i===void 0||a===void 0){let c=t[s]+t[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Se(...t){let e=0;for(let n=0;n<t.length;n++){let o=t[n];H(o),e+=o.length}let r=new Uint8Array(e);for(let n=0,o=0;n<t.length;n++){let s=t[n];r.set(s,o),o+=s.length}return r}function Qi(t,e={}){let r=(o,s)=>t(s).update(o).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.create=o=>t(o),Object.assign(r,e),Object.freeze(r)}function zr(t=32){let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return e.getRandomValues(new Uint8Array(t))}var Xi=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function Ji(t,e,r){return t&e^~t&r}function ea(t,e,r){return t&e^t&r^e&r}var Wr=class{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,r,n,o){this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(e),this.view=jr(this.buffer)}update(e){At(this),H(e);let{view:r,buffer:n,blockLen:o}=this,s=e.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=jr(e);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(e.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){At(this),Yi(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,tt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let f=i;f<o;f++)r[f]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let a=jr(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=c/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)a.setUint32(4*f,l[f],s)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return e.destroyed=i,e.finished=s,e.length=o,e.pos=a,o%r&&e.buffer.set(n),e}clone(){return this._cloneInto()}},ke=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var qf=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),je=new Uint32Array(64),Lo=class extends Wr{constructor(e){super(64,e,8,!1)}get(){let{A:e,B:r,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[e,r,n,o,s,i,a,c]}set(e,r,n,o,s,i,a,c){this.A=e|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(e,r){for(let f=0;f<16;f++,r+=4)je[f]=e.getUint32(r,!1);for(let f=16;f<64;f++){let x=je[f-15],g=je[f-2],h=ve(x,7)^ve(x,18)^x>>>3,w=ve(g,17)^ve(g,19)^g>>>10;je[f]=w+je[f-7]+h+je[f-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:u,H:l}=this;for(let f=0;f<64;f++){let x=ve(a,6)^ve(a,11)^ve(a,25),g=l+x+Ji(a,c,u)+qf[f]+je[f]|0,w=(ve(n,2)^ve(n,13)^ve(n,22))+ea(n,o,s)|0;l=u,u=c,c=a,a=i+g|0,i=s,s=o,o=n,n=g+w|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(n,o,s,i,a,c,u,l)}roundClean(){tt(je)}destroy(){this.set(0,0,0,0,0,0,0,0),tt(this.buffer)}},Oo=class extends Lo{A=ke[0]|0;B=ke[1]|0;C=ke[2]|0;D=ke[3]|0;E=ke[4]|0;F=ke[5]|0;G=ke[6]|0;H=ke[7]|0;constructor(){super(32)}};var ta=Qi(()=>new Oo,Xi(1));import nl from"node:crypto";var ko=BigInt(0),To=BigInt(1);function cr(t,e=""){if(typeof t!="boolean"){let r=e&&`"${e}" `;throw new Error(r+"expected boolean, got type="+typeof t)}return t}function ra(t){if(typeof t=="bigint"){if(!Gr(t))throw new Error("positive bigint expected, got "+t)}else Le(t);return t}function ur(t){let e=ra(t).toString(16);return e.length&1?"0"+e:e}function na(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?ko:BigInt("0x"+t)}function _t(t){return na(rt(t))}function Ko(t){return na(rt(Mf(H(t)).reverse()))}function Yr(t,e){Le(e),t=ra(t);let r=nt(t.toString(16).padStart(e*2,"0"));if(r.length!==e)throw new Error("number too large");return r}function Uo(t,e){return Yr(t,e).reverse()}function Mf(t){return Uint8Array.from(t)}var Gr=t=>typeof t=="bigint"&&ko<=t;function Hf(t,e,r){return Gr(t)&&Gr(e)&&Gr(r)&&e<=t&&t<r}function oa(t,e,r,n){if(!Hf(e,r,n))throw new Error("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function Vo(t){let e;for(e=0;t>ko;t>>=To,e+=1);return e}var fr=t=>(To<<BigInt(t))-To;function sa(t,e,r){if(Le(t,"hashLen"),Le(e,"qByteLen"),typeof r!="function")throw new Error("hmacFn must be a function");let n=y=>new Uint8Array(y),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(t),u=n(t),l=0,f=()=>{c.fill(1),u.fill(0),l=0},x=(...y)=>r(u,Se(c,...y)),g=(y=o)=>{u=x(s,y),c=x(),y.length!==0&&(u=x(i,y),c=x())},h=()=>{if(l++>=a)throw new Error("drbg: tried max amount of iterations");let y=0,S=[];for(;y<e;){c=x();let P=c.slice();S.push(P),y+=c.length}return Se(...S)};return(y,S)=>{f(),g(y);let P;for(;!(P=S(h()));)g();return f(),P}}function lr(t,e={},r={}){if(!t||typeof t!="object")throw new Error("expected valid options object");function n(s,i,a){let c=t[s];if(a&&c===void 0)return;let u=typeof c;if(u!==i||c===null)throw new Error(`param "${s}" is invalid: expected ${i}, got ${u}`)}let o=(s,i)=>Object.entries(s).forEach(([a,c])=>n(a,c,i));o(e,!1),o(r,!0)}function qo(t){let e=new WeakMap;return(r,...n)=>{let o=e.get(r);if(o!==void 0)return o;let s=t(r,...n);return e.set(r,s),s}}var fe=BigInt(0),ce=BigInt(1),ot=BigInt(2),ca=BigInt(3),ua=BigInt(4),fa=BigInt(5),Ff=BigInt(7),la=BigInt(8),$f=BigInt(9),ha=BigInt(16);function Ce(t,e){let r=t%e;return r>=fe?r:e+r}function be(t,e,r){let n=t;for(;e-- >fe;)n*=n,n%=r;return n}function ia(t,e){if(t===fe)throw new Error("invert: expected non-zero number");if(e<=fe)throw new Error("invert: expected positive modulus, got "+e);let r=Ce(t,e),n=e,o=fe,s=ce,i=ce,a=fe;for(;r!==fe;){let u=n/r,l=n%r,f=o-i*u,x=s-a*u;n=r,r=l,o=i,s=a,i=f,a=x}if(n!==ce)throw new Error("invert: does not exist");return Ce(o,e)}function Ho(t,e,r){if(!t.eql(t.sqr(e),r))throw new Error("Cannot find square root")}function da(t,e){let r=(t.ORDER+ce)/ua,n=t.pow(e,r);return Ho(t,n,e),n}function jf(t,e){let r=(t.ORDER-fa)/la,n=t.mul(e,ot),o=t.pow(n,r),s=t.mul(e,o),i=t.mul(t.mul(s,ot),o),a=t.mul(s,t.sub(i,t.ONE));return Ho(t,a,e),a}function zf(t){let e=It(t),r=pa(t),n=r(e,e.neg(e.ONE)),o=r(e,n),s=r(e,e.neg(n)),i=(t+Ff)/ha;return(a,c)=>{let u=a.pow(c,i),l=a.mul(u,n),f=a.mul(u,o),x=a.mul(u,s),g=a.eql(a.sqr(l),c),h=a.eql(a.sqr(f),c);u=a.cmov(u,l,g),l=a.cmov(x,f,h);let w=a.eql(a.sqr(l),c),y=a.cmov(u,l,w);return Ho(a,y,c),y}}function pa(t){if(t<ca)throw new Error("sqrt is not defined for small field");let e=t-ce,r=0;for(;e%ot===fe;)e/=ot,r++;let n=ot,o=It(t);for(;aa(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return da;let s=o.pow(n,e),i=(e+ce)/ot;return function(c,u){if(c.is0(u))return u;if(aa(c,u)!==1)throw new Error("Cannot find square root");let l=r,f=c.mul(c.ONE,s),x=c.pow(u,e),g=c.pow(u,i);for(;!c.eql(x,c.ONE);){if(c.is0(x))return c.ZERO;let h=1,w=c.sqr(x);for(;!c.eql(w,c.ONE);)if(h++,w=c.sqr(w),h===l)throw new Error("Cannot find square root");let y=ce<<BigInt(l-h-1),S=c.pow(f,y);l=h,f=c.sqr(S),x=c.mul(x,f),g=c.mul(g,S)}return g}}function Wf(t){return t%ua===ca?da:t%la===fa?jf:t%ha===$f?zf(t):pa(t)}var Gf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Fo(t){let e={ORDER:"bigint",BYTES:"number",BITS:"number"},r=Gf.reduce((n,o)=>(n[o]="function",n),e);return lr(t,r),t}function Yf(t,e,r){if(r<fe)throw new Error("invalid exponent, negatives unsupported");if(r===fe)return t.ONE;if(r===ce)return e;let n=t.ONE,o=e;for(;r>fe;)r&ce&&(n=t.mul(n,o)),o=t.sqr(o),r>>=ce;return n}function Zr(t,e,r=!1){let n=new Array(e.length).fill(r?t.ZERO:void 0),o=e.reduce((i,a,c)=>t.is0(a)?i:(n[c]=i,t.mul(i,a)),t.ONE),s=t.inv(o);return e.reduceRight((i,a,c)=>t.is0(a)?i:(n[c]=t.mul(i,n[c]),t.mul(i,a)),s),n}function aa(t,e){let r=(t.ORDER-ce)/ot,n=t.pow(e,r),o=t.eql(n,t.ONE),s=t.eql(n,t.ZERO),i=t.eql(n,t.neg(t.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function Zf(t,e){e!==void 0&&Le(e);let r=e!==void 0?e:t.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}var Mo=class{ORDER;BITS;BYTES;isLE;ZERO=fe;ONE=ce;_lengths;_sqrt;_mod;constructor(e,r={}){if(e<=fe)throw new Error("invalid field: expected ORDER > 0, got "+e);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&(this.sqrt=r.sqrt),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=r.allowedLengths?.slice()),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:o,nByteLength:s}=Zf(e,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=e,this.BITS=o,this.BYTES=s,this._sqrt=void 0,Object.preventExtensions(this)}create(e){return Ce(e,this.ORDER)}isValid(e){if(typeof e!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof e);return fe<=e&&e<this.ORDER}is0(e){return e===fe}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&ce)===ce}neg(e){return Ce(-e,this.ORDER)}eql(e,r){return e===r}sqr(e){return Ce(e*e,this.ORDER)}add(e,r){return Ce(e+r,this.ORDER)}sub(e,r){return Ce(e-r,this.ORDER)}mul(e,r){return Ce(e*r,this.ORDER)}pow(e,r){return Yf(this,e,r)}div(e,r){return Ce(e*ia(r,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,r){return e+r}subN(e,r){return e-r}mulN(e,r){return e*r}inv(e){return ia(e,this.ORDER)}sqrt(e){return this._sqrt||(this._sqrt=Wf(this.ORDER)),this._sqrt(this,e)}toBytes(e){return this.isLE?Uo(e,this.BYTES):Yr(e,this.BYTES)}fromBytes(e,r=!1){H(e);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=this;if(n){if(!n.includes(e.length)||e.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+e.length);let u=new Uint8Array(o);u.set(e,s?0:u.length-e.length),e=u}if(e.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+e.length);let c=s?Ko(e):_t(e);if(a&&(c=Ce(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(e){return Zr(this,e)}cmov(e,r,n){return n?r:e}};function It(t,e={}){return new Mo(t,e)}function ma(t){if(typeof t!="bigint")throw new Error("field order must be bigint");let e=t.toString(2).length;return Math.ceil(e/8)}function $o(t){let e=ma(t);return e+Math.ceil(e/2)}function jo(t,e,r=!1){H(t);let n=t.length,o=ma(e),s=$o(e);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Ko(t):_t(t),a=Ce(i,e-ce)+ce;return r?Uo(a,o):Yr(a,o)}var Dt=BigInt(0),st=BigInt(1);function hr(t,e){let r=e.negate();return t?r:e}function Yo(t,e){let r=Zr(t.Fp,e.map(n=>n.Z));return e.map((n,o)=>t.fromAffine(n.toAffine(r[o])))}function xa(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function zo(t,e){xa(t,e);let r=Math.ceil(e/t)+1,n=2**(t-1),o=2**t,s=fr(t),i=BigInt(t);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function ba(t,e,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,a=Number(t&o),c=t>>i;a>n&&(a-=s,c+=st);let u=e*n,l=u+Math.abs(a)-1,f=a===0,x=a<0,g=e%2!==0;return{nextN:c,offset:l,isZero:f,isNeg:x,isNegF:g,offsetF:u}}var Wo=new WeakMap,wa=new WeakMap;function Go(t){return wa.get(t)||1}function ga(t){if(t!==Dt)throw new Error("invalid wNAF")}var Qr=class{BASE;ZERO;Fn;bits;constructor(e,r){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=r}_unsafeLadder(e,r,n=this.ZERO){let o=e;for(;r>Dt;)r&st&&(n=n.add(o)),o=o.double(),r>>=st;return n}precomputeWindow(e,r){let{windows:n,windowSize:o}=zo(r,this.bits),s=[],i=e,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let u=1;u<o;u++)a=a.add(i),s.push(a);i=a.double()}return s}wNAF(e,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=zo(e,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:u,isZero:l,isNeg:f,isNegF:x,offsetF:g}=ba(n,a,i);n=c,l?s=s.add(hr(x,r[g])):o=o.add(hr(f,r[u]))}return ga(n),{p:o,f:s}}wNAFUnsafe(e,r,n,o=this.ZERO){let s=zo(e,this.bits);for(let i=0;i<s.windows&&n!==Dt;i++){let{nextN:a,offset:c,isZero:u,isNeg:l}=ba(n,i,s);if(n=a,!u){let f=r[c];o=o.add(l?f.negate():f)}}return ga(n),o}getPrecomputes(e,r,n){let o=Wo.get(r);return o||(o=this.precomputeWindow(r,e),e!==1&&(typeof n=="function"&&(o=n(o)),Wo.set(r,o))),o}cached(e,r,n){let o=Go(e);return this.wNAF(o,this.getPrecomputes(o,e,n),r)}unsafe(e,r,n,o){let s=Go(e);return s===1?this._unsafeLadder(e,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,e,n),r,o)}createCache(e,r){xa(r,this.bits),wa.set(e,r),Wo.delete(e)}hasCache(e){return Go(e)!==1}};function Ea(t,e,r,n){let o=e,s=t.ZERO,i=t.ZERO;for(;r>Dt||n>Dt;)r&st&&(s=s.add(o)),n&st&&(i=i.add(o)),o=o.double(),r>>=st,n>>=st;return{p1:s,p2:i}}function ya(t,e,r){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Fo(e),e}else return It(t,{isLE:r})}function va(t,e,r={},n){if(n===void 0&&(n=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);for(let c of["p","n","h"]){let u=e[c];if(!(typeof u=="bigint"&&u>Dt))throw new Error(`CURVE.${c} must be positive bigint`)}let o=ya(e.p,r.Fp,n),s=ya(e.n,r.Fn,n),a=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:o,Fn:s}}function Sa(t,e){return function(n){let o=t(n);return{secretKey:o,publicKey:e(o)}}}var Xr=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(e,r){if($r(e),H(r,void 0,"key"),this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?e.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=e.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),tt(o)}update(e){return At(this),this.iHash.update(e),this}digestInto(e){At(this),H(e,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return e=e,e.finished=o,e.destroyed=s,e.blockLen=i,e.outputLen=a,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},Zo=(t,e,r)=>new Xr(t,e).update(r).digest();Zo.create=(t,e)=>new Xr(t,e);var Ca=(t,e)=>(t+(t>=0?e:-e)/Aa)/e;function Qf(t,e,r){let[[n,o],[s,i]]=e,a=Ca(i*t,r),c=Ca(-o*t,r),u=t-a*n-c*s,l=-a*o-c*i,f=u<Ke,x=l<Ke;f&&(u=-u),x&&(l=-l);let g=fr(Math.ceil(Vo(r)/2))+Rt;if(u<Ke||u>=g||l<Ke||l>=g)throw new Error("splitScalar (endomorphism): failed, k="+t);return{k1neg:f,k1:u,k2neg:x,k2:l}}function Xo(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function Qo(t,e){let r={};for(let n of Object.keys(e))r[n]=t[n]===void 0?e[n]:t[n];return cr(r.lowS,"lowS"),cr(r.prehash,"prehash"),r.format!==void 0&&Xo(r.format),r}var Jo=class extends Error{constructor(e=""){super(e)}},ze={Err:Jo,_tlv:{encode:(t,e)=>{let{Err:r}=ze;if(t<0||t>256)throw new r("tlv.encode: wrong tag");if(e.length&1)throw new r("tlv.encode: unpadded data");let n=e.length/2,o=ur(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?ur(o.length/2|128):"";return ur(t)+s+o+e},decode(t,e){let{Err:r}=ze,n=0;if(t<0||t>256)throw new r("tlv.encode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");let o=e[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=e.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let l of u)i=i<<8|l;if(n+=c,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=e.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+i)}}},_int:{encode(t){let{Err:e}=ze;if(t<Ke)throw new e("integer: negative integers are not allowed");let r=ur(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){let{Err:e}=ze;if(t[0]&128)throw new e("invalid signature integer: negative");if(t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return _t(t)}},toSig(t){let{Err:e,_int:r,_tlv:n}=ze,o=H(t,void 0,"signature"),{v:s,l:i}=n.decode(48,o);if(i.length)throw new e("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:u,l}=n.decode(2,c);if(l.length)throw new e("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(u)}},hexFromSig(t){let{_tlv:e,_int:r}=ze,n=e.encode(2,r.encode(t.r)),o=e.encode(2,r.encode(t.s)),s=n+o;return e.encode(48,s)}},Ke=BigInt(0),Rt=BigInt(1),Aa=BigInt(2),Jr=BigInt(3),Xf=BigInt(4);function _a(t,e={}){let r=va("weierstrass",t,e),{Fp:n,Fn:o}=r,s=r.CURVE,{h:i,n:a}=s;lr(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c}=e;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=Da(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function f(V,b,m){let{x:d,y:v}=b.toAffine(),A=n.toBytes(d);if(cr(m,"isCompressed"),m){l();let D=!n.isOdd(v);return Se(Ia(D),A)}else return Se(Uint8Array.of(4),A,n.toBytes(v))}function x(V){H(V,void 0,"Point");let{publicKey:b,publicKeyUncompressed:m}=u,d=V.length,v=V[0],A=V.subarray(1);if(d===b&&(v===2||v===3)){let D=n.fromBytes(A);if(!n.isValid(D))throw new Error("bad point: is not on curve, wrong x");let I=w(D),C;try{C=n.sqrt(I)}catch(J){let W=J instanceof Error?": "+J.message:"";throw new Error("bad point: is not on curve, sqrt error"+W)}l();let R=n.isOdd(C);return(v&1)===1!==R&&(C=n.neg(C)),{x:D,y:C}}else if(d===m&&v===4){let D=n.BYTES,I=n.fromBytes(A.subarray(0,D)),C=n.fromBytes(A.subarray(D,D*2));if(!y(I,C))throw new Error("bad point: is not on curve");return{x:I,y:C}}else throw new Error(`bad point: got length ${d}, expected compressed=${b} or uncompressed=${m}`)}let g=e.toBytes||f,h=e.fromBytes||x;function w(V){let b=n.sqr(V),m=n.mul(b,V);return n.add(n.add(m,n.mul(V,s.a)),s.b)}function y(V,b){let m=n.sqr(b),d=w(V);return n.eql(m,d)}if(!y(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let S=n.mul(n.pow(s.a,Jr),Xf),P=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(S,P)))throw new Error("bad curve params: a or b");function O(V,b,m=!1){if(!n.isValid(b)||m&&n.is0(b))throw new Error(`bad point coordinate ${V}`);return b}function B(V){if(!(V instanceof N))throw new Error("Weierstrass Point expected")}function K(V){if(!c||!c.basises)throw new Error("no endo");return Qf(V,c.basises,o.ORDER)}let F=qo((V,b)=>{let{X:m,Y:d,Z:v}=V;if(n.eql(v,n.ONE))return{x:m,y:d};let A=V.is0();b==null&&(b=A?n.ONE:n.inv(v));let D=n.mul(m,b),I=n.mul(d,b),C=n.mul(v,b);if(A)return{x:n.ZERO,y:n.ZERO};if(!n.eql(C,n.ONE))throw new Error("invZ was invalid");return{x:D,y:I}}),M=qo(V=>{if(V.is0()){if(e.allowInfinityPoint&&!n.is0(V.Y))return;throw new Error("bad point: ZERO")}let{x:b,y:m}=V.toAffine();if(!n.isValid(b)||!n.isValid(m))throw new Error("bad point: x or y not field elements");if(!y(b,m))throw new Error("bad point: equation left != right");if(!V.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function $(V,b,m,d,v){return m=new N(n.mul(m.X,V),m.Y,m.Z),b=hr(d,b),m=hr(v,m),b.add(m)}class N{static BASE=new N(s.Gx,s.Gy,n.ONE);static ZERO=new N(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(b,m,d){this.X=O("x",b),this.Y=O("y",m,!0),this.Z=O("z",d),Object.freeze(this)}static CURVE(){return s}static fromAffine(b){let{x:m,y:d}=b||{};if(!b||!n.isValid(m)||!n.isValid(d))throw new Error("invalid affine point");if(b instanceof N)throw new Error("projective point not allowed");return n.is0(m)&&n.is0(d)?N.ZERO:new N(m,d,n.ONE)}static fromBytes(b){let m=N.fromAffine(h(H(b,void 0,"point")));return m.assertValidity(),m}static fromHex(b){return N.fromBytes(nt(b))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=8,m=!0){return We.createCache(this,b),m||this.multiply(Jr),this}assertValidity(){M(this)}hasEvenY(){let{y:b}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(b)}equals(b){B(b);let{X:m,Y:d,Z:v}=this,{X:A,Y:D,Z:I}=b,C=n.eql(n.mul(m,I),n.mul(A,v)),R=n.eql(n.mul(d,I),n.mul(D,v));return C&&R}negate(){return new N(this.X,n.neg(this.Y),this.Z)}double(){let{a:b,b:m}=s,d=n.mul(m,Jr),{X:v,Y:A,Z:D}=this,I=n.ZERO,C=n.ZERO,R=n.ZERO,L=n.mul(v,v),J=n.mul(A,A),W=n.mul(D,D),k=n.mul(v,A);return k=n.add(k,k),R=n.mul(v,D),R=n.add(R,R),I=n.mul(b,R),C=n.mul(d,W),C=n.add(I,C),I=n.sub(J,C),C=n.add(J,C),C=n.mul(I,C),I=n.mul(k,I),R=n.mul(d,R),W=n.mul(b,W),k=n.sub(L,W),k=n.mul(b,k),k=n.add(k,R),R=n.add(L,L),L=n.add(R,L),L=n.add(L,W),L=n.mul(L,k),C=n.add(C,L),W=n.mul(A,D),W=n.add(W,W),L=n.mul(W,k),I=n.sub(I,L),R=n.mul(W,J),R=n.add(R,R),R=n.add(R,R),new N(I,C,R)}add(b){B(b);let{X:m,Y:d,Z:v}=this,{X:A,Y:D,Z:I}=b,C=n.ZERO,R=n.ZERO,L=n.ZERO,J=s.a,W=n.mul(s.b,Jr),k=n.mul(m,A),Y=n.mul(d,D),ne=n.mul(v,I),Ae=n.add(m,d),Z=n.add(A,D);Ae=n.mul(Ae,Z),Z=n.add(k,Y),Ae=n.sub(Ae,Z),Z=n.add(m,v);let se=n.add(A,I);return Z=n.mul(Z,se),se=n.add(k,ne),Z=n.sub(Z,se),se=n.add(d,v),C=n.add(D,I),se=n.mul(se,C),C=n.add(Y,ne),se=n.sub(se,C),L=n.mul(J,Z),C=n.mul(W,ne),L=n.add(C,L),C=n.sub(Y,L),L=n.add(Y,L),R=n.mul(C,L),Y=n.add(k,k),Y=n.add(Y,k),ne=n.mul(J,ne),Z=n.mul(W,Z),Y=n.add(Y,ne),ne=n.sub(k,ne),ne=n.mul(J,ne),Z=n.add(Z,ne),k=n.mul(Y,Z),R=n.add(R,k),k=n.mul(se,Z),C=n.mul(Ae,C),C=n.sub(C,k),k=n.mul(Ae,Y),L=n.mul(se,L),L=n.add(L,k),new N(C,R,L)}subtract(b){return this.add(b.negate())}is0(){return this.equals(N.ZERO)}multiply(b){let{endo:m}=e;if(!o.isValidNot0(b))throw new Error("invalid scalar: out of range");let d,v,A=D=>We.cached(this,D,I=>Yo(N,I));if(m){let{k1neg:D,k1:I,k2neg:C,k2:R}=K(b),{p:L,f:J}=A(I),{p:W,f:k}=A(R);v=J.add(k),d=$(m.beta,L,W,D,C)}else{let{p:D,f:I}=A(b);d=D,v=I}return Yo(N,[d,v])[0]}multiplyUnsafe(b){let{endo:m}=e,d=this;if(!o.isValid(b))throw new Error("invalid scalar: out of range");if(b===Ke||d.is0())return N.ZERO;if(b===Rt)return d;if(We.hasCache(this))return this.multiply(b);if(m){let{k1neg:v,k1:A,k2neg:D,k2:I}=K(b),{p1:C,p2:R}=Ea(N,d,A,I);return $(m.beta,C,R,v,D)}else return We.unsafe(d,b)}toAffine(b){return F(this,b)}isTorsionFree(){let{isTorsionFree:b}=e;return i===Rt?!0:b?b(N,this):We.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:b}=e;return i===Rt?this:b?b(N,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(b=!0){return cr(b,"isCompressed"),this.assertValidity(),g(N,this,b)}toHex(b=!0){return rt(this.toBytes(b))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let vr=o.BITS,We=new Qr(N,e.endo?Math.ceil(vr/2):vr);return N.BASE.precompute(8),N}function Ia(t){return Uint8Array.of(t?2:3)}function Da(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function Jf(t,e={}){let{Fn:r}=t,n=e.randomBytes||zr,o=Object.assign(Da(t.Fp,r),{seed:$o(r.ORDER)});function s(g){try{let h=r.fromBytes(g);return r.isValidNot0(h)}catch{return!1}}function i(g,h){let{publicKey:w,publicKeyUncompressed:y}=o;try{let S=g.length;return h===!0&&S!==w||h===!1&&S!==y?!1:!!t.fromBytes(g)}catch{return!1}}function a(g=n(o.seed)){return jo(H(g,o.seed,"seed"),r.ORDER)}function c(g,h=!0){return t.BASE.multiply(r.fromBytes(g)).toBytes(h)}function u(g){let{secretKey:h,publicKey:w,publicKeyUncompressed:y}=o;if(!ar(g)||"_lengths"in r&&r._lengths||h===w)return;let S=H(g,void 0,"key").length;return S===w||S===y}function l(g,h,w=!0){if(u(g)===!0)throw new Error("first arg must be private key");if(u(h)===!1)throw new Error("second arg must be public key");let y=r.fromBytes(g);return t.fromBytes(h).multiply(y).toBytes(w)}let f={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},x=Sa(a,c);return Object.freeze({getPublicKey:c,getSharedSecret:l,keygen:x,Point:t,utils:f,lengths:o})}function Ra(t,e,r={}){$r(e),lr(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let n=r.randomBytes||zr,o=r.hmac||((m,d)=>Zo(e,m,d)),{Fp:s,Fn:i}=t,{ORDER:a,BITS:c}=i,{keygen:u,getPublicKey:l,getSharedSecret:f,utils:x,lengths:g}=Jf(t,r),h={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},w=a*Aa<s.ORDER;function y(m){let d=a>>Rt;return m>d}function S(m,d){if(!i.isValidNot0(d))throw new Error(`invalid signature ${m}: out of range 1..Point.Fn.ORDER`);return d}function P(){if(w)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function O(m,d){Xo(d);let v=g.signature,A=d==="compact"?v:d==="recovered"?v+1:void 0;return H(m,A)}class B{r;s;recovery;constructor(d,v,A){if(this.r=S("r",d),this.s=S("s",v),A!=null){if(P(),![0,1,2,3].includes(A))throw new Error("invalid recovery id");this.recovery=A}Object.freeze(this)}static fromBytes(d,v=h.format){O(d,v);let A;if(v==="der"){let{r:R,s:L}=ze.toSig(H(d));return new B(R,L)}v==="recovered"&&(A=d[0],v="compact",d=d.subarray(1));let D=g.signature/2,I=d.subarray(0,D),C=d.subarray(D,D*2);return new B(i.fromBytes(I),i.fromBytes(C),A)}static fromHex(d,v){return this.fromBytes(nt(d),v)}assertRecovery(){let{recovery:d}=this;if(d==null)throw new Error("invalid recovery id: must be present");return d}addRecoveryBit(d){return new B(this.r,this.s,d)}recoverPublicKey(d){let{r:v,s:A}=this,D=this.assertRecovery(),I=D===2||D===3?v+a:v;if(!s.isValid(I))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let C=s.toBytes(I),R=t.fromBytes(Se(Ia((D&1)===0),C)),L=i.inv(I),J=F(H(d,void 0,"msgHash")),W=i.create(-J*L),k=i.create(A*L),Y=t.BASE.multiplyUnsafe(W).add(R.multiplyUnsafe(k));if(Y.is0())throw new Error("invalid recovery: point at infinify");return Y.assertValidity(),Y}hasHighS(){return y(this.s)}toBytes(d=h.format){if(Xo(d),d==="der")return nt(ze.hexFromSig(this));let{r:v,s:A}=this,D=i.toBytes(v),I=i.toBytes(A);return d==="recovered"?(P(),Se(Uint8Array.of(this.assertRecovery()),D,I)):Se(D,I)}toHex(d){return rt(this.toBytes(d))}}let K=r.bits2int||function(d){if(d.length>8192)throw new Error("input is too large");let v=_t(d),A=d.length*8-c;return A>0?v>>BigInt(A):v},F=r.bits2int_modN||function(d){return i.create(K(d))},M=fr(c);function $(m){return oa("num < 2^"+c,m,Ke,M),i.toBytes(m)}function N(m,d){return H(m,void 0,"message"),d?H(e(m),void 0,"prehashed message"):m}function vr(m,d,v){let{lowS:A,prehash:D,extraEntropy:I}=Qo(v,h);m=N(m,D);let C=F(m),R=i.fromBytes(d);if(!i.isValidNot0(R))throw new Error("invalid private key");let L=[$(R),$(C)];if(I!=null&&I!==!1){let Y=I===!0?n(g.secretKey):I;L.push(H(Y,void 0,"extraEntropy"))}let J=Se(...L),W=C;function k(Y){let ne=K(Y);if(!i.isValidNot0(ne))return;let Ae=i.inv(ne),Z=t.BASE.multiply(ne).toAffine(),se=i.create(Z.x);if(se===Ke)return;let Sr=i.create(Ae*i.create(W+se*R));if(Sr===Ke)return;let Vs=(Z.x===se?0:2)|Number(Z.y&Rt),qs=Sr;return A&&y(Sr)&&(qs=i.neg(Sr),Vs^=1),new B(se,qs,w?void 0:Vs)}return{seed:J,k2sig:k}}function We(m,d,v={}){let{seed:A,k2sig:D}=vr(m,d,v);return sa(e.outputLen,i.BYTES,o)(A,D).toBytes(v.format)}function V(m,d,v,A={}){let{lowS:D,prehash:I,format:C}=Qo(A,h);if(v=H(v,void 0,"publicKey"),d=N(d,I),!ar(m)){let R=m instanceof B?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+R)}O(m,C);try{let R=B.fromBytes(m,C),L=t.fromBytes(v);if(D&&R.hasHighS())return!1;let{r:J,s:W}=R,k=F(d),Y=i.inv(W),ne=i.create(k*Y),Ae=i.create(J*Y),Z=t.BASE.multiplyUnsafe(ne).add(L.multiplyUnsafe(Ae));return Z.is0()?!1:i.create(Z.x)===J}catch{return!1}}function b(m,d,v={}){let{prehash:A}=Qo(v,h);return d=N(d,A),B.fromBytes(m,"recovered").recoverPublicKey(d).toBytes()}return Object.freeze({keygen:u,getPublicKey:l,getSharedSecret:f,utils:x,lengths:g,Point:t,sign:We,verify:V,recoverPublicKey:b,Signature:B,hash:e})}var ts={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},el={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Ba=BigInt(2);function tl(t){let e=ts.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),u=t*t*t%e,l=u*u*t%e,f=be(l,r,e)*l%e,x=be(f,r,e)*l%e,g=be(x,Ba,e)*u%e,h=be(g,o,e)*g%e,w=be(h,s,e)*h%e,y=be(w,a,e)*w%e,S=be(y,c,e)*y%e,P=be(S,a,e)*w%e,O=be(P,r,e)*l%e,B=be(O,i,e)*h%e,K=be(B,n,e)*u%e,F=be(K,Ba,e);if(!es.eql(es.sqr(F),t))throw new Error("Cannot find square root");return F}var es=It(ts.p,{sqrt:tl}),rl=_a(ts,{Fp:es,endo:el}),dr=Ra(rl,ta);var en=class extends Error{constructor(e="An error occurred while verifying a message"){super(e),this.name="VerificationError"}};function Pa(t,e,r,n){n?.signal?.throwIfAborted();let o=nl.createHash("sha256");if(r instanceof Uint8Array)o.update(r);else for(let i of r)o.update(i);let s=o.digest();try{return dr.verify(e,s,t,{prehash:!1,format:"der"})}catch(i){throw new en(String(i))}}var tn=class{type="secp256k1";raw;_key;constructor(e){this._key=La(e),this.raw=Na(this._key)}toMultihash(){return Ne.digest(Ct(this))}toCID(){return pe.createV1(114,this.toMultihash())}toString(){return te.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:he(this.raw,e.raw)}verify(e,r,n){return Pa(this._key,r,e,n)}};function Oa(t){return new tn(t)}function Na(t){return dr.Point.fromBytes(t).toBytes()}function La(t){try{return dr.Point.fromBytes(t),t}catch(e){throw new Lr(String(e))}}function Ta(t){let{Type:e,Data:r}=ir.decode(t.digest),n=r??new Uint8Array;switch(e){case me.Ed25519:return Wi(n);case me.secp256k1:return Oa(n);case me.ECDSA:return Mi(n);default:throw new Qt}}function Ct(t){return ir.encode({Type:me[t.type],Data:t.raw})}import Ka from"crypto";var ol=20;function ns({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:o}){return new rs(t,e,r,n,o)}var rs=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,o,s){this.name=e,this.code=r,this.encode=n,this.minDigestLength=o??ol,this.maxDigestLength=s}digest(e,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?ka(n,this.code,r?.truncate):n.then(o=>ka(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function ka(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return vt(e,t)}var Ua=ns({name:"sha2-256",code:18,encode:t=>Ee(Ka.createHash("sha256").update(t).digest())}),v0=ns({name:"sha2-512",code:19,encode:t=>Ee(Ka.createHash("sha512").update(t).digest())});var Va=Symbol.for("nodejs.util.inspect.custom"),sl=114,pr=class{type;multihash;publicKey;string;constructor(e){this.type=e.type,this.multihash=e.multihash,Object.defineProperty(this,"string",{enumerable:!1,writable:!0})}get[Symbol.toStringTag](){return`PeerId(${this.toString()})`}[bo]=!0;toString(){return this.string==null&&(this.string=te.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return pe.createV1(sl,this.multihash)}toJSON(){return this.toString()}equals(e){if(e==null)return!1;if(e instanceof Uint8Array)return he(this.multihash.bytes,e);if(typeof e=="string")return this.toString()===e;if(e?.toMultihash()?.bytes!=null)return he(this.multihash.bytes,e.toMultihash().bytes);throw new Error("not valid Id")}[Va](){return`PeerId(${this.toString()})`}},rn=class extends pr{type="RSA";publicKey;constructor(e){super({...e,type:"RSA"}),this.publicKey=e.publicKey}},nn=class extends pr{type="Ed25519";publicKey;constructor(e){super({...e,type:"Ed25519"}),this.publicKey=e.publicKey}},on=class extends pr{type="secp256k1";publicKey;constructor(e){super({...e,type:"secp256k1"}),this.publicKey=e.publicKey}},il=2336,mr=class{type="url";multihash;publicKey;url;constructor(e){this.url=e.toString(),this.multihash=Ne.digest(le(this.url))}[Va](){return`PeerId(${this.url})`}[bo]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return pe.createV1(il,this.toMultihash())}toJSON(){return this.toString()}equals(e){return e==null?!1:(e instanceof Uint8Array&&(e=X(e)),e.toString()===this.toString())}};var al=114,qa=2336;function br(t,e){let r;if(t.charAt(0)==="1"||t.charAt(0)==="Q")r=tr(te.decode(`z${t}`));else{if(t.startsWith("k51qzi5uqu5")||t.startsWith("kzwfwjn5ji4")||t.startsWith("k2k4r8")||t.startsWith("bafz"))return cl(pe.parse(t));if(e==null)throw new Be('Please pass a multibase decoder for strings that do not start with "1" or "Q"');r=tr(e.decode(t))}return Ma(r)}function Ma(t){if(fl(t))return new rn({multihash:t});if(ul(t))try{let e=Ta(t);if(e.type==="Ed25519")return new nn({multihash:t,publicKey:e});if(e.type==="secp256k1")return new on({multihash:t,publicKey:e})}catch{let r=X(t.digest);return new mr(new URL(r))}throw new kr("Supplied PeerID Multihash is invalid")}function cl(t){if(t?.multihash==null||t.version==null||t.version===1&&t.code!==al&&t.code!==qa)throw new Tr("Supplied PeerID CID is invalid");if(t.code===qa){let e=X(t.multihash.digest);return new mr(new URL(e))}return Ma(t.multihash)}function ul(t){return t.code===Ne.code}function fl(t){return t.code===Ua.code}import{isIPv4 as sn,isIPv6 as Ha,isIP as H0}from"node:net";function an(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var cn=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||(e-1&e)!==0)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},Bt=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new cn(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let r=this.head;this.head=r.next=new cn(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var os=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function Fa(t={}){return ll(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},t)}function ll(t,e){e=e??{};let r=e.onEnd,n=new Bt,o,s,i,a=an(),c=async()=>{try{return n.isEmpty()?i?{done:!0}:await new Promise((y,S)=>{s=P=>{s=null,n.push(P);try{y(t(n))}catch(O){S(O)}return o}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=an()})}},u=y=>s!=null?s(y):(n.push(y),o),l=y=>(n=new Bt,s!=null?s({error:y}):(n.push({error:y}),o)),f=y=>{if(i)return o;if(e?.objectMode!==!0&&y?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:y})},x=y=>i?o:(i=!0,y!=null?l(y):u({done:!0})),g=()=>(n=new Bt,x(),{done:!0}),h=y=>(x(y),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:g,throw:h,push:f,end:x,get readableLength(){return n.size},onEmpty:async y=>{let S=y?.signal;if(S?.throwIfAborted(),n.isEmpty())return;let P,O;S!=null&&(P=new Promise((B,K)=>{O=()=>{K(new os)},S.addEventListener("abort",O)}));try{await Promise.race([a.promise,P])}finally{O!=null&&S!=null&&S?.removeEventListener("abort",O)}}},r==null)return o;let w=o;return o={[Symbol.asyncIterator](){return this},next(){return w.next()},throw(y){return w.throw(y),r!=null&&(r(y),r=void 0),{done:!0}},return(){return w.return(),r!=null&&(r(),r=void 0),{done:!0}},push:f,end(y){return w.end(y),r!=null&&(r(y),r=void 0),o},get readableLength(){return w.readableLength},onEmpty:y=>w.onEmpty(y)},o}var ss=class t extends Error{name="TimeoutError";constructor(e,r){super(e,r),Error.captureStackTrace?.(this,t)}},$a=t=>t.reason??new DOMException("This operation was aborted.","AbortError");function is(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout},signal:i}=e,a,c,l=new Promise((f,x)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(i?.aborted){x($a(i));return}if(i&&(c=()=>{x($a(i))},i.addEventListener("abort",c,{once:!0})),t.then(f,x),r===Number.POSITIVE_INFINITY)return;let g=new ss;a=s.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(h){x(h)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?f():o instanceof Error?x(o):(g.message=o??`Promise timed out after ${r} milliseconds`,x(g))},r)}).finally(()=>{l.clear(),c&&i&&i.removeEventListener("abort",c)});return l.clear=()=>{s.clearTimeout.call(void 0,a),a=void 0},l}var hl=t=>{let e=t.addEventListener||t.on||t.addListener,r=t.removeEventListener||t.off||t.removeListener;if(!e||!r)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(t),removeListener:r.bind(t)}};function dl(t,e,r){let n,o=new Promise((s,i)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!1,resolveImmediately:!1,...r},!(r.count>=0&&(r.count===Number.POSITIVE_INFINITY||Number.isInteger(r.count))))throw new TypeError("The `count` option should be at least 0 or more");r.signal?.throwIfAborted();let a=[e].flat(),c=[],{addListener:u,removeListener:l}=hl(t),f=async(...g)=>{let h=r.multiArgs?g:g[0];if(r.filter)try{if(!await r.filter(h))return}catch(w){n(),i(w);return}c.push(h),r.count===c.length&&(n(),s(c))},x=(...g)=>{n(),i(r.rejectionMultiArgs?g:g[0])};n=()=>{for(let g of a)l(g,f);for(let g of r.rejectionEvents)a.includes(g)||l(g,x)};for(let g of a)u(g,f);for(let g of r.rejectionEvents)a.includes(g)||u(g,x);r.signal&&r.signal.addEventListener("abort",()=>{x(r.signal.reason)},{once:!0}),r.resolveImmediately&&s(c)});if(o.cancel=n,typeof r.timeout=="number"){let s=is(o,{milliseconds:r.timeout});return s.cancel=()=>{n(),s.clear()},s}return o}function Pt(t,e,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=dl(t,e,r),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}var un=class extends Error{static name="StreamClosedError";name="StreamClosedError"};function pl(t){return t.reason}async function ja(t,e,r){if(e==null)return t;let n=r?.translateError??pl;if(e.aborted)return t.catch(()=>{}),Promise.reject(n(e));let o;try{return await Promise.race([t,new Promise((s,i)=>{o=()=>{i(n(e))},e.addEventListener("abort",o)})])}finally{o!=null&&e.removeEventListener("abort",o)}}var ml=Math.pow(2,20)*4,Nt=class extends qe{status;timeline;inactivityTimeout;maxReadBufferLength;maxWriteBufferLength;log;direction;maxMessageSize;readStatus;writeStatus;remoteReadStatus;remoteWriteStatus;writableNeedsDrain;readBuffer;writeBuffer;sendingData;onDrainPromise;constructor(e){super(),this.status="open",this.log=e.log,this.direction=e.direction??"outbound",this.inactivityTimeout=e.inactivityTimeout??12e4,this.maxReadBufferLength=e.maxReadBufferLength??ml,this.maxWriteBufferLength=e.maxWriteBufferLength,this.maxMessageSize=e.maxMessageSize,this.readBuffer=new ee,this.writeBuffer=new ee,this.readStatus="readable",this.remoteReadStatus="readable",this.writeStatus="writable",this.remoteWriteStatus="writable",this.sendingData=!1,this.writableNeedsDrain=!1,this.timeline={open:Date.now()},this.processSendQueue=this.processSendQueue.bind(this);let r=()=>{this.writableNeedsDrain&&(this.log.trace("drain event received, continue sending data"),this.writableNeedsDrain=!1,this.processSendQueue()),this.onDrainPromise?.resolve()};this.addEventListener("drain",r);let n=o=>{this.onDrainPromise?.reject(o.error??new un)};this.addEventListener("close",n)}get readBufferLength(){return this.readBuffer.byteLength}get writeBufferLength(){return this.writeBuffer.byteLength}async onDrain(e){return this.writableNeedsDrain!==!0?Promise.resolve():(this.onDrainPromise==null&&(this.onDrainPromise=Promise.withResolvers()),ja(this.onDrainPromise.promise,e?.signal))}async*[Symbol.asyncIterator](){if(this.readStatus!=="readable"&&this.readStatus!=="paused")return;let e=Fa(),r=s=>{e.push(s.data)};this.addEventListener("message",r);let n=s=>{e.end(s.error)};this.addEventListener("close",n);let o=()=>{e.end()};this.addEventListener("remoteCloseWrite",o);try{yield*e}finally{this.removeEventListener("message",r),this.removeEventListener("close",n),this.removeEventListener("remoteCloseWrite",o)}}isReadable(){return this.status==="open"}send(e){if(this.writeStatus==="closed"||this.writeStatus==="closing")throw new $e(`Cannot write to a stream that is ${this.writeStatus}`);return this.log.trace("append %d bytes to write buffer",e.byteLength),this.writeBuffer.append(e),this.processSendQueue()}abort(e){if(!(this.status==="aborted"||this.status==="reset"||this.status==="closed")){this.log.error("abort with error - %e",e),this.status="aborted",this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle")),this.writeStatus="closed",this.remoteWriteStatus="closed",this.readStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now();try{this.sendReset(e)}catch(r){this.log("failed to send reset to remote - %e",r)}this.dispatchEvent(new Ur(e))}}pause(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new $e("Cannot pause a stream that is closing/closed");this.readStatus!=="paused"&&(this.readStatus="paused",this.sendPause())}resume(){if(this.readStatus==="closed"||this.readStatus==="closing")throw new $e("Cannot resume a stream that is closing/closed");this.readStatus!=="readable"&&(this.readStatus="readable",this.dispatchReadBuffer(),this.sendResume())}push(e){if(this.readStatus==="closed"||this.readStatus==="closing")throw new $e(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.append(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}unshift(e){if(this.readStatus==="closed"||this.readStatus==="closing")throw new $e(`Cannot push data onto a stream that is ${this.readStatus}`);if(e.byteLength!==0){if(this.readBuffer.prepend(e),this.readStatus==="paused"||this.listenerCount("message")===0){this.checkReadBufferLength();return}setTimeout(()=>{this.dispatchReadBuffer()},0)}}onData(e){if(e.byteLength!==0){if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("ignoring data - read status %s",this.readStatus);return}this.readBuffer.append(e),this.dispatchReadBuffer()}}addEventListener(...e){super.addEventListener.apply(this,e),e[0]==="message"&&this.readBuffer.byteLength>0&&queueMicrotask(()=>{this.dispatchReadBuffer()})}onRemoteReset(){this.log("remote reset"),this.status="reset",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.timeline.close=Date.now(),this.readBuffer.byteLength===0&&(this.readStatus="closed");let e=new Or;this.dispatchEvent(new Vr(e))}onTransportClosed(e){this.log("transport closed"),this.readStatus==="readable"&&this.readBuffer.byteLength===0&&(this.log("close readable end after transport closed and read buffer is empty"),this.readStatus="closed"),this.remoteReadStatus!=="closed"&&(this.remoteReadStatus="closed"),this.remoteWriteStatus!=="closed"&&(this.remoteWriteStatus="closed"),this.writeStatus!=="closed"&&(this.writeStatus="closed"),e!=null?this.abort(e):(this.status==="open"||this.status==="closing")&&(this.timeline.close=Date.now(),this.status="closed",this.writeStatus="closed",this.remoteWriteStatus="closed",this.remoteReadStatus="closed",this.dispatchEvent(new gt))}onRemoteCloseWrite(){this.remoteWriteStatus!=="closed"&&(this.log.trace("on remote close write"),this.remoteWriteStatus="closed",this.safeDispatchEvent("remoteCloseWrite"),this.writeStatus==="closed"&&this.onTransportClosed())}onRemoteCloseRead(){this.log.trace("on remote close read"),this.remoteReadStatus="closed",this.writeBuffer.byteLength>0&&(this.writeBuffer.consume(this.writeBuffer.byteLength),this.safeDispatchEvent("idle"))}processSendQueue(){if(this.writableNeedsDrain)return this.log.trace("not processing send queue as drain is required"),this.checkWriteBufferLength(),!1;if(this.writeBuffer.byteLength===0)return this.log.trace("not processing send queue as no bytes to send"),!0;if(this.sendingData)return this.log.trace("not processing send queue as already sending data"),!0;this.sendingData=!0,this.log.trace("processing send queue with %d queued bytes",this.writeBuffer.byteLength);try{let e=!0,r=this.writeBuffer.byteLength,n=0;for(;this.writeBuffer.byteLength>0;){let o=Math.min(this.maxMessageSize??this.writeBuffer.byteLength,this.writeBuffer.byteLength);if(o===0){e=!1;break}let s=this.writeBuffer.sublist(0,o),i=new ee(s);this.writeBuffer.consume(s.byteLength);let a=this.sendData(s);if(e=a.canSendMore,n+=a.sentBytes,a.sentBytes!==i.byteLength&&(i.consume(a.sentBytes),this.writeBuffer.prepend(i)),!e)break}return e||(this.log.trace("sent %d/%d bytes, pausing sending because underlying stream is full, %d bytes left in the write buffer",n,r,this.writeBuffer.byteLength),this.writableNeedsDrain=!0,this.checkWriteBufferLength()),this.writeBuffer.byteLength===0&&this.safeDispatchEvent("idle"),e}finally{this.sendingData=!1}}dispatchReadBuffer(){try{if(this.listenerCount("message")===0){this.log.trace("not dispatching pause buffer as there are no listeners for the message event");return}if(this.readBuffer.byteLength===0){this.log.trace("not dispatching pause buffer as there is no data to dispatch");return}if(this.readStatus==="paused"){this.log.trace("not dispatching pause buffer we are paused");return}if(this.readStatus==="closing"||this.readStatus==="closed"){this.log("dropping %d bytes because the readable end is %s",this.readBuffer.byteLength,this.readStatus),this.readBuffer.consume(this.readBuffer.byteLength);return}let e=this.readBuffer.sublist();this.readBuffer.consume(e.byteLength),this.dispatchEvent(new Kr(e))}finally{this.readBuffer.byteLength===0&&this.remoteWriteStatus==="closed"&&(this.log("close readable end after dispatching read buffer and remote writable end is closed"),this.readStatus="closed"),this.checkReadBufferLength()}}checkReadBufferLength(){this.readBuffer.byteLength>this.maxReadBufferLength&&this.abort(new Zt(`Read buffer length of ${this.readBuffer.byteLength} exceeded limit of ${this.maxReadBufferLength}, read status is ${this.readStatus}`))}checkWriteBufferLength(){this.maxWriteBufferLength!=null&&this.writeBuffer.byteLength>this.maxWriteBufferLength&&this.abort(new Zt(`Write buffer length of ${this.writeBuffer.byteLength} exceeded limit of ${this.maxWriteBufferLength}, write status is ${this.writeStatus}`))}onMuxerNeedsDrain(){this.writableNeedsDrain=!0}onMuxerDrain(){this.safeDispatchEvent("drain")}};var fn=class extends Nt{remoteAddr;metricPrefix;metrics;constructor(e){super(e),this.metricPrefix=e.metricPrefix??"",this.metrics=e.metrics,this.remoteAddr=e.remoteAddr,this.addEventListener("close",r=>{this.metrics?.increment({[`${this.metricPrefix}end`]:!0}),r.error!=null?r.local?this.metrics?.increment({[`${this.metricPrefix}abort`]:!0}):this.metrics?.increment({[`${this.metricPrefix}reset`]:!0}):r.local?this.metrics?.increment({[`${this.metricPrefix}_local_close`]:!0}):this.metrics?.increment({[`${this.metricPrefix}_remote_close`]:!0})})}async close(e){this.status==="open"&&(this.status="closing",this.writeStatus="closing",this.remoteWriteStatus="closing",this.remoteReadStatus="closing",(this.sendingData||this.writeBuffer.byteLength>0)&&(this.log("waiting for write queue to become idle before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await Pt(this,"idle",{...e,rejectionEvents:["close"]})),this.writableNeedsDrain&&(this.log("waiting for write queue to drain before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await Pt(this,"drain",{...e,rejectionEvents:["close"]})),await this.sendClose(e),this.onTransportClosed())}};var ln=class extends Nt{id;protocol;constructor(e){super(e),this.id=e.id,this.protocol=e.protocol??""}async close(e){this.writeStatus==="closing"||this.writeStatus==="closed"||(this.writeStatus="closing",(this.sendingData||this.writeBuffer.byteLength>0)&&(this.log("waiting for write queue to become idle before closing writable end of stream, %d unsent bytes",this.writeBuffer.byteLength),await Pt(this,"idle",{...e,rejectionEvents:["close"]})),this.writableNeedsDrain&&(this.log("waiting for write queue to drain before closing writable end of stream, %d unsent bytes, sending %s",this.writeBuffer.byteLength,this.sendingData),await Pt(this,"drain",{...e,rejectionEvents:["close"]}),this.log("write queue drained, closing writable end of stream, %d unsent bytes, sending %s",this.writeBuffer.byteLength,this.sendingData)),await this.sendCloseWrite(e),this.writeStatus="closed",this.log("closed writable end gracefully"),this.remoteWriteStatus==="closed"&&this.onTransportClosed())}async closeRead(e){this.readStatus==="closing"||this.readStatus==="closed"||(this.readBuffer.byteLength>0&&this.readBuffer.consume(this.readBuffer.byteLength),this.readStatus="closing",await this.sendCloseRead(e),this.readStatus="closed",this.log("closed readable end gracefully"))}};var oe=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},Ue=class extends Error{static name="ValidationError";name="ValidationError"},hn=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},dn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};function cs(t){return e=>X(e,t)}function us(t){return e=>le(e,t)}function Lt(t){return new DataView(t.buffer).getUint16(t.byteOffset).toString()}function it(t){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,typeof t=="string"?parseInt(t):t),new Uint8Array(e)}function za(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let r=le(e[0],"base32"),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=it(n);return Ie([r,o],r.length+o.length)}function Wa(t){let e=t.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let r=He.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=it(n);return Ie([r,o],r.length+o.length)}function fs(t){let e=t.subarray(0,t.length-2),r=t.subarray(t.length-2),n=X(e,"base32"),o=Lt(r);return`${n}:${o}`}var ls=function(t){t=t.toString().trim();let e=new Uint8Array(4);return t.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new oe("Invalid byte value in IP address");e[n]=o}),e},Ga=function(t){let e=0;t=t.toString().trim();let r=t.split(":",8),n;for(n=0;n<r.length;n++){let s=sn(r[n]),i;s&&(i=ls(r[n]),r[n]=X(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,X(i.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let s=[n,1];for(n=9-r.length;n>0;n--)s.push("0");r.splice.apply(r,s)}let o=new Uint8Array(e+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let s=parseInt(r[n],16);if(isNaN(s)||s<0||s>65535)throw new oe("Invalid byte value in IP address");o[e++]=s>>8&255,o[e++]=s&255}return o},Ya=function(t){if(t.byteLength!==4)throw new oe("IPv4 address was incorrect length");let e=[];for(let r=0;r<t.byteLength;r++)e.push(t[r]);return e.join(".")},Za=function(t){if(t.byteLength!==16)throw new oe("IPv6 address was incorrect length");let e=[];for(let n=0;n<t.byteLength;n+=2){let o=t[n],s=t[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;e.push(i)}let r=e.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new oe(`Invalid IPv6 address "${r}"`)}};function Qa(t){try{let e=new URL(`http://[${t}]`);return e.hostname.substring(1,e.hostname.length-1)}catch{throw new oe(`Invalid IPv6 address "${t}"`)}}var as=Object.values(jt).map(t=>t.decoder),bl=function(){let t=as[0].or(as[1]);return as.slice(2).forEach(e=>t=t.or(e)),t}();function Xa(t){return bl.decode(t)}function Ja(t){return e=>t.encoder.encode(e)}function gl(t){if(parseInt(t).toString()!==t)throw new Ue("Value must be an integer")}function yl(t){if(t<0)throw new Ue("Value must be a positive integer, or zero")}function xl(t){return e=>{if(e>t)throw new Ue(`Value must be smaller than or equal to ${t}`)}}function wl(...t){return e=>{for(let r of t)r(e)}}var gr=wl(gl,yl,xl(65535));var re=-1,hs=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(e){let r;if(typeof e=="string"?r=this.protocolsByName.get(e):r=this.protocolsByCode.get(e),r==null)throw new dn(`Protocol ${e} was unknown`);return r}addProtocol(e){this.protocolsByCode.set(e.code,e),this.protocolsByName.set(e.name,e),e.aliases?.forEach(r=>{this.protocolsByName.set(r,e)})}removeProtocol(e){let r=this.protocolsByCode.get(e);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},Ve=new hs,Tl=[{code:4,name:"ip4",size:32,valueToBytes:ls,bytesToValue:Ya,validate:t=>{if(!sn(t))throw new Ue(`Invalid IPv4 address "${t}"`)}},{code:6,name:"tcp",size:16,valueToBytes:it,bytesToValue:Lt,validate:gr},{code:273,name:"udp",size:16,valueToBytes:it,bytesToValue:Lt,validate:gr},{code:33,name:"dccp",size:16,valueToBytes:it,bytesToValue:Lt,validate:gr},{code:41,name:"ip6",size:128,valueToBytes:Ga,bytesToValue:Za,stringToValue:Qa,validate:t=>{if(!Ha(t))throw new Ue(`Invalid IPv6 address "${t}"`)}},{code:42,name:"ip6zone",size:re},{code:43,name:"ipcidr",size:8,bytesToValue:cs("base10"),valueToBytes:us("base10")},{code:53,name:"dns",size:re},{code:54,name:"dns4",size:re},{code:55,name:"dns6",size:re},{code:56,name:"dnsaddr",size:re},{code:132,name:"sctp",size:16,valueToBytes:it,bytesToValue:Lt,validate:gr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:re,stringToValue:t=>decodeURIComponent(t),valueToString:t=>encodeURIComponent(t)},{code:421,name:"p2p",aliases:["ipfs"],size:re,bytesToValue:cs("base58btc"),valueToBytes:t=>t.startsWith("Q")||t.startsWith("1")?us("base58btc")(t):mt.parse(t).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:fs,valueToBytes:za},{code:445,name:"onion3",size:296,bytesToValue:fs,valueToBytes:Wa},{code:446,name:"garlic64",size:re},{code:447,name:"garlic32",size:re},{code:448,name:"tls"},{code:449,name:"sni",size:re},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:re,bytesToValue:Ja(Hn),valueToBytes:Xa},{code:480,name:"http"},{code:481,name:"http-path",size:re,stringToValue:t=>`/${decodeURIComponent(t)}`,valueToString:t=>encodeURIComponent(t.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:re}];Tl.forEach(t=>{Ve.addProtocol(t)});function ec(t){let e=[],r=0;for(;r<t.length;){let n=to(t,r),o=Ve.getProtocol(n),s=De(n),i=kl(o,t,r+s),a=0;i>0&&o.size===re&&(a=De(i));let c=s+a+i,u={code:n,name:o.name,bytes:t.subarray(r,r+c)};if(i>0){let l=r+s+a,f=t.subarray(l,l+i);u.value=o.bytesToValue?.(f)??X(f)}e.push(u),r+=c}return e}function tc(t){let e=0,r=[];for(let n of t){if(n.bytes==null){let o=Ve.getProtocol(n.code),s=De(n.code),i,a=0,c=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??le(n.value),a=i.byteLength,o.size===re&&(c=De(a)));let u=new Uint8Array(s+c+a),l=0;zt(n.code,u,l),l+=s,i!=null&&(o.size===re&&(zt(a,u,l),l+=c),u.set(i,l)),n.bytes=u}r.push(n.bytes),e+=n.bytes.byteLength}return Ie(r,e)}function rc(t){if(t.charAt(0)!=="/")throw new oe('String multiaddr must start with "/"');let e=[],r="protocol",n="",o="";for(let s=1;s<t.length;s++){let i=t.charAt(s);i!=="/"&&(r==="protocol"?o+=t.charAt(s):n+=t.charAt(s));let a=s===t.length-1;if(i==="/"||a){let c=Ve.getProtocol(o);if(r==="protocol"){if(c.size==null||c.size===0){e.push({code:c.code,name:c.name}),n="",o="",r="protocol";continue}else if(a)throw new oe(`Component ${o} was missing value`);r="value"}else if(r==="value"){let u={code:c.code,name:c.name};if(c.size!=null&&c.size!==0){if(n==="")throw new oe(`Component ${o} was missing value`);u.value=c.stringToValue?.(n)??n}e.push(u),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new oe("Incomplete multiaddr");return e}function nc(t){return`/${t.flatMap(e=>{if(e.value==null)return e.name;let r=Ve.getProtocol(e.code);if(r==null)throw new oe(`Unknown protocol code ${e.code}`);return[e.name,r.valueToString?.(e.value)??e.value]}).join("/")}`}function kl(t,e,r){return t.size==null||t.size===0?0:t.size>0?t.size/8:to(e,r)}var Kl=Symbol.for("nodejs.util.inspect.custom"),Rs=Symbol.for("@multiformats/multiaddr");function Ul(t){if(t==null&&(t="/"),oc(t))return t.getComponents();if(t instanceof Uint8Array)return ec(t);if(typeof t=="string")return t=t.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),t===""&&(t="/"),rc(t);if(Array.isArray(t))return t;throw new oe("Must be a string, Uint8Array, Component[], or another Multiaddr")}var yn=class t{[Rs]=!0;#e;#r;#n;constructor(e="/",r={}){this.#e=Ul(e),r.validate!==!1&&Vl(this)}get bytes(){return this.#n==null&&(this.#n=tc(this.#e)),this.#n}toString(){return this.#r==null&&(this.#r=nc(this.#e)),this.#r}toJSON(){return this.toString()}getComponents(){return[...this.#e.map(e=>({...e}))]}encapsulate(e){let r=new t(e);return new t([...this.#e,...r.getComponents()],{validate:!1})}decapsulate(e){let r=e.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new hn(`Address ${this.toString()} does not contain subaddress: ${r}`);return new t(n.slice(0,o),{validate:!1})}decapsulateCode(e){let r;for(let n=this.#e.length-1;n>-1;n--)if(this.#e[n].code===e){r=n;break}return new t(this.#e.slice(0,r),{validate:!1})}equals(e){return he(this.bytes,e.bytes)}[Kl](){return`Multiaddr(${this.toString()})`}};function Vl(t){t.getComponents().forEach(e=>{let r=Ve.getProtocol(e.code);e.value!=null&&r.validate?.(e.value)})}function oc(t){return!!t?.[Rs]}function Kt(t){return new yn(t)}var xn=class extends Error{type;code;constructor(e,r,n){super(e??"The operation was aborted"),this.type="aborted",this.name=n??"AbortError",this.code=r??"ABORT_ERR"}};async function wn(t,e,r){if(e==null)return t;if(e.aborted)return t.catch(()=>{}),Promise.reject(new xn(r?.errorMessage,r?.errorCode,r?.errorName));let n,o=new xn(r?.errorMessage,r?.errorCode,r?.errorName);try{return await Promise.race([t,new Promise((s,i)=>{n=()=>{i(o)},e.addEventListener("abort",n)})])}finally{n!=null&&e.removeEventListener("abort",n)}}var Ut=class extends fn{#e;constructor(e){let r=Kt(e.connection.remoteMultiaddr());super({remoteAddr:r,direction:e.direction,log:e.log,metrics:e.metrics,metricPrefix:e.metricsPrefix}),this.#e=e.connection,this.#e.closed().then(()=>{this.onTransportClosed()},n=>{this.onTransportClosed(n)})}sendData(e){throw new Error("QuicConnection does not support direct data writes \u2014 use streams instead")}sendReset(e){this.#e.abort()}sendPause(){}sendResume(){}async sendClose(e){this.#e.abort()}};var j=t=>({match:e=>{let r=e[0];return r==null||r.code!==t||r.value!=null?!1:e.slice(1)}}),_=(t,e)=>({match:r=>{let n=r[0];return n?.code!==t||n.value==null||e!=null&&n.value!==e?!1:r.slice(1)}}),sc=t=>({match:e=>t.match(e)===!1?e:!1}),T=t=>({match:e=>{let r=t.match(e);return r===!1?e:r}}),ue=(...t)=>({match:e=>{let r;for(let n of t){let o=n.match(e);o!==!1&&(r==null||o.length<r.length)&&(r=o)}return r??!1}}),U=(...t)=>({match:e=>{for(let r of t){let n=r.match(e);if(n===!1)return!1;e=n}return e}});function z(...t){function e(o){if(o==null)return!1;let s=o.getComponents();for(let i of t){let a=i.match(s);if(a===!1)return!1;s=a}return s}function r(o){return e(o)!==!1}function n(o){let s=e(o);return s===!1?!1:s.length===0}return{matchers:t,matches:r,exactMatch:n}}var ql=_(421),ty=z(ql),vn=_(54),Sn=_(55),Cn=_(56),Ps=_(53),ry=z(vn,T(_(421))),ny=z(Sn,T(_(421))),oy=z(Cn,T(_(421))),sy=z(ue(Ps,Cn,vn,Sn),T(_(421))),ic=U(_(4),T(_(43))),ac=U(T(_(42)),_(41),T(_(43))),Ns=ue(ic,ac),ut=ue(Ns,Ps,vn,Sn,Cn),iy=z(ue(Ns,U(ue(Ps,Cn,vn,Sn),T(_(421))))),ay=z(ic),cy=z(ac),uy=z(Ns),Ls=U(ut,_(6)),yr=U(ut,_(273)),fy=z(U(Ls,T(_(421)))),ly=z(yr),Os=U(yr,j(460),T(_(421))),An=U(yr,j(461),T(_(421))),Ml=ue(Os,An),hy=z(Os),cc=z(An),Bs=ue(ut,Ls,yr,Os,An),uc=ue(U(Bs,j(477),T(_(421)))),dy=z(uc),fc=ue(U(Bs,j(478),T(_(421))),U(Bs,j(448),T(_(449)),j(477),T(_(421)))),py=z(fc),lc=U(yr,j(280),T(_(466)),T(_(466)),T(_(421))),my=z(lc),hc=U(An,j(465),T(_(466)),T(_(466)),T(_(421))),by=z(hc),En=ue(uc,fc,U(Ls,T(_(421))),U(Ml,T(_(421))),U(ut,T(_(421))),lc,hc,_(421)),gy=z(En),Hl=U(T(En),j(290),sc(j(281)),T(_(421))),yy=z(Hl),Fl=ue(U(En,j(290),j(281),T(_(421))),U(En,j(281),T(_(421))),U(j(281),T(_(421)))),xy=z(Fl),$l=ue(U(ut,_(6),j(480),T(_(421))),U(ut,j(480),T(_(421)))),wy=z($l),jl=U(ut,ue(U(_(6,"443"),j(480)),U(_(6),j(443)),U(_(6),j(448),j(480)),U(j(448),j(480)),j(448),j(443)),T(_(421))),Ey=z(jl),zl=ue(U(_(777),T(_(421)))),vy=z(zl),Wl=ue(U(_(400),T(_(421)))),Sy=z(Wl);function Ts(t){return t.filter(e=>cc.exactMatch(e))}function dc(t){return Ts(t)}import{createRequire as Yl}from"node:module";var Gl=function(t,e){return typeof t=="string"&&/^\.\.?\//.test(t)?t.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i,function(r,n,o,s,i){return n?e?".jsx":".js":o&&(!s||!i)?r:o+s+"."+i.toLowerCase()+"js"}):t},p=Yl(import.meta.url),Dy=new URL(".",import.meta.url).pathname,{readFileSync:Zl}=p("node:fs"),ft=null,E=[],xr=()=>{let t=!1;return process.platform==="linux"&&(t=Xl(),t===null&&(t=Jl()),t===null&&(t=eh())),t},Ql=t=>t.includes("libc.musl-")||t.includes("ld-musl-"),Xl=()=>{try{return Zl("/usr/bin/ldd","utf-8").includes("musl")}catch{return null}},Jl=()=>{let t=null;return typeof process.report?.getReport=="function"&&(process.report.excludeNetwork=!0,t=process.report.getReport()),t?t.header&&t.header.glibcVersionRuntime?!1:!!(Array.isArray(t.sharedObjects)&&t.sharedObjects.some(Ql)):null},eh=()=>{try{return p("child_process").execSync("ldd --version",{encoding:"utf8"}).includes("musl")}catch{return!1}};function th(){if(process.env.NAPI_RS_NATIVE_LIBRARY_PATH)try{return p(Gl(process.env.NAPI_RS_NATIVE_LIBRARY_PATH))}catch(t){E.push(t)}else if(process.platform==="android")if(process.arch==="arm64"){try{return p("./libp2p-quic.android-arm64.node")}catch(t){E.push(t)}try{let t=p("@chainsafe/libp2p-quic-android-arm64"),e=p("@chainsafe/libp2p-quic-android-arm64/package.json").version;if(e!=="1.1.7"&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK!=="0")throw new Error(`Native binding package version mismatch, expected 1.1.7 but got ${e}. You can reinstall dependencies to fix this issue.`);return t}catch(t){E.push(t)}}else if(process.arch==="arm"){try{return p("./libp2p-quic.android-arm-eabi.node")}catch(t){E.push(t)}try{let t=p("@chainsafe/libp2p-quic-android-arm-eabi"),e=p("@chainsafe/libp2p-quic-android-arm-eabi/package.json").version;if(e!=="1.1.7"&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK!=="0")throw new Error(`Native binding package version mismatch, expected 1.1.7 but got ${e}. You can reinstall dependencies to fix this issue.`);return t}catch(t){E.push(t)}}else E.push(new Error(`Unsupported architecture on Android ${process.arch}`));else if(process.platform==="win32")if(process.arch==="x64")if(process.config?.variables?.shlib_suffix==="dll.a"||process.config?.variables?.node_target_type==="shared_library"){try{return p("./libp2p-quic.win32-x64-gnu.node")}catch(t){E.push(t)}try{let t=p("@chainsafe/libp2p-quic-win32-x64-gnu"),e=p("@chainsafe/libp2p-quic-win32-x64-gnu/package.json").version;if(e!=="1.1.7"&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK!=="0")throw new Error(`Native binding package version mismatch, expected 1.1.7 but got ${e}. You can reinstall dependencies to fix this issue.`);return t}catch(t){E.push(t)}}else{try{return p("./libp2p-quic.win32-x64-msvc.node")}catch(t){E.push(t)}try{let t=p("@chainsafe/libp2p-quic-win32-x64-msvc"),e=p("@chainsafe/libp2p-quic-win32-x64-msvc/package.json").version;if(e!=="1.1.7"&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK!=="0")throw new Error(`Native binding package version mismatch, expected 1.1.7 but got ${e}. You can reinstall dependencies to fix this issue.`);return t}catch(t){E.push(t)}}else if(process.arch==="ia32"){try{return p("./libp2p-quic.win32-ia32-msvc.node")}catch(t){E.push(t)}try{let t=p("@chainsafe/libp2p-quic-win32-ia32-msvc"),e=p("@chainsafe/libp2p-quic-win32-ia32-msvc/package.json").version;if(e!=="1.1.7"&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK!=="0")throw new Error(`Native binding package version mismatch, expected 1.1.7 but got ${e}. You can reinstall dependencies to fix this issue.`);return t}catch(t){E.push(t)}}else if(process.arch==="arm64"){try{return p("./libp2p-quic.win32-arm64-msvc.node")}catch(t){E.push(t)}try{let t=p("@chainsafe/libp2p-quic-win32-arm64-msvc"),e=p("@chainsafe/libp2p-quic-win32-arm64-msvc/package.json").version;if(e!=="1.1.7"&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK!=="0")throw new Error(`Native binding package version mismatch, expected 1.1.7 but got ${e}. You can reinstall dependencies to fix this issue.`);return t}catch(t){E.push(t)}}else E.push(new Error(`Unsupported architecture on Windows: ${process.arch}`));else if(process.platform==="darwin"){try{return p("./libp2p-quic.darwin-universal.node")}catch(t){E.push(t)}try{let t=p("@chainsafe/libp2p-quic-darwin-universal"),e=p("@chainsafe/libp2p-quic-darwin-universal/package.json").version;if(e!=="1.1.7"&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK!=="0")throw new Error(`Native binding package version mismatch, expected 1.1.7 but got ${e}. You can reinstall dependencies to fix this issue.`);return t}catch(t){E.push(t)}if(process.arch==="x64"){try{return p("./libp2p-quic.darwin-x64.node")}catch(t){E.push(t)}try{let t=p("@chainsafe/libp2p-quic-darwin-x64"),e=p("@chainsafe/libp2p-quic-darwin-x64/package.json").version;if(e!=="1.1.7"&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK!=="0")throw new Error(`Native binding package version mismatch, expected 1.1.7 but got ${e}. You can reinstall dependencies to fix this issue.`);return t}catch(t){E.push(t)}}else if(process.arch==="arm64"){try{return p("./libp2p-quic.darwin-arm64.node")}catch(t){E.push(t)}try{let t=p("@chainsafe/libp2p-quic-darwin-arm64"),e=p("@chainsafe/libp2p-quic-darwin-arm64/package.json").version;if(e!=="1.1.7"&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK!=="0")throw new Error(`Native binding package version mismatch, expected 1.1.7 but got ${e}. You can reinstall dependencies to fix this issue.`);return t}catch(t){E.push(t)}}else E.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))}else if(process.platform==="freebsd")if(process.arch==="x64"){try{return p("./libp2p-quic.freebsd-x64.node")}catch(t){E.push(t)}try{let t=p("@chainsafe/libp2p-quic-freebsd-x64"),e=p("@chainsafe/libp2p-quic-freebsd-x64/package.json").version;if(e!=="1.1.7"&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK!=="0")throw new Error(`Native binding package version mismatch, expected 1.1.7 but got ${e}. You can reinstall dependencies to fix this issue.`);return t}catch(t){E.push(t)}}else if(process.arch==="arm64"){try{return p("./libp2p-quic.freebsd-arm64.node")}catch(t){E.push(t)}try{let t=p("@chainsafe/libp2p-quic-freebsd-arm64"),e=p("@chainsafe/libp2p-quic-freebsd-arm64/package.json").version;if(e!=="1.1.7"&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK!=="0")throw new Error(`Native binding package version mismatch, expected 1.1.7 but got ${e}. You can reinstall dependencies to fix this issue.`);return t}catch(t){E.push(t)}}else E.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`));else if(process.platform==="linux")if(process.arch==="x64")if(xr()){try{return p("./libp2p-quic.linux-x64-musl.node")}catch(t){E.push(t)}try{let t=p("@chainsafe/libp2p-quic-linux-x64-musl"),e=p("@chainsafe/libp2p-quic-linux-x64-musl/package.json").version;if(e!=="1.1.7"&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK!=="0")throw new Error(`Native binding package version mismatch, expected 1.1.7 but got ${e}. You can reinstall dependencies to fix this issue.`);return t}catch(t){E.push(t)}}else{try{return p("./libp2p-quic.linux-x64-gnu.node")}catch(t){E.push(t)}try{let t=p("@chainsafe/libp2p-quic-linux-x64-gnu"),e=p("@chainsafe/libp2p-quic-linux-x64-gnu/package.json").version;if(e!=="1.1.7"&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK!=="0")throw new Error(`Native binding package version mismatch, expected 1.1.7 but got ${e}. You can reinstall dependencies to fix this issue.`);return t}catch(t){E.push(t)}}else if(process.arch==="arm64")if(xr()){try{return p("./libp2p-quic.linux-arm64-musl.node")}catch(t){E.push(t)}try{let t=p("@chainsafe/libp2p-quic-linux-arm64-musl"),e=p("@chainsafe/libp2p-quic-linux-arm64-musl/package.json").version;if(e!=="1.1.7"&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK!=="0")throw new Error(`Native binding package version mismatch, expected 1.1.7 but got ${e}. You can reinstall dependencies to fix this issue.`);return t}catch(t){E.push(t)}}else{try{return p("./libp2p-quic.linux-arm64-gnu.node")}catch(t){E.push(t)}try{let t=p("@chainsafe/libp2p-quic-linux-arm64-gnu"),e=p("@chainsafe/libp2p-quic-linux-arm64-gnu/package.json").version;if(e!=="1.1.7"&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK!=="0")throw new Error(`Native binding package version mismatch, expected 1.1.7 but got ${e}. You can reinstall dependencies to fix this issue.`);return t}catch(t){E.push(t)}}else if(process.arch==="arm")if(xr()){try{return p("./libp2p-quic.linux-arm-musleabihf.node")}catch(t){E.push(t)}try{let t=p("@chainsafe/libp2p-quic-linux-arm-musleabihf"),e=p("@chainsafe/libp2p-quic-linux-arm-musleabihf/package.json").version;if(e!=="1.1.7"&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK!=="0")throw new Error(`Native binding package version mismatch, expected 1.1.7 but got ${e}. You can reinstall dependencies to fix this issue.`);return t}catch(t){E.push(t)}}else{try{return p("./libp2p-quic.linux-arm-gnueabihf.node")}catch(t){E.push(t)}try{let t=p("@chainsafe/libp2p-quic-linux-arm-gnueabihf"),e=p("@chainsafe/libp2p-quic-linux-arm-gnueabihf/package.json").version;if(e!=="1.1.7"&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK!=="0")throw new Error(`Native binding package version mismatch, expected 1.1.7 but got ${e}. You can reinstall dependencies to fix this issue.`);return t}catch(t){E.push(t)}}else if(process.arch==="loong64")if(xr()){try{return p("./libp2p-quic.linux-loong64-musl.node")}catch(t){E.push(t)}try{let t=p("@chainsafe/libp2p-quic-linux-loong64-musl"),e=p("@chainsafe/libp2p-quic-linux-loong64-musl/package.json").version;if(e!=="1.1.7"&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK!=="0")throw new Error(`Native binding package version mismatch, expected 1.1.7 but got ${e}. You can reinstall dependencies to fix this issue.`);return t}catch(t){E.push(t)}}else{try{return p("./libp2p-quic.linux-loong64-gnu.node")}catch(t){E.push(t)}try{let t=p("@chainsafe/libp2p-quic-linux-loong64-gnu"),e=p("@chainsafe/libp2p-quic-linux-loong64-gnu/package.json").version;if(e!=="1.1.7"&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK!=="0")throw new Error(`Native binding package version mismatch, expected 1.1.7 but got ${e}. You can reinstall dependencies to fix this issue.`);return t}catch(t){E.push(t)}}else if(process.arch==="riscv64")if(xr()){try{return p("./libp2p-quic.linux-riscv64-musl.node")}catch(t){E.push(t)}try{let t=p("@chainsafe/libp2p-quic-linux-riscv64-musl"),e=p("@chainsafe/libp2p-quic-linux-riscv64-musl/package.json").version;if(e!=="1.1.7"&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK!=="0")throw new Error(`Native binding package version mismatch, expected 1.1.7 but got ${e}. You can reinstall dependencies to fix this issue.`);return t}catch(t){E.push(t)}}else{try{return p("./libp2p-quic.linux-riscv64-gnu.node")}catch(t){E.push(t)}try{let t=p("@chainsafe/libp2p-quic-linux-riscv64-gnu"),e=p("@chainsafe/libp2p-quic-linux-riscv64-gnu/package.json").version;if(e!=="1.1.7"&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK!=="0")throw new Error(`Native binding package version mismatch, expected 1.1.7 but got ${e}. You can reinstall dependencies to fix this issue.`);return t}catch(t){E.push(t)}}else if(process.arch==="ppc64"){try{return p("./libp2p-quic.linux-ppc64-gnu.node")}catch(t){E.push(t)}try{let t=p("@chainsafe/libp2p-quic-linux-ppc64-gnu"),e=p("@chainsafe/libp2p-quic-linux-ppc64-gnu/package.json").version;if(e!=="1.1.7"&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK!=="0")throw new Error(`Native binding package version mismatch, expected 1.1.7 but got ${e}. You can reinstall dependencies to fix this issue.`);return t}catch(t){E.push(t)}}else if(process.arch==="s390x"){try{return p("./libp2p-quic.linux-s390x-gnu.node")}catch(t){E.push(t)}try{let t=p("@chainsafe/libp2p-quic-linux-s390x-gnu"),e=p("@chainsafe/libp2p-quic-linux-s390x-gnu/package.json").version;if(e!=="1.1.7"&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK!=="0")throw new Error(`Native binding package version mismatch, expected 1.1.7 but got ${e}. You can reinstall dependencies to fix this issue.`);return t}catch(t){E.push(t)}}else E.push(new Error(`Unsupported architecture on Linux: ${process.arch}`));else if(process.platform==="openharmony")if(process.arch==="arm64"){try{return p("./libp2p-quic.openharmony-arm64.node")}catch(t){E.push(t)}try{let t=p("@ohos-ports/chainsafe-libp2p-quic-openharmony-arm64"),e=p("@ohos-ports/chainsafe-libp2p-quic-openharmony-arm64/package.json").version;if(e!=="1.1.7"&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK!=="0")throw new Error(`Native binding package version mismatch, expected 1.1.7 but got ${e}. You can reinstall dependencies to fix this issue.`);return t}catch(t){E.push(t)}}else if(process.arch==="x64"){try{return p("./libp2p-quic.openharmony-x64.node")}catch(t){E.push(t)}try{let t=p("@chainsafe/libp2p-quic-openharmony-x64"),e=p("@chainsafe/libp2p-quic-openharmony-x64/package.json").version;if(e!=="1.1.7"&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK!=="0")throw new Error(`Native binding package version mismatch, expected 1.1.7 but got ${e}. You can reinstall dependencies to fix this issue.`);return t}catch(t){E.push(t)}}else if(process.arch==="arm"){try{return p("./libp2p-quic.openharmony-arm.node")}catch(t){E.push(t)}try{let t=p("@chainsafe/libp2p-quic-openharmony-arm"),e=p("@chainsafe/libp2p-quic-openharmony-arm/package.json").version;if(e!=="1.1.7"&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK&&process.env.NAPI_RS_ENFORCE_VERSION_CHECK!=="0")throw new Error(`Native binding package version mismatch, expected 1.1.7 but got ${e}. You can reinstall dependencies to fix this issue.`);return t}catch(t){E.push(t)}}else E.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`));else E.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))}ft=th();if(!ft||process.env.NAPI_RS_FORCE_WASI){let t=null,e=null;try{t=p("./libp2p-quic.wasi.cjs"),ft=t}catch(r){process.env.NAPI_RS_FORCE_WASI&&(e=r)}if(!ft)try{t=p("@chainsafe/libp2p-quic-wasm32-wasi"),ft=t}catch(r){process.env.NAPI_RS_FORCE_WASI&&(e.cause=r,E.push(r))}if(process.env.NAPI_RS_FORCE_WASI==="error"&&!t){let r=new Error("WASI binding not found and NAPI_RS_FORCE_WASI is set to error");throw r.cause=e,r}}if(!ft)throw E.length>0?new Error("Cannot find native binding. npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). Please try `npm i` again after removing both package-lock.json and node_modules directory.",{cause:E.reduce((t,e)=>(e.cause=t,e))}):new Error("Failed to load native binding");var{Client:ks,Connection:Ry,ConnectionStats:By,EndpointStats:Py,QuinnConfig:pc,Server:mc,Stream:Ny,SocketFamily:Ly}=ft;var wr=class extends ln{#e;#r=!1;constructor(e){super(e),this.#e=e.stream,this.log("new",this.direction,this.id),this.readFromStream().catch(r=>{this.log.error("error reading from stream - %e",r)})}sendData(e){this.log.trace("writing %d bytes",e.byteLength);let r=e.subarray();return this.#e.write(r).then(()=>{this.log.trace("wrote %d bytes",r.byteLength),this.safeDispatchEvent("drain")},n=>{this.log.error("write error - %e",n),this.abort(n)}),{sentBytes:e.byteLength,canSendMore:!1}}sendReset(e){this.#e.resetWrite(),this.#e.stopRead()}async sendCloseWrite(e){await this.#e.finishWrite()}async sendCloseRead(e){this.#r=!0}sendPause(){}sendResume(){}async readFromStream(){try{for(;;){this.log.trace("reading");let e=await this.#e.read(rh);if(e==null)break;this.#r||this.onData(new ee(e)),this.log.trace("read %d bytes",e.length)}}catch(e){if(e.code==="Unknown"){this.log.trace("read ended - %e",e);return}this.log.error("source error - %e",e),this.abort(e)}finally{this.onRemoteCloseWrite()}}},rh=4096;var Vt=class{#e;init;protocol="quic";constructor(e){this.#e=e.connection,this.init=e}createStreamMuxer(e){return new Ks({connection:this.#e,logger:this.init.logger,maConn:e})}},Ks=class extends qe{id;#e;init;log;protocol="quic";streams=[];status="open";controller=new AbortController;constructor(e){super(),this.id=e.connection.id(),this.#e=e.connection,this.init=e,this.log=e.logger.forComponent("libp2p:quic:muxer"),this.awaitInboundStreams(),e.maConn.addEventListener("close",()=>{this.abort(new Error("connection closed"))},{once:!0}),this.log("new",this.id)}async awaitInboundStreams(){for(;;)try{let e=await wn(this.#e.inboundStream(),this.controller.signal);this.onInboundStream(e)}catch(e){if(this.log.error("%s error accepting stream - %e",this.id,e),this.controller.signal.aborted)break}this.log("%s no longer awaiting inbound streams",this.id)}onInboundStream=e=>{let r=new wr({id:e.id(),stream:e,direction:"inbound",log:this.init.logger.forComponent(`libp2p:quic:stream:${this.#e.id()}:${e.id()}:inbound`)});this.streams.push(r),this.cleanUpStream(r),this.safeDispatchEvent("stream",{detail:r})};async createStream(e){let r=await this.#e.outboundStream();this.controller.signal.throwIfAborted();let n=new wr({id:r.id(),stream:r,direction:"outbound",log:this.init.logger.forComponent(`libp2p:quic:stream:${this.#e.id()}:${r.id()}:outbound`)});return this.streams.push(n),this.cleanUpStream(n),n}cleanUpStream(e){e.addEventListener("close",()=>{let r=this.streams.findIndex(n=>n===e);r!==-1&&this.streams.splice(r,1)},{once:!0})}async close(e){if(!(this.status==="closed"||this.status==="closing")){this.status="closing",this.controller.abort();try{await Promise.all(this.streams.map(async r=>r.close(e)))}catch{}for(let r of[...this.streams])r.abort(new Error("muxer closed"));this.streams=[],this.status="closed",this.log("%s closed",this.id)}}abort(e){if(this.status!=="closed"){this.status="closing",this.controller.abort();for(let r of this.streams)r.abort(e);this.streams=[],this.status="closed",this.log("%s aborted",this.id)}}};import nh from"node:os";function Er(t){let e=t.getComponents(),r=e.find(o=>o.name==="ip4"||o.name==="ip6"),n=e.find(o=>o.name==="udp");if(r?.value==null)throw new Error(`Multiaddr is missing an ip4/ip6 component: ${t.toString()}`);if(n?.value==null)throw new Error(`Multiaddr is missing a udp component: ${t.toString()}`);return{family:r.name==="ip4"?4:6,address:r.value,port:parseInt(n.value,10)}}var oh={ip4:"IPv4",ip6:"IPv6"};function Us(t,e,r){let n=o=>Kt(`/${t}/${o}/udp/${r}/quic-v1`);return(sh(e)?ah(oh[t]):[e]).map(n)}function sh(t){return["0.0.0.0","::"].includes(t)}var ih=nh.networkInterfaces();function ah(t){let e=[];for(let[,r]of Object.entries(ih))if(r!=null)for(let n of r)n.family===t&&e.push(n.address);return e}var _n=class extends qe{#e;init;options;log;metrics;shutdownController;addr;state={status:"ready"};constructor(e){super(),this.#e=e.config,this.init=e,this.options=e.options,this.log=e.logger.forComponent("libp2p:quic:listener"),this.addr="unknown",this.shutdownController=new AbortController,Cr(1/0,this.shutdownController.signal),e.metrics?.registerMetricGroup("libp2p_quic_inbound_connections_total",{label:"address",help:"Current active connections in QUIC listener",calculate:()=>this.state.status!=="listening"?{[this.addr]:0}:{[this.addr]:this.state.connections.size}}),this.metrics={events:e.metrics?.registerMetricGroup("libp2p_quic_listener_events_total",{label:"address",help:"Total count of QUIC listener events by type"}),errors:e.metrics?.registerMetricGroup("libp2p_quic_listener_errors_total",{label:"address",help:"Total count of QUIC listener errors by type"})},this.log("new")}updateAnnounceAddrs(e){}getAddrs(){if(this.state.status==="listening"){let e=this.state.listenAddr,r=Er(e);return r.address==="0.0.0.0"?Us("ip4",r.address,r.port):r.address==="::"?Us("ip6",r.address,r.port):[this.state.listenAddr]}return[]}async listen(e){let r=Er(e),n=new AbortController,o=new mc(this.#e,r.address,r.port);if(this.addr=`${r.address}:${r.port===0?o.port():r.port}`,r.port===0){let s=e.getComponents();for(let i of s)i.name==="udp"&&(i.value=`${o.port()}`);e=Kt(s)}this.state={status:"listening",listener:o,listenAddr:e,controller:n,connections:new Set},this.awaitInboundConnections(),this.safeDispatchEvent("listening"),this.log("listening",e.toString())}async close(){if(this.state.status==="listening"){this.state.controller.abort();for(let r of this.state.connections)r.abort(new Error("listener closed"));this.state.connections.clear(),await this.state.listener.abort();let e=this.state.listenAddr;this.state={status:"closed"},this.shutdownController.abort(),this.safeDispatchEvent("close"),this.log("closed",e.toString())}}async awaitInboundConnections(){if(this.state.status==="listening"){let e=this.state.controller.signal,r=this.state.listenAddr;for(;;)try{let n=this.state.listener.inboundConnection();n.then(()=>this.metrics.events?.increment({[`${this.addr} connect`]:!0})).catch(s=>{this.log.error("%a error awaiting inbound connection - %e",r,s),this.metrics.events?.increment({[`${this.addr} error`]:!0})});let o=await wn(n,e);this.onInboundConnection(o).catch(s=>{this.log.error("%a error handling inbound connection - %e",r,s)})}catch(n){if(this.log.error("%a error accepting connection - %e",r,n),e.aborted)break}this.log("%s no longer awaiting inbound connections",r.toString())}}async onInboundConnection(e){if(this.state.status!=="listening"){this.log.error("ignoring inbound connection after listener closed"),e.abort();return}let r;try{r=new Ut({connection:e,log:this.init.logger.forComponent(`libp2p:quic:connection:${e.id()}:inbound`),direction:"inbound",metrics:this.metrics?.events,metricsPrefix:`${this.addr} `})}catch(n){throw this.metrics.errors?.increment({[`${this.addr} inbound_to_connection`]:!0}),n}try{let n=r.remoteAddr.getComponents().find(s=>s.name==="p2p");if(n?.value==null)throw new Error(`Remote multiaddr does not contain a peer ID: ${r.remoteAddr.toString()}`);let o=br(n.value);await this.options.upgrader.upgradeInbound(r,{skipEncryption:!0,skipProtection:!0,remotePeer:o,muxerFactory:new Vt({connection:e,logger:this.init.logger}),signal:this.shutdownController.signal}),this.state.connections.add(r),r.addEventListener("close",()=>{this.state.status==="listening"&&this.state.connections.delete(r)},{once:!0})}catch(n){this.log.error("%s error handling inbound connection",this.state.listenAddr.toString(),n),this.metrics.errors?.increment({[`${this.addr} inbound_upgrade`]:!0}),r.abort(n)}}};var In=class{[Symbol.toStringTag]="quic";[Ei]=!0;[vi]=["@libp2p/transport"];log;components;metrics;#e;#r;#n;#t;listenFilter;dialFilter;constructor(e,r){let n=xi(e.privateKey),o={...r,privateKeyProto:n};this.log=e.logger.forComponent("libp2p:quic:transport"),this.components=e,this.#e=new pc(o),this.#r=r.ipv4!==!1,this.#n=r.ipv6!==!1,this.#t={},this.#o(),this.metrics={events:this.components.metrics?.registerCounterGroup("libp2p_quic_dialer_events_total",{label:"event",help:"Total count of QUIC dialer events by type"}),errors:this.components.metrics?.registerCounterGroup("libp2p_quic_dialer_errors_total",{label:"event",help:"Total count of QUIC dialer errors by type"})},this.listenFilter=Ts,this.dialFilter=dc,this.log("new")}#o(){if(!(this.#t.ip4!=null||this.#t.ip6!=null)){if(this.#r)try{this.#t.ip4=new ks(this.#e,0)}catch{this.log("IPv4 QUIC client not available")}if(this.#n)try{this.#t.ip6=new ks(this.#e,1)}catch{this.log("IPv6 QUIC client not available")}if(this.#t.ip4==null&&this.#t.ip6==null)throw new Error("At least one of ipv4 or ipv6 must be enabled for QUIC transport")}}async start(){this.#o(),this.log("started")}async stop(){let{ip4:e,ip6:r}=this.#t;this.#t.ip4=void 0,this.#t.ip6=void 0,e?.abort(),r?.abort(),this.log("stopped")}async dial(e,r){if(r.signal?.aborted)throw new Nr;this.log("dialing",e.toString());let n=Er(e),o=n.family===4?this.#t.ip4:this.#t.ip6;if(o==null)throw new Error(`No QUIC client available for IPv${n.family}`);let s=o.outboundConnection(n.address,n.port);s.then(()=>this.metrics.events?.increment({connect:!0})).catch(()=>this.metrics.events?.increment({error:!0}));let i=await s,a;try{a=new Ut({connection:i,log:this.components.logger.forComponent(`libp2p:quic:connection:${i.id()}:outbound`),direction:"outbound",metrics:this.metrics?.events})}catch(c){throw this.metrics.errors?.increment({outbound_to_connection:!0}),c}try{this.log("new outbound connection %a",a.remoteAddr);let c=a.remoteAddr.getComponents().find(f=>f.name==="p2p");if(c?.value==null)throw new Error(`Remote multiaddr does not contain a peer ID: ${a.remoteAddr.toString()}`);let u=br(c.value),l=e.getComponents().find(f=>f.name==="p2p");if(l?.value!=null){let f=br(l.value);if(!u.equals(f))throw new Error(`Dialed peer ${f.toString()} but connected to ${u.toString()}`)}return await r.upgrader.upgradeOutbound(a,{skipEncryption:!0,skipProtection:!0,remotePeer:u,muxerFactory:new Vt({connection:i,logger:this.components.logger}),signal:r.signal})}catch(c){throw this.metrics.errors?.increment({outbound_upgrade:!0}),this.log.error("error upgrading outbound connection - %e",c),a.abort(c),c}}createListener(e){return new _n({options:e,config:this.#e,logger:this.components.logger,metrics:this.components.metrics})}};function cx(t){return e=>new In(e,{...ch,...t})}var ch={handshakeTimeout:5e3,shutdownTimeout:3e3,maxIdleTimeout:1e4,keepAliveInterval:5e3,maxConcurrentStreamLimit:256,maxStreamData:1e7,maxConnectionData:15e6,receiveBufferSize:5e5,sendBufferSize:5e5};export{ch as defaultOptions,cx as quic};
|
|
3
|
+
/*! Bundled license information:
|
|
4
|
+
|
|
5
|
+
@noble/hashes/utils.js:
|
|
6
|
+
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
7
|
+
|
|
8
|
+
@noble/curves/utils.js:
|
|
9
|
+
@noble/curves/abstract/modular.js:
|
|
10
|
+
@noble/curves/abstract/curve.js:
|
|
11
|
+
@noble/curves/abstract/weierstrass.js:
|
|
12
|
+
@noble/curves/secp256k1.js:
|
|
13
|
+
(*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
14
|
+
*/
|
|
15
|
+
return ChainsafeLibp2PQuic}));
|
|
16
|
+
//# sourceMappingURL=index.min.js.map
|