@dmarket/p2p-tracker-headless 0.0.0-bootstrap.0

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 (102) hide show
  1. package/Kotlin-DateTime-library-kotlinx-datetime.mjs +4 -0
  2. package/Kotlin-DateTime-library-kotlinx-datetime.mjs.map +1 -0
  3. package/VERSION +14 -0
  4. package/dmarket-p2p-tracker-core-domain.mjs +16699 -0
  5. package/dmarket-p2p-tracker-core-domain.mjs.map +1 -0
  6. package/index.d.ts +195 -0
  7. package/kotlin-kotlin-stdlib.mjs +18834 -0
  8. package/kotlin-kotlin-stdlib.mjs.map +1 -0
  9. package/kotlin_org_jetbrains_kotlin_kotlin_dom_api_compat.mjs +4 -0
  10. package/kotlin_org_jetbrains_kotlin_kotlin_dom_api_compat.mjs.map +1 -0
  11. package/kotlinx-atomicfu.mjs +251 -0
  12. package/kotlinx-atomicfu.mjs.map +1 -0
  13. package/kotlinx-browser.mjs +8 -0
  14. package/kotlinx-browser.mjs.map +1 -0
  15. package/kotlinx-coroutines-core.mjs +12437 -0
  16. package/kotlinx-coroutines-core.mjs.map +1 -0
  17. package/kotlinx-io-kotlinx-io-bytestring.mjs +202 -0
  18. package/kotlinx-io-kotlinx-io-bytestring.mjs.map +1 -0
  19. package/kotlinx-io-kotlinx-io-core.mjs +2034 -0
  20. package/kotlinx-io-kotlinx-io-core.mjs.map +1 -0
  21. package/kotlinx-serialization-kotlinx-serialization-core.mjs +6163 -0
  22. package/kotlinx-serialization-kotlinx-serialization-core.mjs.map +1 -0
  23. package/kotlinx-serialization-kotlinx-serialization-json-io.mjs +4 -0
  24. package/kotlinx-serialization-kotlinx-serialization-json-io.mjs.map +1 -0
  25. package/kotlinx-serialization-kotlinx-serialization-json.mjs +5957 -0
  26. package/kotlinx-serialization-kotlinx-serialization-json.mjs.map +1 -0
  27. package/ktor-ktor-client-content-negotiation.mjs +4 -0
  28. package/ktor-ktor-client-content-negotiation.mjs.map +1 -0
  29. package/ktor-ktor-client-core.mjs +9986 -0
  30. package/ktor-ktor-client-core.mjs.map +1 -0
  31. package/ktor-ktor-events.mjs +82 -0
  32. package/ktor-ktor-events.mjs.map +1 -0
  33. package/ktor-ktor-http-cio.mjs +2253 -0
  34. package/ktor-ktor-http-cio.mjs.map +1 -0
  35. package/ktor-ktor-http.mjs +3261 -0
  36. package/ktor-ktor-http.mjs.map +1 -0
  37. package/ktor-ktor-io.mjs +3546 -0
  38. package/ktor-ktor-io.mjs.map +1 -0
  39. package/ktor-ktor-openapi-schema.mjs +4 -0
  40. package/ktor-ktor-openapi-schema.mjs.map +1 -0
  41. package/ktor-ktor-serialization-kotlinx-json.mjs +4 -0
  42. package/ktor-ktor-serialization-kotlinx-json.mjs.map +1 -0
  43. package/ktor-ktor-serialization-kotlinx.mjs +4 -0
  44. package/ktor-ktor-serialization-kotlinx.mjs.map +1 -0
  45. package/ktor-ktor-serialization.mjs +4 -0
  46. package/ktor-ktor-serialization.mjs.map +1 -0
  47. package/ktor-ktor-sse.mjs +4 -0
  48. package/ktor-ktor-sse.mjs.map +1 -0
  49. package/ktor-ktor-utils.mjs +3427 -0
  50. package/ktor-ktor-utils.mjs.map +1 -0
  51. package/ktor-ktor-websocket-serialization.mjs +4 -0
  52. package/ktor-ktor-websocket-serialization.mjs.map +1 -0
  53. package/ktor-ktor-websockets.mjs +2589 -0
  54. package/ktor-ktor-websockets.mjs.map +1 -0
  55. package/p2p-tracker-core.mjs +41977 -0
  56. package/p2p-tracker-core.mjs.map +1 -0
  57. package/p2p-tracker-headless.mjs +4939 -0
  58. package/p2p-tracker-headless.mjs.map +1 -0
  59. package/package.json +58 -0
  60. package/pkg/README.md +104 -0
  61. package/pkg/client_wasm.d.ts +316 -0
  62. package/pkg/client_wasm.js +1199 -0
  63. package/pkg/client_wasm_bg.wasm +0 -0
  64. package/pkg/client_wasm_bg.wasm.d.ts +32 -0
  65. package/pkg/package.json +19 -0
  66. package/pkg/snippets/web-spawn-05868593a72e2d44/js/spawn.js +73 -0
  67. package/pkg/spawn.js +73 -0
  68. package/prover-child.mjs +2 -0
  69. package/transport/README.md +240 -0
  70. package/transport/dist/channel.d.ts +48 -0
  71. package/transport/dist/channel.d.ts.map +1 -0
  72. package/transport/dist/channel.js +150 -0
  73. package/transport/dist/channel.js.map +1 -0
  74. package/transport/dist/index.d.ts +10 -0
  75. package/transport/dist/index.d.ts.map +1 -0
  76. package/transport/dist/index.js +19 -0
  77. package/transport/dist/index.js.map +1 -0
  78. package/transport/dist/node.d.ts +4 -0
  79. package/transport/dist/node.d.ts.map +1 -0
  80. package/transport/dist/node.js +62 -0
  81. package/transport/dist/node.js.map +1 -0
  82. package/transport/dist/prover.d.ts +105 -0
  83. package/transport/dist/prover.d.ts.map +1 -0
  84. package/transport/dist/prover.js +139 -0
  85. package/transport/dist/prover.js.map +1 -0
  86. package/transport/dist/tcp.d.ts +38 -0
  87. package/transport/dist/tcp.d.ts.map +1 -0
  88. package/transport/dist/tcp.js +88 -0
  89. package/transport/dist/tcp.js.map +1 -0
  90. package/transport/dist/transport.d.ts +31 -0
  91. package/transport/dist/transport.d.ts.map +1 -0
  92. package/transport/dist/transport.js +75 -0
  93. package/transport/dist/transport.js.map +1 -0
  94. package/transport/dist/types.d.ts +162 -0
  95. package/transport/dist/types.d.ts.map +1 -0
  96. package/transport/dist/types.js +21 -0
  97. package/transport/dist/types.js.map +1 -0
  98. package/transport/dist/wasm-compat.d.ts +2 -0
  99. package/transport/dist/wasm-compat.d.ts.map +1 -0
  100. package/transport/dist/wasm-compat.js +15 -0
  101. package/transport/dist/wasm-compat.js.map +1 -0
  102. package/transport/package.json +34 -0
@@ -0,0 +1,10 @@
1
+ export { WsIoChannel } from "./channel.js";
2
+ export type { WebSocketCtor } from "./channel.js";
3
+ export { NOTARY_SUBPROTOCOL, connectNotary, connectProxy } from "./transport.js";
4
+ export type { ConnectOptions } from "./transport.js";
5
+ export { connectTcp, TcpIoChannel } from "./tcp.js";
6
+ export type { TcpSocket, TcpConnectOptions } from "./tcp.js";
7
+ export { createProver } from "./prover.js";
8
+ export type { ClientWasmModule, Prover } from "./prover.js";
9
+ export type { BodyReveal, CrateLogFilter, HttpRequest, HttpResponse, IoChannel, IssuanceConfig, LoggingConfig, LoggingLevel, ProgressCallback, ProveOutput, ProveProgress, RevealPolicy, RootStore, RootStorePreset, } from "./types.js";
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,YAAY,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACjF,YAAY,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAErD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACpD,YAAY,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE7D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,YAAY,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE5D,YAAY,EACV,UAAU,EACV,cAAc,EACd,WAAW,EACX,YAAY,EACZ,SAAS,EACT,cAAc,EACd,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,WAAW,EACX,aAAa,EACb,YAAY,EACZ,SAAS,EACT,eAAe,GAChB,MAAM,YAAY,CAAC"}
@@ -0,0 +1,19 @@
1
+ // client-wasm-transport — the TS companion to the `client-wasm` wasm prover.
2
+ //
3
+ // Two layers, both wasm-free at runtime (this package emits **no** import of
4
+ // the wasm pkg — load-bearing for the extension bundle, see ./prover.ts):
5
+ //
6
+ // - **Transport**: WebSocket or host-provided TCP `IoChannel`s for prove().
7
+ // Node's TCP connector is separately exported from /node.
8
+ // - **Prover façade** (`createProver`): a pass-through mirror of the wasm
9
+ // API (`initialize` / `prove` / `present`) over a caller-injected pkg
10
+ // module — owns instantiation + rayon-pool setup and the wire
11
+ // conversions.
12
+ //
13
+ // All DTO types are declared locally in ./types.ts (self-contained d.ts) and
14
+ // compile-time-checked against the generated pkg in ./wasm-compat.ts.
15
+ export { WsIoChannel } from "./channel.js";
16
+ export { NOTARY_SUBPROTOCOL, connectNotary, connectProxy } from "./transport.js";
17
+ export { connectTcp, TcpIoChannel } from "./tcp.js";
18
+ export { createProver } from "./prover.js";
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,EAAE;AACF,6EAA6E;AAC7E,0EAA0E;AAC1E,EAAE;AACF,8EAA8E;AAC9E,8DAA8D;AAC9D,4EAA4E;AAC5E,0EAA0E;AAC1E,kEAAkE;AAClE,mBAAmB;AACnB,EAAE;AACF,6EAA6E;AAC7E,sEAAsE;AAEtE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAG3C,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAGjF,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAGpD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { type TcpIoChannel } from "./tcp.js";
2
+ /** Open a raw Node TCP target socket, ready to pass as prove()'s serverIo. */
3
+ export declare function connectTcp(host: string, port?: number): Promise<TcpIoChannel>;
4
+ //# sourceMappingURL=node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAIA,OAAO,EAAiC,KAAK,YAAY,EAAE,MAAM,UAAU,CAAC;AAE5E,8EAA8E;AAC9E,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,SAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAuD1E"}
@@ -0,0 +1,62 @@
1
+ // Kept behind the /node entry point so browser bundles never import node:*.
2
+ import { once } from "node:events";
3
+ import { createConnection } from "node:net";
4
+ import { finished, Readable } from "node:stream";
5
+ import { connectTcp as connectWithHost } from "./tcp.js";
6
+ /** Open a raw Node TCP target socket, ready to pass as prove()'s serverIo. */
7
+ export function connectTcp(host, port = 443) {
8
+ return connectWithHost(host, port, {
9
+ async connect(host, port) {
10
+ // Let TcpIoChannel close the writer after flushing accepted writes.
11
+ // Otherwise peer EOF auto-ends the socket's writable side; Node 18's
12
+ // Duplex.toWeb then errors the Web writer before channel.close().
13
+ const socket = createConnection({ host, port, noDelay: true, allowHalfOpen: true });
14
+ // Node 18's Duplex.toWeb waits for BOTH socket halves before reporting
15
+ // either EOF or write completion. Adapt them independently instead.
16
+ // The read iterator must not destroy the write side when it reaches EOF.
17
+ const readable = Readable.toWeb(Readable.from(socket.iterator({ destroyOnReturn: false }), { objectMode: false }));
18
+ const writable = new WritableStream({
19
+ start(controller) {
20
+ // Install stream error handlers before awaiting the connection.
21
+ socket.on("error", (error) => controller.error(error));
22
+ },
23
+ write(data) {
24
+ return new Promise((resolve, reject) => {
25
+ socket.write(data, (error) => error ? reject(error) : resolve());
26
+ });
27
+ },
28
+ close() {
29
+ return new Promise((resolve, reject) => {
30
+ const cleanup = finished(socket, { readable: false }, (error) => {
31
+ cleanup();
32
+ error ? reject(error) : resolve();
33
+ });
34
+ socket.end();
35
+ });
36
+ },
37
+ abort() {
38
+ socket.destroy();
39
+ },
40
+ });
41
+ try {
42
+ await once(socket, "connect");
43
+ }
44
+ catch (error) {
45
+ socket.destroy();
46
+ throw error;
47
+ }
48
+ return {
49
+ readable,
50
+ writable,
51
+ async close() {
52
+ if (socket.closed)
53
+ return;
54
+ const closed = new Promise((resolve) => socket.once("close", () => resolve()));
55
+ socket.destroy();
56
+ await closed;
57
+ },
58
+ };
59
+ },
60
+ });
61
+ }
62
+ //# sourceMappingURL=node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.js","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,UAAU,IAAI,eAAe,EAAqB,MAAM,UAAU,CAAC;AAE5E,8EAA8E;AAC9E,MAAM,UAAU,UAAU,CAAC,IAAY,EAAE,IAAI,GAAG,GAAG;IACjD,OAAO,eAAe,CAAC,IAAI,EAAE,IAAI,EAAE;QACjC,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI;YACtB,oEAAoE;YACpE,qEAAqE;YACrE,kEAAkE;YAClE,MAAM,MAAM,GAAG,gBAAgB,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;YACpF,uEAAuE;YACvE,oEAAoE;YACpE,yEAAyE;YACzE,MAAM,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAC3C,MAAM,CAAC,QAAQ,CAAC,EAAE,eAAe,EAAE,KAAK,EAAE,CAAC,EAC3C,EAAE,UAAU,EAAE,KAAK,EAAE,CACtB,CAAC,CAAC;YACH,MAAM,QAAQ,GAAG,IAAI,cAAc,CAAa;gBAC9C,KAAK,CAAC,UAAU;oBACd,gEAAgE;oBAChE,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;gBACzD,CAAC;gBACD,KAAK,CAAC,IAAI;oBACR,OAAO,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,MAAM,MAAM,CAAC;gBACf,CAAC;aACF,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,105 @@
1
+ import type { HttpRequest, IoChannel, IssuanceConfig, LoggingConfig, LoggingLevel, CrateLogFilter, ProgressCallback, ProveOutput, RevealPolicy } from "./types.js";
2
+ /** Wire shape of the generated `LoggingConfig` (required-but-nullable, snake_case). */
3
+ export interface WasmLoggingConfig {
4
+ level: LoggingLevel | undefined;
5
+ crate_filters: CrateLogFilter[] | undefined;
6
+ }
7
+ /** Wire shape of the generated `HttpRequest` (`body` is tsify `number[]`). */
8
+ export interface WasmHttpRequest {
9
+ method: string;
10
+ uri: string;
11
+ headers?: [string, string][];
12
+ body?: number[];
13
+ }
14
+ /** Wire shape of the generated `HttpResponse` (`body` is tsify `number[]`). */
15
+ export interface WasmHttpResponse {
16
+ status: number;
17
+ headers: [string, string][];
18
+ body: number[];
19
+ }
20
+ /**
21
+ * The members of the generated `ProveOutput` class the façade reads. The
22
+ * getters copy out of wasm memory, so after reading all three the handle is
23
+ * `free()`d eagerly rather than left to `[Symbol.dispose]`.
24
+ */
25
+ export interface WasmProveOutput {
26
+ readonly attestation: Uint8Array;
27
+ readonly secrets: Uint8Array;
28
+ readonly response: WasmHttpResponse;
29
+ free(): void;
30
+ }
31
+ /**
32
+ * The subset of the generated wasm module `createProver` drives — exactly
33
+ * what `import * as wasm from ".../pkg/client_wasm.js"` provides
34
+ * (`wasm-compat.ts` asserts the generated module satisfies this). The
35
+ * web-spawn glue (`startSpawner`, `web_spawn_*`) is deliberately not part of
36
+ * the contract: it is called by the pkg's own worker snippet through the
37
+ * pkg's module identity and is meaningless behind a façade (journal 21).
38
+ */
39
+ export interface ClientWasmModule {
40
+ /**
41
+ * wasm-pack `--target web`'s default-export `init` (`__wbg_init`): fetches
42
+ * and instantiates the `.wasm` relative to the pkg module. Optional so a
43
+ * pre-instantiated or hand-assembled module can be injected; when present,
44
+ * the façade calls it (once) before anything else.
45
+ */
46
+ default?: () => Promise<unknown>;
47
+ initialize(loggingConfig: WasmLoggingConfig | null | undefined, threadCount: number): Promise<void>;
48
+ prove(notaryIo: IoChannel, serverIo: IoChannel, config: IssuanceConfig, request: WasmHttpRequest, progressCb?: ProgressCallback | null): Promise<WasmProveOutput>;
49
+ present(attestationBytes: Uint8Array, secretsBytes: Uint8Array, policy?: RevealPolicy | null): Uint8Array;
50
+ }
51
+ /**
52
+ * The pass-through prover surface: the wasm API's three calls with the same
53
+ * shapes, minus the setup and wire warts (see each method).
54
+ */
55
+ export interface Prover {
56
+ /**
57
+ * One-time setup: instantiates the wasm module (the pkg's default `init()`,
58
+ * if the injected module carries one) and starts logging + the rayon thread
59
+ * pool (`wasm.initialize`). Idempotent — concurrent and repeat calls share
60
+ * one underlying run; arguments of later calls are ignored. On failure the
61
+ * memo is released so a genuine retry (e.g. after fixing COOP/COEP) re-runs.
62
+ *
63
+ * `threadCount` defaults to `navigator.hardwareConcurrency` clamped to
64
+ * [1, 8] (8 is the extension harness default).
65
+ */
66
+ initialize(loggingConfig?: LoggingConfig | null, threadCount?: number): Promise<void>;
67
+ /**
68
+ * One full issuance over the two injected IO channels — MPC-TLS with the
69
+ * notary over `notaryIo`, the single HTTP exchange with the target over
70
+ * `serverIo` — yielding the notary-signed attestation. Pass-through to
71
+ * `wasm.prove` with the conversions applied (request/response `body` bytes,
72
+ * typed progress callback) and the returned wasm handle copied out and
73
+ * freed. Runs `initialize()` with defaults first if it was never called.
74
+ * `serverIo` may be a direct TCP channel or a WS-to-TCP proxy channel;
75
+ * either supplies raw bytes, with TLS performed inside the prover.
76
+ */
77
+ prove(notaryIo: IoChannel, serverIo: IoChannel, config: IssuanceConfig, request: HttpRequest, progressCb?: ProgressCallback | null): Promise<ProveOutput>;
78
+ /**
79
+ * Builds a verifiable `Presentation` from a persisted
80
+ * `(attestation, secrets)` pair, revealing exactly what `policy` permits —
81
+ * pass-through to `wasm.present`. Offline (no notary, no network, no rayon
82
+ * pool), but the wasm module must be *instantiated*: await `initialize()`
83
+ * (or a `prove()`) once beforehand, or instantiate the pkg yourself before
84
+ * injecting it. When `policy` is omitted the wasm side applies
85
+ * `client_core::HttpRevealPolicy::default` — it redacts the
86
+ * `authorization` / `cookie` / `user-agent` header values but **reveals the
87
+ * request target (path+query)**; supply an explicit policy to withhold it.
88
+ */
89
+ present(attestationBytes: Uint8Array, secretsBytes: Uint8Array, policy?: RevealPolicy | null): Uint8Array;
90
+ }
91
+ /**
92
+ * Wraps an injected `client-wasm` pkg module in the pass-through `Prover`
93
+ * façade. The caller keeps ownership of the import — typically
94
+ * `import * as wasm from "./pkg/client_wasm.js"` kept `--external` in the
95
+ * bundle — and hands it in:
96
+ *
97
+ * ```ts
98
+ * import * as wasm from "./pkg/client_wasm.js"; // loose, external
99
+ * import { createProver } from "client-wasm-transport";
100
+ *
101
+ * const prover = createProver(wasm);
102
+ * ```
103
+ */
104
+ export declare function createProver(wasm: ClientWasmModule): Prover;
105
+ //# sourceMappingURL=prover.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prover.d.ts","sourceRoot":"","sources":["../src/prover.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EACV,WAAW,EAEX,SAAS,EACT,cAAc,EACd,aAAa,EACb,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,WAAW,EACX,YAAY,EACb,MAAM,YAAY,CAAC;AAQpB,uFAAuF;AACvF,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,YAAY,GAAG,SAAS,CAAC;IAChC,aAAa,EAAE,cAAc,EAAE,GAAG,SAAS,CAAC;CAC7C;AAED,8EAA8E;AAC9E,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;IAC7B,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,+EAA+E;AA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W,EACpB,UAAU,CAAC,EAAE,gBAAgB,GAAG,IAAI,GACnC,OAAO,CAAC,WAAW,CAAC,CAAC;IAExB;;;;;;;;;;OAUG;IACH,OAAO,CACL,gBAAgB,EAAE,UAAU,EAC5B,YAAY,EAAE,UAAU,EACxB,MAAM,CAAC,EAAE,YAAY,GAAG,IAAI,GAC3B,UAAU,CAAC;CACf;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,gBAAgB,GAAG,MAAM,CAE3D"}
@@ -0,0 +1,139 @@
1
+ // The injection-based pass-through façade over the `client-wasm` prover.
2
+ //
3
+ // `createProver(wasm)` mirrors the wasm API surface — `initialize` / `prove` /
4
+ // `present`, same call shapes — while owning the setup the raw pkg leaves to
5
+ // the caller (module instantiation via the default-export `init()`, then the
6
+ // rayon-pool `initialize()`) and absorbing the wire conversions (tsify
7
+ // `number[]` bodies ↔ `Uint8Array`, the `crate_filters` snake_case wart, the
8
+ // disposable `ProveOutput` class → a plain object).
9
+ //
10
+ // **Why injection instead of `import ... from "client-wasm"`:** this package
11
+ // is inlined by the extension bundle while the wasm-pack `pkg/` must stay
12
+ // loose (its rayon spawner does `new Worker(new URL("./spawn.js",
13
+ // import.meta.url))` and fetches the `.wasm` via `import.meta.url` — inlining
14
+ // 404s both, and `--external:./pkg/*` cannot catch a bare specifier). A value
15
+ // re-export here would therefore either tree-shake away the instantiation
16
+ // chain (green build, dead API) or double-instantiate the module. Measured in
17
+ // branch journal entries 20/21; the caller passing in its own pkg import is
18
+ // the only shape that keeps `sideEffects: false` honest, the transport
19
+ // inlinable, and the wasm module single-instance.
20
+ //
21
+ // Because the *module namespace itself* is injected, its `import.meta.url`
22
+ // semantics are untouched: calling `wasm.default()` from here still resolves
23
+ // `client_wasm_bg.wasm` (and the worker `spawn.js`) relative to the loose
24
+ // `pkg/`, so the façade can safely own the init lifecycle.
25
+ /**
26
+ * Wraps an injected `client-wasm` pkg module in the pass-through `Prover`
27
+ * façade. The caller keeps ownership of the import — typically
28
+ * `import * as wasm from "./pkg/client_wasm.js"` kept `--external` in the
29
+ * bundle — and hands it in:
30
+ *
31
+ * ```ts
32
+ * import * as wasm from "./pkg/client_wasm.js"; // loose, external
33
+ * import { createProver } from "client-wasm-transport";
34
+ *
35
+ * const prover = createProver(wasm);
36
+ * ```
37
+ */
38
+ export function createProver(wasm) {
39
+ return new WasmProver(wasm);
40
+ }
41
+ class WasmProver {
42
+ #wasm;
43
+ /** Memoized `wasm.default()` (module instantiation); cleared on failure. */
44
+ #instantiation = null;
45
+ /** True once instantiation has resolved — used only to enrich `present` errors. */
46
+ #instantiated = false;
47
+ /** Memoized full `initialize()` run; cleared on failure so a retry re-runs. */
48
+ #initialized = null;
49
+ constructor(wasm) {
50
+ this.#wasm = wasm;
51
+ }
52
+ initialize(loggingConfig, threadCount) {
53
+ this.#initialized ??= this.#runInitialize(loggingConfig, threadCount);
54
+ return this.#initialized;
55
+ }
56
+ async prove(notaryIo, serverIo, config, request, progressCb) {
57
+ await this.initialize();
58
+ const out = await this.#wasm.prove(notaryIo, serverIo, config, toWireRequest(request), progressCb ?? null);
59
+ try {
60
+ return {
61
+ attestation: out.attestation,
62
+ secrets: out.secrets,
63
+ response: fromWireResponse(out.response),
64
+ };
65
+ }
66
+ finally {
67
+ out.free();
68
+ }
69
+ }
70
+ present(attestationBytes, secretsBytes, policy) {
71
+ try {
72
+ return this.#wasm.present(attestationBytes, secretsBytes, policy ?? null);
73
+ }
74
+ catch (cause) {
75
+ // An un-instantiated module fails with a TypeError on the pkg's
76
+ // module-level `wasm` binding — turn that into an actionable message.
77
+ // (If the caller instantiated the pkg itself, #instantiated is false
78
+ // but present() simply succeeds, so this never misfires on real
79
+ // presentation errors — those are not TypeErrors.)
80
+ if (!this.#instantiated && cause instanceof TypeError) {
81
+ throw new Error("present() called before the wasm module was instantiated — " +
82
+ "await prover.initialize() (or a prove()) once first", { cause });
83
+ }
84
+ throw cause;
85
+ }
86
+ }
87
+ async #runInitialize(loggingConfig, threadCount) {
88
+ try {
89
+ await this.#ensureInstantiated();
90
+ await this.#wasm.initialize(toWireLogging(loggingConfig), threadCount ?? defaultThreadCount());
91
+ }
92
+ catch (err) {
93
+ // Release the memo: wasm-side initialize releases its one-time claim on
94
+ // failure precisely so a retry can proceed — mirror that here.
95
+ this.#initialized = null;
96
+ throw err;
97
+ }
98
+ }
99
+ async #ensureInstantiated() {
100
+ // `init()` is idempotent in the generated glue, but memoize anyway so an
101
+ // injected module without the guard (or a hand-built one) is safe too.
102
+ this.#instantiation ??= this.#wasm.default?.() ?? Promise.resolve();
103
+ try {
104
+ await this.#instantiation;
105
+ }
106
+ catch (err) {
107
+ this.#instantiation = null; // e.g. the .wasm fetch failed — allow retry
108
+ throw err;
109
+ }
110
+ this.#instantiated = true;
111
+ }
112
+ }
113
+ // --- Conversions ----------------------------------------------------------------
114
+ function toWireLogging(config) {
115
+ if (config == null)
116
+ return null;
117
+ return { level: config.level, crate_filters: config.crateFilters };
118
+ }
119
+ function toWireRequest(request) {
120
+ const wire = { method: request.method, uri: request.uri };
121
+ if (request.headers !== undefined)
122
+ wire.headers = request.headers;
123
+ // Always hand serde a plain number[] — tsify renders `Vec<u8>` as number[],
124
+ // and a Uint8Array is not guaranteed to deserialize as one.
125
+ if (request.body !== undefined)
126
+ wire.body = Array.from(request.body);
127
+ return wire;
128
+ }
129
+ function fromWireResponse(wire) {
130
+ return { status: wire.status, headers: wire.headers, body: Uint8Array.from(wire.body) };
131
+ }
132
+ function defaultThreadCount() {
133
+ const n = globalThis.navigator
134
+ ?.hardwareConcurrency;
135
+ // Cap at 8 — the extension harness default (prover-worker.js): each rayon
136
+ // thread is a real web worker, and past ~8 the MPC gains nothing.
137
+ return typeof n === "number" && n >= 1 ? Math.min(Math.floor(n), 8) : 8;
138
+ }
139
+ //# sourceMappingURL=prover.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prover.js","sourceRoot":"","sources":["../src/prover.ts"],"names":[],"mappings":"AAAA,y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;IAC1E,kEAAkE;IAClE,OAAO,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC1E,CAAC"}
@@ -0,0 +1,38 @@
1
+ import type { IoChannel } from "./types.js";
2
+ /**
3
+ * An established raw TCP socket supplied by the host (Node, Electron, or a
4
+ * native bridge). No TLS or WebSocket framing: the prover owns TLS.
5
+ * Both streams must be unlocked, binary, and propagate socket errors.
6
+ */
7
+ export interface TcpSocket {
8
+ readable: {
9
+ getReader(): ReadableStreamDefaultReader<Uint8Array>;
10
+ };
11
+ writable: {
12
+ getWriter(): WritableStreamDefaultWriter<Uint8Array>;
13
+ };
14
+ /** Release the socket, including its read side. Must unblock pending reads. */
15
+ close(): Promise<void>;
16
+ }
17
+ export interface TcpConnectOptions {
18
+ /**
19
+ * Resolve only once connected, with TCP_NODELAY enabled. The host owns DNS,
20
+ * permissions, connection timeouts, and cleanup if connecting fails.
21
+ */
22
+ connect(host: string, port: number): Promise<TcpSocket>;
23
+ }
24
+ /** A host TCP socket adapted to the same IoChannel accepted by prove(). */
25
+ export declare class TcpIoChannel implements IoChannel {
26
+ #private;
27
+ constructor(socket: TcpSocket);
28
+ read(): Promise<Uint8Array | null>;
29
+ write(data: Uint8Array): Promise<void>;
30
+ close(): Promise<void>;
31
+ }
32
+ /**
33
+ * Open a direct TCP target channel through a host connector. Ordinary browser
34
+ * pages need connectProxy; Node users can import connectTcp from the /node
35
+ * entry point, which supplies the connector.
36
+ */
37
+ export declare function connectTcp(host: string, port: number, opts: TcpConnectOptions): Promise<TcpIoChannel>;
38
+ //# sourceMappingURL=tcp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tcp.d.ts","sourceRoot":"","sources":["../src/tcp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C;;;;GAIG;AACH,MAAM,WAAW,SAAS;IAGxB,QAAQ,EAAE;QAAE,SAAS,IAAI,2BAA2B,CAAC,UAAU,CAAC,CAAA;KAAE,CAAC;IACnE,QAAQ,EAAE;QAAE,SAAS,IAAI,2BAA2B,CAAC,UAAU,CAAC,CAAA;KAAE,CAAC;IACnE,+EAA+E;IAC/E,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;CACzD;AAED,2EAA2E;AAC3E,qBAAa,YAAa,YAAW,SAAS;;IAO5C,YAAY,MAAM,EAAE,SAAS,EAa5B;IAEK,IAAI,IAAI,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAQvC;IAEK,KAAK,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAK3C;IAED,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CASrB;CAgBF;AAED;;;;GAIG;AACH,wBAAsB,UAAU,CAC9B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,iBAAiB,GACtB,OAAO,CAAC,YAAY,CAAC,CAWvB"}
@@ -0,0 +1,88 @@
1
+ /** A host TCP socket adapted to the same IoChannel accepted by prove(). */
2
+ export class TcpIoChannel {
3
+ #socket;
4
+ #reader;
5
+ #writer;
6
+ #closePromise;
7
+ #writeEnded = false;
8
+ constructor(socket) {
9
+ this.#socket = socket;
10
+ this.#reader = socket.readable.getReader();
11
+ try {
12
+ this.#writer = socket.writable.getWriter();
13
+ }
14
+ catch (error) {
15
+ this.#reader.releaseLock();
16
+ throw error;
17
+ }
18
+ // Stream errors are surfaced by read/write/close, even when they arrive
19
+ // while WASM is busy doing MPC computation and no operation is pending.
20
+ this.#reader.closed.catch(() => { });
21
+ this.#writer.closed.then(() => { this.#writeEnded = true; }, () => { });
22
+ }
23
+ async read() {
24
+ if (this.#closePromise)
25
+ return null;
26
+ for (;;) {
27
+ const { value, done } = await this.#reader.read();
28
+ if (done)
29
+ return null;
30
+ // Rust treats an empty chunk as EOF; only an actual stream end is EOF.
31
+ if (value.byteLength !== 0)
32
+ return value;
33
+ }
34
+ }
35
+ async write(data) {
36
+ if (this.#closePromise)
37
+ throw new Error("cannot write: TCP channel is closed");
38
+ // Own the bytes before yielding. WASM may reuse its shared memory and a
39
+ // Node Buffer's slice() would only create another view of the same bytes.
40
+ await this.#writer.write(new Uint8Array(data));
41
+ }
42
+ close() {
43
+ if (!this.#closePromise) {
44
+ this.#closePromise = this.#close();
45
+ // JsIoAdapter currently starts close without awaiting its promise.
46
+ // Prevent an unhandled rejection there; explicit callers still receive
47
+ // the original rejected promise and can observe cleanup failures.
48
+ this.#closePromise.catch(() => { });
49
+ }
50
+ return this.#closePromise;
51
+ }
52
+ async #close() {
53
+ try {
54
+ // Web Streams serializes this after all accepted writes.
55
+ if (!this.#writeEnded)
56
+ await this.#writer.close();
57
+ }
58
+ finally {
59
+ try {
60
+ await this.#socket.close();
61
+ }
62
+ finally {
63
+ await this.#reader.cancel().catch(() => { });
64
+ this.#reader.releaseLock();
65
+ this.#writer.releaseLock();
66
+ }
67
+ }
68
+ }
69
+ }
70
+ /**
71
+ * Open a direct TCP target channel through a host connector. Ordinary browser
72
+ * pages need connectProxy; Node users can import connectTcp from the /node
73
+ * entry point, which supplies the connector.
74
+ */
75
+ export async function connectTcp(host, port, opts) {
76
+ if (!host || !Number.isInteger(port) || port < 1 || port > 65535) {
77
+ throw new Error("TCP destination requires a host and a port between 1 and 65535");
78
+ }
79
+ const socket = await opts.connect(host, port);
80
+ try {
81
+ return new TcpIoChannel(socket);
82
+ }
83
+ catch (error) {
84
+ await socket.close().catch(() => { });
85
+ throw error;
86
+ }
87
+ }
88
+ //# source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AI,GAAG,CAAC,IAAI,IAAI,GAAG,KAAK,EAAE,CAAC;QACjE,MAAM,IAAI,KAAK,CAAC,gEAAgE,CAAC,CAAC;IACpF,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC9C,IAAI,CAAC;QACH,OAAO,IAAI,YAAY,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QACrC,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,31 @@
1
+ import { WsIoChannel, type WebSocketCtor } from "./channel.js";
2
+ /**
3
+ * WebSocket subprotocol marker for the notary channel. **Must** match the
4
+ * notary's `transport::SUBPROTOCOL` and the native `ws.rs` `SUBPROTOCOL`
5
+ * (`tlsn.notary.v2`) — bump all three together on a contract change.
6
+ */
7
+ export declare const NOTARY_SUBPROTOCOL = "tlsn.notary.v2";
8
+ /** Shared options for the `connect*` helpers. */
9
+ export interface ConnectOptions {
10
+ /**
11
+ * `WebSocket` implementation to use. Defaults to the global browser
12
+ * `WebSocket`. Inject a polyfill (e.g. Node's `ws`) to run outside a browser.
13
+ */
14
+ WebSocketImpl?: WebSocketCtor;
15
+ }
16
+ /**
17
+ * Connect the notary channel, offering `tlsn.notary.v2, bearer.<token>` in
18
+ * `Sec-WebSocket-Protocol`, and resolve once the socket is open with the
19
+ * negotiated subprotocol confirmed to be `tlsn.notary.v2` (the notary echoes
20
+ * back only the marker, never the token).
21
+ */
22
+ export declare function connectNotary(url: string, token: string, opts?: ConnectOptions): Promise<WsIoChannel>;
23
+ /**
24
+ * Connect the target byte pipe through the `p2p-wss-proxy` worker: opens
25
+ * `ws://<proxyBase>/?host=<host>&port=<port>` (no subprotocol / auth — the proxy
26
+ * reads its target from the query string), and resolves once open. The worker
27
+ * opens a raw TCP socket to `host:port` and relays bytes; MPC-TLS then runs over
28
+ * this pipe inside `prove()`.
29
+ */
30
+ export declare function connectProxy(proxyBase: string, host: string, port: number, opts?: ConnectOptions): Promise<WsIoChannel>;
31
+ //# sourceMappingURL=transport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,WAAW,EAAE,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AAE/D;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,mBAAmB,CAAC;AAEnD,iDAAiD;AACjD,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,aAAa,CAAC,EAAE,aAAa,CAAC;CAC/B;AAaD;;;;;GAKG;AACH,wBAAsB,aAAa,CACjC,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,IAAI,CAAC,EAAE,cAAc,GACpB,OAAO,CAAC,WAAW,CAAC,CAgBtB;AAED;;;;;;GAMG;AACH,wBAAsB,YAAY,CAChC,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,cAAc,GACpB,OAAO,CAAC,WAAW,CAAC,CAWtB"}
@@ -0,0 +1,75 @@
1
+ // WebSocket transport for the `client-wasm` browser-extension prover.
2
+ //
3
+ // Provides the two `IoChannel`s that `prove()` (see `client_wasm.d.ts`) needs,
4
+ // mirroring the native `connect_notary` / `connect_proxy` in
5
+ // `test-full-e2e/src/ws.rs`:
6
+ //
7
+ // - `connectNotary(url, token)` — the notary socket, authenticated via the
8
+ // `Sec-WebSocket-Protocol` bearer subprotocol (browsers can't set an
9
+ // `Authorization` header on a WS handshake — only subprotocols — so the
10
+ // contract carries the token this way; CLIENT_CONTRACT §2).
11
+ // - `connectProxy(proxyBase, host, port)` — the target byte pipe, tunnelled
12
+ // through the `p2p-wss-proxy` worker (a browser extension can't open raw
13
+ // TCP, so `serverIo` is WS → proxy → TCP; JOURNAL toplevel/06).
14
+ //
15
+ // Both return a `WsIoChannel` (see `./channel`) already open, so a bad handshake
16
+ // (auth failure, unreachable proxy) rejects here rather than surfacing later as
17
+ // a mid-MPC read error.
18
+ import { WsIoChannel } from "./channel.js";
19
+ /**
20
+ * WebSocket subprotocol marker for the notary channel. **Must** match the
21
+ * notary's `transport::SUBPROTOCOL` and the native `ws.rs` `SUBPROTOCOL`
22
+ * (`tlsn.notary.v2`) — bump all three together on a contract change.
23
+ */
24
+ export const NOTARY_SUBPROTOCOL = "tlsn.notary.v2";
25
+ function resolveWebSocket(opts) {
26
+ const impl = opts?.WebSocketImpl ?? globalThis.WebSocket;
27
+ if (!impl) {
28
+ throw new Error("no WebSocket implementation: not in a browser and none injected — " +
29
+ "pass { WebSocketImpl } (e.g. Node's `ws` package)");
30
+ }
31
+ return impl;
32
+ }
33
+ /**
34
+ * Connect the notary channel, offering `tlsn.notary.v2, bearer.<token>` in
35
+ * `Sec-WebSocket-Protocol`, and resolve once the socket is open with the
36
+ * negotiated subprotocol confirmed to be `tlsn.notary.v2` (the notary echoes
37
+ * back only the marker, never the token).
38
+ */
39
+ export async function connectNotary(url, token, opts) {
40
+ const WS = resolveWebSocket(opts);
41
+ const ws = new WS(url, [NOTARY_SUBPROTOCOL, `bearer.${token}`]);
42
+ const channel = new WsIoChannel(ws);
43
+ try {
44
+ await channel.whenReady();
45
+ }
46
+ catch (cause) {
47
+ throw new Error(`notary websocket handshake failed (auth?): ${url}`, { cause });
48
+ }
49
+ if (channel.protocol !== NOTARY_SUBPROTOCOL) {
50
+ await channel.close();
51
+ throw new Error(`notary negotiated an unexpected subprotocol: ${JSON.stringify(channel.protocol)}`);
52
+ }
53
+ return channel;
54
+ }
55
+ /**
56
+ * Connect the target byte pipe through the `p2p-wss-proxy` worker: opens
57
+ * `ws://<proxyBase>/?host=<host>&port=<port>` (no subprotocol / auth — the proxy
58
+ * reads its target from the query string), and resolves once open. The worker
59
+ * opens a raw TCP socket to `host:port` and relays bytes; MPC-TLS then runs over
60
+ * this pipe inside `prove()`.
61
+ */
62
+ export async function connectProxy(proxyBase, host, port, opts) {
63
+ const WS = resolveWebSocket(opts);
64
+ const url = `${proxyBase.replace(/\/+$/, "")}/?host=${encodeURIComponent(host)}&port=${port}`;
65
+ const ws = new WS(url);
66
+ const channel = new WsIoChannel(ws);
67
+ try {
68
+ await channel.whenReady();
69
+ }
70
+ catch (cause) {
71
+ throw new Error(`proxy websocket handshake failed: ${url}`, { cause });
72
+ }
73
+ return channel;
74
+ }
75
+ //# sourceMappingURL=transport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport.js","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,EAAE;AACF,+EAA+E;AAC/E,6DAA6D;AAC7D,6BAA6B;AAC7B,EAAE;AACF,8EAA8E;AAC9E,yEAAyE;AACzE,4EAA4E;AAC5E,gEAAgE;AAChE,8EAA8E;AAC9E,6EAA6E;AAC7E,oEAAoE;AACpE,EAAE;AACF,iFAAiF;AACjF,gFAAgF;AAChF,wBAAwB;AAExB,OAAO,EAAE,WAAW,EAAsB,MAAM,cAAc,CAAC;AAE/D;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,gBAAgB,CAAC;AAWnD,SAAS,gBAAgB,CAAC,IAAqB;IAC7C,MAAM,IAAI,GAAG,IAAI,EAAE,aAAa,IAAK,UAA4C,CAAC,SAAS,CAAC;IAC5F,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,IAAI,KAAK,CACb,oEAAoE;YAClE,mDAAmD,CACtD,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,GAAW,EACX,KAAa,EACb,IAAqB;IAErB,MAAM,EAAE,GAAG,gBAAgB,CAAC,IAAI,CA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