@browsercore/contracts 0.2.4 → 0.2.6

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.
@@ -0,0 +1,317 @@
1
+ /**
2
+ * TLS handshake engine contracts — the seam that lets QUIC drive a TLS
3
+ * handshake without importing `@browsercore/tls`.
4
+ *
5
+ * Why this module exists (replaceability audit 2026-11-16, remediation
6
+ * item #2): `@browsercore/quic` RUNTIME-EMBEDS the tls handshake engine —
7
+ * `runHandshake` / `generateKeyShares` / `cipherSuiteToAead` plus twelve
8
+ * types imported directly from `@browsercore/tls`
9
+ * (`quic/src/handshake/quic-handshake.ts`) — the one true protocol→protocol
10
+ * engine coupling in the stack, and the only violation of the no-hard-wires
11
+ * invariant ("protocol packages must never import each other directly; all
12
+ * inter-package communication flows through Platform interfaces defined in
13
+ * @browsercore/contracts").
14
+ *
15
+ * The fix shape: `@browsercore/tls` implements
16
+ * {@link TlsHandshakeEngine} and the composition root (browsersmith) injects
17
+ * it into quic via options, exactly like crypto/transport/events — quic
18
+ * consumes this interface, never the tls package directly. The pattern is
19
+ * already proven end-to-end by http3's fake-quic compatibility test
20
+ * (`http3/tests/fake-quic.ts`): a local structural implementation satisfying
21
+ * the consumer's contract is the sanctioned way to swap an engine.
22
+ *
23
+ * Shape derivation: every operation and type below is exactly what quic
24
+ * CALLS and the data it passes/receives on the real code path
25
+ * (`quic-handshake.ts` imports `runHandshake`, `generateKeyShares`,
26
+ * `cipherSuiteToAead` and the types `AeadAlgorithm`, `CipherSuite`,
27
+ * `ClientHelloConfig`, `ServerHello`, `Certificate`, `TrafficSecrets`,
28
+ * `HandshakeContext`, `HandshakePhase`, `AlertLevel`; `KeyPair` and
29
+ * `ApplicationTrafficSecrets` ride along as the callback/return data).
30
+ * Division of labor: quic implements the context itself (its
31
+ * `QuicHandshakeContext` — the consumer-side SPI), so
32
+ * {@link TlsHandshakeContext} here describes only the structural data
33
+ * surface the engine reads and mutates; the engine implements
34
+ * {@link TlsHandshakeEngine}. `HandshakeContext` AS A TYPE stays
35
+ * consumer-side (quic's class keeps implementing it structurally); nothing
36
+ * here is a class or carries runtime behavior.
37
+ *
38
+ * All shapes are pure data / function signatures — no runtime, no node:*.
39
+ */
40
+ import type { CryptoProvider, Transport } from "./contracts.js";
41
+ import type { HashId } from "./models.js";
42
+ /** TLS 1.3 AEAD algorithms used by record protection (TLS 1.3 only negotiates these four). */
43
+ export type AeadAlgorithm = "AES-128-GCM" | "AES-256-GCM" | "AES-128-CCM" | "CHACHA20-POLY1305";
44
+ /**
45
+ * A TLS cipher suite: string-literal union, never bare string.
46
+ *
47
+ * Covers every suite the shipped browser profiles OFFER (the four TLS 1.3
48
+ * AEAD suites plus the TLS 1.2 suites and GREASE placeholder real browsers
49
+ * place in the offered list); the NEGOTIATED suite is always one of the four
50
+ * AEAD suites. Keyed by the same canonical names as
51
+ * {@link ../models.js~CIPHER_SUITE_CODES}.
52
+ */
53
+ export type CipherSuite = "TLS_GREASE_RESERVED_0" | "TLS_AES_128_GCM_SHA256" | "TLS_AES_256_GCM_SHA384" | "TLS_CHACHA20_POLY1305_SHA256" | "TLS_AES_128_CCM_SHA256" | "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256" | "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256" | "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384" | "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384" | "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256" | "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256" | "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA" | "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA" | "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA" | "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA" | "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256" | "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384" | "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256" | "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384" | "TLS_RSA_WITH_AES_128_GCM_SHA256" | "TLS_RSA_WITH_AES_256_GCM_SHA384" | "TLS_RSA_WITH_AES_128_CBC_SHA" | "TLS_RSA_WITH_AES_256_CBC_SHA" | "TLS_RSA_WITH_AES_128_CBC_SHA256" | "TLS_RSA_WITH_AES_256_CBC_SHA256" | "TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA" | "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA" | "TLS_RSA_WITH_3DES_EDE_CBC_SHA";
54
+ /** Named groups for key exchange (ECDHE / hybrid PQ), IANA canonical names. */
55
+ export type NamedGroup = "secp256r1" | "secp384r1" | "secp521r1" | "x25519" | "x448" | "ffdhe2048" | "ffdhe3072" | "X25519MLKEM768" | "X25519Kyber768";
56
+ /** Signature algorithms accepted in CertificateVerify (IANA canonical names). */
57
+ export type SignatureScheme = "ecdsa_secp256r1_sha256" | "ecdsa_secp384r1_sha384" | "ecdsa_secp521r1_sha512" | "ecdsa_sha1" | "ed25519" | "rsa_pss_rsae_sha256" | "rsa_pss_rsae_sha384" | "rsa_pss_rsae_sha512" | "rsa_pkcs1_sha256" | "rsa_pkcs1_sha384" | "rsa_pkcs1_sha512" | "rsa_pkcs1_sha1";
58
+ /**
59
+ * A TLS protocol version — name plus IANA wire code as a discriminated pair
60
+ * (the wire code is what the supported_versions extension carries).
61
+ */
62
+ export type ProtocolVersion = {
63
+ readonly name: "TLS 1.2";
64
+ readonly wire: 0x0303;
65
+ } | {
66
+ readonly name: "TLS 1.3";
67
+ readonly wire: 0x0304;
68
+ };
69
+ /**
70
+ * ClientHello configuration — the fingerprint-driven offer.
71
+ *
72
+ * Pure data: the offered cipher suites, exact extension order, GREASE flag,
73
+ * key-share groups, signature algorithms, supported versions, SNI, and ALPN.
74
+ * Higher layers (fetch) translate a `BrowserProfile` into this shape. quic's
75
+ * options surface keeps its own wider `ClientHelloConfigLike` mirror
76
+ * (plain-string lists) and converts to this typed shape at the engine call.
77
+ */
78
+ export interface ClientHelloConfig {
79
+ /** Ordered list of cipher suites the client advertises (most-preferred first). */
80
+ readonly cipherSuites: readonly CipherSuite[];
81
+ /**
82
+ * Extension types in the exact order they must appear in the ClientHello.
83
+ * Every type present here is emitted; anything absent is omitted. This is
84
+ * the primary fingerprinting signal, so the order is load-bearing.
85
+ */
86
+ readonly extensionOrder: readonly number[];
87
+ /** Named groups for key share, ordered by preference. */
88
+ readonly keyShareGroups: readonly NamedGroup[];
89
+ /**
90
+ * Named groups ADVERTISED in supported_groups when the advertised set
91
+ * differs from the groups actually shared in key_share (real Chrome
92
+ * advertises a wider set than it key-shares). When omitted,
93
+ * supported_groups is derived from {@link keyShareGroups}.
94
+ */
95
+ readonly supportedGroups?: readonly NamedGroup[];
96
+ /** Signature algorithms the client accepts in CertificateVerify. */
97
+ readonly signatureAlgorithms: readonly SignatureScheme[];
98
+ /** Protocol versions the client advertises via supported_versions. */
99
+ readonly supportedVersions: readonly ProtocolVersion[];
100
+ /** Server Name Indication hostname (SNI). */
101
+ readonly serverName: string;
102
+ /** ALPN protocols the client wishes to negotiate (e.g. "h2", "h3"). */
103
+ readonly alpnProtocols?: readonly string[];
104
+ /** Whether to inject GREASE (RFC 8701) sentinel values. */
105
+ readonly grease: boolean;
106
+ /**
107
+ * EC point formats offered in the `ec_point_formats` extension (wire byte
108
+ * values). Omit for the default (uncompressed only).
109
+ */
110
+ readonly ecPointFormats?: readonly number[];
111
+ /**
112
+ * Algorithm IDs offered in the `compress_certificate` extension
113
+ * (RFC 8879), as 16-bit IANA wire values. Omit for the default `[2]`
114
+ * (brotli).
115
+ */
116
+ readonly compressCertificateAlgorithms?: readonly number[];
117
+ /**
118
+ * Target ClientHello message length in bytes for the PADDING extension
119
+ * (RFC 7685). Omit to disable padding.
120
+ */
121
+ readonly recordPadding?: number;
122
+ }
123
+ /** A parsed ServerHello — the first handshake message the server sends. */
124
+ export interface ServerHello {
125
+ /**
126
+ * Legacy protocol version (always 0x0303 in TLS 1.3, for middlebox
127
+ * compatibility). The real negotiated version is {@link selectedVersion}.
128
+ */
129
+ readonly protocolVersion: number;
130
+ readonly random: Uint8Array;
131
+ readonly sessionId: Uint8Array;
132
+ readonly cipherSuite: CipherSuite;
133
+ readonly compressionMethod: number;
134
+ /**
135
+ * The protocol version the server actually negotiated, from the
136
+ * supported_versions extension. This is the authoritative version.
137
+ */
138
+ readonly selectedVersion: ProtocolVersion;
139
+ /** Raw, undecoded ServerHello extensions bytes. */
140
+ readonly extensions: Uint8Array;
141
+ }
142
+ /**
143
+ * A parsed X.509 certificate (validation-relevant fields only) — pure data.
144
+ * The engine writes the validated leaf into the context's `peerCertificate`.
145
+ */
146
+ export interface Certificate {
147
+ /** DER-encoded TBSCertificate bytes, needed for signature verification. */
148
+ readonly tbsBytes: Uint8Array;
149
+ /** DER-encoded SubjectPublicKeyInfo. */
150
+ readonly subjectPublicKeyInfo: Uint8Array;
151
+ /** Subject alternative DNS names (from the SAN extension), if any. */
152
+ readonly subjectAltNames: readonly string[];
153
+ /** Common Name from the subject DN, if present (legacy hostname match). */
154
+ readonly commonName?: string;
155
+ /** Not-before timestamp (epoch seconds). */
156
+ readonly notBefore: number;
157
+ /** Not-after timestamp (epoch seconds). */
158
+ readonly notAfter: number;
159
+ /** True if the certificate has the keyUsage bit for digital signature. */
160
+ readonly keyUsageDigitalSignature: boolean;
161
+ /** True if the certificate has the keyUsage bit for key encipherment/agreement. */
162
+ readonly keyUsageKeyEncipherment: boolean;
163
+ /** Signature algorithm used by the issuer over the TBSCertificate. */
164
+ readonly signatureScheme: SignatureScheme;
165
+ /** Raw signature value from the issuer. */
166
+ readonly signatureValue: Uint8Array;
167
+ /** DER-encoded SubjectPublicKeyInfo of the issuer (for chain building). */
168
+ readonly issuer: string;
169
+ /** True for a CA certificate. */
170
+ readonly isCa: boolean;
171
+ }
172
+ /**
173
+ * A key share for one named group — the data `generateKeyShares` returns.
174
+ * `privateKey` is opaque to the consumer; the engine consumes it during the
175
+ * handshake.
176
+ */
177
+ export interface KeyPair {
178
+ readonly algorithm: NamedGroup;
179
+ /** Private key bytes (opaque to the consumer of the engine). */
180
+ readonly privateKey: Uint8Array;
181
+ /** Public key bytes, as they appear in a KeyShareEntry. */
182
+ readonly publicKey: Uint8Array;
183
+ }
184
+ /** Traffic secrets derived by the TLS 1.3 key schedule for one direction. */
185
+ export interface TrafficSecrets {
186
+ /** AEAD key for this direction. */
187
+ readonly key: Uint8Array;
188
+ /** AEAD IV (often called "write_iv") for this direction. */
189
+ readonly iv: Uint8Array;
190
+ }
191
+ /** Full set of application traffic secrets for both directions after the handshake. */
192
+ export interface ApplicationTrafficSecrets {
193
+ readonly client: TrafficSecrets;
194
+ readonly server: TrafficSecrets;
195
+ }
196
+ /**
197
+ * The handshake phase at which the engine currently is — granular enough
198
+ * that a timeout or error names exactly which step was in progress. The
199
+ * consumer exposes it as `currentPhase` on the context for error attribution.
200
+ */
201
+ export type HandshakePhase = "init" | "client_hello" | "server_hello" | "key_exchange" | "encrypted_extensions" | "certificate" | "certificate_verify" | "finished" | "client_finished" | "application";
202
+ /** Alert level of a TLS alert, per RFC 8446 §6. */
203
+ export type AlertLevel = "warning" | "fatal";
204
+ /**
205
+ * `TlsHandshakeContext` — the slice of consumer state the handshake engine
206
+ * reads and mutates while driving a handshake to completion.
207
+ *
208
+ * Implemented by the CONSUMER: quic's `QuicHandshakeContext` satisfies this
209
+ * structurally today (against tls's local `HandshakeContext`, whose shape is
210
+ * identical where it matters), which is why the fields are mutable — the
211
+ * engine mutates the context's negotiated parameters and secrets in place,
212
+ * and the consumer reads them after `runHandshake` resolves (quic then
213
+ * derives its QUIC packet-protection keys from the intermediate secrets).
214
+ * The full tls-local `HandshakeContext` type stays consumer/implementer-side;
215
+ * this is the contract-level structural description of the same surface.
216
+ *
217
+ * The `compression` field is deliberately the structural slice
218
+ * `{ brotliDecompress }` (RFC 8879 CompressedCertificate) rather than
219
+ * {@link CompressionProvider}: quic already declares it that way
220
+ * structurally, and it keeps this module decoupled from the compression
221
+ * contract. QUIC never advertises compress_certificate, so quic's value is
222
+ * always `undefined`.
223
+ */
224
+ export interface TlsHandshakeContext {
225
+ /** The byte-stream transport the handshake runs over (e.g. QUIC stream 0). */
226
+ readonly transport: Transport;
227
+ /** Cryptographic provider, injected by the consumer (no default). */
228
+ crypto: CryptoProvider;
229
+ /**
230
+ * Brotli decompression for RFC 8879 CompressedCertificate (type 25).
231
+ * `undefined` when the consumer did not advertise compress_certificate —
232
+ * the server must then never send a compressed certificate.
233
+ */
234
+ compression: {
235
+ brotliDecompress(data: Uint8Array): Uint8Array;
236
+ } | undefined;
237
+ /** Mutable: buffered bytes not yet consumed by the record framer. */
238
+ readBuffer: Uint8Array;
239
+ /** Mutable: running transcript of full handshake messages. */
240
+ readonly transcript: Uint8Array[];
241
+ /** Mutable: negotiated cipher suite plus the derived AEAD and hash. */
242
+ cipherSuite: CipherSuite;
243
+ aead: AeadAlgorithm;
244
+ hash: HashId;
245
+ /** Mutable: parsed ServerHello, set when it arrives. */
246
+ serverHello: ServerHello;
247
+ /** Mutable: handshake traffic secrets (per direction) and the raw secrets. */
248
+ clientHsTraffic: TrafficSecrets;
249
+ serverHsTraffic: TrafficSecrets;
250
+ clientHsTrafficSecret: Uint8Array;
251
+ serverHsTrafficSecret: Uint8Array;
252
+ masterSecret: Uint8Array;
253
+ /**
254
+ * Mutable: raw application traffic secrets, set when the engine derives
255
+ * them. Retained so the consumer can rotate keys on KeyUpdate
256
+ * (RFC 8446 §4.6.3) — and so quic can derive its 1-RTT keys.
257
+ */
258
+ clientAppSecret: Uint8Array;
259
+ serverAppSecret: Uint8Array;
260
+ /** Mutable: handshake-direction record sequence counters. */
261
+ clientHsSeq: number;
262
+ serverHsSeq: number;
263
+ /** True once the handshake traffic secrets have been derived (sendAlert gate). */
264
+ hsTrafficReady: boolean;
265
+ /** Set when the server negotiates ALPN in EncryptedExtensions. */
266
+ alpnProtocol?: string | undefined;
267
+ /** Set to the validated leaf once the Certificate message is consumed. */
268
+ peerCertificate?: Certificate | undefined;
269
+ /** Mutable: the handshake phase currently in progress (error attribution). */
270
+ currentPhase: HandshakePhase;
271
+ /** Optional debug trace callback — one line before/after each I/O and crypto step. */
272
+ onDebug: ((msg: string) => void) | undefined;
273
+ /**
274
+ * Send a TLS alert (RFC 8446 §6) to the peer. Best-effort. QUIC signals
275
+ * transport-level errors via CONNECTION_CLOSE (RFC 9001 §4.8), so its
276
+ * implementation is a no-op — the hook exists for TLS-over-TCP consumers.
277
+ */
278
+ sendAlert(level: AlertLevel, description: number): Promise<void>;
279
+ }
280
+ /**
281
+ * `TlsHandshakeEngine` — the injected TLS 1.3 handshake engine.
282
+ *
283
+ * Implemented by `@browsercore/tls` (wired at the composition root into
284
+ * quic's options); quic consumes this, never the tls package directly
285
+ * (no-hard-wires invariant). Each operation below is exactly the function
286
+ * quic's handshake orchestration calls on `@browsercore/tls` today —
287
+ * signatures lifted verbatim so the tls implementation satisfies this
288
+ * interface without adaptation.
289
+ */
290
+ export interface TlsHandshakeEngine {
291
+ /**
292
+ * Drive the TLS 1.3 handshake to completion against `ctx`.
293
+ *
294
+ * The engine mutates the context's negotiated parameters and secrets
295
+ * (including the INTERMEDIATE handshake secrets quic needs for its key
296
+ * phases) and resolves with the final application traffic secrets.
297
+ *
298
+ * @param ctx Consumer-implemented state (see {@link TlsHandshakeContext}).
299
+ * @param config ClientHello configuration (the fingerprint offer).
300
+ * @param serverName SNI hostname (for SNI + certificate validation).
301
+ * @param trustAnchors Trust anchors (PEM/DER) for certificate validation.
302
+ * @param generateKeyShares Key-share generator — `(groups) => Promise<KeyPair[]>`;
303
+ * the consumer injects its crypto provider here
304
+ * (quic: `(groups) => engine.generateKeyShares(groups, crypto)`).
305
+ * @param now Current epoch SECONDS (injected so cert validation stays deterministic).
306
+ */
307
+ runHandshake(ctx: TlsHandshakeContext, config: ClientHelloConfig, serverName: string, trustAnchors: readonly Uint8Array[], generateKeyShares: (groups: readonly string[]) => Promise<KeyPair[]>, now: number): Promise<ApplicationTrafficSecrets>;
308
+ /**
309
+ * Generate key shares for the requested groups (all offered groups,
310
+ * including post-quantum hybrids). Delegates to the injected crypto
311
+ * provider; quic wraps this into its `runHandshake` callback.
312
+ */
313
+ generateKeyShares(groups: readonly string[], crypto: CryptoProvider): Promise<KeyPair[]>;
314
+ /** Map a TLS cipher suite to its AEAD algorithm (exhaustive over TLS 1.3 suites). */
315
+ cipherSuiteToAead(cipherSuite: CipherSuite): AeadAlgorithm;
316
+ }
317
+ //# sourceMappingURL=tls-engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tls-engine.d.ts","sourceRoot":"","sources":["../src/tls-engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAY1C,8FAA8F;AAC9F,MAAM,MAAM,aAAa,GACnB,aAAa,GACb,aAAa,GACb,aAAa,GACb,mBAAmB,CAAC;AAE1B;;;;;;;;GAQG;AACH,MAAM,MAAM,WAAW,GACjB,uBAAuB,GACvB,wBAAwB,GACxB,wBAAwB,GACxB,8BAA8B,GAC9B,wBAAwB,GACxB,yCAAyC,GACzC,uCAAuC,GACvC,yCAAyC,GACzC,uCAAuC,GACvC,+CAA+C,GAC/C,6CAA6C,GAC7C,oCAAoC,GACpC,oCAAoC,GACpC,sCAAsC,GACtC,sCAAsC,GACtC,yCAAyC,GACzC,yCAAyC,GACzC,uCAAuC,GACvC,uCAAuC,GACvC,iCAAiC,GACjC,iCAAiC,GACjC,8BAA8B,GAC9B,8BAA8B,GAC9B,iCAAiC,GACjC,iCAAiC,GACjC,uCAAuC,GACvC,qCAAqC,GACrC,+BAA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ACnC,iBAAiB,EAAE,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,KAAK,OAAO,CAAC,OAAO,EAAE,CAAC,EACpE,GAAG,EAAE,MAAM,GACZ,OAAO,CAAC,yBAAyB,CAAC,CAAC;IAEtC;;;;OAIG;IACH,iBAAiB,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,EAAE,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IAEzF,qFAAqF;IACrF,iBAAiB,CAAC,WAAW,EAAE,WAAW,GAAG,aAAa,CAAC;CAC9D"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * TLS handshake engine contracts — the seam that lets QUIC drive a TLS
3
+ * handshake without importing `@browsercore/tls`.
4
+ *
5
+ * Why this module exists (replaceability audit 2026-11-16, remediation
6
+ * item #2): `@browsercore/quic` RUNTIME-EMBEDS the tls handshake engine —
7
+ * `runHandshake` / `generateKeyShares` / `cipherSuiteToAead` plus twelve
8
+ * types imported directly from `@browsercore/tls`
9
+ * (`quic/src/handshake/quic-handshake.ts`) — the one true protocol→protocol
10
+ * engine coupling in the stack, and the only violation of the no-hard-wires
11
+ * invariant ("protocol packages must never import each other directly; all
12
+ * inter-package communication flows through Platform interfaces defined in
13
+ * @browsercore/contracts").
14
+ *
15
+ * The fix shape: `@browsercore/tls` implements
16
+ * {@link TlsHandshakeEngine} and the composition root (browsersmith) injects
17
+ * it into quic via options, exactly like crypto/transport/events — quic
18
+ * consumes this interface, never the tls package directly. The pattern is
19
+ * already proven end-to-end by http3's fake-quic compatibility test
20
+ * (`http3/tests/fake-quic.ts`): a local structural implementation satisfying
21
+ * the consumer's contract is the sanctioned way to swap an engine.
22
+ *
23
+ * Shape derivation: every operation and type below is exactly what quic
24
+ * CALLS and the data it passes/receives on the real code path
25
+ * (`quic-handshake.ts` imports `runHandshake`, `generateKeyShares`,
26
+ * `cipherSuiteToAead` and the types `AeadAlgorithm`, `CipherSuite`,
27
+ * `ClientHelloConfig`, `ServerHello`, `Certificate`, `TrafficSecrets`,
28
+ * `HandshakeContext`, `HandshakePhase`, `AlertLevel`; `KeyPair` and
29
+ * `ApplicationTrafficSecrets` ride along as the callback/return data).
30
+ * Division of labor: quic implements the context itself (its
31
+ * `QuicHandshakeContext` — the consumer-side SPI), so
32
+ * {@link TlsHandshakeContext} here describes only the structural data
33
+ * surface the engine reads and mutates; the engine implements
34
+ * {@link TlsHandshakeEngine}. `HandshakeContext` AS A TYPE stays
35
+ * consumer-side (quic's class keeps implementing it structurally); nothing
36
+ * here is a class or carries runtime behavior.
37
+ *
38
+ * All shapes are pure data / function signatures — no runtime, no node:*.
39
+ */
40
+ export {};
41
+ //# sourceMappingURL=tls-engine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tls-engine.js","sourceRoot":"","sources":["../src/tls-engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@browsercore/contracts",
3
- "version": "0.2.4",
4
- "description": "Shared interfaces, models, and options for the browsercore stack",
3
+ "version": "0.2.6",
4
+ "description": "Shared interfaces and models for the browsercore stack",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/jverneuer/browsercore-contracts.git"
@@ -33,7 +33,7 @@
33
33
  "clean": "rm -rf dist",
34
34
  "build": "tsc -p tsconfig.json",
35
35
  "prepublishOnly": "npm run clean && npm run build",
36
- "typecheck": "tsc -p tsconfig.json --noEmit",
36
+ "typecheck": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.test.json --noEmit",
37
37
  "test": "vitest run",
38
38
  "lint": "oxlint --type-aware src/"
39
39
  },
package/dist/options.d.ts DELETED
@@ -1,51 +0,0 @@
1
- /**
2
- * Options — configuration for protocol packages.
3
- *
4
- * Each protocol package accepts an options object that implements one of
5
- * these interfaces. Options are implementation-independent configuration
6
- * that gets passed down from consumers like browsersmith.
7
- */
8
- import type { Transport, DatagramTransport, QuicConnection, PacketCallback, CookieJar } from "./contracts.js";
9
- import type { Clock } from "./time.js";
10
- import type { BrowserProfile, UdpAddress } from "./models.js";
11
- export interface TlsOptions {
12
- readonly transport: Transport;
13
- readonly profile: BrowserProfile;
14
- readonly serverName: string;
15
- readonly clock?: Clock;
16
- readonly onPacket?: PacketCallback;
17
- }
18
- export interface Http1Options {
19
- readonly transport: Transport;
20
- readonly profile: BrowserProfile;
21
- readonly onPacket?: PacketCallback;
22
- }
23
- export interface Http2Options {
24
- readonly transport: Transport;
25
- readonly profile: BrowserProfile;
26
- readonly onPacket?: PacketCallback;
27
- }
28
- export interface Http3Options {
29
- readonly quic: QuicConnection;
30
- readonly clock?: Clock;
31
- readonly onPacket?: PacketCallback;
32
- }
33
- export interface QuicOptions {
34
- readonly transport: DatagramTransport;
35
- readonly peer: UdpAddress;
36
- readonly serverName: string;
37
- readonly initialDcid: Uint8Array;
38
- readonly initialScid: Uint8Array;
39
- readonly handshakeTimeoutMs?: number;
40
- readonly clock?: Clock;
41
- readonly onPacket?: PacketCallback;
42
- }
43
- export interface FetchClientOptions {
44
- readonly profile?: BrowserProfile;
45
- readonly cookieJar?: CookieJar;
46
- readonly tls?: Partial<TlsOptions>;
47
- readonly http2?: Partial<Http2Options>;
48
- readonly http3?: Partial<Http3Options>;
49
- readonly transport?: Transport;
50
- }
51
- //# sourceMappingURL=options.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EACR,SAAS,EACT,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,SAAS,EACZ,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAM9D,MAAM,WAAW,UA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;IAClC,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,CAAC;IAC/B,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;IACnC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;IACvC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;IACvC,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,CAAC;CAClC"}
package/dist/options.js DELETED
@@ -1,9 +0,0 @@
1
- /**
2
- * Options — configuration for protocol packages.
3
- *
4
- * Each protocol package accepts an options object that implements one of
5
- * these interfaces. Options are implementation-independent configuration
6
- * that gets passed down from consumers like browsersmith.
7
- */
8
- export {};
9
- //# sourceMappingURL=options.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"options.js","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}