@minip2p/web 0.0.0 → 0.10.1
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 +21 -0
- package/README.md +66 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/io.d.ts +107 -0
- package/dist/io.d.ts.map +1 -0
- package/dist/io.js +480 -0
- package/dist/io.js.map +1 -0
- package/dist/manual.d.ts +10 -0
- package/dist/manual.d.ts.map +1 -0
- package/dist/manual.js +10 -0
- package/dist/manual.js.map +1 -0
- package/dist/sdk.d.ts +35 -0
- package/dist/sdk.d.ts.map +1 -0
- package/dist/sdk.js +191 -0
- package/dist/sdk.js.map +1 -0
- package/dist/wasm.d.ts +18 -0
- package/dist/wasm.d.ts.map +1 -0
- package/dist/wasm.js +37 -0
- package/dist/wasm.js.map +1 -0
- package/package.json +75 -4
- package/src/index.ts +19 -0
- package/src/io.ts +601 -0
- package/src/manual.ts +17 -0
- package/src/sdk.ts +237 -0
- package/src/wasm.ts +48 -0
- package/wasm/minip2p_web.d.ts +241 -0
- package/wasm/minip2p_web.js +1100 -0
- package/wasm/minip2p_web_bg.wasm +0 -0
- package/wasm/minip2p_web_bg.wasm.d.ts +48 -0
package/dist/io.js
ADDED
|
@@ -0,0 +1,480 @@
|
|
|
1
|
+
/* oxlint-disable func-style, max-classes-per-file, no-empty-function, no-use-before-define, promise/prefer-await-to-callbacks, promise/prefer-await-to-then, promise/prefer-catch -- Promise callbacks become queued events here by design: nothing awaits, so the wasm side stays caller-driven, and a rejection the end of a stream or session already reports is dropped on purpose. */
|
|
2
|
+
/**
|
|
3
|
+
* `JsIo`: the `WebTransportIo` seam of `minip2p-webtransport` over the
|
|
4
|
+
* browser's `WebTransport` API. Rust owns the protocol and calls these
|
|
5
|
+
* methods synchronously; every outcome the browser learns later (a session
|
|
6
|
+
* coming up, a read, a write resolving, a reset) is queued as an
|
|
7
|
+
* {@link IoEvent} and handed back by {@link JsIo.pollEvent}, and `wake`
|
|
8
|
+
* asks the host to pump.
|
|
9
|
+
*
|
|
10
|
+
* The rules Rust relies on:
|
|
11
|
+
*
|
|
12
|
+
* - `write` copies what it accepts before returning, so a queued browser
|
|
13
|
+
* write never views wasm memory, and caps each stream's in-flight bytes;
|
|
14
|
+
* each accepted write reports exactly one `writeCompleted` with its own
|
|
15
|
+
* length, and a write the browser rejects reports nothing.
|
|
16
|
+
* - Reads are pulled: `grantRead` is additive, at most one read is
|
|
17
|
+
* outstanding per stream, and `data` never exceeds what was granted.
|
|
18
|
+
* - Handles are never reused, and events for a reset stream or an ended
|
|
19
|
+
* session are dropped. A stream whose read side ended and whose write
|
|
20
|
+
* side finished (every accepted write reported first) or was stopped is
|
|
21
|
+
* retired, so finished streams hold nothing.
|
|
22
|
+
* - Stream error codes are WebTransport application codes cut to `u8`
|
|
23
|
+
* (minip2p only sends 0); a missing code is 0.
|
|
24
|
+
* - Only `connect`, `openStream` and `write` may throw (Rust catches those
|
|
25
|
+
* as `IoError`s). An exception escaping any other method would unwind
|
|
26
|
+
* through Rust and leave the `WebEndpoint` borrowed for good, so they
|
|
27
|
+
* swallow everything.
|
|
28
|
+
*/
|
|
29
|
+
/** In-flight write bytes each stream may hold in the browser. */
|
|
30
|
+
export const MAX_IN_FLIGHT_BYTES = 64 * 1024;
|
|
31
|
+
/** The largest single read requested from the browser. */
|
|
32
|
+
const MAX_READ_BYTES = 64 * 1024;
|
|
33
|
+
class Stream {
|
|
34
|
+
writer;
|
|
35
|
+
reader;
|
|
36
|
+
inFlight = 0;
|
|
37
|
+
granted = 0;
|
|
38
|
+
reading = false;
|
|
39
|
+
/** Fin, reset or a local stop: no more `data`. */
|
|
40
|
+
readEnded = false;
|
|
41
|
+
/** Finished after its last write, or stopped by the peer. */
|
|
42
|
+
writeEnded = false;
|
|
43
|
+
/** Reset locally or its session ended: no more events at all. */
|
|
44
|
+
dead = false;
|
|
45
|
+
/** A `stop` that arrived before the stream finished opening. */
|
|
46
|
+
pendingStop;
|
|
47
|
+
session;
|
|
48
|
+
constructor(session) {
|
|
49
|
+
this.session = session;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const defaultOpenSession = () => typeof WebTransport === "function"
|
|
53
|
+
? (url, options) => new WebTransport(url, options)
|
|
54
|
+
: undefined;
|
|
55
|
+
/** The browser `WebTransportIo` behind one `WebEndpoint`. */
|
|
56
|
+
export class JsIo {
|
|
57
|
+
#wake;
|
|
58
|
+
#openSession;
|
|
59
|
+
#events = [];
|
|
60
|
+
#sessions = new Map();
|
|
61
|
+
#streams = new Map();
|
|
62
|
+
#nextSession = 1;
|
|
63
|
+
#nextStream = 1;
|
|
64
|
+
#disposed = false;
|
|
65
|
+
/**
|
|
66
|
+
* `wake` runs whenever an event is queued; `openSession` defaults to the
|
|
67
|
+
* global `WebTransport`.
|
|
68
|
+
*/
|
|
69
|
+
constructor(wake, openSession = defaultOpenSession()) {
|
|
70
|
+
this.#wake = wake;
|
|
71
|
+
this.#openSession = openSession;
|
|
72
|
+
}
|
|
73
|
+
/** Starts a session trusting exactly the certificates `certhashes` name. */
|
|
74
|
+
connect(url, certhashes) {
|
|
75
|
+
if (this.#disposed) {
|
|
76
|
+
throw new Error("this endpoint's WebTransport I/O was disposed");
|
|
77
|
+
}
|
|
78
|
+
if (this.#openSession === undefined) {
|
|
79
|
+
throw new Error("this browser has no WebTransport; minip2p needs a WebTransport-capable browser");
|
|
80
|
+
}
|
|
81
|
+
const transport = this.#openSession(url, {
|
|
82
|
+
serverCertificateHashes: certhashes.map((value) => ({
|
|
83
|
+
algorithm: "sha-256",
|
|
84
|
+
value,
|
|
85
|
+
})),
|
|
86
|
+
});
|
|
87
|
+
const id = this.#nextSession;
|
|
88
|
+
this.#nextSession += 1;
|
|
89
|
+
const session = { streams: new Set(), transport };
|
|
90
|
+
this.#sessions.set(id, session);
|
|
91
|
+
transport.ready.then(() => {
|
|
92
|
+
if (this.#sessions.get(id) === session) {
|
|
93
|
+
this.#push({ kind: "sessionReady", session: id });
|
|
94
|
+
void this.#acceptIncoming(id, session);
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
// `closed` rejects too and reports it.
|
|
98
|
+
() => { });
|
|
99
|
+
transport.closed.then((info) => {
|
|
100
|
+
this.#endSession({
|
|
101
|
+
code: info.closeCode ?? 0,
|
|
102
|
+
kind: "sessionClosed",
|
|
103
|
+
reason: info.reason ?? "",
|
|
104
|
+
session: id,
|
|
105
|
+
});
|
|
106
|
+
},
|
|
107
|
+
// Never came up, or lost (the network going away): not an orderly close.
|
|
108
|
+
(error) => {
|
|
109
|
+
this.#endSession({
|
|
110
|
+
kind: "sessionFailed",
|
|
111
|
+
reason: errorMessage(error),
|
|
112
|
+
session: id,
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
return id;
|
|
116
|
+
}
|
|
117
|
+
/** Opens a bidirectional stream; `streamOpened` follows. */
|
|
118
|
+
openStream(sessionId) {
|
|
119
|
+
const session = this.#sessions.get(sessionId);
|
|
120
|
+
if (session === undefined) {
|
|
121
|
+
throw new Error(`session ${sessionId} is closed`);
|
|
122
|
+
}
|
|
123
|
+
const id = this.#addStream(sessionId, session);
|
|
124
|
+
const stream = this.#streams.get(id);
|
|
125
|
+
session.transport.createBidirectionalStream().then((bidi) => {
|
|
126
|
+
if (stream === undefined || stream.dead) {
|
|
127
|
+
abandon(bidi);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
this.#attach(id, stream, bidi);
|
|
131
|
+
this.#push({ kind: "streamOpened", stream: id });
|
|
132
|
+
}, () => {
|
|
133
|
+
if (stream !== undefined && !stream.dead) {
|
|
134
|
+
this.#forget(id, stream);
|
|
135
|
+
this.#push({ code: 0, kind: "reset", stream: id });
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
return id;
|
|
139
|
+
}
|
|
140
|
+
/** Copies and queues a prefix of `data`; a short write is backpressure. */
|
|
141
|
+
write(streamId, data) {
|
|
142
|
+
const stream = this.#streams.get(streamId);
|
|
143
|
+
const writer = stream?.writer;
|
|
144
|
+
if (stream === undefined || writer === undefined) {
|
|
145
|
+
throw new Error(`stream ${streamId} is not writable`);
|
|
146
|
+
}
|
|
147
|
+
const accepted = Math.min(MAX_IN_FLIGHT_BYTES - stream.inFlight, data.length);
|
|
148
|
+
if (accepted <= 0) {
|
|
149
|
+
return 0;
|
|
150
|
+
}
|
|
151
|
+
// `data` views wasm memory, which may move: copy before returning.
|
|
152
|
+
const copy = data.slice(0, accepted);
|
|
153
|
+
stream.inFlight += accepted;
|
|
154
|
+
writer.write(copy).then(() => {
|
|
155
|
+
if (!stream.dead) {
|
|
156
|
+
stream.inFlight -= accepted;
|
|
157
|
+
this.#push({
|
|
158
|
+
bytes: accepted,
|
|
159
|
+
kind: "writeCompleted",
|
|
160
|
+
stream: streamId,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
// A rejected write reports nothing: the stream's end releases it.
|
|
165
|
+
() => { });
|
|
166
|
+
return accepted;
|
|
167
|
+
}
|
|
168
|
+
/** Finishes the write side after every accepted write. */
|
|
169
|
+
closeWrite(streamId) {
|
|
170
|
+
quietly(() => {
|
|
171
|
+
const stream = this.#streams.get(streamId);
|
|
172
|
+
// Resolves once every accepted write has resolved, and been reported.
|
|
173
|
+
stream?.writer?.close().then(() => {
|
|
174
|
+
stream.writeEnded = true;
|
|
175
|
+
this.#retireIfDone(streamId, stream);
|
|
176
|
+
},
|
|
177
|
+
// Stopped or reset: `writer.closed` or the reset covers it.
|
|
178
|
+
() => { });
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
/** Resets the stream both ways (`abort()` and `cancel()`). */
|
|
182
|
+
reset(streamId, code) {
|
|
183
|
+
quietly(() => {
|
|
184
|
+
const stream = this.#streams.get(streamId);
|
|
185
|
+
if (stream === undefined) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
this.#forget(streamId, stream);
|
|
189
|
+
stream.writer?.abort(streamError(code)).catch(() => { });
|
|
190
|
+
stream.reader?.cancel(streamError(code)).catch(() => { });
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
/** Asks the peer to stop sending (`cancel()` only). */
|
|
194
|
+
stop(streamId, code) {
|
|
195
|
+
quietly(() => {
|
|
196
|
+
const stream = this.#streams.get(streamId);
|
|
197
|
+
if (stream === undefined) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
stream.readEnded = true;
|
|
201
|
+
if (stream.reader === undefined) {
|
|
202
|
+
stream.pendingStop = code;
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
stream.reader.cancel(streamError(code)).catch(() => { });
|
|
206
|
+
this.#retireIfDone(streamId, stream);
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
/** Lets the stream deliver up to `bytes` more. */
|
|
210
|
+
grantRead(streamId, bytes) {
|
|
211
|
+
quietly(() => {
|
|
212
|
+
const stream = this.#streams.get(streamId);
|
|
213
|
+
if (stream === undefined) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
stream.granted += bytes;
|
|
217
|
+
this.#read(streamId, stream);
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
/** Closes the session with a close capsule, as `WebTransport.close()` does. */
|
|
221
|
+
close(sessionId, code, reason) {
|
|
222
|
+
quietly(() => {
|
|
223
|
+
const session = this.#sessions.get(sessionId);
|
|
224
|
+
if (session === undefined) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
// Rust forgets the session's streams with it.
|
|
228
|
+
for (const id of session.streams) {
|
|
229
|
+
const stream = this.#streams.get(id);
|
|
230
|
+
if (stream !== undefined) {
|
|
231
|
+
this.#forget(id, stream);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
// Throws once already closed, when `closed` reports the end anyway.
|
|
235
|
+
session.transport.close({ closeCode: code, reason });
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
/** The next queued event, if any. */
|
|
239
|
+
pollEvent() {
|
|
240
|
+
return this.#events.shift();
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Closes every session and forgets everything, for an owner that can no
|
|
244
|
+
* longer drive Rust (a trapped wasm module): no later event or wake, and
|
|
245
|
+
* `connect` throws. Idempotent; called from TypeScript, not Rust.
|
|
246
|
+
*/
|
|
247
|
+
dispose() {
|
|
248
|
+
this.#disposed = true;
|
|
249
|
+
this.#events.length = 0;
|
|
250
|
+
// `close` retires each session's streams, silencing their callbacks.
|
|
251
|
+
for (const id of this.#sessions.keys()) {
|
|
252
|
+
this.close(id, 0, "");
|
|
253
|
+
}
|
|
254
|
+
this.#sessions.clear();
|
|
255
|
+
}
|
|
256
|
+
#push(event) {
|
|
257
|
+
if (this.#disposed) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
this.#events.push(event);
|
|
261
|
+
this.#wake();
|
|
262
|
+
}
|
|
263
|
+
#addStream(sessionId, session) {
|
|
264
|
+
const id = this.#nextStream;
|
|
265
|
+
this.#nextStream += 1;
|
|
266
|
+
this.#streams.set(id, new Stream(sessionId));
|
|
267
|
+
session.streams.add(id);
|
|
268
|
+
return id;
|
|
269
|
+
}
|
|
270
|
+
/** Forgets a stream once both of its sides are done. */
|
|
271
|
+
#retireIfDone(id, stream) {
|
|
272
|
+
if (!stream.dead && stream.readEnded && stream.writeEnded) {
|
|
273
|
+
this.#forget(id, stream);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
#forget(id, stream) {
|
|
277
|
+
stream.dead = true;
|
|
278
|
+
this.#streams.delete(id);
|
|
279
|
+
this.#sessions.get(stream.session)?.streams.delete(id);
|
|
280
|
+
}
|
|
281
|
+
#attach(id, stream, bidi) {
|
|
282
|
+
stream.writer = bidi.writable.getWriter();
|
|
283
|
+
stream.reader = chunkReader(bidi.readable);
|
|
284
|
+
// The peer's STOP_SENDING errors the write side.
|
|
285
|
+
stream.writer.closed.catch((error) => {
|
|
286
|
+
const code = peerStreamCode(error);
|
|
287
|
+
if (!stream.dead && code !== undefined) {
|
|
288
|
+
stream.writeEnded = true;
|
|
289
|
+
this.#push({ code, kind: "stopSending", stream: id });
|
|
290
|
+
this.#retireIfDone(id, stream);
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
// The peer's RESET_STREAM errors the read side, read pending or not.
|
|
294
|
+
stream.reader.closed.catch((error) => {
|
|
295
|
+
this.#readFailed(id, stream, error);
|
|
296
|
+
});
|
|
297
|
+
if (stream.pendingStop !== undefined) {
|
|
298
|
+
stream.reader.cancel(streamError(stream.pendingStop)).catch(() => { });
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
this.#read(id, stream);
|
|
302
|
+
}
|
|
303
|
+
#read(id, stream) {
|
|
304
|
+
const { reader } = stream;
|
|
305
|
+
if (reader === undefined ||
|
|
306
|
+
stream.reading ||
|
|
307
|
+
stream.readEnded ||
|
|
308
|
+
stream.dead ||
|
|
309
|
+
stream.granted <= 0) {
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
stream.reading = true;
|
|
313
|
+
reader.read(Math.min(stream.granted, MAX_READ_BYTES)).then(({ done, value }) => {
|
|
314
|
+
stream.reading = false;
|
|
315
|
+
if (stream.dead || stream.readEnded) {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
if (done) {
|
|
319
|
+
stream.readEnded = true;
|
|
320
|
+
this.#push({ kind: "fin", stream: id });
|
|
321
|
+
this.#retireIfDone(id, stream);
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
if (value.byteLength > 0) {
|
|
325
|
+
stream.granted -= value.byteLength;
|
|
326
|
+
this.#push({ bytes: value, kind: "data", stream: id });
|
|
327
|
+
}
|
|
328
|
+
this.#read(id, stream);
|
|
329
|
+
}, (error) => {
|
|
330
|
+
stream.reading = false;
|
|
331
|
+
this.#readFailed(id, stream, error);
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* A read side errored: a peer reset, its session going away (which
|
|
336
|
+
* `closed` reports too), or an error with no WebTransport code (Firefox
|
|
337
|
+
* errors the read side so when the peer stops our sending as it closes).
|
|
338
|
+
* Each ends the read side as a reset, so nothing waits on it.
|
|
339
|
+
*/
|
|
340
|
+
#readFailed(id, stream, error) {
|
|
341
|
+
if (stream.dead || stream.readEnded) {
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
stream.readEnded = true;
|
|
345
|
+
this.#push({ code: peerStreamCode(error) ?? 0, kind: "reset", stream: id });
|
|
346
|
+
this.#retireIfDone(id, stream);
|
|
347
|
+
}
|
|
348
|
+
async #acceptIncoming(id, session) {
|
|
349
|
+
const reader = session.transport.incomingBidirectionalStreams.getReader();
|
|
350
|
+
try {
|
|
351
|
+
for (;;) {
|
|
352
|
+
// oxlint-disable-next-line no-await-in-loop -- One stream at a time, in arrival order.
|
|
353
|
+
const { done, value } = await reader.read();
|
|
354
|
+
if (done || this.#sessions.get(id) !== session) {
|
|
355
|
+
if (!done) {
|
|
356
|
+
abandon(value);
|
|
357
|
+
}
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
const stream = this.#addStream(id, session);
|
|
361
|
+
const state = this.#streams.get(stream);
|
|
362
|
+
if (state !== undefined) {
|
|
363
|
+
this.#attach(stream, state, value);
|
|
364
|
+
this.#push({ kind: "incomingStream", session: id, stream });
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
catch {
|
|
369
|
+
// The session ended; `closed` reports it.
|
|
370
|
+
}
|
|
371
|
+
finally {
|
|
372
|
+
reader.releaseLock();
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
#endSession(end) {
|
|
376
|
+
const id = end.session;
|
|
377
|
+
const session = this.#sessions.get(id);
|
|
378
|
+
if (session === undefined) {
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
for (const streamId of session.streams) {
|
|
382
|
+
const stream = this.#streams.get(streamId);
|
|
383
|
+
if (stream !== undefined) {
|
|
384
|
+
this.#forget(streamId, stream);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
this.#sessions.delete(id);
|
|
388
|
+
this.#push(end);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
function chunkReader(readable) {
|
|
392
|
+
try {
|
|
393
|
+
const byob = readable.getReader({ mode: "byob" });
|
|
394
|
+
return {
|
|
395
|
+
cancel: (reason) => byob.cancel(reason),
|
|
396
|
+
closed: byob.closed,
|
|
397
|
+
read: (max) => byob.read(new Uint8Array(max)),
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
catch {
|
|
401
|
+
// Not a byte stream: split default chunks to the grant instead.
|
|
402
|
+
}
|
|
403
|
+
const reader = readable.getReader();
|
|
404
|
+
let rest;
|
|
405
|
+
return {
|
|
406
|
+
cancel: (reason) => reader.cancel(reason),
|
|
407
|
+
closed: reader.closed,
|
|
408
|
+
read: async (max) => {
|
|
409
|
+
if (rest === undefined) {
|
|
410
|
+
const result = await reader.read();
|
|
411
|
+
if (result.done) {
|
|
412
|
+
return result;
|
|
413
|
+
}
|
|
414
|
+
rest = result.value;
|
|
415
|
+
}
|
|
416
|
+
const value = rest.subarray(0, max);
|
|
417
|
+
rest = rest.byteLength > max ? rest.subarray(max) : undefined;
|
|
418
|
+
return { done: false, value };
|
|
419
|
+
},
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* The reason a reset or stop passes, carrying its code: none for 0 (what
|
|
424
|
+
* the browser sends by default), else a `WebTransportError`, in the spec's
|
|
425
|
+
* `(message, options)` form or the `(init)` form Chrome implements.
|
|
426
|
+
*/
|
|
427
|
+
function streamError(code) {
|
|
428
|
+
if (code === 0 || typeof WebTransportError !== "function") {
|
|
429
|
+
return undefined;
|
|
430
|
+
}
|
|
431
|
+
try {
|
|
432
|
+
return new WebTransportError("minip2p stream error", {
|
|
433
|
+
streamErrorCode: code,
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
catch {
|
|
437
|
+
// Chrome's constructor takes one init dictionary.
|
|
438
|
+
}
|
|
439
|
+
try {
|
|
440
|
+
const init = {
|
|
441
|
+
message: "minip2p stream error",
|
|
442
|
+
streamErrorCode: code,
|
|
443
|
+
};
|
|
444
|
+
return Reflect.construct(WebTransportError, [init]);
|
|
445
|
+
}
|
|
446
|
+
catch {
|
|
447
|
+
return undefined;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
/** Runs a `JsIo` call Rust makes without catching, swallowing any throw. */
|
|
451
|
+
function quietly(operation) {
|
|
452
|
+
try {
|
|
453
|
+
operation();
|
|
454
|
+
}
|
|
455
|
+
catch {
|
|
456
|
+
// See the module rules: nothing may unwind into Rust from here.
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* The WebTransport code of an error the peer caused on one stream (a
|
|
461
|
+
* `WebTransportError` with `source: "stream"`), cut to `u8`; `undefined`
|
|
462
|
+
* for anything else, such as the session ending.
|
|
463
|
+
*/
|
|
464
|
+
function peerStreamCode(error) {
|
|
465
|
+
if (error === null ||
|
|
466
|
+
typeof error !== "object" ||
|
|
467
|
+
Reflect.get(error, "source") !== "stream") {
|
|
468
|
+
return undefined;
|
|
469
|
+
}
|
|
470
|
+
const code = Reflect.get(error, "streamErrorCode");
|
|
471
|
+
return typeof code === "number" ? Math.min(Math.max(code, 0), 0xff) : 0;
|
|
472
|
+
}
|
|
473
|
+
function abandon(bidi) {
|
|
474
|
+
bidi.writable.abort().catch(() => { });
|
|
475
|
+
bidi.readable.cancel().catch(() => { });
|
|
476
|
+
}
|
|
477
|
+
function errorMessage(error) {
|
|
478
|
+
return error instanceof Error ? error.message : String(error);
|
|
479
|
+
}
|
|
480
|
+
//# sourceMappingURL=io.js.map
|
package/dist/io.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"io.js","sourceRoot":"","sources":["../src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AAC;IAC5D,OAAO,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC1E,CAAC;AAED,SAAS,OAAO,CAAC,IAAqC;IACpD,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IACtC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;AACzC,CAAC;AAED,SAAS,YAAY,CAAC,KAAc;IAClC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAChE,CAAC"}
|
package/dist/manual.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@minip2p/web/manual`: the same API as `@minip2p/web`, without loading
|
|
3
|
+
* the wasm module at import. For hosts that serve the `.wasm` themselves (a
|
|
4
|
+
* CDN, a strict CSP): `await initMinip2p({ wasm })` before
|
|
5
|
+
* `Minip2p.create`, which throws until it has resolved.
|
|
6
|
+
*/
|
|
7
|
+
export * from "@minip2p/core";
|
|
8
|
+
export { Minip2p, circuitAddress, generateSecretKey, initMinip2p, peerIdFromSecretKey, type InitMinip2pOptions, } from "./sdk.js";
|
|
9
|
+
export { type WasmSource } from "./wasm.js";
|
|
10
|
+
//# sourceMappingURL=manual.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manual.d.ts","sourceRoot":"","sources":["../src/manual.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EACL,OAAO,EACP,cAAc,EACd,iBAAiB,EACjB,WAAW,EACX,mBAAmB,EACnB,KAAK,kBAAkB,GACxB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/manual.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@minip2p/web/manual`: the same API as `@minip2p/web`, without loading
|
|
3
|
+
* the wasm module at import. For hosts that serve the `.wasm` themselves (a
|
|
4
|
+
* CDN, a strict CSP): `await initMinip2p({ wasm })` before
|
|
5
|
+
* `Minip2p.create`, which throws until it has resolved.
|
|
6
|
+
*/
|
|
7
|
+
export * from "@minip2p/core";
|
|
8
|
+
export { Minip2p, circuitAddress, generateSecretKey, initMinip2p, peerIdFromSecretKey, } from "./sdk.js";
|
|
9
|
+
export {} from "./wasm.js";
|
|
10
|
+
//# sourceMappingURL=manual.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manual.js","sourceRoot":"","sources":["../src/manual.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EACL,OAAO,EACP,cAAc,EACd,iBAAiB,EACjB,WAAW,EACX,mBAAmB,GAEpB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAmB,MAAM,WAAW,CAAC"}
|
package/dist/sdk.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The implementation both entry points share: `Minip2p` over the wasm
|
|
3
|
+
* module's `WebEndpoint`, the key helpers, and `initMinip2p`.
|
|
4
|
+
*/
|
|
5
|
+
import { Minip2pBase } from "@minip2p/core";
|
|
6
|
+
import type { Bytes, Minip2pConfig } from "@minip2p/core";
|
|
7
|
+
import type { WasmSource } from "./wasm.js";
|
|
8
|
+
/** Options for {@link initMinip2p}. */
|
|
9
|
+
export interface InitMinip2pOptions {
|
|
10
|
+
/**
|
|
11
|
+
* The `.wasm`: a URL, a `Response`, its bytes, or a compiled
|
|
12
|
+
* `WebAssembly.Module`. Defaults to the file beside the package.
|
|
13
|
+
*/
|
|
14
|
+
readonly wasm?: WasmSource;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Loads minip2p's wasm module. `@minip2p/web` calls it at import;
|
|
18
|
+
* `@minip2p/web/manual` leaves it to the host, which must await it before
|
|
19
|
+
* `Minip2p.create`. Safe to call again: later calls share the first load
|
|
20
|
+
* that succeeds, and a failed load can be retried.
|
|
21
|
+
*/
|
|
22
|
+
export declare function initMinip2p(options?: InitMinip2pOptions): Promise<void>;
|
|
23
|
+
/** High-level browser owner for one minip2p endpoint. */
|
|
24
|
+
export declare class Minip2p extends Minip2pBase {
|
|
25
|
+
private constructor();
|
|
26
|
+
/** Constructs and starts a browser endpoint. */
|
|
27
|
+
static create(config: Minip2pConfig): Minip2p;
|
|
28
|
+
}
|
|
29
|
+
/** Generates a new 32-byte Ed25519 secret key with `crypto.getRandomValues`. */
|
|
30
|
+
export declare function generateSecretKey(): Uint8Array;
|
|
31
|
+
/** Derives a peer ID from raw Ed25519 secret key material. */
|
|
32
|
+
export declare function peerIdFromSecretKey(secretKey: Bytes): string;
|
|
33
|
+
/** Builds a circuit multiaddress through a direct relay address. */
|
|
34
|
+
export declare function circuitAddress(relayAddress: string, peerId: string): string;
|
|
35
|
+
//# sourceMappingURL=sdk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../src/sdk.ts"],"names":[],"mappings":"AAEA;;;GAGG;AAEH,OAAO,EAIL,WAAW,EACZ,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAO1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE5C,uCAAuC;AACvC,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC;CAC5B;AAED;;;;;GAKG;AACH,wBAAsB,WAAW,CAC/B,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,IAAI,CAAC,CAEf;AAED,yDAAyD;AACzD,qBAAa,OAAQ,SAAQ,WAAW;IACtC,OAAO,eAEN;IAED,gDAAgD;IAChD,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAE5C;CACF;AAED,gFAAgF;AAChF,wBAAgB,iBAAiB,IAAI,UAAU,CAE9C;AAED,8DAA8D;AAC9D,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,KAAK,GAAG,MAAM,CAI5D;AAED,oEAAoE;AACpE,wBAAgB,cAAc,CAAC,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAE3E"}
|