@libp2p/interface 0.0.1-6fdaa7dc

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
@@ -0,0 +1,51 @@
1
+ import type { AbortOptions } from '../index.js';
2
+ import type { PeerId } from '../peer-id/index.js';
3
+ import type { PeerInfo } from '../peer-info/index.js';
4
+ /**
5
+ * Any object that implements this Symbol as a property should return a
6
+ * PeerRouting instance as the property value, similar to how
7
+ * `Symbol.Iterable` can be used to return an `Iterable` from an `Iterator`.
8
+ *
9
+ * @example
10
+ *
11
+ * ```js
12
+ * import { peerRouting, PeerRouting } from '@libp2p/peer-routing'
13
+ *
14
+ * class MyPeerRouter implements PeerRouting {
15
+ * get [peerRouting] () {
16
+ * return this
17
+ * }
18
+ *
19
+ * // ...other methods
20
+ * }
21
+ * ```
22
+ */
23
+ export declare const peerRouting: unique symbol;
24
+ export interface PeerRouting {
25
+ /**
26
+ * Searches the network for peer info corresponding to the passed peer id.
27
+ *
28
+ * @example
29
+ *
30
+ * ```js
31
+ * // ...
32
+ * const peer = await peerRouting.findPeer(peerId, options)
33
+ * ```
34
+ */
35
+ findPeer: (peerId: PeerId, options?: AbortOptions) => Promise<PeerInfo>;
36
+ /**
37
+ * Search the network for peers that are closer to the passed key. Peer
38
+ * info should be yielded in ever-increasing closeness to the key.
39
+ *
40
+ * @example
41
+ *
42
+ * ```js
43
+ * // Iterate over the closest peers found for the given key
44
+ * for await (const peer of peerRouting.getClosestPeers(key)) {
45
+ * console.log(peer.id, peer.multiaddrs)
46
+ * }
47
+ * ```
48
+ */
49
+ getClosestPeers: (key: Uint8Array, options?: AbortOptions) => AsyncIterable<PeerInfo>;
50
+ }
51
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/peer-routing/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AACjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAErD;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,WAAW,eAAqC,CAAA;AAE7D,MAAM,WAAW,WAAW;IAC1B;;;;;;;;;OASG;IACH,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;IAEvE;;;;;;;;;;;;OAYG;IACH,eAAe,EAAE,CAAC,GAAG,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,YAAY,KAAK,aAAa,CAAC,QAAQ,CAAC,CAAA;CACtF"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Any object that implements this Symbol as a property should return a
3
+ * PeerRouting instance as the property value, similar to how
4
+ * `Symbol.Iterable` can be used to return an `Iterable` from an `Iterator`.
5
+ *
6
+ * @example
7
+ *
8
+ * ```js
9
+ * import { peerRouting, PeerRouting } from '@libp2p/peer-routing'
10
+ *
11
+ * class MyPeerRouter implements PeerRouting {
12
+ * get [peerRouting] () {
13
+ * return this
14
+ * }
15
+ *
16
+ * // ...other methods
17
+ * }
18
+ * ```
19
+ */
20
+ export const peerRouting = Symbol.for('@libp2p/peer-routing');
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/peer-routing/index.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAA"}
@@ -0,0 +1,247 @@
1
+ import type { PeerId } from '../peer-id/index.js';
2
+ import type { Multiaddr } from '@multiformats/multiaddr';
3
+ /**
4
+ * A multiaddr with an optional flag that indicates if its trustworthy
5
+ */
6
+ export interface Address {
7
+ /**
8
+ * Peer multiaddr
9
+ */
10
+ multiaddr: Multiaddr;
11
+ /**
12
+ * Obtained from a signed peer record
13
+ */
14
+ isCertified: boolean;
15
+ }
16
+ /**
17
+ * Data stored in the peer store about peers
18
+ */
19
+ export interface Peer {
20
+ /**
21
+ * Peer's peer-id instance
22
+ */
23
+ id: PeerId;
24
+ /**
25
+ * Peer's addresses containing a list of multiaddrs and a isCertified field
26
+ * indicating if the address was loaded from a signed peer record or not
27
+ */
28
+ addresses: Address[];
29
+ /**
30
+ * Peer's supported protocols
31
+ */
32
+ protocols: string[];
33
+ /**
34
+ * Peer's metadata map
35
+ */
36
+ metadata: Map<string, Uint8Array>;
37
+ /**
38
+ * Tags a peer has
39
+ */
40
+ tags: Map<string, Tag>;
41
+ /**
42
+ * The last peer record envelope received
43
+ */
44
+ peerRecordEnvelope?: Uint8Array;
45
+ }
46
+ /**
47
+ * Peer data used to update the peer store
48
+ */
49
+ export interface PeerData {
50
+ /**
51
+ * Peer's addresses containing its multiaddrs and metadata - multiaddrs
52
+ * passed here can be treated as certified if the `isCertifed` value is
53
+ * set to true.
54
+ *
55
+ * If both addresses and multiaddrs are specified they will be merged
56
+ * together with entries in addresses taking precedence.
57
+ */
58
+ addresses?: Address[];
59
+ /**
60
+ * Peer's multiaddrs - any multiaddrs passed here will be treated as
61
+ * uncertified.
62
+ *
63
+ * If both addresses and multiaddrs are specified they will be merged
64
+ * together with entries in addresses taking precedence.
65
+ */
66
+ multiaddrs?: Multiaddr[];
67
+ /**
68
+ * Peer's supported protocols
69
+ */
70
+ protocols?: string[];
71
+ /**
72
+ * Peer's metadata map. When merging pass undefined as values to remove metadata.
73
+ */
74
+ metadata?: Map<string, Uint8Array | undefined> | Record<string, Uint8Array | undefined>;
75
+ /**
76
+ * Peer tags. When merging pass undefined as values to remove tags.
77
+ */
78
+ tags?: Map<string, TagOptions | undefined> | Record<string, TagOptions | undefined>;
79
+ /**
80
+ * If this Peer has an RSA key, it's public key can be set with this property
81
+ */
82
+ publicKey?: Uint8Array;
83
+ /**
84
+ * The last peer record envelope received
85
+ */
86
+ peerRecordEnvelope?: Uint8Array;
87
+ }
88
+ export interface TagOptions {
89
+ /**
90
+ * An optional tag value (1-100)
91
+ */
92
+ value?: number;
93
+ /**
94
+ * An optional duration in ms after which the tag will expire
95
+ */
96
+ ttl?: number;
97
+ }
98
+ export interface Tag {
99
+ /**
100
+ * The tag value
101
+ */
102
+ value: number;
103
+ }
104
+ /**
105
+ * A predicate by which to filter lists of peers
106
+ */
107
+ export interface PeerQueryFilter {
108
+ (peer: Peer): boolean;
109
+ }
110
+ /**
111
+ * A predicate by which to sort lists of peers
112
+ */
113
+ export interface PeerQueryOrder {
114
+ (a: Peer, b: Peer): -1 | 0 | 1;
115
+ }
116
+ /**
117
+ * A query for getting lists of peers
118
+ */
119
+ export interface PeerQuery {
120
+ filters?: PeerQueryFilter[];
121
+ orders?: PeerQueryOrder[];
122
+ limit?: number;
123
+ offset?: number;
124
+ }
125
+ export interface PeerStore {
126
+ /**
127
+ * Loop over every peer - the looping is async because we read from a
128
+ * datastore but the peer operation is sync, this is to prevent
129
+ * long-lived peer operations causing deadlocks over the datastore
130
+ * which can happen if they try to access the peer store during the
131
+ * loop
132
+ *
133
+ * @example
134
+ *
135
+ * ```js
136
+ * await peerStore.forEach(peer => {
137
+ * // ...
138
+ * })
139
+ * ```
140
+ */
141
+ forEach: (fn: (peer: Peer) => void, query?: PeerQuery) => Promise<void>;
142
+ /**
143
+ * Returns all peers in the peer store.
144
+ *
145
+ * @example
146
+ *
147
+ * ```js
148
+ * for (const peer of await peerStore.all()) {
149
+ * // ...
150
+ * }
151
+ * ```
152
+ */
153
+ all: (query?: PeerQuery) => Promise<Peer[]>;
154
+ /**
155
+ * Delete all data stored for the passed peer
156
+ *
157
+ * @example
158
+ *
159
+ * ```js
160
+ * await peerStore.addressBook.set(peerId, multiaddrs)
161
+ * await peerStore.addressBook.get(peerId)
162
+ * // multiaddrs[]
163
+ *
164
+ * await peerStore.delete(peerId)
165
+ *
166
+ * await peerStore.addressBook.get(peerId)
167
+ * // []
168
+ * ```
169
+ */
170
+ delete: (peerId: PeerId) => Promise<void>;
171
+ /**
172
+ * Returns true if the passed PeerId is in the peer store
173
+ *
174
+ * @example
175
+ *
176
+ * ```js
177
+ * await peerStore.has(peerId)
178
+ * // false
179
+ * await peerStore.addressBook.add(peerId, multiaddrs)
180
+ * await peerStore.has(peerId)
181
+ * // true
182
+ * ```
183
+ */
184
+ has: (peerId: PeerId) => Promise<boolean>;
185
+ /**
186
+ * Returns all data stored for the passed PeerId
187
+ *
188
+ * @example
189
+ *
190
+ * ```js
191
+ * const peer = await peerStore.get(peerId)
192
+ * // { .. }
193
+ * ```
194
+ */
195
+ get: (peerId: PeerId) => Promise<Peer>;
196
+ /**
197
+ * Adds a peer to the peer store, overwriting any existing data
198
+ *
199
+ * @example
200
+ *
201
+ * ```js
202
+ * await peerStore.save(peerId, {
203
+ * multiaddrs
204
+ * })
205
+ * ```
206
+ */
207
+ save: (id: PeerId, data: PeerData) => Promise<Peer>;
208
+ /**
209
+ * Adds a peer to the peer store, overwriting only the passed fields
210
+ *
211
+ * @example
212
+ *
213
+ * ```js
214
+ * await peerStore.patch(peerId, {
215
+ * multiaddrs
216
+ * })
217
+ * ```
218
+ */
219
+ patch: (id: PeerId, data: PeerData) => Promise<Peer>;
220
+ /**
221
+ * Adds a peer to the peer store, deeply merging any existing data.
222
+ *
223
+ * @example
224
+ *
225
+ * ```js
226
+ * await peerStore.merge(peerId, {
227
+ * multiaddrs
228
+ * })
229
+ * ```
230
+ */
231
+ merge: (id: PeerId, data: PeerData) => Promise<Peer>;
232
+ /**
233
+ * Unmarshal and verify a signed peer record, extract the multiaddrs and
234
+ * overwrite the stored addresses for the peer.
235
+ *
236
+ * Optionally pass an expected PeerId to verify that the peer record was
237
+ * signed by that peer.
238
+ *
239
+ * @example
240
+ *
241
+ * ```js
242
+ * await peerStore.consumePeerRecord(buf, expectedPeer)
243
+ * ```
244
+ */
245
+ consumePeerRecord: (buf: Uint8Array, expectedPeer?: PeerId) => Promise<boolean>;
246
+ }
247
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/peer-store/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAExD;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB;;OAEG;IACH,SAAS,EAAE,SAAS,CAAA;IAEpB;;OAEG;IACH,WAAW,EAAE,OAAO,CAAA;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,IAAI;IACnB;;OAEG;IACH,EAAE,EAAE,MAAM,CAAA;IAEV;;;OAGG;IACH,SAAS,EAAE,OAAO,EAAE,CAAA;IAEpB;;OAEG;IACH,SAAS,EAAE,MAAM,EAAE,CAAA;IAEnB;;OAEG;IACH,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;IAEjC;;OAEG;IACH,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAEtB;;OAEG;IACH,kBAAkB,CAAC,EAAE,UAAU,CAAA;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB;;;;;;;OAOG;IACH,SAAS,CAAC,EAAE,OAAO,EAAE,CAAA;IAErB;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,SAAS,EAAE,CAAA;IAExB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;IAEpB;;OAEG;IACH,QAAQ,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,GAAG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AI,EAAE,CAAC,CAAA;IAE3C;;;;;;;;;;;;;;;OAeG;IACH,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAEzC;;;;;;;;;;;;OAYG;IACH,GAAG,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;IAEzC;;;;;;;;;OASG;IACH,GAAG,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAEtC;;;;;;;;;;OAUG;IACH,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAEnD;;;;;;;;;;OAUG;IACH,KAAK,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAEpD;;;;;;;;;;OAUG;IACH,KAAK,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAEpD;;;;;;;;;;;;OAYG;IACH,iBAAiB,EAAE,CAAC,GAAG,EAAE,UAAU,EAAE,YAAY,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;CAChF"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/peer-store/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export declare const KEEP_ALIVE = "keep-alive";
2
+ //# sourceMappingURL=tags.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tags.d.ts","sourceRoot":"","sources":["../../../src/peer-store/tags.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,UAAU,eAAe,CAAA"}
@@ -0,0 +1,2 @@
1
+ export const KEEP_ALIVE = 'keep-alive';
2
+ //# sourceMappingURL=tags.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tags.js","sourceRoot":"","sources":["../../../src/peer-store/tags.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,UAAU,GAAG,YAAY,CAAA"}
@@ -0,0 +1,33 @@
1
+ import type { PeerId } from '../peer-id/index.js';
2
+ import type { Uint8ArrayList } from 'uint8arraylist';
3
+ /**
4
+ * Record is the base implementation of a record that can be used as the payload of a libp2p envelope.
5
+ */
6
+ export interface Record {
7
+ /**
8
+ * signature domain.
9
+ */
10
+ domain: string;
11
+ /**
12
+ * identifier of the type of record
13
+ */
14
+ codec: Uint8Array;
15
+ /**
16
+ * Marshal a record to be used in an envelope.
17
+ */
18
+ marshal: () => Uint8Array;
19
+ /**
20
+ * Verifies if the other provided Record is identical to this one.
21
+ */
22
+ equals: (other: Record) => boolean;
23
+ }
24
+ export interface Envelope {
25
+ peerId: PeerId;
26
+ payloadType: Uint8Array | Uint8ArrayList;
27
+ payload: Uint8Array;
28
+ signature: Uint8Array | Uint8ArrayList;
29
+ marshal: () => Uint8Array;
30
+ validate: (domain: string) => Promise<boolean>;
31
+ equals: (other: Envelope) => boolean;
32
+ }
33
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/record/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAA;IACd;;OAEG;IACH,KAAK,EAAE,UAAU,CAAA;IACjB;;OAEG;IACH,OAAO,EAAE,MAAM,UAAU,CAAA;IACzB;;OAEG;IACH,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAA;CACnC;AAED,MAAM,WAAW,QAAQ;IACvB,MAAM,EAAE,MAAM,CAAA;IACd,WAAW,EAAE,UAAU,GAAG,cAAc,CAAA;IACxC,OAAO,EAAE,UAAU,CAAA;IACnB,SAAS,EAAE,UAAU,GAAG,cAAc,CAAA;IAEtC,OAAO,EAAE,MAAM,UAAU,CAAA;IACzB,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;IAC9C,MAAM,EAAE,CAAC,KAAK,EAAE,QAAQ,KAAK,OAAO,CAAA;CACrC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/record/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Implemented by components that have a lifecycle
3
+ */
4
+ export interface Startable {
5
+ isStarted: () => boolean;
6
+ /**
7
+ * If implemented, this method will be invoked before the start method.
8
+ *
9
+ * It should not assume any other components have been started.
10
+ */
11
+ beforeStart?: () => void | Promise<void>;
12
+ /**
13
+ * This method will be invoked to start the component.
14
+ *
15
+ * It should not assume that any other components have been started.
16
+ */
17
+ start: () => void | Promise<void>;
18
+ /**
19
+ * If implemented, this method will be invoked after the start method.
20
+ *
21
+ * All other components will have had their start method invoked before this method is called.
22
+ */
23
+ afterStart?: () => void | Promise<void>;
24
+ /**
25
+ * If implemented, this method will be invoked before the stop method.
26
+ *
27
+ * Any other components will still be running when this method is called.
28
+ */
29
+ beforeStop?: () => void | Promise<void>;
30
+ /**
31
+ * This method will be invoked to stop the component.
32
+ *
33
+ * It should not assume any other components are running when it is called.
34
+ */
35
+ stop: () => void | Promise<void>;
36
+ /**
37
+ * If implemented, this method will be invoked after the stop method.
38
+ *
39
+ * All other components will have had their stop method invoked before this method is called.
40
+ */
41
+ afterStop?: () => void | Promise<void>;
42
+ }
43
+ export declare function isStartable(obj: any): obj is Startable;
44
+ export declare function start(...objs: any[]): Promise<void>;
45
+ export declare function stop(...objs: any[]): Promise<void>;
46
+ //# sourceMappingURL=startable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"startable.d.ts","sourceRoot":"","sources":["../../src/startable.ts"],"names":[],"mappings":"AACA;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,SAAS,EAAE,MAAM,OAAO,CAAA;IAExB;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAExC;;;;OAIG;IACH,KAAK,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAEjC;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAEvC;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAEvC;;;;OAIG;IACH,IAAI,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAEhC;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACvC;AAED,wBAAgB,WAAW,CAAE,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,SAAS,CAEvD;AAED,wBAAsB,KAAK,CAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CA8B1D;AAED,wBAAsB,IAAI,CAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CA8BzD"}
@@ -0,0 +1,46 @@
1
+ export function isStartable(obj) {
2
+ return obj != null && typeof obj.start === 'function' && typeof obj.stop === 'function';
3
+ }
4
+ export async function start(...objs) {
5
+ const startables = [];
6
+ for (const obj of objs) {
7
+ if (isStartable(obj)) {
8
+ startables.push(obj);
9
+ }
10
+ }
11
+ await Promise.all(startables.map(async (s) => {
12
+ if (s.beforeStart != null) {
13
+ await s.beforeStart();
14
+ }
15
+ }));
16
+ await Promise.all(startables.map(async (s) => {
17
+ await s.start();
18
+ }));
19
+ await Promise.all(startables.map(async (s) => {
20
+ if (s.afterStart != null) {
21
+ await s.afterStart();
22
+ }
23
+ }));
24
+ }
25
+ export async function stop(...objs) {
26
+ const startables = [];
27
+ for (const obj of objs) {
28
+ if (isStartable(obj)) {
29
+ startables.push(obj);
30
+ }
31
+ }
32
+ await Promise.all(startables.map(async (s) => {
33
+ if (s.beforeStop != null) {
34
+ await s.beforeStop();
35
+ }
36
+ }));
37
+ await Promise.all(startables.map(async (s) => {
38
+ await s.stop();
39
+ }));
40
+ await Promise.all(startables.map(async (s) => {
41
+ if (s.afterStop != null) {
42
+ await s.afterStop();
43
+ }
44
+ }));
45
+ }
46
+ //# sourceMappingURL=startable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"startable.js","sourceRoot":"","sources":["../../src/startable.ts"],"names":[],"mappings":"AAkDA,MAAM,UAAU,WAAW,CAAE,GAAQ;IACnC,OAAO,GAAG,IAAI,IAAI,IAAI,OAAO,GAAG,CAAC,KAAK,KAAK,UAAU,IAAI,OAAO,GAAG,CAAC,IAAI,KAAK,UAAU,CAAA;AACzF,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,KAAK,CAAE,GAAG,IAAW;IACzC,MAAM,UAAU,GAAgB,EAAE,CAAA;IAElC,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE;QACtB,IAAI,WAAW,CAAC,GAAG,CAAC,EAAE;YACpB,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;SACrB;KACF;IAED,MAAM,OAAO,CAAC,GAAG,CACf,UAAU,CAAC,GAAG,CAAC,KAAK,EAAC,CAAC,EAAC,EAAE;QACvB,IAAI,CAAC,CAAC,WAAW,IAAI,IAAI,EAAE;YACzB,MAAM,CAAC,CAAC,WAAW,EAAE,CAAA;SACtB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AAC"}
@@ -0,0 +1,23 @@
1
+ import type { Connection, Stream } from '../connection/index.js';
2
+ export interface IncomingStreamData {
3
+ stream: Stream;
4
+ connection: Connection;
5
+ }
6
+ export interface StreamHandler {
7
+ (data: IncomingStreamData): void;
8
+ }
9
+ export interface StreamHandlerOptions {
10
+ /**
11
+ * How many incoming streams can be open for this protocol at the same time on each connection (default: 32)
12
+ */
13
+ maxInboundStreams?: number;
14
+ /**
15
+ * How many outgoing streams can be open for this protocol at the same time on each connection (default: 64)
16
+ */
17
+ maxOutboundStreams?: number;
18
+ }
19
+ export interface StreamHandlerRecord {
20
+ handler: StreamHandler;
21
+ options: StreamHandlerOptions;
22
+ }
23
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/stream-handler/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAEhE,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,UAAU,CAAA;CACvB;AAED,MAAM,WAAW,aAAa;IAC5B,CAAC,IAAI,EAAE,kBAAkB,GAAG,IAAI,CAAA;CACjC;AAED,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAE1B;;OAEG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAA;CAC5B;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,aAAa,CAAA;IACtB,OAAO,EAAE,oBAAoB,CAAA;CAC9B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/stream-handler/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,51 @@
1
+ import type { Direction, Stream } from '../connection/index.js';
2
+ import type { AbortOptions } from '../index.js';
3
+ import type { Duplex, Source } from 'it-stream-types';
4
+ import type { Uint8ArrayList } from 'uint8arraylist';
5
+ export interface StreamMuxerFactory {
6
+ /**
7
+ * The protocol used to select this muxer during connection opening
8
+ */
9
+ protocol: string;
10
+ /**
11
+ * Creates a new stream muxer to be used with a new connection
12
+ */
13
+ createStreamMuxer: (init?: StreamMuxerInit) => StreamMuxer;
14
+ }
15
+ /**
16
+ * A libp2p stream muxer
17
+ */
18
+ export interface StreamMuxer extends Duplex<AsyncGenerator<Uint8Array>, Source<Uint8ArrayList | Uint8Array>, Promise<void>> {
19
+ /**
20
+ * The protocol used to select this muxer during connection opening
21
+ */
22
+ protocol: string;
23
+ /**
24
+ * A list of streams that are currently open. Closed streams will not be returned.
25
+ */
26
+ readonly streams: Stream[];
27
+ /**
28
+ * Initiate a new stream with the given name. If no name is
29
+ * provided, the id of the stream will be used.
30
+ */
31
+ newStream: (name?: string) => Stream | Promise<Stream>;
32
+ /**
33
+ * Close or abort all tracked streams and stop the muxer
34
+ */
35
+ close: (err?: Error) => void;
36
+ }
37
+ export interface StreamMuxerInit extends AbortOptions {
38
+ /**
39
+ * A callback function invoked every time an incoming stream is opened
40
+ */
41
+ onIncomingStream?: (stream: Stream) => void;
42
+ /**
43
+ * A callback function invoke every time a stream ends
44
+ */
45
+ onStreamEnd?: (stream: Stream) => void;
46
+ /**
47
+ * Outbound stream muxers are opened by the local node, inbound stream muxers are opened by the remote
48
+ */
49
+ direction?: Direction;
50
+ }
51
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/stream-muxer/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAA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