@dmarket/p2p-tracker-headless 1.3.0-beta → 1.3.1-SNAPSHOT-development.204

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 (64) hide show
  1. package/VERSION +6 -6
  2. package/dmarket-p2p-tracker-core-domain.mjs +3159 -2269
  3. package/dmarket-p2p-tracker-core-domain.mjs.map +1 -1
  4. package/kotlin-kotlin-stdlib.mjs +29 -29
  5. package/kotlin-kotlin-stdlib.mjs.map +1 -1
  6. package/kotlinx-coroutines-core.mjs +8 -8
  7. package/kotlinx-coroutines-core.mjs.map +1 -1
  8. package/ktor-ktor-websockets.mjs +2 -2
  9. package/p2p-tracker-core.mjs +8471 -8006
  10. package/p2p-tracker-core.mjs.map +1 -1
  11. package/p2p-tracker-headless.mjs +777 -777
  12. package/p2p-tracker-headless.mjs.map +1 -1
  13. package/package.json +1 -1
  14. package/pkg/README.md +27 -23
  15. package/pkg/client_wasm.d.ts +37 -2
  16. package/pkg/client_wasm.js +24 -5
  17. package/pkg/client_wasm_bg.wasm +0 -0
  18. package/pkg/client_wasm_bg.wasm.d.ts +1 -0
  19. package/pkg/snippets/web-spawn-05868593a72e2d44/js/spawn.js +2 -2
  20. package/pkg/spawn.js +4 -4
  21. package/transport/README.md +203 -16
  22. package/transport/dist/channel.d.ts +23 -3
  23. package/transport/dist/channel.d.ts.map +1 -1
  24. package/transport/dist/channel.js +3 -3
  25. package/transport/dist/channel.js.map +1 -1
  26. package/transport/dist/egress.d.ts +33 -0
  27. package/transport/dist/egress.d.ts.map +1 -0
  28. package/transport/dist/egress.js +311 -0
  29. package/transport/dist/egress.js.map +1 -0
  30. package/transport/dist/index.d.ts +5 -3
  31. package/transport/dist/index.d.ts.map +1 -1
  32. package/transport/dist/index.js +3 -2
  33. package/transport/dist/index.js.map +1 -1
  34. package/transport/dist/node-bridge.d.ts +12 -0
  35. package/transport/dist/node-bridge.d.ts.map +1 -0
  36. package/transport/dist/node-bridge.js +181 -0
  37. package/transport/dist/node-bridge.js.map +1 -0
  38. package/transport/dist/node-prover.d.ts +39 -0
  39. package/transport/dist/node-prover.d.ts.map +1 -0
  40. package/transport/dist/node-prover.js +124 -0
  41. package/transport/dist/node-prover.js.map +1 -0
  42. package/transport/dist/node-runtime.d.ts +11 -0
  43. package/transport/dist/node-runtime.d.ts.map +1 -0
  44. package/transport/dist/node-runtime.js +120 -0
  45. package/transport/dist/node-runtime.js.map +1 -0
  46. package/transport/dist/node-socket.d.ts +17 -0
  47. package/transport/dist/node-socket.d.ts.map +1 -0
  48. package/transport/dist/node-socket.js +109 -0
  49. package/transport/dist/node-socket.js.map +1 -0
  50. package/transport/dist/node-worker.d.ts +2 -0
  51. package/transport/dist/node-worker.d.ts.map +1 -0
  52. package/transport/dist/node-worker.js +75 -0
  53. package/transport/dist/node-worker.js.map +1 -0
  54. package/transport/dist/node.d.ts +9 -3
  55. package/transport/dist/node.d.ts.map +1 -1
  56. package/transport/dist/node.js +5 -61
  57. package/transport/dist/node.js.map +1 -1
  58. package/transport/dist/prover.d.ts +18 -2
  59. package/transport/dist/prover.d.ts.map +1 -1
  60. package/transport/dist/prover.js +33 -11
  61. package/transport/dist/prover.js.map +1 -1
  62. package/transport/dist/types.d.ts +24 -0
  63. package/transport/dist/types.d.ts.map +1 -1
  64. package/transport/package.json +4 -1
@@ -18,9 +18,11 @@ wasm pkg — a load-bearing invariant, see below):
18
18
  | export | kind | purpose |
19
19
  | --- | --- | --- |
20
20
  | `createProver(wasm)` | façade | wraps an injected pkg module in the `Prover` surface below |
21
+ | `createProxyProver(wasm)` | façade | adds `proveProxy(notaryIo, proxyConfig, request, onProgress?)` to the existing surface |
22
+ | `ProxyClientWasmModule` / `ProxyProver` | types | extend the old module/facade interfaces without adding required old members |
21
23
  | `Prover` | type | `initialize(logging?, threads?)` / `prove(notaryIo, serverIo, config, request, onProgress?)` / `present(attestation, secrets, policy?)` |
22
24
  | `ClientWasmModule` | type | the injected-module contract (`import * as wasm from ".../pkg/client_wasm.js"` satisfies it) |
23
- | `connectNotary(url, token, opts?)` | transport | the notary MPC channel, authenticated by the `Sec-WebSocket-Protocol` bearer subprotocol |
25
+ | `connectNotary(url, token, opts?)` | transport | the notary channel for either mode, authenticated by the `Sec-WebSocket-Protocol` bearer subprotocol |
24
26
  | `connectProxy(proxyBase, host, port, opts?)` | transport | the target byte pipe, tunnelled `WS → p2p-wss-proxy → TCP` |
25
27
  | `connectTcp(host, port, { connect })` | transport | direct target TCP through an injected host connector |
26
28
  | `TcpIoChannel` / `TcpSocket` / `TcpConnectOptions` | transport / types | adapt host Web Streams to `IoChannel` |
@@ -70,6 +72,53 @@ const presentation = prover.present(out.attestation, out.secrets, {
70
72
  // POST `presentation` (Uint8Array) to your validating backend.
71
73
  ```
72
74
 
75
+ ## Proxy issuance
76
+
77
+ Choose proxy explicitly when the notary has enabled it and authorized the target
78
+ DNS identity. It uses only the notary channel; the notary owns target DNS and
79
+ dialing. The same attestation/secrets, presentation and redaction APIs apply.
80
+
81
+ ```ts
82
+ import * as wasm from "./pkg/client_wasm.js"; // keep loose and external
83
+ import { createProxyProver, connectNotary } from "@dmarket/steam-provenance";
84
+
85
+ const prover = createProxyProver(wasm); // checks the export before initialization
86
+ const notaryIo = await connectNotary("wss://notary.example/", bearerToken);
87
+ try {
88
+ const out = await prover.proveProxy(notaryIo,
89
+ { serverName: "api.example.com", limits: { maxRecvData: 128 * 1024 } },
90
+ { method: "GET", uri: "/v1/resource" });
91
+ // Persist out.attestation and out.secrets together; present later as usual.
92
+ } finally {
93
+ await notaryIo.close();
94
+ }
95
+ ```
96
+
97
+ `ProxyIssuanceConfig` accepts `serverName`, `rootStore` and `limits`. Omitted
98
+ limits retain finite defaults: 16/128 KiB sent/received application plaintext,
99
+ 64/256/320 KiB sent/received/combined TLS wire bytes, 512 records per direction,
100
+ 18 KiB record payload, and 64 KiB handshake/certificate budgets. Byte caps include
101
+ HTTP headers or TLS record headers as applicable. Invalid or inconsistent limits
102
+ fail before protocol IO; the notary independently enforces its own limits.
103
+ Proxy has no MPC preprocessing settings and emits `PROXY_SETUP` and `PROOF`
104
+ stages through the existing progress-event shape.
105
+
106
+ Both modes require the threaded WASM build, workers and browser isolation.
107
+ `connectProxy` remains the MPC WebSocket-to-TCP transport relay; it is not used
108
+ by TLSN proxy mode. `createProver` and old injected modules retain their existing
109
+ MPC behavior. Proxy factories reject a module missing `proveProxy` explicitly;
110
+ issuance failures never trigger automatic MPC replay. Browser hosts own channel
111
+ cleanup and worker cancellation as with the existing facade.
112
+
113
+ For plain Node, import `createNodeProxyProver` from
114
+ `@dmarket/steam-provenance/node`. Its `proveProxy(notaryIo, config, request,
115
+ options?)` takes exactly one channel, with the same validation, one-operation
116
+ limit, cancellation, timeout and disposal rules as `createNodeProver` below.
117
+ Accepted channels close on success or failure; pre-aborted, invalid-option,
118
+ busy and disposed calls retain caller ownership. A failed or cancelled operation
119
+ discards the worker tree and a later call initializes a fresh one. The extended
120
+ object also retains `prove` and asynchronous `present`.
121
+
73
122
  ## Direct TCP for desktop and native hosts
74
123
 
75
124
  In a Node-capable host, replace the target proxy channel with:
@@ -125,10 +174,7 @@ when an issuance fails.
125
174
  errors, copies outgoing bytes before yielding, and waits for pending writes
126
175
  before closing. Repeated `close()` calls share the same promise.
127
176
 
128
- This adds a transport for desktop npm hosts; the shipped WASM binary still
129
- uses browser Web Workers. Electron needs a suitable renderer and host bridge;
130
- plain Node needs a compatible WASM worker/bootstrap integration. A TCP adapter
131
- alone does not supply that runtime. Native mobile Rust integrations can use
177
+ The Node runtime and caller-owned socket handoff are described below. Native mobile Rust integrations can use
132
178
  `client-core` with `features = ["tcp"]`, a Tokio runtime, and
133
179
  `client_core::connect_tcp((host, port))` as the target stream for `issue()`.
134
180
 
@@ -211,9 +257,9 @@ queue in `io.rs` is satisfied immediately here).
211
257
  The generated wasm package (`../pkg`) must exist first — `src/wasm-compat.ts`
212
258
  asserts this package's locally-declared types against the generated
213
259
  `client_wasm.d.ts` (resolved via the `paths` mapping in `tsconfig.json`).
214
- There is **no runtime dependency** on `../pkg`: every import of it is
215
- type-only and erased, so the emitted `dist/` imports nothing from it (verify
216
- with `grep -rE 'from "client-wasm"' dist/` → nothing).
260
+ The browser entry has **no runtime dependency** on `../pkg`: its imports are
261
+ type-only and erased. The Node prover worker loads the adjacent `pkg/` at
262
+ runtime; distribute it together with `transport/`, as the root npm package does.
217
263
 
218
264
  ```sh
219
265
  ../build.sh # 1. build the wasm pkg (produces ../pkg/client_wasm.d.ts)
@@ -223,18 +269,159 @@ npm run build # emit dist/ (ESM + .d.ts)
223
269
  npm test # build + adapter and loopback TCP tests
224
270
  ```
225
271
 
226
- ## Running outside a browser (Node)
272
+ ## Plain Node prover
273
+
274
+ The Node worker prover requires Node 24.18.0 or later; Node 26.7.0 is also tested
275
+ on macOS arm64. Its factories reject older runtimes before starting workers or
276
+ accepting channels. Package installation and browser-entry imports retain the
277
+ published Node >=18 requirement. CI uses Node 24.18.0 for worker tests.
278
+
279
+ Import `@dmarket/steam-provenance/node` from the installed npm package. The
280
+ transport package also exposes these APIs at `client-wasm-transport/node` when
281
+ staged alongside `pkg/`. Keep the Node entry and its worker files on disk;
282
+ do not inline them into an application bundle. The browser entry stays separate.
283
+
284
+ ```js
285
+ import { createConnection } from "node:net";
286
+ import { once } from "node:events";
287
+ import { createNodeProver, wrapTcpSocket, connectNotary }
288
+ from "@dmarket/steam-provenance/node";
289
+
290
+ const prover = createNodeProver({ threadCount: 2, operationTimeoutMs: 120_000 });
291
+ let socket, serverIo, notaryIo;
292
+ try {
293
+ await prover.initialize();
294
+ notaryIo = await connectNotary(notaryUrl, accessToken);
295
+ socket = createConnection({ host: endpointAddress, port: 443 });
296
+ socket.on("error", error => console.error("endpoint socket error", error.code));
297
+ const connectionTimer = setTimeout(() => socket.destroy(new Error("connect timeout")), 10_000);
298
+ try { await once(socket, "connect"); }
299
+ finally { clearTimeout(connectionTimer); }
300
+ serverIo = wrapTcpSocket(socket);
301
+ const out = await prover.prove(notaryIo, serverIo,
302
+ { serverName: "api.example.com" },
303
+ { method: "GET", uri: "/v1/resource" },
304
+ { signal: AbortSignal.timeout(120_000), onProgress: event => console.log(event.step) });
305
+ const presentation = await prover.present(out.attestation, out.secrets, {
306
+ redactRequestHeaderValues: ["authorization", "cookie", "user-agent"],
307
+ revealRequestTarget: false,
308
+ revealResponseHeaders: true,
309
+ revealResponseBody: "all",
310
+ });
311
+ // Send presentation to your validator; persist attestation + secrets together.
312
+ } finally {
313
+ await prover.dispose();
314
+ await serverIo?.abort();
315
+ socket?.destroy();
316
+ await notaryIo?.close();
317
+ }
318
+ ```
227
319
 
228
- `connectNotary` / `connectProxy` use the global `WebSocket` by default. To use
229
- another implementation, pass
230
- `connectNotary(url, token, { WebSocketImpl: WsFromNodePackage })`.
231
- Use the `/node` entry above for a direct TCP target. See its runtime caveat
232
- before attempting to initialize the browser WASM package in plain Node.
320
+ The application opens the endpoint connection **once** and hands over that same
321
+ raw `net.Socket`. It must already be connected, readable/writable, binary, and
322
+ exclusively available: no `setEncoding`, competing data/readable listeners,
323
+ in-flight application writes, or consumed protocol bytes. TLS sockets, connecting
324
+ sockets, and closed sockets are rejected without taking ownership. On successful
325
+ handoff, the adapter owns IO and may close/destroy the socket. Unread buffered
326
+ bytes are retained. It enables `TCP_NODELAY` and `allowHalfOpen`: peer EOF ends
327
+ reads while accepted writes can still drain. Normal close is idempotent and
328
+ drains writes; after five seconds it destroys a blocked connection. `abort()`
329
+ destroys it immediately. Reusing this connection after a proof is not supported.
330
+
331
+ MPC-TLS runs inside the prover, so do not call `tls.connect()` or perform a TLS
332
+ handshake before handoff. `serverName` controls certificate identity and SNI and
333
+ can differ from the routing address. The notary uses its existing authenticated
334
+ WebSocket handshake; `connectNotary` also accepts an injected `WebSocketImpl`.
335
+ Application connection deadlines are separate from prover initialization and
336
+ issuance deadlines.
337
+
338
+ `createNodeProver` runs the existing threaded WASM inside dedicated
339
+ `worker_threads`, with no compatibility globals added to the application.
340
+ `initialize()` coalesces repeated/concurrent calls. `prove()` and `present()` are
341
+ asynchronous and allow one active operation per instance. A rejected concurrent
342
+ call, invalid options, or an already-aborted signal leaves ownership of the
343
+ channels with the caller. An accepted proof closes
344
+ both IO channels on success or failure. Custom channels must make `close()`
345
+ unblock IO; they can expose `abort()` for immediate cleanup. The bridge allows
346
+ one outstanding read, acknowledges write completion, splits messages at 64 KiB,
347
+ and limits queued writes to 8 MiB / 128 calls. Await writes for backpressure.
348
+
349
+ Initialization defaults to 30 seconds; proof/presentation calls default to
350
+ 120 seconds including initialization, configurable per instance or call. An
351
+ AbortSignal, timeout, worker failure, or failed proof discards the entire worker
352
+ module; a later call initializes a fresh one. `dispose()` is terminal and
353
+ idempotent, settles outstanding calls, terminates the complete worker tree, and
354
+ bounds custom-channel cleanup to five seconds. Progress callback errors cannot
355
+ strand a proof. Logging defaults to Off; progress contains stages, not proof data.
356
+
357
+ Separate instances can run independently. Each uses a prover worker, a spawner,
358
+ a Rayon pool, and additional MPC workers; budget CPU and shared memory per
359
+ instance. `threadCount` defaults to available CPUs capped at 8 (range 1–32) and
360
+ also controls the parallelism reported to the MPC executor. A one-thread pool
361
+ still requires workers. No serial WASM rebuild or browser is involved.
233
362
 
234
363
  ## Integrator note (cross-origin isolation)
235
364
 
236
365
  The multi-threaded wasm build uses `SharedArrayBuffer`, so the embedding
237
366
  page/extension **must be cross-origin isolated** (COOP: `same-origin` + COEP:
238
367
  `require-corp`). Plan the extension/page headers accordingly. A failed
239
- `initialize()` (e.g. missing those headers) releases the façade's memo, so
240
- calling it again after fixing the environment retries for real.
368
+ `initialize()` releases the façade's memo. After partial worker startup, discard
369
+ the browser worker/module before retrying; global Rust pools cannot be reset.
370
+ The Node facade performs that replacement automatically.
371
+
372
+
373
+ ### Opt-in Worker egress for proxy issuance
374
+
375
+ Use `connectEgressNotary(workerUrl, token, options?)` when the operator selects
376
+ reverse Worker egress. It returns the ordinary `IoChannel` consumed by
377
+ `proveProxy`; the proof, presentation and validator APIs are unchanged.
378
+ `connectNotary` continues to select the existing direct notary protocol.
379
+
380
+ ```ts
381
+ import { connectEgressNotary, createProxyProver } from "@dmarket/steam-provenance";
382
+ const prover = createProxyProver(wasm);
383
+ await prover.initialize(null, 2);
384
+ const io = await connectEgressNotary(
385
+ "wss://worker.example/notary/egress/v1", bearerToken,
386
+ { timeoutMs: 240_000 },
387
+ );
388
+ try {
389
+ const result = await prover.proveProxy(io, proxyConfig, request);
390
+ // Existing presentation/disclosure API consumes result.attestation/secrets.
391
+ } finally {
392
+ await io.abort();
393
+ }
394
+ ```
395
+
396
+ The connector is also exported from `/node`; use it with
397
+ `createNodeProxyProver`. `WebSocketImpl` injection supports Node WebSocket
398
+ implementations and gateway signing headers. For a signed gateway flow, omit
399
+ `token`, inject a constructor that signs the actual Worker-facing request URL,
400
+ and configure the gateway to mint `Authorization` before forwarding. The Worker
401
+ accepts that user credential; it never validates original API-key signatures or
402
+ forwards those signing headers. A raw API key is not a notary token. Service
403
+ credentials belong only in Worker/notary configuration, never in this API.
404
+
405
+ The frontend requires `tlsn.notary.egress.v1` and implements bounded binary
406
+ framing/credits with 64 KiB per-direction windows and a 16 KiB maximum payload.
407
+ It restricts all traffic to the client channel; the client cannot select an
408
+ upstream notary or send server-leg frames. The total timeout includes the
409
+ WebSocket handshake, admission, TLS, proof and signing (default 240 seconds,
410
+ maximum 600 seconds, reduced by the notary's advertised budget). WSS is required;
411
+ plain WS is allowed only for loopback fixtures. URL credentials, query parameters
412
+ and fragments are rejected.
413
+
414
+ One read and up to 16 writes (at most 1 MiB total) may be pending, matching the
415
+ existing WASM adapter's bounded batching. Writes copy their input and serialize;
416
+ only 64 KiB may be outstanding on the wire until consumption credits arrive.
417
+ Exceeding the local write queue fails the session. `close()` sends a directional FIN after queued writes;
418
+ `abort()` immediately stops a failed or cancelled session and clears pending IO.
419
+ On browser error/cancellation call `abort()` or terminate the owning worker.
420
+ The Node prover uses `abort()` during failed-operation disposal. Target EOF keeps
421
+ the client channel alive for the signing exchange. There is no direct-target,
422
+ transport or mode fallback. The MPC `proxyBaseUrl` setting remains separate.
423
+
424
+ The operator-controlled Worker is part of the notary's trusted observation path.
425
+ It sees the user credential and disclosed proof fields after outer WSS
426
+ termination. The inner target TLS remains between prover and target. This route
427
+ does not guarantee a source-IP country or Steam acceptance.
@@ -2,11 +2,31 @@ import type { IoChannel } from "./types.js";
2
2
  /**
3
3
  * Injectable `WebSocket` constructor. Defaults to the global browser
4
4
  * `WebSocket`. Supplying one lets the transport run under a polyfill (e.g. the
5
- * `ws` package in Node for the deferred single-threaded run — see RUN_E2E.md),
5
+ * `ws` package in Node),
6
6
  * without any code change.
7
7
  */
8
+ export interface WebSocketEvents {
9
+ open: unknown;
10
+ error: unknown;
11
+ close: {
12
+ code: number;
13
+ };
14
+ message: {
15
+ data: unknown;
16
+ };
17
+ }
18
+ export interface WebSocketLike {
19
+ binaryType: string;
20
+ readonly readyState: number;
21
+ readonly protocol: string;
22
+ send(data: Uint8Array<ArrayBuffer>): void;
23
+ close(): void;
24
+ addEventListener<K extends keyof WebSocketEvents>(type: K, listener: (event: WebSocketEvents[K]) => void, options?: {
25
+ once?: boolean;
26
+ }): void;
27
+ }
8
28
  export type WebSocketCtor = {
9
- new (url: string, protocols?: string | string[]): WebSocket;
29
+ new (url: string, protocols?: string | string[]): WebSocketLike;
10
30
  };
11
31
  /**
12
32
  * Adapts a browser `WebSocket` into the wasm prover's `IoChannel`.
@@ -36,7 +56,7 @@ export type WebSocketCtor = {
36
56
  */
37
57
  export declare class WsIoChannel implements IoChannel {
38
58
  #private;
39
- constructor(ws: WebSocket);
59
+ constructor(ws: WebSocketLike);
40
60
  /** Resolves once the socket is open; rejects if it fails to open. */
41
61
  whenReady(): Promise<void>;
42
62
  /** The subprotocol the server selected (`""` until open / if none). */
@@ -1 +1 @@
1
- {"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../src/channel.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YA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IAAI,EAAE,CAAC,EACvD,QAAQ,EAAE,CAAC,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;CACtF;AACD,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,GAAG,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,aAAa,CAAC;CACjE,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qBAAa,WAAY,YAAW,SAAS;;IAW3C,YAAY,EAAE,EAAE,aAAa,EAgC5B;IAED,qEAAqE;IACrE,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAEzB;IAED,uEAAuE;IACvE,IAAI,QAAQ,IAAI,MAAM,CAErB;IAyBD,IAAI,IAAI,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAKjC;IAEK,KAAK,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAe3C;IAED,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAcrB;CACF"}
@@ -40,7 +40,7 @@ export class WsIoChannel {
40
40
  // ArrayBuffer (not Blob); safe to set synchronously right after construction.
41
41
  ws.binaryType = "arraybuffer";
42
42
  this.#ready = new Promise((resolve, reject) => {
43
- if (ws.readyState === WebSocket.OPEN) {
43
+ if (ws.readyState === 1) {
44
44
  resolve();
45
45
  return;
46
46
  }
@@ -103,7 +103,7 @@ export class WsIoChannel {
103
103
  }
104
104
  async write(data) {
105
105
  await this.#ready;
106
- if (this.#closed || this.#ws.readyState !== WebSocket.OPEN) {
106
+ if (this.#closed || this.#ws.readyState !== 1) {
107
107
  // Fail loud: a silently-dropped write would strand a protocol frame and
108
108
  // deadlock the notary (it never replies) — the exact hazard the io.rs
109
109
  // write-completion fix guards against on the Rust side.
@@ -118,7 +118,7 @@ export class WsIoChannel {
118
118
  this.#ws.send(data.slice());
119
119
  }
120
120
  close() {
121
- if (this.#closed || this.#ws.readyState === WebSocket.CLOSED) {
121
+ if (this.#closed || this.#ws.readyState === 3) {
122
122
  this.#onEof();
123
123
  return Promise.resolve();
124
124
  }
@@ -1 +1 @@
1
- {"version":3,"file":"channel.js","sourceRoot":"","sources":["../src/channel.ts"],"names":[],"mappings":"AA0BA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,OAAO,WAAW;IACb,GAAG,CAAY;IACxB,kEAAkE;IACzD,MAAM,GAAiB,EAAE,CAAC;IACnC,gEAAgE;IACvD,QAAQ,GAA2C,EAAE,CAAC;IAC/D,8EAA8E;IACrE,MAAM,CAAgB;IAC/B,+EAA+E;IAC/E,OAAO,GAAG,KAAK,CAAC;IAEhB,YAAY,EAAa;QACvB,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC;QACd,oEAAoE;QACpE,8EAA8E;QAC9E,EAAE,CAAC,UAAU,GAAG,aAAa,CAAC;QAE9B,IAAI,CAAC,MAAM,GAAG,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAClD,IAAI,EAAE,CAAC,UAAU,KAAK,SAAS,CAAC,IAAI,EAAE,CAAC;gBACrC,OAAO,EAAE,CAAC;gBACV,OAAO;YACT,CAAC;YACD,EAAE,CAAC,gBAAgB,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;YAC7D,wEAAwE;YACxE,gEAAgE;YAChE,EAAE,CAAC,gBAAgB,CACjB,OAAO,EACP,CAAC,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,sCAAsC,EAAE,CAAC,IAAI,GAAG,CAAC,CAAC,EAC3E,EAAE,IAAI,EAAE,IAAI,EAAE,CACf,CAAC;YACF,EAAE,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE,CA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,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;IAC7D,IAAI,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,GAAG,IAAuB,CAAC;QACrC,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IACvE,CAAC;IACD,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACpE,oEAAoE;IACpE,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,33 @@
1
+ import type { WebSocketCtor, WebSocketLike } from "./channel.js";
2
+ import type { IoChannel } from "./types.js";
3
+ /** Opt-in Worker frontend; never offered to a direct notary or MPC target relay. */
4
+ export declare const EGRESS_NOTARY_SUBPROTOCOL = "tlsn.notary.egress.v1";
5
+ export interface EgressConnectOptions {
6
+ /** Browser WebSocket by default; inject a Node implementation for headless use. */
7
+ WebSocketImpl?: WebSocketCtor;
8
+ /** Absolute bound including handshake, admission, TLS, proof and signing. Default 240000 ms. */
9
+ timeoutMs?: number;
10
+ }
11
+ /**
12
+ * A bounded, credit-controlled client byte stream. One read and a bounded
13
+ * batch of writes may be pending. Accepted writes copy their input and serialize.
14
+ * close() sends directional FIN; abort() immediately cancels the entire session.
15
+ */
16
+ export declare class EgressIoChannel implements IoChannel {
17
+ #private;
18
+ constructor(ws: WebSocketLike, timeoutMs?: number);
19
+ whenReady(): Promise<void>;
20
+ get protocol(): string;
21
+ read(): Promise<Uint8Array | null>;
22
+ write(data: Uint8Array): Promise<void>;
23
+ close(): Promise<void>;
24
+ abort(): Promise<void>;
25
+ }
26
+ /**
27
+ * Connect an explicitly selected Worker frontend. No direct/mode fallback.
28
+ * For a signed gateway request, omit token and inject a constructor that sends
29
+ * the gateway's signing headers; the gateway must mint Authorization before
30
+ * forwarding to the Worker. The Worker service secret never enters this API.
31
+ */
32
+ export declare function connectEgressNotary(url: string, token?: string, opts?: EgressConnectOptions): Promise<EgressIoChannel>;
33
+ //# sourceMappingURL=egress.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"egress.d.ts","sourceRoot":"","sources":["../src/egress.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,oFAAoF;AACpF,eAAO,MAAM,yBAAyB,0BAA0B,CAAC;AAUjE,MAAM,WAAW,oBAAoB;IACnC,mFAAmF;IACnF,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,gGAAgG;IAChG,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;GAIG;AACH,qBAAa,eAAgB,YAAW,SAAS;;IA6B/C,YAAY,EAAE,EAAE,aAAa,EAAE,SAAS,SAAS,EA6BhD;IACD,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAAwB;IAClD,IAAI,QAAQ,IAAI,MAAM,CAA8B;IA8F9C,IAAI,IAAI,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAMvC;IACD,KAAK,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAyBrC;IACD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAWrB;IACK,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAA0C;CACvE;AAED;;;;;GAKG;AACH,wBAAsB,mBAAmB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,eAAe,CAAC,CAa5H"}