@floegence/flowersec-core 3.2.0 → 4.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/integration.d.ts +5 -5
- package/dist/proxy/integration.js +2 -2
- 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/protocol.js +2 -103
- package/dist/v3/retryDisposition.d.ts +2 -2
- package/dist/v3/retryDisposition.js +0 -7
- package/dist/vendor/tr46.d.ts +4 -0
- package/dist/vendor/tr46.js +37 -32
- package/package.json +21 -19
- 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 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/v2/publicSession.js
DELETED
|
@@ -1,281 +0,0 @@
|
|
|
1
|
-
import { SessionError } from "./contract.js";
|
|
2
|
-
import { createStreamMetadataV2, streamMetadataValuesV2 } from "./streamMetadata.js";
|
|
3
|
-
import { assertRpcTypeId } from "../rpc/validate.js";
|
|
4
|
-
/** @internal */
|
|
5
|
-
export function projectSessionV2(session) {
|
|
6
|
-
const notificationOwner = {
|
|
7
|
-
subscriptions: new Set(),
|
|
8
|
-
closed: false,
|
|
9
|
-
};
|
|
10
|
-
const clearNotificationSubscriptions = () => {
|
|
11
|
-
notificationOwner.closed = true;
|
|
12
|
-
for (const unsubscribe of [...notificationOwner.subscriptions])
|
|
13
|
-
unsubscribe();
|
|
14
|
-
};
|
|
15
|
-
const rpc = projectRpcPeerV2(session.rpc, notificationOwner);
|
|
16
|
-
const unreliable = session.unreliableMessages;
|
|
17
|
-
void session.termination.then(clearNotificationSubscriptions, clearNotificationSubscriptions);
|
|
18
|
-
return Object.freeze({
|
|
19
|
-
rpc,
|
|
20
|
-
...(unreliable === undefined ? {} : { unreliableMessages: unreliable }),
|
|
21
|
-
async openStream(kind, options) {
|
|
22
|
-
try {
|
|
23
|
-
const internalOptions = options === undefined ? undefined : {
|
|
24
|
-
...(options.signal === undefined ? {} : { signal: options.signal }),
|
|
25
|
-
...(options.metadata === undefined ? {} : { metadata: streamMetadataValuesV2(options.metadata) }),
|
|
26
|
-
};
|
|
27
|
-
return projectByteStreamV2(await session.openStream(kind, internalOptions));
|
|
28
|
-
}
|
|
29
|
-
catch (error) {
|
|
30
|
-
throw redactSessionError(error);
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
async acceptStream(options) {
|
|
34
|
-
try {
|
|
35
|
-
const incoming = await session.acceptStream(options);
|
|
36
|
-
return Object.freeze({
|
|
37
|
-
kind: incoming.kind,
|
|
38
|
-
metadata: createStreamMetadataV2(incoming.metadata),
|
|
39
|
-
stream: projectByteStreamV2(incoming.stream),
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
throw redactSessionError(error);
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
async rekey(options) {
|
|
47
|
-
try {
|
|
48
|
-
await session.rekey(options);
|
|
49
|
-
}
|
|
50
|
-
catch (error) {
|
|
51
|
-
throw redactSessionError(error);
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
async probeLiveness(options) {
|
|
55
|
-
try {
|
|
56
|
-
return await session.probeLiveness(options);
|
|
57
|
-
}
|
|
58
|
-
catch (error) {
|
|
59
|
-
throw redactSessionError(error);
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
async waitTermination(options) {
|
|
63
|
-
try {
|
|
64
|
-
const { error } = await raceWithSignal(session.waitTermination(), options?.signal);
|
|
65
|
-
return Object.freeze({ error: redactSessionError(error) });
|
|
66
|
-
}
|
|
67
|
-
catch (error) {
|
|
68
|
-
throw redactSessionError(error);
|
|
69
|
-
}
|
|
70
|
-
},
|
|
71
|
-
async close() {
|
|
72
|
-
try {
|
|
73
|
-
await session.close();
|
|
74
|
-
}
|
|
75
|
-
catch (error) {
|
|
76
|
-
throw redactSessionError(error);
|
|
77
|
-
}
|
|
78
|
-
finally {
|
|
79
|
-
clearNotificationSubscriptions();
|
|
80
|
-
}
|
|
81
|
-
},
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
function projectByteStreamV2(stream) {
|
|
85
|
-
return Object.freeze({
|
|
86
|
-
kind: stream.kind,
|
|
87
|
-
get terminalError() {
|
|
88
|
-
return stream.terminalError === undefined ? undefined : redactSessionError(stream.terminalError);
|
|
89
|
-
},
|
|
90
|
-
async read(options) {
|
|
91
|
-
try {
|
|
92
|
-
return await stream.read(options);
|
|
93
|
-
}
|
|
94
|
-
catch (error) {
|
|
95
|
-
throw redactSessionError(error);
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
async write(data, options) {
|
|
99
|
-
try {
|
|
100
|
-
return await stream.write(data, options);
|
|
101
|
-
}
|
|
102
|
-
catch (error) {
|
|
103
|
-
throw redactSessionError(error);
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
|
-
async closeWrite() {
|
|
107
|
-
try {
|
|
108
|
-
await stream.closeWrite();
|
|
109
|
-
}
|
|
110
|
-
catch (error) {
|
|
111
|
-
throw redactSessionError(error);
|
|
112
|
-
}
|
|
113
|
-
},
|
|
114
|
-
async reset() {
|
|
115
|
-
try {
|
|
116
|
-
await stream.reset();
|
|
117
|
-
}
|
|
118
|
-
catch (error) {
|
|
119
|
-
throw redactSessionError(error);
|
|
120
|
-
}
|
|
121
|
-
},
|
|
122
|
-
async close() {
|
|
123
|
-
try {
|
|
124
|
-
await stream.close();
|
|
125
|
-
}
|
|
126
|
-
catch (error) {
|
|
127
|
-
throw redactSessionError(error);
|
|
128
|
-
}
|
|
129
|
-
},
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
function projectRpcPeerV2(peer, notificationOwner) {
|
|
133
|
-
return Object.freeze({
|
|
134
|
-
async call(typeId, payload, decodeResponse, options) {
|
|
135
|
-
try {
|
|
136
|
-
assertRpcTypeId(typeId);
|
|
137
|
-
assertJsonValue(payload);
|
|
138
|
-
const result = await peer.call(typeId, payload, options?.signal);
|
|
139
|
-
if (result.error !== undefined) {
|
|
140
|
-
return Object.freeze({ ok: false, error: Object.freeze({ ...result.error }) });
|
|
141
|
-
}
|
|
142
|
-
assertJsonValue(result.payload);
|
|
143
|
-
return Object.freeze({ ok: true, payload: decodeResponse(result.payload) });
|
|
144
|
-
}
|
|
145
|
-
catch (error) {
|
|
146
|
-
throw redactSessionError(error);
|
|
147
|
-
}
|
|
148
|
-
},
|
|
149
|
-
async notify(typeId, payload, options) {
|
|
150
|
-
try {
|
|
151
|
-
assertRpcTypeId(typeId);
|
|
152
|
-
assertJsonValue(payload);
|
|
153
|
-
if (options?.signal?.aborted)
|
|
154
|
-
throw options.signal.reason ?? new DOMException("The operation was aborted", "AbortError");
|
|
155
|
-
await raceWithSignal(peer.notify(typeId, payload), options?.signal);
|
|
156
|
-
}
|
|
157
|
-
catch (error) {
|
|
158
|
-
throw redactSessionError(error);
|
|
159
|
-
}
|
|
160
|
-
},
|
|
161
|
-
onNotify(typeId, decodePayload, handler) {
|
|
162
|
-
assertRpcTypeId(typeId);
|
|
163
|
-
if (notificationOwner.closed)
|
|
164
|
-
return () => undefined;
|
|
165
|
-
const unsubscribe = peer.onNotify(typeId, (payload) => {
|
|
166
|
-
let decoded;
|
|
167
|
-
try {
|
|
168
|
-
assertJsonValue(payload);
|
|
169
|
-
decoded = decodePayload(payload);
|
|
170
|
-
}
|
|
171
|
-
catch {
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
try {
|
|
175
|
-
void Promise.resolve(handler(decoded)).catch(() => undefined);
|
|
176
|
-
}
|
|
177
|
-
catch {
|
|
178
|
-
// Notification handlers are isolated from RPC serving.
|
|
179
|
-
}
|
|
180
|
-
});
|
|
181
|
-
let subscribed = true;
|
|
182
|
-
const cancel = () => {
|
|
183
|
-
if (!subscribed)
|
|
184
|
-
return;
|
|
185
|
-
subscribed = false;
|
|
186
|
-
notificationOwner.subscriptions.delete(cancel);
|
|
187
|
-
unsubscribe();
|
|
188
|
-
};
|
|
189
|
-
notificationOwner.subscriptions.add(cancel);
|
|
190
|
-
return cancel;
|
|
191
|
-
},
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
function assertJsonValue(value) {
|
|
195
|
-
validateJsonValue(value, new Set());
|
|
196
|
-
}
|
|
197
|
-
function validateJsonValue(value, ancestors) {
|
|
198
|
-
if (value === null || typeof value === "string" || typeof value === "boolean")
|
|
199
|
-
return;
|
|
200
|
-
if (typeof value === "number") {
|
|
201
|
-
if (Number.isFinite(value))
|
|
202
|
-
return;
|
|
203
|
-
throw new TypeError("RPC payload contains a non-finite number");
|
|
204
|
-
}
|
|
205
|
-
if (typeof value !== "object")
|
|
206
|
-
throw new TypeError("RPC payload is not a JSON value");
|
|
207
|
-
if (ancestors.has(value))
|
|
208
|
-
throw new TypeError("RPC payload contains a cycle");
|
|
209
|
-
ancestors.add(value);
|
|
210
|
-
try {
|
|
211
|
-
if (Array.isArray(value)) {
|
|
212
|
-
for (let index = 0; index < value.length; index += 1) {
|
|
213
|
-
if (!(index in value))
|
|
214
|
-
throw new TypeError("RPC payload contains a sparse array");
|
|
215
|
-
validateJsonValue(value[index], ancestors);
|
|
216
|
-
}
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
const prototype = Object.getPrototypeOf(value);
|
|
220
|
-
if (prototype !== Object.prototype && prototype !== null) {
|
|
221
|
-
throw new TypeError("RPC payload contains a non-JSON object");
|
|
222
|
-
}
|
|
223
|
-
for (const key of Object.keys(value)) {
|
|
224
|
-
validateJsonValue(value[key], ancestors);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
finally {
|
|
228
|
-
ancestors.delete(value);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
async function raceWithSignal(operation, signal) {
|
|
232
|
-
if (signal === undefined)
|
|
233
|
-
return await operation;
|
|
234
|
-
if (signal.aborted)
|
|
235
|
-
throw signal.reason ?? new DOMException("The operation was aborted", "AbortError");
|
|
236
|
-
return await new Promise((resolve, reject) => {
|
|
237
|
-
const abort = () => reject(signal.reason ?? new DOMException("The operation was aborted", "AbortError"));
|
|
238
|
-
signal.addEventListener("abort", abort, { once: true });
|
|
239
|
-
void operation.then(resolve, reject).finally(() => signal.removeEventListener("abort", abort));
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
function redactSessionError(error) {
|
|
243
|
-
if (error instanceof SessionError)
|
|
244
|
-
return error;
|
|
245
|
-
return new SessionError(sessionErrorCode(error));
|
|
246
|
-
}
|
|
247
|
-
function sessionErrorCode(error) {
|
|
248
|
-
if (error instanceof DOMException && error.name === "AbortError")
|
|
249
|
-
return "canceled";
|
|
250
|
-
if (error instanceof Error) {
|
|
251
|
-
if (error.name === "AbortError")
|
|
252
|
-
return "canceled";
|
|
253
|
-
if (error.name === "TimeoutError")
|
|
254
|
-
return "timeout";
|
|
255
|
-
const code = error.code;
|
|
256
|
-
if (error.name === "CarrierError" || typeof code === "string") {
|
|
257
|
-
if (code === "closed" || code === "carrier_closed")
|
|
258
|
-
return "closed";
|
|
259
|
-
if (code === "aborted" || code === "operation_aborted")
|
|
260
|
-
return "canceled";
|
|
261
|
-
if (code === "reset" || code === "stream_reset")
|
|
262
|
-
return "stream_reset";
|
|
263
|
-
}
|
|
264
|
-
if (error.name === "SessionV2Error") {
|
|
265
|
-
const code = error.code;
|
|
266
|
-
switch (code) {
|
|
267
|
-
case "aborted": return "canceled";
|
|
268
|
-
case "timeout": return "timeout";
|
|
269
|
-
case "closed": return "closed";
|
|
270
|
-
case "going_away": return "going_away";
|
|
271
|
-
case "open_rejected": return "stream_rejected";
|
|
272
|
-
case "stream_reset": return "stream_reset";
|
|
273
|
-
case "resource_exhausted": return "resource_exhausted";
|
|
274
|
-
case "rekey_failed": return "rekey_failed";
|
|
275
|
-
case "liveness_failed": return "liveness_failed";
|
|
276
|
-
default: return "operation_failed";
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
return "operation_failed";
|
|
281
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { SessionErrorCode } from "./contract.js";
|
|
2
|
-
import type { ConnectErrorCode } from "../public/connectError.js";
|
|
3
|
-
export type RetryDisposition = Readonly<{
|
|
4
|
-
kind: "terminal";
|
|
5
|
-
}> | Readonly<{
|
|
6
|
-
kind: "retryable";
|
|
7
|
-
}> | Readonly<{
|
|
8
|
-
kind: "retry_after";
|
|
9
|
-
notBeforeUnixMilliseconds: number;
|
|
10
|
-
}>;
|
|
11
|
-
export declare function retryDispositionForConnectError(error: Readonly<{
|
|
12
|
-
code: ConnectErrorCode;
|
|
13
|
-
}>): RetryDisposition;
|
|
14
|
-
export declare function retryDispositionForSessionError(error: Readonly<{
|
|
15
|
-
code: SessionErrorCode;
|
|
16
|
-
}>): RetryDisposition;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
export function retryDispositionForConnectError(error) {
|
|
2
|
-
switch (error.code) {
|
|
3
|
-
case "expired_artifact":
|
|
4
|
-
case "resolve_failed":
|
|
5
|
-
case "credential_spend_failed":
|
|
6
|
-
case "connection_failed":
|
|
7
|
-
case "timeout":
|
|
8
|
-
case "handshake_failed":
|
|
9
|
-
case "rpc_failed":
|
|
10
|
-
case "resource_exhausted":
|
|
11
|
-
case "not_connected":
|
|
12
|
-
return Object.freeze({ kind: "retryable" });
|
|
13
|
-
default:
|
|
14
|
-
return Object.freeze({ kind: "terminal" });
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
export function retryDispositionForSessionError(error) {
|
|
18
|
-
switch (error.code) {
|
|
19
|
-
case "closed":
|
|
20
|
-
case "going_away":
|
|
21
|
-
case "timeout":
|
|
22
|
-
case "resource_exhausted":
|
|
23
|
-
case "stream_reset":
|
|
24
|
-
case "rekey_failed":
|
|
25
|
-
case "liveness_failed":
|
|
26
|
-
return Object.freeze({ kind: "retryable" });
|
|
27
|
-
default:
|
|
28
|
-
return Object.freeze({ kind: "terminal" });
|
|
29
|
-
}
|
|
30
|
-
}
|
package/dist/v2/session.d.ts
DELETED
|
@@ -1,310 +0,0 @@
|
|
|
1
|
-
import { RpcClient } from "../rpc/client.js";
|
|
2
|
-
import { RpcRouter, type RpcServerOptions } from "../rpc/server.js";
|
|
3
|
-
import type { InternalByteStreamV2 as ByteStreamV2, InternalIncomingStreamV2 as IncomingStreamV2, InternalRpcPeerV2, InternalSessionV2 as SessionV2Contract, OperationOptionsV2, PathKind, InternalStreamOpenOptionsV2, UnreliableMessageChannelV2 } from "./contract.js";
|
|
4
|
-
import { type CarrierSessionV2, type CarrierStreamV2 } from "./carrier.js";
|
|
5
|
-
import type { SessionContractV2 } from "./artifact.js";
|
|
6
|
-
import { DirectionV2, InnerTypeV2, type EpochRootsV2, type RecordHeaderV2, type CipherSuiteV2 } from "./protocol.js";
|
|
7
|
-
type SessionTerminationV2 = Readonly<{
|
|
8
|
-
error: Error;
|
|
9
|
-
}>;
|
|
10
|
-
export type SessionRoleV2 = "client" | "server";
|
|
11
|
-
export type SessionDeadlinePhaseV2 = "establish" | "rekey_prepare" | "rekey_completion";
|
|
12
|
-
export type SessionDeadlineHandleV2 = Readonly<{
|
|
13
|
-
signal: AbortSignal;
|
|
14
|
-
cancel(): void;
|
|
15
|
-
}>;
|
|
16
|
-
export type SessionDeadlineFactoryV2 = (timeoutMs: number, phase: SessionDeadlinePhaseV2) => SessionDeadlineHandleV2;
|
|
17
|
-
export type SessionDeadlinesV2 = Readonly<{
|
|
18
|
-
establishTimeoutMs: number;
|
|
19
|
-
rekeyPrepareTimeoutMs: number;
|
|
20
|
-
rekeyCompletionTimeoutMs: number;
|
|
21
|
-
factory?: SessionDeadlineFactoryV2;
|
|
22
|
-
}>;
|
|
23
|
-
export type SessionConfigV2 = Readonly<{
|
|
24
|
-
role: SessionRoleV2;
|
|
25
|
-
path: PathKind;
|
|
26
|
-
channelID: string;
|
|
27
|
-
sessionContractHash: Uint8Array;
|
|
28
|
-
suite: CipherSuiteV2;
|
|
29
|
-
psk: Uint8Array;
|
|
30
|
-
maxInboundStreams: number;
|
|
31
|
-
localAdmissionBinding: Uint8Array;
|
|
32
|
-
peerAdmissionBinding: Uint8Array;
|
|
33
|
-
/** Required by admitted APIs to bind runtime limits and keys to the signed contract. */
|
|
34
|
-
sessionContract?: SessionContractV2;
|
|
35
|
-
localEndpointInstanceID: string;
|
|
36
|
-
expectedPeerEndpointInstanceID: string;
|
|
37
|
-
rpcRouter?: RpcRouter;
|
|
38
|
-
rpcServerOptions?: RpcServerOptions;
|
|
39
|
-
deadlines?: SessionDeadlinesV2;
|
|
40
|
-
idleTimeoutMs?: number;
|
|
41
|
-
closeTimeoutMs?: number;
|
|
42
|
-
runtime: SessionProtocolRuntimeV2;
|
|
43
|
-
}>;
|
|
44
|
-
export type SessionProtocolRuntimeV2 = Readonly<{
|
|
45
|
-
entropy(length: number): Uint8Array;
|
|
46
|
-
monotonicMilliseconds(): number;
|
|
47
|
-
}>;
|
|
48
|
-
export declare class SessionV2Error extends Error {
|
|
49
|
-
readonly code: "aborted" | "closed" | "going_away" | "handshake" | "open_rejected" | "protocol" | "resource_exhausted" | "stream_reset" | "timeout";
|
|
50
|
-
constructor(code: "aborted" | "closed" | "going_away" | "handshake" | "open_rejected" | "protocol" | "resource_exhausted" | "stream_reset" | "timeout", message: string);
|
|
51
|
-
}
|
|
52
|
-
declare class SessionRpcPeerV2 implements InternalRpcPeerV2 {
|
|
53
|
-
private readonly outbound;
|
|
54
|
-
private readonly inbound;
|
|
55
|
-
constructor(outbound: RpcClient, inbound: RpcRouter);
|
|
56
|
-
call(typeId: number, payload: unknown, signal?: AbortSignal): Promise<{
|
|
57
|
-
payload: unknown;
|
|
58
|
-
error?: import("../rpc/wire.js").RpcError;
|
|
59
|
-
}>;
|
|
60
|
-
notify(typeId: number, payload: unknown): Promise<void>;
|
|
61
|
-
onNotify(typeId: number, handler: (payload: unknown) => void): () => void;
|
|
62
|
-
close(): void;
|
|
63
|
-
}
|
|
64
|
-
type HandshakeMaterial = Readonly<{
|
|
65
|
-
h3: Uint8Array;
|
|
66
|
-
sessionPRK: Uint8Array;
|
|
67
|
-
selectedFeatures: number;
|
|
68
|
-
}>;
|
|
69
|
-
export declare function establishSessionV2(carrier: CarrierSessionV2, config: SessionConfigV2, options?: OperationOptionsV2): Promise<SessionV2>;
|
|
70
|
-
export declare class SessionV2 implements SessionV2Contract {
|
|
71
|
-
private readonly carrier;
|
|
72
|
-
private readonly control;
|
|
73
|
-
private readonly controlReader;
|
|
74
|
-
private readonly config;
|
|
75
|
-
readonly path: PathKind;
|
|
76
|
-
readonly endpointInstanceId: string | undefined;
|
|
77
|
-
readonly rpc: SessionRpcPeerV2;
|
|
78
|
-
readonly termination: Promise<SessionTerminationV2>;
|
|
79
|
-
readonly unreliableMessages: UnreliableMessageChannelV2 | undefined;
|
|
80
|
-
terminalError: Error | undefined;
|
|
81
|
-
private readonly role;
|
|
82
|
-
private readonly sendDirection;
|
|
83
|
-
private readonly receiveDirection;
|
|
84
|
-
private readonly h3;
|
|
85
|
-
private readonly sendRoots;
|
|
86
|
-
private readonly receiveRoots;
|
|
87
|
-
private sendEpoch;
|
|
88
|
-
private receiveEpoch;
|
|
89
|
-
private controlSendEpoch;
|
|
90
|
-
private controlSendSequence;
|
|
91
|
-
private controlReceiveEpoch;
|
|
92
|
-
private controlReceiveSequence;
|
|
93
|
-
private controlWriteTail;
|
|
94
|
-
private controlTerminalSealed;
|
|
95
|
-
private nextLogicalID;
|
|
96
|
-
private receivedGoAway;
|
|
97
|
-
private receivedGoAwayLastAccepted;
|
|
98
|
-
private receivedGoAwayReason;
|
|
99
|
-
private sentGoAway;
|
|
100
|
-
private sentGoAwayLastAccepted;
|
|
101
|
-
private sentGoAwayReason;
|
|
102
|
-
private closePromise;
|
|
103
|
-
private lifecycle;
|
|
104
|
-
private sentSessionClose;
|
|
105
|
-
private sessionCloseCommitted;
|
|
106
|
-
private readonly peerSessionClose;
|
|
107
|
-
private readonly streams;
|
|
108
|
-
private readonly releasedStreams;
|
|
109
|
-
private readonly releasedStreamCleanup;
|
|
110
|
-
private readonly peerLedger;
|
|
111
|
-
private readonly outboundLedger;
|
|
112
|
-
private readonly incoming;
|
|
113
|
-
private readonly outboundPermits;
|
|
114
|
-
private readonly inboundPermits;
|
|
115
|
-
private readonly pings;
|
|
116
|
-
private readonly backgroundTasks;
|
|
117
|
-
private nextPing;
|
|
118
|
-
private readonly rpcActivation;
|
|
119
|
-
private rpcStreamPromise;
|
|
120
|
-
private rpcServing;
|
|
121
|
-
private rekeyTail;
|
|
122
|
-
private nextTransition;
|
|
123
|
-
private receiveTransition;
|
|
124
|
-
private pendingSessionRekey;
|
|
125
|
-
private lastSessionRekeyACK;
|
|
126
|
-
private preparingSendEpoch;
|
|
127
|
-
private pendingReceiveEpoch;
|
|
128
|
-
private openFrozen;
|
|
129
|
-
private openGate;
|
|
130
|
-
private outboundFrontierChanged;
|
|
131
|
-
private activeInboundResponders;
|
|
132
|
-
private localResponderFrozen;
|
|
133
|
-
private peerResponderFrozen;
|
|
134
|
-
private responderChanged;
|
|
135
|
-
private idleWatchdogStarted;
|
|
136
|
-
private idleTimerCancel;
|
|
137
|
-
private readonly terminationState;
|
|
138
|
-
private readonly terminationController;
|
|
139
|
-
private readonly rpcRouter;
|
|
140
|
-
constructor(carrier: CarrierSessionV2, control: CarrierStreamV2, controlReader: ExactReader, config: SessionConfigV2, material: HandshakeMaterial);
|
|
141
|
-
openStream(kind: string, options?: InternalStreamOpenOptionsV2): Promise<ByteStreamV2>;
|
|
142
|
-
acceptStream(options?: OperationOptionsV2): Promise<IncomingStreamV2>;
|
|
143
|
-
probeLiveness(options?: OperationOptionsV2): Promise<number>;
|
|
144
|
-
rekey(options?: OperationOptionsV2): Promise<void>;
|
|
145
|
-
close(): Promise<void>;
|
|
146
|
-
start(): void;
|
|
147
|
-
rootForSend(epoch: number): EpochRootsV2;
|
|
148
|
-
rootForReceive(epoch: number): EpochRootsV2;
|
|
149
|
-
hasReceiveRoots(epoch: number): boolean;
|
|
150
|
-
installReceiveRoots(epoch: number, roots: EpochRootsV2): void;
|
|
151
|
-
transcriptHash(): Uint8Array;
|
|
152
|
-
receiveDirectionValue(): DirectionV2;
|
|
153
|
-
terminationSignal(): AbortSignal;
|
|
154
|
-
sendStreamRecord(stream: EncryptedStreamV2, type: InnerTypeV2, payload: Uint8Array, signal?: AbortSignal): Promise<void>;
|
|
155
|
-
readStreamRecord(stream: EncryptedStreamV2): Promise<Readonly<{
|
|
156
|
-
type: InnerTypeV2;
|
|
157
|
-
payload: Uint8Array;
|
|
158
|
-
header: RecordHeaderV2;
|
|
159
|
-
}>>;
|
|
160
|
-
localReset(stream: EncryptedStreamV2, error: Error): Promise<void>;
|
|
161
|
-
releaseStream(stream: EncryptedStreamV2): void;
|
|
162
|
-
private confirmControlDelivery;
|
|
163
|
-
private openLogicalStream;
|
|
164
|
-
private ensureRPCStream;
|
|
165
|
-
private acceptCarrierLoop;
|
|
166
|
-
private acceptCarrierStream;
|
|
167
|
-
private acceptCarrierStreamAfterFSS2;
|
|
168
|
-
private resetInboundBeforeDelivery;
|
|
169
|
-
private sendControl;
|
|
170
|
-
private sendControlResponse;
|
|
171
|
-
private sendControlCleanup;
|
|
172
|
-
private sendTerminalControl;
|
|
173
|
-
private writeControl;
|
|
174
|
-
private readControl;
|
|
175
|
-
private controlLoop;
|
|
176
|
-
private closeOnce;
|
|
177
|
-
waitTermination(): Promise<SessionTerminationV2>;
|
|
178
|
-
private rekeyOnce;
|
|
179
|
-
private receiveSessionRekey;
|
|
180
|
-
private enterInboundResponder;
|
|
181
|
-
private leaveInboundResponder;
|
|
182
|
-
private freezeInboundResponders;
|
|
183
|
-
private unfreezeInboundResponders;
|
|
184
|
-
private notifyResponderChanged;
|
|
185
|
-
private receiveSessionRekeyBeforeDeadline;
|
|
186
|
-
private receiveSessionRekeyACK;
|
|
187
|
-
private waitOpenGate;
|
|
188
|
-
resolveOutboundOpen(id: bigint): void;
|
|
189
|
-
private waitOutboundFrontier;
|
|
190
|
-
private commitOutboundReset;
|
|
191
|
-
private commitLocalReset;
|
|
192
|
-
private notifyOutboundFrontierChanged;
|
|
193
|
-
private isLocalLogicalID;
|
|
194
|
-
private localOpenHighWatermark;
|
|
195
|
-
private validGoAwayBoundary;
|
|
196
|
-
private sendGoAway;
|
|
197
|
-
private receiveGoAway;
|
|
198
|
-
private trackBackground;
|
|
199
|
-
private localOpeningAllowedAfterGoAway;
|
|
200
|
-
private acceptsPeerStreamAfterGoAway;
|
|
201
|
-
private cleanupEpochRoots;
|
|
202
|
-
streamEpochStateChanged(): void;
|
|
203
|
-
private cleanupRootMap;
|
|
204
|
-
private wipeAllRoots;
|
|
205
|
-
private startIdleWatchdog;
|
|
206
|
-
private markAuthenticatedActivity;
|
|
207
|
-
private fail;
|
|
208
|
-
private assertOpen;
|
|
209
|
-
private beginClosing;
|
|
210
|
-
}
|
|
211
|
-
declare class EncryptedStreamV2 implements ByteStreamV2 {
|
|
212
|
-
readonly session: SessionV2;
|
|
213
|
-
readonly carrier: CarrierStreamV2;
|
|
214
|
-
readonly id: bigint;
|
|
215
|
-
readonly kind: string;
|
|
216
|
-
sendEpoch: number;
|
|
217
|
-
receiveEpoch: number;
|
|
218
|
-
private readonly permitRelease;
|
|
219
|
-
readonly reader: ExactReader;
|
|
220
|
-
readonly opened: Readonly<{
|
|
221
|
-
promise: Promise<void>;
|
|
222
|
-
resolve: (value: void | PromiseLike<void>) => void;
|
|
223
|
-
reject: (reason?: unknown) => void;
|
|
224
|
-
readonly settled: boolean;
|
|
225
|
-
}>;
|
|
226
|
-
readonly data: ByteQueue;
|
|
227
|
-
terminalError: Error | undefined;
|
|
228
|
-
sendSequence: bigint;
|
|
229
|
-
receiveSequence: bigint;
|
|
230
|
-
priorACK: Readonly<{
|
|
231
|
-
epoch: number;
|
|
232
|
-
sequence: bigint;
|
|
233
|
-
}> | undefined;
|
|
234
|
-
private sendTail;
|
|
235
|
-
private localFIN;
|
|
236
|
-
private remoteFIN;
|
|
237
|
-
private pumpStarted;
|
|
238
|
-
private permitReleased;
|
|
239
|
-
private closeWriteTask;
|
|
240
|
-
private pendingSendRekey;
|
|
241
|
-
private lastSendRekeyACK;
|
|
242
|
-
private receiveRekey;
|
|
243
|
-
private receiveRekeyChanged;
|
|
244
|
-
constructor(session: SessionV2, carrier: CarrierStreamV2, id: bigint, kind: string, sendEpoch: number, receiveEpoch: number, permitRelease: () => void, reader?: ExactReader);
|
|
245
|
-
read(options?: OperationOptionsV2): Promise<Uint8Array | null>;
|
|
246
|
-
write(payload: Uint8Array, options?: OperationOptionsV2): Promise<number>;
|
|
247
|
-
closeWrite(): Promise<void>;
|
|
248
|
-
reset(): Promise<void>;
|
|
249
|
-
close(): Promise<void>;
|
|
250
|
-
send(type: InnerTypeV2, payload: Uint8Array, signal?: AbortSignal): Promise<void>;
|
|
251
|
-
canRekeySend(): boolean;
|
|
252
|
-
hasRemoteFIN(): boolean;
|
|
253
|
-
startSendRekey(transition: bigint, epoch: number): Readonly<{
|
|
254
|
-
armed: Deferred<void>;
|
|
255
|
-
done: Deferred<void>;
|
|
256
|
-
}>;
|
|
257
|
-
waitReceiveRekey(transition: bigint, epoch: number, signal?: AbortSignal): Promise<void>;
|
|
258
|
-
publishReceiveRekey(transition: bigint, epoch: number): void;
|
|
259
|
-
private notifyReceiveRekeyChanged;
|
|
260
|
-
startPump(): void;
|
|
261
|
-
markOpen(): void;
|
|
262
|
-
markTerminal(error: Error): boolean;
|
|
263
|
-
peerReset(error: Error): void;
|
|
264
|
-
carrierReset(): void;
|
|
265
|
-
abort(error?: Error): void;
|
|
266
|
-
releasePermit(): void;
|
|
267
|
-
private pump;
|
|
268
|
-
private openedHash;
|
|
269
|
-
setOpenHash(value: Uint8Array): void;
|
|
270
|
-
private enqueueSend;
|
|
271
|
-
private waitSendRekey;
|
|
272
|
-
private receiveStreamKeyUpdate;
|
|
273
|
-
private receiveStreamKeyUpdateACK;
|
|
274
|
-
sendEpochsInUse(): readonly number[];
|
|
275
|
-
receiveEpochsInUse(): readonly number[];
|
|
276
|
-
private releaseIfClean;
|
|
277
|
-
}
|
|
278
|
-
declare class ExactReader {
|
|
279
|
-
private readonly stream;
|
|
280
|
-
private chunks;
|
|
281
|
-
private offset;
|
|
282
|
-
private bytes;
|
|
283
|
-
constructor(stream: Pick<CarrierStreamV2, "read">);
|
|
284
|
-
readExactly(length: number, signal?: AbortSignal): Promise<Uint8Array>;
|
|
285
|
-
}
|
|
286
|
-
declare class ByteQueue {
|
|
287
|
-
private readonly limit;
|
|
288
|
-
private readonly chunks;
|
|
289
|
-
private head;
|
|
290
|
-
private bytes;
|
|
291
|
-
private closed;
|
|
292
|
-
private error;
|
|
293
|
-
private readonly waiters;
|
|
294
|
-
private readonly capacityWaiters;
|
|
295
|
-
constructor(limit: number);
|
|
296
|
-
push(chunk: Uint8Array): void;
|
|
297
|
-
close(): void;
|
|
298
|
-
fail(error: Error): void;
|
|
299
|
-
waitForCapacity(required: number): Promise<void>;
|
|
300
|
-
read(signal?: AbortSignal): Promise<Uint8Array | null>;
|
|
301
|
-
private wake;
|
|
302
|
-
private wakeCapacity;
|
|
303
|
-
}
|
|
304
|
-
type Deferred<T> = Readonly<{
|
|
305
|
-
promise: Promise<T>;
|
|
306
|
-
resolve: (value: T | PromiseLike<T>) => void;
|
|
307
|
-
reject: (reason?: unknown) => void;
|
|
308
|
-
readonly settled: boolean;
|
|
309
|
-
}>;
|
|
310
|
-
export {};
|