@libp2p/interface 0.0.1-05abd49f

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.
Files changed (129) hide show
  1. package/LICENSE +4 -0
  2. package/README.md +45 -0
  3. package/dist/index.min.js +3 -0
  4. package/dist/src/connection/index.d.ts +188 -0
  5. package/dist/src/connection/index.d.ts.map +1 -0
  6. package/dist/src/connection/index.js +5 -0
  7. package/dist/src/connection/index.js.map +1 -0
  8. package/dist/src/connection/status.d.ts +4 -0
  9. package/dist/src/connection/status.d.ts.map +1 -0
  10. package/dist/src/connection/status.js +4 -0
  11. package/dist/src/connection/status.js.map +1 -0
  12. package/dist/src/connection-encrypter/index.d.ts +27 -0
  13. package/dist/src/connection-encrypter/index.d.ts.map +1 -0
  14. package/dist/src/connection-encrypter/index.js +2 -0
  15. package/dist/src/connection-encrypter/index.js.map +1 -0
  16. package/dist/src/connection-gater/index.d.ts +117 -0
  17. package/dist/src/connection-gater/index.d.ts.map +1 -0
  18. package/dist/src/connection-gater/index.js +2 -0
  19. package/dist/src/connection-gater/index.js.map +1 -0
  20. package/dist/src/content-routing/index.d.ts +79 -0
  21. package/dist/src/content-routing/index.d.ts.map +1 -0
  22. package/dist/src/content-routing/index.js +21 -0
  23. package/dist/src/content-routing/index.js.map +1 -0
  24. package/dist/src/errors.d.ts +33 -0
  25. package/dist/src/errors.d.ts.map +1 -0
  26. package/dist/src/errors.js +51 -0
  27. package/dist/src/errors.js.map +1 -0
  28. package/dist/src/events.d.ts +28 -0
  29. package/dist/src/events.d.ts.map +1 -0
  30. package/dist/src/events.js +70 -0
  31. package/dist/src/events.js.map +1 -0
  32. package/dist/src/index.d.ts +575 -0
  33. package/dist/src/index.d.ts.map +1 -0
  34. package/dist/src/index.js +17 -0
  35. package/dist/src/index.js.map +1 -0
  36. package/dist/src/keychain/index.d.ts +154 -0
  37. package/dist/src/keychain/index.d.ts.map +1 -0
  38. package/dist/src/keychain/index.js +23 -0
  39. package/dist/src/keychain/index.js.map +1 -0
  40. package/dist/src/keys/index.d.ts +35 -0
  41. package/dist/src/keys/index.d.ts.map +1 -0
  42. package/dist/src/keys/index.js +4 -0
  43. package/dist/src/keys/index.js.map +1 -0
  44. package/dist/src/metrics/index.d.ts +165 -0
  45. package/dist/src/metrics/index.d.ts.map +1 -0
  46. package/dist/src/metrics/index.js +2 -0
  47. package/dist/src/metrics/index.js.map +1 -0
  48. package/dist/src/metrics/tracked-map.d.ts +17 -0
  49. package/dist/src/metrics/tracked-map.d.ts.map +1 -0
  50. package/dist/src/metrics/tracked-map.js +38 -0
  51. package/dist/src/metrics/tracked-map.js.map +1 -0
  52. package/dist/src/peer-discovery/index.d.ts +28 -0
  53. package/dist/src/peer-discovery/index.d.ts.map +1 -0
  54. package/dist/src/peer-discovery/index.js +21 -0
  55. package/dist/src/peer-discovery/index.js.map +1 -0
  56. package/dist/src/peer-id/index.d.ts +30 -0
  57. package/dist/src/peer-id/index.d.ts.map +1 -0
  58. package/dist/src/peer-id/index.js +5 -0
  59. package/dist/src/peer-id/index.js.map +1 -0
  60. package/dist/src/peer-info/index.d.ts +8 -0
  61. package/dist/src/peer-info/index.d.ts.map +1 -0
  62. package/dist/src/peer-info/index.js +2 -0
  63. package/dist/src/peer-info/index.js.map +1 -0
  64. package/dist/src/peer-routing/index.d.ts +51 -0
  65. package/dist/src/peer-routing/index.d.ts.map +1 -0
  66. package/dist/src/peer-routing/index.js +21 -0
  67. package/dist/src/peer-routing/index.js.map +1 -0
  68. package/dist/src/peer-store/index.d.ts +247 -0
  69. package/dist/src/peer-store/index.d.ts.map +1 -0
  70. package/dist/src/peer-store/index.js +2 -0
  71. package/dist/src/peer-store/index.js.map +1 -0
  72. package/dist/src/peer-store/tags.d.ts +2 -0
  73. package/dist/src/peer-store/tags.d.ts.map +1 -0
  74. package/dist/src/peer-store/tags.js +2 -0
  75. package/dist/src/peer-store/tags.js.map +1 -0
  76. package/dist/src/record/index.d.ts +33 -0
  77. package/dist/src/record/index.d.ts.map +1 -0
  78. package/dist/src/record/index.js +2 -0
  79. package/dist/src/record/index.js.map +1 -0
  80. package/dist/src/startable.d.ts +46 -0
  81. package/dist/src/startable.d.ts.map +1 -0
  82. package/dist/src/startable.js +46 -0
  83. package/dist/src/startable.js.map +1 -0
  84. package/dist/src/stream-handler/index.d.ts +23 -0
  85. package/dist/src/stream-handler/index.d.ts.map +1 -0
  86. package/dist/src/stream-handler/index.js +2 -0
  87. package/dist/src/stream-handler/index.js.map +1 -0
  88. package/dist/src/stream-muxer/index.d.ts +51 -0
  89. package/dist/src/stream-muxer/index.d.ts.map +1 -0
  90. package/dist/src/stream-muxer/index.js +2 -0
  91. package/dist/src/stream-muxer/index.js.map +1 -0
  92. package/dist/src/stream-muxer/stream.d.ts +85 -0
  93. package/dist/src/stream-muxer/stream.d.ts.map +1 -0
  94. package/dist/src/stream-muxer/stream.js +255 -0
  95. package/dist/src/stream-muxer/stream.js.map +1 -0
  96. package/dist/src/topology/index.d.ts +9 -0
  97. package/dist/src/topology/index.d.ts.map +1 -0
  98. package/dist/src/topology/index.js +2 -0
  99. package/dist/src/topology/index.js.map +1 -0
  100. package/dist/src/transport/index.d.ts +96 -0
  101. package/dist/src/transport/index.d.ts.map +1 -0
  102. package/dist/src/transport/index.js +19 -0
  103. package/dist/src/transport/index.js.map +1 -0
  104. package/package.json +177 -0
  105. package/src/connection/index.ts +221 -0
  106. package/src/connection/status.ts +4 -0
  107. package/src/connection-encrypter/index.ts +30 -0
  108. package/src/connection-gater/index.ts +128 -0
  109. package/src/content-routing/index.ts +83 -0
  110. package/src/errors.ts +68 -0
  111. package/src/events.ts +100 -0
  112. package/src/index.ts +627 -0
  113. package/src/keychain/index.ts +167 -0
  114. package/src/keys/index.ts +38 -0
  115. package/src/metrics/index.ts +187 -0
  116. package/src/metrics/tracked-map.ts +65 -0
  117. package/src/peer-discovery/index.ts +29 -0
  118. package/src/peer-id/index.ts +39 -0
  119. package/src/peer-info/index.ts +8 -0
  120. package/src/peer-routing/index.ts +53 -0
  121. package/src/peer-store/index.ts +272 -0
  122. package/src/peer-store/tags.ts +2 -0
  123. package/src/record/index.ts +35 -0
  124. package/src/startable.ts +117 -0
  125. package/src/stream-handler/index.ts +27 -0
  126. package/src/stream-muxer/index.ts +58 -0
  127. package/src/stream-muxer/stream.ts +365 -0
  128. package/src/topology/index.ts +10 -0
  129. package/src/transport/index.ts +111 -0
package/src/index.ts ADDED
@@ -0,0 +1,627 @@
1
+ /**
2
+ * @packageDocumentation
3
+ *
4
+ * Exports a `Libp2p` type for modules to use as a type argument.
5
+ *
6
+ * @example
7
+ *
8
+ * ```typescript
9
+ * import type { Libp2p } from '@libp2p/interface'
10
+ *
11
+ * function doSomethingWithLibp2p (node: Libp2p) {
12
+ * // ...
13
+ * }
14
+ * ```
15
+ */
16
+
17
+ import type { Connection, Stream } from './connection/index.js'
18
+ import type { ContentRouting } from './content-routing/index.js'
19
+ import type { EventEmitter } from './events.js'
20
+ import type { KeyChain } from './keychain/index.js'
21
+ import type { Metrics } from './metrics/index.js'
22
+ import type { PeerId } from './peer-id/index.js'
23
+ import type { PeerInfo } from './peer-info/index.js'
24
+ import type { PeerRouting } from './peer-routing/index.js'
25
+ import type { Address, Peer, PeerStore } from './peer-store/index.js'
26
+ import type { Startable } from './startable.js'
27
+ import type { StreamHandler, StreamHandlerOptions } from './stream-handler/index.js'
28
+ import type { Topology } from './topology/index.js'
29
+ import type { Listener } from './transport/index.js'
30
+ import type { Multiaddr } from '@multiformats/multiaddr'
31
+
32
+ /**
33
+ * Used by the connection manager to sort addresses into order before dialling
34
+ */
35
+ export interface AddressSorter {
36
+ (a: Address, b: Address): -1 | 0 | 1
37
+ }
38
+
39
+ /**
40
+ * Event detail emitted when peer data changes
41
+ */
42
+ export interface PeerUpdate {
43
+ peer: Peer
44
+ previous?: Peer
45
+ }
46
+
47
+ /**
48
+ * Peer data signed by the remote Peer's public key
49
+ */
50
+ export interface SignedPeerRecord {
51
+ addresses: Multiaddr[]
52
+ seq: bigint
53
+ }
54
+
55
+ /**
56
+ * Data returned from a successful identify response
57
+ */
58
+ export interface IdentifyResult {
59
+ /**
60
+ * The remote Peer's PeerId
61
+ */
62
+ peerId: PeerId
63
+
64
+ /**
65
+ * The unsigned addresses they are listening on. Note - any multiaddrs present
66
+ * in the signed peer record should be preferred to the value here.
67
+ */
68
+ listenAddrs: Multiaddr[]
69
+
70
+ /**
71
+ * The protocols the remote peer supports
72
+ */
73
+ protocols: string[]
74
+
75
+ /**
76
+ * The remote protocol version
77
+ */
78
+ protocolVersion?: string
79
+
80
+ /**
81
+ * The remote agent version
82
+ */
83
+ agentVersion?: string
84
+
85
+ /**
86
+ * The public key part of the remote PeerId - this is only useful for older
87
+ * RSA-based PeerIds, the more modern Ed25519 and secp256k1 types have the
88
+ * public key embedded in them
89
+ */
90
+ publicKey?: Uint8Array
91
+
92
+ /**
93
+ * If set this is the address that the remote peer saw the identify request
94
+ * originate from
95
+ */
96
+ observedAddr?: Multiaddr
97
+
98
+ /**
99
+ * If sent by the remote peer this is the deserialized signed peer record
100
+ */
101
+ signedPeerRecord?: SignedPeerRecord
102
+ }
103
+
104
+ /**
105
+ * Once you have a libp2p instance, you can listen to several events it emits,
106
+ * so that you can be notified of relevant network events.
107
+ *
108
+ * Event names are `noun:verb` so the first part is the name of the object
109
+ * being acted on and the second is the action.
110
+ */
111
+ export interface Libp2pEvents<T extends ServiceMap = ServiceMap> {
112
+ /**
113
+ * This event is dispatched when a new network peer is discovered.
114
+ *
115
+ * @example
116
+ *
117
+ * ```js
118
+ * libp2p.addEventListener('peer:discovery', (event) => {
119
+ * const peerInfo = event.detail
120
+ * // ...
121
+ * })
122
+ * ```
123
+ */
124
+ 'peer:discovery': CustomEvent<PeerInfo>
125
+
126
+ /**
127
+ * This event will be triggered any time a new peer connects.
128
+ *
129
+ * @example
130
+ *
131
+ * ```js
132
+ * libp2p.addEventListener('peer:connect', (event) => {
133
+ * const peerId = event.detail
134
+ * // ...
135
+ * })
136
+ * ```
137
+ */
138
+ 'peer:connect': CustomEvent<PeerId>
139
+
140
+ /**
141
+ * This event will be triggered any time we are disconnected from another peer, regardless of
142
+ * the circumstances of that disconnection. If we happen to have multiple connections to a
143
+ * peer, this event will **only** be triggered when the last connection is closed.
144
+ *
145
+ * @example
146
+ *
147
+ * ```js
148
+ * libp2p.addEventListener('peer:disconnect', (event) => {
149
+ * const peerId = event.detail
150
+ * // ...
151
+ * })
152
+ * ```
153
+ */
154
+ 'peer:disconnect': CustomEvent<PeerId>
155
+
156
+ /**
157
+ * This event is dispatched after a remote peer has successfully responded to the identify
158
+ * protocol. Note that for this to be emitted, both peers must have an identify service
159
+ * configured.
160
+ *
161
+ * @example
162
+ *
163
+ * ```js
164
+ * libp2p.addEventListener('peer:identify', (event) => {
165
+ * const identifyResult = event.detail
166
+ * // ...
167
+ * })
168
+ * ```
169
+ */
170
+ 'peer:identify': CustomEvent<IdentifyResult>
171
+
172
+ /**
173
+ * This event is dispatched when the peer store data for a peer has been
174
+ * updated - e.g. their multiaddrs, protocols etc have changed.
175
+ *
176
+ * If they were previously known to this node, the old peer data will be
177
+ * set in the `previous` field.
178
+ *
179
+ * This may be in response to the identify protocol running, a manual
180
+ * update or some other event.
181
+ */
182
+ 'peer:update': CustomEvent<PeerUpdate>
183
+
184
+ /**
185
+ * This event is dispatched when the current node's peer record changes -
186
+ * for example a transport started listening on a new address or a new
187
+ * protocol handler was registered.
188
+ *
189
+ * @example
190
+ *
191
+ * ```js
192
+ * libp2p.addEventListener('self:peer:update', (event) => {
193
+ * const { peer } = event.detail
194
+ * // ...
195
+ * })
196
+ * ```
197
+ */
198
+ 'self:peer:update': CustomEvent<PeerUpdate>
199
+
200
+ /**
201
+ * This event is dispatched when a transport begins listening on a new address
202
+ */
203
+ 'transport:listening': CustomEvent<Listener>
204
+
205
+ /**
206
+ * This event is dispatched when a transport stops listening on an address
207
+ */
208
+ 'transport:close': CustomEvent<Listener>
209
+
210
+ /**
211
+ * This event is dispatched when the connection manager has more than the
212
+ * configured allowable max connections and has closed some connections to
213
+ * bring the node back under the limit.
214
+ */
215
+ 'connection:prune': CustomEvent<Connection[]>
216
+
217
+ /**
218
+ * This event notifies listeners when new incoming or outgoing connections
219
+ * are opened.
220
+ */
221
+ 'connection:open': CustomEvent<Connection>
222
+
223
+ /**
224
+ * This event notifies listeners when incoming or outgoing connections are
225
+ * closed.
226
+ */
227
+ 'connection:close': CustomEvent<Connection>
228
+
229
+ /**
230
+ * This event notifies listeners that the node has started
231
+ *
232
+ * ```js
233
+ * libp2p.addEventListener('start', (event) => {
234
+ * console.info(libp2p.isStarted()) // true
235
+ * })
236
+ * ```
237
+ */
238
+ 'start': CustomEvent<Libp2p<T>>
239
+
240
+ /**
241
+ * This event notifies listeners that the node has stopped
242
+ *
243
+ * ```js
244
+ * libp2p.addEventListener('stop', (event) => {
245
+ * console.info(libp2p.isStarted()) // false
246
+ * })
247
+ * ```
248
+ */
249
+ 'stop': CustomEvent<Libp2p<T>>
250
+ }
251
+
252
+ /**
253
+ * A map of user defined services available on the libp2p node via the
254
+ * `services` key
255
+ *
256
+ * @example
257
+ *
258
+ * ```js
259
+ * const node = await createLibp2p({
260
+ * // ...other options
261
+ * services: {
262
+ * myService: myService({
263
+ * // ...service options
264
+ * })
265
+ * }
266
+ * })
267
+ *
268
+ * // invoke methods on the service
269
+ * node.services.myService.anOperation()
270
+ * ```
271
+ */
272
+ export type ServiceMap = Record<string, unknown>
273
+
274
+ export type PendingDialStatus = 'queued' | 'active' | 'error' | 'success'
275
+
276
+ /**
277
+ * An item in the dial queue
278
+ */
279
+ export interface PendingDial {
280
+ /**
281
+ * A unique identifier for this dial
282
+ */
283
+ id: string
284
+
285
+ /**
286
+ * The current status of the dial
287
+ */
288
+ status: PendingDialStatus
289
+
290
+ /**
291
+ * If known, this is the peer id that libp2p expects to be dialling
292
+ */
293
+ peerId?: PeerId
294
+
295
+ /**
296
+ * The list of multiaddrs that will be dialled. The returned connection will
297
+ * use the first address that succeeds, all other dials part of this pending
298
+ * dial will be cancelled.
299
+ */
300
+ multiaddrs: Multiaddr[]
301
+ }
302
+
303
+ /**
304
+ * Libp2p nodes implement this interface.
305
+ */
306
+ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, EventEmitter<Libp2pEvents<T>> {
307
+ /**
308
+ * The PeerId is a unique identifier for a node on the network.
309
+ *
310
+ * It is the hash of an RSA public key or, for Ed25519 or secp256k1 keys,
311
+ * the key itself.
312
+ *
313
+ * @example
314
+ *
315
+ * ```js
316
+ * console.info(libp2p.peerId)
317
+ * // PeerId(12D3Foo...)
318
+ * ````
319
+ */
320
+ peerId: PeerId
321
+
322
+ /**
323
+ * The peer store holds information we know about other peers on the network.
324
+ * - multiaddrs, supported protocols, etc.
325
+ *
326
+ * @example
327
+ *
328
+ * ```js
329
+ * const peer = await libp2p.peerStore.get(peerId)
330
+ * console.info(peer)
331
+ * // { id: PeerId(12D3Foo...), addresses: [] ... }
332
+ * ```
333
+ */
334
+ peerStore: PeerStore
335
+
336
+ /**
337
+ * The peer routing subsystem allows the user to find peers on the network
338
+ * or to find peers close to binary keys.
339
+ *
340
+ * @example
341
+ *
342
+ * ```js
343
+ * const peerInfo = await libp2p.peerRouting.findPeer(peerId)
344
+ * console.info(peerInfo)
345
+ * // { id: PeerId(12D3Foo...), multiaddrs: [] ... }
346
+ * ```
347
+ *
348
+ * @example
349
+ *
350
+ * ```js
351
+ * for await (const peerInfo of libp2p.peerRouting.getClosestPeers(key)) {
352
+ * console.info(peerInfo)
353
+ * // { id: PeerId(12D3Foo...), multiaddrs: [] ... }
354
+ * }
355
+ * ```
356
+ */
357
+ peerRouting: PeerRouting
358
+
359
+ /**
360
+ * The content routing subsystem allows the user to find providers for content,
361
+ * let the network know they are providers for content, and get/put values to
362
+ * the DHT.
363
+ *
364
+ * @example
365
+ *
366
+ * ```js
367
+ * for await (const peerInfo of libp2p.contentRouting.findProviders(cid)) {
368
+ * console.info(peerInfo)
369
+ * // { id: PeerId(12D3Foo...), multiaddrs: [] ... }
370
+ * }
371
+ * ```
372
+ */
373
+ contentRouting: ContentRouting
374
+
375
+ /**
376
+ * The keychain contains the keys used by the current node, and can create new
377
+ * keys, export them, import them, etc.
378
+ *
379
+ * @example
380
+ *
381
+ * ```js
382
+ * const keyInfo = await libp2p.keychain.createKey('new key')
383
+ * console.info(keyInfo)
384
+ * // { id: '...', name: 'new key' }
385
+ * ```
386
+ */
387
+ keychain: KeyChain
388
+
389
+ /**
390
+ * The metrics subsystem allows recording values to assess the health/performance
391
+ * of the running node.
392
+ *
393
+ * @example
394
+ *
395
+ * ```js
396
+ * const metric = libp2p.metrics.registerMetric({
397
+ * 'my-metric'
398
+ * })
399
+ *
400
+ * // later
401
+ * metric.update(5)
402
+ * ```
403
+ */
404
+ metrics?: Metrics
405
+
406
+ /**
407
+ * Get a deduplicated list of peer advertising multiaddrs by concatenating
408
+ * the listen addresses used by transports with any configured
409
+ * announce addresses as well as observed addresses reported by peers.
410
+ *
411
+ * If Announce addrs are specified, configured listen addresses will be
412
+ * ignored though observed addresses will still be included.
413
+ *
414
+ * @example
415
+ *
416
+ * ```js
417
+ * const listenMa = libp2p.getMultiaddrs()
418
+ * // [ <Multiaddr 047f00000106f9ba - /ip4/127.0.0.1/tcp/63930> ]
419
+ * ```
420
+ */
421
+ getMultiaddrs: () => Multiaddr[]
422
+
423
+ /**
424
+ * Returns a list of supported protocols
425
+ *
426
+ * @example
427
+ *
428
+ * ```js
429
+ * const protocols = libp2p.getProtocols()
430
+ * // [ '/ipfs/ping/1.0.0', '/ipfs/id/1.0.0' ]
431
+ * ```
432
+ */
433
+ getProtocols: () => string[]
434
+
435
+ /**
436
+ * Return a list of all connections this node has open, optionally filtering
437
+ * by a PeerId
438
+ *
439
+ * @example
440
+ *
441
+ * ```js
442
+ * for (const connection of libp2p.getConnections()) {
443
+ * console.log(peerId, connection.remoteAddr.toString())
444
+ * // Logs the PeerId string and the observed remote multiaddr of each Connection
445
+ * }
446
+ * ```
447
+ */
448
+ getConnections: (peerId?: PeerId) => Connection[]
449
+
450
+ /**
451
+ * Return the list of dials currently in progress or queued to start
452
+ *
453
+ * @example
454
+ *
455
+ * ```js
456
+ * for (const pendingDial of libp2p.getDialQueue()) {
457
+ * console.log(pendingDial)
458
+ * }
459
+ * ```
460
+ */
461
+ getDialQueue: () => PendingDial[]
462
+
463
+ /**
464
+ * Return a list of all peers we currently have a connection open to
465
+ */
466
+ getPeers: () => PeerId[]
467
+
468
+ /**
469
+ * Dials to the provided peer. If successful, the known metadata of the
470
+ * peer will be added to the nodes `peerStore`.
471
+ *
472
+ * If a PeerId is passed as the first argument, the peer will need to have known multiaddrs for it in the PeerStore.
473
+ *
474
+ * @example
475
+ *
476
+ * ```js
477
+ * const conn = await libp2p.dial(remotePeerId)
478
+ *
479
+ * // create a new stream within the connection
480
+ * const { stream, protocol } = await conn.newStream(['/echo/1.1.0', '/echo/1.0.0'])
481
+ *
482
+ * // protocol negotiated: 'echo/1.0.0' means that the other party only supports the older version
483
+ *
484
+ * // ...
485
+ * await conn.close()
486
+ * ```
487
+ */
488
+ dial: (peer: PeerId | Multiaddr | Multiaddr[], options?: AbortOptions) => Promise<Connection>
489
+
490
+ /**
491
+ * Dials to the provided peer and tries to handshake with the given protocols in order.
492
+ * If successful, the known metadata of the peer will be added to the nodes `peerStore`,
493
+ * and the `MuxedStream` will be returned together with the successful negotiated protocol.
494
+ *
495
+ * @example
496
+ *
497
+ * ```js
498
+ * import { pipe } from 'it-pipe'
499
+ *
500
+ * const { stream, protocol } = await libp2p.dialProtocol(remotePeerId, protocols)
501
+ *
502
+ * // Use this new stream like any other duplex stream
503
+ * pipe([1, 2, 3], stream, consume)
504
+ * ```
505
+ */
506
+ dialProtocol: (peer: PeerId | Multiaddr | Multiaddr[], protocols: string | string[], options?: AbortOptions) => Promise<Stream>
507
+
508
+ /**
509
+ * Attempts to gracefully close an open connection to the given peer. If the connection is not closed in the grace period, it will be forcefully closed.
510
+ *
511
+ * @example
512
+ *
513
+ * ```js
514
+ * await libp2p.hangUp(remotePeerId)
515
+ * ```
516
+ */
517
+ hangUp: (peer: PeerId | Multiaddr) => Promise<void>
518
+
519
+ /**
520
+ * 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.
521
+ *
522
+ * `libp2p.handle(protocols, handler, options)`
523
+ *
524
+ * In the event of a new handler for the same protocol being added, the first one is discarded.
525
+ *
526
+ * @example
527
+ *
528
+ * ```js
529
+ * const handler = ({ connection, stream, protocol }) => {
530
+ * // use stream or connection according to the needs
531
+ * }
532
+ *
533
+ * libp2p.handle('/echo/1.0.0', handler, {
534
+ * maxInboundStreams: 5,
535
+ * maxOutboundStreams: 5
536
+ * })
537
+ * ```
538
+ */
539
+ handle: (protocol: string | string[], handler: StreamHandler, options?: StreamHandlerOptions) => Promise<void>
540
+
541
+ /**
542
+ * Removes the handler for each protocol. The protocol
543
+ * will no longer be supported on streams.
544
+ *
545
+ * @example
546
+ *
547
+ * ```js
548
+ * libp2p.unhandle(['/echo/1.0.0'])
549
+ * ```
550
+ */
551
+ unhandle: (protocols: string[] | string) => Promise<void>
552
+
553
+ /**
554
+ * Register a topology to be informed when peers are encountered that
555
+ * support the specified protocol
556
+ *
557
+ * @example
558
+ *
559
+ * ```js
560
+ * const id = await libp2p.register('/echo/1.0.0', {
561
+ * onConnect: (peer, connection) => {
562
+ * // handle connect
563
+ * },
564
+ * onDisconnect: (peer, connection) => {
565
+ * // handle disconnect
566
+ * }
567
+ * })
568
+ * ```
569
+ */
570
+ register: (protocol: string, topology: Topology) => Promise<string>
571
+
572
+ /**
573
+ * Unregister topology to no longer be informed when peers connect or
574
+ * disconnect.
575
+ *
576
+ * @example
577
+ *
578
+ * ```js
579
+ * const id = await libp2p.register(...)
580
+ *
581
+ * libp2p.unregister(id)
582
+ * ```
583
+ */
584
+ unregister: (id: string) => void
585
+
586
+ /**
587
+ * Returns the public key for the passed PeerId. If the PeerId is of the 'RSA' type
588
+ * this may mean searching the DHT if the key is not present in the KeyStore.
589
+ * A set of user defined services
590
+ */
591
+ getPublicKey: (peer: PeerId, options?: AbortOptions) => Promise<Uint8Array>
592
+
593
+ /**
594
+ * A set of user defined services
595
+ */
596
+ services: T
597
+ }
598
+
599
+ /**
600
+ * An object that contains an AbortSignal as
601
+ * the optional `signal` property.
602
+ *
603
+ * @example
604
+ *
605
+ * ```js
606
+ * const controller = new AbortController()
607
+ *
608
+ * aLongRunningOperation({
609
+ * signal: controller.signal
610
+ * })
611
+ *
612
+ * // later
613
+ *
614
+ * controller.abort()
615
+ */
616
+ export interface AbortOptions {
617
+ signal?: AbortSignal
618
+ }
619
+
620
+ /**
621
+ * Returns a new type with all fields marked optional.
622
+ *
623
+ * Borrowed from the tsdef module.
624
+ */
625
+ export type RecursivePartial<T> = {
626
+ [P in keyof T]?: T[P] extends Array<infer I> ? Array<RecursivePartial<I>> : T[P] extends (...args: any[]) => any ? T[P] : RecursivePartial<T[P]>
627
+ }