@libp2p/interface 2.9.0-f1de46607 → 2.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/dist/index.min.js +1 -1
  2. package/dist/index.min.js.map +3 -3
  3. package/dist/src/content-routing.d.ts +2 -2
  4. package/dist/src/content-routing.d.ts.map +1 -1
  5. package/dist/src/content-routing.js +1 -1
  6. package/dist/src/errors.d.ts +8 -1
  7. package/dist/src/errors.d.ts.map +1 -1
  8. package/dist/src/errors.js +11 -1
  9. package/dist/src/errors.js.map +1 -1
  10. package/dist/src/event-target.d.ts +2 -2
  11. package/dist/src/event-target.d.ts.map +1 -1
  12. package/dist/src/event-target.js +0 -1
  13. package/dist/src/event-target.js.map +1 -1
  14. package/dist/src/index.d.ts +38 -1
  15. package/dist/src/index.d.ts.map +1 -1
  16. package/dist/src/index.js.map +1 -1
  17. package/dist/src/metrics.d.ts +1 -2
  18. package/dist/src/metrics.d.ts.map +1 -1
  19. package/dist/src/peer-discovery.d.ts +5 -0
  20. package/dist/src/peer-discovery.d.ts.map +1 -1
  21. package/dist/src/peer-routing.d.ts +3 -3
  22. package/dist/src/peer-routing.d.ts.map +1 -1
  23. package/dist/src/peer-routing.js +2 -2
  24. package/dist/src/peer-store.d.ts +26 -0
  25. package/dist/src/peer-store.d.ts.map +1 -1
  26. package/dist/src/peer-store.js.map +1 -1
  27. package/dist/src/pubsub.d.ts +3 -0
  28. package/dist/src/pubsub.d.ts.map +1 -1
  29. package/dist/src/pubsub.js.map +1 -1
  30. package/dist/src/record.d.ts +25 -1
  31. package/dist/src/record.d.ts.map +1 -1
  32. package/dist/src/startable.d.ts +52 -1
  33. package/dist/src/startable.d.ts.map +1 -1
  34. package/dist/src/startable.js +51 -0
  35. package/dist/src/startable.js.map +1 -1
  36. package/dist/src/topology.d.ts +2 -1
  37. package/dist/src/topology.d.ts.map +1 -1
  38. package/dist/src/transport.d.ts +37 -1
  39. package/dist/src/transport.d.ts.map +1 -1
  40. package/dist/src/transport.js +3 -0
  41. package/dist/src/transport.js.map +1 -1
  42. package/dist/typedoc-urls.json +223 -0
  43. package/package.json +1 -1
  44. package/src/content-routing.ts +2 -2
  45. package/src/errors.ts +13 -1
  46. package/src/event-target.ts +2 -2
  47. package/src/index.ts +38 -1
  48. package/src/metrics.ts +1 -1
  49. package/src/peer-discovery.ts +5 -0
  50. package/src/peer-routing.ts +3 -3
  51. package/src/peer-store.ts +27 -0
  52. package/src/pubsub.ts +3 -0
  53. package/src/record.ts +30 -1
  54. package/src/startable.ts +52 -1
  55. package/src/topology.ts +2 -1
  56. package/src/transport.ts +44 -2
package/src/peer-store.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { PublicKey } from './keys.js'
2
2
  import type { PeerId } from './peer-id.js'
3
+ import type { PeerInfo } from './peer-info.js'
3
4
  import type { Multiaddr } from '@multiformats/multiaddr'
4
5
 
5
6
  /**
@@ -229,6 +230,32 @@ export interface PeerStore {
229
230
  */
230
231
  get(peerId: PeerId): Promise<Peer>
231
232
 
233
+ /**
234
+ * Returns a PeerInfo object for the passed peer id. This is similar to `get`
235
+ * except the returned value contains fewer fields and is often used to
236
+ * exchange peer information with other systems.
237
+ *
238
+ * The returned object can be passed to `JSON.stringify` without any
239
+ * additional processing.
240
+ *
241
+ * @see https://docs.libp2p.io/concepts/fundamentals/peers/#peer-info
242
+ *
243
+ * @example
244
+ *
245
+ * ```TypeScript
246
+ * const peerInfo = await peerStore.getInfo(peerId)
247
+ *
248
+ * console.info(JSON.stringify(peerInfo))
249
+ * // {
250
+ * // id: 'peerId'
251
+ * // multiaddrs: [
252
+ * // '...'
253
+ * // ]
254
+ * // }
255
+ * ```
256
+ */
257
+ getInfo (peerId: PeerId): Promise<PeerInfo>
258
+
232
259
  /**
233
260
  * Adds a peer to the peer store, overwriting any existing data
234
261
  *
package/src/pubsub.ts CHANGED
@@ -153,6 +153,9 @@ export interface TopicValidatorFn {
153
153
  (peer: PeerId, message: Message): TopicValidatorResult | Promise<TopicValidatorResult>
154
154
  }
155
155
 
156
+ /**
157
+ * @deprecated This will be removed from `@libp2p/interface` in a future release, pubsub implementations should declare their own types
158
+ */
156
159
  export interface PubSub<Events extends Record<string, any> = PubSubEvents> extends TypedEventTarget<Events> {
157
160
  /**
158
161
  * The global signature policy controls whether or not we sill send and receive
package/src/record.ts CHANGED
@@ -23,13 +23,42 @@ export interface Record {
23
23
  equals(other: Record): boolean
24
24
  }
25
25
 
26
+ /**
27
+ * A message with a signed payload.
28
+ */
26
29
  export interface Envelope {
30
+ /**
31
+ * The public key of the keypair used to sign the payload
32
+ */
27
33
  publicKey: PublicKey
34
+
35
+ /**
36
+ * How the payload should be interpreted
37
+ */
28
38
  payloadType: Uint8Array | Uint8ArrayList
39
+
40
+ /**
41
+ * The contents of the envelope
42
+ */
29
43
  payload: Uint8Array
44
+
45
+ /**
46
+ * A signature that can be used to verify the payload is intact
47
+ */
30
48
  signature: Uint8Array | Uint8ArrayList
31
49
 
50
+ /**
51
+ * Serialize the envelope to a binary format
52
+ */
32
53
  marshal(): Uint8Array
54
+
55
+ /**
56
+ * Use the public key to validate that the payload is intact
57
+ */
33
58
  validate(domain: string): Promise<boolean>
34
- equals(other: Envelope): boolean
59
+
60
+ /**
61
+ * Returns true if this envelope has equivalency with the passed object
62
+ */
63
+ equals(other?: Envelope): boolean
35
64
  }
package/src/startable.ts CHANGED
@@ -45,10 +45,37 @@ export interface Startable {
45
45
  afterStop?(): void | Promise<void>
46
46
  }
47
47
 
48
- export function isStartable (obj: any): obj is Startable {
48
+ /**
49
+ * Returns `true` if the object has type overlap with `Startable`
50
+ */
51
+ export function isStartable (obj?: any): obj is Startable {
49
52
  return obj != null && typeof obj.start === 'function' && typeof obj.stop === 'function'
50
53
  }
51
54
 
55
+ /**
56
+ * A function that can be used to start and objects passed to it. This checks
57
+ * that an object is startable before invoking its lifecycle methods so it is
58
+ * safe to pass non-`Startable`s in.
59
+ *
60
+ * @example
61
+ *
62
+ * ```TypeScript
63
+ * import { start } from '@libp2p/interface'
64
+ * import type { Startable } from '@libp2p/interface'
65
+ *
66
+ * const startable: Startable = {
67
+ * start: () => {},
68
+ * stop: () => {}
69
+ * }
70
+ *
71
+ * const notStartable = 5
72
+ *
73
+ * await start(
74
+ * startable,
75
+ * notStartable
76
+ * )
77
+ * ```
78
+ */
52
79
  export async function start (...objs: any[]): Promise<void> {
53
80
  const startables: Startable[] = []
54
81
 
@@ -81,6 +108,30 @@ export async function start (...objs: any[]): Promise<void> {
81
108
  )
82
109
  }
83
110
 
111
+ /**
112
+ * A function that can be used to stop and objects passed to it. This checks
113
+ * that an object is startable before invoking its lifecycle methods so it is
114
+ * safe to pass non-`Startable`s in.
115
+ *
116
+ * @example
117
+ *
118
+ * ```TypeScript
119
+ * import { stop } from '@libp2p/interface'
120
+ * import type { Startable } from '@libp2p/interface'
121
+ *
122
+ * const startable: Startable = {
123
+ * start: () => {},
124
+ * stop: () => {}
125
+ * }
126
+ *
127
+ * const notStartable = 5
128
+ *
129
+ * await stop(
130
+ * startable,
131
+ * notStartable
132
+ * )
133
+ * ```
134
+ */
84
135
  export async function stop (...objs: any[]): Promise<void> {
85
136
  const startables: Startable[] = []
86
137
 
package/src/topology.ts CHANGED
@@ -2,7 +2,8 @@ import type { Connection } from './connection.js'
2
2
  import type { PeerId } from './peer-id.js'
3
3
 
4
4
  /**
5
- * A topology filter
5
+ * A topology filter - this can be used by topologies to ensure they do not
6
+ * receive duplicate notifications of individual peers
6
7
  *
7
8
  * @see https://libp2p.github.io/js-libp2p/functions/_libp2p_peer_collections.peerFilter-1.html
8
9
  */
package/src/transport.ts CHANGED
@@ -48,7 +48,12 @@ export interface Listener extends TypedEventTarget<ListenerEvents> {
48
48
 
49
49
  export const transportSymbol = Symbol.for('@libp2p/transport')
50
50
 
51
- export interface MultiaddrFilter { (multiaddrs: Multiaddr[]): Multiaddr[] }
51
+ /**
52
+ * A filter that acts on a list of multiaddrs
53
+ */
54
+ export interface MultiaddrFilter {
55
+ (multiaddrs: Multiaddr[]): Multiaddr[]
56
+ }
52
57
 
53
58
  export interface CreateListenerOptions {
54
59
  /**
@@ -103,7 +108,10 @@ export interface Transport<DialEvents extends ProgressEvent = ProgressEvent> {
103
108
  dialFilter: MultiaddrFilter
104
109
  }
105
110
 
106
- export function isTransport (other: any): other is Transport {
111
+ /**
112
+ * Used to disambiguate transport implementations
113
+ */
114
+ export function isTransport (other?: any): other is Transport {
107
115
  return other != null && Boolean(other[transportSymbol])
108
116
  }
109
117
 
@@ -122,11 +130,45 @@ export enum FaultTolerance {
122
130
  NO_FATAL
123
131
  }
124
132
 
133
+ /**
134
+ * Options accepted by the upgrader during connection establishment
135
+ */
125
136
  export interface UpgraderOptions<ConnectionUpgradeEvents extends ProgressEvent = ProgressEvent> extends ProgressOptions<ConnectionUpgradeEvents>, Required<AbortOptions> {
137
+ /**
138
+ * If true the invoking transport is expected to implement it's own encryption
139
+ * and an encryption protocol will not attempted to be negotiated via
140
+ * multi-stream select
141
+ *
142
+ * @default false
143
+ */
126
144
  skipEncryption?: boolean
145
+
146
+ /**
147
+ * If true no connection protection will be performed on the connection.
148
+ */
127
149
  skipProtection?: boolean
150
+
151
+ /**
152
+ * By default a stream muxer protocol will be negotiated via multi-stream
153
+ * select after an encryption protocol has been agreed on.
154
+ *
155
+ * If a transport provides it's own stream muxing facility pass a muxer
156
+ * factory instance here to skip muxer negotiation.
157
+ */
128
158
  muxerFactory?: StreamMuxerFactory
159
+
160
+ /**
161
+ * If the connection is to have limits applied to it, pass them here
162
+ */
129
163
  limits?: ConnectionLimits
164
+
165
+ /**
166
+ * Multi-stream select is a initiator/responder protocol. By default a
167
+ * connection returned from `upgrader.upgradeOutbound` will be the initiator
168
+ * and one returned from `upgrader.upgradeInbound` will be the responder.
169
+ *
170
+ * Pass a value here to override the default.
171
+ */
130
172
  initiator?: boolean
131
173
  }
132
174