@floegence/flowersec-core 3.2.1 → 5.0.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.
- package/README.md +57 -200
- package/THIRD_PARTY_NOTICES.md +11 -11
- package/dist/browser/index.d.ts +0 -5
- package/dist/browser/index.js +0 -3
- package/dist/cli.js +93 -64
- package/dist/facade.d.ts +0 -17
- package/dist/facade.js +0 -11
- package/dist/generated/unicode151.d.ts +2 -0
- package/dist/generated/unicode151.js +83 -0
- package/dist/interop/proxyServerPeer.js +34 -20
- package/dist/interop/serverParityPeer.js +11 -252
- package/dist/node/acceptor.d.ts +1 -57
- package/dist/node/acceptor.js +3 -420
- package/dist/node/acceptorV3.js +2 -2
- package/dist/node/connectSessionV3.js +2 -2
- package/dist/node/index.d.ts +2 -17
- package/dist/node/index.js +1 -9
- package/dist/node/nativeTransportAddon.d.ts +7 -36
- package/dist/node/nativeTransportAddon.js +7 -27
- package/dist/node/proxyServer.d.ts +2 -2
- package/dist/node/proxyServer.js +2 -2
- package/dist/node/rawQuicAdapterV3.d.ts +2 -2
- package/dist/node/rawQuicAdapterV3.js +1 -1
- package/dist/node/rawQuicServerV3.d.ts +2 -2
- package/dist/node/rawQuicServerV3.js +1 -1
- package/dist/node/rawQuicTls.d.ts +2 -0
- package/dist/node/{rawQuicAdapter.js → rawQuicTls.js} +30 -45
- package/dist/node/tunnelRuntimeV3.js +2 -2
- package/dist/proxy/index.d.ts +1 -1
- package/dist/proxy/index.js +1 -1
- package/dist/proxy/integration.d.ts +5 -5
- package/dist/proxy/integration.js +2 -2
- package/dist/proxy/runtime.js +11 -26
- package/dist/proxy/serviceWorkerRuntime.d.ts +7 -0
- package/dist/proxy/serviceWorkerRuntime.js +75 -0
- package/dist/proxy/types.d.ts +0 -1
- package/dist/proxy/windowBridge.d.ts +2 -0
- package/dist/proxy/windowBridge.js +53 -6
- package/dist/public/contract.d.ts +1 -3
- package/dist/public/streamHandlers.d.ts +0 -3
- package/dist/public/streamHandlers.js +2 -4
- package/dist/public/streamMetadata.js +2 -2
- package/dist/runtime/errors.d.ts +2 -2
- package/dist/testSupport/tlsFixture.d.ts +2 -0
- package/dist/testSupport/tlsFixture.js +8 -0
- package/dist/utils/errors.d.ts +0 -2
- package/dist/utils/errors.js +0 -80
- package/dist/v3/artifact.js +17 -3
- package/dist/v3/carrier.d.ts +2 -2
- package/dist/v3/controller.js +2 -6
- package/dist/v3/protocol.js +2 -103
- package/dist/v3/retryDisposition.d.ts +2 -2
- package/dist/v3/retryDisposition.js +0 -7
- package/dist/v3/security.d.ts +1 -10
- package/dist/v3/security.js +2 -9
- package/dist/vendor/tr46.d.ts +4 -0
- package/dist/vendor/tr46.js +37 -32
- package/package.json +19 -17
- package/sbom/cyclonedx.json +62 -62
- package/sbom/spdx.json +65 -65
- package/dist/browser/connectSession.d.ts +0 -13
- package/dist/browser/connectSession.js +0 -40
- package/dist/browser/runtimeCapability.d.ts +0 -13
- package/dist/browser/runtimeCapability.js +0 -27
- package/dist/browser/sessionRuntime.d.ts +0 -2
- package/dist/browser/sessionRuntime.js +0 -21
- package/dist/browser/v2.d.ts +0 -3
- package/dist/browser/v2.js +0 -2
- package/dist/browser/webTransportClient.d.ts +0 -8
- package/dist/browser/webTransportClient.js +0 -55
- package/dist/connectionController.d.ts +0 -55
- package/dist/connectionController.js +0 -441
- package/dist/connector/adapters/rawQuicCandidate.d.ts +0 -5
- package/dist/connector/adapters/rawQuicCandidate.js +0 -71
- package/dist/connector/adapters/webSocketCandidate.d.ts +0 -7
- package/dist/connector/adapters/webSocketCandidate.js +0 -116
- package/dist/connector/adapters/webTransportCandidate.d.ts +0 -5
- package/dist/connector/adapters/webTransportCandidate.js +0 -73
- package/dist/connector/admissionCommit.d.ts +0 -31
- package/dist/connector/admissionCommit.js +0 -239
- package/dist/connector/sessionAcceptor.d.ts +0 -38
- package/dist/connector/sessionAcceptor.js +0 -158
- package/dist/connector/sessionConfig.d.ts +0 -3
- package/dist/connector/sessionConfig.js +0 -30
- package/dist/connector/sessionConnector.d.ts +0 -47
- package/dist/connector/sessionConnector.js +0 -606
- package/dist/node/connectSession.d.ts +0 -23
- package/dist/node/connectSession.js +0 -93
- package/dist/node/controlplane.d.ts +0 -137
- package/dist/node/controlplane.js +0 -443
- package/dist/node/rawQuicAdapter.d.ts +0 -9
- package/dist/node/rawQuicServer.d.ts +0 -24
- package/dist/node/rawQuicServer.js +0 -37
- package/dist/node/runtimeCapability.d.ts +0 -14
- package/dist/node/runtimeCapability.js +0 -24
- package/dist/node/sessionRuntime.d.ts +0 -2
- package/dist/node/sessionRuntime.js +0 -13
- package/dist/node/tunnelRuntime.d.ts +0 -42
- package/dist/node/tunnelRuntime.js +0 -559
- package/dist/node/v2.d.ts +0 -11
- package/dist/node/v2.js +0 -6
- package/dist/node/webSocketServer.d.ts +0 -24
- package/dist/node/webSocketServer.js +0 -135
- package/dist/public/artifact.d.ts +0 -11
- package/dist/public/artifact.js +0 -44
- package/dist/public/artifactLease.d.ts +0 -10
- package/dist/public/artifactLease.js +0 -41
- package/dist/public/connectError.d.ts +0 -6
- package/dist/public/connectError.js +0 -9
- package/dist/transport/webSocketAdapter.d.ts +0 -31
- package/dist/transport/webSocketAdapter.js +0 -370
- package/dist/transport/webTransportAdapter.d.ts +0 -27
- package/dist/transport/webTransportAdapter.js +0 -534
- package/dist/v2/admissionError.d.ts +0 -4
- package/dist/v2/admissionError.js +0 -8
- package/dist/v2/artifact.d.ts +0 -128
- package/dist/v2/artifact.js +0 -1131
- package/dist/v2/artifactLease.d.ts +0 -1
- package/dist/v2/artifactLease.js +0 -7
- package/dist/v2/capability.d.ts +0 -29
- package/dist/v2/capability.js +0 -190
- package/dist/v2/carrier.d.ts +0 -84
- package/dist/v2/carrier.js +0 -411
- package/dist/v2/contract.d.ts +0 -46
- package/dist/v2/contract.js +0 -1
- package/dist/v2/handshake.d.ts +0 -80
- package/dist/v2/handshake.js +0 -470
- package/dist/v2/index.d.ts +0 -14
- package/dist/v2/index.js +0 -7
- package/dist/v2/opaqueArtifact.d.ts +0 -1
- package/dist/v2/opaqueArtifact.js +0 -2
- package/dist/v2/protocol.d.ts +0 -99
- package/dist/v2/protocol.js +0 -737
- package/dist/v2/publicSession.d.ts +0 -1
- package/dist/v2/publicSession.js +0 -281
- package/dist/v2/retryDisposition.d.ts +0 -16
- package/dist/v2/retryDisposition.js +0 -30
- package/dist/v2/session.d.ts +0 -310
- package/dist/v2/session.js +0 -2127
- package/dist/v2/streamLifetimeLedger.d.ts +0 -31
- package/dist/v2/streamLifetimeLedger.js +0 -131
- package/dist/v2/streamMetadata.d.ts +0 -1
- package/dist/v2/streamMetadata.js +0 -7
- package/dist/v2/unreliableMessage.d.ts +0 -43
- package/dist/v2/unreliableMessage.js +0 -254
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { type NativeCarrierSessionV2 } from "../v2/carrier.js";
|
|
2
|
-
import type { PathKind } from "../v2/contract.js";
|
|
3
|
-
export type WebTransportBidirectionalLikeV2 = Readonly<{
|
|
4
|
-
readable: ReadableStream<Uint8Array>;
|
|
5
|
-
writable: WritableStream<Uint8Array>;
|
|
6
|
-
}>;
|
|
7
|
-
export type WebTransportDatagramsLikeV2 = Readonly<{
|
|
8
|
-
readable: ReadableStream<Uint8Array>;
|
|
9
|
-
writable: WritableStream<Uint8Array>;
|
|
10
|
-
maxDatagramSize?: number;
|
|
11
|
-
}>;
|
|
12
|
-
export type WebTransportSessionLikeV2 = Readonly<{
|
|
13
|
-
closed: Promise<unknown>;
|
|
14
|
-
incomingBidirectionalStreams: ReadableStream<WebTransportBidirectionalLikeV2>;
|
|
15
|
-
datagrams: WebTransportDatagramsLikeV2;
|
|
16
|
-
createBidirectionalStream(): Promise<WebTransportBidirectionalLikeV2>;
|
|
17
|
-
close(info?: Readonly<{
|
|
18
|
-
closeCode: number;
|
|
19
|
-
reason: string;
|
|
20
|
-
}>): void;
|
|
21
|
-
}>;
|
|
22
|
-
export declare function adaptWebTransportCarrierSessionV2(native: WebTransportSessionLikeV2, options: Readonly<{
|
|
23
|
-
path: PathKind;
|
|
24
|
-
inboundBidirectionalStreamCapacity: number;
|
|
25
|
-
datagramMaxSize?: number;
|
|
26
|
-
}>): NativeCarrierSessionV2;
|
|
27
|
-
export declare function hasWebTransportConstructorSurfaceV2(value: unknown): boolean;
|
|
@@ -1,534 +0,0 @@
|
|
|
1
|
-
import { CarrierError, } from "../v2/carrier.js";
|
|
2
|
-
export function adaptWebTransportCarrierSessionV2(native, options) {
|
|
3
|
-
requireWebTransportSessionSurfaceV2(native);
|
|
4
|
-
return new WebTransportCarrierSessionAdapter(native, options);
|
|
5
|
-
}
|
|
6
|
-
export function hasWebTransportConstructorSurfaceV2(value) {
|
|
7
|
-
if (typeof value !== "function")
|
|
8
|
-
return false;
|
|
9
|
-
const prototype = value.prototype;
|
|
10
|
-
return typeof prototype === "object" && prototype !== null &&
|
|
11
|
-
typeof prototype.createBidirectionalStream === "function" &&
|
|
12
|
-
typeof prototype.close === "function" &&
|
|
13
|
-
"incomingBidirectionalStreams" in prototype &&
|
|
14
|
-
"datagrams" in prototype &&
|
|
15
|
-
"ready" in prototype &&
|
|
16
|
-
"closed" in prototype;
|
|
17
|
-
}
|
|
18
|
-
function requireWebTransportSessionSurfaceV2(value) {
|
|
19
|
-
const missing = [];
|
|
20
|
-
if (typeof value.createBidirectionalStream !== "function")
|
|
21
|
-
missing.push("outgoing bidirectional streams");
|
|
22
|
-
if (typeof value.incomingBidirectionalStreams?.getReader !== "function")
|
|
23
|
-
missing.push("incoming bidirectional streams");
|
|
24
|
-
if (typeof value.datagrams?.readable?.getReader !== "function")
|
|
25
|
-
missing.push("incoming DATAGRAMs");
|
|
26
|
-
if (typeof value.datagrams?.writable?.getWriter !== "function")
|
|
27
|
-
missing.push("outgoing DATAGRAMs");
|
|
28
|
-
if (typeof value.close !== "function")
|
|
29
|
-
missing.push("close");
|
|
30
|
-
if (typeof value.closed?.then !== "function")
|
|
31
|
-
missing.push("termination");
|
|
32
|
-
if (missing.length !== 0) {
|
|
33
|
-
throw new TypeError(`WebTransport runtime lacks required ${missing.join(", ")}`);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
class WebTransportCarrierSessionAdapter {
|
|
37
|
-
native;
|
|
38
|
-
kind = "webtransport";
|
|
39
|
-
path;
|
|
40
|
-
inboundBidirectionalStreamCapacity;
|
|
41
|
-
unreliableDatagrams;
|
|
42
|
-
incoming;
|
|
43
|
-
incomingQueue = new IncomingWebTransportStreamQueue();
|
|
44
|
-
streams = new Set();
|
|
45
|
-
datagramsAdapter;
|
|
46
|
-
closed = false;
|
|
47
|
-
terminalError;
|
|
48
|
-
closePromise;
|
|
49
|
-
activeIncomingStreams = 0;
|
|
50
|
-
constructor(native, options) {
|
|
51
|
-
this.native = native;
|
|
52
|
-
if (!Number.isInteger(options.inboundBidirectionalStreamCapacity) || options.inboundBidirectionalStreamCapacity < 3) {
|
|
53
|
-
throw new RangeError("WebTransport carrier stream capacity must be at least 3");
|
|
54
|
-
}
|
|
55
|
-
this.path = options.path;
|
|
56
|
-
this.inboundBidirectionalStreamCapacity = options.inboundBidirectionalStreamCapacity;
|
|
57
|
-
this.incoming = native.incomingBidirectionalStreams.getReader();
|
|
58
|
-
this.datagramsAdapter = new WebTransportDatagramAdapter(native.datagrams, options.datagramMaxSize);
|
|
59
|
-
this.unreliableDatagrams = this.datagramsAdapter;
|
|
60
|
-
void this.pumpIncoming();
|
|
61
|
-
void native.closed.then(() => { this.terminate(new CarrierError("closed", "WebTransport carrier is closed")); }, (error) => {
|
|
62
|
-
this.terminate(carrierFailure("WebTransport closed with an error", error));
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
async openStream(options = {}) {
|
|
66
|
-
this.assertOpen();
|
|
67
|
-
if (options.signal?.aborted === true)
|
|
68
|
-
throw abortedCarrierError(options.signal.reason);
|
|
69
|
-
const pending = this.native.createBidirectionalStream();
|
|
70
|
-
let stream;
|
|
71
|
-
try {
|
|
72
|
-
stream = await carrierCall(raceAbort(pending, options.signal), "WebTransport failed to open a stream");
|
|
73
|
-
}
|
|
74
|
-
catch (error) {
|
|
75
|
-
if (isAborted(options.signal)) {
|
|
76
|
-
void pending.then((late) => abortNativeStream(late, abortedCarrierError()), () => undefined);
|
|
77
|
-
}
|
|
78
|
-
throw error;
|
|
79
|
-
}
|
|
80
|
-
try {
|
|
81
|
-
this.assertOpen();
|
|
82
|
-
}
|
|
83
|
-
catch (error) {
|
|
84
|
-
abortNativeStream(stream, asError(error));
|
|
85
|
-
throw error;
|
|
86
|
-
}
|
|
87
|
-
return this.track(stream);
|
|
88
|
-
}
|
|
89
|
-
async acceptStream(options = {}) {
|
|
90
|
-
this.assertOpen();
|
|
91
|
-
return await this.incomingQueue.shift(options.signal);
|
|
92
|
-
}
|
|
93
|
-
async waitTermination() {
|
|
94
|
-
try {
|
|
95
|
-
await this.native.closed;
|
|
96
|
-
}
|
|
97
|
-
catch (error) {
|
|
98
|
-
throw carrierFailure("WebTransport terminated with an error", error);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
close() {
|
|
102
|
-
this.closePromise ??= this.closeOnce({ closeCode: 0, reason: "" });
|
|
103
|
-
return this.closePromise;
|
|
104
|
-
}
|
|
105
|
-
abort(error = { code: 6, reason: "carrier aborted" }) {
|
|
106
|
-
if (this.closed)
|
|
107
|
-
return;
|
|
108
|
-
this.terminate(new CarrierError("aborted", "WebTransport carrier aborted"));
|
|
109
|
-
try {
|
|
110
|
-
this.native.close({ closeCode: error.code, reason: error.reason });
|
|
111
|
-
}
|
|
112
|
-
catch (cause) {
|
|
113
|
-
this.terminalError = carrierFailure("WebTransport abort failed", cause);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
async closeOnce(info) {
|
|
117
|
-
if (this.closed)
|
|
118
|
-
return;
|
|
119
|
-
this.terminate(new CarrierError("closed", "WebTransport carrier is closed"));
|
|
120
|
-
try {
|
|
121
|
-
this.native.close(info);
|
|
122
|
-
await this.native.closed;
|
|
123
|
-
}
|
|
124
|
-
catch (error) {
|
|
125
|
-
throw carrierFailure("WebTransport close failed", error);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
assertOpen() {
|
|
129
|
-
if (this.terminalError !== undefined)
|
|
130
|
-
throw this.terminalError;
|
|
131
|
-
if (this.closed)
|
|
132
|
-
throw new CarrierError("closed", "WebTransport carrier is closed");
|
|
133
|
-
}
|
|
134
|
-
track(native, incoming = false) {
|
|
135
|
-
if (incoming)
|
|
136
|
-
this.activeIncomingStreams += 1;
|
|
137
|
-
let stream;
|
|
138
|
-
stream = new WebTransportCarrierStreamAdapter(native, () => {
|
|
139
|
-
this.streams.delete(stream);
|
|
140
|
-
if (incoming)
|
|
141
|
-
this.activeIncomingStreams = Math.max(0, this.activeIncomingStreams - 1);
|
|
142
|
-
});
|
|
143
|
-
this.streams.add(stream);
|
|
144
|
-
return stream;
|
|
145
|
-
}
|
|
146
|
-
async pumpIncoming() {
|
|
147
|
-
try {
|
|
148
|
-
while (!this.closed) {
|
|
149
|
-
const result = await this.incoming.read();
|
|
150
|
-
if (result.done || result.value === undefined) {
|
|
151
|
-
this.terminate(new CarrierError("closed", "WebTransport incoming streams closed"));
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
if (this.activeIncomingStreams >= this.inboundBidirectionalStreamCapacity) {
|
|
155
|
-
abortNativeStream(result.value, new CarrierError("reset", "WebTransport inbound stream capacity exceeded"));
|
|
156
|
-
continue;
|
|
157
|
-
}
|
|
158
|
-
this.incomingQueue.push(this.track(result.value, true));
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
catch (error) {
|
|
162
|
-
if (!this.closed)
|
|
163
|
-
this.terminate(carrierFailure("WebTransport stream accept failed", error));
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
terminate(error) {
|
|
167
|
-
if (this.closed)
|
|
168
|
-
return;
|
|
169
|
-
this.closed = true;
|
|
170
|
-
if (error.code !== "closed")
|
|
171
|
-
this.terminalError = error;
|
|
172
|
-
this.incomingQueue.fail(error);
|
|
173
|
-
for (const stream of [...this.streams])
|
|
174
|
-
stream.abort(error);
|
|
175
|
-
this.streams.clear();
|
|
176
|
-
this.datagramsAdapter.abort(error);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
class WebTransportCarrierStreamAdapter {
|
|
180
|
-
onRelease;
|
|
181
|
-
reader;
|
|
182
|
-
writer;
|
|
183
|
-
readClosed = false;
|
|
184
|
-
readStopError;
|
|
185
|
-
writeClosed = false;
|
|
186
|
-
terminalError;
|
|
187
|
-
closeWritePromise;
|
|
188
|
-
stopSendingPromise;
|
|
189
|
-
resetPromise;
|
|
190
|
-
released = false;
|
|
191
|
-
constructor(stream, onRelease) {
|
|
192
|
-
this.onRelease = onRelease;
|
|
193
|
-
this.reader = stream.readable.getReader();
|
|
194
|
-
this.writer = stream.writable.getWriter();
|
|
195
|
-
}
|
|
196
|
-
async read(options = {}) {
|
|
197
|
-
this.assertReadable();
|
|
198
|
-
if (this.readClosed)
|
|
199
|
-
return null;
|
|
200
|
-
const result = await carrierCall(raceAbort(this.reader.read(), options.signal), "WebTransport stream read failed", "reset");
|
|
201
|
-
if (result.done || result.value === undefined) {
|
|
202
|
-
this.readClosed = true;
|
|
203
|
-
this.releaseIfComplete();
|
|
204
|
-
return null;
|
|
205
|
-
}
|
|
206
|
-
return result.value.slice();
|
|
207
|
-
}
|
|
208
|
-
async write(data) {
|
|
209
|
-
this.assertNotTerminal();
|
|
210
|
-
if (this.writeClosed)
|
|
211
|
-
throw new CarrierError("write_closed", "WebTransport stream write side is closed");
|
|
212
|
-
await carrierCall(this.writer.write(data.slice()), "WebTransport stream write failed", "reset");
|
|
213
|
-
return data.byteLength;
|
|
214
|
-
}
|
|
215
|
-
closeWrite() {
|
|
216
|
-
if (this.closeWritePromise !== undefined)
|
|
217
|
-
return this.closeWritePromise;
|
|
218
|
-
this.assertNotTerminal();
|
|
219
|
-
this.writeClosed = true;
|
|
220
|
-
this.closeWritePromise = carrierCall(this.writer.close(), "WebTransport stream FIN failed", "reset")
|
|
221
|
-
.then(() => { this.releaseIfComplete(); });
|
|
222
|
-
return this.closeWritePromise;
|
|
223
|
-
}
|
|
224
|
-
stopSending() {
|
|
225
|
-
if (this.stopSendingPromise !== undefined)
|
|
226
|
-
return this.stopSendingPromise;
|
|
227
|
-
this.assertNotTerminal();
|
|
228
|
-
const stopped = new CarrierError("stop_sending", "WebTransport stream receive side stopped");
|
|
229
|
-
this.readClosed = true;
|
|
230
|
-
this.readStopError = stopped;
|
|
231
|
-
this.stopSendingPromise ??= carrierCall(this.reader.cancel(stopped), "WebTransport STOP_SENDING failed", "stop_sending").then(() => { this.releaseIfComplete(); });
|
|
232
|
-
return this.stopSendingPromise;
|
|
233
|
-
}
|
|
234
|
-
reset() {
|
|
235
|
-
this.resetPromise ??= this.resetOnce();
|
|
236
|
-
return this.resetPromise;
|
|
237
|
-
}
|
|
238
|
-
abort(error = new CarrierError("aborted", "WebTransport stream aborted")) {
|
|
239
|
-
if (this.terminalError !== undefined)
|
|
240
|
-
return;
|
|
241
|
-
this.terminalError = error instanceof CarrierError
|
|
242
|
-
? error
|
|
243
|
-
: new CarrierError("aborted", "WebTransport stream aborted", error);
|
|
244
|
-
this.readClosed = true;
|
|
245
|
-
this.writeClosed = true;
|
|
246
|
-
void this.writer.abort(this.terminalError).catch(() => undefined);
|
|
247
|
-
void this.reader.cancel(this.terminalError).catch(() => undefined);
|
|
248
|
-
this.release();
|
|
249
|
-
}
|
|
250
|
-
async resetOnce() {
|
|
251
|
-
if (this.terminalError !== undefined)
|
|
252
|
-
return;
|
|
253
|
-
this.writeClosed = true;
|
|
254
|
-
this.readClosed = true;
|
|
255
|
-
const error = new CarrierError("reset", "WebTransport stream reset");
|
|
256
|
-
this.terminalError = error;
|
|
257
|
-
try {
|
|
258
|
-
await Promise.allSettled([this.writer.abort(error), this.reader.cancel(error)]);
|
|
259
|
-
}
|
|
260
|
-
finally {
|
|
261
|
-
this.release();
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
assertReadable() {
|
|
265
|
-
this.assertNotTerminal();
|
|
266
|
-
if (this.readStopError !== undefined)
|
|
267
|
-
throw this.readStopError;
|
|
268
|
-
}
|
|
269
|
-
assertNotTerminal() {
|
|
270
|
-
if (this.terminalError !== undefined)
|
|
271
|
-
throw this.terminalError;
|
|
272
|
-
}
|
|
273
|
-
releaseIfComplete() {
|
|
274
|
-
if (this.readClosed && this.writeClosed)
|
|
275
|
-
this.release();
|
|
276
|
-
}
|
|
277
|
-
release() {
|
|
278
|
-
if (this.released)
|
|
279
|
-
return;
|
|
280
|
-
this.released = true;
|
|
281
|
-
this.onRelease();
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
class WebTransportDatagramAdapter {
|
|
285
|
-
maxDatagramSize;
|
|
286
|
-
readable;
|
|
287
|
-
writable;
|
|
288
|
-
incoming = new IncomingDatagramQueue();
|
|
289
|
-
terminalError;
|
|
290
|
-
constructor(native, configuredMaxSize) {
|
|
291
|
-
const maxDatagramSize = configuredMaxSize ?? native.maxDatagramSize;
|
|
292
|
-
if (!Number.isInteger(maxDatagramSize) || maxDatagramSize < 1) {
|
|
293
|
-
throw new TypeError("WebTransport runtime did not provide a valid DATAGRAM size");
|
|
294
|
-
}
|
|
295
|
-
this.maxDatagramSize = maxDatagramSize;
|
|
296
|
-
this.readable = native.readable.getReader();
|
|
297
|
-
this.writable = native.writable.getWriter();
|
|
298
|
-
void this.pumpIncoming();
|
|
299
|
-
}
|
|
300
|
-
async send(data, options = {}) {
|
|
301
|
-
this.assertOpen();
|
|
302
|
-
if (options.signal?.aborted === true)
|
|
303
|
-
throw abortedCarrierError(options.signal.reason);
|
|
304
|
-
if (options.expiresAt !== undefined && options.expiresAt <= Date.now())
|
|
305
|
-
return "dropped_expired";
|
|
306
|
-
if (data.byteLength < 1 || data.byteLength > this.maxDatagramSize)
|
|
307
|
-
return "dropped_carrier";
|
|
308
|
-
try {
|
|
309
|
-
await raceAbort(this.writable.write(data.slice()), options.signal);
|
|
310
|
-
return "accepted";
|
|
311
|
-
}
|
|
312
|
-
catch (error) {
|
|
313
|
-
if (isAborted(options.signal))
|
|
314
|
-
throw abortedCarrierError(error);
|
|
315
|
-
if (this.terminalError !== undefined)
|
|
316
|
-
throw this.terminalError;
|
|
317
|
-
return "dropped_carrier";
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
async receive(options = {}) {
|
|
321
|
-
this.assertOpen();
|
|
322
|
-
return await this.incoming.shift(options.signal);
|
|
323
|
-
}
|
|
324
|
-
abort(error) {
|
|
325
|
-
if (this.terminalError !== undefined)
|
|
326
|
-
return;
|
|
327
|
-
this.terminalError = error;
|
|
328
|
-
this.incoming.fail(error);
|
|
329
|
-
void this.writable.abort(error).catch(() => undefined);
|
|
330
|
-
void this.readable.cancel(error).catch(() => undefined);
|
|
331
|
-
}
|
|
332
|
-
assertOpen() {
|
|
333
|
-
if (this.terminalError !== undefined)
|
|
334
|
-
throw this.terminalError;
|
|
335
|
-
}
|
|
336
|
-
async pumpIncoming() {
|
|
337
|
-
try {
|
|
338
|
-
while (this.terminalError === undefined) {
|
|
339
|
-
const result = await this.readable.read();
|
|
340
|
-
if (result.done || result.value === undefined) {
|
|
341
|
-
this.abort(new CarrierError("closed", "WebTransport datagrams closed"));
|
|
342
|
-
return;
|
|
343
|
-
}
|
|
344
|
-
if (result.value.byteLength < 1 || result.value.byteLength > this.maxDatagramSize)
|
|
345
|
-
continue;
|
|
346
|
-
this.incoming.push(result.value.slice());
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
catch (error) {
|
|
350
|
-
if (this.terminalError === undefined) {
|
|
351
|
-
this.abort(carrierFailure("WebTransport datagram receive failed", error));
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
class IncomingWebTransportStreamQueue {
|
|
357
|
-
values = [];
|
|
358
|
-
waiters = new Set();
|
|
359
|
-
terminalError;
|
|
360
|
-
push(stream) {
|
|
361
|
-
if (this.terminalError !== undefined) {
|
|
362
|
-
stream.abort(this.terminalError);
|
|
363
|
-
return;
|
|
364
|
-
}
|
|
365
|
-
const waiter = this.waiters.values().next().value;
|
|
366
|
-
if (waiter === undefined)
|
|
367
|
-
this.values.push(stream);
|
|
368
|
-
else
|
|
369
|
-
waiter.deliver(stream);
|
|
370
|
-
}
|
|
371
|
-
shift(signal) {
|
|
372
|
-
if (signal?.aborted === true)
|
|
373
|
-
return Promise.reject(abortedCarrierError(signal.reason));
|
|
374
|
-
if (this.terminalError !== undefined)
|
|
375
|
-
return Promise.reject(this.terminalError);
|
|
376
|
-
const value = this.values.shift();
|
|
377
|
-
if (value !== undefined)
|
|
378
|
-
return Promise.resolve(value);
|
|
379
|
-
return new Promise((resolve, reject) => {
|
|
380
|
-
let settled = false;
|
|
381
|
-
const cleanup = () => {
|
|
382
|
-
this.waiters.delete(waiter);
|
|
383
|
-
signal?.removeEventListener("abort", abort);
|
|
384
|
-
};
|
|
385
|
-
const waiter = {
|
|
386
|
-
deliver: (stream) => {
|
|
387
|
-
if (settled)
|
|
388
|
-
return;
|
|
389
|
-
settled = true;
|
|
390
|
-
cleanup();
|
|
391
|
-
resolve(stream);
|
|
392
|
-
},
|
|
393
|
-
fail: (error) => {
|
|
394
|
-
if (settled)
|
|
395
|
-
return;
|
|
396
|
-
settled = true;
|
|
397
|
-
cleanup();
|
|
398
|
-
reject(error);
|
|
399
|
-
},
|
|
400
|
-
};
|
|
401
|
-
const abort = () => waiter.fail(abortedCarrierError(signal?.reason));
|
|
402
|
-
this.waiters.add(waiter);
|
|
403
|
-
signal?.addEventListener("abort", abort, { once: true });
|
|
404
|
-
if (signal?.aborted === true)
|
|
405
|
-
abort();
|
|
406
|
-
});
|
|
407
|
-
}
|
|
408
|
-
fail(error) {
|
|
409
|
-
if (this.terminalError !== undefined)
|
|
410
|
-
return;
|
|
411
|
-
this.terminalError = error;
|
|
412
|
-
for (const stream of this.values)
|
|
413
|
-
stream.abort(error);
|
|
414
|
-
this.values.length = 0;
|
|
415
|
-
for (const waiter of [...this.waiters])
|
|
416
|
-
waiter.fail(error);
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
class IncomingDatagramQueue {
|
|
420
|
-
static MAX_VALUES = 256;
|
|
421
|
-
static MAX_BYTES = 4 * 1024 * 1024;
|
|
422
|
-
values = [];
|
|
423
|
-
bufferedBytes = 0;
|
|
424
|
-
waiters = new Set();
|
|
425
|
-
terminalError;
|
|
426
|
-
push(value) {
|
|
427
|
-
if (this.terminalError !== undefined)
|
|
428
|
-
return;
|
|
429
|
-
const waiter = this.waiters.values().next().value;
|
|
430
|
-
if (waiter === undefined) {
|
|
431
|
-
// DATAGRAMs are lossy by contract. Drop an incoming value once the
|
|
432
|
-
// bounded queue budget is exhausted, while keeping the native reader
|
|
433
|
-
// drained so an unconsumed peer cannot grow memory without bound.
|
|
434
|
-
if (this.values.length >= IncomingDatagramQueue.MAX_VALUES ||
|
|
435
|
-
this.bufferedBytes + value.byteLength > IncomingDatagramQueue.MAX_BYTES)
|
|
436
|
-
return;
|
|
437
|
-
this.values.push(value);
|
|
438
|
-
this.bufferedBytes += value.byteLength;
|
|
439
|
-
}
|
|
440
|
-
else
|
|
441
|
-
waiter.deliver(value);
|
|
442
|
-
}
|
|
443
|
-
shift(signal) {
|
|
444
|
-
if (signal?.aborted === true)
|
|
445
|
-
return Promise.reject(abortedCarrierError(signal.reason));
|
|
446
|
-
if (this.terminalError !== undefined)
|
|
447
|
-
return Promise.reject(this.terminalError);
|
|
448
|
-
const value = this.values.shift();
|
|
449
|
-
if (value !== undefined) {
|
|
450
|
-
this.bufferedBytes -= value.byteLength;
|
|
451
|
-
return Promise.resolve(value);
|
|
452
|
-
}
|
|
453
|
-
return new Promise((resolve, reject) => {
|
|
454
|
-
let settled = false;
|
|
455
|
-
const cleanup = () => {
|
|
456
|
-
this.waiters.delete(waiter);
|
|
457
|
-
signal?.removeEventListener("abort", abort);
|
|
458
|
-
};
|
|
459
|
-
const waiter = {
|
|
460
|
-
deliver: (next) => {
|
|
461
|
-
if (settled)
|
|
462
|
-
return;
|
|
463
|
-
settled = true;
|
|
464
|
-
cleanup();
|
|
465
|
-
resolve(next);
|
|
466
|
-
},
|
|
467
|
-
fail: (error) => {
|
|
468
|
-
if (settled)
|
|
469
|
-
return;
|
|
470
|
-
settled = true;
|
|
471
|
-
cleanup();
|
|
472
|
-
reject(error);
|
|
473
|
-
},
|
|
474
|
-
};
|
|
475
|
-
const abort = () => waiter.fail(abortedCarrierError(signal?.reason));
|
|
476
|
-
this.waiters.add(waiter);
|
|
477
|
-
signal?.addEventListener("abort", abort, { once: true });
|
|
478
|
-
if (signal?.aborted === true)
|
|
479
|
-
abort();
|
|
480
|
-
});
|
|
481
|
-
}
|
|
482
|
-
fail(error) {
|
|
483
|
-
if (this.terminalError !== undefined)
|
|
484
|
-
return;
|
|
485
|
-
this.terminalError = error;
|
|
486
|
-
this.values.length = 0;
|
|
487
|
-
this.bufferedBytes = 0;
|
|
488
|
-
for (const waiter of [...this.waiters])
|
|
489
|
-
waiter.fail(error);
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
function abortNativeStream(stream, error) {
|
|
493
|
-
const reader = stream.readable.getReader();
|
|
494
|
-
const writer = stream.writable.getWriter();
|
|
495
|
-
void reader.cancel(error).catch(() => undefined);
|
|
496
|
-
void writer.abort(error).catch(() => undefined);
|
|
497
|
-
}
|
|
498
|
-
function abortedCarrierError(cause) {
|
|
499
|
-
return new CarrierError("aborted", "WebTransport operation aborted", cause);
|
|
500
|
-
}
|
|
501
|
-
function isAborted(signal) {
|
|
502
|
-
return signal?.aborted === true;
|
|
503
|
-
}
|
|
504
|
-
async function raceAbort(promise, signal) {
|
|
505
|
-
if (signal === undefined)
|
|
506
|
-
return await promise;
|
|
507
|
-
if (signal.aborted)
|
|
508
|
-
throw abortedCarrierError(signal.reason);
|
|
509
|
-
return await new Promise((resolve, reject) => {
|
|
510
|
-
const abort = () => reject(abortedCarrierError(signal.reason));
|
|
511
|
-
signal.addEventListener("abort", abort, { once: true });
|
|
512
|
-
void promise.then(resolve, reject).finally(() => signal.removeEventListener("abort", abort));
|
|
513
|
-
});
|
|
514
|
-
}
|
|
515
|
-
async function carrierCall(promise, message, code = "closed") {
|
|
516
|
-
try {
|
|
517
|
-
return await promise;
|
|
518
|
-
}
|
|
519
|
-
catch (error) {
|
|
520
|
-
if (error instanceof CarrierError)
|
|
521
|
-
throw error;
|
|
522
|
-
if (error instanceof DOMException && error.name === "AbortError" ||
|
|
523
|
-
error instanceof Error && error.name === "AbortError") {
|
|
524
|
-
throw new CarrierError("aborted", message, error);
|
|
525
|
-
}
|
|
526
|
-
throw new CarrierError(code, message, error);
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
function carrierFailure(message, cause) {
|
|
530
|
-
return cause instanceof CarrierError ? cause : new CarrierError("closed", message, cause);
|
|
531
|
-
}
|
|
532
|
-
function asError(error) {
|
|
533
|
-
return error instanceof Error ? error : new Error(String(error));
|
|
534
|
-
}
|
package/dist/v2/artifact.d.ts
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
export type ArtifactCarrierV2 = "websocket" | "raw_quic" | "webtransport";
|
|
2
|
-
export type ArtifactPathKindV2 = "direct" | "tunnel";
|
|
3
|
-
export type ArtifactCandidateV2 = Readonly<{
|
|
4
|
-
id: string;
|
|
5
|
-
carrier: ArtifactCarrierV2;
|
|
6
|
-
url: string;
|
|
7
|
-
wire_profile: string;
|
|
8
|
-
normalized_url?: string;
|
|
9
|
-
}>;
|
|
10
|
-
export type CanonicalArtifactCandidateV2 = Readonly<{
|
|
11
|
-
carrier: ArtifactCarrierV2;
|
|
12
|
-
id: string;
|
|
13
|
-
normalized_url: string;
|
|
14
|
-
wire_profile: string;
|
|
15
|
-
}>;
|
|
16
|
-
export type SessionContractV2 = Readonly<{
|
|
17
|
-
channel_id: string;
|
|
18
|
-
init_expire_at_unix_s: number;
|
|
19
|
-
idle_timeout_seconds: number;
|
|
20
|
-
establish_timeout_seconds: number;
|
|
21
|
-
rekey_prepare_timeout_seconds: number;
|
|
22
|
-
rekey_completion_timeout_seconds: number;
|
|
23
|
-
max_inbound_streams: number;
|
|
24
|
-
e2ee_psk_b64u: string;
|
|
25
|
-
allowed_suites: readonly number[];
|
|
26
|
-
default_suite: number;
|
|
27
|
-
selected_features: number;
|
|
28
|
-
contract_hash_b64u: string;
|
|
29
|
-
}>;
|
|
30
|
-
export type DirectArtifactPathV2 = Readonly<{
|
|
31
|
-
kind: "direct";
|
|
32
|
-
rendezvous_group_id: string;
|
|
33
|
-
listener_audience: string;
|
|
34
|
-
routing_token: string;
|
|
35
|
-
candidates: readonly ArtifactCandidateV2[];
|
|
36
|
-
}>;
|
|
37
|
-
export type TunnelArtifactPathV2 = Readonly<{
|
|
38
|
-
kind: "tunnel";
|
|
39
|
-
rendezvous_group_id: string;
|
|
40
|
-
listener_audience: string;
|
|
41
|
-
role: 1 | 2;
|
|
42
|
-
local_endpoint_instance_id: string;
|
|
43
|
-
expected_peer_endpoint_instance_id: string;
|
|
44
|
-
token: string;
|
|
45
|
-
candidates: readonly ArtifactCandidateV2[];
|
|
46
|
-
}>;
|
|
47
|
-
export type ScopeMetadataV2 = Readonly<{
|
|
48
|
-
scope: string;
|
|
49
|
-
scope_version: number;
|
|
50
|
-
critical: boolean;
|
|
51
|
-
payload: Readonly<Record<string, unknown>>;
|
|
52
|
-
}>;
|
|
53
|
-
export type CorrelationTagV2 = Readonly<{
|
|
54
|
-
key: string;
|
|
55
|
-
value: string;
|
|
56
|
-
}>;
|
|
57
|
-
export type CorrelationContextV2 = Readonly<{
|
|
58
|
-
v: 2;
|
|
59
|
-
tags: readonly CorrelationTagV2[];
|
|
60
|
-
}>;
|
|
61
|
-
export type ArtifactV2 = Readonly<{
|
|
62
|
-
v: 2;
|
|
63
|
-
profile: "flowersec/2";
|
|
64
|
-
session: SessionContractV2;
|
|
65
|
-
path: DirectArtifactPathV2 | TunnelArtifactPathV2;
|
|
66
|
-
scoped: readonly ScopeMetadataV2[];
|
|
67
|
-
correlation: CorrelationContextV2;
|
|
68
|
-
}>;
|
|
69
|
-
type CommonFSB2RequestV2 = Readonly<{
|
|
70
|
-
profile: "flowersec/2";
|
|
71
|
-
channel_id: string;
|
|
72
|
-
session_contract_hash_b64u: string;
|
|
73
|
-
rendezvous_group_id: string;
|
|
74
|
-
candidates: readonly CanonicalArtifactCandidateV2[];
|
|
75
|
-
candidate_set_hash_b64u: string;
|
|
76
|
-
chosen_candidate_id: string;
|
|
77
|
-
listener_audience: string;
|
|
78
|
-
}>;
|
|
79
|
-
export type DirectFSB2RequestV2 = CommonFSB2RequestV2 & Readonly<{
|
|
80
|
-
pathKind: "direct";
|
|
81
|
-
routing_token: string;
|
|
82
|
-
}>;
|
|
83
|
-
export type TunnelFSB2RequestV2 = CommonFSB2RequestV2 & Readonly<{
|
|
84
|
-
pathKind: "tunnel";
|
|
85
|
-
role: 1 | 2;
|
|
86
|
-
endpoint_instance_id: string;
|
|
87
|
-
attach_token: string;
|
|
88
|
-
}>;
|
|
89
|
-
export type FSB2RequestV2 = DirectFSB2RequestV2 | TunnelFSB2RequestV2;
|
|
90
|
-
export type DecodedFSB2RequestV2 = Readonly<{
|
|
91
|
-
request: FSB2RequestV2;
|
|
92
|
-
raw: Uint8Array;
|
|
93
|
-
localAdmissionBinding: Uint8Array;
|
|
94
|
-
}>;
|
|
95
|
-
export declare enum AdmissionStatusV2 {
|
|
96
|
-
Success = 0,
|
|
97
|
-
Reject = 1,
|
|
98
|
-
Retryable = 2
|
|
99
|
-
}
|
|
100
|
-
export type AdmissionResponseV2 = Readonly<{
|
|
101
|
-
status: AdmissionStatusV2;
|
|
102
|
-
reason: string;
|
|
103
|
-
}>;
|
|
104
|
-
export type ArtifactV2ErrorCode = "artifact_too_large" | "fsb2_payload_too_large" | "invalid_artifact" | "invalid_candidate" | "invalid_fsa2" | "invalid_fsb2" | "noncanonical_fsb2";
|
|
105
|
-
export declare class ArtifactV2Error extends Error {
|
|
106
|
-
readonly code: ArtifactV2ErrorCode;
|
|
107
|
-
constructor(code: ArtifactV2ErrorCode, message: string);
|
|
108
|
-
}
|
|
109
|
-
export type LabeledHashV2 = Readonly<{
|
|
110
|
-
canonicalJSON: string;
|
|
111
|
-
hash: Uint8Array;
|
|
112
|
-
hashBase64URL: string;
|
|
113
|
-
}>;
|
|
114
|
-
export type CanonicalCandidateSetV2 = LabeledHashV2 & Readonly<{
|
|
115
|
-
candidates: readonly CanonicalArtifactCandidateV2[];
|
|
116
|
-
}>;
|
|
117
|
-
export declare function computeSessionContractHashV2(session: SessionContractV2): LabeledHashV2;
|
|
118
|
-
export declare function canonicalizeCandidatesV2(kind: ArtifactPathKindV2, candidates: readonly ArtifactCandidateV2[]): CanonicalCandidateSetV2;
|
|
119
|
-
export declare function decodeArtifactV2JSON(raw: string | Uint8Array): ArtifactV2;
|
|
120
|
-
export declare function encodeArtifactV2JSON(artifact: ArtifactV2): Uint8Array;
|
|
121
|
-
export declare function validateArtifactV2(artifact: ArtifactV2): CanonicalCandidateSetV2;
|
|
122
|
-
export declare function buildFSB2RequestV2(artifact: ArtifactV2, chosenCandidateID: string): FSB2RequestV2;
|
|
123
|
-
export declare function encodeFSB2RequestV2(request: FSB2RequestV2): Uint8Array;
|
|
124
|
-
export declare function decodeFSB2RequestV2(raw: Uint8Array): DecodedFSB2RequestV2;
|
|
125
|
-
export declare function admissionBindingV2(rawFSB2: Uint8Array): Uint8Array;
|
|
126
|
-
export declare function encodeFSA2ResponseV2(response: AdmissionResponseV2): Uint8Array;
|
|
127
|
-
export declare function decodeFSA2ResponseV2(raw: Uint8Array): AdmissionResponseV2;
|
|
128
|
-
export {};
|