@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.
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +3 -3
- package/dist/src/content-routing.d.ts +2 -2
- package/dist/src/content-routing.d.ts.map +1 -1
- package/dist/src/content-routing.js +1 -1
- package/dist/src/errors.d.ts +8 -1
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +11 -1
- package/dist/src/errors.js.map +1 -1
- package/dist/src/event-target.d.ts +2 -2
- package/dist/src/event-target.d.ts.map +1 -1
- package/dist/src/event-target.js +0 -1
- package/dist/src/event-target.js.map +1 -1
- package/dist/src/index.d.ts +38 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/metrics.d.ts +1 -2
- package/dist/src/metrics.d.ts.map +1 -1
- package/dist/src/peer-discovery.d.ts +5 -0
- package/dist/src/peer-discovery.d.ts.map +1 -1
- package/dist/src/peer-routing.d.ts +3 -3
- package/dist/src/peer-routing.d.ts.map +1 -1
- package/dist/src/peer-routing.js +2 -2
- package/dist/src/peer-store.d.ts +26 -0
- package/dist/src/peer-store.d.ts.map +1 -1
- package/dist/src/peer-store.js.map +1 -1
- package/dist/src/pubsub.d.ts +3 -0
- package/dist/src/pubsub.d.ts.map +1 -1
- package/dist/src/pubsub.js.map +1 -1
- package/dist/src/record.d.ts +25 -1
- package/dist/src/record.d.ts.map +1 -1
- package/dist/src/startable.d.ts +52 -1
- package/dist/src/startable.d.ts.map +1 -1
- package/dist/src/startable.js +51 -0
- package/dist/src/startable.js.map +1 -1
- package/dist/src/topology.d.ts +2 -1
- package/dist/src/topology.d.ts.map +1 -1
- package/dist/src/transport.d.ts +37 -1
- package/dist/src/transport.d.ts.map +1 -1
- package/dist/src/transport.js +3 -0
- package/dist/src/transport.js.map +1 -1
- package/dist/typedoc-urls.json +223 -0
- package/package.json +1 -1
- package/src/content-routing.ts +2 -2
- package/src/errors.ts +13 -1
- package/src/event-target.ts +2 -2
- package/src/index.ts +38 -1
- package/src/metrics.ts +1 -1
- package/src/peer-discovery.ts +5 -0
- package/src/peer-routing.ts +3 -3
- package/src/peer-store.ts +27 -0
- package/src/pubsub.ts +3 -0
- package/src/record.ts +30 -1
- package/src/startable.ts +52 -1
- package/src/topology.ts +2 -1
- 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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|