@browsercore/quic 0.2.0 → 0.2.2
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/README.md +14 -9
- package/bin/coverage-md.mjs +99 -0
- package/dist/connection.d.ts +159 -24
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +490 -60
- package/dist/connection.js.map +1 -1
- package/dist/crypto/hash-length.d.ts +11 -0
- package/dist/crypto/hash-length.d.ts.map +1 -0
- package/dist/crypto/hash-length.js +20 -0
- package/dist/crypto/hash-length.js.map +1 -0
- package/dist/crypto/index.d.ts +8 -0
- package/dist/crypto/index.d.ts.map +1 -0
- package/dist/crypto/index.js +8 -0
- package/dist/crypto/index.js.map +1 -0
- package/dist/crypto/key-derivation.d.ts +86 -0
- package/dist/crypto/key-derivation.d.ts.map +1 -0
- package/dist/crypto/key-derivation.js +123 -0
- package/dist/crypto/key-derivation.js.map +1 -0
- package/dist/errors.d.ts +26 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +35 -0
- package/dist/errors.js.map +1 -1
- package/dist/frame/frame.d.ts.map +1 -1
- package/dist/frame/frame.js +2 -2
- package/dist/frame/frame.js.map +1 -1
- package/dist/handshake/index.d.ts +10 -0
- package/dist/handshake/index.d.ts.map +1 -0
- package/dist/handshake/index.js +9 -0
- package/dist/handshake/index.js.map +1 -0
- package/dist/handshake/quic-handshake.d.ts +73 -0
- package/dist/handshake/quic-handshake.d.ts.map +1 -0
- package/dist/handshake/quic-handshake.js +213 -0
- package/dist/handshake/quic-handshake.js.map +1 -0
- package/dist/handshake/quic-transport-adapter.d.ts +78 -0
- package/dist/handshake/quic-transport-adapter.d.ts.map +1 -0
- package/dist/handshake/quic-transport-adapter.js +140 -0
- package/dist/handshake/quic-transport-adapter.js.map +1 -0
- package/dist/index.d.ts +9 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -4
- package/dist/index.js.map +1 -1
- package/dist/packet/packet-protection.d.ts +158 -0
- package/dist/packet/packet-protection.d.ts.map +1 -0
- package/dist/packet/packet-protection.js +313 -0
- package/dist/packet/packet-protection.js.map +1 -0
- package/dist/packet/packet.d.ts +2 -2
- package/dist/packet/packet.d.ts.map +1 -1
- package/dist/packet/packet.js +4 -4
- package/dist/packet/packet.js.map +1 -1
- package/dist/stream/stream.d.ts.map +1 -1
- package/dist/stream/stream.js +10 -6
- package/dist/stream/stream.js.map +1 -1
- package/dist/types.d.ts +98 -41
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +27 -20
- package/dist/types.js.map +1 -1
- package/package.json +8 -4
package/README.md
CHANGED
|
@@ -14,15 +14,25 @@ Packet header parse/serialization (long + short headers), the full QUIC frame
|
|
|
14
14
|
set (RFC 9000 §12), variable-length integer encoding (RFC 9000 §16), per-stream
|
|
15
15
|
state machines, receive reassembly, and flow control (connection + stream
|
|
16
16
|
level). The package knows nothing about HTTP/3, TLS, or sockets — it composes
|
|
17
|
-
exclusively over an injected `DatagramTransport` and
|
|
17
|
+
exclusively over an injected `DatagramTransport` and an injected
|
|
18
|
+
`CryptoProvider` (see `QuicOptions.crypto`).
|
|
18
19
|
|
|
19
20
|
## What it does NOT know about
|
|
20
21
|
|
|
21
22
|
- HTTP/3, QPACK, or any application protocol
|
|
22
|
-
- TLS 1.3 / the QUIC handshake (key derivation lives in `@browsercore/crypto`)
|
|
23
23
|
- UDP, DNS, or sockets
|
|
24
24
|
- Browser fingerprints
|
|
25
25
|
|
|
26
|
+
## TLS handshake + packet protection (RFC 9001)
|
|
27
|
+
|
|
28
|
+
`connectQuic()` runs the @browsercore/tls 1.3 handshake over QUIC stream 0
|
|
29
|
+
(a bidirectional stream) and derives QUIC packet-protection secrets at each
|
|
30
|
+
key phase (initial / handshake / application). Inbound + outbound packets
|
|
31
|
+
are protected with AEAD payload encryption (AES-128/256-GCM, ChaCha20-Poly1305)
|
|
32
|
+
and header protection (AES-ECB mask). Pass `skipHandshake: true` to skip the
|
|
33
|
+
TLS handshake and return an *unprotected* connection (the data plane is fully
|
|
34
|
+
functional and testable with a fake datagram transport, but it is not wire-ready).
|
|
35
|
+
|
|
26
36
|
Higher layers compose exclusively through the `QuicConnection` interface. A
|
|
27
37
|
future `@browsercore/http3` opens bidirectional + unidirectional QUIC streams
|
|
28
38
|
and never touches QUIC internals. The production UDP transport **never** calls
|
|
@@ -113,10 +123,5 @@ outbound frames into short-header (1-RTT) packets.
|
|
|
113
123
|
|
|
114
124
|
## Known limitations
|
|
115
125
|
|
|
116
|
-
-
|
|
117
|
-
|
|
118
|
-
that moves *unprotected* frames over the transport — the data plane is fully
|
|
119
|
-
functional and unit-tested, but it is not wire-ready without a protection +
|
|
120
|
-
handshake layer on top.
|
|
121
|
-
- No congestion controller, no connection migration, no PATH_CHALLENGE /
|
|
122
|
-
PATH_RESPONSE beyond frame relay, and no liveness PING.
|
|
126
|
+
- No 0-RTT, no KeyUpdate, no connection migration beyond PATH_CHALLENGE /
|
|
127
|
+
PATH_RESPONSE, no congestion controller, and no liveness PING.
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Convert vitest's coverage-summary.json into a markdown coverage table.
|
|
4
|
+
*
|
|
5
|
+
* Run AFTER `vitest run --coverage` (with the json-summary reporter) so
|
|
6
|
+
* coverage-summary.json exists. Writes COVERAGE.md and coverage/badge.json to
|
|
7
|
+
* the current working directory (the consumer package root).
|
|
8
|
+
*
|
|
9
|
+
* Distributed as the `coverage-md` bin of @browsercore/dev, replacing the
|
|
10
|
+
* per-repo scripts/coverage-md.mjs copies.
|
|
11
|
+
*
|
|
12
|
+
* Dependency-free: only node:fs + node:path. Safe in CI with no install step.
|
|
13
|
+
*/
|
|
14
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
15
|
+
import { join, relative } from "node:path";
|
|
16
|
+
|
|
17
|
+
const pkgRoot = process.cwd();
|
|
18
|
+
const summaryPath = join(pkgRoot, "coverage", "coverage-summary.json");
|
|
19
|
+
const outPath = join(pkgRoot, "COVERAGE.md");
|
|
20
|
+
const badgePath = join(pkgRoot, "coverage", "badge.json");
|
|
21
|
+
|
|
22
|
+
/** @type {Record<string, { lines:{total:number,covered:number,pct:number}, statements:{total:number,covered:number,pct:number}, functions:{total:number,covered:number,pct:number}, branches:{total:number,covered:number,pct:number} }>} */
|
|
23
|
+
let data;
|
|
24
|
+
try {
|
|
25
|
+
data = JSON.parse(readFileSync(summaryPath, "utf-8"));
|
|
26
|
+
} catch {
|
|
27
|
+
console.error(
|
|
28
|
+
`[coverage-md] Could not read ${summaryPath}. ` +
|
|
29
|
+
`Run vitest with the json-summary reporter first.`,
|
|
30
|
+
);
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const total = data.total;
|
|
35
|
+
/**
|
|
36
|
+
* @typedef {Object} Metric
|
|
37
|
+
* @property {string} label
|
|
38
|
+
* @property {keyof typeof total} key
|
|
39
|
+
*/
|
|
40
|
+
/** @type {Metric[]} */
|
|
41
|
+
const metrics = [
|
|
42
|
+
{ label: "Statements", key: "statements" },
|
|
43
|
+
{ label: "Branches", key: "branches" },
|
|
44
|
+
{ label: "Functions", key: "functions" },
|
|
45
|
+
{ label: "Lines", key: "lines" },
|
|
46
|
+
];
|
|
47
|
+
/** @param {{pct:number,covered:number,total:number}} m */
|
|
48
|
+
const render = (m) => `${m.pct}% (${m.covered}/${m.total})`;
|
|
49
|
+
|
|
50
|
+
const fileEntries = Object.entries(data)
|
|
51
|
+
.filter(([key]) => key !== "total")
|
|
52
|
+
.map(([file, m]) => {
|
|
53
|
+
// coverage-summary.json keys are absolute paths; show repo-relative.
|
|
54
|
+
const rel = relative(pkgRoot, file).split("\\").join("/");
|
|
55
|
+
return { file: rel, m };
|
|
56
|
+
})
|
|
57
|
+
.sort((a, b) => a.file.localeCompare(b.file));
|
|
58
|
+
|
|
59
|
+
const lines = [];
|
|
60
|
+
lines.push(`# Coverage report`);
|
|
61
|
+
lines.push("");
|
|
62
|
+
lines.push(`Generated from \`coverage-summary.json\` by \`coverage-md\` (@browsercore/dev).`);
|
|
63
|
+
lines.push("");
|
|
64
|
+
lines.push(`## Total`);
|
|
65
|
+
lines.push("");
|
|
66
|
+
lines.push(`| Metric | Coverage |`);
|
|
67
|
+
lines.push(`| --- | --- |`);
|
|
68
|
+
for (const { label, key } of metrics) {
|
|
69
|
+
lines.push(`| ${label} | ${render(total[key])} |`);
|
|
70
|
+
}
|
|
71
|
+
lines.push("");
|
|
72
|
+
lines.push(`## Per-file`);
|
|
73
|
+
lines.push("");
|
|
74
|
+
const header = `| File | ${metrics.map((m) => m.label).join(" | ")} |`;
|
|
75
|
+
const sep = `| --- | ${metrics.map(() => "---").join(" | ")} |`;
|
|
76
|
+
lines.push(header);
|
|
77
|
+
lines.push(sep);
|
|
78
|
+
for (const { file, m } of fileEntries) {
|
|
79
|
+
lines.push(`| \`${file}\` | ${metrics.map((met) => render(m[met.key])).join(" | ")} |`);
|
|
80
|
+
}
|
|
81
|
+
lines.push("");
|
|
82
|
+
|
|
83
|
+
writeFileSync(outPath, lines.join("\n"));
|
|
84
|
+
console.log(`[coverage-md] wrote ${relative(process.cwd(), outPath)}`);
|
|
85
|
+
|
|
86
|
+
// shields.io endpoint badge: a single coverage figure (statements %) for the
|
|
87
|
+
// README badge. Color tiers mirror shields.io conventions.
|
|
88
|
+
const pct = total.statements.pct;
|
|
89
|
+
const badgeColor =
|
|
90
|
+
pct >= 90 ? "brightgreen" : pct >= 75 ? "green" : pct >= 50 ? "yellow" : "red";
|
|
91
|
+
const badge = {
|
|
92
|
+
schemaVersion: 1,
|
|
93
|
+
label: "coverage",
|
|
94
|
+
message: `${pct}%`,
|
|
95
|
+
color: badgeColor,
|
|
96
|
+
namedLogo: "vitest",
|
|
97
|
+
};
|
|
98
|
+
writeFileSync(badgePath, JSON.stringify(badge));
|
|
99
|
+
console.log(`[coverage-md] wrote ${relative(process.cwd(), badgePath)}`);
|
package/dist/connection.d.ts
CHANGED
|
@@ -1,28 +1,57 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* QUIC connection lifecycle + datagram read loop (RFC 9000 §5, §12)
|
|
2
|
+
* QUIC connection lifecycle + datagram read loop (RFC 9000 §5, §12) with TLS
|
|
3
|
+
* handshake + packet protection (RFC 9001).
|
|
3
4
|
*
|
|
4
|
-
* Wires packet header parsing/serialization, the frame layer,
|
|
5
|
-
* manager
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* Wires packet header parsing/serialization, the frame layer, the stream
|
|
6
|
+
* manager, the TLS 1.3 handshake (over QUIC stream 0), and QUIC's two-layer
|
|
7
|
+
* packet protection (AEAD payload encryption + header protection) over an
|
|
8
|
+
* injected {@link DatagramTransport} (UDP).
|
|
9
|
+
*
|
|
10
|
+
* The connection owns the read loop: it turns inbound datagrams into frames,
|
|
11
|
+
* dispatches each to the stream manager, and drains pending stream sends back
|
|
12
|
+
* into outbound packets. After the TLS handshake completes, every packet is
|
|
13
|
+
* protected with the derived QUIC keys for its key phase:
|
|
14
|
+
*
|
|
15
|
+
* Initial packets → initial keys (derived from DCID)
|
|
16
|
+
* Handshake packets → handshake keys (derived from TLS handshake secrets)
|
|
17
|
+
* 1-RTT packets → application keys (derived from TLS application secrets)
|
|
8
18
|
*
|
|
9
19
|
* Honest limitations:
|
|
10
|
-
* -
|
|
11
|
-
*
|
|
12
|
-
*
|
|
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 connection migration beyond PATH_CHALLENGE / PATH_RESPONSE, and no
|
|
16
|
-
* liveness PING.
|
|
20
|
+
* - 0-RTT, KeyUpdate, key-phase-bit handling, and connection migration
|
|
21
|
+
* beyond PATH_CHALLENGE / PATH_RESPONSE are out of scope. No congestion
|
|
22
|
+
* controller. No liveness PING.
|
|
17
23
|
*
|
|
18
24
|
* Concurrency model: the read loop is a single async task pulling datagrams from
|
|
19
25
|
* the transport. Outbound frames are produced synchronously by the stream
|
|
20
26
|
* manager and packed into packets; writes resolve once bytes are buffered.
|
|
21
27
|
*/
|
|
22
|
-
import type
|
|
23
|
-
import { type ConnectionId, type QuicConnection, type QuicFrame, type QuicOptions, type QuicStream, type QuicTransportParameters } from "./types.js";
|
|
28
|
+
import { type CryptoProvider } from "@browsercore/crypto";
|
|
29
|
+
import { type ConnectionId, type Logger, type QuicConnection, type QuicFrame, type QuicOptions, type QuicStream, type QuicTransportParameters } from "./types.js";
|
|
24
30
|
import { type StreamManager } from "./stream/stream.js";
|
|
25
31
|
import { type TransportParameters } from "./transport-params.js";
|
|
32
|
+
/**
|
|
33
|
+
* Events the stream manager emits for the connection layer to react to.
|
|
34
|
+
* Typed here (rather than depending on `node:events`'s untyped `EventEmitter`)
|
|
35
|
+
* so event payloads are known at the subscribe site.
|
|
36
|
+
*/
|
|
37
|
+
export interface ConnectionEvents {
|
|
38
|
+
/** The peer sent a CONNECTION_CLOSE frame. */
|
|
39
|
+
readonly connectionClose: {
|
|
40
|
+
readonly errorCode: bigint;
|
|
41
|
+
readonly reason: string;
|
|
42
|
+
};
|
|
43
|
+
/** The peer grew our connection send window via MAX_DATA. */
|
|
44
|
+
readonly maxData: bigint;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Minimal event-emitter surface the connection subscribes to. Defined here
|
|
48
|
+
* (rather than depending on `node:events`) so the connection layer stays
|
|
49
|
+
* decoupled from Node's EventEmitter — the stream manager satisfies this
|
|
50
|
+
* interface structurally through its `on` method.
|
|
51
|
+
*/
|
|
52
|
+
export interface ConnectionEventEmitter {
|
|
53
|
+
on<E extends keyof ConnectionEvents>(event: E, listener: (payload: ConnectionEvents[E]) => void): void;
|
|
54
|
+
}
|
|
26
55
|
/**
|
|
27
56
|
* Concrete QUIC connection. The public surface matches the fixed
|
|
28
57
|
* `QuicConnection` interface; internal state is kept on the instance.
|
|
@@ -33,20 +62,42 @@ export declare class QuicConnectionImpl implements QuicConnection {
|
|
|
33
62
|
private readonly transport;
|
|
34
63
|
/** The peer's UDP address. */
|
|
35
64
|
private readonly peer;
|
|
36
|
-
/** Stream manager (
|
|
65
|
+
/** Stream manager (emits connection-level signals). */
|
|
37
66
|
private readonly manager;
|
|
38
67
|
/** Our current destination connection id (the one we put on outbound packets). */
|
|
39
68
|
private readonly dcid;
|
|
69
|
+
/** Logging sink for lifecycle + frame diagnostics. */
|
|
70
|
+
private readonly logger;
|
|
71
|
+
/** Random source for connection ids and packet numbers. */
|
|
72
|
+
private readonly random;
|
|
73
|
+
/**
|
|
74
|
+
* Cryptographic provider for QUIC key derivation and packet protection
|
|
75
|
+
* (RFC 9001). Seeded with the injected {@link random} source so the
|
|
76
|
+
* HKDF-based key schedule is reproducible under test.
|
|
77
|
+
*/
|
|
78
|
+
private readonly cryptoProvider;
|
|
79
|
+
/** TLS ClientHello configuration for the handshake. */
|
|
80
|
+
private readonly tlsProfile;
|
|
40
81
|
/**
|
|
41
82
|
* Our transport parameters encoded for the wire. Produced at handshake
|
|
42
83
|
* time so a TLS layer can carry them to the peer in the QUIC extension.
|
|
43
84
|
*/
|
|
44
85
|
private readonly encodedLocalParameters;
|
|
86
|
+
/** Result of the TLS handshake — set once the handshake completes. */
|
|
87
|
+
private handshakeResult;
|
|
88
|
+
/**
|
|
89
|
+
* Current key phase for outbound packets. Advances from initial → handshake
|
|
90
|
+
* → application as the handshake progresses. The protection layer selects
|
|
91
|
+
* the correct secrets based on this + the packet's header form.
|
|
92
|
+
*/
|
|
93
|
+
private outboundKeyPhase;
|
|
94
|
+
/** Next outbound packet number, per key phase (RFC 9000 §12.3). */
|
|
95
|
+
private readonly nextPacketNumber;
|
|
96
|
+
/** Largest received packet number per key phase (for packet-number decoding). */
|
|
97
|
+
private readonly largestReceivedPn;
|
|
45
98
|
/**
|
|
46
99
|
* PATH_CHALLENGEs we have issued and are awaiting a PATH_RESPONSE for,
|
|
47
100
|
* keyed by the hex-encoded 8-byte challenge data (RFC 9000 §8.2.1).
|
|
48
|
-
* A full implementation would also track the address pair being validated
|
|
49
|
-
* and retire stale challenges on a timer; this is the data plane only.
|
|
50
101
|
*/
|
|
51
102
|
private readonly pendingPathChallenges;
|
|
52
103
|
/** Set once the connection begins graceful shutdown. */
|
|
@@ -55,7 +106,7 @@ export declare class QuicConnectionImpl implements QuicConnection {
|
|
|
55
106
|
private closed;
|
|
56
107
|
/** Buffered outbound frames waiting to be packed into the next packet. */
|
|
57
108
|
private readonly outboundFrames;
|
|
58
|
-
constructor(id: string, options: QuicOptions, manager: StreamManager &
|
|
109
|
+
constructor(id: string, options: QuicOptions, manager: StreamManager & ConnectionEventEmitter, dcid: ConnectionId, logger: Logger);
|
|
59
110
|
openBidirectionalStream(): Promise<QuicStream>;
|
|
60
111
|
acceptBidirectionalStream(): Promise<QuicStream>;
|
|
61
112
|
openUnidirectionalStream(): Promise<QuicStream>;
|
|
@@ -79,6 +130,12 @@ export declare class QuicConnectionImpl implements QuicConnection {
|
|
|
79
130
|
* reads these once and carries them to the peer in the QUIC extension.
|
|
80
131
|
*/
|
|
81
132
|
getEncodedLocalParameters(): Uint8Array;
|
|
133
|
+
/**
|
|
134
|
+
* The logging sink for this connection. A TLS handshake layer or test
|
|
135
|
+
* harness reads this to attach diagnostics, or to swap in a capturing
|
|
136
|
+
* logger — the connection itself stays agnostic to where log lines go.
|
|
137
|
+
*/
|
|
138
|
+
getLogger(): Logger;
|
|
82
139
|
/**
|
|
83
140
|
* Ingest the peer's transport parameters from their wire encoding. Decodes
|
|
84
141
|
* them and feeds them to the stream manager so its send windows match what
|
|
@@ -88,6 +145,19 @@ export declare class QuicConnectionImpl implements QuicConnection {
|
|
|
88
145
|
receivePeerParameters(peerWireParameters: Uint8Array): void;
|
|
89
146
|
/** Expose the wire-form peer parameters for inspection (tests, debugging). */
|
|
90
147
|
toWireParameters(params: QuicTransportParameters): TransportParameters;
|
|
148
|
+
/**
|
|
149
|
+
* Generate a random connection id of `length` bytes (RFC 9000 §5.1). Drawn
|
|
150
|
+
* from the injected random source so connection ids are reproducible under
|
|
151
|
+
* test. Useful for NEW_CONNECTION_ID frames and the endpoint's own source
|
|
152
|
+
* connection ids.
|
|
153
|
+
*/
|
|
154
|
+
generateConnectionId(length: number): ConnectionId;
|
|
155
|
+
/**
|
|
156
|
+
* The crypto provider for QUIC key derivation (RFC 9001). A handshake
|
|
157
|
+
* layer uses this to run the HKDF-based key schedule; it is seeded with the
|
|
158
|
+
* injected random source so derived keys are reproducible under test.
|
|
159
|
+
*/
|
|
160
|
+
getCrypto(): CryptoProvider;
|
|
91
161
|
/**
|
|
92
162
|
* Pack all buffered outbound frames into a short-header packet and send it.
|
|
93
163
|
* Splits into multiple datagrams if the payload exceeds MAX_DATAGRAM_PAYLOAD.
|
|
@@ -95,8 +165,45 @@ export declare class QuicConnectionImpl implements QuicConnection {
|
|
|
95
165
|
private flush;
|
|
96
166
|
/** Serialize frames into a single byte buffer (no packet header). */
|
|
97
167
|
private packFrames;
|
|
98
|
-
/**
|
|
168
|
+
/**
|
|
169
|
+
* Wrap a serialized payload in a packet header + protect it.
|
|
170
|
+
*
|
|
171
|
+
* Selects long vs short header based on the current handshake state:
|
|
172
|
+
* - Before the handshake is complete: long-header Initial / Handshake packets.
|
|
173
|
+
* - After: short-header (1-RTT) packets.
|
|
174
|
+
*
|
|
175
|
+
* For now, we always emit short-header (1-RTT) packets once the handshake
|
|
176
|
+
* is complete, and long-header Handshake packets during the handshake.
|
|
177
|
+
* The very first packets (ClientHello) are also carried in Handshake packets
|
|
178
|
+
* by this simplified implementation — a full client would send the
|
|
179
|
+
* ClientHello in an Initial packet with a token, but the protection layer
|
|
180
|
+
* is identical.
|
|
181
|
+
*/
|
|
99
182
|
private wrapPacket;
|
|
183
|
+
/**
|
|
184
|
+
* Wrap a payload in a simple unprotected short-header packet — the original
|
|
185
|
+
* behavior for tests that don't exercise the TLS handshake + protection layer.
|
|
186
|
+
*/
|
|
187
|
+
private wrapPacketUnprotectedShort;
|
|
188
|
+
/** Wrap a payload in a protected packet using the given key-phase secrets. */
|
|
189
|
+
private wrapPacketProtected;
|
|
190
|
+
/**
|
|
191
|
+
* Wrap a payload in an *unprotected* packet — used only before the TLS
|
|
192
|
+
* handshake has produced keys (e.g. in tests that don't exercise the
|
|
193
|
+
* protection layer). A production build would never emit these.
|
|
194
|
+
*/
|
|
195
|
+
private wrapPacketUnprotected;
|
|
196
|
+
/**
|
|
197
|
+
* Get the QUIC protection secrets for a given key phase. Returns undefined
|
|
198
|
+
* if the handshake has not yet produced keys for that phase (e.g. before
|
|
199
|
+
* the TLS handshake has started).
|
|
200
|
+
*/
|
|
201
|
+
private getProtectionSecrets;
|
|
202
|
+
/**
|
|
203
|
+
* Run the TLS 1.3 handshake over QUIC stream 0 and derive QUIC packet-
|
|
204
|
+
* protection secrets at each key phase.
|
|
205
|
+
*/
|
|
206
|
+
performHandshake(): Promise<void>;
|
|
100
207
|
/**
|
|
101
208
|
* Start the datagram read loop. Must be called once after construction.
|
|
102
209
|
* Runs until the transport closes or the connection tears down.
|
|
@@ -105,7 +212,28 @@ export declare class QuicConnectionImpl implements QuicConnection {
|
|
|
105
212
|
private onPeerClose;
|
|
106
213
|
/** Parse a single datagram into frames and dispatch them. */
|
|
107
214
|
private dispatchDatagram;
|
|
108
|
-
/**
|
|
215
|
+
/**
|
|
216
|
+
* Dispatch an unprotected datagram — the original behavior for tests that
|
|
217
|
+
* don't exercise the TLS handshake + protection layer. Parses the packet
|
|
218
|
+
* header and decodes frames directly, matching the pre-handshake read loop.
|
|
219
|
+
*/
|
|
220
|
+
private dispatchDatagramUnprotected;
|
|
221
|
+
/** Apply a parsed header (unprotected path) into connection state. */
|
|
222
|
+
private applyHeaderUnprotected;
|
|
223
|
+
/**
|
|
224
|
+
* Determine the key phase of an inbound packet from its first byte.
|
|
225
|
+
*
|
|
226
|
+
* Long headers: Initial (0b00) → initial, Handshake (0b10) → handshake,
|
|
227
|
+
* Retry/0-RTT → initial (we treat them as initial-key for simplicity).
|
|
228
|
+
* Short headers: application (1-RTT).
|
|
229
|
+
*/
|
|
230
|
+
private classifyKeyPhase;
|
|
231
|
+
/**
|
|
232
|
+
* Decrypt the packet number and remove header protection from an inbound
|
|
233
|
+
* packet. Returns the recovered packet number and the decrypted header.
|
|
234
|
+
*/
|
|
235
|
+
private unprotectHeader;
|
|
236
|
+
/** Header fields after header-protection removal. */
|
|
109
237
|
private applyHeader;
|
|
110
238
|
/**
|
|
111
239
|
* Build a pull-based byte reader over a fixed buffer. `readFrames` consumes
|
|
@@ -129,10 +257,17 @@ export declare class QuicConnectionImpl implements QuicConnection {
|
|
|
129
257
|
/**
|
|
130
258
|
* Establish a QUIC connection over an existing datagram transport.
|
|
131
259
|
*
|
|
132
|
-
* Creates the stream manager and the read loop.
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
260
|
+
* Creates the stream manager and the read loop. By default, runs the TLS 1.3
|
|
261
|
+
* handshake over QUIC stream 0 (a bidirectional stream), derives QUIC packet-
|
|
262
|
+
* protection secrets at each key phase, and returns a connection that protects
|
|
263
|
+
* inbound + outbound packets with the derived keys.
|
|
264
|
+
*
|
|
265
|
+
* The `tlsProfile` option selects the ClientHello configuration for the
|
|
266
|
+
* handshake. Defaults to a modern TLS 1.3 profile (X25519 + secp256r1 key
|
|
267
|
+
* shares, AES-256/128-GCM + ChaCha20-Poly1305). Set `skipHandshake: true` to
|
|
268
|
+
* skip the TLS handshake and return an *unprotected* connection (the data plane
|
|
269
|
+
* is fully functional and testable with a fake datagram transport, but it is
|
|
270
|
+
* not wire-ready without a protection + handshake layer on top).
|
|
136
271
|
*/
|
|
137
272
|
export declare function connectQuic(options: QuicOptions): Promise<QuicConnection>;
|
|
138
273
|
//# sourceMappingURL=connection.d.ts.map
|
package/dist/connection.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"conn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