tunnelfetch 1.0.0 → 1.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tunnelfetch",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "A fetch-shaped HTTP client that can route through HTTP CONNECT / HTTPS / SOCKS5 proxies on runtimes with only raw TCP, such as Cloudflare Workers. Implements TLS in userland because the runtime cannot verify a tunnelled peer.",
5
5
  "keywords": [
6
6
  "fetch",
@@ -123,7 +123,7 @@ export class Http2Retryable extends Http2Error {}
123
123
 
124
124
  export class Http2Connection {
125
125
  /**
126
- * @param {import('./frames.js').ByteDuplex | { readable: ReadableStream<Uint8Array>,
126
+ * @param {import('../tls/connect.js').ByteDuplex | { readable: ReadableStream<Uint8Array>,
127
127
  * writable: WritableStream<Uint8Array> }} duplex plaintext transport (a TLS session's
128
128
  * plaintextDuplex, or a raw socket for cleartext h2 in tests)
129
129
  * @param {Http2ConnectionOptions} [opts]
package/src/tls/record.js CHANGED
@@ -81,8 +81,19 @@ async function withGrace(promise, ms) {
81
81
  /**
82
82
  * Keys for one direction: a TLS 1.3 traffic `secret` (key and IV derived per RFC 8446 s7.3,
83
83
  * KeyUpdate rotation possible) or raw TLS 1.2 key_block slices (no forward rotation).
84
- * @typedef {{ cipher: number, secret: Uint8Array }
85
- * | { cipher: number, key: Uint8Array, iv: Uint8Array }} DirectionKeys
84
+ * Exactly one of the two shapes is valid — a 1.3 `secret`, or a 1.2 `key`+`iv` — and _makeState
85
+ * enforces that at runtime. It is spelled with optional members rather than as a union because the
86
+ * setters destructure all four names, and TypeScript cannot destructure a union member that some
87
+ * branch lacks; a union here emits declarations that do not type-check for a consumer.
88
+ * @typedef {{ cipher: number, secret?: Uint8Array, key?: Uint8Array, iv?: Uint8Array }} DirectionKeys
89
+ */
90
+
91
+ /**
92
+ * One direction's live protection state. Module-level, not inside the constructor: a typedef
93
+ * declared in a function body is not in scope where the emitted declaration needs it.
94
+ * @typedef {null | { aead: import('./aead.js').Aead, seq: bigint, cipher: number,
95
+ * hash: import('./keyschedule.js').ScheduleHash,
96
+ * secret: Uint8Array | null }} DirectionState
86
97
  */
87
98
 
88
99
  /**
@@ -113,9 +124,6 @@ export class RecordLayer {
113
124
  this._onPostHandshake = opts.onPostHandshake ?? null;
114
125
 
115
126
  this._version = TLS13; // semantics selector; setVersion() pins it when negotiated
116
- /** @typedef {null | { aead: import('./aead.js').Aead, seq: bigint, cipher: number,
117
- * hash: import('./keyschedule.js').ScheduleHash,
118
- * secret: Uint8Array | null }} DirectionState */
119
127
  /** @type {DirectionState} */
120
128
  this._send = null;
121
129
  /** @type {DirectionState} */
@@ -49,12 +49,12 @@ export class Http2Retryable extends Http2Error {
49
49
  */
50
50
  export class Http2Connection {
51
51
  /**
52
- * @param {import('./frames.js').ByteDuplex | { readable: ReadableStream<Uint8Array>,
52
+ * @param {import('../tls/connect.js').ByteDuplex | { readable: ReadableStream<Uint8Array>,
53
53
  * writable: WritableStream<Uint8Array> }} duplex plaintext transport (a TLS session's
54
54
  * plaintextDuplex, or a raw socket for cleartext h2 in tests)
55
55
  * @param {Http2ConnectionOptions} [opts]
56
56
  */
57
- constructor(duplex: import("./frames.js").ByteDuplex | {
57
+ constructor(duplex: import("../tls/connect.js").ByteDuplex | {
58
58
  readable: ReadableStream<Uint8Array>;
59
59
  writable: WritableStream<Uint8Array>;
60
60
  }, opts?: Http2ConnectionOptions);
@@ -9,8 +9,18 @@
9
9
  /**
10
10
  * Keys for one direction: a TLS 1.3 traffic `secret` (key and IV derived per RFC 8446 s7.3,
11
11
  * KeyUpdate rotation possible) or raw TLS 1.2 key_block slices (no forward rotation).
12
- * @typedef {{ cipher: number, secret: Uint8Array }
13
- * | { cipher: number, key: Uint8Array, iv: Uint8Array }} DirectionKeys
12
+ * Exactly one of the two shapes is valid — a 1.3 `secret`, or a 1.2 `key`+`iv` — and _makeState
13
+ * enforces that at runtime. It is spelled with optional members rather than as a union because the
14
+ * setters destructure all four names, and TypeScript cannot destructure a union member that some
15
+ * branch lacks; a union here emits declarations that do not type-check for a consumer.
16
+ * @typedef {{ cipher: number, secret?: Uint8Array, key?: Uint8Array, iv?: Uint8Array }} DirectionKeys
17
+ */
18
+ /**
19
+ * One direction's live protection state. Module-level, not inside the constructor: a typedef
20
+ * declared in a function body is not in scope where the emitted declaration needs it.
21
+ * @typedef {null | { aead: import('./aead.js').Aead, seq: bigint, cipher: number,
22
+ * hash: import('./keyschedule.js').ScheduleHash,
23
+ * secret: Uint8Array | null }} DirectionState
14
24
  */
15
25
  /**
16
26
  * @typedef {object} RecordLayerOptions
@@ -37,25 +47,10 @@ export class RecordLayer {
37
47
  _padding: ((type: number, length: number) => number) | null;
38
48
  _onPostHandshake: ((msg: HandshakeMessage) => void | Promise<void>) | null;
39
49
  _version: number;
40
- /** @typedef {null | { aead: import('./aead.js').Aead, seq: bigint, cipher: number,
41
- * hash: import('./keyschedule.js').ScheduleHash,
42
- * secret: Uint8Array | null }} DirectionState */
43
50
  /** @type {DirectionState} */
44
- _send: {
45
- aead: import("./aead.js").Aead;
46
- seq: bigint;
47
- cipher: number;
48
- hash: import("./keyschedule.js").ScheduleHash;
49
- secret: Uint8Array | null;
50
- } | null;
51
+ _send: DirectionState;
51
52
  /** @type {DirectionState} */
52
- _recv: {
53
- aead: import("./aead.js").Aead;
54
- seq: bigint;
55
- cipher: number;
56
- hash: import("./keyschedule.js").ScheduleHash;
57
- secret: Uint8Array | null;
58
- } | null;
53
+ _recv: DirectionState;
59
54
  /** Handshake reassembly. Chunk list, not one growing buffer, so a peer drip-feeding a
60
55
  * message in tiny records costs O(records), not O(records^2).
61
56
  * @type {Uint8Array[]} */
@@ -323,14 +318,27 @@ export type HandshakeMessage = {
323
318
  /**
324
319
  * Keys for one direction: a TLS 1.3 traffic `secret` (key and IV derived per RFC 8446 s7.3,
325
320
  * KeyUpdate rotation possible) or raw TLS 1.2 key_block slices (no forward rotation).
321
+ * Exactly one of the two shapes is valid — a 1.3 `secret`, or a 1.2 `key`+`iv` — and _makeState
322
+ * enforces that at runtime. It is spelled with optional members rather than as a union because the
323
+ * setters destructure all four names, and TypeScript cannot destructure a union member that some
324
+ * branch lacks; a union here emits declarations that do not type-check for a consumer.
326
325
  */
327
326
  export type DirectionKeys = {
328
327
  cipher: number;
329
- secret: Uint8Array;
330
- } | {
328
+ secret?: Uint8Array;
329
+ key?: Uint8Array;
330
+ iv?: Uint8Array;
331
+ };
332
+ /**
333
+ * One direction's live protection state. Module-level, not inside the constructor: a typedef
334
+ * declared in a function body is not in scope where the emitted declaration needs it.
335
+ */
336
+ export type DirectionState = null | {
337
+ aead: import("./aead.js").Aead;
338
+ seq: bigint;
331
339
  cipher: number;
332
- key: Uint8Array;
333
- iv: Uint8Array;
340
+ hash: import("./keyschedule.js").ScheduleHash;
341
+ secret: Uint8Array | null;
334
342
  };
335
343
  export type RecordLayerOptions = {
336
344
  /**