@browsercore/quic 0.1.3

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 (55) hide show
  1. package/.github/workflows/ci.yml +17 -0
  2. package/.github/workflows/publish.yml +49 -0
  3. package/CODING_STANDARDS.md +205 -0
  4. package/LICENSE +21 -0
  5. package/dist/connection.d.ts +104 -0
  6. package/dist/connection.d.ts.map +1 -0
  7. package/dist/connection.js +334 -0
  8. package/dist/connection.js.map +1 -0
  9. package/dist/errors.d.ts +98 -0
  10. package/dist/errors.d.ts.map +1 -0
  11. package/dist/errors.js +130 -0
  12. package/dist/errors.js.map +1 -0
  13. package/dist/frame/frame.d.ts +22 -0
  14. package/dist/frame/frame.d.ts.map +1 -0
  15. package/dist/frame/frame.js +365 -0
  16. package/dist/frame/frame.js.map +1 -0
  17. package/dist/frame/varint.d.ts +32 -0
  18. package/dist/frame/varint.d.ts.map +1 -0
  19. package/dist/frame/varint.js +119 -0
  20. package/dist/frame/varint.js.map +1 -0
  21. package/dist/index.d.ts +20 -0
  22. package/dist/index.d.ts.map +1 -0
  23. package/dist/index.js +19 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/packet/packet.d.ts +71 -0
  26. package/dist/packet/packet.d.ts.map +1 -0
  27. package/dist/packet/packet.js +150 -0
  28. package/dist/packet/packet.js.map +1 -0
  29. package/dist/stream/stream.d.ts +66 -0
  30. package/dist/stream/stream.d.ts.map +1 -0
  31. package/dist/stream/stream.js +617 -0
  32. package/dist/stream/stream.js.map +1 -0
  33. package/dist/types.d.ts +344 -0
  34. package/dist/types.d.ts.map +1 -0
  35. package/dist/types.js +127 -0
  36. package/dist/types.js.map +1 -0
  37. package/dist/utils.d.ts +16 -0
  38. package/dist/utils.d.ts.map +1 -0
  39. package/dist/utils.js +36 -0
  40. package/dist/utils.js.map +1 -0
  41. package/package.json +43 -0
  42. package/src/connection.ts +374 -0
  43. package/src/errors.ts +153 -0
  44. package/src/frame/frame.ts +423 -0
  45. package/src/frame/varint.ts +124 -0
  46. package/src/index.ts +70 -0
  47. package/src/packet/packet.ts +210 -0
  48. package/src/stream/stream.ts +746 -0
  49. package/src/types.ts +441 -0
  50. package/src/utils.ts +38 -0
  51. package/tests/connection.test.ts +106 -0
  52. package/tests/fake-transport.ts +107 -0
  53. package/tests/stream.test.ts +152 -0
  54. package/tests/wire.test.ts +342 -0
  55. package/tsconfig.json +30 -0
@@ -0,0 +1,334 @@
1
+ /**
2
+ * QUIC connection lifecycle + datagram read loop (RFC 9000 §5, §12).
3
+ *
4
+ * Wires packet header parsing/serialization, the frame layer, and the stream
5
+ * manager over an injected {@link DatagramTransport} (UDP). The connection owns
6
+ * the read loop: it turns inbound datagrams into frames, dispatches each to the
7
+ * stream manager, and drains pending stream sends back into outbound packets.
8
+ *
9
+ * Honest limitations:
10
+ * - The TLS 1.3 handshake and packet protection (header protection + AEAD
11
+ * payload encryption) are out of scope. `connectQuic()` returns a connection
12
+ * that moves *unprotected* frames over the transport directly — enough to
13
+ * drive the data plane and to be tested with a fake datagram transport. A
14
+ * production build layers protection + the handshake on top of this.
15
+ * - No congestion controller, no connection migration, no PATH_CHALLENGE /
16
+ * PATH_RESPONSE beyond frame relay, and no liveness PING.
17
+ *
18
+ * Concurrency model: the read loop is a single async task pulling datagrams from
19
+ * the transport. Outbound frames are produced synchronously by the stream
20
+ * manager and packed into packets; writes resolve once bytes are buffered.
21
+ */
22
+ import { QuicFrameType } from "./types.js";
23
+ import { parsePacketHeader, serializeShortHeader } from "./packet/packet.js";
24
+ import { readFrames, serializeFrame } from "./frame/frame.js";
25
+ import { ConnectionClosedError } from "./errors.js";
26
+ import { createStreamManager } from "./stream/stream.js";
27
+ import { concatAll } from "./utils.js";
28
+ /** Largest UDP payload we will pack into a single datagram (RFC 9000 §14). */
29
+ const MAX_DATAGRAM_PAYLOAD = 1200;
30
+ /**
31
+ * Concrete QUIC connection. The public surface matches the fixed
32
+ * `QuicConnection` interface; internal state is kept on the instance.
33
+ */
34
+ export class QuicConnectionImpl {
35
+ id;
36
+ /** The underlying datagram (UDP) transport. */
37
+ transport;
38
+ /** The peer's UDP address. */
39
+ peer;
40
+ /** Stream manager (also an EventEmitter for connection-level signals). */
41
+ manager;
42
+ /** Our current destination connection id (the one we put on outbound packets). */
43
+ dcid;
44
+ /** Set once the connection begins graceful shutdown. */
45
+ closing = false;
46
+ /** Set once the connection is fully torn down. */
47
+ closed = false;
48
+ /** Buffered outbound frames waiting to be packed into the next packet. */
49
+ outboundFrames = [];
50
+ constructor(id, options, manager, dcid) {
51
+ this.id = id;
52
+ this.transport = options.transport;
53
+ this.peer = options.peer;
54
+ this.manager = manager;
55
+ this.dcid = dcid;
56
+ }
57
+ // --- public QuicConnection surface ------------------------------------------
58
+ async openBidirectionalStream() {
59
+ this._ensureOpen();
60
+ return this.manager.openStream(true);
61
+ }
62
+ async acceptBidirectionalStream() {
63
+ this._ensureOpen();
64
+ return this.manager.acceptStream(true);
65
+ }
66
+ async openUnidirectionalStream() {
67
+ this._ensureOpen();
68
+ return this.manager.openStream(false);
69
+ }
70
+ async acceptUnidirectionalStream() {
71
+ this._ensureOpen();
72
+ return this.manager.acceptStream(false);
73
+ }
74
+ async close(errorCode, reason) {
75
+ if (this.closed)
76
+ return;
77
+ this.closing = true;
78
+ this.manager.close(errorCode, reason);
79
+ // Pack + flush the CONNECTION_CLOSE frame, then tear down.
80
+ await this._flush();
81
+ await this._teardown({ kind: "client_close" });
82
+ }
83
+ // --- frame I/O -------------------------------------------------------------
84
+ /**
85
+ * Enqueue a frame for the next outbound packet. Control frames from the
86
+ * stream manager flow through here so they are serialized + sent by the
87
+ * connection's packetizer.
88
+ */
89
+ sendFrame(frame) {
90
+ this.outboundFrames.push(frame);
91
+ }
92
+ /**
93
+ * Pack all buffered outbound frames into a short-header packet and send it.
94
+ * Splits into multiple datagrams if the payload exceeds MAX_DATAGRAM_PAYLOAD.
95
+ */
96
+ async _flush() {
97
+ if (this.outboundFrames.length === 0)
98
+ return;
99
+ const frames = this.outboundFrames.splice(0, this.outboundFrames.length);
100
+ const payload = this._packFrames(frames);
101
+ let offset = 0;
102
+ while (offset < payload.length) {
103
+ const slice = payload.subarray(offset, offset + MAX_DATAGRAM_PAYLOAD);
104
+ const packet = this._wrapPacket(slice);
105
+ await this.transport.send(packet, this.peer);
106
+ offset += MAX_DATAGRAM_PAYLOAD;
107
+ }
108
+ }
109
+ /** Serialize frames into a single byte buffer (no packet header). */
110
+ _packFrames(frames) {
111
+ return concatAll(frames.map((f) => serializeFrame(f)));
112
+ }
113
+ /** Wrap a serialized payload in a short (1-RTT) header + packet number. */
114
+ _wrapPacket(payload) {
115
+ const header = serializeShortHeader(this.dcid, 1, false, false);
116
+ // 1-byte packet number (relative offset 0) — placeholder for the
117
+ // protection layer, which assigns real packet numbers.
118
+ const packetNumber = new Uint8Array([0]);
119
+ return concatAll([header, packetNumber, payload]);
120
+ }
121
+ // --- read loop -------------------------------------------------------------
122
+ /**
123
+ * Start the datagram read loop. Must be called once after construction.
124
+ * Runs until the transport closes or the connection tears down.
125
+ */
126
+ startReadLoop() {
127
+ // React to connection-level signals from the stream manager.
128
+ this.manager.on("connectionClose", ({ errorCode, reason }) => {
129
+ void errorCode;
130
+ void reason;
131
+ void this._onPeerClose(errorCode, reason);
132
+ });
133
+ void this._readLoop();
134
+ }
135
+ async _onPeerClose(errorCode, reason) {
136
+ if (this.closed)
137
+ return;
138
+ this.closing = true;
139
+ this.manager.abortAll(new ConnectionClosedError(errorCode, reason));
140
+ await this._teardown({ kind: "remote_close" });
141
+ }
142
+ /** Parse a single datagram into frames and dispatch them. */
143
+ async _dispatchDatagram(data) {
144
+ if (data.length === 0)
145
+ return;
146
+ try {
147
+ const header = parsePacketHeader(data);
148
+ this._applyHeader(header);
149
+ // Skip the header + packet number to reach the frame payload. The
150
+ // protection layer would decrypt first in a full implementation.
151
+ const pnLength = header.packetNumberLength;
152
+ // Short headers carry a variable-length DCID after the first byte;
153
+ // its length is not on the wire, so the connection supplies it from
154
+ // the handshake state we already know (this.dcid).
155
+ const dcidLength = header.form === 0 ? this.dcid.length : 0;
156
+ const payloadStart = header.headerLength + dcidLength + pnLength;
157
+ const payload = data.subarray(payloadStart);
158
+ if (payload.length === 0)
159
+ return;
160
+ const read = this._byteStreamReader(payload);
161
+ for await (const frame of readFrames(read)) {
162
+ this._handleFrame(frame);
163
+ }
164
+ }
165
+ catch (err) {
166
+ // A parse error on one datagram is not necessarily fatal for the
167
+ // connection, but without a protection layer to frame it we close.
168
+ this._handleFatal(err instanceof Error ? err : new Error(String(err)));
169
+ }
170
+ }
171
+ /** Pull the DCID / version from a parsed header into connection state. */
172
+ _applyHeader(header) {
173
+ if (header.form === 1) {
174
+ // Long header: could carry a version negotiation. We ignore for now.
175
+ return;
176
+ }
177
+ // Short header: the DCID on the wire is the route to the peer.
178
+ void header.dcid;
179
+ }
180
+ /**
181
+ * Build a pull-based byte reader over a fixed buffer. `readFrames` consumes
182
+ * bytes incrementally; this yields slices until the buffer is exhausted.
183
+ */
184
+ _byteStreamReader(buf) {
185
+ let offset = 0;
186
+ return async () => {
187
+ if (offset >= buf.length)
188
+ return null;
189
+ const chunk = buf.subarray(offset);
190
+ offset = buf.length;
191
+ return chunk;
192
+ };
193
+ }
194
+ /** Route a decoded frame: data-plane frames to the manager, the rest here. */
195
+ _handleFrame(frame) {
196
+ switch (frame.type) {
197
+ case QuicFrameType.PADDING:
198
+ case QuicFrameType.PING:
199
+ return;
200
+ case QuicFrameType.ACK:
201
+ case QuicFrameType.ACK_ECN:
202
+ case QuicFrameType.CRYPTO:
203
+ case QuicFrameType.NEW_TOKEN:
204
+ case QuicFrameType.NEW_CONNECTION_ID:
205
+ case QuicFrameType.RETIRE_CONNECTION_ID:
206
+ case QuicFrameType.PATH_CHALLENGE:
207
+ case QuicFrameType.PATH_RESPONSE:
208
+ case QuicFrameType.HANDSHAKE_DONE:
209
+ // Connection / handshake layer concerns — relay only.
210
+ return;
211
+ default:
212
+ // Data-plane frame: dispatch to the stream manager, which may
213
+ // emit outbound control frames (MAX_DATA, MAX_STREAM_DATA, ...).
214
+ this._withOutbound(() => this.manager.dispatch(frame));
215
+ return;
216
+ }
217
+ }
218
+ /** Run `fn`, then flush any outbound frames it produced to the peer. */
219
+ _withOutbound(fn) {
220
+ const before = this.outboundFrames.length;
221
+ fn();
222
+ if (this.outboundFrames.length > before) {
223
+ void this._flush();
224
+ }
225
+ }
226
+ /** Main read loop: pull datagrams, dispatch, drain sends. */
227
+ async _readLoop() {
228
+ try {
229
+ while (!this.closed) {
230
+ const { data } = await this.transport.recv();
231
+ await this._dispatchDatagram(data);
232
+ // Drain any pending stream sends after handling each datagram.
233
+ this._drainSends();
234
+ }
235
+ }
236
+ catch (err) {
237
+ if (!this.closed) {
238
+ this._handleFatal(err instanceof Error ? err : new Error(String(err)));
239
+ }
240
+ }
241
+ }
242
+ /** Emit STREAM frames for streams with queued data, then flush. */
243
+ _drainSends() {
244
+ if (!this.manager.hasPendingSends)
245
+ return;
246
+ this.manager.flushSends(MAX_DATAGRAM_PAYLOAD, (frame) => this.sendFrame(frame));
247
+ void this._flush();
248
+ }
249
+ /** Tear down the connection on a fatal transport / parse error. */
250
+ _handleFatal(err) {
251
+ if (this.closed)
252
+ return;
253
+ this.closing = true;
254
+ this.manager.abortAll(err);
255
+ this._teardown({ kind: "error", error: err });
256
+ }
257
+ /** Mark closed and release the transport. */
258
+ async _teardown(reason) {
259
+ if (this.closed)
260
+ return;
261
+ this.closed = true;
262
+ this.closing = true;
263
+ try {
264
+ await this.transport.close(reason);
265
+ }
266
+ catch {
267
+ // best-effort
268
+ }
269
+ }
270
+ _ensureOpen() {
271
+ if (this.closing || this.closed) {
272
+ throw new Error("connection is closing");
273
+ }
274
+ }
275
+ }
276
+ // ---------------------------------------------------------------------------
277
+ // helpers
278
+ // ---------------------------------------------------------------------------
279
+ /** Resolve the local transport parameters, filling in defaults. */
280
+ function resolveLocalParameters(options) {
281
+ const src = options.transportParameters;
282
+ const out = {};
283
+ if (src?.initialMaxData !== undefined)
284
+ out.initialMaxData = src.initialMaxData;
285
+ if (src?.initialMaxStreamDataBidiLocal !== undefined) {
286
+ out.initialMaxStreamDataBidiLocal = src.initialMaxStreamDataBidiLocal;
287
+ }
288
+ if (src?.initialMaxStreamDataBidiRemote !== undefined) {
289
+ out.initialMaxStreamDataBidiRemote = src.initialMaxStreamDataBidiRemote;
290
+ }
291
+ if (src?.initialMaxStreamDataUni !== undefined)
292
+ out.initialMaxStreamDataUni = src.initialMaxStreamDataUni;
293
+ if (src?.initialMaxStreamsBidi !== undefined)
294
+ out.initialMaxStreamsBidi = src.initialMaxStreamsBidi;
295
+ if (src?.initialMaxStreamsUni !== undefined)
296
+ out.initialMaxStreamsUni = src.initialMaxStreamsUni;
297
+ if (src?.maxIdleTimeoutMs !== undefined)
298
+ out.maxIdleTimeoutMs = src.maxIdleTimeoutMs;
299
+ if (src?.maxUdpPayloadSize !== undefined)
300
+ out.maxUdpPayloadSize = src.maxUdpPayloadSize;
301
+ if (src?.activeConnectionIdLimit !== undefined)
302
+ out.activeConnectionIdLimit = src.activeConnectionIdLimit;
303
+ return out;
304
+ }
305
+ // ---------------------------------------------------------------------------
306
+ // connectQuic
307
+ // ---------------------------------------------------------------------------
308
+ /**
309
+ * Establish a QUIC connection over an existing datagram transport.
310
+ *
311
+ * Creates the stream manager and the read loop. Because the TLS handshake and
312
+ * packet protection are out of scope, this returns a connection that moves
313
+ * unprotected frames — the data plane is fully functional and testable with a
314
+ * fake datagram transport.
315
+ */
316
+ export async function connectQuic(options) {
317
+ const id = `quic_${Date.now().toString(36)}`;
318
+ // The stream manager is constructed before the connection, but its frames
319
+ // must reach the connection's packetizer. We bridge the two with a mutable
320
+ // router that we point at the connection once it exists.
321
+ const frameRouter = { send: () => { } };
322
+ const manager = createStreamManager({
323
+ sendFrame: (frame) => frameRouter.send(frame),
324
+ localParameters: resolveLocalParameters(options),
325
+ peerParameters: options.transportParameters ?? {},
326
+ });
327
+ const conn = new QuicConnectionImpl(id, options, manager, options.initialDcid);
328
+ frameRouter.send = (frame) => conn.sendFrame(frame);
329
+ // A larger send window may have queued stream data — the read loop drains it.
330
+ manager.on("maxData", () => { });
331
+ conn.startReadLoop();
332
+ return conn;
333
+ }
334
+ //# sourceMappingURL=connection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection.js","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAYH,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAE7E,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAsB,MAAM,oBAAoB,CAAC;AAC7E,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAKvC,8EAA8E;AAC9E,MAAM,oBAAoB,GAAG,IAAI,CAAC;AAElC;;;GAGG;AACH,MAAM,OAAO,kBAAkB;IACX,EAAE,CAAS;IAE3B,+CAA+C;IAC9B,SAAS,CAA2B;IACrD,8BAA8B;IACb,IAAI,CAAa;IAClC,0EAA0E;IACzD,OAAO,CAA+B;IACvD,kFAAkF;IACjE,IAAI,CAAe;IAEpC,wDAAwD;IAChD,OAAO,GAAG,KAAK,CAAC;IACxB,kDAAkD;IAC1C,MAAM,GAAG,KAAK,CAAC;IACvB,0EAA0E;IACzD,cAAc,GAAgB,EAAE,CAAC;IAElD,YACI,EAAU,EACV,OAAoB,EACpB,OAAqC,EACrC,IAAkB;QAElB,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;QACnC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QACzB,IA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AAG,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;IAE7C,0EAA0E;IAC1E,2EAA2E;IAC3E,yDAAyD;IACzD,MAAM,WAAW,GAAyC,EAAE,IAAI,EAAE,GAAG,EAAE,GAAE,CAAC,EAAE,CAAC;IAE7E,MAAM,OAAO,GAAG,mBAAmB,CAAC;QAChC,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC;QAC7C,eAAe,EAAE,sBAAsB,CAAC,OAAO,CAAC;QAChD,cAAc,EAAE,OAAO,CAAC,mBAAmB,IAAI,EAAE;KACpD,CAAC,CAAC;IAEH,MAAM,IAAI,GAAG,IAAI,kBAAkB,CAAC,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;IAC/E,WAAW,CAAC,IAAI,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAEpD,8EAA8E;IAC9E,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE,GAAsC,CAAC,CAAC,CAAC;IAEpE,IAAI,CAAC,aAAa,EAAE,CAAC;IACrB,OAAO,IAAI,CAAC;AAChB,CAAC"}
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Typed errors for @browsercore/quic.
3
+ *
4
+ * Errors are part of the API — every failure mode is an explicit type so callers
5
+ * can match on `kind` instead of parsing messages.
6
+ */
7
+ /** Base class for all QUIC errors. */
8
+ export declare class QuicError extends Error {
9
+ readonly kind: "QuicError";
10
+ readonly cause: Error | undefined;
11
+ constructor(message: string, options?: {
12
+ cause?: Error;
13
+ });
14
+ }
15
+ /** The peer closed the connection with a CONNECTION_CLOSE frame. */
16
+ export declare class ConnectionClosedError extends Error {
17
+ readonly kind: "ConnectionClosedError";
18
+ /** Application error code (application-layer close) or transport error code. */
19
+ readonly errorCode: bigint;
20
+ /** Frame type that triggered the close, if any. */
21
+ readonly frameType: bigint | undefined;
22
+ /** Human-readable reason phrase. */
23
+ readonly reason: string;
24
+ readonly cause: Error | undefined;
25
+ constructor(errorCode: bigint, reason: string, options?: {
26
+ frameType?: bigint;
27
+ cause?: Error;
28
+ });
29
+ }
30
+ /** The peer closed a specific stream with a STOP_SENDING frame. */
31
+ export declare class StopSendingError extends Error {
32
+ readonly kind: "StopSendingError";
33
+ readonly streamId: bigint;
34
+ readonly errorCode: bigint;
35
+ readonly cause: Error | undefined;
36
+ constructor(streamId: bigint, errorCode: bigint, options?: {
37
+ cause?: Error;
38
+ });
39
+ }
40
+ /** The peer reset a specific stream with a RESET_STREAM frame. */
41
+ export declare class ResetStreamError extends Error {
42
+ readonly kind: "ResetStreamError";
43
+ readonly streamId: bigint;
44
+ readonly errorCode: bigint;
45
+ readonly finalSize: bigint;
46
+ readonly cause: Error | undefined;
47
+ constructor(streamId: bigint, errorCode: bigint, finalSize: bigint, options?: {
48
+ cause?: Error;
49
+ });
50
+ }
51
+ /** A flow-control window was violated (send exceeded the peer's limit). */
52
+ export declare class FlowControlError extends Error {
53
+ readonly kind: "FlowControlError";
54
+ readonly streamId: bigint | undefined;
55
+ readonly limit: bigint;
56
+ readonly attempted: bigint;
57
+ readonly cause: Error | undefined;
58
+ constructor(limit: bigint, attempted: bigint, streamId?: bigint, options?: {
59
+ cause?: Error;
60
+ });
61
+ }
62
+ /** A packet could not be parsed from the wire. */
63
+ export declare class PacketParseError extends Error {
64
+ readonly kind: "PacketParseError";
65
+ readonly offset: number;
66
+ readonly cause: Error | undefined;
67
+ constructor(offset: number, options?: {
68
+ cause?: Error;
69
+ });
70
+ }
71
+ /** A QUIC frame could not be parsed. */
72
+ export declare class FrameParseError extends Error {
73
+ readonly kind: "FrameParseError";
74
+ readonly offset: number;
75
+ readonly cause: Error | undefined;
76
+ constructor(offset: number, options?: {
77
+ cause?: Error;
78
+ });
79
+ }
80
+ /** The peer violated the transport parameters we advertised. */
81
+ export declare class TransportParameterError extends Error {
82
+ readonly kind: "TransportParameterError";
83
+ readonly parameter: number;
84
+ readonly cause: Error | undefined;
85
+ constructor(parameter: number, options?: {
86
+ cause?: Error;
87
+ });
88
+ }
89
+ /** A connection could not be established within the configured timeout. */
90
+ export declare class HandshakeTimeoutError extends Error {
91
+ readonly kind: "HandshakeTimeoutError";
92
+ readonly timeoutMs: number;
93
+ readonly cause: Error | undefined;
94
+ constructor(timeoutMs: number, options?: {
95
+ cause?: Error;
96
+ });
97
+ }
98
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,sCAAsC;AACtC,qBAAa,SAAU,SAAQ,KAAK;IAChC,SAAgB,IAAI,EAAG,WAAW,CAAU;IAC5C,SAAyB,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC;gBAEtC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,KAAK,CAAA;KAAE;CAK3D;AAED,oEAAoE;AACpE,qBAAa,qBAAsB,SAAQ,KAAK;IAC5C,SAAgB,IAAI,EAAG,uBAAuB,CAAU;IACxD,gFAAgF;IAChF,SAAgB,SAAS,EAAE,MAAM,CAAC;IAClC,mDAAmD;IACnD,SAAgB,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9C,oCAAoC;IACpC,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,SAAyB,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC;gBAG9C,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,KAAK,CAAA;KAAE;CAStD;AAED,mEAAmE;AACnE,qBAAa,gBAAiB,SAAQ,KAAK;IACvC,SAAgB,IAAI,EAAG,kBAAkB,CAAU;IACn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AAS,CAAC;gBAEtC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,KAAK,CAAA;KAAE;CAM1D;AAED,wCAAwC;AACxC,qBAAa,eAAgB,SAAQ,KAAK;IACtC,SAAgB,IAAI,EAAG,iBAAiB,CAAU;IAClD,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,SAAyB,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC;gBAEtC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,KAAK,CAAA;KAAE;CAM1D;AAED,gEAAgE;AAChE,qBAAa,uBAAwB,SAAQ,KAAK;IAC9C,SAAgB,IAAI,EAAG,yBAAyB,CAAU;IAC1D,SAAgB,SAAS,EAAE,MAAM,CAAC;IAClC,SAAyB,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC;gBAEtC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,KAAK,CAAA;KAAE;CAM7D;AAED,2EAA2E;AAC3E,qBAAa,qBAAsB,SAAQ,KAAK;IAC5C,SAAgB,IAAI,EAAG,uBAAuB,CAAU;IACxD,SAAgB,SAAS,EAAE,MAAM,CAAC;IAClC,SAAyB,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC;gBAEtC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,KAAK,CAAA;KAAE;CAM7D"}
package/dist/errors.js ADDED
@@ -0,0 +1,130 @@
1
+ /**
2
+ * Typed errors for @browsercore/quic.
3
+ *
4
+ * Errors are part of the API — every failure mode is an explicit type so callers
5
+ * can match on `kind` instead of parsing messages.
6
+ */
7
+ /** Base class for all QUIC errors. */
8
+ export class QuicError extends Error {
9
+ kind = "QuicError";
10
+ cause;
11
+ constructor(message, options) {
12
+ super(message, options);
13
+ this.name = new.target.name;
14
+ this.cause = options?.cause;
15
+ }
16
+ }
17
+ /** The peer closed the connection with a CONNECTION_CLOSE frame. */
18
+ export class ConnectionClosedError extends Error {
19
+ kind = "ConnectionClosedError";
20
+ /** Application error code (application-layer close) or transport error code. */
21
+ errorCode;
22
+ /** Frame type that triggered the close, if any. */
23
+ frameType;
24
+ /** Human-readable reason phrase. */
25
+ reason;
26
+ cause;
27
+ constructor(errorCode, reason, options) {
28
+ super(`CONNECTION_CLOSE: errorCode=${errorCode}, reason="${reason}"`);
29
+ this.name = "ConnectionClosedError";
30
+ this.errorCode = errorCode;
31
+ this.frameType = options?.frameType;
32
+ this.reason = reason;
33
+ this.cause = options?.cause;
34
+ }
35
+ }
36
+ /** The peer closed a specific stream with a STOP_SENDING frame. */
37
+ export class StopSendingError extends Error {
38
+ kind = "StopSendingError";
39
+ streamId;
40
+ errorCode;
41
+ cause;
42
+ constructor(streamId, errorCode, options) {
43
+ super(`STOP_SENDING on stream ${streamId}: errorCode=${errorCode}`);
44
+ this.name = "StopSendingError";
45
+ this.streamId = streamId;
46
+ this.errorCode = errorCode;
47
+ this.cause = options?.cause;
48
+ }
49
+ }
50
+ /** The peer reset a specific stream with a RESET_STREAM frame. */
51
+ export class ResetStreamError extends Error {
52
+ kind = "ResetStreamError";
53
+ streamId;
54
+ errorCode;
55
+ finalSize;
56
+ cause;
57
+ constructor(streamId, errorCode, finalSize, options) {
58
+ super(`RESET_STREAM on stream ${streamId}: errorCode=${errorCode}, finalSize=${finalSize}`);
59
+ this.name = "ResetStreamError";
60
+ this.streamId = streamId;
61
+ this.errorCode = errorCode;
62
+ this.finalSize = finalSize;
63
+ this.cause = options?.cause;
64
+ }
65
+ }
66
+ /** A flow-control window was violated (send exceeded the peer's limit). */
67
+ export class FlowControlError extends Error {
68
+ kind = "FlowControlError";
69
+ streamId;
70
+ limit;
71
+ attempted;
72
+ cause;
73
+ constructor(limit, attempted, streamId, options) {
74
+ super(`Flow control violation: attempted ${attempted} bytes against limit ${limit} (stream ${streamId ?? "connection"})`);
75
+ this.name = "FlowControlError";
76
+ this.streamId = streamId;
77
+ this.limit = limit;
78
+ this.attempted = attempted;
79
+ this.cause = options?.cause;
80
+ }
81
+ }
82
+ /** A packet could not be parsed from the wire. */
83
+ export class PacketParseError extends Error {
84
+ kind = "PacketParseError";
85
+ offset;
86
+ cause;
87
+ constructor(offset, options) {
88
+ super(`Packet parse error at offset ${offset}`);
89
+ this.name = "PacketParseError";
90
+ this.offset = offset;
91
+ this.cause = options?.cause;
92
+ }
93
+ }
94
+ /** A QUIC frame could not be parsed. */
95
+ export class FrameParseError extends Error {
96
+ kind = "FrameParseError";
97
+ offset;
98
+ cause;
99
+ constructor(offset, options) {
100
+ super(`Frame parse error at offset ${offset}`);
101
+ this.name = "FrameParseError";
102
+ this.offset = offset;
103
+ this.cause = options?.cause;
104
+ }
105
+ }
106
+ /** The peer violated the transport parameters we advertised. */
107
+ export class TransportParameterError extends Error {
108
+ kind = "TransportParameterError";
109
+ parameter;
110
+ cause;
111
+ constructor(parameter, options) {
112
+ super(`Transport parameter error: parameter=0x${parameter.toString(16)}`);
113
+ this.name = "TransportParameterError";
114
+ this.parameter = parameter;
115
+ this.cause = options?.cause;
116
+ }
117
+ }
118
+ /** A connection could not be established within the configured timeout. */
119
+ export class HandshakeTimeoutError extends Error {
120
+ kind = "HandshakeTimeoutError";
121
+ timeoutMs;
122
+ cause;
123
+ constructor(timeoutMs, options) {
124
+ super(`QUIC handshake not completed within ${timeoutMs}ms`);
125
+ this.name = "HandshakeTimeoutError";
126
+ this.timeoutMs = timeoutMs;
127
+ this.cause = options?.cause;
128
+ }
129
+ }
130
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,sCAAsC;AACtC,MAAM,OAAO,SAAU,SAAQ,KAAK;IAChB,IAAI,GAAG,WAAoB,CAAC;IACnB,KAAK,CAAoB;IAElD,YAAY,OAAe,EAAE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;QACpC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,KAAK,GAAG,OAAO,EAAE,KAAK,CAAC;IAChC,CAAC;CACJ"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * QUIC frame parser and serializer (RFC 9000 §12).
3
+ *
4
+ * Pure wire-format logic — no I/O. Frames are written into packets; the frame
5
+ * layer does not own the packet or the transport. Each frame is encoded as its
6
+ * type varint followed by type-specific fields. The reader functions consume
7
+ * bytes from a pull-based source so they can be driven by a packet reassembly
8
+ * buffer.
9
+ *
10
+ * STREAM frames (0x08–0x0f) are encoded with their off/len/fin flags folded
11
+ * into the type byte; the reader/writer handle that transparently.
12
+ */
13
+ import type { QuicFrame, QuicFrameTypeValue } from "../types.js";
14
+ import { QuicFrameType } from "../types.js";
15
+ export { QuicFrameType, type QuicFrame, type QuicFrameTypeValue, };
16
+ /** Serialize a single QUIC frame to wire bytes (type varint + fields). */
17
+ export declare function serializeFrame(frame: QuicFrame): Uint8Array;
18
+ /** Read frames from a pull-based byte source until it reports end-of-packet. */
19
+ export declare function readFrames(read: () => Promise<Uint8Array | null>): AsyncGenerator<QuicFrame, void, unknown>;
20
+ /** Decode a single frame given its type value and byte-reading helpers. */
21
+ export declare function decodeFrame(type: bigint, readVarint: () => Promise<bigint>, readBytes: (count: bigint) => Promise<Uint8Array>): Promise<QuicFrame>;
22
+ //# sourceMappingURL=frame.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"frame.d.ts","sourceRoot":"","sources":["../../src/frame/frame.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,aAAa,EAAkD,MAAM,aAAa,CAAC;AAI5F,OAAO,EACH,aAAa,EACb,KAAK,SAAS,EACd,KAAK,kBAAkB,GAC1B,CAAC;AAEF,0EAA0E;AAC1E,wBAAgB,cAAc,CAAC,KAAK,EAAE,SAAS,GAAG,UAAU,CA4I3D;AAED,gFAAgF;AAChF,wBAAgB,UAAU,CACtB,IAAI,EAAE,MAAM,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,GACvC,cAAc,CAAC,SAAS,EAAE,IAAI,EAAE,OAAO,CAAC,CA8D1C;AAED,2EAA2E;AAC3E,wBAAsB,WAAW,CAC7B,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,EACjC,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,UAAU,CAAC,GAClD,OAAO,CAAC,SAAS,CAAC,CAuLpB"}