swarm-pubsub 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2026, Cafe137
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md CHANGED
@@ -1,3 +1,145 @@
1
- # Temporary Holding Version
1
+ # swarm-pubsub
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Publish and receive [Swarm](https://www.ethswarm.org) pubsub messages straight from the browser. There is no local Bee node: the library connects to a broker node over libp2p and speaks the BPS protocol itself.
4
+
5
+ It works with channels from bee-js and [`sample-bps`](https://github.com/slapec93/sample-bps): the chunks are byte-for-byte identical.
6
+
7
+ ## Quick start
8
+
9
+ ```ts
10
+ import { addressFromPrivateKey, connect, generatePrivateKey } from 'swarm-pubsub'
11
+
12
+ const broker = await connect('/dns4/broker.example.com/tcp/443/tls/ws/p2p/Qm...')
13
+
14
+ const key = generatePrivateKey()
15
+ const channel = await broker.publish('my-room', key)
16
+ await channel.send('hello swarm')
17
+ ```
18
+
19
+ Anyone can listen, and needs no key. Listeners connect on their own, so run this in another tab or on another machine:
20
+
21
+ ```ts
22
+ const broker = await connect('/dns4/broker.example.com/tcp/443/tls/ws/p2p/Qm...')
23
+
24
+ const owner = addressFromPrivateKey(key)
25
+ await broker.subscribe(owner, 'my-room', {
26
+ onMessage: message => console.log(message.publisher, message.text()),
27
+ })
28
+ ```
29
+
30
+ A channel is identified by its **owner address** and **topic**.
31
+
32
+ ## API
33
+
34
+ ### `connect(address, options?)`
35
+
36
+ Opens a connection to a broker and returns a `Broker`. `address` is a multiaddr; include `/p2p/<peer id>` so the library verifies it reached the right node. In a browser it must be `wss` (`/tls/ws`), except on `localhost`.
37
+
38
+ | Option | Default | Meaning |
39
+ | ------------ | -------------- | -------------------------------------------------------- |
40
+ | `networkId` | `1n` (mainnet) | Swarm network id |
41
+ | `transports` | WebSockets | libp2p transports, such as `[tcp()]` in Node |
42
+
43
+ ### `broker.publish(topic, privateKey, options?)`
44
+
45
+ Resolves with a `Publisher` once it may publish. Topics are hashed the same way as bee-js `Topic.fromString`, or pass 32 raw bytes.
46
+
47
+ Without `owner` you own the channel. With `owner`, you take a **seat**: the promise stays pending until the owner adds your address to the roster, so use `signal` to give up.
48
+
49
+ | Option | Default | Meaning |
50
+ | ----------------- | --------------- | --------------------------------------------------------- |
51
+ | `owner` | your address | Channel to join as a seat |
52
+ | `index` | `Date.now()` | First message index. It must exceed every index used before |
53
+ | `rosterIndex` | `Date.now()` | First roster index, with the same rule |
54
+ | `heartbeatMillis` | `60000` | Keepalive. The broker drops channels idle for 10 minutes |
55
+ | `signal` | | `AbortSignal` that stops waiting for a seat |
56
+ | `onMessage`, `onRoster`, `onClose` | | See below |
57
+
58
+ | `Publisher` | |
59
+ | ---------------------------- | ------------------------------------------------------------- |
60
+ | `send(data)` | Sends a string or bytes, up to 4096 bytes. Resolves with the index |
61
+ | `setRoster(addresses)` | Owner only. Replaces all seats, up to 186 |
62
+ | `end()` | Owner only. Ends the channel for everyone |
63
+ | `close()` | Leaves without ending the channel |
64
+ | `closed` | Promise of the `CloseEvent` |
65
+ | `position`, `address` | Current position and your address |
66
+
67
+ You don't receive your own messages back.
68
+
69
+ ### `broker.subscribe(owner, topic, options?)`
70
+
71
+ Resolves with a `Subscription` that has `close()`, `closed` and `position`. Options are `onMessage`, `onRoster`, `onClose` and `position`.
72
+
73
+ - `onMessage({ publisher, index, payload, text() })`
74
+ - `onRoster(addresses)`: the owner is not listed
75
+ - `onClose({ ended, error })`: `ended` means the owner ended the channel; `error` is set when something went wrong
76
+
77
+ **Reconnecting.** A connection can drop at any time. Pass the old position to continue without duplicates:
78
+
79
+ ```ts
80
+ async function listen(position) {
81
+ const subscription = await broker.subscribe(owner, topic, {
82
+ ...(position ? { position } : {}),
83
+ onMessage,
84
+ onClose: event => {
85
+ if (!event.ended) setTimeout(() => listen(subscription.position), 3000)
86
+ },
87
+ })
88
+ }
89
+ ```
90
+
91
+ If the broker connection itself dropped, call `connect` again first. See `examples/chat/main.ts`.
92
+
93
+ ### `broker.close()`
94
+
95
+ Closes every channel and the connection.
96
+
97
+ ### Keys
98
+
99
+ `generatePrivateKey()` returns a new hex key. `addressFromPrivateKey(key)` returns its address. Keys need no funds and are not a Bee wallet.
100
+
101
+ ## Good to know
102
+
103
+ - **Messages are public.** Anyone who knows the owner and topic can read them. Encrypt sensitive payloads yourself.
104
+ - **Messages are live only.** Nothing is stored; a new subscriber sees messages sent after it joined, plus the current roster.
105
+ - **Delivery isn't guaranteed.** A subscriber that falls behind is disconnected by the broker, and messages sent while it reconnects are lost.
106
+ - **Ordering** holds per publisher, not across publishers.
107
+ - **Every delivery is verified.** Signatures are checked against the owner and roster, so a broker can drop messages but can't forge them. A forged delivery closes the channel with an `error`.
108
+ - **Web Crypto is required**, so pages must be served from `https://` or `localhost`.
109
+
110
+ ## Chat example
111
+
112
+ The chat recreates `sample-bps` in the browser: rooms, seats, `/roster`, `/end` and `/quit`.
113
+
114
+ ```sh
115
+ npm install
116
+ npm run chat
117
+ ```
118
+
119
+ Open the printed URL. The default broker is `/dns4/broker.hiveway.xyz/tcp/443/tls/ws/p2p/QmSjaR7gK8jmVvU6kfH5n2vDj9yjDkN9rXCddtBcDdm844`.
120
+
121
+ To try a broker with no `wss://` endpoint from `localhost`, run the development bridge and use `/ip4/127.0.0.1/tcp/1636/ws/p2p/<peer id>`. Set `BROKER_HOST` and `BROKER_PORT` to choose the broker:
122
+
123
+ ```sh
124
+ npm run bridge
125
+ ```
126
+
127
+ ## Broker requirements
128
+
129
+ The broker is a Bee node built from [bee#5626](https://github.com/ethersphere/bee/pull/5626), started with `bps-broker: true`. Browsers also need a `wss://` endpoint with a certificate they trust. [DESIGN.md](DESIGN.md) describes the two ways to set that up.
130
+
131
+ ## Development
132
+
133
+ ```sh
134
+ npm install # also applies patches/ to libp2p
135
+ npm run typecheck
136
+ npm test
137
+ npm run test:live # against the real broker
138
+ npm run build
139
+ ```
140
+
141
+ `dist/index.js` bundles libp2p, including the patches in `patches/`, so users of the package need nothing extra.
142
+
143
+ ## License
144
+
145
+ [BSD-3-Clause](LICENSE)
@@ -0,0 +1,431 @@
1
+ # Licenses
2
+
3
+ The app bundles dependencies which contain the following licenses:
4
+
5
+ ## @chainsafe/is-ip - 2.1.0 (MIT)
6
+
7
+ Copyright © 2022 ChainSafe Systems
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
14
+
15
+ ## @chainsafe/libp2p-noise - 17.0.0 (Apache-2.0 OR MIT)
16
+
17
+ ## @chainsafe/libp2p-yamux - 8.0.1 (Apache-2.0 OR MIT)
18
+
19
+ ## @chainsafe/netmask - 2.0.0 (MIT)
20
+
21
+ Copyright (c) 2023 Chainsafe Systems Inc.
22
+
23
+ Permission is hereby granted, free of charge, to any person obtaining
24
+ a copy of this software and associated documentation files (the
25
+ "Software"), to deal in the Software without restriction, including
26
+ without limitation the rights to use, copy, modify, merge, publish,
27
+ distribute, sublicense, and/or sell copies of the Software, and to
28
+ permit persons to whom the Software is furnished to do so, subject to
29
+ the following conditions:
30
+
31
+ The above copyright notice and this permission notice shall be
32
+ included in all copies or substantial portions of the Software.
33
+
34
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
35
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
36
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
37
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
38
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
39
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
40
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
41
+
42
+ ## @libp2p/crypto - 5.2.0 (Apache-2.0 OR MIT)
43
+
44
+ ## @libp2p/identify - 4.1.18 (Apache-2.0 OR MIT)
45
+
46
+ ## @libp2p/interface - 3.4.0 (Apache-2.0 OR MIT)
47
+
48
+ ## @libp2p/logger - 6.2.16 (Apache-2.0 OR MIT)
49
+
50
+ ## @libp2p/multistream-select - 7.0.32 (Apache-2.0 OR MIT)
51
+
52
+ ## @libp2p/peer-collections - 7.0.32 (Apache-2.0 OR MIT)
53
+
54
+ ## @libp2p/peer-id - 6.0.18 (Apache-2.0 OR MIT)
55
+
56
+ ## @libp2p/peer-record - 9.0.19 (Apache-2.0 OR MIT)
57
+
58
+ ## @libp2p/peer-store - 12.0.32 (Apache-2.0 OR MIT)
59
+
60
+ ## @libp2p/utils - 7.4.5 (Apache-2.0 OR MIT)
61
+
62
+ ## @libp2p/websockets - 10.1.25 (Apache-2.0 OR MIT)
63
+
64
+ ## @multiformats/dns - 1.0.15 (Apache-2.0 OR MIT)
65
+
66
+ ## @multiformats/multiaddr-matcher - 3.0.2 (Apache-2.0 OR MIT)
67
+
68
+ ## @multiformats/multiaddr-to-uri - 12.0.0 (Apache-2.0 OR MIT)
69
+
70
+ ## @multiformats/multiaddr - 13.0.3 (Apache-2.0 OR MIT)
71
+
72
+ ## @noble/ciphers - 2.4.0 (MIT)
73
+
74
+ The MIT License (MIT)
75
+
76
+ Copyright (c) 2022 Paul Miller (https://paulmillr.com)
77
+ Copyright (c) 2016 Thomas Pornin <pornin@bolet.org>
78
+
79
+ Permission is hereby granted, free of charge, to any person obtaining a copy
80
+ of this software and associated documentation files (the “Software”), to deal
81
+ in the Software without restriction, including without limitation the rights
82
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
83
+ copies of the Software, and to permit persons to whom the Software is
84
+ furnished to do so, subject to the following conditions:
85
+
86
+ The above copyright notice and this permission notice shall be included in
87
+ all copies or substantial portions of the Software.
88
+
89
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
90
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
91
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
92
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
93
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
94
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
95
+ THE SOFTWARE.
96
+
97
+ ## @noble/curves - 2.4.0 (MIT)
98
+
99
+ The MIT License (MIT)
100
+
101
+ Copyright (c) 2022 Paul Miller (https://paulmillr.com)
102
+
103
+ Permission is hereby granted, free of charge, to any person obtaining a copy
104
+ of this software and associated documentation files (the “Software”), to deal
105
+ in the Software without restriction, including without limitation the rights
106
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
107
+ copies of the Software, and to permit persons to whom the Software is
108
+ furnished to do so, subject to the following conditions:
109
+
110
+ The above copyright notice and this permission notice shall be included in
111
+ all copies or substantial portions of the Software.
112
+
113
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
114
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
115
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
116
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
117
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
118
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
119
+ THE SOFTWARE.
120
+
121
+ ## @noble/hashes - 2.4.0 (MIT)
122
+
123
+ The MIT License (MIT)
124
+
125
+ Copyright (c) 2022 Paul Miller (https://paulmillr.com)
126
+
127
+ Permission is hereby granted, free of charge, to any person obtaining a copy
128
+ of this software and associated documentation files (the “Software”), to deal
129
+ in the Software without restriction, including without limitation the rights
130
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
131
+ copies of the Software, and to permit persons to whom the Software is
132
+ furnished to do so, subject to the following conditions:
133
+
134
+ The above copyright notice and this permission notice shall be included in
135
+ all copies or substantial portions of the Software.
136
+
137
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
138
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
139
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
140
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
141
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
142
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
143
+ THE SOFTWARE.
144
+
145
+ ## @sindresorhus/fnv1a - 3.1.0 (MIT)
146
+
147
+ MIT License
148
+
149
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
150
+
151
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
152
+
153
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
154
+
155
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
156
+
157
+ ## abort-error - 1.0.2 (Apache-2.0 OR MIT)
158
+
159
+ ## any-signal - 4.2.0 (Apache-2.0 OR MIT)
160
+
161
+ ## datastore-core - 12.0.1 (Apache-2.0 OR MIT)
162
+
163
+ ## eventemitter3 - 5.0.4 (MIT)
164
+
165
+ The MIT License (MIT)
166
+
167
+ Copyright (c) 2014 Arnout Kazemier
168
+
169
+ Permission is hereby granted, free of charge, to any person obtaining a copy
170
+ of this software and associated documentation files (the "Software"), to deal
171
+ in the Software without restriction, including without limitation the rights
172
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
173
+ copies of the Software, and to permit persons to whom the Software is
174
+ furnished to do so, subject to the following conditions:
175
+
176
+ The above copyright notice and this permission notice shall be included in all
177
+ copies or substantial portions of the Software.
178
+
179
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
180
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
181
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
182
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
183
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
184
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
185
+ SOFTWARE.
186
+
187
+ ## hashlru - 2.3.0 (MIT)
188
+
189
+ Copyright (c) 2016 'Dominic Tarr'
190
+
191
+ Permission is hereby granted, free of charge,
192
+ to any person obtaining a copy of this software and
193
+ associated documentation files (the "Software"), to
194
+ deal in the Software without restriction, including
195
+ without limitation the rights to use, copy, modify,
196
+ merge, publish, distribute, sublicense, and/or sell
197
+ copies of the Software, and to permit persons to whom
198
+ the Software is furnished to do so,
199
+ subject to the following conditions:
200
+
201
+ The above copyright notice and this permission notice
202
+ shall be included in all copies or substantial portions of the Software.
203
+
204
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
205
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
206
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
207
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
208
+ ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
209
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
210
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
211
+
212
+ ## interface-datastore - 10.0.1 (Apache-2.0 OR MIT)
213
+
214
+ ## interface-store - 8.0.0 (Apache-2.0 OR MIT)
215
+
216
+ ## is-loopback-addr - 2.1.0 (MIT)
217
+
218
+ MIT License
219
+
220
+ Copyright (c) 2020 Vasco Santos
221
+
222
+ Permission is hereby granted, free of charge, to any person obtaining a copy
223
+ of this software and associated documentation files (the "Software"), to deal
224
+ in the Software without restriction, including without limitation the rights
225
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
226
+ copies of the Software, and to permit persons to whom the Software is
227
+ furnished to do so, subject to the following conditions:
228
+
229
+ The above copyright notice and this permission notice shall be included in all
230
+ copies or substantial portions of the Software.
231
+
232
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
233
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
234
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
235
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
236
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
237
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
238
+ SOFTWARE.
239
+
240
+ ## is-network-error - 1.3.2 (MIT)
241
+
242
+ MIT License
243
+
244
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
245
+
246
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
247
+
248
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
249
+
250
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
251
+
252
+ ## it-all - 3.0.11 (Apache-2.0 OR MIT)
253
+
254
+ ## it-drain - 3.0.12 (Apache-2.0 OR MIT)
255
+
256
+ ## it-filter - 3.1.6 (Apache-2.0 OR MIT)
257
+
258
+ ## it-length-prefixed - 11.0.1 (Apache-2.0 OR MIT)
259
+
260
+ ## it-merge - 3.0.15 (Apache-2.0 OR MIT)
261
+
262
+ ## it-parallel - 3.0.16 (Apache-2.0 OR MIT)
263
+
264
+ ## it-peekable - 3.0.10 (Apache-2.0 OR MIT)
265
+
266
+ ## it-pushable - 3.2.4 (Apache-2.0 OR MIT)
267
+
268
+ ## it-queue - 1.1.4 (Apache-2.0 OR MIT)
269
+
270
+ ## it-queueless-pushable - 2.0.5 (Apache-2.0 OR MIT)
271
+
272
+ ## it-sort - 3.0.11 (Apache-2.0 OR MIT)
273
+
274
+ ## it-take - 3.0.11 (Apache-2.0 OR MIT)
275
+
276
+ ## libp2p - 3.5.1 (Apache-2.0 OR MIT)
277
+
278
+ ## main-event - 1.0.5 (Apache-2.0 OR MIT)
279
+
280
+ ## mortice - 3.3.1 (Apache-2.0 OR MIT)
281
+
282
+ ## ms - 4.0.0-nightly.202508271359 (MIT)
283
+
284
+ The MIT License (MIT)
285
+
286
+ Copyright (c) 2025 Vercel, Inc.
287
+
288
+ Permission is hereby granted, free of charge, to any person obtaining a copy
289
+ of this software and associated documentation files (the "Software"), to deal
290
+ in the Software without restriction, including without limitation the rights
291
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
292
+ copies of the Software, and to permit persons to whom the Software is
293
+ furnished to do so, subject to the following conditions:
294
+
295
+ The above copyright notice and this permission notice shall be included in all
296
+ copies or substantial portions of the Software.
297
+
298
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
299
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
300
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
301
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
302
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
303
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
304
+ SOFTWARE.
305
+
306
+ ## multiformats - 13.4.2 (Apache-2.0 OR MIT)
307
+
308
+ This project is dual licensed under MIT and Apache-2.0.
309
+
310
+ MIT: https://www.opensource.org/licenses/mit
311
+ Apache-2.0: https://www.apache.org/licenses/license-2.0
312
+
313
+ ## multiformats - 14.0.5 (Apache-2.0 OR MIT)
314
+
315
+ This project is dual licensed under MIT and Apache-2.0.
316
+
317
+ MIT: https://www.opensource.org/licenses/mit
318
+ Apache-2.0: https://www.apache.org/licenses/license-2.0
319
+
320
+ ## netmask - 2.1.1 (MIT)
321
+
322
+ MIT License
323
+
324
+ Copyright (c) 2011 Olivier Poitrey rs@rhapsodyk.net
325
+
326
+ Permission is hereby granted, free of charge, to any person obtaining a copy
327
+ of this software and associated documentation files (the "Software"), to deal
328
+ in the Software without restriction, including without limitation the rights
329
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
330
+ copies of the Software, and to permit persons to whom the Software is
331
+ furnished to do so, subject to the following conditions:
332
+
333
+ The above copyright notice and this permission notice shall be included in all
334
+ copies or substantial portions of the Software.
335
+
336
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
337
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
338
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
339
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
340
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
341
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
342
+ SOFTWARE.
343
+
344
+ ## p-defer - 4.0.1 (MIT)
345
+
346
+ MIT License
347
+
348
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
349
+
350
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
351
+
352
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
353
+
354
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
355
+
356
+ ## p-event - 8.0.1 (MIT)
357
+
358
+ MIT License
359
+
360
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
361
+
362
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
363
+
364
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
365
+
366
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
367
+
368
+ ## p-queue - 9.3.5 (MIT)
369
+
370
+ MIT License
371
+
372
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
373
+
374
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
375
+
376
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
377
+
378
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
379
+
380
+ ## p-retry - 8.0.1 (MIT)
381
+
382
+ MIT License
383
+
384
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
385
+
386
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
387
+
388
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
389
+
390
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
391
+
392
+ ## p-timeout - 7.0.2 (MIT)
393
+
394
+ MIT License
395
+
396
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
397
+
398
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
399
+
400
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
401
+
402
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
403
+
404
+ ## progress-events - 1.1.0 (Apache-2.0 OR MIT)
405
+
406
+ ## protons-runtime - 5.6.0 (Apache-2.0 OR MIT)
407
+
408
+ This project is dual licensed under MIT and Apache-2.0.
409
+
410
+ MIT: https://www.opensource.org/licenses/mit
411
+ Apache-2.0: https://www.apache.org/licenses/license-2.0
412
+
413
+ ## protons-runtime - 7.1.2 (Apache-2.0 OR MIT)
414
+
415
+ ## race-event - 1.6.1 (Apache-2.0 OR MIT)
416
+
417
+ ## race-signal - 2.0.2 (Apache-2.0 OR MIT)
418
+
419
+ ## uint8-varint - 2.0.5 (Apache-2.0 OR MIT)
420
+
421
+ ## uint8-varint - 3.0.0 (Apache-2.0 OR MIT)
422
+
423
+ ## uint8arraylist - 2.4.9 (Apache-2.0 OR MIT)
424
+
425
+ ## uint8arraylist - 3.0.2 (Apache-2.0 OR MIT)
426
+
427
+ ## uint8arrays - 5.1.1 (Apache-2.0 OR MIT)
428
+
429
+ ## uint8arrays - 6.1.1 (Apache-2.0 OR MIT)
430
+
431
+ ## weald - 1.1.3 (Apache-2.0 OR MIT)
@@ -0,0 +1,56 @@
1
+ export declare const MAX_PAYLOAD_SIZE: number;
2
+ export interface Message {
3
+ publisher: string;
4
+ index: bigint;
5
+ payload: Uint8Array;
6
+ text(): string;
7
+ }
8
+ export interface CloseEvent {
9
+ ended: boolean;
10
+ error?: Error;
11
+ }
12
+ export interface Handlers {
13
+ onMessage?: (message: Message) => void;
14
+ onRoster?: (roster: string[]) => void;
15
+ onClose?: (event: CloseEvent) => void;
16
+ }
17
+ export interface Position {
18
+ cursors: Map<string, bigint>;
19
+ roster: string[];
20
+ rosterCursor: bigint;
21
+ ended: boolean;
22
+ }
23
+ export interface SubscribeOptions extends Handlers {
24
+ position?: Position;
25
+ }
26
+ export interface PublishOptions extends Handlers {
27
+ owner?: string;
28
+ index?: bigint;
29
+ rosterIndex?: bigint;
30
+ heartbeatMillis?: number;
31
+ signal?: AbortSignal;
32
+ }
33
+ export interface ConnectOptions {
34
+ networkId?: bigint;
35
+ transports?: ((components: any) => unknown)[];
36
+ }
37
+ export type Topic = string | Uint8Array;
38
+ export interface Subscription {
39
+ readonly position: Position;
40
+ readonly closed: Promise<CloseEvent>;
41
+ close(): void;
42
+ }
43
+ export interface Publisher extends Subscription {
44
+ readonly address: string;
45
+ send(data: string | Uint8Array): Promise<bigint>;
46
+ setRoster(addresses: string[]): Promise<bigint>;
47
+ end(): Promise<void>;
48
+ }
49
+ export interface Broker {
50
+ subscribe(owner: string, topic: Topic, options?: SubscribeOptions): Promise<Subscription>;
51
+ publish(topic: Topic, privateKey: string, options?: PublishOptions): Promise<Publisher>;
52
+ close(): Promise<void>;
53
+ }
54
+ export declare function connect(address: string, options?: ConnectOptions): Promise<Broker>;
55
+ export declare function generatePrivateKey(): string;
56
+ export declare function addressFromPrivateKey(privateKey: string): string;