ftown-bridge 0.30.84 → 0.30.86
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/dist/direct-transport/loopback-server.d.ts +26 -4
- package/dist/direct-transport/loopback-server.js +112 -38
- package/dist/direct-transport/loopback-server.js.map +1 -1
- package/dist/ftown-cli.js +4 -1
- package/dist/ftown-cli.js.map +1 -1
- package/dist/index.js +35 -0
- package/dist/index.js.map +1 -1
- package/dist/local-api-server.d.ts +10 -0
- package/dist/local-api-server.js +73 -25
- package/dist/local-api-server.js.map +1 -1
- package/dist/workspace/authority.d.ts +21 -230
- package/dist/workspace/authority.js +86 -239
- package/dist/workspace/authority.js.map +1 -1
- package/dist/workspace/browser-application.d.ts +26 -0
- package/dist/workspace/browser-application.js +10 -0
- package/dist/workspace/browser-application.js.map +1 -0
- package/dist/workspace/browser-authority.d.ts +2 -0
- package/dist/workspace/browser-authority.js +49 -0
- package/dist/workspace/browser-authority.js.map +1 -0
- package/dist/workspace/browser-relay.d.ts +17 -0
- package/dist/workspace/browser-relay.js +222 -0
- package/dist/workspace/browser-relay.js.map +1 -0
- package/dist/workspace/browser-rtc.d.ts +29 -0
- package/dist/workspace/browser-rtc.js +247 -0
- package/dist/workspace/browser-rtc.js.map +1 -0
- package/dist/workspace/browser-session.d.ts +109 -0
- package/dist/workspace/browser-session.js +781 -0
- package/dist/workspace/browser-session.js.map +1 -0
- package/dist/workspace/cli.js +136 -9
- package/dist/workspace/cli.js.map +1 -1
- package/dist/workspace/cutover.d.ts +1 -0
- package/dist/workspace/cutover.js +4 -0
- package/dist/workspace/cutover.js.map +1 -1
- package/dist/workspace/device.d.ts +9 -4
- package/dist/workspace/device.js +46 -1
- package/dist/workspace/device.js.map +1 -1
- package/dist/workspace/enrollment.d.ts +25 -2
- package/dist/workspace/enrollment.js +144 -26
- package/dist/workspace/enrollment.js.map +1 -1
- package/dist/workspace/listener.d.ts +1 -1
- package/dist/workspace/listener.js +13 -5
- package/dist/workspace/listener.js.map +1 -1
- package/dist/workspace/local-dashboard-cli.d.ts +1 -0
- package/dist/workspace/local-dashboard-cli.js +109 -0
- package/dist/workspace/local-dashboard-cli.js.map +1 -0
- package/dist/workspace/native-client-bridge.js +8 -1
- package/dist/workspace/native-client-bridge.js.map +1 -1
- package/dist/workspace/native-client-cli.d.ts +3 -0
- package/dist/workspace/native-client-cli.js +15 -12
- package/dist/workspace/native-client-cli.js.map +1 -1
- package/dist/workspace/pq/bytes.d.ts +15 -0
- package/dist/workspace/pq/bytes.js +80 -0
- package/dist/workspace/pq/bytes.js.map +1 -0
- package/dist/workspace/pq/carrier.d.ts +24 -0
- package/dist/workspace/pq/carrier.js +70 -0
- package/dist/workspace/pq/carrier.js.map +1 -0
- package/dist/workspace/pq/ledger-core.d.ts +597 -0
- package/dist/workspace/pq/ledger-core.js +524 -0
- package/dist/workspace/pq/ledger-core.js.map +1 -0
- package/dist/workspace/pq/pairing-link.d.ts +15 -0
- package/dist/workspace/pq/pairing-link.js +88 -0
- package/dist/workspace/pq/pairing-link.js.map +1 -0
- package/dist/workspace/pq/relay-client.d.ts +76 -0
- package/dist/workspace/pq/relay-client.js +307 -0
- package/dist/workspace/pq/relay-client.js.map +1 -0
- package/dist/workspace/pq/relay-identity.d.ts +7 -0
- package/dist/workspace/pq/relay-identity.js +6 -0
- package/dist/workspace/pq/relay-identity.js.map +1 -0
- package/dist/workspace/pq/relay-stream.d.ts +89 -0
- package/dist/workspace/pq/relay-stream.js +318 -0
- package/dist/workspace/pq/relay-stream.js.map +1 -0
- package/dist/workspace/pq/session-client.d.ts +103 -0
- package/dist/workspace/pq/session-client.js +607 -0
- package/dist/workspace/pq/session-client.js.map +1 -0
- package/dist/workspace/pq/session-protocol.d.ts +226 -0
- package/dist/workspace/pq/session-protocol.js +301 -0
- package/dist/workspace/pq/session-protocol.js.map +1 -0
- package/dist/workspace/rendezvous-client.js +1 -1
- package/dist/workspace/rendezvous-client.js.map +1 -1
- package/dist/workspace/rendezvous-wire.d.ts +33 -4
- package/dist/workspace/rendezvous-wire.js +77 -2
- package/dist/workspace/rendezvous-wire.js.map +1 -1
- package/dist/workspace/rendezvous.js +2 -1
- package/dist/workspace/rendezvous.js.map +1 -1
- package/dist/workspace/runtime.d.ts +4 -0
- package/dist/workspace/runtime.js +11 -1
- package/dist/workspace/runtime.js.map +1 -1
- package/dist/workspace/writer-only.d.ts +3 -1
- package/dist/workspace/writer-only.js +23 -0
- package/dist/workspace/writer-only.js.map +1 -1
- package/package.json +2 -2
- package/skills/ftown/SKILL.md +1 -1
|
@@ -0,0 +1,781 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bridge side of the authenticated browser session (see pq/session-protocol.ts). TLS 1.3 with one fixed profile runs
|
|
3
|
+
* over an untrusted byte carrier; the device proves itself by signing a TLS exporter value, then unlocks with a
|
|
4
|
+
* WebAuthn assertion bound to the same session. No application message is processed before both succeed.
|
|
5
|
+
*/
|
|
6
|
+
import { constants, createHash, randomBytes, X509Certificate } from 'node:crypto';
|
|
7
|
+
import { Duplex } from 'node:stream';
|
|
8
|
+
import { createSecureContext, TLSSocket } from 'node:tls';
|
|
9
|
+
import { isPeerPqCertificate } from '../peer-pq-identity.js';
|
|
10
|
+
import { verifyPasskeyAssertion } from '../security/ledger/webauthn.js';
|
|
11
|
+
import { verifyPq } from './authority.js';
|
|
12
|
+
import { ACCOUNT_UNLOCK_LABEL, DEVICE_AUTH_LABEL, EXPORTER_LENGTH, FrameDecoder, MAX_OFFERS_IN_FLIGHT, MAX_PAIR_IN_FLIGHT, MAX_RPC_IN_FLIGHT, MAX_SOCKETS, MAX_UNLOCK_REFUSALS, MAX_WS_DATA_CHARS, SESSION_VERSION, TLS_PROFILE, accountUnlockChallenge, deviceAuthChallenge, encodeMessage, exporterContext, pairReceiptApproved, parseClientPair, parseClientSession, parseHello, parseServerSession, rosterChunks, } from './pq/session-protocol.js';
|
|
13
|
+
const DEFAULT_LIMITS = {
|
|
14
|
+
handshakeMs: 10_000, helloMs: 5_000, idleMs: 90_000, sessionsPerMember: 4, pairingSessionsPerInvite: 2, sessionsTotal: 64,
|
|
15
|
+
outboundQueueBytes: 8 * 1024 * 1024, inboundBufferBytes: 1024 * 1024, rpcInFlight: MAX_RPC_IN_FLIGHT, sockets: MAX_SOCKETS,
|
|
16
|
+
};
|
|
17
|
+
/** The lifetime of the existing standard browser unlock flow. */
|
|
18
|
+
const DEFAULT_UNLOCK_LIFETIME_MS = 15 * 60_000;
|
|
19
|
+
const ROSTER_LOW_WATER = 1024 * 1024;
|
|
20
|
+
const REFUSAL_LINGER_MS = 1_000;
|
|
21
|
+
const MAX_TIMER_MS = 0x7fffffff;
|
|
22
|
+
const hooks = { sha256: (bytes) => new Uint8Array(createHash('sha256').update(bytes).digest()) };
|
|
23
|
+
const nonce = () => randomBytes(32).toString('base64url');
|
|
24
|
+
function activeDevice(snapshot, memberId) {
|
|
25
|
+
if (snapshot.revoked.includes(memberId))
|
|
26
|
+
return null;
|
|
27
|
+
const member = snapshot.members.find(candidate => candidate.id === memberId);
|
|
28
|
+
if (!member || member.role !== 'pq-browser' || !member.account)
|
|
29
|
+
return null;
|
|
30
|
+
if (!snapshot.accounts.some(account => account.id === member.account))
|
|
31
|
+
return null;
|
|
32
|
+
return { member, accountId: member.account };
|
|
33
|
+
}
|
|
34
|
+
function activeCredential(snapshot, accountId, credentialId) {
|
|
35
|
+
const account = snapshot.accounts.find(candidate => candidate.id === accountId);
|
|
36
|
+
if (!account || account.revokedCredentials.includes(credentialId))
|
|
37
|
+
return null;
|
|
38
|
+
return account.credentials.find(credential => credential.credentialId === credentialId)?.publicKey ?? null;
|
|
39
|
+
}
|
|
40
|
+
export class BrowserSessionServer {
|
|
41
|
+
#authority;
|
|
42
|
+
#application;
|
|
43
|
+
#now;
|
|
44
|
+
#monotonic;
|
|
45
|
+
#limits;
|
|
46
|
+
#unlockLifetimeMs;
|
|
47
|
+
#context;
|
|
48
|
+
#sessions = new Set();
|
|
49
|
+
#windows = new Map();
|
|
50
|
+
#unsubscribe;
|
|
51
|
+
#closed = false;
|
|
52
|
+
constructor(authority, application, options = {}) {
|
|
53
|
+
this.#authority = authority;
|
|
54
|
+
this.#application = application;
|
|
55
|
+
this.#now = options.now ?? (() => Date.now());
|
|
56
|
+
this.#monotonic = options.monotonic ?? (() => performance.now());
|
|
57
|
+
this.#limits = { ...DEFAULT_LIMITS, ...options.limits };
|
|
58
|
+
this.#unlockLifetimeMs = options.unlockLifetimeMs ?? DEFAULT_UNLOCK_LIFETIME_MS;
|
|
59
|
+
if (!(this.#unlockLifetimeMs > 0))
|
|
60
|
+
throw new Error('Invalid unlock lifetime');
|
|
61
|
+
if (!isPeerPqCertificate(new X509Certificate(authority.identity.cert)))
|
|
62
|
+
throw new Error('Browser sessions require an ML-DSA-87 bridge identity');
|
|
63
|
+
this.#context = createSecureContext({
|
|
64
|
+
minVersion: 'TLSv1.3', maxVersion: 'TLSv1.3', ciphers: TLS_PROFILE.cipher, ecdhCurve: TLS_PROFILE.group, sigalgs: 'mldsa87',
|
|
65
|
+
secureOptions: constants.SSL_OP_NO_TICKET, cert: authority.identity.cert, key: authority.identity.key,
|
|
66
|
+
});
|
|
67
|
+
this.#unsubscribe = authority.onMembershipChanged(() => this.#membershipChanged());
|
|
68
|
+
}
|
|
69
|
+
accept(carrier, expect = {}) {
|
|
70
|
+
if (this.#closed || this.#sessions.size >= this.#limits.sessionsTotal) {
|
|
71
|
+
try {
|
|
72
|
+
carrier.close();
|
|
73
|
+
}
|
|
74
|
+
catch { /* Already closed. */ }
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const session = new ServerSession(this, carrier, expect);
|
|
78
|
+
this.#sessions.add(session);
|
|
79
|
+
session.start();
|
|
80
|
+
}
|
|
81
|
+
unlockedUntil(memberId) {
|
|
82
|
+
const window = this.#liveWindow(memberId);
|
|
83
|
+
return window ? window.until : null;
|
|
84
|
+
}
|
|
85
|
+
sessions(memberId) {
|
|
86
|
+
let count = 0;
|
|
87
|
+
for (const session of this.#sessions)
|
|
88
|
+
if (!session.closed && (memberId === undefined || session.memberId === memberId))
|
|
89
|
+
count++;
|
|
90
|
+
return count;
|
|
91
|
+
}
|
|
92
|
+
close() {
|
|
93
|
+
if (this.#closed)
|
|
94
|
+
return;
|
|
95
|
+
this.#closed = true;
|
|
96
|
+
this.#unsubscribe();
|
|
97
|
+
for (const session of [...this.#sessions])
|
|
98
|
+
session.close(true);
|
|
99
|
+
for (const window of this.#windows.values())
|
|
100
|
+
clearTimeout(window.timer);
|
|
101
|
+
this.#windows.clear();
|
|
102
|
+
}
|
|
103
|
+
// ---- Internal API used by ServerSession ----
|
|
104
|
+
get authority() { return this.#authority; }
|
|
105
|
+
get application() { return this.#application; }
|
|
106
|
+
get limits() { return this.#limits; }
|
|
107
|
+
get context() { return this.#context; }
|
|
108
|
+
now() { return this.#now(); }
|
|
109
|
+
removed(session) { this.#sessions.delete(session); }
|
|
110
|
+
countMember(memberId, except) {
|
|
111
|
+
let count = 0;
|
|
112
|
+
for (const session of this.#sessions)
|
|
113
|
+
if (session !== except && !session.closed && session.memberId === memberId)
|
|
114
|
+
count++;
|
|
115
|
+
return count;
|
|
116
|
+
}
|
|
117
|
+
countInvite(inviteId, except) {
|
|
118
|
+
let count = 0;
|
|
119
|
+
for (const session of this.#sessions)
|
|
120
|
+
if (session !== except && !session.closed && session.inviteId === inviteId)
|
|
121
|
+
count++;
|
|
122
|
+
return count;
|
|
123
|
+
}
|
|
124
|
+
/** Current snapshot, or null when the roster cannot be read or this bridge cannot serve it. */
|
|
125
|
+
servingSnapshot() {
|
|
126
|
+
try {
|
|
127
|
+
const snapshot = this.#authority.snapshot();
|
|
128
|
+
if (snapshot.workspaceId !== this.#authority.workspaceId)
|
|
129
|
+
return null;
|
|
130
|
+
if (snapshot.revoked.includes(this.#authority.bridgeMemberId))
|
|
131
|
+
return null;
|
|
132
|
+
if (!snapshot.members.some(member => member.id === this.#authority.bridgeMemberId && member.role === 'bridge'))
|
|
133
|
+
return null;
|
|
134
|
+
return snapshot;
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/** Re-check one member against the roster: close its sessions or end its unlock window as needed. Returns true if still active. */
|
|
141
|
+
enforce(memberId) {
|
|
142
|
+
const snapshot = this.servingSnapshot();
|
|
143
|
+
const device = snapshot && snapshot.leaseUntil > this.#now() ? activeDevice(snapshot, memberId) : null;
|
|
144
|
+
if (!snapshot || !device) {
|
|
145
|
+
this.#endWindow(memberId, false);
|
|
146
|
+
for (const session of [...this.#sessions])
|
|
147
|
+
if (session.memberId === memberId)
|
|
148
|
+
session.close();
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
const window = this.#windows.get(memberId);
|
|
152
|
+
if (window && (window.accountId !== device.accountId || !activeCredential(snapshot, window.accountId, window.credentialId))) {
|
|
153
|
+
this.#endWindow(memberId, true);
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
this.#liveWindow(memberId);
|
|
157
|
+
}
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
/** The member's unlock window if it is still open; an elapsed window is ended (and its sessions locked) here. */
|
|
161
|
+
#liveWindow(memberId) {
|
|
162
|
+
const window = this.#windows.get(memberId);
|
|
163
|
+
if (!window)
|
|
164
|
+
return null;
|
|
165
|
+
if (this.#monotonic() >= window.deadline || this.#now() >= window.until) {
|
|
166
|
+
this.#endWindow(memberId, true);
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
return window;
|
|
170
|
+
}
|
|
171
|
+
windowOpen(memberId) { return this.#liveWindow(memberId); }
|
|
172
|
+
openWindow(memberId, accountId, credentialId, leaseUntil) {
|
|
173
|
+
const now = this.#now();
|
|
174
|
+
const until = Math.min(now + this.#unlockLifetimeMs, leaseUntil);
|
|
175
|
+
const previous = this.#windows.get(memberId);
|
|
176
|
+
clearTimeout(previous?.timer);
|
|
177
|
+
const window = { deadline: this.#monotonic() + (until - now), until, credentialId, accountId, timer: undefined };
|
|
178
|
+
this.#windows.set(memberId, window);
|
|
179
|
+
this.#schedule(memberId, window);
|
|
180
|
+
return until;
|
|
181
|
+
}
|
|
182
|
+
#schedule(memberId, window) {
|
|
183
|
+
const remaining = Math.max(1, Math.min(MAX_TIMER_MS, Math.ceil(window.deadline - this.#monotonic())));
|
|
184
|
+
window.timer = setTimeout(() => {
|
|
185
|
+
if (this.#windows.get(memberId) !== window)
|
|
186
|
+
return;
|
|
187
|
+
if (this.#liveWindow(memberId))
|
|
188
|
+
this.#schedule(memberId, window);
|
|
189
|
+
}, remaining);
|
|
190
|
+
window.timer.unref?.();
|
|
191
|
+
}
|
|
192
|
+
#endWindow(memberId, notify) {
|
|
193
|
+
const window = this.#windows.get(memberId);
|
|
194
|
+
if (!window)
|
|
195
|
+
return;
|
|
196
|
+
clearTimeout(window.timer);
|
|
197
|
+
this.#windows.delete(memberId);
|
|
198
|
+
for (const session of this.#sessions)
|
|
199
|
+
if (session.memberId === memberId)
|
|
200
|
+
session.windowEnded(notify);
|
|
201
|
+
}
|
|
202
|
+
#membershipChanged() {
|
|
203
|
+
if (this.#closed)
|
|
204
|
+
return;
|
|
205
|
+
const snapshot = this.servingSnapshot();
|
|
206
|
+
const writer = (() => { try {
|
|
207
|
+
return this.#authority.isWriter();
|
|
208
|
+
}
|
|
209
|
+
catch {
|
|
210
|
+
return false;
|
|
211
|
+
} })();
|
|
212
|
+
const members = new Set();
|
|
213
|
+
for (const session of [...this.#sessions]) {
|
|
214
|
+
if (session.mode === 'pair' && (!snapshot || !writer))
|
|
215
|
+
session.close();
|
|
216
|
+
if (session.memberId)
|
|
217
|
+
members.add(session.memberId);
|
|
218
|
+
}
|
|
219
|
+
for (const memberId of this.#windows.keys())
|
|
220
|
+
members.add(memberId);
|
|
221
|
+
for (const memberId of members)
|
|
222
|
+
this.enforce(memberId);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
class ServerSession {
|
|
226
|
+
#server;
|
|
227
|
+
#carrier;
|
|
228
|
+
#expect;
|
|
229
|
+
#wire;
|
|
230
|
+
#decoder = new FrameDecoder();
|
|
231
|
+
#sessionId = randomBytes(16).toString('base64url');
|
|
232
|
+
#socket;
|
|
233
|
+
#phase = 'handshake';
|
|
234
|
+
#timer;
|
|
235
|
+
#pendingCarrier = 0;
|
|
236
|
+
#queue = Promise.resolve();
|
|
237
|
+
#unlockBinding = null;
|
|
238
|
+
#deviceBinding = null;
|
|
239
|
+
#nonce = null;
|
|
240
|
+
#refusals = 0;
|
|
241
|
+
#rosterBusy = false;
|
|
242
|
+
#rpcs = new Map();
|
|
243
|
+
#sockets = new Map();
|
|
244
|
+
#offers = new Set();
|
|
245
|
+
#pairInFlight = 0;
|
|
246
|
+
#finished = false;
|
|
247
|
+
mode;
|
|
248
|
+
memberId;
|
|
249
|
+
inviteId;
|
|
250
|
+
#accountId = '';
|
|
251
|
+
constructor(server, carrier, expect) {
|
|
252
|
+
this.#server = server;
|
|
253
|
+
this.#carrier = carrier;
|
|
254
|
+
this.#expect = expect;
|
|
255
|
+
// Node TLS needs a byte stream; each write completes only when the carrier accepted it (back-pressure).
|
|
256
|
+
this.#wire = new Duplex({
|
|
257
|
+
read() { },
|
|
258
|
+
write: (chunk, _encoding, done) => {
|
|
259
|
+
if (this.#phase === 'closed')
|
|
260
|
+
return done(new Error('Session closed'));
|
|
261
|
+
this.#pendingCarrier += chunk.length;
|
|
262
|
+
carrier.write(new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.length)).then(() => { this.#pendingCarrier -= chunk.length; done(); this.#lingerCheck(); }, () => { done(new Error('Carrier write failed')); this.close(true); });
|
|
263
|
+
},
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
get closed() { return this.#phase === 'closed' || this.#phase === 'closing'; }
|
|
267
|
+
start() {
|
|
268
|
+
const limits = this.#server.limits;
|
|
269
|
+
this.#carrier.onClose(() => this.close(true));
|
|
270
|
+
this.#carrier.onData(bytes => {
|
|
271
|
+
if (this.closed)
|
|
272
|
+
return;
|
|
273
|
+
if (!(bytes instanceof Uint8Array) || this.#wire.readableLength + bytes.length > limits.inboundBufferBytes)
|
|
274
|
+
return this.close();
|
|
275
|
+
this.#wire.push(Buffer.from(bytes));
|
|
276
|
+
});
|
|
277
|
+
this.#wire.on('error', () => this.close());
|
|
278
|
+
this.#arm(limits.handshakeMs);
|
|
279
|
+
try {
|
|
280
|
+
const socket = new TLSSocket(this.#wire, { isServer: true, secureContext: this.#server.context, requestCert: false, rejectUnauthorized: false });
|
|
281
|
+
this.#socket = socket;
|
|
282
|
+
socket.on('error', () => this.close());
|
|
283
|
+
socket.once('close', () => this.close());
|
|
284
|
+
socket.once('end', () => this.close());
|
|
285
|
+
socket.once('secure', () => this.#secure());
|
|
286
|
+
socket.once('finish', () => { this.#finished = true; this.#lingerCheck(); });
|
|
287
|
+
socket.on('data', (data) => this.#receive(data));
|
|
288
|
+
}
|
|
289
|
+
catch {
|
|
290
|
+
this.close();
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
#arm(ms) {
|
|
294
|
+
clearTimeout(this.#timer);
|
|
295
|
+
this.#timer = setTimeout(() => this.close(), ms);
|
|
296
|
+
this.#timer.unref?.();
|
|
297
|
+
}
|
|
298
|
+
#secure() {
|
|
299
|
+
const socket = this.#socket;
|
|
300
|
+
if (!socket || this.#phase !== 'handshake')
|
|
301
|
+
return this.close();
|
|
302
|
+
try {
|
|
303
|
+
if (socket.getProtocol() !== TLS_PROFILE.version || socket.getCipher()?.standardName !== TLS_PROFILE.cipher || socket.isSessionReused()) {
|
|
304
|
+
return this.close();
|
|
305
|
+
}
|
|
306
|
+
const context = Buffer.from(exporterContext(this.#server.authority.workspaceId, this.#server.authority.bridgeMemberId));
|
|
307
|
+
this.#deviceBinding = socket.exportKeyingMaterial(EXPORTER_LENGTH, DEVICE_AUTH_LABEL, context);
|
|
308
|
+
this.#unlockBinding = socket.exportKeyingMaterial(EXPORTER_LENGTH, ACCOUNT_UNLOCK_LABEL, context);
|
|
309
|
+
}
|
|
310
|
+
catch {
|
|
311
|
+
return this.close();
|
|
312
|
+
}
|
|
313
|
+
this.#phase = 'hello';
|
|
314
|
+
this.#arm(this.#server.limits.helloMs);
|
|
315
|
+
}
|
|
316
|
+
#receive(data) {
|
|
317
|
+
if (this.closed)
|
|
318
|
+
return;
|
|
319
|
+
if (this.#phase !== 'hello' && this.#phase !== 'open')
|
|
320
|
+
return this.close();
|
|
321
|
+
let messages;
|
|
322
|
+
try {
|
|
323
|
+
messages = this.#decoder.push(data);
|
|
324
|
+
}
|
|
325
|
+
catch {
|
|
326
|
+
return this.close();
|
|
327
|
+
}
|
|
328
|
+
for (const message of messages) {
|
|
329
|
+
if (this.#phase === 'open')
|
|
330
|
+
this.#arm(this.#server.limits.idleMs);
|
|
331
|
+
// Messages are handled strictly in order; only unlock verification and pairing awaits inside the queue.
|
|
332
|
+
this.#queue = this.#queue.then(() => this.closed ? undefined : this.#handle(message)).catch(() => this.close());
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
#send(message) {
|
|
336
|
+
const socket = this.#socket;
|
|
337
|
+
if (this.closed || !socket)
|
|
338
|
+
return false;
|
|
339
|
+
try {
|
|
340
|
+
socket.write(encodeMessage(message));
|
|
341
|
+
}
|
|
342
|
+
catch {
|
|
343
|
+
this.close();
|
|
344
|
+
return false;
|
|
345
|
+
}
|
|
346
|
+
if (this.#queued() > this.#server.limits.outboundQueueBytes) {
|
|
347
|
+
this.close();
|
|
348
|
+
return false;
|
|
349
|
+
}
|
|
350
|
+
return true;
|
|
351
|
+
}
|
|
352
|
+
#queued() {
|
|
353
|
+
return (this.#socket?.writableLength ?? 0) + this.#wire.writableLength + this.#pendingCarrier;
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Send a final message and close_notify, then close once the carrier accepted every byte, or after
|
|
357
|
+
* REFUSAL_LINGER_MS at most. Nothing from the peer is processed meanwhile.
|
|
358
|
+
*/
|
|
359
|
+
#refuse(message) {
|
|
360
|
+
if (this.closed || !this.#socket)
|
|
361
|
+
return this.close();
|
|
362
|
+
this.#phase = 'closing';
|
|
363
|
+
this.#teardown();
|
|
364
|
+
this.#timer = setTimeout(() => this.close(true), REFUSAL_LINGER_MS);
|
|
365
|
+
this.#timer.unref?.();
|
|
366
|
+
try {
|
|
367
|
+
this.#socket.end(encodeMessage(message));
|
|
368
|
+
}
|
|
369
|
+
catch {
|
|
370
|
+
return this.close(true);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
#lingerCheck() {
|
|
374
|
+
if (this.#phase === 'closing' && this.#finished && this.#pendingCarrier === 0 && this.#wire.writableLength === 0)
|
|
375
|
+
this.close(true);
|
|
376
|
+
}
|
|
377
|
+
async #handle(raw) {
|
|
378
|
+
if (this.#phase === 'hello') {
|
|
379
|
+
let hello;
|
|
380
|
+
try {
|
|
381
|
+
hello = parseHello(raw);
|
|
382
|
+
}
|
|
383
|
+
catch {
|
|
384
|
+
return this.close();
|
|
385
|
+
}
|
|
386
|
+
if (this.#expect.mode && this.#expect.mode !== hello.mode)
|
|
387
|
+
return this.#refuse({ t: 'refused', reason: 'unknown' });
|
|
388
|
+
if (hello.mode === 'session')
|
|
389
|
+
return this.#helloSession(hello);
|
|
390
|
+
return this.#helloPair(hello);
|
|
391
|
+
}
|
|
392
|
+
if (this.#phase !== 'open')
|
|
393
|
+
return;
|
|
394
|
+
if (this.mode === 'pair') {
|
|
395
|
+
let message;
|
|
396
|
+
try {
|
|
397
|
+
message = parseClientPair(raw);
|
|
398
|
+
}
|
|
399
|
+
catch {
|
|
400
|
+
return this.close();
|
|
401
|
+
}
|
|
402
|
+
return this.#pair(message);
|
|
403
|
+
}
|
|
404
|
+
let message;
|
|
405
|
+
try {
|
|
406
|
+
message = parseClientSession(raw);
|
|
407
|
+
}
|
|
408
|
+
catch {
|
|
409
|
+
return this.close();
|
|
410
|
+
}
|
|
411
|
+
const memberId = this.memberId;
|
|
412
|
+
if (!this.#server.enforce(memberId) || this.closed)
|
|
413
|
+
return;
|
|
414
|
+
if (message.t === 'roster')
|
|
415
|
+
return this.#sendRoster();
|
|
416
|
+
if (message.t === 'unlock')
|
|
417
|
+
return this.#unlock(message.credentialId, message.assertion);
|
|
418
|
+
if (!this.#server.windowOpen(memberId)) {
|
|
419
|
+
if (this.closed)
|
|
420
|
+
return;
|
|
421
|
+
return void this.#send({ t: 'error', id: message.id, code: 'locked' });
|
|
422
|
+
}
|
|
423
|
+
return this.#application(message);
|
|
424
|
+
}
|
|
425
|
+
#helloSession(hello) {
|
|
426
|
+
const server = this.#server, authority = server.authority;
|
|
427
|
+
const refuse = (reason) => this.#refuse({ t: 'refused', reason });
|
|
428
|
+
const snapshot = server.servingSnapshot();
|
|
429
|
+
if (!snapshot || hello.workspace !== authority.workspaceId)
|
|
430
|
+
return refuse('unknown');
|
|
431
|
+
if (this.#expect.memberId !== undefined && this.#expect.memberId !== hello.member)
|
|
432
|
+
return refuse('unknown');
|
|
433
|
+
const device = activeDevice(snapshot, hello.member);
|
|
434
|
+
if (!device || !snapshot.browserDevices || !this.#deviceBinding)
|
|
435
|
+
return refuse('unknown');
|
|
436
|
+
const challenge = deviceAuthChallenge(hooks, { workspaceId: authority.workspaceId, bridge: authority.bridgeMemberId, member: hello.member, binding: this.#deviceBinding });
|
|
437
|
+
this.#deviceBinding.fill(0);
|
|
438
|
+
this.#deviceBinding = null;
|
|
439
|
+
if (!verifyPq(device.member.publicKey, Buffer.from(challenge), hello.proof))
|
|
440
|
+
return refuse('unknown');
|
|
441
|
+
// Only an authenticated device learns that the lease has lapsed.
|
|
442
|
+
if (!(snapshot.leaseUntil > server.now()))
|
|
443
|
+
return refuse('expired');
|
|
444
|
+
if (server.countMember(hello.member, this) >= server.limits.sessionsPerMember)
|
|
445
|
+
return refuse('unknown');
|
|
446
|
+
this.mode = 'session';
|
|
447
|
+
this.memberId = hello.member;
|
|
448
|
+
this.#accountId = device.accountId;
|
|
449
|
+
this.#phase = 'open';
|
|
450
|
+
this.#arm(server.limits.idleMs);
|
|
451
|
+
const window = server.windowOpen(hello.member);
|
|
452
|
+
if (window && window.accountId === device.accountId && activeCredential(snapshot, window.accountId, window.credentialId)) {
|
|
453
|
+
this.#send({ t: 'welcome', v: SESSION_VERSION, mode: 'session', view: this.#view(snapshot), unlock: { until: window.until } });
|
|
454
|
+
}
|
|
455
|
+
else {
|
|
456
|
+
this.#nonce = nonce();
|
|
457
|
+
this.#send({ t: 'welcome', v: SESSION_VERSION, mode: 'session', view: this.#view(snapshot), unlock: { nonce: this.#nonce } });
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
#view(snapshot) {
|
|
461
|
+
return { generation: snapshot.generation, revision: snapshot.revision, head: snapshot.head, leaseUntil: snapshot.leaseUntil };
|
|
462
|
+
}
|
|
463
|
+
#helloPair(hello) {
|
|
464
|
+
const server = this.#server, authority = server.authority;
|
|
465
|
+
this.#deviceBinding?.fill(0);
|
|
466
|
+
this.#deviceBinding = null;
|
|
467
|
+
this.#unlockBinding?.fill(0);
|
|
468
|
+
this.#unlockBinding = null;
|
|
469
|
+
const refuse = () => this.#refuse({ t: 'refused', reason: 'unknown' });
|
|
470
|
+
try {
|
|
471
|
+
if (hello.workspace !== authority.workspaceId || !server.servingSnapshot() || !authority.isWriter() || !authority.pairing)
|
|
472
|
+
return refuse();
|
|
473
|
+
if (this.#expect.inviteId !== undefined && this.#expect.inviteId !== hello.invite)
|
|
474
|
+
return refuse();
|
|
475
|
+
if (!authority.pairing.inviteActive(hello.invite))
|
|
476
|
+
return refuse();
|
|
477
|
+
}
|
|
478
|
+
catch {
|
|
479
|
+
return refuse();
|
|
480
|
+
}
|
|
481
|
+
if (server.countInvite(hello.invite, this) >= server.limits.pairingSessionsPerInvite)
|
|
482
|
+
return refuse();
|
|
483
|
+
this.mode = 'pair';
|
|
484
|
+
this.inviteId = hello.invite;
|
|
485
|
+
this.#phase = 'open';
|
|
486
|
+
this.#arm(server.limits.idleMs);
|
|
487
|
+
this.#send({ t: 'welcome', v: SESSION_VERSION, mode: 'pair' });
|
|
488
|
+
}
|
|
489
|
+
async #pair(message) {
|
|
490
|
+
const authority = this.#server.authority;
|
|
491
|
+
if (++this.#pairInFlight > MAX_PAIR_IN_FLIGHT)
|
|
492
|
+
return this.close();
|
|
493
|
+
try {
|
|
494
|
+
let writer = false;
|
|
495
|
+
try {
|
|
496
|
+
writer = authority.isWriter();
|
|
497
|
+
}
|
|
498
|
+
catch { /* Treated as not the writer. */ }
|
|
499
|
+
if (!writer || !authority.pairing)
|
|
500
|
+
return this.close();
|
|
501
|
+
let result;
|
|
502
|
+
try {
|
|
503
|
+
result = await authority.pairing.request(message.op, message.body, this.inviteId);
|
|
504
|
+
}
|
|
505
|
+
catch {
|
|
506
|
+
// The device learns only that the request failed.
|
|
507
|
+
return void this.#send({ t: 'pair', id: message.id, ok: false });
|
|
508
|
+
}
|
|
509
|
+
if (this.closed)
|
|
510
|
+
return;
|
|
511
|
+
if (!pairReceiptApproved(message.op, result)) {
|
|
512
|
+
try {
|
|
513
|
+
encodeMessage({ t: 'pair', id: message.id, ok: true, result });
|
|
514
|
+
}
|
|
515
|
+
catch {
|
|
516
|
+
return void this.#send({ t: 'pair', id: message.id, ok: false });
|
|
517
|
+
}
|
|
518
|
+
return void this.#send({ t: 'pair', id: message.id, ok: true, result });
|
|
519
|
+
}
|
|
520
|
+
const { state, ...summary } = result;
|
|
521
|
+
let bundle = state;
|
|
522
|
+
let chunks;
|
|
523
|
+
try {
|
|
524
|
+
if (typeof bundle !== 'object' || bundle === null)
|
|
525
|
+
bundle = authority.exportBundle();
|
|
526
|
+
chunks = rosterChunks(JSON.stringify(bundle));
|
|
527
|
+
encodeMessage({ t: 'pair', id: message.id, ok: true, result: summary });
|
|
528
|
+
}
|
|
529
|
+
catch {
|
|
530
|
+
return void this.#send({ t: 'pair', id: message.id, ok: false });
|
|
531
|
+
}
|
|
532
|
+
if (!this.#send({ t: 'pair', id: message.id, ok: true, result: summary }))
|
|
533
|
+
return;
|
|
534
|
+
await this.#sendChunks(chunks);
|
|
535
|
+
}
|
|
536
|
+
finally {
|
|
537
|
+
this.#pairInFlight--;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
async #sendRoster() {
|
|
541
|
+
if (this.#rosterBusy)
|
|
542
|
+
return this.close();
|
|
543
|
+
let chunks;
|
|
544
|
+
try {
|
|
545
|
+
chunks = rosterChunks(JSON.stringify(this.#server.authority.exportBundle()));
|
|
546
|
+
}
|
|
547
|
+
catch {
|
|
548
|
+
return this.close();
|
|
549
|
+
}
|
|
550
|
+
this.#rosterBusy = true;
|
|
551
|
+
// Do not hold the message queue while a large roster drains.
|
|
552
|
+
void this.#sendChunks(chunks).finally(() => { this.#rosterBusy = false; });
|
|
553
|
+
}
|
|
554
|
+
async #sendChunks(chunks) {
|
|
555
|
+
for (const chunk of chunks) {
|
|
556
|
+
while (!this.closed && this.#queued() > ROSTER_LOW_WATER)
|
|
557
|
+
await new Promise(resolve => setTimeout(resolve, 5));
|
|
558
|
+
if (!this.#send(chunk))
|
|
559
|
+
return;
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
async #unlock(credentialId, assertion) {
|
|
563
|
+
const server = this.#server, authority = server.authority, memberId = this.memberId;
|
|
564
|
+
const current = this.#nonce;
|
|
565
|
+
if (!current || !this.#unlockBinding)
|
|
566
|
+
return this.close();
|
|
567
|
+
this.#nonce = null;
|
|
568
|
+
const snapshot = server.servingSnapshot();
|
|
569
|
+
const publicKey = snapshot ? activeCredential(snapshot, this.#accountId, credentialId) : null;
|
|
570
|
+
let ok = false;
|
|
571
|
+
if (snapshot?.browserDevices && publicKey) {
|
|
572
|
+
const challenge = accountUnlockChallenge(hooks, {
|
|
573
|
+
workspaceId: authority.workspaceId, bridge: authority.bridgeMemberId, member: memberId, account: this.#accountId,
|
|
574
|
+
binding: this.#unlockBinding, nonce: current,
|
|
575
|
+
});
|
|
576
|
+
ok = await verifyPasskeyAssertion({
|
|
577
|
+
publicKey, rpId: snapshot.browserDevices.rpId, origins: [snapshot.browserDevices.origin], challenge, signature: assertion,
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
if (this.closed)
|
|
581
|
+
return;
|
|
582
|
+
if (ok && server.enforce(memberId) && !this.closed) {
|
|
583
|
+
const latest = server.servingSnapshot();
|
|
584
|
+
if (latest && activeCredential(latest, this.#accountId, credentialId) === publicKey) {
|
|
585
|
+
const until = server.openWindow(memberId, this.#accountId, credentialId, latest.leaseUntil);
|
|
586
|
+
this.#nonce = null;
|
|
587
|
+
this.#send({ t: 'unlocked', until });
|
|
588
|
+
return;
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
if (this.closed)
|
|
592
|
+
return;
|
|
593
|
+
if (++this.#refusals >= MAX_UNLOCK_REFUSALS)
|
|
594
|
+
return this.#refuse({ t: 'unlock-refused', nonce: nonce() });
|
|
595
|
+
this.#nonce = nonce();
|
|
596
|
+
this.#send({ t: 'unlock-refused', nonce: this.#nonce });
|
|
597
|
+
}
|
|
598
|
+
#context() {
|
|
599
|
+
return { memberId: this.memberId, accountId: this.#accountId, carrier: this.#carrier.kind, sessionId: this.#sessionId };
|
|
600
|
+
}
|
|
601
|
+
#application(message) {
|
|
602
|
+
const app = this.#server.application, limits = this.#server.limits;
|
|
603
|
+
switch (message.t) {
|
|
604
|
+
case 'rpc': {
|
|
605
|
+
if (this.#rpcs.has(message.id) || this.#rpcs.size >= limits.rpcInFlight)
|
|
606
|
+
return this.close();
|
|
607
|
+
const controller = new AbortController();
|
|
608
|
+
this.#rpcs.set(message.id, controller);
|
|
609
|
+
const id = message.id;
|
|
610
|
+
void (async () => {
|
|
611
|
+
let reply;
|
|
612
|
+
try {
|
|
613
|
+
const result = await app.rpc(this.#context(), message.path, message.packet, controller.signal);
|
|
614
|
+
const status = result?.status;
|
|
615
|
+
reply = Number.isInteger(status) && status >= 100 && status <= 599
|
|
616
|
+
? (result.body === undefined ? { t: 'rpc', id, status } : { t: 'rpc', id, status, body: result.body })
|
|
617
|
+
: { t: 'rpc', id, status: 500 };
|
|
618
|
+
encodeMessage(reply);
|
|
619
|
+
}
|
|
620
|
+
catch {
|
|
621
|
+
reply = { t: 'rpc', id, status: 500 };
|
|
622
|
+
}
|
|
623
|
+
// A call that was cancelled by a lock or close already got its answer.
|
|
624
|
+
if (this.#rpcs.get(id) !== controller)
|
|
625
|
+
return;
|
|
626
|
+
this.#rpcs.delete(id);
|
|
627
|
+
this.#send(reply);
|
|
628
|
+
})();
|
|
629
|
+
return;
|
|
630
|
+
}
|
|
631
|
+
case 'ws-open': {
|
|
632
|
+
const id = message.id;
|
|
633
|
+
if (this.#sockets.has(id))
|
|
634
|
+
return this.close();
|
|
635
|
+
if (this.#sockets.size >= limits.sockets)
|
|
636
|
+
return void this.#send({ t: 'ws-closed', id });
|
|
637
|
+
let handle = null;
|
|
638
|
+
const peer = {
|
|
639
|
+
send: (data) => {
|
|
640
|
+
if (this.#sockets.get(id) !== handle || handle === null)
|
|
641
|
+
return;
|
|
642
|
+
if (typeof data !== 'string' || data.length > MAX_WS_DATA_CHARS) {
|
|
643
|
+
this.#sockets.delete(id);
|
|
644
|
+
try {
|
|
645
|
+
handle.close();
|
|
646
|
+
}
|
|
647
|
+
catch { /* ignore */ }
|
|
648
|
+
return void this.#send({ t: 'ws-close', id });
|
|
649
|
+
}
|
|
650
|
+
this.#send({ t: 'ws', id, data });
|
|
651
|
+
},
|
|
652
|
+
close: () => {
|
|
653
|
+
if (handle === null || this.#sockets.get(id) !== handle)
|
|
654
|
+
return;
|
|
655
|
+
this.#sockets.delete(id);
|
|
656
|
+
this.#send({ t: 'ws-close', id });
|
|
657
|
+
},
|
|
658
|
+
};
|
|
659
|
+
try {
|
|
660
|
+
handle = app.openSocket(this.#context(), id, peer);
|
|
661
|
+
}
|
|
662
|
+
catch {
|
|
663
|
+
handle = null;
|
|
664
|
+
}
|
|
665
|
+
if (!handle || this.closed)
|
|
666
|
+
return void this.#send({ t: 'ws-closed', id });
|
|
667
|
+
this.#sockets.set(id, handle);
|
|
668
|
+
return void this.#send({ t: 'ws-opened', id });
|
|
669
|
+
}
|
|
670
|
+
case 'ws': {
|
|
671
|
+
const handle = this.#sockets.get(message.id);
|
|
672
|
+
if (!handle)
|
|
673
|
+
return;
|
|
674
|
+
try {
|
|
675
|
+
handle.receive(message.data);
|
|
676
|
+
}
|
|
677
|
+
catch {
|
|
678
|
+
this.#closeSocket(message.id, true);
|
|
679
|
+
}
|
|
680
|
+
return;
|
|
681
|
+
}
|
|
682
|
+
case 'ws-close': return void this.#closeSocket(message.id, false);
|
|
683
|
+
case 'rtc-offer': {
|
|
684
|
+
const id = message.id;
|
|
685
|
+
if (this.#offers.has(id))
|
|
686
|
+
return this.close();
|
|
687
|
+
if (this.#carrier.kind !== 'relay' || !app.acceptOffer || this.#offers.size >= MAX_OFFERS_IN_FLIGHT)
|
|
688
|
+
return void this.#send({ t: 'rtc-refused', id });
|
|
689
|
+
this.#offers.add(id);
|
|
690
|
+
void (async () => {
|
|
691
|
+
let answer = null;
|
|
692
|
+
try {
|
|
693
|
+
answer = await app.acceptOffer(this.#context(), id, message.sdp, message.hostOnly);
|
|
694
|
+
}
|
|
695
|
+
catch {
|
|
696
|
+
answer = null;
|
|
697
|
+
}
|
|
698
|
+
if (!this.#offers.delete(id) || this.closed)
|
|
699
|
+
return;
|
|
700
|
+
const reply = { t: 'rtc-answer', id, sdp: answer?.sdp };
|
|
701
|
+
try {
|
|
702
|
+
parseServerSession(reply);
|
|
703
|
+
this.#send(reply);
|
|
704
|
+
}
|
|
705
|
+
catch {
|
|
706
|
+
this.#send({ t: 'rtc-refused', id });
|
|
707
|
+
}
|
|
708
|
+
})();
|
|
709
|
+
return;
|
|
710
|
+
}
|
|
711
|
+
case 'ping': return void this.#send({ t: 'pong', id: message.id });
|
|
712
|
+
case 'pong': return;
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
#closeSocket(id, notify) {
|
|
716
|
+
const handle = this.#sockets.get(id);
|
|
717
|
+
if (!handle)
|
|
718
|
+
return;
|
|
719
|
+
this.#sockets.delete(id);
|
|
720
|
+
try {
|
|
721
|
+
handle.close();
|
|
722
|
+
}
|
|
723
|
+
catch { /* ignore */ }
|
|
724
|
+
if (notify)
|
|
725
|
+
this.#send({ t: 'ws-close', id });
|
|
726
|
+
}
|
|
727
|
+
/** The member's unlock window ended: stop application work and, when asked, send `locked` with a fresh nonce. */
|
|
728
|
+
windowEnded(notify) {
|
|
729
|
+
if (this.closed || this.#phase !== 'open')
|
|
730
|
+
return;
|
|
731
|
+
for (const id of [...this.#sockets.keys()])
|
|
732
|
+
this.#closeSocket(id, true);
|
|
733
|
+
for (const [id, controller] of [...this.#rpcs]) {
|
|
734
|
+
this.#rpcs.delete(id);
|
|
735
|
+
controller.abort();
|
|
736
|
+
this.#send({ t: 'error', id, code: 'locked' });
|
|
737
|
+
}
|
|
738
|
+
for (const id of [...this.#offers]) {
|
|
739
|
+
this.#offers.delete(id);
|
|
740
|
+
this.#send({ t: 'rtc-refused', id });
|
|
741
|
+
}
|
|
742
|
+
if (notify && this.#nonce === null) {
|
|
743
|
+
this.#nonce = nonce();
|
|
744
|
+
this.#send({ t: 'locked', nonce: this.#nonce });
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
#teardown() {
|
|
748
|
+
clearTimeout(this.#timer);
|
|
749
|
+
this.#deviceBinding?.fill(0);
|
|
750
|
+
this.#deviceBinding = null;
|
|
751
|
+
this.#unlockBinding?.fill(0);
|
|
752
|
+
this.#unlockBinding = null;
|
|
753
|
+
this.#nonce = null;
|
|
754
|
+
for (const controller of this.#rpcs.values())
|
|
755
|
+
controller.abort();
|
|
756
|
+
this.#rpcs.clear();
|
|
757
|
+
for (const handle of this.#sockets.values()) {
|
|
758
|
+
try {
|
|
759
|
+
handle.close();
|
|
760
|
+
}
|
|
761
|
+
catch { /* ignore */ }
|
|
762
|
+
}
|
|
763
|
+
this.#sockets.clear();
|
|
764
|
+
this.#offers.clear();
|
|
765
|
+
}
|
|
766
|
+
/** During a refusal linger only the linger itself (or the peer closing the carrier) may finish the close. */
|
|
767
|
+
close(force = false) {
|
|
768
|
+
if (this.#phase === 'closed' || (this.#phase === 'closing' && !force))
|
|
769
|
+
return;
|
|
770
|
+
this.#phase = 'closed';
|
|
771
|
+
this.#teardown();
|
|
772
|
+
this.#socket?.destroy();
|
|
773
|
+
this.#wire.destroy();
|
|
774
|
+
try {
|
|
775
|
+
this.#carrier.close();
|
|
776
|
+
}
|
|
777
|
+
catch { /* Already closed. */ }
|
|
778
|
+
this.#server.removed(this);
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
//# sourceMappingURL=browser-session.js.map
|