@libp2p/interface 0.1.6-effcfaa8e → 1.0.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 (85) hide show
  1. package/README.md +15 -1
  2. package/dist/index.min.js +1 -1
  3. package/dist/src/connection/index.d.ts +15 -3
  4. package/dist/src/connection/index.d.ts.map +1 -1
  5. package/dist/src/connection/index.js +2 -2
  6. package/dist/src/connection/index.js.map +1 -1
  7. package/dist/src/connection-encrypter/index.d.ts +7 -5
  8. package/dist/src/connection-encrypter/index.d.ts.map +1 -1
  9. package/dist/src/content-routing/index.d.ts +1 -1
  10. package/dist/src/content-routing/index.d.ts.map +1 -1
  11. package/dist/src/content-routing/index.js +1 -1
  12. package/dist/src/content-routing/index.js.map +1 -1
  13. package/dist/src/errors.d.ts +20 -5
  14. package/dist/src/errors.d.ts.map +1 -1
  15. package/dist/src/errors.js +20 -8
  16. package/dist/src/errors.js.map +1 -1
  17. package/dist/src/events.d.ts +0 -1
  18. package/dist/src/events.d.ts.map +1 -1
  19. package/dist/src/events.js +0 -2
  20. package/dist/src/events.js.map +1 -1
  21. package/dist/src/index.d.ts +34 -14
  22. package/dist/src/index.d.ts.map +1 -1
  23. package/dist/src/index.js +21 -1
  24. package/dist/src/index.js.map +1 -1
  25. package/dist/src/keys/index.d.ts +5 -4
  26. package/dist/src/keys/index.d.ts.map +1 -1
  27. package/dist/src/keys/index.js.map +1 -1
  28. package/dist/src/peer-discovery/index.d.ts +1 -1
  29. package/dist/src/peer-discovery/index.d.ts.map +1 -1
  30. package/dist/src/peer-discovery/index.js +1 -1
  31. package/dist/src/peer-discovery/index.js.map +1 -1
  32. package/dist/src/peer-id/index.d.ts +1 -1
  33. package/dist/src/peer-id/index.d.ts.map +1 -1
  34. package/dist/src/peer-id/index.js +2 -2
  35. package/dist/src/peer-id/index.js.map +1 -1
  36. package/dist/src/peer-info/index.d.ts +12 -1
  37. package/dist/src/peer-info/index.d.ts.map +1 -1
  38. package/dist/src/peer-routing/index.d.ts +1 -1
  39. package/dist/src/peer-routing/index.d.ts.map +1 -1
  40. package/dist/src/peer-routing/index.js +1 -1
  41. package/dist/src/peer-routing/index.js.map +1 -1
  42. package/dist/src/startable.d.ts +8 -1
  43. package/dist/src/startable.d.ts.map +1 -1
  44. package/dist/src/startable.js +8 -0
  45. package/dist/src/startable.js.map +1 -1
  46. package/dist/src/stream-muxer/index.d.ts +2 -2
  47. package/dist/src/stream-muxer/index.d.ts.map +1 -1
  48. package/dist/src/stream-muxer/stream.d.ts +2 -149
  49. package/dist/src/stream-muxer/stream.d.ts.map +1 -1
  50. package/dist/src/stream-muxer/stream.js +8 -322
  51. package/dist/src/stream-muxer/stream.js.map +1 -1
  52. package/dist/src/topology/index.d.ts +0 -2
  53. package/dist/src/topology/index.d.ts.map +1 -1
  54. package/dist/src/transport/index.d.ts +2 -2
  55. package/dist/src/transport/index.d.ts.map +1 -1
  56. package/dist/src/transport/index.js +2 -2
  57. package/dist/src/transport/index.js.map +1 -1
  58. package/dist/typedoc-urls.json +265 -0
  59. package/package.json +15 -27
  60. package/src/connection/index.ts +19 -4
  61. package/src/connection-encrypter/index.ts +7 -5
  62. package/src/content-routing/index.ts +1 -1
  63. package/src/errors.ts +21 -8
  64. package/src/events.ts +0 -3
  65. package/src/index.ts +37 -15
  66. package/src/keys/index.ts +6 -4
  67. package/src/peer-discovery/index.ts +1 -1
  68. package/src/peer-id/index.ts +2 -2
  69. package/src/peer-info/index.ts +13 -1
  70. package/src/peer-routing/index.ts +1 -1
  71. package/src/startable.ts +8 -2
  72. package/src/stream-muxer/index.ts +2 -2
  73. package/src/stream-muxer/stream.ts +9 -494
  74. package/src/topology/index.ts +0 -3
  75. package/src/transport/index.ts +3 -3
  76. package/dist/src/keychain/index.d.ts +0 -154
  77. package/dist/src/keychain/index.d.ts.map +0 -1
  78. package/dist/src/keychain/index.js +0 -23
  79. package/dist/src/keychain/index.js.map +0 -1
  80. package/dist/src/metrics/tracked-map.d.ts +0 -17
  81. package/dist/src/metrics/tracked-map.d.ts.map +0 -1
  82. package/dist/src/metrics/tracked-map.js +0 -38
  83. package/dist/src/metrics/tracked-map.js.map +0 -1
  84. package/src/keychain/index.ts +0 -167
  85. package/src/metrics/tracked-map.ts +0 -65
package/src/index.ts CHANGED
@@ -17,7 +17,6 @@
17
17
  import type { Connection, NewStreamOptions, Stream } from './connection/index.js'
18
18
  import type { ContentRouting } from './content-routing/index.js'
19
19
  import type { TypedEventTarget } from './events.js'
20
- import type { KeyChain } from './keychain/index.js'
21
20
  import type { Metrics } from './metrics/index.js'
22
21
  import type { PeerId } from './peer-id/index.js'
23
22
  import type { PeerInfo } from './peer-info/index.js'
@@ -394,20 +393,6 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
394
393
  */
395
394
  contentRouting: ContentRouting
396
395
 
397
- /**
398
- * The keychain contains the keys used by the current node, and can create new
399
- * keys, export them, import them, etc.
400
- *
401
- * @example
402
- *
403
- * ```js
404
- * const keyInfo = await libp2p.keychain.createKey('new key')
405
- * console.info(keyInfo)
406
- * // { id: '...', name: 'new key' }
407
- * ```
408
- */
409
- keychain: KeyChain
410
-
411
396
  /**
412
397
  * The metrics subsystem allows recording values to assess the health/performance
413
398
  * of the running node.
@@ -624,6 +609,21 @@ export interface Libp2p<T extends ServiceMap = ServiceMap> extends Startable, Ty
624
609
  services: T
625
610
  }
626
611
 
612
+ /**
613
+ * Metadata about the current node
614
+ */
615
+ export interface NodeInfo {
616
+ /**
617
+ * The implementation name
618
+ */
619
+ name: string
620
+
621
+ /**
622
+ * The implementation version
623
+ */
624
+ version: string
625
+ }
626
+
627
627
  /**
628
628
  * An object that contains an AbortSignal as
629
629
  * the optional `signal` property.
@@ -660,3 +660,25 @@ export interface LoggerOptions {
660
660
  export type RecursivePartial<T> = {
661
661
  [P in keyof T]?: T[P] extends Array<infer I> ? Array<RecursivePartial<I>> : T[P] extends (...args: any[]) => any ? T[P] : RecursivePartial<T[P]>
662
662
  }
663
+
664
+ export * from './connection/index.js'
665
+ export * from './connection-encrypter/index.js'
666
+ export * from './connection-gater/index.js'
667
+ export * from './content-routing/index.js'
668
+ export * from './keys/index.js'
669
+ export * from './metrics/index.js'
670
+ export * from './peer-discovery/index.js'
671
+ export * from './peer-id/index.js'
672
+ export * from './peer-info/index.js'
673
+ export * from './peer-routing/index.js'
674
+ export * from './peer-store/index.js'
675
+ export * from './peer-store/tags.js'
676
+ export * from './pubsub/index.js'
677
+ export * from './record/index.js'
678
+ export * from './stream-handler/index.js'
679
+ export * from './stream-muxer/index.js'
680
+ export * from './topology/index.js'
681
+ export * from './transport/index.js'
682
+ export * from './errors.js'
683
+ export * from './events.js'
684
+ export * from './startable.js'
package/src/keys/index.ts CHANGED
@@ -1,9 +1,11 @@
1
+ import type { Uint8ArrayList } from 'uint8arraylist'
2
+
1
3
  export interface PublicKey {
2
4
  readonly bytes: Uint8Array
3
- verify(data: Uint8Array, sig: Uint8Array): Promise<boolean>
5
+ verify(data: Uint8Array | Uint8ArrayList, sig: Uint8Array): boolean | Promise<boolean>
4
6
  marshal(): Uint8Array
5
7
  equals(key: PublicKey): boolean
6
- hash(): Promise<Uint8Array>
8
+ hash(): Uint8Array | Promise<Uint8Array>
7
9
  }
8
10
 
9
11
  /**
@@ -12,10 +14,10 @@ export interface PublicKey {
12
14
  export interface PrivateKey {
13
15
  readonly public: PublicKey
14
16
  readonly bytes: Uint8Array
15
- sign(data: Uint8Array): Promise<Uint8Array>
17
+ sign(data: Uint8Array | Uint8ArrayList): Uint8Array | Promise<Uint8Array>
16
18
  marshal(): Uint8Array
17
19
  equals(key: PrivateKey): boolean
18
- hash(): Promise<Uint8Array>
20
+ hash(): Uint8Array | Promise<Uint8Array>
19
21
  /**
20
22
  * Gets the ID of the key.
21
23
  *
@@ -20,7 +20,7 @@ import type { PeerInfo } from '../peer-info/index.js'
20
20
  * }
21
21
  * ```
22
22
  */
23
- export const peerDiscovery = Symbol.for('@libp2p/peer-discovery')
23
+ export const peerDiscoverySymbol = Symbol.for('@libp2p/peer-discovery')
24
24
 
25
25
  export interface PeerDiscoveryEvents {
26
26
  'peer': CustomEvent<PeerInfo>
@@ -32,8 +32,8 @@ export interface Secp256k1PeerId extends BasePeerId {
32
32
 
33
33
  export type PeerId = RSAPeerId | Ed25519PeerId | Secp256k1PeerId
34
34
 
35
- export const symbol = Symbol.for('@libp2p/peer-id')
35
+ export const peerIdSymbol = Symbol.for('@libp2p/peer-id')
36
36
 
37
37
  export function isPeerId (other: any): other is PeerId {
38
- return other != null && Boolean(other[symbol])
38
+ return other != null && Boolean(other[peerIdSymbol])
39
39
  }
@@ -1,8 +1,20 @@
1
1
  import type { PeerId } from '../peer-id/index.js'
2
2
  import type { Multiaddr } from '@multiformats/multiaddr'
3
3
 
4
+ /**
5
+ * A `PeerInfo` is a lightweight object that represents a remote peer, it can be
6
+ * obtained from peer discovery mechanisms, HTTP RPC endpoints, etc.
7
+ *
8
+ * @see https://docs.libp2p.io/concepts/fundamentals/peers/#peer-info
9
+ */
4
10
  export interface PeerInfo {
11
+ /**
12
+ * The identifier of the remote peer
13
+ */
5
14
  id: PeerId
15
+
16
+ /**
17
+ * The multiaddrs a peer is listening on
18
+ */
6
19
  multiaddrs: Multiaddr[]
7
- protocols: string[]
8
20
  }
@@ -21,7 +21,7 @@ import type { PeerInfo } from '../peer-info/index.js'
21
21
  * }
22
22
  * ```
23
23
  */
24
- export const peerRouting = Symbol.for('@libp2p/peer-routing')
24
+ export const peerRoutingSymbol = Symbol.for('@libp2p/peer-routing')
25
25
 
26
26
  export interface PeerRouting {
27
27
  /**
package/src/startable.ts CHANGED
@@ -2,8 +2,6 @@
2
2
  * Implemented by components that have a lifecycle
3
3
  */
4
4
  export interface Startable {
5
- isStarted(): boolean
6
-
7
5
  /**
8
6
  * If implemented, this method will be invoked before the start method.
9
7
  *
@@ -51,6 +49,10 @@ export function isStartable (obj: any): obj is Startable {
51
49
  return obj != null && typeof obj.start === 'function' && typeof obj.stop === 'function'
52
50
  }
53
51
 
52
+ /**
53
+ * Start one or more {@link Startable}s, calling the `beforeStart` and
54
+ * `afterStart` lifecycle methods if defined.
55
+ */
54
56
  export async function start (...objs: any[]): Promise<void> {
55
57
  const startables: Startable[] = []
56
58
 
@@ -83,6 +85,10 @@ export async function start (...objs: any[]): Promise<void> {
83
85
  )
84
86
  }
85
87
 
88
+ /**
89
+ * Stop one or more {@link Startable}s, calling the `beforeStop` and
90
+ * `afterStop` lifecycle methods if defined.
91
+ */
86
92
  export async function stop (...objs: any[]): Promise<void> {
87
93
  const startables: Startable[] = []
88
94
 
@@ -1,6 +1,6 @@
1
1
  import type { Direction, Stream } from '../connection/index.js'
2
2
  import type { AbortOptions } from '../index.js'
3
- import type { Duplex, Source } from 'it-stream-types'
3
+ import type { Duplex } from 'it-stream-types'
4
4
  import type { Uint8ArrayList } from 'uint8arraylist'
5
5
 
6
6
  export interface StreamMuxerFactory {
@@ -18,7 +18,7 @@ export interface StreamMuxerFactory {
18
18
  /**
19
19
  * A libp2p stream muxer
20
20
  */
21
- export interface StreamMuxer extends Duplex<AsyncGenerator<Uint8Array>, Source<Uint8ArrayList | Uint8Array>, Promise<void>> {
21
+ export interface StreamMuxer extends Duplex<AsyncGenerator<Uint8Array | Uint8ArrayList>> {
22
22
  /**
23
23
  * The protocol used to select this muxer during connection opening
24
24
  */