@floegence/flowersec-core 0.27.0 → 2.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 +91 -22
- package/THIRD_PARTY_NOTICES.md +141 -0
- package/dist/browser/connectSession.d.ts +13 -0
- package/dist/browser/connectSession.js +40 -0
- package/dist/browser/index.d.ts +3 -10
- package/dist/browser/index.js +2 -5
- package/dist/browser/runtimeCapability.d.ts +13 -0
- package/dist/browser/runtimeCapability.js +27 -0
- package/dist/browser/sessionRuntime.d.ts +2 -0
- package/dist/browser/sessionRuntime.js +21 -0
- package/dist/browser/webTransportClient.d.ts +8 -0
- package/dist/browser/webTransportClient.js +55 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +126 -0
- package/dist/cliSpendMarker.d.ts +1 -0
- package/dist/cliSpendMarker.js +22 -0
- package/dist/connectionController.d.ts +54 -0
- package/dist/connectionController.js +438 -0
- package/dist/connector/adapters/webSocketCandidate.d.ts +7 -0
- package/dist/connector/adapters/webSocketCandidate.js +116 -0
- package/dist/connector/adapters/webTransportCandidate.d.ts +5 -0
- package/dist/connector/adapters/webTransportCandidate.js +73 -0
- package/dist/connector/admissionCommit.d.ts +31 -0
- package/dist/connector/admissionCommit.js +239 -0
- package/dist/connector/sessionAcceptor.d.ts +16 -0
- package/dist/connector/sessionAcceptor.js +114 -0
- package/dist/connector/sessionConfig.d.ts +3 -0
- package/dist/connector/sessionConfig.js +30 -0
- package/dist/connector/sessionConnector.d.ts +45 -0
- package/dist/connector/sessionConnector.js +603 -0
- package/dist/defaults.d.ts +7 -7
- package/dist/defaults.js +7 -7
- package/dist/facade.d.ts +12 -27
- package/dist/facade.js +6 -24
- package/dist/node/connectSession.d.ts +21 -0
- package/dist/node/connectSession.js +62 -0
- package/dist/node/index.d.ts +3 -11
- package/dist/node/index.js +2 -8
- package/dist/node/runtimeCapability.d.ts +7 -0
- package/dist/node/runtimeCapability.js +10 -0
- package/dist/node/sessionRuntime.d.ts +2 -0
- package/dist/node/sessionRuntime.js +13 -0
- package/dist/node/webTransportClient.d.ts +9 -0
- package/dist/node/webTransportClient.js +56 -0
- package/dist/node/webTransportServer.d.ts +22 -0
- package/dist/node/webTransportServer.js +100 -0
- package/dist/node/wsFactory.d.ts +3 -1
- package/dist/node/wsFactory.js +4 -3
- package/dist/proxy/controllerGuard.d.ts +4 -4
- package/dist/proxy/controllerGuard.js +83 -177
- package/dist/proxy/disableUpstreamServiceWorkerRegister.d.ts +3 -1
- package/dist/proxy/disableUpstreamServiceWorkerRegister.js +19 -17
- package/dist/proxy/index.d.ts +16 -15
- package/dist/proxy/index.js +8 -14
- package/dist/proxy/integration.d.ts +23 -71
- package/dist/proxy/integration.js +37 -340
- package/dist/proxy/registerServiceWorker.d.ts +1 -10
- package/dist/proxy/registerServiceWorker.js +43 -105
- package/dist/proxy/runtime.d.ts +3 -63
- package/dist/proxy/runtime.js +349 -462
- package/dist/proxy/scope.d.ts +6 -0
- package/dist/proxy/scope.js +131 -0
- package/dist/proxy/serviceWorker.d.ts +5 -16
- package/dist/proxy/serviceWorker.js +230 -617
- package/dist/proxy/stream.d.ts +9 -0
- package/dist/proxy/stream.js +40 -0
- package/dist/proxy/types.d.ts +78 -30
- package/dist/proxy/windowBridge.d.ts +61 -0
- package/dist/proxy/windowBridge.js +344 -0
- package/dist/proxy/wsPatch.d.ts +4 -14
- package/dist/proxy/wsPatch.js +173 -268
- package/dist/public/artifact.d.ts +11 -0
- package/dist/public/artifact.js +44 -0
- package/dist/public/artifactLease.d.ts +10 -0
- package/dist/public/artifactLease.js +48 -0
- package/dist/public/connectError.d.ts +6 -0
- package/dist/public/connectError.js +9 -0
- package/dist/public/contract.d.ts +83 -0
- package/dist/public/contract.js +17 -0
- package/dist/public/streamMetadata.d.ts +10 -0
- package/dist/public/streamMetadata.js +40 -0
- package/dist/rpc/caller.d.ts +1 -1
- package/dist/rpc/client.d.ts +1 -4
- package/dist/rpc/client.js +0 -21
- package/dist/rpc/rpcProxy.d.ts +1 -1
- package/dist/rpc/server.d.ts +1 -1
- package/dist/rpc/validate.d.ts +1 -1
- package/dist/rpc/wire.d.ts +15 -0
- package/dist/runtime/errors.d.ts +6 -0
- package/dist/runtime/errors.js +10 -0
- package/dist/transport/webSocketAdapter.d.ts +24 -0
- package/dist/transport/webSocketAdapter.js +234 -0
- package/dist/transport/webTransportAdapter.d.ts +27 -0
- package/dist/transport/webTransportAdapter.js +519 -0
- package/dist/utils/errors.d.ts +2 -20
- package/dist/utils/errors.js +73 -20
- package/dist/v2/admissionError.d.ts +4 -0
- package/dist/v2/admissionError.js +8 -0
- package/dist/v2/artifact.d.ts +128 -0
- package/dist/v2/artifact.js +1126 -0
- package/dist/v2/artifactLease.d.ts +1 -0
- package/dist/v2/artifactLease.js +7 -0
- package/dist/v2/capability.d.ts +29 -0
- package/dist/v2/capability.js +190 -0
- package/dist/v2/carrier.d.ts +79 -0
- package/dist/v2/carrier.js +405 -0
- package/dist/v2/contract.d.ts +37 -0
- package/dist/v2/contract.js +1 -0
- package/dist/v2/handshake.d.ts +80 -0
- package/dist/v2/handshake.js +470 -0
- package/dist/v2/opaqueArtifact.d.ts +1 -0
- package/dist/v2/opaqueArtifact.js +2 -0
- package/dist/v2/protocol.d.ts +99 -0
- package/dist/v2/protocol.js +739 -0
- package/dist/v2/publicSession.d.ts +1 -0
- package/dist/v2/publicSession.js +179 -0
- package/dist/v2/retryDisposition.d.ts +16 -0
- package/dist/v2/retryDisposition.js +30 -0
- package/dist/v2/session.d.ts +277 -0
- package/dist/v2/session.js +1879 -0
- package/dist/v2/streamLifetimeLedger.d.ts +31 -0
- package/dist/v2/streamLifetimeLedger.js +131 -0
- package/dist/v2/streamMetadata.d.ts +1 -0
- package/dist/v2/streamMetadata.js +7 -0
- package/dist/v2/unreliableMessage.d.ts +43 -0
- package/dist/v2/unreliableMessage.js +252 -0
- package/dist/vendor/tr46.d.ts +10 -0
- package/dist/vendor/tr46.js +501 -0
- package/dist/ws-client/binaryTransport.d.ts +0 -3
- package/dist/ws-client/binaryTransport.js +15 -39
- package/dist/yamux/errors.d.ts +0 -4
- package/dist/yamux/errors.js +0 -9
- package/dist/yamux/session.d.ts +0 -5
- package/dist/yamux/session.js +4 -70
- package/dist/yamux/stream.d.ts +1 -0
- package/dist/yamux/stream.js +4 -0
- package/package.json +29 -81
- package/sbom/cyclonedx.json +2764 -0
- package/sbom/spdx.json +1947 -0
- package/YAMUX_ALIGNMENT.md +0 -127
- package/dist/_examples/flowersec/demo/v1.facade.gen.d.ts +0 -12
- package/dist/_examples/flowersec/demo/v1.facade.gen.js +0 -15
- package/dist/_examples/flowersec/demo/v1.gen.d.ts +0 -16
- package/dist/_examples/flowersec/demo/v1.gen.js +0 -86
- package/dist/_examples/flowersec/demo/v1.rpc.gen.d.ts +0 -11
- package/dist/_examples/flowersec/demo/v1.rpc.gen.js +0 -22
- package/dist/browser/connect.d.ts +0 -13
- package/dist/browser/connect.js +0 -31
- package/dist/browser/reconnectConfig.d.ts +0 -15
- package/dist/browser/reconnectConfig.js +0 -20
- package/dist/client-connect/common.d.ts +0 -26
- package/dist/client-connect/common.js +0 -167
- package/dist/client-connect/connectCore.d.ts +0 -61
- package/dist/client-connect/connectCore.js +0 -572
- package/dist/client-connect/contract.d.ts +0 -8
- package/dist/client-connect/contract.js +0 -51
- package/dist/client-connect/termination.d.ts +0 -6
- package/dist/client-connect/termination.js +0 -7
- package/dist/client-connect/transportSecurity.d.ts +0 -27
- package/dist/client-connect/transportSecurity.js +0 -199
- package/dist/client-connect/tunnelAttachCloseReason.d.ts +0 -3
- package/dist/client-connect/tunnelAttachCloseReason.js +0 -23
- package/dist/client.d.ts +0 -23
- package/dist/connect/artifact.d.ts +0 -36
- package/dist/connect/artifact.js +0 -213
- package/dist/connect/resolveArtifact.d.ts +0 -22
- package/dist/connect/resolveArtifact.js +0 -87
- package/dist/controlplane/channelInit.d.ts +0 -27
- package/dist/controlplane/channelInit.js +0 -116
- package/dist/controlplane/http.d.ts +0 -16
- package/dist/controlplane/http.js +0 -59
- package/dist/controlplane/index.d.ts +0 -6
- package/dist/controlplane/index.js +0 -5
- package/dist/controlplane/issuer.d.ts +0 -18
- package/dist/controlplane/issuer.js +0 -113
- package/dist/controlplane/request.d.ts +0 -51
- package/dist/controlplane/request.js +0 -273
- package/dist/controlplane/token.d.ts +0 -33
- package/dist/controlplane/token.js +0 -119
- package/dist/direct-client/connect.d.ts +0 -9
- package/dist/direct-client/connect.js +0 -90
- package/dist/direct-client/index.d.ts +0 -1
- package/dist/direct-client/index.js +0 -1
- package/dist/e2ee/constants.d.ts +0 -9
- package/dist/e2ee/constants.js +0 -18
- package/dist/e2ee/errors.d.ts +0 -5
- package/dist/e2ee/errors.js +0 -8
- package/dist/e2ee/framing.d.ts +0 -12
- package/dist/e2ee/framing.js +0 -57
- package/dist/e2ee/handshake.d.ts +0 -88
- package/dist/e2ee/handshake.js +0 -353
- package/dist/e2ee/index.d.ts +0 -7
- package/dist/e2ee/index.js +0 -7
- package/dist/e2ee/kdf.d.ts +0 -15
- package/dist/e2ee/kdf.js +0 -39
- package/dist/e2ee/record.d.ts +0 -11
- package/dist/e2ee/record.js +0 -80
- package/dist/e2ee/secureChannel.d.ts +0 -93
- package/dist/e2ee/secureChannel.js +0 -342
- package/dist/e2ee/transcript.d.ts +0 -23
- package/dist/e2ee/transcript.js +0 -31
- package/dist/endpoint/index.d.ts +0 -84
- package/dist/endpoint/index.js +0 -557
- package/dist/endpoint/node.d.ts +0 -9
- package/dist/endpoint/node.js +0 -51
- package/dist/gen/flowersec/controlplane/v1.gen.d.ts +0 -36
- package/dist/gen/flowersec/controlplane/v1.gen.js +0 -135
- package/dist/gen/flowersec/direct/v1.gen.d.ts +0 -21
- package/dist/gen/flowersec/direct/v1.gen.js +0 -101
- package/dist/gen/flowersec/e2ee/v1.gen.d.ts +0 -68
- package/dist/gen/flowersec/e2ee/v1.gen.js +0 -194
- package/dist/gen/flowersec/rpc/v1.gen.d.ts +0 -30
- package/dist/gen/flowersec/rpc/v1.gen.js +0 -107
- package/dist/gen/flowersec/tunnel/v1.gen.d.ts +0 -23
- package/dist/gen/flowersec/tunnel/v1.gen.js +0 -104
- package/dist/index.d.ts +0 -22
- package/dist/index.js +0 -22
- package/dist/node/connect.d.ts +0 -10
- package/dist/node/connect.js +0 -29
- package/dist/node/reconnectConfig.d.ts +0 -16
- package/dist/node/reconnectConfig.js +0 -20
- package/dist/observability/index.d.ts +0 -1
- package/dist/observability/index.js +0 -1
- package/dist/observability/observer.d.ts +0 -52
- package/dist/observability/observer.js +0 -314
- package/dist/proxy/appWindow.d.ts +0 -37
- package/dist/proxy/appWindow.js +0 -273
- package/dist/proxy/bootstrap.d.ts +0 -35
- package/dist/proxy/bootstrap.js +0 -119
- package/dist/proxy/constants.d.ts +0 -7
- package/dist/proxy/constants.js +0 -8
- package/dist/proxy/controllerWindow.d.ts +0 -12
- package/dist/proxy/controllerWindow.js +0 -384
- package/dist/proxy/cookieJar.d.ts +0 -7
- package/dist/proxy/cookieJar.js +0 -136
- package/dist/proxy/headerPolicy.d.ts +0 -14
- package/dist/proxy/headerPolicy.js +0 -134
- package/dist/proxy/portStream.d.ts +0 -5
- package/dist/proxy/portStream.js +0 -256
- package/dist/proxy/preset.d.ts +0 -29
- package/dist/proxy/preset.js +0 -111
- package/dist/proxy/runtimeScope.d.ts +0 -57
- package/dist/proxy/runtimeScope.js +0 -218
- package/dist/proxy/server.d.ts +0 -28
- package/dist/proxy/server.js +0 -833
- package/dist/proxy/windowBridgeProtocol.d.ts +0 -65
- package/dist/proxy/windowBridgeProtocol.js +0 -11
- package/dist/reconnect/artifactControlplane.d.ts +0 -16
- package/dist/reconnect/artifactControlplane.js +0 -35
- package/dist/reconnect/index.d.ts +0 -36
- package/dist/reconnect/index.js +0 -388
- package/dist/rpc-proxy/index.d.ts +0 -1
- package/dist/rpc-proxy/index.js +0 -1
- package/dist/rpc-proxy/rpcProxy.d.ts +0 -1
- package/dist/rpc-proxy/rpcProxy.js +0 -1
- package/dist/streamhello/index.d.ts +0 -1
- package/dist/streamhello/index.js +0 -1
- package/dist/streamhello/streamHello.d.ts +0 -3
- package/dist/streamhello/streamHello.js +0 -13
- package/dist/streamio/index.d.ts +0 -32
- package/dist/streamio/index.js +0 -87
- package/dist/tunnel-client/connect.d.ts +0 -9
- package/dist/tunnel-client/connect.js +0 -147
- package/dist/tunnel-client/index.d.ts +0 -1
- package/dist/tunnel-client/index.js +0 -1
- package/dist/ws/index.d.ts +0 -1
- package/dist/ws/index.js +0 -1
- /package/dist/{client.js → rpc/wire.js} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { SessionError } from "./contract.js";
|
|
2
|
+
import { createStreamMetadataV2, streamMetadataValuesV2 } from "./streamMetadata.js";
|
|
3
|
+
/** @internal */
|
|
4
|
+
export function projectSessionV2(session) {
|
|
5
|
+
const rpc = projectRpcPeerV2(session.rpc);
|
|
6
|
+
const unreliable = session.unreliableMessages;
|
|
7
|
+
return Object.freeze({
|
|
8
|
+
rpc,
|
|
9
|
+
...(unreliable === undefined ? {} : { unreliableMessages: unreliable }),
|
|
10
|
+
async openStream(kind, options) {
|
|
11
|
+
try {
|
|
12
|
+
const internalOptions = options === undefined ? undefined : {
|
|
13
|
+
...(options.signal === undefined ? {} : { signal: options.signal }),
|
|
14
|
+
...(options.metadata === undefined ? {} : { metadata: streamMetadataValuesV2(options.metadata) }),
|
|
15
|
+
};
|
|
16
|
+
return projectByteStreamV2(await session.openStream(kind, internalOptions));
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
throw redactSessionError(error);
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
async acceptStream(options) {
|
|
23
|
+
try {
|
|
24
|
+
const incoming = await session.acceptStream(options);
|
|
25
|
+
return Object.freeze({
|
|
26
|
+
kind: incoming.kind,
|
|
27
|
+
metadata: createStreamMetadataV2(incoming.metadata),
|
|
28
|
+
stream: projectByteStreamV2(incoming.stream),
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
throw redactSessionError(error);
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
async rekey(options) {
|
|
36
|
+
try {
|
|
37
|
+
await session.rekey(options);
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
throw redactSessionError(error);
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
async probeLiveness(options) {
|
|
44
|
+
try {
|
|
45
|
+
return await session.probeLiveness(options);
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
throw redactSessionError(error);
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
async waitTermination() {
|
|
52
|
+
const { error } = await session.waitTermination();
|
|
53
|
+
return Object.freeze({ error: redactSessionError(error) });
|
|
54
|
+
},
|
|
55
|
+
async close() {
|
|
56
|
+
try {
|
|
57
|
+
await session.close();
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
throw redactSessionError(error);
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
function projectByteStreamV2(stream) {
|
|
66
|
+
return Object.freeze({
|
|
67
|
+
kind: stream.kind,
|
|
68
|
+
get terminalError() {
|
|
69
|
+
return stream.terminalError === undefined ? undefined : redactSessionError(stream.terminalError);
|
|
70
|
+
},
|
|
71
|
+
async read(options) {
|
|
72
|
+
try {
|
|
73
|
+
return await stream.read(options);
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
throw redactSessionError(error);
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
async write(data, options) {
|
|
80
|
+
try {
|
|
81
|
+
return await stream.write(data, options);
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
throw redactSessionError(error);
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
async closeWrite() {
|
|
88
|
+
try {
|
|
89
|
+
await stream.closeWrite();
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
throw redactSessionError(error);
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
async reset() {
|
|
96
|
+
try {
|
|
97
|
+
await stream.reset();
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
throw redactSessionError(error);
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
async close() {
|
|
104
|
+
try {
|
|
105
|
+
await stream.close();
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
throw redactSessionError(error);
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
function projectRpcPeerV2(peer) {
|
|
114
|
+
return Object.freeze({
|
|
115
|
+
async call(typeId, payload, decodeResponse, signal) {
|
|
116
|
+
try {
|
|
117
|
+
const result = await peer.call(typeId, payload, signal);
|
|
118
|
+
if (result.error !== undefined) {
|
|
119
|
+
return Object.freeze({ ok: false, error: Object.freeze({ ...result.error }) });
|
|
120
|
+
}
|
|
121
|
+
return Object.freeze({ ok: true, payload: decodeResponse(result.payload) });
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
throw redactSessionError(error);
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
async notify(typeId, payload) {
|
|
128
|
+
try {
|
|
129
|
+
await peer.notify(typeId, payload);
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
throw redactSessionError(error);
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
onNotify(typeId, handler) {
|
|
136
|
+
return peer.onNotify(typeId, (payload) => handler(payload));
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
function redactSessionError(error) {
|
|
141
|
+
if (error instanceof SessionError)
|
|
142
|
+
return error;
|
|
143
|
+
return new SessionError(sessionErrorCode(error));
|
|
144
|
+
}
|
|
145
|
+
function sessionErrorCode(error) {
|
|
146
|
+
if (error instanceof DOMException && error.name === "AbortError")
|
|
147
|
+
return "canceled";
|
|
148
|
+
if (error instanceof Error) {
|
|
149
|
+
if (error.name === "AbortError")
|
|
150
|
+
return "canceled";
|
|
151
|
+
if (error.name === "TimeoutError")
|
|
152
|
+
return "timeout";
|
|
153
|
+
const code = error.code;
|
|
154
|
+
if (error.name === "CarrierError" || typeof code === "string") {
|
|
155
|
+
if (code === "closed" || code === "carrier_closed")
|
|
156
|
+
return "closed";
|
|
157
|
+
if (code === "aborted" || code === "operation_aborted")
|
|
158
|
+
return "canceled";
|
|
159
|
+
if (code === "reset" || code === "stream_reset")
|
|
160
|
+
return "stream_reset";
|
|
161
|
+
}
|
|
162
|
+
if (error.name === "SessionV2Error") {
|
|
163
|
+
const code = error.code;
|
|
164
|
+
switch (code) {
|
|
165
|
+
case "aborted": return "canceled";
|
|
166
|
+
case "timeout": return "timeout";
|
|
167
|
+
case "closed": return "closed";
|
|
168
|
+
case "going_away": return "going_away";
|
|
169
|
+
case "open_rejected": return "stream_rejected";
|
|
170
|
+
case "stream_reset": return "stream_reset";
|
|
171
|
+
case "resource_exhausted": return "resource_exhausted";
|
|
172
|
+
case "rekey_failed": return "rekey_failed";
|
|
173
|
+
case "liveness_failed": return "liveness_failed";
|
|
174
|
+
default: return "operation_failed";
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return "operation_failed";
|
|
179
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
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;
|
|
@@ -0,0 +1,30 @@
|
|
|
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 { kind: "retryable" };
|
|
13
|
+
default:
|
|
14
|
+
return { 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 { kind: "retryable" };
|
|
27
|
+
default:
|
|
28
|
+
return { kind: "terminal" };
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,277 @@
|
|
|
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, 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" | "timeout";
|
|
50
|
+
constructor(code: "aborted" | "closed" | "going_away" | "handshake" | "open_rejected" | "protocol" | "resource_exhausted" | "timeout", message: string);
|
|
51
|
+
}
|
|
52
|
+
type HandshakeMaterial = Readonly<{
|
|
53
|
+
h3: Uint8Array;
|
|
54
|
+
sessionPRK: Uint8Array;
|
|
55
|
+
selectedFeatures: number;
|
|
56
|
+
}>;
|
|
57
|
+
export declare function establishSessionV2(carrier: CarrierSessionV2, config: SessionConfigV2, options?: OperationOptionsV2): Promise<SessionV2>;
|
|
58
|
+
export declare class SessionV2 implements SessionV2Contract {
|
|
59
|
+
private readonly carrier;
|
|
60
|
+
private readonly control;
|
|
61
|
+
private readonly controlReader;
|
|
62
|
+
private readonly config;
|
|
63
|
+
readonly path: PathKind;
|
|
64
|
+
readonly endpointInstanceId: string | undefined;
|
|
65
|
+
readonly rpc: RpcClient;
|
|
66
|
+
readonly termination: Promise<SessionTerminationV2>;
|
|
67
|
+
readonly unreliableMessages: UnreliableMessageChannelV2 | undefined;
|
|
68
|
+
terminalError: Error | undefined;
|
|
69
|
+
private readonly role;
|
|
70
|
+
private readonly sendDirection;
|
|
71
|
+
private readonly receiveDirection;
|
|
72
|
+
private readonly h3;
|
|
73
|
+
private readonly sendRoots;
|
|
74
|
+
private readonly receiveRoots;
|
|
75
|
+
private sendEpoch;
|
|
76
|
+
private receiveEpoch;
|
|
77
|
+
private controlSendEpoch;
|
|
78
|
+
private controlSendSequence;
|
|
79
|
+
private controlReceiveEpoch;
|
|
80
|
+
private controlReceiveSequence;
|
|
81
|
+
private controlWriteTail;
|
|
82
|
+
private nextLogicalID;
|
|
83
|
+
private receivedGoAway;
|
|
84
|
+
private receivedGoAwayLastAccepted;
|
|
85
|
+
private receivedGoAwayReason;
|
|
86
|
+
private sentGoAway;
|
|
87
|
+
private sentGoAwayLastAccepted;
|
|
88
|
+
private sentGoAwayReason;
|
|
89
|
+
private closePromise;
|
|
90
|
+
private lifecycle;
|
|
91
|
+
private sentSessionClose;
|
|
92
|
+
private sessionCloseCommitted;
|
|
93
|
+
private readonly peerSessionClose;
|
|
94
|
+
private readonly streams;
|
|
95
|
+
private readonly peerLedger;
|
|
96
|
+
private readonly outboundLedger;
|
|
97
|
+
private readonly incoming;
|
|
98
|
+
private readonly outboundPermits;
|
|
99
|
+
private readonly inboundPermits;
|
|
100
|
+
private readonly pings;
|
|
101
|
+
private nextPing;
|
|
102
|
+
private readonly rpcActivation;
|
|
103
|
+
private rpcStreamPromise;
|
|
104
|
+
private rpcServing;
|
|
105
|
+
private rekeyTail;
|
|
106
|
+
private nextTransition;
|
|
107
|
+
private receiveTransition;
|
|
108
|
+
private pendingSessionRekey;
|
|
109
|
+
private lastSessionRekeyACK;
|
|
110
|
+
private preparingSendEpoch;
|
|
111
|
+
private pendingReceiveEpoch;
|
|
112
|
+
private openFrozen;
|
|
113
|
+
private openGate;
|
|
114
|
+
private outboundFrontierChanged;
|
|
115
|
+
private activeInboundResponders;
|
|
116
|
+
private localResponderFrozen;
|
|
117
|
+
private peerResponderFrozen;
|
|
118
|
+
private responderChanged;
|
|
119
|
+
private idleWatchdogStarted;
|
|
120
|
+
private idleTimer;
|
|
121
|
+
private readonly terminationState;
|
|
122
|
+
constructor(carrier: CarrierSessionV2, control: CarrierStreamV2, controlReader: ExactReader, config: SessionConfigV2, material: HandshakeMaterial);
|
|
123
|
+
openStream(kind: string, options?: InternalStreamOpenOptionsV2): Promise<ByteStreamV2>;
|
|
124
|
+
acceptStream(options?: OperationOptionsV2): Promise<IncomingStreamV2>;
|
|
125
|
+
probeLiveness(options?: OperationOptionsV2): Promise<number>;
|
|
126
|
+
rekey(options?: OperationOptionsV2): Promise<void>;
|
|
127
|
+
close(): Promise<void>;
|
|
128
|
+
start(): void;
|
|
129
|
+
rootForSend(epoch: number): EpochRootsV2;
|
|
130
|
+
rootForReceive(epoch: number): EpochRootsV2;
|
|
131
|
+
hasReceiveRoots(epoch: number): boolean;
|
|
132
|
+
installReceiveRoots(epoch: number, roots: EpochRootsV2): void;
|
|
133
|
+
transcriptHash(): Uint8Array;
|
|
134
|
+
receiveDirectionValue(): DirectionV2;
|
|
135
|
+
sendStreamRecord(stream: EncryptedStreamV2, type: InnerTypeV2, payload: Uint8Array, signal?: AbortSignal): Promise<void>;
|
|
136
|
+
readStreamRecord(stream: EncryptedStreamV2): Promise<Readonly<{
|
|
137
|
+
type: InnerTypeV2;
|
|
138
|
+
payload: Uint8Array;
|
|
139
|
+
header: RecordHeaderV2;
|
|
140
|
+
}>>;
|
|
141
|
+
localReset(stream: EncryptedStreamV2, error: Error): Promise<void>;
|
|
142
|
+
releaseStream(stream: EncryptedStreamV2): void;
|
|
143
|
+
private openLogicalStream;
|
|
144
|
+
private ensureRPCStream;
|
|
145
|
+
private acceptCarrierLoop;
|
|
146
|
+
private acceptCarrierStream;
|
|
147
|
+
private acceptCarrierStreamAfterFSS2;
|
|
148
|
+
private resetInboundBeforeDelivery;
|
|
149
|
+
private sendControl;
|
|
150
|
+
private readControl;
|
|
151
|
+
private controlLoop;
|
|
152
|
+
private closeOnce;
|
|
153
|
+
waitTermination(): Promise<SessionTerminationV2>;
|
|
154
|
+
private rekeyOnce;
|
|
155
|
+
private receiveSessionRekey;
|
|
156
|
+
private enterInboundResponder;
|
|
157
|
+
private leaveInboundResponder;
|
|
158
|
+
private freezeInboundResponders;
|
|
159
|
+
private unfreezeInboundResponders;
|
|
160
|
+
private notifyResponderChanged;
|
|
161
|
+
private receiveSessionRekeyBeforeDeadline;
|
|
162
|
+
private receiveSessionRekeyACK;
|
|
163
|
+
private waitOpenGate;
|
|
164
|
+
resolveOutboundOpen(id: bigint): void;
|
|
165
|
+
private waitOutboundFrontier;
|
|
166
|
+
private commitOutboundReset;
|
|
167
|
+
private commitLocalReset;
|
|
168
|
+
private notifyOutboundFrontierChanged;
|
|
169
|
+
private isLocalLogicalID;
|
|
170
|
+
private localOpenHighWatermark;
|
|
171
|
+
private validGoAwayBoundary;
|
|
172
|
+
private sendGoAway;
|
|
173
|
+
private receiveGoAway;
|
|
174
|
+
private localOpeningAllowedAfterGoAway;
|
|
175
|
+
private acceptsPeerStreamAfterGoAway;
|
|
176
|
+
private cleanupEpochRoots;
|
|
177
|
+
streamEpochStateChanged(): void;
|
|
178
|
+
private cleanupRootMap;
|
|
179
|
+
private wipeAllRoots;
|
|
180
|
+
private startIdleWatchdog;
|
|
181
|
+
private markAuthenticatedActivity;
|
|
182
|
+
private fail;
|
|
183
|
+
private assertOpen;
|
|
184
|
+
private beginClosing;
|
|
185
|
+
}
|
|
186
|
+
declare class EncryptedStreamV2 implements ByteStreamV2 {
|
|
187
|
+
readonly session: SessionV2;
|
|
188
|
+
readonly carrier: CarrierStreamV2;
|
|
189
|
+
readonly id: bigint;
|
|
190
|
+
readonly kind: string;
|
|
191
|
+
sendEpoch: number;
|
|
192
|
+
receiveEpoch: number;
|
|
193
|
+
private readonly permitRelease;
|
|
194
|
+
readonly reader: ExactReader;
|
|
195
|
+
readonly opened: Readonly<{
|
|
196
|
+
promise: Promise<void>;
|
|
197
|
+
resolve: (value: void | PromiseLike<void>) => void;
|
|
198
|
+
reject: (reason?: unknown) => void;
|
|
199
|
+
readonly settled: boolean;
|
|
200
|
+
}>;
|
|
201
|
+
readonly data: ByteQueue;
|
|
202
|
+
terminalError: Error | undefined;
|
|
203
|
+
sendSequence: bigint;
|
|
204
|
+
receiveSequence: bigint;
|
|
205
|
+
priorACK: Readonly<{
|
|
206
|
+
epoch: number;
|
|
207
|
+
sequence: bigint;
|
|
208
|
+
}> | undefined;
|
|
209
|
+
private sendTail;
|
|
210
|
+
private localFIN;
|
|
211
|
+
private remoteFIN;
|
|
212
|
+
private pumpStarted;
|
|
213
|
+
private permitReleased;
|
|
214
|
+
private pendingSendRekey;
|
|
215
|
+
private lastSendRekeyACK;
|
|
216
|
+
private receiveRekey;
|
|
217
|
+
constructor(session: SessionV2, carrier: CarrierStreamV2, id: bigint, kind: string, sendEpoch: number, receiveEpoch: number, permitRelease: () => void, reader?: ExactReader);
|
|
218
|
+
read(options?: OperationOptionsV2): Promise<Uint8Array | null>;
|
|
219
|
+
write(payload: Uint8Array, options?: OperationOptionsV2): Promise<number>;
|
|
220
|
+
closeWrite(): Promise<void>;
|
|
221
|
+
reset(): Promise<void>;
|
|
222
|
+
close(): Promise<void>;
|
|
223
|
+
send(type: InnerTypeV2, payload: Uint8Array, signal?: AbortSignal): Promise<void>;
|
|
224
|
+
canRekeySend(): boolean;
|
|
225
|
+
startSendRekey(transition: bigint, epoch: number): Readonly<{
|
|
226
|
+
armed: Deferred<void>;
|
|
227
|
+
done: Deferred<void>;
|
|
228
|
+
}>;
|
|
229
|
+
waitReceiveRekey(transition: bigint, epoch: number, signal?: AbortSignal): Promise<void>;
|
|
230
|
+
publishReceiveRekey(transition: bigint, epoch: number): void;
|
|
231
|
+
startPump(): void;
|
|
232
|
+
markOpen(): void;
|
|
233
|
+
markTerminal(error: Error): boolean;
|
|
234
|
+
peerReset(error: Error): void;
|
|
235
|
+
abort(error?: Error): void;
|
|
236
|
+
releasePermit(): void;
|
|
237
|
+
private pump;
|
|
238
|
+
private openedHash;
|
|
239
|
+
setOpenHash(value: Uint8Array): void;
|
|
240
|
+
private enqueueSend;
|
|
241
|
+
private waitSendRekey;
|
|
242
|
+
private receiveStreamKeyUpdate;
|
|
243
|
+
private receiveStreamKeyUpdateACK;
|
|
244
|
+
sendEpochsInUse(): readonly number[];
|
|
245
|
+
receiveEpochsInUse(): readonly number[];
|
|
246
|
+
private releaseIfClean;
|
|
247
|
+
}
|
|
248
|
+
declare class ExactReader {
|
|
249
|
+
private readonly stream;
|
|
250
|
+
private chunks;
|
|
251
|
+
private offset;
|
|
252
|
+
private bytes;
|
|
253
|
+
constructor(stream: Pick<CarrierStreamV2, "read">);
|
|
254
|
+
readExactly(length: number, signal?: AbortSignal): Promise<Uint8Array>;
|
|
255
|
+
}
|
|
256
|
+
declare class ByteQueue {
|
|
257
|
+
private readonly limit;
|
|
258
|
+
private readonly chunks;
|
|
259
|
+
private head;
|
|
260
|
+
private bytes;
|
|
261
|
+
private closed;
|
|
262
|
+
private error;
|
|
263
|
+
private readonly waiters;
|
|
264
|
+
constructor(limit: number);
|
|
265
|
+
push(chunk: Uint8Array): void;
|
|
266
|
+
close(): void;
|
|
267
|
+
fail(error: Error): void;
|
|
268
|
+
read(signal?: AbortSignal): Promise<Uint8Array | null>;
|
|
269
|
+
private wake;
|
|
270
|
+
}
|
|
271
|
+
type Deferred<T> = Readonly<{
|
|
272
|
+
promise: Promise<T>;
|
|
273
|
+
resolve: (value: T | PromiseLike<T>) => void;
|
|
274
|
+
reject: (reason?: unknown) => void;
|
|
275
|
+
readonly settled: boolean;
|
|
276
|
+
}>;
|
|
277
|
+
export {};
|