@libp2p/interface 3.1.0 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js.map +1 -1
- package/dist/src/peer-info.d.ts +1 -1
- package/dist/src/peer-store.d.ts +1 -1
- package/package.json +1 -1
- package/src/peer-info.ts +1 -1
- package/src/peer-store.ts +1 -1
package/dist/index.min.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts", "../src/connection.ts", "../src/content-routing.ts", "../src/errors.ts", "../src/events.ts", "../src/keys.ts", "../src/peer-discovery.ts", "../src/peer-id.ts", "../src/peer-routing.ts", "../src/peer-store.ts", "../src/startable.ts", "../src/transport.ts", "../../../node_modules/main-event/src/events.browser.ts", "../../../node_modules/main-event/src/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * @packageDocumentation\n *\n * Exports a `Libp2p` type for modules to use as a type argument.\n *\n * @example\n *\n * ```typescript\n * import type { Libp2p } from '@libp2p/interface'\n *\n * function doSomethingWithLibp2p (node: Libp2p) {\n * // ...\n * }\n * ```\n */\n\nimport type { Connection, NewStreamOptions } from './connection.js'\nimport type { ContentRouting } from './content-routing.js'\nimport type { Ed25519PublicKey, PublicKey, RSAPublicKey, Secp256k1PublicKey } from './keys.js'\nimport type { Metrics } from './metrics.js'\nimport type { Ed25519PeerId, PeerId, RSAPeerId, Secp256k1PeerId, URLPeerId } from './peer-id.js'\nimport type { PeerInfo } from './peer-info.js'\nimport type { PeerRouting } from './peer-routing.js'\nimport type { Address, Peer, PeerStore } from './peer-store.js'\nimport type { Startable } from './startable.js'\nimport type { StreamHandler, StreamHandlerOptions, StreamMiddleware } from './stream-handler.js'\nimport type { Stream } from './stream.js'\nimport type { Topology } from './topology.js'\nimport type { Listener, OutboundConnectionUpgradeEvents } from './transport.js'\nimport type { DNS } from '@multiformats/dns'\nimport type { Multiaddr } from '@multiformats/multiaddr'\nimport type { TypedEventTarget } from 'main-event'\nimport type { ProgressOptions, ProgressEvent } from 'progress-events'\n\n/**\n * Used by the connection manager to sort addresses into order before dialling\n */\nexport interface AddressSorter {\n (a: Address, b: Address): -1 | 0 | 1\n}\n\n/**\n * Event detail emitted when peer data changes\n */\nexport interface PeerUpdate {\n peer: Peer\n previous?: Peer\n}\n\n/**\n * Peer data signed by the remote Peer's public key\n */\nexport interface SignedPeerRecord {\n addresses: Multiaddr[]\n seq: bigint\n}\n\n/**\n * A certificate that can be used to secure connections\n */\nexport interface TLSCertificate {\n /**\n * The private key that corresponds to the certificate in PEM format\n */\n key: string\n\n /**\n * The certificate chain in PEM format\n */\n cert: string\n}\n\n/**\n * Data returned from a successful identify response\n */\nexport interface IdentifyResult {\n /**\n * The remote Peer's PeerId\n */\n peerId: PeerId\n\n /**\n * The unsigned addresses they are listening on. Note - any multiaddrs present\n * in the signed peer record should be preferred to the value here.\n */\n listenAddrs: Multiaddr[]\n\n /**\n * The protocols the remote peer supports\n */\n protocols: string[]\n\n /**\n * The remote protocol version\n */\n protocolVersion?: string\n\n /**\n * The remote agent version\n */\n agentVersion?: string\n\n /**\n * The public key part of the remote PeerId - this is only useful for older\n * RSA-based PeerIds, the more modern Ed25519 and secp256k1 types have the\n * public key embedded in them\n */\n publicKey?: Uint8Array\n\n /**\n * If set this is the address that the remote peer saw the identify request\n * originate from\n */\n observedAddr?: Multiaddr\n\n /**\n * If sent by the remote peer this is the deserialized signed peer record\n */\n signedPeerRecord?: SignedPeerRecord\n\n /**\n * The connection that the identify protocol ran over\n */\n connection: Connection\n}\n\n/**\n * Logger component for libp2p\n */\nexport interface Logger {\n /**\n * Log a message\n */\n (formatter: any, ...args: any[]): void\n\n /**\n * Log an error message\n */\n error(formatter: any, ...args: any[]): void\n\n /**\n * Log a trace message\n */\n trace(formatter: any, ...args: any[]): void\n\n /**\n * `true` if this logger is enabled\n */\n enabled: boolean\n\n /**\n * Create a logger scoped below this one\n *\n * @example\n *\n * ```ts\n * import { defaultLogger } from '@libp2p/logger'\n *\n * const log = defaultLogger().forComponent('foo')\n *\n * log('hello')\n * // foo hello\n *\n * const subLog = log.newScope('bar')\n *\n * subLog('hello')\n * // foo:bar hello\n * ```\n */\n newScope(name: string): Logger\n}\n\n/**\n * Peer logger component for libp2p. This can be used to create loggers that are\n * scoped to individual system components or services.\n *\n * To see logs, run your app with `DEBUG` set as an env var or for browsers, in\n * `localStorage`:\n *\n * ```console\n * $ DEBUG=libp2p* node index.js\n * libp2p:my-service hello +0ms\n * ```\n */\nexport interface ComponentLogger {\n /**\n * Returns a logger for the specified component.\n *\n * @example\n *\n * ```TypeScript\n * import { ComponentLogger, Logger } from '@libp2p/interface'\n *\n * interface MyServiceComponents {\n * logger: ComponentLogger\n * }\n *\n * class MyService {\n * private readonly log: Logger\n *\n * constructor (components) {\n * this.log = components.logger.forComponent('libp2p:my-service')\n *\n * this.log('hello')\n * // logs:\n * // libp2p:my-service hello +0ms\n * }\n * }\n * ```\n */\n forComponent(name: string): Logger\n}\n\nexport interface MultiaddrResolveOptions extends AbortOptions, LoggerOptions {\n /**\n * An optional DNS resolver\n */\n dns?: DNS\n}\n\n/**\n * `MultiaddrResolver`s perform resolution of multiaddr components that require\n * translation by external systems (for example DNSADDR to TXT records).\n */\nexport interface MultiaddrResolver {\n /**\n * Returns true if this resolver can resolve components of this multiaddr\n */\n canResolve (address: Multiaddr): boolean\n\n /**\n * Returns one or more multiaddrs with components resolved to other values\n */\n resolve (address: Multiaddr, options: MultiaddrResolveOptions): Promise<Multiaddr[]>\n}\n\n/**\n * Once you have a libp2p instance, you can listen to several events it emits,\n * so that you can be notified of relevant network events.\n *\n * Event names are `noun:verb` so the first part is the name of the object\n * being acted on and the second is the action.\n */\nexport interface Libp2pEvents<T extends ServiceMap = ServiceMap> {\n /**\n * This event is dispatched when a new network peer is discovered.\n *\n * @example\n *\n * ```TypeScript\n * libp2p.addEventListener('peer:discovery', (event) => {\n * const peerInfo = event.detail\n * // ...\n * })\n * ```\n */\n 'peer:discovery': CustomEvent<PeerInfo>\n\n /**\n * This event will be triggered any time a new peer connects.\n *\n * @example\n *\n * ```TypeScript\n * libp2p.addEventListener('peer:connect', (event) => {\n * const peerId = event.detail\n * // ...\n * })\n * ```\n */\n 'peer:connect': CustomEvent<PeerId>\n\n /**\n * This event will be triggered any time we are disconnected from another\n * peer, regardless of the circumstances of that disconnection. If we happen\n * to have multiple connections to a peer, this event will **only** be\n * triggered when the last connection is closed.\n *\n * @example\n *\n * ```TypeScript\n * libp2p.addEventListener('peer:disconnect', (event) => {\n * const peerId = event.detail\n * // ...\n * })\n * ```\n */\n 'peer:disconnect': CustomEvent<PeerId>\n\n /**\n * When a peer tagged with `keep-alive` disconnects, we will make multiple\n * attempts to reconnect to it with a backoff factor (see the connection\n * manager settings for details). If these all fail, the `keep-alive` tag will\n * be removed and this event will be emitted.\n *\n * @example\n *\n * ```TypeScript\n * libp2p.addEventListener('peer:reconnect-failure', (event) => {\n * const peerId = event.detail\n * // ...\n * })\n * ```\n */\n 'peer:reconnect-failure': CustomEvent<PeerId>\n\n /**\n * This event is dispatched after a remote peer has successfully responded to\n * the identify protocol. Note that for this to be emitted, both peers must\n * have an identify service configured.\n *\n * @example\n *\n * ```TypeScript\n * libp2p.addEventListener('peer:identify', (event) => {\n * const identifyResult = event.detail\n * // ...\n * })\n * ```\n */\n 'peer:identify': CustomEvent<IdentifyResult>\n\n /**\n * This event is dispatched when the peer store data for a peer has been\n * updated - e.g. their multiaddrs, protocols etc have changed.\n *\n * If they were previously known to this node, the old peer data will be\n * set in the `previous` field.\n *\n * This may be in response to the identify protocol running, a manual\n * update or some other event.\n */\n 'peer:update': CustomEvent<PeerUpdate>\n\n /**\n * This event is dispatched when the current node's peer record changes -\n * for example a transport started listening on a new address or a new\n * protocol handler was registered.\n *\n * @example\n *\n * ```TypeScript\n * libp2p.addEventListener('self:peer:update', (event) => {\n * const { peer } = event.detail\n * // ...\n * })\n * ```\n */\n 'self:peer:update': CustomEvent<PeerUpdate>\n\n /**\n * This event is dispatched when a transport begins listening on a new address\n */\n 'transport:listening': CustomEvent<Listener>\n\n /**\n * This event is dispatched when a transport stops listening on an address\n */\n 'transport:close': CustomEvent<Listener>\n\n /**\n * This event is dispatched when the connection manager has more than the\n * configured allowable max connections and has closed some connections to\n * bring the node back under the limit.\n */\n 'connection:prune': CustomEvent<Connection[]>\n\n /**\n * This event notifies listeners when new incoming or outgoing connections\n * are opened.\n */\n 'connection:open': CustomEvent<Connection>\n\n /**\n * This event notifies listeners when incoming or outgoing connections are\n * closed.\n */\n 'connection:close': CustomEvent<Connection>\n\n /**\n * This event notifies listeners that a TLS certificate is available for use\n */\n 'certificate:provision': CustomEvent<TLSCertificate>\n\n /**\n * This event notifies listeners that a new TLS certificate is available for\n * use. Any previous certificate may no longer be valid.\n */\n 'certificate:renew': CustomEvent<TLSCertificate>\n\n /**\n * This event notifies listeners that the node has started\n *\n * ```TypeScript\n * libp2p.addEventListener('start', (event) => {\n * console.info(libp2p.isStarted()) // true\n * })\n * ```\n */\n start: CustomEvent<Libp2p<T>>\n\n /**\n * This event notifies listeners that the node has stopped\n *\n * ```TypeScript\n * libp2p.addEventListener('stop', (event) => {\n * console.info(libp2p.isStarted()) // false\n * })\n * ```\n */\n stop: CustomEvent<Libp2p<T>>\n}\n\n/**\n * A map of user defined services available on the libp2p node via the\n * `services` key\n *\n * @example\n *\n * ```TypeScript\n * const node = await createLibp2p({\n * // ...other options\n * services: {\n * myService: myService({\n * // ...service options\n * })\n * }\n * })\n *\n * // invoke methods on the service\n * node.services.myService.anOperation()\n * ```\n */\nexport type ServiceMap = Record<string, unknown>\n\nexport type PendingDialStatus = 'queued' | 'active' | 'error' | 'success'\n\n/**\n * An item in the dial queue\n */\nexport interface PendingDial {\n /**\n * A unique identifier for this dial\n */\n id: string\n\n /**\n * The current status of the dial\n */\n status: PendingDialStatus\n\n /**\n * If known, this is the peer id that libp2p expects to be dialling\n */\n peerId?: PeerId\n\n /**\n * The list of multiaddrs that will be dialled. The returned connection will\n * use the first address that succeeds, all other dials part of this pending\n * dial will be cancelled.\n */\n multiaddrs: Multiaddr[]\n}\n\nexport type Libp2pStatus = 'starting' | 'started' | 'stopping' | 'stopped'\n\nexport interface IsDialableOptions extends AbortOptions {\n /**\n * If the dial attempt would open a protocol, and the multiaddr being dialed\n * is a circuit relay address, passing true here would cause the test to fail\n * because that protocol would not be allowed to run over a data/time limited\n * connection.\n */\n runOnLimitedConnection?: boolean\n}\n\nexport type TransportManagerDialProgressEvents =\n ProgressEvent<'transport-manager:selected-transport', string>\n\nexport type OpenConnectionProgressEvents =\n TransportManagerDialProgressEvents |\n ProgressEvent<'dial-queue:already-connected'> |\n ProgressEvent<'dial-queue:already-in-dial-queue'> |\n ProgressEvent<'dial-queue:add-to-dial-queue'> |\n ProgressEvent<'dial-queue:start-dial'> |\n ProgressEvent<'dial-queue:calculated-addresses', Address[]> |\n OutboundConnectionUpgradeEvents\n\nexport interface DialOptions extends AbortOptions, ProgressOptions {\n /**\n * If true, open a new connection to the remote even if one already exists\n */\n force?: boolean\n}\n\nexport interface DialProtocolOptions extends NewStreamOptions {\n\n}\n\n/**\n * Libp2p nodes implement this interface.\n */\nexport interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, TypedEventTarget<Libp2pEvents<T>> {\n /**\n * The PeerId is a unique identifier for a node on the network.\n *\n * It is the hash of an RSA public key or, for Ed25519 or secp256k1 keys,\n * the key itself.\n *\n * @example\n *\n * ```TypeScript\n * console.info(libp2p.peerId)\n * // PeerId(12D3Foo...)\n * ````\n */\n peerId: PeerId\n\n /**\n * The peer store holds information we know about other peers on the network.\n * - multiaddrs, supported protocols, etc.\n *\n * @example\n *\n * ```TypeScript\n * const peer = await libp2p.peerStore.get(peerId)\n * console.info(peer)\n * // { id: PeerId(12D3Foo...), addresses: [] ... }\n * ```\n */\n peerStore: PeerStore\n\n /**\n * The peer routing subsystem allows the user to find peers on the network\n * or to find peers close to binary keys.\n *\n * @example\n *\n * ```TypeScript\n * const peerInfo = await libp2p.peerRouting.findPeer(peerId)\n * console.info(peerInfo)\n * // { id: PeerId(12D3Foo...), multiaddrs: [] ... }\n * ```\n *\n * @example\n *\n * ```TypeScript\n * for await (const peerInfo of libp2p.peerRouting.getClosestPeers(key)) {\n * console.info(peerInfo)\n * // { id: PeerId(12D3Foo...), multiaddrs: [] ... }\n * }\n * ```\n */\n peerRouting: PeerRouting\n\n /**\n * The content routing subsystem allows the user to find providers for content,\n * let the network know they are providers for content, and get/put values to\n * the DHT.\n *\n * @example\n *\n * ```TypeScript\n * for await (const peerInfo of libp2p.contentRouting.findProviders(cid)) {\n * console.info(peerInfo)\n * // { id: PeerId(12D3Foo...), multiaddrs: [] ... }\n * }\n * ```\n */\n contentRouting: ContentRouting\n\n /**\n * The metrics subsystem allows recording values to assess the health/performance\n * of the running node.\n *\n * @example\n *\n * ```TypeScript\n * const metric = libp2p.metrics.registerMetric({\n * 'my-metric'\n * })\n *\n * // later\n * metric.update(5)\n * ```\n */\n metrics?: Metrics\n\n /**\n * The logger used by this libp2p node\n */\n logger: ComponentLogger\n\n /**\n * The current status of the libp2p node\n */\n status: Libp2pStatus\n\n /**\n * Get a deduplicated list of peer advertising multiaddrs by concatenating\n * the listen addresses used by transports with any configured\n * announce addresses as well as observed addresses reported by peers.\n *\n * If Announce addrs are specified, configured listen addresses will be\n * ignored though observed addresses will still be included.\n *\n * @example\n *\n * ```TypeScript\n * const listenMa = libp2p.getMultiaddrs()\n * // [ <Multiaddr 047f00000106f9ba - /ip4/127.0.0.1/tcp/63930> ]\n * ```\n */\n getMultiaddrs(): Multiaddr[]\n\n /**\n * Returns a list of supported protocols\n *\n * @example\n *\n * ```TypeScript\n * const protocols = libp2p.getProtocols()\n * // [ '/ipfs/ping/1.0.0', '/ipfs/id/1.0.0' ]\n * ```\n */\n getProtocols(): string[]\n\n /**\n * Return a list of all connections this node has open, optionally filtering\n * by a PeerId\n *\n * @example\n *\n * ```TypeScript\n * for (const connection of libp2p.getConnections()) {\n * console.log(peerId, connection.remoteAddr.toString())\n * // Logs the PeerId string and the observed remote multiaddr of each Connection\n * }\n * ```\n */\n getConnections(peerId?: PeerId): Connection[]\n\n /**\n * Return the list of dials currently in progress or queued to start\n *\n * @example\n *\n * ```TypeScript\n * for (const pendingDial of libp2p.getDialQueue()) {\n * console.log(pendingDial)\n * }\n * ```\n */\n getDialQueue(): PendingDial[]\n\n /**\n * Return a list of all peers we currently have a connection open to\n */\n getPeers(): PeerId[]\n\n /**\n * Dials to the provided peer. If successful, the known metadata of the\n * peer will be added to the nodes `peerStore`.\n *\n * If a PeerId is passed as the first argument, the peer will need to have known multiaddrs for it in the PeerStore.\n *\n * @example\n *\n * ```TypeScript\n * const conn = await libp2p.dial(remotePeerId)\n *\n * // create a new stream within the connection\n * const stream = await conn.newStream(['/echo/1.1.0', '/echo/1.0.0'])\n *\n * // protocol negotiated: 'echo/1.0.0' means that the other party only supports the older version\n *\n * // ...\n * await conn.close()\n * ```\n */\n dial(peer: PeerId | Multiaddr | Multiaddr[], options?: DialOptions): Promise<Connection>\n\n /**\n * Dials to the provided peer and tries to handshake with the given protocols in order.\n * If successful, the known metadata of the peer will be added to the nodes `peerStore`,\n * and the `MuxedStream` will be returned together with the successful negotiated protocol.\n *\n * @example\n *\n * ```TypeScript\n * import { pipe } from 'it-pipe'\n *\n * const { stream, protocol } = await libp2p.dialProtocol(remotePeerId, protocols)\n *\n * // Use this new stream like any other duplex stream\n * pipe([1, 2, 3], stream, consume)\n * ```\n */\n dialProtocol(peer: PeerId | Multiaddr | Multiaddr[], protocols: string | string[], options?: DialProtocolOptions): Promise<Stream>\n\n /**\n * Attempts to gracefully close an open connection to the given peer. If the\n * connection is not closed in the grace period, it will be forcefully closed.\n *\n * An AbortSignal can optionally be passed to control when the connection is\n * forcefully closed.\n *\n * @example\n *\n * ```TypeScript\n * await libp2p.hangUp(remotePeerId)\n * ```\n */\n hangUp(peer: PeerId | Multiaddr, options?: AbortOptions): Promise<void>\n\n /**\n * Sets up [multistream-select routing](https://github.com/multiformats/multistream-select) of protocols to their application handlers. Whenever a stream is opened on one of the provided protocols, the handler will be called. `handle` must be called in order to register a handler and support for a given protocol. This also informs other peers of the protocols you support.\n *\n * `libp2p.handle(protocols, handler, options)`\n *\n * In the event of a new handler for the same protocol being added and error\n * will be thrown. Pass `force: true` to override this.\n *\n * @example\n *\n * ```TypeScript\n * const handler = ({ connection, stream, protocol }) => {\n * // use stream or connection according to the needs\n * }\n *\n * libp2p.handle('/echo/1.0.0', handler, {\n * maxInboundStreams: 5,\n * maxOutboundStreams: 5\n * })\n * ```\n */\n handle(protocol: string | string[], handler: StreamHandler, options?: StreamHandlerOptions): Promise<void>\n\n /**\n * Removes the handler for each protocol. The protocol\n * will no longer be supported on streams.\n *\n * @example\n *\n * ```TypeScript\n * libp2p.unhandle(['/echo/1.0.0'])\n * ```\n */\n unhandle(protocols: string[] | string, options?: AbortOptions): Promise<void>\n\n /**\n * Register a topology to be informed when peers are encountered that\n * support the specified protocol\n *\n * @example\n *\n * ```TypeScript\n * const id = await libp2p.register('/echo/1.0.0', {\n * onConnect: (peer, connection) => {\n * // handle connect\n * },\n * onDisconnect: (peer, connection) => {\n * // handle disconnect\n * }\n * })\n * ```\n */\n register(protocol: string, topology: Topology, options?: AbortOptions): Promise<string>\n\n /**\n * Unregister topology to no longer be informed when peers connect or\n * disconnect.\n *\n * @example\n *\n * ```TypeScript\n * const id = await libp2p.register(...)\n *\n * libp2p.unregister(id)\n * ```\n */\n unregister(id: string): void\n\n /**\n * Registers one or more middleware implementations that will be invoked for\n * incoming and outgoing protocol streams that match the passed protocol.\n *\n * @example\n *\n * ```TypeScript\n * libp2p.use('/my/protocol/1.0.0', (stream, connection, next) => {\n * // do something with stream and/or connection\n * next(stream, connection)\n * })\n * ```\n */\n use (protocol: string, middleware: StreamMiddleware | StreamMiddleware[]): void\n\n /**\n * Deregisters all middleware for the passed protocol.\n *\n * @example\n *\n * ```TypeScript\n * libp2p.unuse('/my/protocol/1.0.0')\n * // any previously registered middleware will no longer be invoked\n * ```\n */\n unuse (protocol: string): void\n\n /**\n * Returns the public key for the passed PeerId. If the PeerId is of the 'RSA'\n * type this may mean searching the routing if the peer's key is not present\n * in the peer store.\n */\n getPublicKey(peer: Ed25519PeerId, options?: AbortOptions): Promise<Ed25519PublicKey>\n getPublicKey(peer: Secp256k1PeerId, options?: AbortOptions): Promise<Secp256k1PublicKey>\n getPublicKey(peer: RSAPeerId, options?: AbortOptions): Promise<RSAPublicKey>\n getPublicKey(peer: URLPeerId, options?: AbortOptions): Promise<never>\n getPublicKey(peer: PeerId, options?: AbortOptions): Promise<PublicKey>\n\n /**\n * Given the current node configuration, returns a promise of `true` or\n * `false` if the node would attempt to dial the passed multiaddr.\n *\n * This means a relevant transport is configured, and the connection gater\n * would not block the dial attempt.\n *\n * This may involve resolving DNS addresses so you should pass an AbortSignal.\n */\n isDialable(multiaddr: Multiaddr | Multiaddr[], options?: IsDialableOptions): Promise<boolean>\n\n /**\n * A set of user defined services\n */\n services: T\n}\n\n/**\n * Metadata about the current node\n */\nexport interface NodeInfo {\n /**\n * The implementation name\n */\n name: string\n\n /**\n * The implementation version\n */\n version: string\n\n /**\n * A string that contains information about the implementation and runtime\n */\n userAgent: string\n}\n\n/**\n * An object that contains an AbortSignal as\n * the optional `signal` property.\n *\n * @example\n *\n * ```TypeScript\n * const controller = new AbortController()\n *\n * aLongRunningOperation({\n * signal: controller.signal\n * })\n *\n * // later\n *\n * controller.abort()\n */\nexport interface AbortOptions {\n signal?: AbortSignal\n}\n\n/**\n * An object that contains a Logger as the `log` property.\n */\nexport interface LoggerOptions {\n log: Logger\n}\n\n/**\n * An object that includes a trace object that is passed onwards.\n *\n * This is used by metrics method tracing to link function calls together.\n */\nexport interface TraceOptions {\n trace?: any\n}\n\n/**\n * A signal that needs to be cleared when no longer in use\n */\nexport interface ClearableSignal extends AbortSignal {\n clear(): void\n}\n\n/**\n * When a routing operation involves reading values, these options allow\n * controlling where the values are read from. By default libp2p will check\n * local caches but may not use the network if a valid local value is found,\n * these options allow tuning that behavior.\n */\nexport interface RoutingOptions extends AbortOptions, ProgressOptions, TraceOptions {\n /**\n * Pass `false` to not use the network\n *\n * @default true\n */\n useNetwork?: boolean\n\n /**\n * Pass `false` to not use cached values\n *\n * @default true\n */\n useCache?: boolean\n}\n\n/**\n * This symbol is used by libp2p services to define the capabilities they can\n * provide to other libp2p services.\n *\n * The service should define a property with this symbol as the key and the\n * value should be a string array of provided capabilities.\n */\nexport const serviceCapabilities = Symbol.for('@libp2p/service-capabilities')\n\n/**\n * This symbol is used by libp2p services to define the capabilities they\n * require from other libp2p services.\n *\n * The service should define a property with this symbol as the key and the\n * value should be a string array of required capabilities.\n */\nexport const serviceDependencies = Symbol.for('@libp2p/service-dependencies')\n\nexport * from './connection.js'\nexport * from './connection-encrypter.js'\nexport * from './connection-gater.js'\nexport * from './connection-protector.js'\nexport * from './content-routing.js'\nexport * from './errors.js'\nexport * from './events.js'\nexport * from './keys.js'\nexport * from './message-stream.js'\nexport * from './metrics.js'\nexport * from './multiaddr-connection.js'\nexport * from './peer-discovery.js'\nexport * from './peer-id.js'\nexport * from './peer-info.js'\nexport * from './peer-routing.js'\nexport * from './peer-store.js'\nexport * from './record.js'\nexport * from './startable.js'\nexport * from './stream-handler.js'\nexport * from './stream-muxer.js'\nexport * from './stream.js'\nexport * from './topology.js'\nexport * from './transport.js'\n\nexport * from 'main-event'\n", "import type { AbortOptions, Logger, TypedEventTarget, Stream, MessageStreamEvents, PeerId, MultiaddrConnectionTimeline, MessageStreamStatus, MessageStreamDirection } from './index.js'\nimport type { Multiaddr } from '@multiformats/multiaddr'\n\nexport type ConnectionStatus = MessageStreamStatus\n\n/**\n * Connection limits are present on connections that are only allowed to\n * transfer a certain amount of bytes or be open for a certain number\n * of seconds.\n *\n * These limits are applied by Circuit Relay v2 servers, for example and\n * the connection will normally be closed abruptly if the limits are\n * exceeded.\n */\nexport interface ConnectionLimits {\n /**\n * If present this is the number of bytes remaining that may be\n * transferred over this connection\n */\n bytes?: bigint\n\n /**\n * If present this is the number of seconds that this connection will\n * remain open for\n */\n seconds?: number\n}\n\nexport interface NewStreamOptions extends AbortOptions {\n /**\n * If specified, and no handler has been registered with the registrar for the\n * successfully negotiated protocol, use this as the max outbound stream limit\n * for the protocol\n */\n maxOutboundStreams?: number\n\n /**\n * Opt-in to running over a limited connection - one that has restrictions\n * on the amount of data that may be transferred or how long it may be open\n * for.\n *\n * These limits are typically enforced by a relay server, if the protocol will\n * be transferring a lot of data or the stream will be open for a long time\n * consider upgrading to a direct connection before opening the stream.\n *\n * @default false\n */\n runOnLimitedConnection?: boolean\n\n /**\n * By default when negotiating a protocol the dialer writes then protocol name\n * then reads the response.\n *\n * When a only a single protocol is being negotiated on an outbound stream,\n * and the stream is written to before being read from, we can optimistically\n * write the protocol name and the first chunk of data together in the first\n * message.\n *\n * Reading and handling the protocol response is done asynchronously, which\n * means we can skip a round trip on writing to newly opened streams which\n * significantly reduces the time-to-first-byte on a stream.\n *\n * The side-effect of this is that the underlying stream won't negotiate the\n * protocol until either data is written to or read from the stream so it will\n * not be opened on the remote until this is done.\n *\n * Pass `false` here to optimistically write the protocol name and first chunk\n * of data in the first message.\n *\n * If multiple protocols are being negotiated, negotiation is always completed\n * in full before the stream is returned so this option has no effect.\n *\n * @default true\n */\n negotiateFully?: boolean\n}\n\n/**\n * A Connection is a high-level representation of a connection\n * to a remote peer that may have been secured by encryption and\n * multiplexed, depending on the configuration of the nodes\n * between which the connection is made.\n */\nexport interface Connection extends TypedEventTarget<Omit<MessageStreamEvents, 'drain' | 'message'>> {\n /**\n * The unique identifier for this connection\n */\n id: string\n\n /**\n * The address of the remote end of the connection\n */\n remoteAddr: Multiaddr\n\n /**\n * The id of the peer at the remote end of the connection\n */\n remotePeer: PeerId\n\n /**\n * A list of open streams on this connection\n */\n streams: Stream[]\n\n /**\n * Outbound connections are opened by the local node, inbound streams are opened by the remote\n */\n direction: MessageStreamDirection\n\n /**\n * When stream life cycle events occurred\n */\n timeline: MultiaddrConnectionTimeline\n\n /**\n * The multiplexer negotiated for this connection\n */\n multiplexer?: string\n\n /**\n * The encryption protocol negotiated for this connection\n */\n encryption?: string\n\n /**\n * The current status of the connection\n */\n status: ConnectionStatus\n\n /**\n * Whether this connection is direct or, for example, is via a relay\n */\n direct: boolean\n\n /**\n * If present, this connection has limits applied to it, perhaps by an\n * intermediate relay. Once the limits have been reached the connection will\n * be closed by the relay.\n */\n limits?: ConnectionLimits\n\n /**\n * The time in milliseconds it takes to make a round trip to the remote peer.\n *\n * This is updated periodically by the connection monitor.\n */\n rtt?: number\n\n /**\n * The connection logger, used to log connection-specific information\n */\n log: Logger\n\n /**\n * Create a new stream on this connection and negotiate one of the passed protocols\n */\n newStream(protocols: string | string[], options?: NewStreamOptions): Promise<Stream>\n\n /**\n * Gracefully close the connection. The returned promise will resolve when all\n * queued data has been written to the underlying transport. Any unread data\n * will still be emitted as a 'message' event.\n */\n close(options?: AbortOptions): Promise<void>\n\n /**\n * Immediately close the connection. Any data queued to be sent or read will\n * be discarded.\n */\n abort(err: Error): void\n}\n\nexport const connectionSymbol = Symbol.for('@libp2p/connection')\n\nexport function isConnection (other: any): other is Connection {\n return other != null && Boolean(other[connectionSymbol])\n}\n", "import type { RoutingOptions } from './index.js'\nimport type { PeerInfo } from './peer-info.js'\nimport type { CID } from 'multiformats/cid'\n\nexport interface Provider extends PeerInfo {\n /**\n * Which routing subsystem found the provider\n */\n routing: string\n}\n\n/**\n * Any object that implements this Symbol as a property should return a\n * Partial<ContentRouting> instance as the property value, similar to how\n * `Symbol.Iterable` can be used to return an `Iterable` from an `Iterator`.\n *\n * @example\n *\n * ```TypeScript\n * import { contentRoutingSymbol, ContentRouting } from '@libp2p/content-routing'\n *\n * class MyContentRouter implements ContentRouting {\n * get [contentRoutingSymbol] () {\n * return this\n * }\n *\n * // ...other methods\n * }\n * ```\n */\nexport const contentRoutingSymbol = Symbol.for('@libp2p/content-routing')\n\n/**\n * Implementers of this interface can provide a ContentRouting implementation to\n * interested callers.\n */\nexport interface ContentRoutingProvider {\n [contentRoutingSymbol]: Partial<ContentRouting>\n}\n\nexport interface ContentRouting {\n /**\n * The implementation of this method should ensure that network peers know the\n * caller can provide content that corresponds to the passed CID.\n *\n * @example\n *\n * ```TypeScript\n * // ...\n * await contentRouting.provide(cid)\n * ```\n */\n provide(cid: CID, options?: RoutingOptions): Promise<void>\n\n /**\n * If network peers need to be periodically reminded that the caller can\n * provide content corresponding to the passed CID, call this function to no\n * longer remind them.\n */\n cancelReprovide (key: CID, options?: RoutingOptions): Promise<void>\n\n /**\n * Find the providers of the passed CID.\n *\n * @example\n *\n * ```TypeScript\n * // Iterate over the providers found for the given cid\n * for await (const provider of contentRouting.findProviders(cid)) {\n * console.log(provider.id, provider.multiaddrs)\n * }\n * ```\n */\n findProviders(cid: CID, options?: RoutingOptions): AsyncIterable<Provider>\n\n /**\n * Puts a value corresponding to the passed key in a way that can later be\n * retrieved by another network peer using the get method.\n *\n * @example\n *\n * ```TypeScript\n * // ...\n * const key = '/key'\n * const value = uint8ArrayFromString('oh hello there')\n *\n * await contentRouting.put(key, value)\n * ```\n */\n put(key: Uint8Array, value: Uint8Array, options?: RoutingOptions): Promise<void>\n\n /**\n * Retrieves a value from the network corresponding to the passed key.\n *\n * @example\n *\n * ```TypeScript\n * // ...\n *\n * const key = '/key'\n * const value = await contentRouting.get(key)\n * ```\n */\n get(key: Uint8Array, options?: RoutingOptions): Promise<Uint8Array>\n}\n", "/**\n * When this error is thrown it means an operation was aborted,\n * usually in response to the `abort` event being emitted by an\n * AbortSignal.\n */\nexport class AbortError extends Error {\n static name = 'AbortError'\n\n constructor (message: string = 'The operation was aborted') {\n super(message)\n this.name = 'AbortError'\n }\n}\n\n/**\n * Thrown when a remote Peer ID does not match the expected one\n */\nexport class UnexpectedPeerError extends Error {\n static name = 'UnexpectedPeerError'\n\n constructor (message = 'Unexpected Peer') {\n super(message)\n this.name = 'UnexpectedPeerError'\n }\n}\n\n/**\n * Thrown when a crypto exchange fails\n */\nexport class InvalidCryptoExchangeError extends Error {\n static name = 'InvalidCryptoExchangeError'\n\n constructor (message = 'Invalid crypto exchange') {\n super(message)\n this.name = 'InvalidCryptoExchangeError'\n }\n}\n\n/**\n * Thrown when invalid parameters are passed to a function or method call\n */\nexport class InvalidParametersError extends Error {\n static name = 'InvalidParametersError'\n\n constructor (message = 'Invalid parameters') {\n super(message)\n this.name = 'InvalidParametersError'\n }\n}\n\n/**\n * Thrown when a public key is invalid\n */\nexport class InvalidPublicKeyError extends Error {\n static name = 'InvalidPublicKeyError'\n\n constructor (message = 'Invalid public key') {\n super(message)\n this.name = 'InvalidPublicKeyError'\n }\n}\n\n/**\n * Thrown when a private key is invalid\n */\nexport class InvalidPrivateKeyError extends Error {\n static name = 'InvalidPrivateKeyError'\n\n constructor (message = 'Invalid private key') {\n super(message)\n this.name = 'InvalidPrivateKeyError'\n }\n}\n\n/**\n * Thrown when a operation is unsupported\n */\nexport class UnsupportedOperationError extends Error {\n static name = 'UnsupportedOperationError'\n\n constructor (message = 'Unsupported operation') {\n super(message)\n this.name = 'UnsupportedOperationError'\n }\n}\n\n/**\n * Thrown when a connection is closing\n */\nexport class ConnectionClosingError extends Error {\n static name = 'ConnectionClosingError'\n\n constructor (message = 'The connection is closing') {\n super(message)\n this.name = 'ConnectionClosingError'\n }\n}\n\n/**\n * Thrown when a connection is closed\n */\nexport class ConnectionClosedError extends Error {\n static name = 'ConnectionClosedError'\n\n constructor (message = 'The connection is closed') {\n super(message)\n this.name = 'ConnectionClosedError'\n }\n}\n\n/**\n * Thrown when a connection fails\n */\nexport class ConnectionFailedError extends Error {\n static name = 'ConnectionFailedError'\n\n constructor (message = 'Connection failed') {\n super(message)\n this.name = 'ConnectionFailedError'\n }\n}\n\n/**\n * Thrown when the muxer is closed and an attempt to open a stream occurs\n */\nexport class MuxerClosedError extends Error {\n static name = 'MuxerClosedError'\n\n constructor (message = 'The muxer is closed') {\n super(message)\n this.name = 'MuxerClosedError'\n }\n}\n\n/**\n * Thrown when a protocol stream is reset by the remote muxer\n */\nexport class StreamResetError extends Error {\n static name = 'StreamResetError'\n\n constructor (message = 'The stream has been reset') {\n super(message)\n this.name = 'StreamResetError'\n }\n}\n\n/**\n * Thrown when a protocol stream is aborted locally\n */\nexport class StreamAbortedError extends Error {\n static name = 'StreamAbortedError'\n\n constructor (message = 'The stream has been aborted') {\n super(message)\n this.name = 'StreamAbortedError'\n }\n}\n\n/**\n * Thrown when a stream is in an invalid state\n */\nexport class StreamStateError extends Error {\n static name = 'StreamStateError'\n\n constructor (message = 'The stream is in an invalid state') {\n super(message)\n this.name = 'StreamStateError'\n }\n}\n\n/**\n * Thrown when a stream buffer is full\n */\nexport class StreamBufferError extends Error {\n static name = 'StreamBufferError'\n\n constructor (message = 'The stream buffer was full') {\n super(message)\n this.name = 'StreamBufferError'\n }\n}\n\n/**\n * Thrown when a value could not be found\n */\nexport class NotFoundError extends Error {\n static name = 'NotFoundError'\n\n constructor (message = 'Not found') {\n super(message)\n this.name = 'NotFoundError'\n }\n}\n\n/**\n * Thrown when an invalid peer ID is encountered\n */\nexport class InvalidPeerIdError extends Error {\n static name = 'InvalidPeerIdError'\n\n constructor (message = 'Invalid PeerID') {\n super(message)\n this.name = 'InvalidPeerIdError'\n }\n}\n\n/**\n * Thrown when an invalid multiaddr is encountered\n */\nexport class InvalidMultiaddrError extends Error {\n static name = 'InvalidMultiaddrError'\n\n constructor (message = 'Invalid multiaddr') {\n super(message)\n this.name = 'InvalidMultiaddrError'\n }\n}\n\n/**\n * Thrown when an invalid CID is encountered\n */\nexport class InvalidCIDError extends Error {\n static name = 'InvalidCIDError'\n\n constructor (message = 'Invalid CID') {\n super(message)\n this.name = 'InvalidCIDError'\n }\n}\n\n/**\n * Thrown when an invalid multihash is encountered\n */\nexport class InvalidMultihashError extends Error {\n static name = 'InvalidMultihashError'\n\n constructor (message = 'Invalid Multihash') {\n super(message)\n this.name = 'InvalidMultihashError'\n }\n}\n\n/**\n * Thrown when a protocol is not supported\n */\nexport class UnsupportedProtocolError extends Error {\n static name = 'UnsupportedProtocolError'\n\n constructor (message = 'Unsupported protocol error') {\n super(message)\n this.name = 'UnsupportedProtocolError'\n }\n}\n\n/**\n * An invalid or malformed message was encountered during a protocol exchange\n */\nexport class InvalidMessageError extends Error {\n static name = 'InvalidMessageError'\n\n constructor (message = 'Invalid message') {\n super(message)\n this.name = 'InvalidMessageError'\n }\n}\n\n/**\n * Thrown when a remote peer sends a structurally valid message that does not\n * comply with the protocol\n */\nexport class ProtocolError extends Error {\n static name = 'ProtocolError'\n\n constructor (message = 'Protocol error') {\n super(message)\n this.name = 'ProtocolError'\n }\n}\n\n/**\n * Throw when an operation times out\n */\nexport class TimeoutError extends Error {\n static name = 'TimeoutError'\n\n constructor (message = 'Timed out') {\n super(message)\n this.name = 'TimeoutError'\n }\n}\n\n/**\n * Thrown when a startable component is interacted with but it has not been\n * started yet\n */\nexport class NotStartedError extends Error {\n static name = 'NotStartedError'\n\n constructor (message = 'Not started') {\n super(message)\n this.name = 'NotStartedError'\n }\n}\n\n/**\n * Thrown when a component is started that has already been started\n */\nexport class AlreadyStartedError extends Error {\n static name = 'AlreadyStartedError'\n\n constructor (message = 'Already started') {\n super(message)\n this.name = 'AlreadyStartedError'\n }\n}\n\n/**\n * Thrown when dialing an address failed\n */\nexport class DialError extends Error {\n static name = 'DialError'\n\n constructor (message = 'Dial error') {\n super(message)\n this.name = 'DialError'\n }\n}\n\n/**\n * Thrown when listening on an address failed\n */\nexport class ListenError extends Error {\n static name = 'ListenError'\n\n constructor (message = 'Listen error') {\n super(message)\n this.name = 'ListenError'\n }\n}\n\n/**\n * This error is thrown when a limited connection is encountered, i.e. if the\n * user tried to open a stream on a connection for a protocol that is not\n * configured to run over limited connections.\n */\nexport class LimitedConnectionError extends Error {\n static name = 'LimitedConnectionError'\n\n constructor (message = 'Limited connection') {\n super(message)\n this.name = 'LimitedConnectionError'\n }\n}\n\n/**\n * This error is thrown where there are too many inbound protocols streams open\n */\nexport class TooManyInboundProtocolStreamsError extends Error {\n static name = 'TooManyInboundProtocolStreamsError'\n\n constructor (message = 'Too many inbound protocol streams') {\n super(message)\n this.name = 'TooManyInboundProtocolStreamsError'\n }\n}\n\n/**\n * This error is thrown where there are too many outbound protocols streams open\n */\nexport class TooManyOutboundProtocolStreamsError extends Error {\n static name = 'TooManyOutboundProtocolStreamsError'\n\n constructor (message = 'Too many outbound protocol streams') {\n super(message)\n this.name = 'TooManyOutboundProtocolStreamsError'\n }\n}\n\n/**\n * Thrown when an attempt to operate on an unsupported key was made\n */\nexport class UnsupportedKeyTypeError extends Error {\n static name = 'UnsupportedKeyTypeError'\n\n constructor (message = 'Unsupported key type') {\n super(message)\n this.name = 'UnsupportedKeyTypeError'\n }\n}\n\n/**\n * Thrown when an operation has not been implemented\n */\nexport class NotImplementedError extends Error {\n static name = 'NotImplementedError'\n\n constructor (message = 'Not implemented') {\n super(message)\n this.name = 'NotImplementedError'\n }\n}\n", "import type { Uint8ArrayList } from 'uint8arraylist'\n\n/**\n * A custom implementation of MessageEvent as the Undici version does too much\n * validation in it's constructor so is very slow.\n */\nexport class StreamMessageEvent extends Event {\n public data: Uint8Array | Uint8ArrayList\n\n constructor (data: Uint8Array | Uint8ArrayList, eventInitDict?: EventInit) {\n super('message', eventInitDict)\n\n this.data = data\n }\n}\n\n/**\n * An event dispatched when the stream is closed. The `error` property can be\n * inspected to discover if the closing was graceful or not, and the `remote`\n * property shows which end of the stream initiated the closure\n */\nexport class StreamCloseEvent extends Event {\n public error?: Error\n public local?: boolean\n\n constructor (local?: boolean, error?: Error, eventInitDict?: EventInit) {\n super('close', eventInitDict)\n\n this.error = error\n this.local = local\n }\n}\n\nexport class StreamAbortEvent extends StreamCloseEvent {\n constructor (error: Error, eventInitDict?: EventInit) {\n super(true, error, eventInitDict)\n }\n}\n\nexport class StreamResetEvent extends StreamCloseEvent {\n constructor (error: Error, eventInitDict?: EventInit) {\n super(false, error, eventInitDict)\n }\n}\n", "import type { AbortOptions } from './index.ts'\nimport type { CID } from 'multiformats/cid'\nimport type { MultihashDigest } from 'multiformats/hashes/interface'\nimport type { Uint8ArrayList } from 'uint8arraylist'\n\nexport type KeyType = 'RSA' | 'Ed25519' | 'secp256k1' | 'ECDSA'\n\nexport interface RSAPublicKey {\n /**\n * The type of this key\n */\n readonly type: 'RSA'\n\n /**\n * PKIX in ASN1 DER format\n */\n readonly raw: Uint8Array\n\n /**\n * The public key as a JSON web key\n */\n readonly jwk: JsonWebKey\n\n /**\n * Returns `true` if the passed object matches this key\n */\n equals(key?: any): boolean\n\n /**\n * Returns this public key as a Multihash digest.\n *\n * It contains a sha256 hash of the protobuf version of the public key.\n */\n toMultihash(): MultihashDigest<0x12>\n\n /**\n * Return this public key as a CID encoded with the `libp2p-key` codec\n *\n * The digest contains a sha256 hash of the protobuf version of the public\n * key.\n */\n toCID(): CID<unknown, 0x72, 0x12, 1>\n\n /**\n * Verify the passed data was signed by the private key corresponding to this\n * public key\n */\n verify(data: Uint8Array | Uint8ArrayList, sig: Uint8Array, options?: AbortOptions): boolean | Promise<boolean>\n\n /**\n * Returns this key as a multihash with base58btc encoding\n */\n toString(): string\n}\n\nexport interface Ed25519PublicKey {\n /**\n * The type of this key\n */\n readonly type: 'Ed25519'\n\n /**\n * The raw public key bytes\n */\n readonly raw: Uint8Array\n\n /**\n * Returns `true` if the passed object matches this key\n */\n equals(key?: any): boolean\n\n /**\n * Returns this public key as an identity hash containing the protobuf wrapped\n * public key\n */\n toMultihash(): MultihashDigest<0x0>\n\n /**\n * Return this public key as a CID encoded with the `libp2p-key` codec\n *\n * The digest contains an identity hash containing the protobuf wrapped\n * version of the public key.\n */\n toCID(): CID<unknown, 0x72, 0x0, 1>\n\n /**\n * Verify the passed data was signed by the private key corresponding to this\n * public key\n */\n verify(data: Uint8Array | Uint8ArrayList, sig: Uint8Array, options?: AbortOptions): boolean | Promise<boolean>\n\n /**\n * Returns this key as a multihash with base58btc encoding\n */\n toString(): string\n}\n\nexport interface Secp256k1PublicKey {\n /**\n * The type of this key\n */\n readonly type: 'secp256k1'\n\n /**\n * The raw public key bytes\n */\n readonly raw: Uint8Array\n\n /**\n * Returns `true` if the passed object matches this key\n */\n equals(key?: any): boolean\n\n /**\n * Returns this public key as an identity hash containing the protobuf wrapped\n * public key\n */\n toMultihash(): MultihashDigest<0x0>\n\n /**\n * Return this public key as a CID encoded with the `libp2p-key` codec\n *\n * The digest contains an identity hash containing the protobuf wrapped\n * version of the public key.\n */\n toCID(): CID<unknown, 0x72, 0x0, 1>\n\n /**\n * Verify the passed data was signed by the private key corresponding to this\n * public key\n */\n verify(data: Uint8Array | Uint8ArrayList, sig: Uint8Array, options?: AbortOptions): boolean | Promise<boolean>\n\n /**\n * Returns this key as a multihash with base58btc encoding\n */\n toString(): string\n}\n\nexport interface ECDSAPublicKey {\n /**\n * The type of this key\n */\n readonly type: 'ECDSA'\n\n /**\n * The public key as a DER-encoded PKIMessage\n */\n readonly raw: Uint8Array\n\n /**\n * The public key as a JSON web key\n */\n readonly jwk: JsonWebKey\n\n /**\n * Returns `true` if the passed object matches this key\n */\n equals(key?: any): boolean\n\n /**\n * Returns this public key as an identity hash containing the protobuf wrapped\n * public key\n */\n toMultihash(): MultihashDigest<0x0>\n\n /**\n * Return this public key as a CID encoded with the `libp2p-key` codec\n *\n * The digest contains an identity hash containing the protobuf wrapped\n * version of the public key.\n */\n toCID(): CID<unknown, 0x72, 0x0, 1>\n\n /**\n * Verify the passed data was signed by the private key corresponding to this\n * public key\n */\n verify(data: Uint8Array | Uint8ArrayList, sig: Uint8Array, options?: AbortOptions): boolean | Promise<boolean>\n\n /**\n * Returns this key as a multihash with base58btc encoding\n */\n toString(): string\n}\n\nexport type PublicKey = RSAPublicKey | Ed25519PublicKey | Secp256k1PublicKey | ECDSAPublicKey\n\n/**\n * Returns true if the passed argument has type overlap with the `PublicKey`\n * interface. Can be used to disambiguate object types.\n */\nexport function isPublicKey (key?: any): key is PublicKey {\n if (key == null) {\n return false\n }\n\n return (key.type === 'RSA' || key.type === 'Ed25519' || key.type === 'secp256k1' || key.type === 'ECDSA') &&\n key.raw instanceof Uint8Array &&\n typeof key.equals === 'function' &&\n typeof key.toMultihash === 'function' &&\n typeof key.toCID === 'function' &&\n typeof key.verify === 'function'\n}\n\n/**\n * Generic private key interface\n */\nexport interface RSAPrivateKey {\n /**\n * The type of this key\n */\n readonly type: 'RSA'\n\n /**\n * The public key that corresponds to this private key\n */\n readonly publicKey: RSAPublicKey\n\n /**\n * PKIX in ASN1 DER format\n */\n readonly raw: Uint8Array\n\n /**\n * The private key as a JSON web key\n */\n readonly jwk: JsonWebKey\n\n /**\n * Returns `true` if the passed object matches this key\n */\n equals(key?: any): boolean\n\n /**\n * Sign the passed data with this private key and return the signature for\n * later verification\n */\n sign(data: Uint8Array | Uint8ArrayList, options?: AbortOptions): Uint8Array | Promise<Uint8Array>\n}\n\nexport interface Ed25519PrivateKey {\n /**\n * The type of this key\n */\n readonly type: 'Ed25519'\n\n /**\n * The public key that corresponds to this private key\n */\n readonly publicKey: Ed25519PublicKey\n\n /**\n * The raw private key bytes\n */\n readonly raw: Uint8Array\n\n /**\n * Returns `true` if the passed object matches this key\n */\n equals(key?: any): boolean\n\n /**\n * Sign the passed data with this private key and return the signature for\n * later verification\n */\n sign(data: Uint8Array | Uint8ArrayList, options?: AbortOptions): Uint8Array | Promise<Uint8Array>\n}\n\nexport interface Secp256k1PrivateKey {\n /**\n * The type of this key\n */\n readonly type: 'secp256k1'\n\n /**\n * The public key that corresponds to this private key\n */\n readonly publicKey: Secp256k1PublicKey\n\n /**\n * The raw private key bytes\n */\n readonly raw: Uint8Array\n\n /**\n * Returns `true` if the passed object matches this key\n */\n equals(key?: any): boolean\n\n /**\n * Sign the passed data with this private key and return the signature for\n * later verification\n */\n sign(data: Uint8Array | Uint8ArrayList, options?: AbortOptions): Uint8Array | Promise<Uint8Array>\n}\n\nexport interface ECDSAPrivateKey {\n /**\n * The type of this key\n */\n readonly type: 'ECDSA'\n\n /**\n * The public key that corresponds to this private key\n */\n readonly publicKey: ECDSAPublicKey\n\n /**\n * The private key as a DER-encoded PKIMessage\n */\n readonly raw: Uint8Array\n\n /**\n * The private key as a JSON web key\n */\n readonly jwk: JsonWebKey\n\n /**\n * Returns `true` if the passed object matches this key\n */\n equals(key?: any): boolean\n\n /**\n * Sign the passed data with this private key and return the signature for\n * later verification\n */\n sign(data: Uint8Array | Uint8ArrayList, options?: AbortOptions): Uint8Array | Promise<Uint8Array>\n}\n\nexport type PrivateKey = RSAPrivateKey | Ed25519PrivateKey | Secp256k1PrivateKey | ECDSAPrivateKey\n\n/**\n * Returns true if the passed argument has type overlap with the `PrivateKey`\n * interface. Can be used to disambiguate object types.\n */\nexport function isPrivateKey (key?: any): key is PrivateKey {\n if (key == null) {\n return false\n }\n\n return (key.type === 'RSA' || key.type === 'Ed25519' || key.type === 'secp256k1' || key.type === 'ECDSA') &&\n isPublicKey(key.publicKey) &&\n key.raw instanceof Uint8Array &&\n typeof key.equals === 'function' &&\n typeof key.sign === 'function'\n}\n", "import type { PeerInfo } from './peer-info.js'\nimport type { TypedEventTarget } from 'main-event'\n\n/**\n * Any object that implements this Symbol as a property should return a\n * PeerDiscovery instance as the property value, similar to how\n * `Symbol.Iterable` can be used to return an `Iterable` from an `Iterator`.\n *\n * @example\n *\n * ```TypeScript\n * import { peerDiscovery, PeerDiscovery } from '@libp2p/peer-discovery'\n *\n * class MyPeerDiscoverer implements PeerDiscovery {\n * get [peerDiscovery] () {\n * return this\n * }\n *\n * // ...other methods\n * }\n * ```\n */\nexport const peerDiscoverySymbol = Symbol.for('@libp2p/peer-discovery')\n\n/**\n * Implementers of this interface can provide a PeerDiscovery implementation to\n * interested callers.\n */\nexport interface PeerDiscoveryProvider {\n [peerDiscoverySymbol]: PeerDiscovery\n}\n\nexport interface PeerDiscoveryEvents {\n peer: CustomEvent<PeerInfo>\n}\n\n/**\n * A class that implements the `PeerDiscovery` interface uses an\n * implementation-specific method to discover peers. These peers are then added\n * to the peer store for use by other system components and services.\n */\nexport interface PeerDiscovery extends TypedEventTarget<PeerDiscoveryEvents> {}\n", "import type { Ed25519PublicKey, KeyType, RSAPublicKey, Secp256k1PublicKey } from './keys.js'\nimport type { CID } from 'multiformats/cid'\nimport type { MultihashDigest } from 'multiformats/hashes/interface'\n\nexport type PeerIdType = KeyType | string\n\n/**\n * A PeerId generated from an RSA public key - it is a base58btc encoded sha-256\n * hash of the public key.\n *\n * RSA public keys are too large to pass around freely, instead Ed25519 or\n * secp256k1 should be preferred as they can embed their public key in the\n * PeerId itself.\n *\n * @deprecated Ed25519 or secp256k1 keys are preferred to RSA\n */\nexport interface RSAPeerId {\n readonly type: 'RSA'\n\n /**\n * RSA public keys are too large to embed in the multihash commonly used to\n * refer to peers, so this will only be defined if the public key has\n * previously been found through a routing query or during normal protocol\n * operations\n */\n readonly publicKey?: RSAPublicKey\n\n /**\n * Returns the multihash from `toMultihash()` as a base58btc encoded string\n */\n toString(): string\n\n /**\n * Returns a multihash, the digest of which is the SHA2-256 hash of the public\n * key\n */\n toMultihash(): MultihashDigest<0x12>\n\n /**\n * Returns a CID with the libp2p key code and the same multihash as\n * `toMultihash()`\n */\n toCID(): CID<Uint8Array, 0x72, 0x12, 1>\n\n /**\n * Returns true if the passed argument is equivalent to this PeerId\n */\n equals(other?: any): boolean\n}\n\nexport interface Ed25519PeerId {\n readonly type: 'Ed25519'\n\n /**\n * This will always be defined as the public key is embedded in the multihash\n * of this PeerId\n */\n readonly publicKey: Ed25519PublicKey\n\n /**\n * Returns the multihash from `toMultihash()` as a base58btc encoded string\n */\n toString(): string\n\n /**\n * Returns a multihash, the digest of which is the protobuf-encoded public key\n * encoded as an identity hash\n */\n toMultihash(): MultihashDigest<0x0>\n\n /**\n * Returns a CID with the libp2p key code and the same multihash as\n * `toMultihash()`\n */\n toCID(): CID<Uint8Array, 0x72, 0x0, 1>\n\n /**\n * Returns true if the passed argument is equivalent to this PeerId\n */\n equals(other?: any): boolean\n}\n\nexport interface Secp256k1PeerId {\n readonly type: 'secp256k1'\n\n /**\n * This will always be defined as the public key is embedded in the multihash\n * of this PeerId\n */\n readonly publicKey: Secp256k1PublicKey\n\n /**\n * Returns the multihash from `toMultihash()` as a base58btc encoded string\n */\n toString(): string\n\n /**\n * Returns a multihash, the digest of which is the protobuf-encoded public key\n * encoded as an identity hash\n */\n toMultihash(): MultihashDigest<0x0>\n\n /**\n * Returns a CID with the libp2p key code and the same multihash as\n * `toMultihash()`\n */\n toCID(): CID<Uint8Array, 0x72, 0x0, 1>\n\n /**\n * Returns true if the passed argument is equivalent to this PeerId\n */\n equals(other?: any): boolean\n}\n\nexport interface URLPeerId {\n readonly type: 'url'\n\n /**\n * This will always be undefined as URL Peers do not have public keys\n */\n readonly publicKey: undefined\n\n /**\n * Returns CID from `toCID()` encoded as a base36 string\n */\n toString(): string\n\n /**\n * Returns a multihash, the digest of which is the URL encoded as an identity\n * hash\n */\n toMultihash(): MultihashDigest<0x0>\n\n /**\n * Returns a CID with the Transport IPFS Gateway HTTP code and the same\n * multihash as `toMultihash()`\n */\n toCID(): CID<Uint8Array, 0x0920, 0x0, 1>\n\n /**\n * Returns true if the passed argument is equivalent to this PeerId\n */\n equals(other?: any): boolean\n}\n\n/**\n * This is a union of all known PeerId types - use the `.type` field to\n * disambiguate them\n */\nexport type PeerId = RSAPeerId | Ed25519PeerId | Secp256k1PeerId | URLPeerId\n\n/**\n * All PeerId implementations must use this symbol as the name of a property\n * with a boolean `true` value\n */\nexport const peerIdSymbol = Symbol.for('@libp2p/peer-id')\n\n/**\n * Returns true if the passed argument is a PeerId implementation\n */\nexport function isPeerId (other?: any): other is PeerId {\n return Boolean(other?.[peerIdSymbol])\n}\n", "import type { RoutingOptions } from './index.js'\nimport type { PeerId } from './peer-id.js'\nimport type { PeerInfo } from './peer-info.js'\n\n/**\n * Any object that implements this Symbol as a property should return a\n * PeerRouting instance as the property value, similar to how `Symbol.Iterable`\n * can be used to return an `Iterable` from an `Iterator`.\n *\n * @example\n *\n * ```TypeScript\n * import { peerRouting, PeerRouting } from '@libp2p/peer-routing'\n *\n * class MyPeerRouter implements PeerRouting {\n * get [peerRouting] () {\n * return this\n * }\n *\n * // ...other methods\n * }\n * ```\n */\nexport const peerRoutingSymbol = Symbol.for('@libp2p/peer-routing')\n\n/**\n * Implementers of this interface can provide a PeerRouting implementation to\n * interested callers.\n */\nexport interface PeerRoutingProvider {\n [peerRoutingSymbol]: Partial<PeerRouting>\n}\n\nexport interface PeerRouting {\n /**\n * Searches the network for peer info corresponding to the passed peer id.\n *\n * @example\n *\n * ```TypeScript\n * // ...\n * const peer = await peerRouting.findPeer(peerId, options)\n * ```\n */\n findPeer(peerId: PeerId, options?: RoutingOptions): Promise<PeerInfo>\n\n /**\n * Search the network for peers that are closer to the passed key. Peer\n * info should be yielded in ever-increasing closeness to the key.\n *\n * @example\n *\n * ```TypeScript\n * // Iterate over the closest peers found for the given key\n * for await (const peer of peerRouting.getClosestPeers(key)) {\n * console.log(peer.id, peer.multiaddrs)\n * }\n * ```\n */\n getClosestPeers(key: Uint8Array, options?: RoutingOptions): AsyncIterable<PeerInfo>\n}\n", "import type { AbortOptions } from './index.ts'\nimport type { PublicKey } from './keys.js'\nimport type { PeerId } from './peer-id.js'\nimport type { PeerInfo } from './peer-info.js'\nimport type { Multiaddr } from '@multiformats/multiaddr'\n\n/**\n * When a peer that is tagged with this prefix disconnects, we will attempt to\n * redial it, up to a limit.\n *\n * To allow multiple components to add/remove their own keep-alive tags without\n * accidentally overwriting those of other components, attach a unique suffix to\n * the tag, e.g. `keep-alive-circuit-relay` or `keep-alive-kad-dht`, etc.\n */\nexport const KEEP_ALIVE = 'keep-alive'\n\n/**\n * A multiaddr with an optional flag that indicates if its trustworthy\n */\nexport interface Address {\n /**\n * Peer multiaddr\n */\n multiaddr: Multiaddr\n\n /**\n * Obtained from a signed peer record\n */\n isCertified: boolean\n}\n\n/**\n * Data stored in the peer store about peers\n */\nexport interface Peer {\n /**\n * Peer's peer-id instance\n */\n id: PeerId\n\n /**\n * Peer's addresses containing a list of multiaddrs and a isCertified field\n * indicating if the address was loaded from a signed peer record or not\n */\n addresses: Address[]\n\n /**\n * Peer's supported protocols\n */\n protocols: string[]\n\n /**\n * Peer's metadata map\n */\n metadata: Map<string, Uint8Array>\n\n /**\n * Tags a peer has\n */\n tags: Map<string, Tag>\n\n /**\n * The last peer record envelope received\n */\n peerRecordEnvelope?: Uint8Array\n}\n\n/**\n * Peer data used to update the peer store\n */\nexport interface PeerData {\n /**\n * Peer's addresses containing its multiaddrs and metadata - multiaddrs\n * passed here can be treated as certified if the `isCertifed` value is\n * set to true.\n *\n * If both addresses and multiaddrs are specified they will be merged\n * together with entries in addresses taking precedence.\n */\n addresses?: Address[]\n\n /**\n * Peer's multiaddrs - any multiaddrs passed here will be treated as\n * uncertified.\n *\n * If both addresses and multiaddrs are specified they will be merged\n * together with entries in addresses taking precedence.\n */\n multiaddrs?: Multiaddr[]\n\n /**\n * Peer's supported protocols\n */\n protocols?: string[]\n\n /**\n * Peer's metadata map. When merging pass undefined as values to remove metadata.\n */\n metadata?: Map<string, Uint8Array | undefined> | Record<string, Uint8Array | undefined>\n\n /**\n * Peer tags. When merging pass undefined as values to remove tags.\n */\n tags?: Map<string, TagOptions | undefined> | Record<string, TagOptions | undefined>\n\n /**\n * If this Peer has an RSA key, it's public key can be set with this property.\n *\n * The byte array should be the protobuf encoded form of the public key.\n */\n publicKey?: PublicKey\n\n /**\n * The last peer record envelope received\n */\n peerRecordEnvelope?: Uint8Array\n}\n\nexport interface TagOptions {\n /**\n * An optional tag value (1-100)\n */\n value?: number\n\n /**\n * An optional duration in ms after which the tag will expire\n */\n ttl?: number\n}\n\nexport interface Tag {\n /**\n * The tag value\n */\n value: number\n}\n\n/**\n * A predicate by which to filter lists of peers\n */\nexport interface PeerQueryFilter { (peer: Peer): boolean }\n\n/**\n * A predicate by which to sort lists of peers\n */\nexport interface PeerQueryOrder { (a: Peer, b: Peer): -1 | 0 | 1 }\n\n/**\n * A query for getting lists of peers\n */\nexport interface PeerQuery extends AbortOptions {\n filters?: PeerQueryFilter[]\n orders?: PeerQueryOrder[]\n limit?: number\n offset?: number\n}\n\nexport interface ConsumePeerRecordOptions extends AbortOptions {\n expectedPeer?: PeerId\n}\n\nexport interface PeerStore {\n /**\n * Loop over every peer - the looping is async because we read from a\n * datastore but the peer operation is sync, this is to prevent\n * long-lived peer operations causing deadlocks over the datastore\n * which can happen if they try to access the peer store during the\n * loop\n *\n * @example\n *\n * ```TypeScript\n * await peerStore.forEach(peer => {\n * // ...\n * })\n * ```\n */\n forEach(fn: (peer: Peer) => void, query?: PeerQuery): Promise<void>\n\n /**\n * Returns all peers in the peer store.\n *\n * @example\n *\n * ```TypeScript\n * for (const peer of await peerStore.all()) {\n * // ...\n * }\n * ```\n */\n all(query?: PeerQuery): Promise<Peer[]>\n\n /**\n * Delete all data stored for the passed peer\n *\n * @example\n *\n * ```TypeScript\n * await peerStore.addressBook.set(peerId, multiaddrs)\n * await peerStore.addressBook.get(peerId)\n * // multiaddrs[]\n *\n * await peerStore.delete(peerId)\n *\n * await peerStore.addressBook.get(peerId)\n * // []\n * ```\n */\n delete(peerId: PeerId, options?: AbortOptions): Promise<void>\n\n /**\n * Returns true if the passed PeerId is in the peer store\n *\n * @example\n *\n * ```TypeScript\n * await peerStore.has(peerId)\n * // false\n * await peerStore.addressBook.add(peerId, multiaddrs)\n * await peerStore.has(peerId)\n * // true\n * ```\n */\n has(peerId: PeerId, options?: AbortOptions): Promise<boolean>\n\n /**\n * Returns all data stored for the passed PeerId\n *\n * @example\n *\n * ```TypeScript\n * const peer = await peerStore.get(peerId)\n * // { .. }\n * ```\n */\n get(peerId: PeerId, options?: AbortOptions): Promise<Peer>\n\n /**\n * Returns a PeerInfo object for the passed peer id. This is similar to `get`\n * except the returned value contains fewer fields and is often used to\n * exchange peer information with other systems.\n *\n * The returned object can be passed to `JSON.stringify` without any\n * additional processing.\n *\n * @see https://docs.libp2p.io/concepts/fundamentals/peers/#peer-info\n *\n * @example\n *\n * ```TypeScript\n * const peerInfo = await peerStore.getInfo(peerId)\n *\n * console.info(JSON.stringify(peerInfo))\n * // {\n * // id: 'peerId'\n * // multiaddrs: [\n * // '...'\n * // ]\n * // }\n * ```\n */\n getInfo (peerId: PeerId, options?: AbortOptions): Promise<PeerInfo>\n\n /**\n * Adds a peer to the peer store, overwriting any existing data\n *\n * @example\n *\n * ```TypeScript\n * await peerStore.save(peerId, {\n * multiaddrs\n * })\n * ```\n */\n save(id: PeerId, data: PeerData, options?: AbortOptions): Promise<Peer>\n\n /**\n * Adds a peer to the peer store, overwriting only the passed fields\n *\n * @example\n *\n * ```TypeScript\n * await peerStore.patch(peerId, {\n * multiaddrs\n * })\n * ```\n */\n patch(id: PeerId, data: PeerData, options?: AbortOptions): Promise<Peer>\n\n /**\n * Adds a peer to the peer store, deeply merging any existing data.\n *\n * @example\n *\n * ```TypeScript\n * await peerStore.merge(peerId, {\n * multiaddrs\n * })\n * ```\n */\n merge(id: PeerId, data: PeerData, options?: AbortOptions): Promise<Peer>\n\n /**\n * Unmarshal and verify a signed peer record, extract the multiaddrs and\n * overwrite the stored addresses for the peer.\n *\n * Optionally pass an expected PeerId to verify that the peer record was\n * signed by that peer.\n *\n * @example\n *\n * ```TypeScript\n * await peerStore.consumePeerRecord(buf, expectedPeer)\n * ```\n */\n consumePeerRecord(buf: Uint8Array, options?: ConsumePeerRecordOptions): Promise<boolean>\n}\n", "/**\n * Implemented by components that have a life cycle\n */\nexport interface Startable {\n /**\n * If implemented, this method will be invoked before the start method.\n *\n * It should not assume any other components have been started.\n */\n beforeStart?(): void | Promise<void>\n\n /**\n * This method will be invoked to start the component.\n *\n * It should not assume that any other components have been started.\n */\n start(): void | Promise<void>\n\n /**\n * If implemented, this method will be invoked after the start method.\n *\n * All other components will have had their start method invoked before this method is called.\n */\n afterStart?(): void | Promise<void>\n\n /**\n * If implemented, this method will be invoked before the stop method.\n *\n * Any other components will still be running when this method is called.\n */\n beforeStop?(): void | Promise<void>\n\n /**\n * This method will be invoked to stop the component.\n *\n * It should not assume any other components are running when it is called.\n */\n stop(): void | Promise<void>\n\n /**\n * If implemented, this method will be invoked after the stop method.\n *\n * All other components will have had their stop method invoked before this method is called.\n */\n afterStop?(): void | Promise<void>\n}\n\n/**\n * Returns `true` if the object has type overlap with `Startable`\n */\nexport function isStartable (obj?: any): obj is Startable {\n return obj != null && typeof obj.start === 'function' && typeof obj.stop === 'function'\n}\n\n/**\n * A function that can be used to start and objects passed to it. This checks\n * that an object is startable before invoking its lifecycle methods so it is\n * safe to pass non-`Startable`s in.\n *\n * @example\n *\n * ```TypeScript\n * import { start } from '@libp2p/interface'\n * import type { Startable } from '@libp2p/interface'\n *\n * const startable: Startable = {\n * start: () => {},\n * stop: () => {}\n * }\n *\n * const notStartable = 5\n *\n * await start(\n * startable,\n * notStartable\n * )\n * ```\n */\nexport async function start (...objs: any[]): Promise<void> {\n const startables: Startable[] = []\n\n for (const obj of objs) {\n if (isStartable(obj)) {\n startables.push(obj)\n }\n }\n\n await Promise.all(\n startables.map(async s => {\n if (s.beforeStart != null) {\n await s.beforeStart()\n }\n })\n )\n\n await Promise.all(\n startables.map(async s => {\n await s.start()\n })\n )\n\n await Promise.all(\n startables.map(async s => {\n if (s.afterStart != null) {\n await s.afterStart()\n }\n })\n )\n}\n\n/**\n * A function that can be used to stop and objects passed to it. This checks\n * that an object is startable before invoking its lifecycle methods so it is\n * safe to pass non-`Startable`s in.\n *\n * @example\n *\n * ```TypeScript\n * import { stop } from '@libp2p/interface'\n * import type { Startable } from '@libp2p/interface'\n *\n * const startable: Startable = {\n * start: () => {},\n * stop: () => {}\n * }\n *\n * const notStartable = 5\n *\n * await stop(\n * startable,\n * notStartable\n * )\n * ```\n */\nexport async function stop (...objs: any[]): Promise<void> {\n const startables: Startable[] = []\n\n for (const obj of objs) {\n if (isStartable(obj)) {\n startables.push(obj)\n }\n }\n\n await Promise.all(\n startables.map(async s => {\n if (s.beforeStop != null) {\n await s.beforeStop()\n }\n })\n )\n\n await Promise.all(\n startables.map(async s => {\n await s.stop()\n })\n )\n\n await Promise.all(\n startables.map(async s => {\n if (s.afterStop != null) {\n await s.afterStop()\n }\n })\n )\n}\n", "import type { AbortOptions, ClearableSignal, ConnectionEncrypter, MultiaddrConnection, Connection, ConnectionLimits, StreamMuxerFactory, PeerId } from './index.js'\nimport type { Multiaddr } from '@multiformats/multiaddr'\nimport type { TypedEventTarget } from 'main-event'\nimport type { ProgressOptions, ProgressEvent } from 'progress-events'\n\nexport interface ListenerEvents {\n /**\n * This event signals to the transport manager that the listening addresses\n * have changed and may be emitted at any point and/or multiple times\n */\n listening: CustomEvent\n\n /**\n * Emitted if listening on an address failed\n */\n error: CustomEvent<Error>\n\n /**\n * Emitted when the listener has been shut down, has no open connections and\n * will no longer accept new connections\n */\n close: CustomEvent\n}\n\nexport interface Listener extends TypedEventTarget<ListenerEvents> {\n /**\n * Start a listener\n */\n listen(multiaddr: Multiaddr): Promise<void>\n\n /**\n * Get listen addresses\n */\n getAddrs(): Multiaddr[]\n\n /**\n * Close listener\n *\n * @returns {Promise<void>}\n */\n close(): Promise<void>\n\n /**\n * Allows transports to amend announce addresses - to add certificate hashes\n * or other metadata that cannot be known before runtime\n */\n updateAnnounceAddrs(addrs: Multiaddr[]): void\n}\n\nexport const transportSymbol = Symbol.for('@libp2p/transport')\n\n/**\n * A filter that acts on a list of multiaddrs\n */\nexport interface MultiaddrFilter {\n (multiaddrs: Multiaddr[]): Multiaddr[]\n}\n\nexport interface CreateListenerOptions {\n /**\n * The upgrader turns a MultiaddrConnection into a Connection and notifies\n * other libp2p components about a new incoming connection.\n */\n upgrader: Upgrader\n}\n\nexport interface DialTransportOptions<DialEvents extends ProgressEvent = ProgressEvent> extends Required<AbortOptions>, ProgressOptions<DialEvents> {\n /**\n * The upgrader turns a MultiaddrConnection into a Connection which should be\n * returned by the transport's dial method\n */\n upgrader: Upgrader\n}\n\n/**\n * A libp2p transport offers dial and listen methods to establish connections.\n */\nexport interface Transport<DialEvents extends ProgressEvent = ProgressEvent> {\n /**\n * Used to identify the transport\n */\n [Symbol.toStringTag]: string\n\n /**\n * Used by the isTransport function\n */\n [transportSymbol]: true\n\n /**\n * Dial a given multiaddr.\n */\n dial(ma: Multiaddr, options: DialTransportOptions<DialEvents>): Promise<Connection>\n\n /**\n * Create transport listeners.\n */\n createListener(options: CreateListenerOptions): Listener\n\n /**\n * Takes a list of `Multiaddr`s and returns only addresses that are valid for\n * the transport to listen on\n */\n listenFilter: MultiaddrFilter\n\n /**\n * Takes a list of `Multiaddr`s and returns only addresses that are valid for\n * the transport to dial\n */\n dialFilter: MultiaddrFilter\n}\n\n/**\n * Used to disambiguate transport implementations\n */\nexport function isTransport (other?: any): other is Transport {\n return other != null && Boolean(other[transportSymbol])\n}\n\n/**\n * Enum Transport Manager Fault Tolerance values\n */\nexport enum FaultTolerance {\n /**\n * should be used for failing in any listen circumstance\n */\n FATAL_ALL = 0,\n\n /**\n * should be used for not failing when not listening\n */\n NO_FATAL\n}\n\n/**\n * Options accepted by the upgrader during connection establishment\n */\nexport interface UpgraderOptions<ConnectionUpgradeEvents extends ProgressEvent = ProgressEvent> extends ProgressOptions<ConnectionUpgradeEvents>, Required<AbortOptions> {\n /**\n * If true no connection protection will be performed on the connection.\n */\n skipProtection?: boolean\n\n /**\n * By default a stream muxer protocol will be negotiated via multi-stream\n * select after an encryption protocol has been agreed on.\n *\n * If a transport provides it's own stream muxing facility pass a muxer\n * factory instance here to skip muxer negotiation.\n */\n muxerFactory?: StreamMuxerFactory\n\n /**\n * If the connection is to have limits applied to it, pass them here\n */\n limits?: ConnectionLimits\n\n /**\n * Multi-stream select is a initiator/responder protocol. By default a\n * connection returned from `upgrader.upgradeOutbound` will be the initiator\n * and one returned from `upgrader.upgradeInbound` will be the responder.\n *\n * Pass a value here to override the default.\n */\n initiator?: boolean\n}\n\n/**\n * Options accepted by the upgrader during connection establishment\n */\nexport interface UpgraderWithoutEncryptionOptions extends UpgraderOptions {\n /**\n * If true the invoking transport is expected to implement it's own encryption\n * and an encryption protocol will not attempted to be negotiated via\n * multi-stream select\n */\n skipEncryption: true\n\n /**\n * If `skipEncryption` is true, a remote PeerId must be supplied\n */\n remotePeer: PeerId\n}\n\nexport type InboundConnectionUpgradeEvents =\nProgressEvent<'upgrader:encrypt-inbound-connection'> |\nProgressEvent<'upgrader:multiplex-inbound-connection'>\n\nexport type OutboundConnectionUpgradeEvents =\nProgressEvent<'upgrader:encrypt-outbound-connection'> |\nProgressEvent<'upgrader:multiplex-outbound-connection'>\n\nexport interface Upgrader {\n /**\n * Upgrades an outbound connection created by the `dial` method of a transport\n */\n upgradeOutbound(maConn: MultiaddrConnection, opts: UpgraderOptions<OutboundConnectionUpgradeEvents>): Promise<Connection>\n upgradeOutbound(maConn: MultiaddrConnection, opts: UpgraderWithoutEncryptionOptions): Promise<Connection>\n\n /**\n * Upgrades an inbound connection received by a transport listener and\n * notifies other libp2p components about the new connection\n */\n upgradeInbound(maConn: MultiaddrConnection, opts: UpgraderOptions<InboundConnectionUpgradeEvents>): Promise<void>\n upgradeInbound(maConn: MultiaddrConnection, opts: UpgraderWithoutEncryptionOptions): Promise<void>\n\n /**\n * Used by transports that perform part of the upgrade process themselves and\n * do some async work. This allows configuring inbound upgrade timeouts from a\n * single location.\n *\n * Regular transports should just pass the signal from their shutdown\n * controller to `upgradeInbound`.\n */\n createInboundAbortSignal (signal: AbortSignal): ClearableSignal\n\n /**\n * Returns configured stream muxers\n */\n getStreamMuxers (): Map<string, StreamMuxerFactory>\n\n /**\n * Returns configured connection encrypters\n */\n getConnectionEncrypters (): Map<string, ConnectionEncrypter>\n}\n", "/**\n * Noop for browser compatibility\n */\nexport function setMaxListeners (): void {}\n", "/**\n * @packageDocumentation\n *\n * Adds types to the EventTarget class.\n *\n * Hopefully this won't be necessary\n * forever:\n *\n * - https://github.com/microsoft/TypeScript/issues/28357\n * - https://github.com/microsoft/TypeScript/issues/43477\n * - https://github.com/microsoft/TypeScript/issues/299\n * - https://www.npmjs.com/package/typed-events\n * - https://www.npmjs.com/package/typed-event-emitter\n * - https://www.npmjs.com/package/typed-event-target\n * - etc\n *\n * In addition to types, a `safeDispatchEvent` method is available which\n * prevents dispatching events that aren't in the event map, and a\n * `listenerCount` method which reports the number of listeners that are\n * currently registered for a given event.\n *\n * @example\n *\n * ```ts\n * import { TypedEventEmitter } from 'main-event'\n * import type { TypedEventTarget } from 'main-event'\n *\n * interface EventTypes {\n * 'test': CustomEvent<string>\n * }\n *\n * const target = new TypedEventEmitter<EventTypes>()\n *\n * // it's a regular EventTarget\n * console.info(target instanceof EventTarget) // true\n *\n * // register listeners normally\n * target.addEventListener('test', (evt) => {\n * // evt is CustomEvent<string>\n * })\n *\n * // @ts-expect-error 'derp' is not in the event map\n * target.addEventListener('derp', () => {})\n *\n * // use normal dispatchEvent method\n * target.dispatchEvent(new CustomEvent('test', {\n * detail: 'hello'\n * }))\n *\n * // use type safe dispatch method\n * target.safeDispatchEvent('test', {\n * detail: 'world'\n * })\n *\n * // report listener count\n * console.info(target.listenerCount('test')) // 0\n *\n * // event emitters can be used purely as interfaces too\n * function acceptTarget (target: TypedEventTarget<EventTypes>) {\n * // ...\n * }\n * ```\n */\n\nimport { setMaxListeners } from './events.js'\n\nexport interface EventCallback<EventType> { (evt: EventType): void }\nexport interface EventObject<EventType> { handleEvent: EventCallback<EventType> }\nexport type EventHandler<EventType> = EventCallback<EventType> | EventObject<EventType>\n\ninterface Listener {\n once: boolean\n callback: any\n}\n\n/**\n *\n */\nexport interface TypedEventTarget <EventMap extends Record<string, any>> extends EventTarget {\n addEventListener<K extends keyof EventMap>(type: K, listener: EventHandler<EventMap[K]> | null, options?: boolean | AddEventListenerOptions): void\n\n listenerCount (type: string): number\n\n removeEventListener<K extends keyof EventMap>(type: K, listener?: EventHandler<EventMap[K]> | null, options?: boolean | EventListenerOptions): void\n\n removeEventListener (type: string, listener?: EventHandler<Event>, options?: boolean | EventListenerOptions): void\n\n safeDispatchEvent<Detail>(type: keyof EventMap, detail?: CustomEventInit<Detail>): boolean\n}\n\n/**\n * An implementation of a typed event target\n */\nexport class TypedEventEmitter<EventMap extends Record<string, any>> extends EventTarget implements TypedEventTarget<EventMap> {\n readonly #listeners = new Map<any, Listener[]>()\n\n constructor () {\n super()\n\n // silence MaxListenersExceededWarning warning on Node.js, this is a red\n // herring almost all of the time\n setMaxListeners(Infinity, this)\n }\n\n listenerCount (type: string): number {\n const listeners = this.#listeners.get(type)\n\n if (listeners == null) {\n return 0\n }\n\n return listeners.length\n }\n\n addEventListener<K extends keyof EventMap>(type: K, listener: EventHandler<EventMap[K]> | null, options?: boolean | AddEventListenerOptions): void\n addEventListener (type: string, listener: EventHandler<Event>, options?: boolean | AddEventListenerOptions): void {\n super.addEventListener(type, listener, options)\n\n let list = this.#listeners.get(type)\n\n if (list == null) {\n list = []\n this.#listeners.set(type, list)\n }\n\n list.push({\n callback: listener,\n once: (options !== true && options !== false && options?.once) ?? false\n })\n }\n\n removeEventListener<K extends keyof EventMap>(type: K, listener?: EventHandler<EventMap[K]> | null, options?: boolean | EventListenerOptions): void\n removeEventListener (type: string, listener?: EventHandler<Event>, options?: boolean | EventListenerOptions): void {\n super.removeEventListener(type.toString(), listener ?? null, options)\n\n let list = this.#listeners.get(type)\n\n if (list == null) {\n return\n }\n\n list = list.filter(({ callback }) => callback !== listener)\n this.#listeners.set(type, list)\n }\n\n dispatchEvent (event: Event): boolean {\n const result = super.dispatchEvent(event)\n\n let list = this.#listeners.get(event.type)\n\n if (list == null) {\n return result\n }\n\n list = list.filter(({ once }) => !once)\n this.#listeners.set(event.type, list)\n\n return result\n }\n\n safeDispatchEvent<Detail>(type: keyof EventMap, detail: CustomEventInit<Detail> = {}): boolean {\n return this.dispatchEvent(new CustomEvent<Detail>(type as string, detail))\n }\n}\n\nexport { setMaxListeners }\n"],
|
|
4
|
+
"sourcesContent": ["/**\n * @packageDocumentation\n *\n * Exports a `Libp2p` type for modules to use as a type argument.\n *\n * @example\n *\n * ```typescript\n * import type { Libp2p } from '@libp2p/interface'\n *\n * function doSomethingWithLibp2p (node: Libp2p) {\n * // ...\n * }\n * ```\n */\n\nimport type { Connection, NewStreamOptions } from './connection.js'\nimport type { ContentRouting } from './content-routing.js'\nimport type { Ed25519PublicKey, PublicKey, RSAPublicKey, Secp256k1PublicKey } from './keys.js'\nimport type { Metrics } from './metrics.js'\nimport type { Ed25519PeerId, PeerId, RSAPeerId, Secp256k1PeerId, URLPeerId } from './peer-id.js'\nimport type { PeerInfo } from './peer-info.js'\nimport type { PeerRouting } from './peer-routing.js'\nimport type { Address, Peer, PeerStore } from './peer-store.js'\nimport type { Startable } from './startable.js'\nimport type { StreamHandler, StreamHandlerOptions, StreamMiddleware } from './stream-handler.js'\nimport type { Stream } from './stream.js'\nimport type { Topology } from './topology.js'\nimport type { Listener, OutboundConnectionUpgradeEvents } from './transport.js'\nimport type { DNS } from '@multiformats/dns'\nimport type { Multiaddr } from '@multiformats/multiaddr'\nimport type { TypedEventTarget } from 'main-event'\nimport type { ProgressOptions, ProgressEvent } from 'progress-events'\n\n/**\n * Used by the connection manager to sort addresses into order before dialling\n */\nexport interface AddressSorter {\n (a: Address, b: Address): -1 | 0 | 1\n}\n\n/**\n * Event detail emitted when peer data changes\n */\nexport interface PeerUpdate {\n peer: Peer\n previous?: Peer\n}\n\n/**\n * Peer data signed by the remote Peer's public key\n */\nexport interface SignedPeerRecord {\n addresses: Multiaddr[]\n seq: bigint\n}\n\n/**\n * A certificate that can be used to secure connections\n */\nexport interface TLSCertificate {\n /**\n * The private key that corresponds to the certificate in PEM format\n */\n key: string\n\n /**\n * The certificate chain in PEM format\n */\n cert: string\n}\n\n/**\n * Data returned from a successful identify response\n */\nexport interface IdentifyResult {\n /**\n * The remote Peer's PeerId\n */\n peerId: PeerId\n\n /**\n * The unsigned addresses they are listening on. Note - any multiaddrs present\n * in the signed peer record should be preferred to the value here.\n */\n listenAddrs: Multiaddr[]\n\n /**\n * The protocols the remote peer supports\n */\n protocols: string[]\n\n /**\n * The remote protocol version\n */\n protocolVersion?: string\n\n /**\n * The remote agent version\n */\n agentVersion?: string\n\n /**\n * The public key part of the remote PeerId - this is only useful for older\n * RSA-based PeerIds, the more modern Ed25519 and secp256k1 types have the\n * public key embedded in them\n */\n publicKey?: Uint8Array\n\n /**\n * If set this is the address that the remote peer saw the identify request\n * originate from\n */\n observedAddr?: Multiaddr\n\n /**\n * If sent by the remote peer this is the deserialized signed peer record\n */\n signedPeerRecord?: SignedPeerRecord\n\n /**\n * The connection that the identify protocol ran over\n */\n connection: Connection\n}\n\n/**\n * Logger component for libp2p\n */\nexport interface Logger {\n /**\n * Log a message\n */\n (formatter: any, ...args: any[]): void\n\n /**\n * Log an error message\n */\n error(formatter: any, ...args: any[]): void\n\n /**\n * Log a trace message\n */\n trace(formatter: any, ...args: any[]): void\n\n /**\n * `true` if this logger is enabled\n */\n enabled: boolean\n\n /**\n * Create a logger scoped below this one\n *\n * @example\n *\n * ```ts\n * import { defaultLogger } from '@libp2p/logger'\n *\n * const log = defaultLogger().forComponent('foo')\n *\n * log('hello')\n * // foo hello\n *\n * const subLog = log.newScope('bar')\n *\n * subLog('hello')\n * // foo:bar hello\n * ```\n */\n newScope(name: string): Logger\n}\n\n/**\n * Peer logger component for libp2p. This can be used to create loggers that are\n * scoped to individual system components or services.\n *\n * To see logs, run your app with `DEBUG` set as an env var or for browsers, in\n * `localStorage`:\n *\n * ```console\n * $ DEBUG=libp2p* node index.js\n * libp2p:my-service hello +0ms\n * ```\n */\nexport interface ComponentLogger {\n /**\n * Returns a logger for the specified component.\n *\n * @example\n *\n * ```TypeScript\n * import { ComponentLogger, Logger } from '@libp2p/interface'\n *\n * interface MyServiceComponents {\n * logger: ComponentLogger\n * }\n *\n * class MyService {\n * private readonly log: Logger\n *\n * constructor (components) {\n * this.log = components.logger.forComponent('libp2p:my-service')\n *\n * this.log('hello')\n * // logs:\n * // libp2p:my-service hello +0ms\n * }\n * }\n * ```\n */\n forComponent(name: string): Logger\n}\n\nexport interface MultiaddrResolveOptions extends AbortOptions, LoggerOptions {\n /**\n * An optional DNS resolver\n */\n dns?: DNS\n}\n\n/**\n * `MultiaddrResolver`s perform resolution of multiaddr components that require\n * translation by external systems (for example DNSADDR to TXT records).\n */\nexport interface MultiaddrResolver {\n /**\n * Returns true if this resolver can resolve components of this multiaddr\n */\n canResolve (address: Multiaddr): boolean\n\n /**\n * Returns one or more multiaddrs with components resolved to other values\n */\n resolve (address: Multiaddr, options: MultiaddrResolveOptions): Promise<Multiaddr[]>\n}\n\n/**\n * Once you have a libp2p instance, you can listen to several events it emits,\n * so that you can be notified of relevant network events.\n *\n * Event names are `noun:verb` so the first part is the name of the object\n * being acted on and the second is the action.\n */\nexport interface Libp2pEvents<T extends ServiceMap = ServiceMap> {\n /**\n * This event is dispatched when a new network peer is discovered.\n *\n * @example\n *\n * ```TypeScript\n * libp2p.addEventListener('peer:discovery', (event) => {\n * const peerInfo = event.detail\n * // ...\n * })\n * ```\n */\n 'peer:discovery': CustomEvent<PeerInfo>\n\n /**\n * This event will be triggered any time a new peer connects.\n *\n * @example\n *\n * ```TypeScript\n * libp2p.addEventListener('peer:connect', (event) => {\n * const peerId = event.detail\n * // ...\n * })\n * ```\n */\n 'peer:connect': CustomEvent<PeerId>\n\n /**\n * This event will be triggered any time we are disconnected from another\n * peer, regardless of the circumstances of that disconnection. If we happen\n * to have multiple connections to a peer, this event will **only** be\n * triggered when the last connection is closed.\n *\n * @example\n *\n * ```TypeScript\n * libp2p.addEventListener('peer:disconnect', (event) => {\n * const peerId = event.detail\n * // ...\n * })\n * ```\n */\n 'peer:disconnect': CustomEvent<PeerId>\n\n /**\n * When a peer tagged with `keep-alive` disconnects, we will make multiple\n * attempts to reconnect to it with a backoff factor (see the connection\n * manager settings for details). If these all fail, the `keep-alive` tag will\n * be removed and this event will be emitted.\n *\n * @example\n *\n * ```TypeScript\n * libp2p.addEventListener('peer:reconnect-failure', (event) => {\n * const peerId = event.detail\n * // ...\n * })\n * ```\n */\n 'peer:reconnect-failure': CustomEvent<PeerId>\n\n /**\n * This event is dispatched after a remote peer has successfully responded to\n * the identify protocol. Note that for this to be emitted, both peers must\n * have an identify service configured.\n *\n * @example\n *\n * ```TypeScript\n * libp2p.addEventListener('peer:identify', (event) => {\n * const identifyResult = event.detail\n * // ...\n * })\n * ```\n */\n 'peer:identify': CustomEvent<IdentifyResult>\n\n /**\n * This event is dispatched when the peer store data for a peer has been\n * updated - e.g. their multiaddrs, protocols etc have changed.\n *\n * If they were previously known to this node, the old peer data will be\n * set in the `previous` field.\n *\n * This may be in response to the identify protocol running, a manual\n * update or some other event.\n */\n 'peer:update': CustomEvent<PeerUpdate>\n\n /**\n * This event is dispatched when the current node's peer record changes -\n * for example a transport started listening on a new address or a new\n * protocol handler was registered.\n *\n * @example\n *\n * ```TypeScript\n * libp2p.addEventListener('self:peer:update', (event) => {\n * const { peer } = event.detail\n * // ...\n * })\n * ```\n */\n 'self:peer:update': CustomEvent<PeerUpdate>\n\n /**\n * This event is dispatched when a transport begins listening on a new address\n */\n 'transport:listening': CustomEvent<Listener>\n\n /**\n * This event is dispatched when a transport stops listening on an address\n */\n 'transport:close': CustomEvent<Listener>\n\n /**\n * This event is dispatched when the connection manager has more than the\n * configured allowable max connections and has closed some connections to\n * bring the node back under the limit.\n */\n 'connection:prune': CustomEvent<Connection[]>\n\n /**\n * This event notifies listeners when new incoming or outgoing connections\n * are opened.\n */\n 'connection:open': CustomEvent<Connection>\n\n /**\n * This event notifies listeners when incoming or outgoing connections are\n * closed.\n */\n 'connection:close': CustomEvent<Connection>\n\n /**\n * This event notifies listeners that a TLS certificate is available for use\n */\n 'certificate:provision': CustomEvent<TLSCertificate>\n\n /**\n * This event notifies listeners that a new TLS certificate is available for\n * use. Any previous certificate may no longer be valid.\n */\n 'certificate:renew': CustomEvent<TLSCertificate>\n\n /**\n * This event notifies listeners that the node has started\n *\n * ```TypeScript\n * libp2p.addEventListener('start', (event) => {\n * console.info(libp2p.isStarted()) // true\n * })\n * ```\n */\n start: CustomEvent<Libp2p<T>>\n\n /**\n * This event notifies listeners that the node has stopped\n *\n * ```TypeScript\n * libp2p.addEventListener('stop', (event) => {\n * console.info(libp2p.isStarted()) // false\n * })\n * ```\n */\n stop: CustomEvent<Libp2p<T>>\n}\n\n/**\n * A map of user defined services available on the libp2p node via the\n * `services` key\n *\n * @example\n *\n * ```TypeScript\n * const node = await createLibp2p({\n * // ...other options\n * services: {\n * myService: myService({\n * // ...service options\n * })\n * }\n * })\n *\n * // invoke methods on the service\n * node.services.myService.anOperation()\n * ```\n */\nexport type ServiceMap = Record<string, unknown>\n\nexport type PendingDialStatus = 'queued' | 'active' | 'error' | 'success'\n\n/**\n * An item in the dial queue\n */\nexport interface PendingDial {\n /**\n * A unique identifier for this dial\n */\n id: string\n\n /**\n * The current status of the dial\n */\n status: PendingDialStatus\n\n /**\n * If known, this is the peer id that libp2p expects to be dialling\n */\n peerId?: PeerId\n\n /**\n * The list of multiaddrs that will be dialled. The returned connection will\n * use the first address that succeeds, all other dials part of this pending\n * dial will be cancelled.\n */\n multiaddrs: Multiaddr[]\n}\n\nexport type Libp2pStatus = 'starting' | 'started' | 'stopping' | 'stopped'\n\nexport interface IsDialableOptions extends AbortOptions {\n /**\n * If the dial attempt would open a protocol, and the multiaddr being dialed\n * is a circuit relay address, passing true here would cause the test to fail\n * because that protocol would not be allowed to run over a data/time limited\n * connection.\n */\n runOnLimitedConnection?: boolean\n}\n\nexport type TransportManagerDialProgressEvents =\n ProgressEvent<'transport-manager:selected-transport', string>\n\nexport type OpenConnectionProgressEvents =\n TransportManagerDialProgressEvents |\n ProgressEvent<'dial-queue:already-connected'> |\n ProgressEvent<'dial-queue:already-in-dial-queue'> |\n ProgressEvent<'dial-queue:add-to-dial-queue'> |\n ProgressEvent<'dial-queue:start-dial'> |\n ProgressEvent<'dial-queue:calculated-addresses', Address[]> |\n OutboundConnectionUpgradeEvents\n\nexport interface DialOptions extends AbortOptions, ProgressOptions {\n /**\n * If true, open a new connection to the remote even if one already exists\n */\n force?: boolean\n}\n\nexport interface DialProtocolOptions extends NewStreamOptions {\n\n}\n\n/**\n * Libp2p nodes implement this interface.\n */\nexport interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, TypedEventTarget<Libp2pEvents<T>> {\n /**\n * The PeerId is a unique identifier for a node on the network.\n *\n * It is the hash of an RSA public key or, for Ed25519 or secp256k1 keys,\n * the key itself.\n *\n * @example\n *\n * ```TypeScript\n * console.info(libp2p.peerId)\n * // PeerId(12D3Foo...)\n * ````\n */\n peerId: PeerId\n\n /**\n * The peer store holds information we know about other peers on the network.\n * - multiaddrs, supported protocols, etc.\n *\n * @example\n *\n * ```TypeScript\n * const peer = await libp2p.peerStore.get(peerId)\n * console.info(peer)\n * // { id: PeerId(12D3Foo...), addresses: [] ... }\n * ```\n */\n peerStore: PeerStore\n\n /**\n * The peer routing subsystem allows the user to find peers on the network\n * or to find peers close to binary keys.\n *\n * @example\n *\n * ```TypeScript\n * const peerInfo = await libp2p.peerRouting.findPeer(peerId)\n * console.info(peerInfo)\n * // { id: PeerId(12D3Foo...), multiaddrs: [] ... }\n * ```\n *\n * @example\n *\n * ```TypeScript\n * for await (const peerInfo of libp2p.peerRouting.getClosestPeers(key)) {\n * console.info(peerInfo)\n * // { id: PeerId(12D3Foo...), multiaddrs: [] ... }\n * }\n * ```\n */\n peerRouting: PeerRouting\n\n /**\n * The content routing subsystem allows the user to find providers for content,\n * let the network know they are providers for content, and get/put values to\n * the DHT.\n *\n * @example\n *\n * ```TypeScript\n * for await (const peerInfo of libp2p.contentRouting.findProviders(cid)) {\n * console.info(peerInfo)\n * // { id: PeerId(12D3Foo...), multiaddrs: [] ... }\n * }\n * ```\n */\n contentRouting: ContentRouting\n\n /**\n * The metrics subsystem allows recording values to assess the health/performance\n * of the running node.\n *\n * @example\n *\n * ```TypeScript\n * const metric = libp2p.metrics.registerMetric({\n * 'my-metric'\n * })\n *\n * // later\n * metric.update(5)\n * ```\n */\n metrics?: Metrics\n\n /**\n * The logger used by this libp2p node\n */\n logger: ComponentLogger\n\n /**\n * The current status of the libp2p node\n */\n status: Libp2pStatus\n\n /**\n * Get a deduplicated list of peer advertising multiaddrs by concatenating\n * the listen addresses used by transports with any configured\n * announce addresses as well as observed addresses reported by peers.\n *\n * If Announce addrs are specified, configured listen addresses will be\n * ignored though observed addresses will still be included.\n *\n * @example\n *\n * ```TypeScript\n * const listenMa = libp2p.getMultiaddrs()\n * // [ <Multiaddr 047f00000106f9ba - /ip4/127.0.0.1/tcp/63930> ]\n * ```\n */\n getMultiaddrs(): Multiaddr[]\n\n /**\n * Returns a list of supported protocols\n *\n * @example\n *\n * ```TypeScript\n * const protocols = libp2p.getProtocols()\n * // [ '/ipfs/ping/1.0.0', '/ipfs/id/1.0.0' ]\n * ```\n */\n getProtocols(): string[]\n\n /**\n * Return a list of all connections this node has open, optionally filtering\n * by a PeerId\n *\n * @example\n *\n * ```TypeScript\n * for (const connection of libp2p.getConnections()) {\n * console.log(peerId, connection.remoteAddr.toString())\n * // Logs the PeerId string and the observed remote multiaddr of each Connection\n * }\n * ```\n */\n getConnections(peerId?: PeerId): Connection[]\n\n /**\n * Return the list of dials currently in progress or queued to start\n *\n * @example\n *\n * ```TypeScript\n * for (const pendingDial of libp2p.getDialQueue()) {\n * console.log(pendingDial)\n * }\n * ```\n */\n getDialQueue(): PendingDial[]\n\n /**\n * Return a list of all peers we currently have a connection open to\n */\n getPeers(): PeerId[]\n\n /**\n * Dials to the provided peer. If successful, the known metadata of the\n * peer will be added to the nodes `peerStore`.\n *\n * If a PeerId is passed as the first argument, the peer will need to have known multiaddrs for it in the PeerStore.\n *\n * @example\n *\n * ```TypeScript\n * const conn = await libp2p.dial(remotePeerId)\n *\n * // create a new stream within the connection\n * const stream = await conn.newStream(['/echo/1.1.0', '/echo/1.0.0'])\n *\n * // protocol negotiated: 'echo/1.0.0' means that the other party only supports the older version\n *\n * // ...\n * await conn.close()\n * ```\n */\n dial(peer: PeerId | Multiaddr | Multiaddr[], options?: DialOptions): Promise<Connection>\n\n /**\n * Dials to the provided peer and tries to handshake with the given protocols in order.\n * If successful, the known metadata of the peer will be added to the nodes `peerStore`,\n * and the `MuxedStream` will be returned together with the successful negotiated protocol.\n *\n * @example\n *\n * ```TypeScript\n * import { pipe } from 'it-pipe'\n *\n * const { stream, protocol } = await libp2p.dialProtocol(remotePeerId, protocols)\n *\n * // Use this new stream like any other duplex stream\n * pipe([1, 2, 3], stream, consume)\n * ```\n */\n dialProtocol(peer: PeerId | Multiaddr | Multiaddr[], protocols: string | string[], options?: DialProtocolOptions): Promise<Stream>\n\n /**\n * Attempts to gracefully close an open connection to the given peer. If the\n * connection is not closed in the grace period, it will be forcefully closed.\n *\n * An AbortSignal can optionally be passed to control when the connection is\n * forcefully closed.\n *\n * @example\n *\n * ```TypeScript\n * await libp2p.hangUp(remotePeerId)\n * ```\n */\n hangUp(peer: PeerId | Multiaddr, options?: AbortOptions): Promise<void>\n\n /**\n * Sets up [multistream-select routing](https://github.com/multiformats/multistream-select) of protocols to their application handlers. Whenever a stream is opened on one of the provided protocols, the handler will be called. `handle` must be called in order to register a handler and support for a given protocol. This also informs other peers of the protocols you support.\n *\n * `libp2p.handle(protocols, handler, options)`\n *\n * In the event of a new handler for the same protocol being added and error\n * will be thrown. Pass `force: true` to override this.\n *\n * @example\n *\n * ```TypeScript\n * const handler = ({ connection, stream, protocol }) => {\n * // use stream or connection according to the needs\n * }\n *\n * libp2p.handle('/echo/1.0.0', handler, {\n * maxInboundStreams: 5,\n * maxOutboundStreams: 5\n * })\n * ```\n */\n handle(protocol: string | string[], handler: StreamHandler, options?: StreamHandlerOptions): Promise<void>\n\n /**\n * Removes the handler for each protocol. The protocol\n * will no longer be supported on streams.\n *\n * @example\n *\n * ```TypeScript\n * libp2p.unhandle(['/echo/1.0.0'])\n * ```\n */\n unhandle(protocols: string[] | string, options?: AbortOptions): Promise<void>\n\n /**\n * Register a topology to be informed when peers are encountered that\n * support the specified protocol\n *\n * @example\n *\n * ```TypeScript\n * const id = await libp2p.register('/echo/1.0.0', {\n * onConnect: (peer, connection) => {\n * // handle connect\n * },\n * onDisconnect: (peer, connection) => {\n * // handle disconnect\n * }\n * })\n * ```\n */\n register(protocol: string, topology: Topology, options?: AbortOptions): Promise<string>\n\n /**\n * Unregister topology to no longer be informed when peers connect or\n * disconnect.\n *\n * @example\n *\n * ```TypeScript\n * const id = await libp2p.register(...)\n *\n * libp2p.unregister(id)\n * ```\n */\n unregister(id: string): void\n\n /**\n * Registers one or more middleware implementations that will be invoked for\n * incoming and outgoing protocol streams that match the passed protocol.\n *\n * @example\n *\n * ```TypeScript\n * libp2p.use('/my/protocol/1.0.0', (stream, connection, next) => {\n * // do something with stream and/or connection\n * next(stream, connection)\n * })\n * ```\n */\n use (protocol: string, middleware: StreamMiddleware | StreamMiddleware[]): void\n\n /**\n * Deregisters all middleware for the passed protocol.\n *\n * @example\n *\n * ```TypeScript\n * libp2p.unuse('/my/protocol/1.0.0')\n * // any previously registered middleware will no longer be invoked\n * ```\n */\n unuse (protocol: string): void\n\n /**\n * Returns the public key for the passed PeerId. If the PeerId is of the 'RSA'\n * type this may mean searching the routing if the peer's key is not present\n * in the peer store.\n */\n getPublicKey(peer: Ed25519PeerId, options?: AbortOptions): Promise<Ed25519PublicKey>\n getPublicKey(peer: Secp256k1PeerId, options?: AbortOptions): Promise<Secp256k1PublicKey>\n getPublicKey(peer: RSAPeerId, options?: AbortOptions): Promise<RSAPublicKey>\n getPublicKey(peer: URLPeerId, options?: AbortOptions): Promise<never>\n getPublicKey(peer: PeerId, options?: AbortOptions): Promise<PublicKey>\n\n /**\n * Given the current node configuration, returns a promise of `true` or\n * `false` if the node would attempt to dial the passed multiaddr.\n *\n * This means a relevant transport is configured, and the connection gater\n * would not block the dial attempt.\n *\n * This may involve resolving DNS addresses so you should pass an AbortSignal.\n */\n isDialable(multiaddr: Multiaddr | Multiaddr[], options?: IsDialableOptions): Promise<boolean>\n\n /**\n * A set of user defined services\n */\n services: T\n}\n\n/**\n * Metadata about the current node\n */\nexport interface NodeInfo {\n /**\n * The implementation name\n */\n name: string\n\n /**\n * The implementation version\n */\n version: string\n\n /**\n * A string that contains information about the implementation and runtime\n */\n userAgent: string\n}\n\n/**\n * An object that contains an AbortSignal as\n * the optional `signal` property.\n *\n * @example\n *\n * ```TypeScript\n * const controller = new AbortController()\n *\n * aLongRunningOperation({\n * signal: controller.signal\n * })\n *\n * // later\n *\n * controller.abort()\n */\nexport interface AbortOptions {\n signal?: AbortSignal\n}\n\n/**\n * An object that contains a Logger as the `log` property.\n */\nexport interface LoggerOptions {\n log: Logger\n}\n\n/**\n * An object that includes a trace object that is passed onwards.\n *\n * This is used by metrics method tracing to link function calls together.\n */\nexport interface TraceOptions {\n trace?: any\n}\n\n/**\n * A signal that needs to be cleared when no longer in use\n */\nexport interface ClearableSignal extends AbortSignal {\n clear(): void\n}\n\n/**\n * When a routing operation involves reading values, these options allow\n * controlling where the values are read from. By default libp2p will check\n * local caches but may not use the network if a valid local value is found,\n * these options allow tuning that behavior.\n */\nexport interface RoutingOptions extends AbortOptions, ProgressOptions, TraceOptions {\n /**\n * Pass `false` to not use the network\n *\n * @default true\n */\n useNetwork?: boolean\n\n /**\n * Pass `false` to not use cached values\n *\n * @default true\n */\n useCache?: boolean\n}\n\n/**\n * This symbol is used by libp2p services to define the capabilities they can\n * provide to other libp2p services.\n *\n * The service should define a property with this symbol as the key and the\n * value should be a string array of provided capabilities.\n */\nexport const serviceCapabilities = Symbol.for('@libp2p/service-capabilities')\n\n/**\n * This symbol is used by libp2p services to define the capabilities they\n * require from other libp2p services.\n *\n * The service should define a property with this symbol as the key and the\n * value should be a string array of required capabilities.\n */\nexport const serviceDependencies = Symbol.for('@libp2p/service-dependencies')\n\nexport * from './connection.js'\nexport * from './connection-encrypter.js'\nexport * from './connection-gater.js'\nexport * from './connection-protector.js'\nexport * from './content-routing.js'\nexport * from './errors.js'\nexport * from './events.js'\nexport * from './keys.js'\nexport * from './message-stream.js'\nexport * from './metrics.js'\nexport * from './multiaddr-connection.js'\nexport * from './peer-discovery.js'\nexport * from './peer-id.js'\nexport * from './peer-info.js'\nexport * from './peer-routing.js'\nexport * from './peer-store.js'\nexport * from './record.js'\nexport * from './startable.js'\nexport * from './stream-handler.js'\nexport * from './stream-muxer.js'\nexport * from './stream.js'\nexport * from './topology.js'\nexport * from './transport.js'\n\nexport * from 'main-event'\n", "import type { AbortOptions, Logger, TypedEventTarget, Stream, MessageStreamEvents, PeerId, MultiaddrConnectionTimeline, MessageStreamStatus, MessageStreamDirection } from './index.js'\nimport type { Multiaddr } from '@multiformats/multiaddr'\n\nexport type ConnectionStatus = MessageStreamStatus\n\n/**\n * Connection limits are present on connections that are only allowed to\n * transfer a certain amount of bytes or be open for a certain number\n * of seconds.\n *\n * These limits are applied by Circuit Relay v2 servers, for example and\n * the connection will normally be closed abruptly if the limits are\n * exceeded.\n */\nexport interface ConnectionLimits {\n /**\n * If present this is the number of bytes remaining that may be\n * transferred over this connection\n */\n bytes?: bigint\n\n /**\n * If present this is the number of seconds that this connection will\n * remain open for\n */\n seconds?: number\n}\n\nexport interface NewStreamOptions extends AbortOptions {\n /**\n * If specified, and no handler has been registered with the registrar for the\n * successfully negotiated protocol, use this as the max outbound stream limit\n * for the protocol\n */\n maxOutboundStreams?: number\n\n /**\n * Opt-in to running over a limited connection - one that has restrictions\n * on the amount of data that may be transferred or how long it may be open\n * for.\n *\n * These limits are typically enforced by a relay server, if the protocol will\n * be transferring a lot of data or the stream will be open for a long time\n * consider upgrading to a direct connection before opening the stream.\n *\n * @default false\n */\n runOnLimitedConnection?: boolean\n\n /**\n * By default when negotiating a protocol the dialer writes then protocol name\n * then reads the response.\n *\n * When a only a single protocol is being negotiated on an outbound stream,\n * and the stream is written to before being read from, we can optimistically\n * write the protocol name and the first chunk of data together in the first\n * message.\n *\n * Reading and handling the protocol response is done asynchronously, which\n * means we can skip a round trip on writing to newly opened streams which\n * significantly reduces the time-to-first-byte on a stream.\n *\n * The side-effect of this is that the underlying stream won't negotiate the\n * protocol until either data is written to or read from the stream so it will\n * not be opened on the remote until this is done.\n *\n * Pass `false` here to optimistically write the protocol name and first chunk\n * of data in the first message.\n *\n * If multiple protocols are being negotiated, negotiation is always completed\n * in full before the stream is returned so this option has no effect.\n *\n * @default true\n */\n negotiateFully?: boolean\n}\n\n/**\n * A Connection is a high-level representation of a connection\n * to a remote peer that may have been secured by encryption and\n * multiplexed, depending on the configuration of the nodes\n * between which the connection is made.\n */\nexport interface Connection extends TypedEventTarget<Omit<MessageStreamEvents, 'drain' | 'message'>> {\n /**\n * The unique identifier for this connection\n */\n id: string\n\n /**\n * The address of the remote end of the connection\n */\n remoteAddr: Multiaddr\n\n /**\n * The id of the peer at the remote end of the connection\n */\n remotePeer: PeerId\n\n /**\n * A list of open streams on this connection\n */\n streams: Stream[]\n\n /**\n * Outbound connections are opened by the local node, inbound streams are opened by the remote\n */\n direction: MessageStreamDirection\n\n /**\n * When stream life cycle events occurred\n */\n timeline: MultiaddrConnectionTimeline\n\n /**\n * The multiplexer negotiated for this connection\n */\n multiplexer?: string\n\n /**\n * The encryption protocol negotiated for this connection\n */\n encryption?: string\n\n /**\n * The current status of the connection\n */\n status: ConnectionStatus\n\n /**\n * Whether this connection is direct or, for example, is via a relay\n */\n direct: boolean\n\n /**\n * If present, this connection has limits applied to it, perhaps by an\n * intermediate relay. Once the limits have been reached the connection will\n * be closed by the relay.\n */\n limits?: ConnectionLimits\n\n /**\n * The time in milliseconds it takes to make a round trip to the remote peer.\n *\n * This is updated periodically by the connection monitor.\n */\n rtt?: number\n\n /**\n * The connection logger, used to log connection-specific information\n */\n log: Logger\n\n /**\n * Create a new stream on this connection and negotiate one of the passed protocols\n */\n newStream(protocols: string | string[], options?: NewStreamOptions): Promise<Stream>\n\n /**\n * Gracefully close the connection. The returned promise will resolve when all\n * queued data has been written to the underlying transport. Any unread data\n * will still be emitted as a 'message' event.\n */\n close(options?: AbortOptions): Promise<void>\n\n /**\n * Immediately close the connection. Any data queued to be sent or read will\n * be discarded.\n */\n abort(err: Error): void\n}\n\nexport const connectionSymbol = Symbol.for('@libp2p/connection')\n\nexport function isConnection (other: any): other is Connection {\n return other != null && Boolean(other[connectionSymbol])\n}\n", "import type { RoutingOptions } from './index.js'\nimport type { PeerInfo } from './peer-info.js'\nimport type { CID } from 'multiformats/cid'\n\nexport interface Provider extends PeerInfo {\n /**\n * Which routing subsystem found the provider\n */\n routing: string\n}\n\n/**\n * Any object that implements this Symbol as a property should return a\n * Partial<ContentRouting> instance as the property value, similar to how\n * `Symbol.Iterable` can be used to return an `Iterable` from an `Iterator`.\n *\n * @example\n *\n * ```TypeScript\n * import { contentRoutingSymbol, ContentRouting } from '@libp2p/content-routing'\n *\n * class MyContentRouter implements ContentRouting {\n * get [contentRoutingSymbol] () {\n * return this\n * }\n *\n * // ...other methods\n * }\n * ```\n */\nexport const contentRoutingSymbol = Symbol.for('@libp2p/content-routing')\n\n/**\n * Implementers of this interface can provide a ContentRouting implementation to\n * interested callers.\n */\nexport interface ContentRoutingProvider {\n [contentRoutingSymbol]: Partial<ContentRouting>\n}\n\nexport interface ContentRouting {\n /**\n * The implementation of this method should ensure that network peers know the\n * caller can provide content that corresponds to the passed CID.\n *\n * @example\n *\n * ```TypeScript\n * // ...\n * await contentRouting.provide(cid)\n * ```\n */\n provide(cid: CID, options?: RoutingOptions): Promise<void>\n\n /**\n * If network peers need to be periodically reminded that the caller can\n * provide content corresponding to the passed CID, call this function to no\n * longer remind them.\n */\n cancelReprovide (key: CID, options?: RoutingOptions): Promise<void>\n\n /**\n * Find the providers of the passed CID.\n *\n * @example\n *\n * ```TypeScript\n * // Iterate over the providers found for the given cid\n * for await (const provider of contentRouting.findProviders(cid)) {\n * console.log(provider.id, provider.multiaddrs)\n * }\n * ```\n */\n findProviders(cid: CID, options?: RoutingOptions): AsyncIterable<Provider>\n\n /**\n * Puts a value corresponding to the passed key in a way that can later be\n * retrieved by another network peer using the get method.\n *\n * @example\n *\n * ```TypeScript\n * // ...\n * const key = '/key'\n * const value = uint8ArrayFromString('oh hello there')\n *\n * await contentRouting.put(key, value)\n * ```\n */\n put(key: Uint8Array, value: Uint8Array, options?: RoutingOptions): Promise<void>\n\n /**\n * Retrieves a value from the network corresponding to the passed key.\n *\n * @example\n *\n * ```TypeScript\n * // ...\n *\n * const key = '/key'\n * const value = await contentRouting.get(key)\n * ```\n */\n get(key: Uint8Array, options?: RoutingOptions): Promise<Uint8Array>\n}\n", "/**\n * When this error is thrown it means an operation was aborted,\n * usually in response to the `abort` event being emitted by an\n * AbortSignal.\n */\nexport class AbortError extends Error {\n static name = 'AbortError'\n\n constructor (message: string = 'The operation was aborted') {\n super(message)\n this.name = 'AbortError'\n }\n}\n\n/**\n * Thrown when a remote Peer ID does not match the expected one\n */\nexport class UnexpectedPeerError extends Error {\n static name = 'UnexpectedPeerError'\n\n constructor (message = 'Unexpected Peer') {\n super(message)\n this.name = 'UnexpectedPeerError'\n }\n}\n\n/**\n * Thrown when a crypto exchange fails\n */\nexport class InvalidCryptoExchangeError extends Error {\n static name = 'InvalidCryptoExchangeError'\n\n constructor (message = 'Invalid crypto exchange') {\n super(message)\n this.name = 'InvalidCryptoExchangeError'\n }\n}\n\n/**\n * Thrown when invalid parameters are passed to a function or method call\n */\nexport class InvalidParametersError extends Error {\n static name = 'InvalidParametersError'\n\n constructor (message = 'Invalid parameters') {\n super(message)\n this.name = 'InvalidParametersError'\n }\n}\n\n/**\n * Thrown when a public key is invalid\n */\nexport class InvalidPublicKeyError extends Error {\n static name = 'InvalidPublicKeyError'\n\n constructor (message = 'Invalid public key') {\n super(message)\n this.name = 'InvalidPublicKeyError'\n }\n}\n\n/**\n * Thrown when a private key is invalid\n */\nexport class InvalidPrivateKeyError extends Error {\n static name = 'InvalidPrivateKeyError'\n\n constructor (message = 'Invalid private key') {\n super(message)\n this.name = 'InvalidPrivateKeyError'\n }\n}\n\n/**\n * Thrown when a operation is unsupported\n */\nexport class UnsupportedOperationError extends Error {\n static name = 'UnsupportedOperationError'\n\n constructor (message = 'Unsupported operation') {\n super(message)\n this.name = 'UnsupportedOperationError'\n }\n}\n\n/**\n * Thrown when a connection is closing\n */\nexport class ConnectionClosingError extends Error {\n static name = 'ConnectionClosingError'\n\n constructor (message = 'The connection is closing') {\n super(message)\n this.name = 'ConnectionClosingError'\n }\n}\n\n/**\n * Thrown when a connection is closed\n */\nexport class ConnectionClosedError extends Error {\n static name = 'ConnectionClosedError'\n\n constructor (message = 'The connection is closed') {\n super(message)\n this.name = 'ConnectionClosedError'\n }\n}\n\n/**\n * Thrown when a connection fails\n */\nexport class ConnectionFailedError extends Error {\n static name = 'ConnectionFailedError'\n\n constructor (message = 'Connection failed') {\n super(message)\n this.name = 'ConnectionFailedError'\n }\n}\n\n/**\n * Thrown when the muxer is closed and an attempt to open a stream occurs\n */\nexport class MuxerClosedError extends Error {\n static name = 'MuxerClosedError'\n\n constructor (message = 'The muxer is closed') {\n super(message)\n this.name = 'MuxerClosedError'\n }\n}\n\n/**\n * Thrown when a protocol stream is reset by the remote muxer\n */\nexport class StreamResetError extends Error {\n static name = 'StreamResetError'\n\n constructor (message = 'The stream has been reset') {\n super(message)\n this.name = 'StreamResetError'\n }\n}\n\n/**\n * Thrown when a protocol stream is aborted locally\n */\nexport class StreamAbortedError extends Error {\n static name = 'StreamAbortedError'\n\n constructor (message = 'The stream has been aborted') {\n super(message)\n this.name = 'StreamAbortedError'\n }\n}\n\n/**\n * Thrown when a stream is in an invalid state\n */\nexport class StreamStateError extends Error {\n static name = 'StreamStateError'\n\n constructor (message = 'The stream is in an invalid state') {\n super(message)\n this.name = 'StreamStateError'\n }\n}\n\n/**\n * Thrown when a stream buffer is full\n */\nexport class StreamBufferError extends Error {\n static name = 'StreamBufferError'\n\n constructor (message = 'The stream buffer was full') {\n super(message)\n this.name = 'StreamBufferError'\n }\n}\n\n/**\n * Thrown when a value could not be found\n */\nexport class NotFoundError extends Error {\n static name = 'NotFoundError'\n\n constructor (message = 'Not found') {\n super(message)\n this.name = 'NotFoundError'\n }\n}\n\n/**\n * Thrown when an invalid peer ID is encountered\n */\nexport class InvalidPeerIdError extends Error {\n static name = 'InvalidPeerIdError'\n\n constructor (message = 'Invalid PeerID') {\n super(message)\n this.name = 'InvalidPeerIdError'\n }\n}\n\n/**\n * Thrown when an invalid multiaddr is encountered\n */\nexport class InvalidMultiaddrError extends Error {\n static name = 'InvalidMultiaddrError'\n\n constructor (message = 'Invalid multiaddr') {\n super(message)\n this.name = 'InvalidMultiaddrError'\n }\n}\n\n/**\n * Thrown when an invalid CID is encountered\n */\nexport class InvalidCIDError extends Error {\n static name = 'InvalidCIDError'\n\n constructor (message = 'Invalid CID') {\n super(message)\n this.name = 'InvalidCIDError'\n }\n}\n\n/**\n * Thrown when an invalid multihash is encountered\n */\nexport class InvalidMultihashError extends Error {\n static name = 'InvalidMultihashError'\n\n constructor (message = 'Invalid Multihash') {\n super(message)\n this.name = 'InvalidMultihashError'\n }\n}\n\n/**\n * Thrown when a protocol is not supported\n */\nexport class UnsupportedProtocolError extends Error {\n static name = 'UnsupportedProtocolError'\n\n constructor (message = 'Unsupported protocol error') {\n super(message)\n this.name = 'UnsupportedProtocolError'\n }\n}\n\n/**\n * An invalid or malformed message was encountered during a protocol exchange\n */\nexport class InvalidMessageError extends Error {\n static name = 'InvalidMessageError'\n\n constructor (message = 'Invalid message') {\n super(message)\n this.name = 'InvalidMessageError'\n }\n}\n\n/**\n * Thrown when a remote peer sends a structurally valid message that does not\n * comply with the protocol\n */\nexport class ProtocolError extends Error {\n static name = 'ProtocolError'\n\n constructor (message = 'Protocol error') {\n super(message)\n this.name = 'ProtocolError'\n }\n}\n\n/**\n * Throw when an operation times out\n */\nexport class TimeoutError extends Error {\n static name = 'TimeoutError'\n\n constructor (message = 'Timed out') {\n super(message)\n this.name = 'TimeoutError'\n }\n}\n\n/**\n * Thrown when a startable component is interacted with but it has not been\n * started yet\n */\nexport class NotStartedError extends Error {\n static name = 'NotStartedError'\n\n constructor (message = 'Not started') {\n super(message)\n this.name = 'NotStartedError'\n }\n}\n\n/**\n * Thrown when a component is started that has already been started\n */\nexport class AlreadyStartedError extends Error {\n static name = 'AlreadyStartedError'\n\n constructor (message = 'Already started') {\n super(message)\n this.name = 'AlreadyStartedError'\n }\n}\n\n/**\n * Thrown when dialing an address failed\n */\nexport class DialError extends Error {\n static name = 'DialError'\n\n constructor (message = 'Dial error') {\n super(message)\n this.name = 'DialError'\n }\n}\n\n/**\n * Thrown when listening on an address failed\n */\nexport class ListenError extends Error {\n static name = 'ListenError'\n\n constructor (message = 'Listen error') {\n super(message)\n this.name = 'ListenError'\n }\n}\n\n/**\n * This error is thrown when a limited connection is encountered, i.e. if the\n * user tried to open a stream on a connection for a protocol that is not\n * configured to run over limited connections.\n */\nexport class LimitedConnectionError extends Error {\n static name = 'LimitedConnectionError'\n\n constructor (message = 'Limited connection') {\n super(message)\n this.name = 'LimitedConnectionError'\n }\n}\n\n/**\n * This error is thrown where there are too many inbound protocols streams open\n */\nexport class TooManyInboundProtocolStreamsError extends Error {\n static name = 'TooManyInboundProtocolStreamsError'\n\n constructor (message = 'Too many inbound protocol streams') {\n super(message)\n this.name = 'TooManyInboundProtocolStreamsError'\n }\n}\n\n/**\n * This error is thrown where there are too many outbound protocols streams open\n */\nexport class TooManyOutboundProtocolStreamsError extends Error {\n static name = 'TooManyOutboundProtocolStreamsError'\n\n constructor (message = 'Too many outbound protocol streams') {\n super(message)\n this.name = 'TooManyOutboundProtocolStreamsError'\n }\n}\n\n/**\n * Thrown when an attempt to operate on an unsupported key was made\n */\nexport class UnsupportedKeyTypeError extends Error {\n static name = 'UnsupportedKeyTypeError'\n\n constructor (message = 'Unsupported key type') {\n super(message)\n this.name = 'UnsupportedKeyTypeError'\n }\n}\n\n/**\n * Thrown when an operation has not been implemented\n */\nexport class NotImplementedError extends Error {\n static name = 'NotImplementedError'\n\n constructor (message = 'Not implemented') {\n super(message)\n this.name = 'NotImplementedError'\n }\n}\n", "import type { Uint8ArrayList } from 'uint8arraylist'\n\n/**\n * A custom implementation of MessageEvent as the Undici version does too much\n * validation in it's constructor so is very slow.\n */\nexport class StreamMessageEvent extends Event {\n public data: Uint8Array | Uint8ArrayList\n\n constructor (data: Uint8Array | Uint8ArrayList, eventInitDict?: EventInit) {\n super('message', eventInitDict)\n\n this.data = data\n }\n}\n\n/**\n * An event dispatched when the stream is closed. The `error` property can be\n * inspected to discover if the closing was graceful or not, and the `remote`\n * property shows which end of the stream initiated the closure\n */\nexport class StreamCloseEvent extends Event {\n public error?: Error\n public local?: boolean\n\n constructor (local?: boolean, error?: Error, eventInitDict?: EventInit) {\n super('close', eventInitDict)\n\n this.error = error\n this.local = local\n }\n}\n\nexport class StreamAbortEvent extends StreamCloseEvent {\n constructor (error: Error, eventInitDict?: EventInit) {\n super(true, error, eventInitDict)\n }\n}\n\nexport class StreamResetEvent extends StreamCloseEvent {\n constructor (error: Error, eventInitDict?: EventInit) {\n super(false, error, eventInitDict)\n }\n}\n", "import type { AbortOptions } from './index.ts'\nimport type { CID } from 'multiformats/cid'\nimport type { MultihashDigest } from 'multiformats/hashes/interface'\nimport type { Uint8ArrayList } from 'uint8arraylist'\n\nexport type KeyType = 'RSA' | 'Ed25519' | 'secp256k1' | 'ECDSA'\n\nexport interface RSAPublicKey {\n /**\n * The type of this key\n */\n readonly type: 'RSA'\n\n /**\n * PKIX in ASN1 DER format\n */\n readonly raw: Uint8Array\n\n /**\n * The public key as a JSON web key\n */\n readonly jwk: JsonWebKey\n\n /**\n * Returns `true` if the passed object matches this key\n */\n equals(key?: any): boolean\n\n /**\n * Returns this public key as a Multihash digest.\n *\n * It contains a sha256 hash of the protobuf version of the public key.\n */\n toMultihash(): MultihashDigest<0x12>\n\n /**\n * Return this public key as a CID encoded with the `libp2p-key` codec\n *\n * The digest contains a sha256 hash of the protobuf version of the public\n * key.\n */\n toCID(): CID<unknown, 0x72, 0x12, 1>\n\n /**\n * Verify the passed data was signed by the private key corresponding to this\n * public key\n */\n verify(data: Uint8Array | Uint8ArrayList, sig: Uint8Array, options?: AbortOptions): boolean | Promise<boolean>\n\n /**\n * Returns this key as a multihash with base58btc encoding\n */\n toString(): string\n}\n\nexport interface Ed25519PublicKey {\n /**\n * The type of this key\n */\n readonly type: 'Ed25519'\n\n /**\n * The raw public key bytes\n */\n readonly raw: Uint8Array\n\n /**\n * Returns `true` if the passed object matches this key\n */\n equals(key?: any): boolean\n\n /**\n * Returns this public key as an identity hash containing the protobuf wrapped\n * public key\n */\n toMultihash(): MultihashDigest<0x0>\n\n /**\n * Return this public key as a CID encoded with the `libp2p-key` codec\n *\n * The digest contains an identity hash containing the protobuf wrapped\n * version of the public key.\n */\n toCID(): CID<unknown, 0x72, 0x0, 1>\n\n /**\n * Verify the passed data was signed by the private key corresponding to this\n * public key\n */\n verify(data: Uint8Array | Uint8ArrayList, sig: Uint8Array, options?: AbortOptions): boolean | Promise<boolean>\n\n /**\n * Returns this key as a multihash with base58btc encoding\n */\n toString(): string\n}\n\nexport interface Secp256k1PublicKey {\n /**\n * The type of this key\n */\n readonly type: 'secp256k1'\n\n /**\n * The raw public key bytes\n */\n readonly raw: Uint8Array\n\n /**\n * Returns `true` if the passed object matches this key\n */\n equals(key?: any): boolean\n\n /**\n * Returns this public key as an identity hash containing the protobuf wrapped\n * public key\n */\n toMultihash(): MultihashDigest<0x0>\n\n /**\n * Return this public key as a CID encoded with the `libp2p-key` codec\n *\n * The digest contains an identity hash containing the protobuf wrapped\n * version of the public key.\n */\n toCID(): CID<unknown, 0x72, 0x0, 1>\n\n /**\n * Verify the passed data was signed by the private key corresponding to this\n * public key\n */\n verify(data: Uint8Array | Uint8ArrayList, sig: Uint8Array, options?: AbortOptions): boolean | Promise<boolean>\n\n /**\n * Returns this key as a multihash with base58btc encoding\n */\n toString(): string\n}\n\nexport interface ECDSAPublicKey {\n /**\n * The type of this key\n */\n readonly type: 'ECDSA'\n\n /**\n * The public key as a DER-encoded PKIMessage\n */\n readonly raw: Uint8Array\n\n /**\n * The public key as a JSON web key\n */\n readonly jwk: JsonWebKey\n\n /**\n * Returns `true` if the passed object matches this key\n */\n equals(key?: any): boolean\n\n /**\n * Returns this public key as an identity hash containing the protobuf wrapped\n * public key\n */\n toMultihash(): MultihashDigest<0x0>\n\n /**\n * Return this public key as a CID encoded with the `libp2p-key` codec\n *\n * The digest contains an identity hash containing the protobuf wrapped\n * version of the public key.\n */\n toCID(): CID<unknown, 0x72, 0x0, 1>\n\n /**\n * Verify the passed data was signed by the private key corresponding to this\n * public key\n */\n verify(data: Uint8Array | Uint8ArrayList, sig: Uint8Array, options?: AbortOptions): boolean | Promise<boolean>\n\n /**\n * Returns this key as a multihash with base58btc encoding\n */\n toString(): string\n}\n\nexport type PublicKey = RSAPublicKey | Ed25519PublicKey | Secp256k1PublicKey | ECDSAPublicKey\n\n/**\n * Returns true if the passed argument has type overlap with the `PublicKey`\n * interface. Can be used to disambiguate object types.\n */\nexport function isPublicKey (key?: any): key is PublicKey {\n if (key == null) {\n return false\n }\n\n return (key.type === 'RSA' || key.type === 'Ed25519' || key.type === 'secp256k1' || key.type === 'ECDSA') &&\n key.raw instanceof Uint8Array &&\n typeof key.equals === 'function' &&\n typeof key.toMultihash === 'function' &&\n typeof key.toCID === 'function' &&\n typeof key.verify === 'function'\n}\n\n/**\n * Generic private key interface\n */\nexport interface RSAPrivateKey {\n /**\n * The type of this key\n */\n readonly type: 'RSA'\n\n /**\n * The public key that corresponds to this private key\n */\n readonly publicKey: RSAPublicKey\n\n /**\n * PKIX in ASN1 DER format\n */\n readonly raw: Uint8Array\n\n /**\n * The private key as a JSON web key\n */\n readonly jwk: JsonWebKey\n\n /**\n * Returns `true` if the passed object matches this key\n */\n equals(key?: any): boolean\n\n /**\n * Sign the passed data with this private key and return the signature for\n * later verification\n */\n sign(data: Uint8Array | Uint8ArrayList, options?: AbortOptions): Uint8Array | Promise<Uint8Array>\n}\n\nexport interface Ed25519PrivateKey {\n /**\n * The type of this key\n */\n readonly type: 'Ed25519'\n\n /**\n * The public key that corresponds to this private key\n */\n readonly publicKey: Ed25519PublicKey\n\n /**\n * The raw private key bytes\n */\n readonly raw: Uint8Array\n\n /**\n * Returns `true` if the passed object matches this key\n */\n equals(key?: any): boolean\n\n /**\n * Sign the passed data with this private key and return the signature for\n * later verification\n */\n sign(data: Uint8Array | Uint8ArrayList, options?: AbortOptions): Uint8Array | Promise<Uint8Array>\n}\n\nexport interface Secp256k1PrivateKey {\n /**\n * The type of this key\n */\n readonly type: 'secp256k1'\n\n /**\n * The public key that corresponds to this private key\n */\n readonly publicKey: Secp256k1PublicKey\n\n /**\n * The raw private key bytes\n */\n readonly raw: Uint8Array\n\n /**\n * Returns `true` if the passed object matches this key\n */\n equals(key?: any): boolean\n\n /**\n * Sign the passed data with this private key and return the signature for\n * later verification\n */\n sign(data: Uint8Array | Uint8ArrayList, options?: AbortOptions): Uint8Array | Promise<Uint8Array>\n}\n\nexport interface ECDSAPrivateKey {\n /**\n * The type of this key\n */\n readonly type: 'ECDSA'\n\n /**\n * The public key that corresponds to this private key\n */\n readonly publicKey: ECDSAPublicKey\n\n /**\n * The private key as a DER-encoded PKIMessage\n */\n readonly raw: Uint8Array\n\n /**\n * The private key as a JSON web key\n */\n readonly jwk: JsonWebKey\n\n /**\n * Returns `true` if the passed object matches this key\n */\n equals(key?: any): boolean\n\n /**\n * Sign the passed data with this private key and return the signature for\n * later verification\n */\n sign(data: Uint8Array | Uint8ArrayList, options?: AbortOptions): Uint8Array | Promise<Uint8Array>\n}\n\nexport type PrivateKey = RSAPrivateKey | Ed25519PrivateKey | Secp256k1PrivateKey | ECDSAPrivateKey\n\n/**\n * Returns true if the passed argument has type overlap with the `PrivateKey`\n * interface. Can be used to disambiguate object types.\n */\nexport function isPrivateKey (key?: any): key is PrivateKey {\n if (key == null) {\n return false\n }\n\n return (key.type === 'RSA' || key.type === 'Ed25519' || key.type === 'secp256k1' || key.type === 'ECDSA') &&\n isPublicKey(key.publicKey) &&\n key.raw instanceof Uint8Array &&\n typeof key.equals === 'function' &&\n typeof key.sign === 'function'\n}\n", "import type { PeerInfo } from './peer-info.js'\nimport type { TypedEventTarget } from 'main-event'\n\n/**\n * Any object that implements this Symbol as a property should return a\n * PeerDiscovery instance as the property value, similar to how\n * `Symbol.Iterable` can be used to return an `Iterable` from an `Iterator`.\n *\n * @example\n *\n * ```TypeScript\n * import { peerDiscovery, PeerDiscovery } from '@libp2p/peer-discovery'\n *\n * class MyPeerDiscoverer implements PeerDiscovery {\n * get [peerDiscovery] () {\n * return this\n * }\n *\n * // ...other methods\n * }\n * ```\n */\nexport const peerDiscoverySymbol = Symbol.for('@libp2p/peer-discovery')\n\n/**\n * Implementers of this interface can provide a PeerDiscovery implementation to\n * interested callers.\n */\nexport interface PeerDiscoveryProvider {\n [peerDiscoverySymbol]: PeerDiscovery\n}\n\nexport interface PeerDiscoveryEvents {\n peer: CustomEvent<PeerInfo>\n}\n\n/**\n * A class that implements the `PeerDiscovery` interface uses an\n * implementation-specific method to discover peers. These peers are then added\n * to the peer store for use by other system components and services.\n */\nexport interface PeerDiscovery extends TypedEventTarget<PeerDiscoveryEvents> {}\n", "import type { Ed25519PublicKey, KeyType, RSAPublicKey, Secp256k1PublicKey } from './keys.js'\nimport type { CID } from 'multiformats/cid'\nimport type { MultihashDigest } from 'multiformats/hashes/interface'\n\nexport type PeerIdType = KeyType | string\n\n/**\n * A PeerId generated from an RSA public key - it is a base58btc encoded sha-256\n * hash of the public key.\n *\n * RSA public keys are too large to pass around freely, instead Ed25519 or\n * secp256k1 should be preferred as they can embed their public key in the\n * PeerId itself.\n *\n * @deprecated Ed25519 or secp256k1 keys are preferred to RSA\n */\nexport interface RSAPeerId {\n readonly type: 'RSA'\n\n /**\n * RSA public keys are too large to embed in the multihash commonly used to\n * refer to peers, so this will only be defined if the public key has\n * previously been found through a routing query or during normal protocol\n * operations\n */\n readonly publicKey?: RSAPublicKey\n\n /**\n * Returns the multihash from `toMultihash()` as a base58btc encoded string\n */\n toString(): string\n\n /**\n * Returns a multihash, the digest of which is the SHA2-256 hash of the public\n * key\n */\n toMultihash(): MultihashDigest<0x12>\n\n /**\n * Returns a CID with the libp2p key code and the same multihash as\n * `toMultihash()`\n */\n toCID(): CID<Uint8Array, 0x72, 0x12, 1>\n\n /**\n * Returns true if the passed argument is equivalent to this PeerId\n */\n equals(other?: any): boolean\n}\n\nexport interface Ed25519PeerId {\n readonly type: 'Ed25519'\n\n /**\n * This will always be defined as the public key is embedded in the multihash\n * of this PeerId\n */\n readonly publicKey: Ed25519PublicKey\n\n /**\n * Returns the multihash from `toMultihash()` as a base58btc encoded string\n */\n toString(): string\n\n /**\n * Returns a multihash, the digest of which is the protobuf-encoded public key\n * encoded as an identity hash\n */\n toMultihash(): MultihashDigest<0x0>\n\n /**\n * Returns a CID with the libp2p key code and the same multihash as\n * `toMultihash()`\n */\n toCID(): CID<Uint8Array, 0x72, 0x0, 1>\n\n /**\n * Returns true if the passed argument is equivalent to this PeerId\n */\n equals(other?: any): boolean\n}\n\nexport interface Secp256k1PeerId {\n readonly type: 'secp256k1'\n\n /**\n * This will always be defined as the public key is embedded in the multihash\n * of this PeerId\n */\n readonly publicKey: Secp256k1PublicKey\n\n /**\n * Returns the multihash from `toMultihash()` as a base58btc encoded string\n */\n toString(): string\n\n /**\n * Returns a multihash, the digest of which is the protobuf-encoded public key\n * encoded as an identity hash\n */\n toMultihash(): MultihashDigest<0x0>\n\n /**\n * Returns a CID with the libp2p key code and the same multihash as\n * `toMultihash()`\n */\n toCID(): CID<Uint8Array, 0x72, 0x0, 1>\n\n /**\n * Returns true if the passed argument is equivalent to this PeerId\n */\n equals(other?: any): boolean\n}\n\nexport interface URLPeerId {\n readonly type: 'url'\n\n /**\n * This will always be undefined as URL Peers do not have public keys\n */\n readonly publicKey: undefined\n\n /**\n * Returns CID from `toCID()` encoded as a base36 string\n */\n toString(): string\n\n /**\n * Returns a multihash, the digest of which is the URL encoded as an identity\n * hash\n */\n toMultihash(): MultihashDigest<0x0>\n\n /**\n * Returns a CID with the Transport IPFS Gateway HTTP code and the same\n * multihash as `toMultihash()`\n */\n toCID(): CID<Uint8Array, 0x0920, 0x0, 1>\n\n /**\n * Returns true if the passed argument is equivalent to this PeerId\n */\n equals(other?: any): boolean\n}\n\n/**\n * This is a union of all known PeerId types - use the `.type` field to\n * disambiguate them\n */\nexport type PeerId = RSAPeerId | Ed25519PeerId | Secp256k1PeerId | URLPeerId\n\n/**\n * All PeerId implementations must use this symbol as the name of a property\n * with a boolean `true` value\n */\nexport const peerIdSymbol = Symbol.for('@libp2p/peer-id')\n\n/**\n * Returns true if the passed argument is a PeerId implementation\n */\nexport function isPeerId (other?: any): other is PeerId {\n return Boolean(other?.[peerIdSymbol])\n}\n", "import type { RoutingOptions } from './index.js'\nimport type { PeerId } from './peer-id.js'\nimport type { PeerInfo } from './peer-info.js'\n\n/**\n * Any object that implements this Symbol as a property should return a\n * PeerRouting instance as the property value, similar to how `Symbol.Iterable`\n * can be used to return an `Iterable` from an `Iterator`.\n *\n * @example\n *\n * ```TypeScript\n * import { peerRouting, PeerRouting } from '@libp2p/peer-routing'\n *\n * class MyPeerRouter implements PeerRouting {\n * get [peerRouting] () {\n * return this\n * }\n *\n * // ...other methods\n * }\n * ```\n */\nexport const peerRoutingSymbol = Symbol.for('@libp2p/peer-routing')\n\n/**\n * Implementers of this interface can provide a PeerRouting implementation to\n * interested callers.\n */\nexport interface PeerRoutingProvider {\n [peerRoutingSymbol]: Partial<PeerRouting>\n}\n\nexport interface PeerRouting {\n /**\n * Searches the network for peer info corresponding to the passed peer id.\n *\n * @example\n *\n * ```TypeScript\n * // ...\n * const peer = await peerRouting.findPeer(peerId, options)\n * ```\n */\n findPeer(peerId: PeerId, options?: RoutingOptions): Promise<PeerInfo>\n\n /**\n * Search the network for peers that are closer to the passed key. Peer\n * info should be yielded in ever-increasing closeness to the key.\n *\n * @example\n *\n * ```TypeScript\n * // Iterate over the closest peers found for the given key\n * for await (const peer of peerRouting.getClosestPeers(key)) {\n * console.log(peer.id, peer.multiaddrs)\n * }\n * ```\n */\n getClosestPeers(key: Uint8Array, options?: RoutingOptions): AsyncIterable<PeerInfo>\n}\n", "import type { AbortOptions } from './index.ts'\nimport type { PublicKey } from './keys.js'\nimport type { PeerId } from './peer-id.js'\nimport type { PeerInfo } from './peer-info.js'\nimport type { Multiaddr } from '@multiformats/multiaddr'\n\n/**\n * When a peer that is tagged with this prefix disconnects, we will attempt to\n * redial it, up to a limit.\n *\n * To allow multiple components to add/remove their own keep-alive tags without\n * accidentally overwriting those of other components, attach a unique suffix to\n * the tag, e.g. `keep-alive-circuit-relay` or `keep-alive-kad-dht`, etc.\n */\nexport const KEEP_ALIVE = 'keep-alive'\n\n/**\n * A multiaddr with an optional flag that indicates if its trustworthy\n */\nexport interface Address {\n /**\n * Peer multiaddr\n */\n multiaddr: Multiaddr\n\n /**\n * Obtained from a signed peer record\n */\n isCertified: boolean\n}\n\n/**\n * Data stored in the peer store about peers\n */\nexport interface Peer {\n /**\n * Peer's peer-id instance\n */\n id: PeerId\n\n /**\n * Peer's addresses containing a list of multiaddrs and a isCertified field\n * indicating if the address was loaded from a signed peer record or not\n */\n addresses: Address[]\n\n /**\n * Peer's supported protocols\n */\n protocols: string[]\n\n /**\n * Peer's metadata map\n */\n metadata: Map<string, Uint8Array>\n\n /**\n * Tags a peer has\n */\n tags: Map<string, Tag>\n\n /**\n * The last peer record envelope received\n */\n peerRecordEnvelope?: Uint8Array\n}\n\n/**\n * Peer data used to update the peer store\n */\nexport interface PeerData {\n /**\n * Peer's addresses containing its multiaddrs and metadata - multiaddrs\n * passed here can be treated as certified if the `isCertifed` value is\n * set to true.\n *\n * If both addresses and multiaddrs are specified they will be merged\n * together with entries in addresses taking precedence.\n */\n addresses?: Address[]\n\n /**\n * Peer's multiaddrs - any multiaddrs passed here will be treated as\n * uncertified.\n *\n * If both addresses and multiaddrs are specified they will be merged\n * together with entries in addresses taking precedence.\n */\n multiaddrs?: Multiaddr[]\n\n /**\n * Peer's supported protocols\n */\n protocols?: string[]\n\n /**\n * Peer's metadata map. When merging pass undefined as values to remove metadata.\n */\n metadata?: Map<string, Uint8Array | undefined> | Record<string, Uint8Array | undefined>\n\n /**\n * Peer tags. When merging pass undefined as values to remove tags.\n */\n tags?: Map<string, TagOptions | undefined> | Record<string, TagOptions | undefined>\n\n /**\n * If this Peer has an RSA key, it's public key can be set with this property.\n *\n * The byte array should be the protobuf encoded form of the public key.\n */\n publicKey?: PublicKey\n\n /**\n * The last peer record envelope received\n */\n peerRecordEnvelope?: Uint8Array\n}\n\nexport interface TagOptions {\n /**\n * An optional tag value (1-100)\n */\n value?: number\n\n /**\n * An optional duration in ms after which the tag will expire\n */\n ttl?: number\n}\n\nexport interface Tag {\n /**\n * The tag value\n */\n value: number\n}\n\n/**\n * A predicate by which to filter lists of peers\n */\nexport interface PeerQueryFilter { (peer: Peer): boolean }\n\n/**\n * A predicate by which to sort lists of peers\n */\nexport interface PeerQueryOrder { (a: Peer, b: Peer): -1 | 0 | 1 }\n\n/**\n * A query for getting lists of peers\n */\nexport interface PeerQuery extends AbortOptions {\n filters?: PeerQueryFilter[]\n orders?: PeerQueryOrder[]\n limit?: number\n offset?: number\n}\n\nexport interface ConsumePeerRecordOptions extends AbortOptions {\n expectedPeer?: PeerId\n}\n\nexport interface PeerStore {\n /**\n * Loop over every peer - the looping is async because we read from a\n * datastore but the peer operation is sync, this is to prevent\n * long-lived peer operations causing deadlocks over the datastore\n * which can happen if they try to access the peer store during the\n * loop\n *\n * @example\n *\n * ```TypeScript\n * await peerStore.forEach(peer => {\n * // ...\n * })\n * ```\n */\n forEach(fn: (peer: Peer) => void, query?: PeerQuery): Promise<void>\n\n /**\n * Returns all peers in the peer store.\n *\n * @example\n *\n * ```TypeScript\n * for (const peer of await peerStore.all()) {\n * // ...\n * }\n * ```\n */\n all(query?: PeerQuery): Promise<Peer[]>\n\n /**\n * Delete all data stored for the passed peer\n *\n * @example\n *\n * ```TypeScript\n * await peerStore.addressBook.set(peerId, multiaddrs)\n * await peerStore.addressBook.get(peerId)\n * // multiaddrs[]\n *\n * await peerStore.delete(peerId)\n *\n * await peerStore.addressBook.get(peerId)\n * // []\n * ```\n */\n delete(peerId: PeerId, options?: AbortOptions): Promise<void>\n\n /**\n * Returns true if the passed PeerId is in the peer store\n *\n * @example\n *\n * ```TypeScript\n * await peerStore.has(peerId)\n * // false\n * await peerStore.addressBook.add(peerId, multiaddrs)\n * await peerStore.has(peerId)\n * // true\n * ```\n */\n has(peerId: PeerId, options?: AbortOptions): Promise<boolean>\n\n /**\n * Returns all data stored for the passed PeerId\n *\n * @example\n *\n * ```TypeScript\n * const peer = await peerStore.get(peerId)\n * // { .. }\n * ```\n */\n get(peerId: PeerId, options?: AbortOptions): Promise<Peer>\n\n /**\n * Returns a PeerInfo object for the passed peer id. This is similar to `get`\n * except the returned value contains fewer fields and is often used to\n * exchange peer information with other systems.\n *\n * The returned object can be passed to `JSON.stringify` without any\n * additional processing.\n *\n * @see https://libp2p.io/docs/peers/#peer-info\n *\n * @example\n *\n * ```TypeScript\n * const peerInfo = await peerStore.getInfo(peerId)\n *\n * console.info(JSON.stringify(peerInfo))\n * // {\n * // id: 'peerId'\n * // multiaddrs: [\n * // '...'\n * // ]\n * // }\n * ```\n */\n getInfo (peerId: PeerId, options?: AbortOptions): Promise<PeerInfo>\n\n /**\n * Adds a peer to the peer store, overwriting any existing data\n *\n * @example\n *\n * ```TypeScript\n * await peerStore.save(peerId, {\n * multiaddrs\n * })\n * ```\n */\n save(id: PeerId, data: PeerData, options?: AbortOptions): Promise<Peer>\n\n /**\n * Adds a peer to the peer store, overwriting only the passed fields\n *\n * @example\n *\n * ```TypeScript\n * await peerStore.patch(peerId, {\n * multiaddrs\n * })\n * ```\n */\n patch(id: PeerId, data: PeerData, options?: AbortOptions): Promise<Peer>\n\n /**\n * Adds a peer to the peer store, deeply merging any existing data.\n *\n * @example\n *\n * ```TypeScript\n * await peerStore.merge(peerId, {\n * multiaddrs\n * })\n * ```\n */\n merge(id: PeerId, data: PeerData, options?: AbortOptions): Promise<Peer>\n\n /**\n * Unmarshal and verify a signed peer record, extract the multiaddrs and\n * overwrite the stored addresses for the peer.\n *\n * Optionally pass an expected PeerId to verify that the peer record was\n * signed by that peer.\n *\n * @example\n *\n * ```TypeScript\n * await peerStore.consumePeerRecord(buf, expectedPeer)\n * ```\n */\n consumePeerRecord(buf: Uint8Array, options?: ConsumePeerRecordOptions): Promise<boolean>\n}\n", "/**\n * Implemented by components that have a life cycle\n */\nexport interface Startable {\n /**\n * If implemented, this method will be invoked before the start method.\n *\n * It should not assume any other components have been started.\n */\n beforeStart?(): void | Promise<void>\n\n /**\n * This method will be invoked to start the component.\n *\n * It should not assume that any other components have been started.\n */\n start(): void | Promise<void>\n\n /**\n * If implemented, this method will be invoked after the start method.\n *\n * All other components will have had their start method invoked before this method is called.\n */\n afterStart?(): void | Promise<void>\n\n /**\n * If implemented, this method will be invoked before the stop method.\n *\n * Any other components will still be running when this method is called.\n */\n beforeStop?(): void | Promise<void>\n\n /**\n * This method will be invoked to stop the component.\n *\n * It should not assume any other components are running when it is called.\n */\n stop(): void | Promise<void>\n\n /**\n * If implemented, this method will be invoked after the stop method.\n *\n * All other components will have had their stop method invoked before this method is called.\n */\n afterStop?(): void | Promise<void>\n}\n\n/**\n * Returns `true` if the object has type overlap with `Startable`\n */\nexport function isStartable (obj?: any): obj is Startable {\n return obj != null && typeof obj.start === 'function' && typeof obj.stop === 'function'\n}\n\n/**\n * A function that can be used to start and objects passed to it. This checks\n * that an object is startable before invoking its lifecycle methods so it is\n * safe to pass non-`Startable`s in.\n *\n * @example\n *\n * ```TypeScript\n * import { start } from '@libp2p/interface'\n * import type { Startable } from '@libp2p/interface'\n *\n * const startable: Startable = {\n * start: () => {},\n * stop: () => {}\n * }\n *\n * const notStartable = 5\n *\n * await start(\n * startable,\n * notStartable\n * )\n * ```\n */\nexport async function start (...objs: any[]): Promise<void> {\n const startables: Startable[] = []\n\n for (const obj of objs) {\n if (isStartable(obj)) {\n startables.push(obj)\n }\n }\n\n await Promise.all(\n startables.map(async s => {\n if (s.beforeStart != null) {\n await s.beforeStart()\n }\n })\n )\n\n await Promise.all(\n startables.map(async s => {\n await s.start()\n })\n )\n\n await Promise.all(\n startables.map(async s => {\n if (s.afterStart != null) {\n await s.afterStart()\n }\n })\n )\n}\n\n/**\n * A function that can be used to stop and objects passed to it. This checks\n * that an object is startable before invoking its lifecycle methods so it is\n * safe to pass non-`Startable`s in.\n *\n * @example\n *\n * ```TypeScript\n * import { stop } from '@libp2p/interface'\n * import type { Startable } from '@libp2p/interface'\n *\n * const startable: Startable = {\n * start: () => {},\n * stop: () => {}\n * }\n *\n * const notStartable = 5\n *\n * await stop(\n * startable,\n * notStartable\n * )\n * ```\n */\nexport async function stop (...objs: any[]): Promise<void> {\n const startables: Startable[] = []\n\n for (const obj of objs) {\n if (isStartable(obj)) {\n startables.push(obj)\n }\n }\n\n await Promise.all(\n startables.map(async s => {\n if (s.beforeStop != null) {\n await s.beforeStop()\n }\n })\n )\n\n await Promise.all(\n startables.map(async s => {\n await s.stop()\n })\n )\n\n await Promise.all(\n startables.map(async s => {\n if (s.afterStop != null) {\n await s.afterStop()\n }\n })\n )\n}\n", "import type { AbortOptions, ClearableSignal, ConnectionEncrypter, MultiaddrConnection, Connection, ConnectionLimits, StreamMuxerFactory, PeerId } from './index.js'\nimport type { Multiaddr } from '@multiformats/multiaddr'\nimport type { TypedEventTarget } from 'main-event'\nimport type { ProgressOptions, ProgressEvent } from 'progress-events'\n\nexport interface ListenerEvents {\n /**\n * This event signals to the transport manager that the listening addresses\n * have changed and may be emitted at any point and/or multiple times\n */\n listening: CustomEvent\n\n /**\n * Emitted if listening on an address failed\n */\n error: CustomEvent<Error>\n\n /**\n * Emitted when the listener has been shut down, has no open connections and\n * will no longer accept new connections\n */\n close: CustomEvent\n}\n\nexport interface Listener extends TypedEventTarget<ListenerEvents> {\n /**\n * Start a listener\n */\n listen(multiaddr: Multiaddr): Promise<void>\n\n /**\n * Get listen addresses\n */\n getAddrs(): Multiaddr[]\n\n /**\n * Close listener\n *\n * @returns {Promise<void>}\n */\n close(): Promise<void>\n\n /**\n * Allows transports to amend announce addresses - to add certificate hashes\n * or other metadata that cannot be known before runtime\n */\n updateAnnounceAddrs(addrs: Multiaddr[]): void\n}\n\nexport const transportSymbol = Symbol.for('@libp2p/transport')\n\n/**\n * A filter that acts on a list of multiaddrs\n */\nexport interface MultiaddrFilter {\n (multiaddrs: Multiaddr[]): Multiaddr[]\n}\n\nexport interface CreateListenerOptions {\n /**\n * The upgrader turns a MultiaddrConnection into a Connection and notifies\n * other libp2p components about a new incoming connection.\n */\n upgrader: Upgrader\n}\n\nexport interface DialTransportOptions<DialEvents extends ProgressEvent = ProgressEvent> extends Required<AbortOptions>, ProgressOptions<DialEvents> {\n /**\n * The upgrader turns a MultiaddrConnection into a Connection which should be\n * returned by the transport's dial method\n */\n upgrader: Upgrader\n}\n\n/**\n * A libp2p transport offers dial and listen methods to establish connections.\n */\nexport interface Transport<DialEvents extends ProgressEvent = ProgressEvent> {\n /**\n * Used to identify the transport\n */\n [Symbol.toStringTag]: string\n\n /**\n * Used by the isTransport function\n */\n [transportSymbol]: true\n\n /**\n * Dial a given multiaddr.\n */\n dial(ma: Multiaddr, options: DialTransportOptions<DialEvents>): Promise<Connection>\n\n /**\n * Create transport listeners.\n */\n createListener(options: CreateListenerOptions): Listener\n\n /**\n * Takes a list of `Multiaddr`s and returns only addresses that are valid for\n * the transport to listen on\n */\n listenFilter: MultiaddrFilter\n\n /**\n * Takes a list of `Multiaddr`s and returns only addresses that are valid for\n * the transport to dial\n */\n dialFilter: MultiaddrFilter\n}\n\n/**\n * Used to disambiguate transport implementations\n */\nexport function isTransport (other?: any): other is Transport {\n return other != null && Boolean(other[transportSymbol])\n}\n\n/**\n * Enum Transport Manager Fault Tolerance values\n */\nexport enum FaultTolerance {\n /**\n * should be used for failing in any listen circumstance\n */\n FATAL_ALL = 0,\n\n /**\n * should be used for not failing when not listening\n */\n NO_FATAL\n}\n\n/**\n * Options accepted by the upgrader during connection establishment\n */\nexport interface UpgraderOptions<ConnectionUpgradeEvents extends ProgressEvent = ProgressEvent> extends ProgressOptions<ConnectionUpgradeEvents>, Required<AbortOptions> {\n /**\n * If true no connection protection will be performed on the connection.\n */\n skipProtection?: boolean\n\n /**\n * By default a stream muxer protocol will be negotiated via multi-stream\n * select after an encryption protocol has been agreed on.\n *\n * If a transport provides it's own stream muxing facility pass a muxer\n * factory instance here to skip muxer negotiation.\n */\n muxerFactory?: StreamMuxerFactory\n\n /**\n * If the connection is to have limits applied to it, pass them here\n */\n limits?: ConnectionLimits\n\n /**\n * Multi-stream select is a initiator/responder protocol. By default a\n * connection returned from `upgrader.upgradeOutbound` will be the initiator\n * and one returned from `upgrader.upgradeInbound` will be the responder.\n *\n * Pass a value here to override the default.\n */\n initiator?: boolean\n}\n\n/**\n * Options accepted by the upgrader during connection establishment\n */\nexport interface UpgraderWithoutEncryptionOptions extends UpgraderOptions {\n /**\n * If true the invoking transport is expected to implement it's own encryption\n * and an encryption protocol will not attempted to be negotiated via\n * multi-stream select\n */\n skipEncryption: true\n\n /**\n * If `skipEncryption` is true, a remote PeerId must be supplied\n */\n remotePeer: PeerId\n}\n\nexport type InboundConnectionUpgradeEvents =\nProgressEvent<'upgrader:encrypt-inbound-connection'> |\nProgressEvent<'upgrader:multiplex-inbound-connection'>\n\nexport type OutboundConnectionUpgradeEvents =\nProgressEvent<'upgrader:encrypt-outbound-connection'> |\nProgressEvent<'upgrader:multiplex-outbound-connection'>\n\nexport interface Upgrader {\n /**\n * Upgrades an outbound connection created by the `dial` method of a transport\n */\n upgradeOutbound(maConn: MultiaddrConnection, opts: UpgraderOptions<OutboundConnectionUpgradeEvents>): Promise<Connection>\n upgradeOutbound(maConn: MultiaddrConnection, opts: UpgraderWithoutEncryptionOptions): Promise<Connection>\n\n /**\n * Upgrades an inbound connection received by a transport listener and\n * notifies other libp2p components about the new connection\n */\n upgradeInbound(maConn: MultiaddrConnection, opts: UpgraderOptions<InboundConnectionUpgradeEvents>): Promise<void>\n upgradeInbound(maConn: MultiaddrConnection, opts: UpgraderWithoutEncryptionOptions): Promise<void>\n\n /**\n * Used by transports that perform part of the upgrade process themselves and\n * do some async work. This allows configuring inbound upgrade timeouts from a\n * single location.\n *\n * Regular transports should just pass the signal from their shutdown\n * controller to `upgradeInbound`.\n */\n createInboundAbortSignal (signal: AbortSignal): ClearableSignal\n\n /**\n * Returns configured stream muxers\n */\n getStreamMuxers (): Map<string, StreamMuxerFactory>\n\n /**\n * Returns configured connection encrypters\n */\n getConnectionEncrypters (): Map<string, ConnectionEncrypter>\n}\n", "/**\n * Noop for browser compatibility\n */\nexport function setMaxListeners (): void {}\n", "/**\n * @packageDocumentation\n *\n * Adds types to the EventTarget class.\n *\n * Hopefully this won't be necessary\n * forever:\n *\n * - https://github.com/microsoft/TypeScript/issues/28357\n * - https://github.com/microsoft/TypeScript/issues/43477\n * - https://github.com/microsoft/TypeScript/issues/299\n * - https://www.npmjs.com/package/typed-events\n * - https://www.npmjs.com/package/typed-event-emitter\n * - https://www.npmjs.com/package/typed-event-target\n * - etc\n *\n * In addition to types, a `safeDispatchEvent` method is available which\n * prevents dispatching events that aren't in the event map, and a\n * `listenerCount` method which reports the number of listeners that are\n * currently registered for a given event.\n *\n * @example\n *\n * ```ts\n * import { TypedEventEmitter } from 'main-event'\n * import type { TypedEventTarget } from 'main-event'\n *\n * interface EventTypes {\n * 'test': CustomEvent<string>\n * }\n *\n * const target = new TypedEventEmitter<EventTypes>()\n *\n * // it's a regular EventTarget\n * console.info(target instanceof EventTarget) // true\n *\n * // register listeners normally\n * target.addEventListener('test', (evt) => {\n * // evt is CustomEvent<string>\n * })\n *\n * // @ts-expect-error 'derp' is not in the event map\n * target.addEventListener('derp', () => {})\n *\n * // use normal dispatchEvent method\n * target.dispatchEvent(new CustomEvent('test', {\n * detail: 'hello'\n * }))\n *\n * // use type safe dispatch method\n * target.safeDispatchEvent('test', {\n * detail: 'world'\n * })\n *\n * // report listener count\n * console.info(target.listenerCount('test')) // 0\n *\n * // event emitters can be used purely as interfaces too\n * function acceptTarget (target: TypedEventTarget<EventTypes>) {\n * // ...\n * }\n * ```\n */\n\nimport { setMaxListeners } from './events.js'\n\nexport interface EventCallback<EventType> { (evt: EventType): void }\nexport interface EventObject<EventType> { handleEvent: EventCallback<EventType> }\nexport type EventHandler<EventType> = EventCallback<EventType> | EventObject<EventType>\n\ninterface Listener {\n once: boolean\n callback: any\n}\n\n/**\n *\n */\nexport interface TypedEventTarget <EventMap extends Record<string, any>> extends EventTarget {\n addEventListener<K extends keyof EventMap>(type: K, listener: EventHandler<EventMap[K]> | null, options?: boolean | AddEventListenerOptions): void\n\n listenerCount (type: string): number\n\n removeEventListener<K extends keyof EventMap>(type: K, listener?: EventHandler<EventMap[K]> | null, options?: boolean | EventListenerOptions): void\n\n removeEventListener (type: string, listener?: EventHandler<Event>, options?: boolean | EventListenerOptions): void\n\n safeDispatchEvent<Detail>(type: keyof EventMap, detail?: CustomEventInit<Detail>): boolean\n}\n\n/**\n * An implementation of a typed event target\n */\nexport class TypedEventEmitter<EventMap extends Record<string, any>> extends EventTarget implements TypedEventTarget<EventMap> {\n readonly #listeners = new Map<any, Listener[]>()\n\n constructor () {\n super()\n\n // silence MaxListenersExceededWarning warning on Node.js, this is a red\n // herring almost all of the time\n setMaxListeners(Infinity, this)\n }\n\n listenerCount (type: string): number {\n const listeners = this.#listeners.get(type)\n\n if (listeners == null) {\n return 0\n }\n\n return listeners.length\n }\n\n addEventListener<K extends keyof EventMap>(type: K, listener: EventHandler<EventMap[K]> | null, options?: boolean | AddEventListenerOptions): void\n addEventListener (type: string, listener: EventHandler<Event>, options?: boolean | AddEventListenerOptions): void {\n super.addEventListener(type, listener, options)\n\n let list = this.#listeners.get(type)\n\n if (list == null) {\n list = []\n this.#listeners.set(type, list)\n }\n\n list.push({\n callback: listener,\n once: (options !== true && options !== false && options?.once) ?? false\n })\n }\n\n removeEventListener<K extends keyof EventMap>(type: K, listener?: EventHandler<EventMap[K]> | null, options?: boolean | EventListenerOptions): void\n removeEventListener (type: string, listener?: EventHandler<Event>, options?: boolean | EventListenerOptions): void {\n super.removeEventListener(type.toString(), listener ?? null, options)\n\n let list = this.#listeners.get(type)\n\n if (list == null) {\n return\n }\n\n list = list.filter(({ callback }) => callback !== listener)\n this.#listeners.set(type, list)\n }\n\n dispatchEvent (event: Event): boolean {\n const result = super.dispatchEvent(event)\n\n let list = this.#listeners.get(event.type)\n\n if (list == null) {\n return result\n }\n\n list = list.filter(({ once }) => !once)\n this.#listeners.set(event.type, list)\n\n return result\n }\n\n safeDispatchEvent<Detail>(type: keyof EventMap, detail: CustomEventInit<Detail> = {}): boolean {\n return this.dispatchEvent(new CustomEvent<Detail>(type as string, detail))\n }\n}\n\nexport { setMaxListeners }\n"],
|
|
5
5
|
"mappings": "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",
|
|
6
6
|
"names": ["index_exports", "__export", "AbortError", "AlreadyStartedError", "ConnectionClosedError", "ConnectionClosingError", "ConnectionFailedError", "DialError", "FaultTolerance", "InvalidCIDError", "InvalidCryptoExchangeError", "InvalidMessageError", "InvalidMultiaddrError", "InvalidMultihashError", "InvalidParametersError", "InvalidPeerIdError", "InvalidPrivateKeyError", "InvalidPublicKeyError", "KEEP_ALIVE", "LimitedConnectionError", "ListenError", "MuxerClosedError", "NotFoundError", "NotImplementedError", "NotStartedError", "ProtocolError", "StreamAbortEvent", "StreamAbortedError", "StreamBufferError", "StreamCloseEvent", "StreamMessageEvent", "StreamResetError", "StreamResetEvent", "StreamStateError", "TimeoutError", "TooManyInboundProtocolStreamsError", "TooManyOutboundProtocolStreamsError", "TypedEventEmitter", "UnexpectedPeerError", "UnsupportedKeyTypeError", "UnsupportedOperationError", "UnsupportedProtocolError", "connectionSymbol", "contentRoutingSymbol", "isConnection", "isPeerId", "isPrivateKey", "isPublicKey", "isStartable", "isTransport", "peerDiscoverySymbol", "peerIdSymbol", "peerRoutingSymbol", "serviceCapabilities", "serviceDependencies", "setMaxListeners", "start", "stop", "transportSymbol", "connectionSymbol", "isConnection", "other", "contentRoutingSymbol", "AbortError", "message", "UnexpectedPeerError", "InvalidCryptoExchangeError", "InvalidParametersError", "InvalidPublicKeyError", "InvalidPrivateKeyError", "UnsupportedOperationError", "ConnectionClosingError", "ConnectionClosedError", "ConnectionFailedError", "MuxerClosedError", "StreamResetError", "StreamAbortedError", "StreamStateError", "StreamBufferError", "NotFoundError", "InvalidPeerIdError", "InvalidMultiaddrError", "InvalidCIDError", "InvalidMultihashError", "UnsupportedProtocolError", "InvalidMessageError", "ProtocolError", "TimeoutError", "NotStartedError", "AlreadyStartedError", "DialError", "ListenError", "LimitedConnectionError", "TooManyInboundProtocolStreamsError", "TooManyOutboundProtocolStreamsError", "UnsupportedKeyTypeError", "NotImplementedError", "StreamMessageEvent", "data", "eventInitDict", "StreamCloseEvent", "local", "error", "StreamAbortEvent", "StreamResetEvent", "isPublicKey", "key", "isPrivateKey", "peerDiscoverySymbol", "peerIdSymbol", "isPeerId", "other", "peerRoutingSymbol", "KEEP_ALIVE", "isStartable", "obj", "start", "objs", "startables", "s", "stop", "transportSymbol", "isTransport", "other", "FaultTolerance", "setMaxListeners", "TypedEventEmitter", "#listeners", "type", "listeners", "listener", "options", "list", "callback", "event", "result", "once", "detail", "serviceCapabilities", "serviceDependencies"]
|
|
7
7
|
}
|
package/dist/src/peer-info.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { Multiaddr } from '@multiformats/multiaddr';
|
|
|
4
4
|
* A `PeerInfo` is a lightweight object that represents a remote peer, it can be
|
|
5
5
|
* obtained from peer discovery mechanisms, HTTP RPC endpoints, etc.
|
|
6
6
|
*
|
|
7
|
-
* @see https://
|
|
7
|
+
* @see https://libp2p.io/docs/peers/#peer-info
|
|
8
8
|
*/
|
|
9
9
|
export interface PeerInfo {
|
|
10
10
|
/**
|
package/dist/src/peer-store.d.ts
CHANGED
|
@@ -218,7 +218,7 @@ export interface PeerStore {
|
|
|
218
218
|
* The returned object can be passed to `JSON.stringify` without any
|
|
219
219
|
* additional processing.
|
|
220
220
|
*
|
|
221
|
-
* @see https://
|
|
221
|
+
* @see https://libp2p.io/docs/peers/#peer-info
|
|
222
222
|
*
|
|
223
223
|
* @example
|
|
224
224
|
*
|
package/package.json
CHANGED
package/src/peer-info.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { Multiaddr } from '@multiformats/multiaddr'
|
|
|
5
5
|
* A `PeerInfo` is a lightweight object that represents a remote peer, it can be
|
|
6
6
|
* obtained from peer discovery mechanisms, HTTP RPC endpoints, etc.
|
|
7
7
|
*
|
|
8
|
-
* @see https://
|
|
8
|
+
* @see https://libp2p.io/docs/peers/#peer-info
|
|
9
9
|
*/
|
|
10
10
|
export interface PeerInfo {
|
|
11
11
|
/**
|
package/src/peer-store.ts
CHANGED
|
@@ -243,7 +243,7 @@ export interface PeerStore {
|
|
|
243
243
|
* The returned object can be passed to `JSON.stringify` without any
|
|
244
244
|
* additional processing.
|
|
245
245
|
*
|
|
246
|
-
* @see https://
|
|
246
|
+
* @see https://libp2p.io/docs/peers/#peer-info
|
|
247
247
|
*
|
|
248
248
|
* @example
|
|
249
249
|
*
|