@dxos/edge-client 0.6.12-main.78ddbdf → 0.6.12-main.7907542
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/lib/browser/index.mjs +291 -29
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +293 -29
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +291 -29
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/auth.d.ts +22 -0
- package/dist/types/src/auth.d.ts.map +1 -0
- package/dist/types/src/edge-client.d.ts +19 -11
- package/dist/types/src/edge-client.d.ts.map +1 -1
- package/dist/types/src/edge-http-client.d.ts +34 -0
- package/dist/types/src/edge-http-client.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +2 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/package.json +14 -11
- package/src/auth.ts +135 -0
- package/src/edge-client.test.ts +40 -8
- package/src/edge-client.ts +56 -16
- package/src/edge-http-client.ts +153 -0
- package/src/index.ts +2 -0
|
@@ -12,9 +12,11 @@ export * from "@dxos/protocols/buf/dxos/edge/messenger_pb";
|
|
|
12
12
|
import WebSocket from "isomorphic-ws";
|
|
13
13
|
import { Trigger, Event, scheduleTaskInterval, scheduleTask, TriggerState } from "@dxos/async";
|
|
14
14
|
import { Context, LifecycleState as LifecycleState2, Resource as Resource2 } from "@dxos/context";
|
|
15
|
+
import { randomBytes } from "@dxos/crypto";
|
|
15
16
|
import { log as log2 } from "@dxos/log";
|
|
16
17
|
import { buf } from "@dxos/protocols/buf";
|
|
17
18
|
import { MessageSchema } from "@dxos/protocols/buf/dxos/edge/messenger_pb";
|
|
19
|
+
import { schema } from "@dxos/protocols/proto";
|
|
18
20
|
|
|
19
21
|
// packages/core/mesh/edge-client/src/errors.ts
|
|
20
22
|
var EdgeConnectionClosedError = class extends Error {
|
|
@@ -125,11 +127,11 @@ _ts_decorate([
|
|
|
125
127
|
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-client.ts";
|
|
126
128
|
var DEFAULT_TIMEOUT = 1e4;
|
|
127
129
|
var SIGNAL_KEEPALIVE_INTERVAL = 5e3;
|
|
130
|
+
var DISABLE_AUTH = true;
|
|
128
131
|
var EdgeClient = class extends Resource2 {
|
|
129
|
-
constructor(
|
|
132
|
+
constructor(_identity, _config) {
|
|
130
133
|
super();
|
|
131
|
-
this.
|
|
132
|
-
this._peerKey = _peerKey;
|
|
134
|
+
this._identity = _identity;
|
|
133
135
|
this._config = _config;
|
|
134
136
|
this.reconnect = new Event();
|
|
135
137
|
this.connected = new Event();
|
|
@@ -148,19 +150,21 @@ var EdgeClient = class extends Resource2 {
|
|
|
148
150
|
get info() {
|
|
149
151
|
return {
|
|
150
152
|
open: this.isOpen,
|
|
151
|
-
identity: this.
|
|
152
|
-
device: this.
|
|
153
|
+
identity: this._identity.identityKey,
|
|
154
|
+
device: this._identity.peerKey
|
|
153
155
|
};
|
|
154
156
|
}
|
|
157
|
+
get isConnected() {
|
|
158
|
+
return Boolean(this._ws) && this._ready.state === TriggerState.RESOLVED;
|
|
159
|
+
}
|
|
155
160
|
get identityKey() {
|
|
156
|
-
return this.
|
|
161
|
+
return this._identity.identityKey;
|
|
157
162
|
}
|
|
158
163
|
get peerKey() {
|
|
159
|
-
return this.
|
|
164
|
+
return this._identity.peerKey;
|
|
160
165
|
}
|
|
161
|
-
setIdentity(
|
|
162
|
-
this.
|
|
163
|
-
this._identityKey = identityKey;
|
|
166
|
+
setIdentity(identity) {
|
|
167
|
+
this._identity = identity;
|
|
164
168
|
this._persistentLifecycle.scheduleRestart();
|
|
165
169
|
}
|
|
166
170
|
addListener(listener) {
|
|
@@ -175,7 +179,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
175
179
|
info: this.info
|
|
176
180
|
}, {
|
|
177
181
|
F: __dxlog_file2,
|
|
178
|
-
L:
|
|
182
|
+
L: 119,
|
|
179
183
|
S: this,
|
|
180
184
|
C: (f, a) => f(...a)
|
|
181
185
|
});
|
|
@@ -184,7 +188,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
184
188
|
err
|
|
185
189
|
}, {
|
|
186
190
|
F: __dxlog_file2,
|
|
187
|
-
L:
|
|
191
|
+
L: 121,
|
|
188
192
|
S: this,
|
|
189
193
|
C: (f, a) => f(...a)
|
|
190
194
|
});
|
|
@@ -195,22 +199,41 @@ var EdgeClient = class extends Resource2 {
|
|
|
195
199
|
*/
|
|
196
200
|
async _close() {
|
|
197
201
|
log2("closing...", {
|
|
198
|
-
peerKey: this.
|
|
202
|
+
peerKey: this._identity.peerKey
|
|
199
203
|
}, {
|
|
200
204
|
F: __dxlog_file2,
|
|
201
|
-
L:
|
|
205
|
+
L: 129,
|
|
202
206
|
S: this,
|
|
203
207
|
C: (f, a) => f(...a)
|
|
204
208
|
});
|
|
205
209
|
await this._persistentLifecycle.close();
|
|
206
210
|
}
|
|
207
211
|
async _openWebSocket() {
|
|
208
|
-
|
|
209
|
-
|
|
212
|
+
let protocolHeader;
|
|
213
|
+
if (!DISABLE_AUTH) {
|
|
214
|
+
const challenge = randomBytes(32);
|
|
215
|
+
const credential = await this._identity.presentCredentials({
|
|
216
|
+
challenge
|
|
217
|
+
});
|
|
218
|
+
protocolHeader = encodePresentationIntoAuthHeader(credential);
|
|
219
|
+
}
|
|
220
|
+
const url = new URL(`/ws/${this._identity.identityKey}/${this._identity.peerKey}`, this._config.socketEndpoint);
|
|
221
|
+
log2("Opening websocket", {
|
|
222
|
+
url: url.toString(),
|
|
223
|
+
protocolHeader
|
|
224
|
+
}, {
|
|
225
|
+
F: __dxlog_file2,
|
|
226
|
+
L: 144,
|
|
227
|
+
S: this,
|
|
228
|
+
C: (f, a) => f(...a)
|
|
229
|
+
});
|
|
230
|
+
this._ws = new WebSocket(url, protocolHeader ? [
|
|
231
|
+
protocolHeader
|
|
232
|
+
] : []);
|
|
210
233
|
this._ws.onopen = () => {
|
|
211
234
|
log2("opened", this.info, {
|
|
212
235
|
F: __dxlog_file2,
|
|
213
|
-
L:
|
|
236
|
+
L: 148,
|
|
214
237
|
S: this,
|
|
215
238
|
C: (f, a) => f(...a)
|
|
216
239
|
});
|
|
@@ -220,7 +243,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
220
243
|
this._ws.onclose = () => {
|
|
221
244
|
log2("closed", this.info, {
|
|
222
245
|
F: __dxlog_file2,
|
|
223
|
-
L:
|
|
246
|
+
L: 153,
|
|
224
247
|
S: this,
|
|
225
248
|
C: (f, a) => f(...a)
|
|
226
249
|
});
|
|
@@ -232,7 +255,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
232
255
|
info: event.message
|
|
233
256
|
}, {
|
|
234
257
|
F: __dxlog_file2,
|
|
235
|
-
L:
|
|
258
|
+
L: 157,
|
|
236
259
|
S: this,
|
|
237
260
|
C: (f, a) => f(...a)
|
|
238
261
|
});
|
|
@@ -246,11 +269,11 @@ var EdgeClient = class extends Resource2 {
|
|
|
246
269
|
const data = await toUint8Array(event.data);
|
|
247
270
|
const message = buf.fromBinary(MessageSchema, data);
|
|
248
271
|
log2("received", {
|
|
249
|
-
peerKey: this.
|
|
272
|
+
peerKey: this._identity.peerKey,
|
|
250
273
|
payload: protocol.getPayloadType(message)
|
|
251
274
|
}, {
|
|
252
275
|
F: __dxlog_file2,
|
|
253
|
-
L:
|
|
276
|
+
L: 170,
|
|
254
277
|
S: this,
|
|
255
278
|
C: (f, a) => f(...a)
|
|
256
279
|
});
|
|
@@ -264,7 +287,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
264
287
|
payload: protocol.getPayloadType(message)
|
|
265
288
|
}, {
|
|
266
289
|
F: __dxlog_file2,
|
|
267
|
-
L:
|
|
290
|
+
L: 176,
|
|
268
291
|
S: this,
|
|
269
292
|
C: (f, a) => f(...a)
|
|
270
293
|
});
|
|
@@ -277,7 +300,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
277
300
|
});
|
|
278
301
|
this._keepaliveCtx = new Context(void 0, {
|
|
279
302
|
F: __dxlog_file2,
|
|
280
|
-
L:
|
|
303
|
+
L: 186
|
|
281
304
|
});
|
|
282
305
|
scheduleTaskInterval(this._keepaliveCtx, async () => {
|
|
283
306
|
this._ws?.send("__ping__");
|
|
@@ -312,7 +335,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
312
335
|
err
|
|
313
336
|
}, {
|
|
314
337
|
F: __dxlog_file2,
|
|
315
|
-
L:
|
|
338
|
+
L: 222,
|
|
316
339
|
S: this,
|
|
317
340
|
C: (f, a) => f(...a)
|
|
318
341
|
});
|
|
@@ -326,7 +349,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
326
349
|
if (this._ready.state !== TriggerState.RESOLVED) {
|
|
327
350
|
log2("waiting for websocket to become ready", void 0, {
|
|
328
351
|
F: __dxlog_file2,
|
|
329
|
-
L:
|
|
352
|
+
L: 232,
|
|
330
353
|
S: this,
|
|
331
354
|
C: (f, a) => f(...a)
|
|
332
355
|
});
|
|
@@ -337,15 +360,15 @@ var EdgeClient = class extends Resource2 {
|
|
|
337
360
|
if (!this._ws) {
|
|
338
361
|
throw new EdgeConnectionClosedError();
|
|
339
362
|
}
|
|
340
|
-
if (message.source && (message.source.peerKey !== this.
|
|
363
|
+
if (message.source && (message.source.peerKey !== this._identity.peerKey || message.source.identityKey !== this.identityKey)) {
|
|
341
364
|
throw new EdgeIdentityChangedError();
|
|
342
365
|
}
|
|
343
366
|
log2("sending...", {
|
|
344
|
-
peerKey: this.
|
|
367
|
+
peerKey: this._identity.peerKey,
|
|
345
368
|
payload: protocol.getPayloadType(message)
|
|
346
369
|
}, {
|
|
347
370
|
F: __dxlog_file2,
|
|
348
|
-
L:
|
|
371
|
+
L: 245,
|
|
349
372
|
S: this,
|
|
350
373
|
C: (f, a) => f(...a)
|
|
351
374
|
});
|
|
@@ -358,18 +381,257 @@ var EdgeClient = class extends Resource2 {
|
|
|
358
381
|
void this._heartBeatContext?.dispose();
|
|
359
382
|
this._heartBeatContext = new Context(void 0, {
|
|
360
383
|
F: __dxlog_file2,
|
|
361
|
-
L:
|
|
384
|
+
L: 254
|
|
362
385
|
});
|
|
363
386
|
scheduleTask(this._heartBeatContext, () => {
|
|
364
387
|
this._persistentLifecycle.scheduleRestart();
|
|
365
388
|
}, 2 * SIGNAL_KEEPALIVE_INTERVAL);
|
|
366
389
|
}
|
|
367
390
|
};
|
|
391
|
+
var encodePresentationIntoAuthHeader = (presentation) => {
|
|
392
|
+
const encoded = schema.getCodecForType("dxos.halo.credentials.Presentation").encode(presentation);
|
|
393
|
+
const encodedToken = Buffer.from(encoded).toString("base64").replace(/=*$/, "").replaceAll("/", "|");
|
|
394
|
+
return `base64url.bearer.authorization.dxos.org.${encodedToken}`;
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
// packages/core/mesh/edge-client/src/auth.ts
|
|
398
|
+
import { createCredential, signPresentation } from "@dxos/credentials";
|
|
399
|
+
import { Keyring } from "@dxos/keyring";
|
|
400
|
+
import { PublicKey } from "@dxos/keys";
|
|
401
|
+
var createDeviceEdgeIdentity = async (signer, key) => {
|
|
402
|
+
return {
|
|
403
|
+
identityKey: key.toHex(),
|
|
404
|
+
peerKey: key.toHex(),
|
|
405
|
+
presentCredentials: async ({ challenge }) => {
|
|
406
|
+
return signPresentation({
|
|
407
|
+
presentation: {
|
|
408
|
+
credentials: [
|
|
409
|
+
// Verifier requires at least one credential in the presentation to establish the subject.
|
|
410
|
+
await createCredential({
|
|
411
|
+
assertion: {
|
|
412
|
+
"@type": "dxos.halo.credentials.Auth"
|
|
413
|
+
},
|
|
414
|
+
issuer: key,
|
|
415
|
+
subject: key,
|
|
416
|
+
signer
|
|
417
|
+
})
|
|
418
|
+
]
|
|
419
|
+
},
|
|
420
|
+
signer,
|
|
421
|
+
signerKey: key,
|
|
422
|
+
nonce: challenge
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
};
|
|
426
|
+
};
|
|
427
|
+
var createChainEdgeIdentity = async (signer, identityKey, peerKey, chain, credentials) => {
|
|
428
|
+
const credentialsToSign = credentials.length > 0 ? credentials : [
|
|
429
|
+
await createCredential({
|
|
430
|
+
assertion: {
|
|
431
|
+
"@type": "dxos.halo.credentials.Auth"
|
|
432
|
+
},
|
|
433
|
+
issuer: identityKey,
|
|
434
|
+
subject: identityKey,
|
|
435
|
+
signer,
|
|
436
|
+
chain,
|
|
437
|
+
signingKey: peerKey
|
|
438
|
+
})
|
|
439
|
+
];
|
|
440
|
+
return {
|
|
441
|
+
identityKey: identityKey.toHex(),
|
|
442
|
+
peerKey: peerKey.toHex(),
|
|
443
|
+
presentCredentials: async ({ challenge }) => {
|
|
444
|
+
return signPresentation({
|
|
445
|
+
presentation: {
|
|
446
|
+
credentials: credentialsToSign
|
|
447
|
+
},
|
|
448
|
+
signer,
|
|
449
|
+
nonce: challenge,
|
|
450
|
+
signerKey: peerKey,
|
|
451
|
+
chain
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
};
|
|
455
|
+
};
|
|
456
|
+
var createEphemeralEdgeIdentity = async () => {
|
|
457
|
+
const keyring = new Keyring();
|
|
458
|
+
const key = await keyring.createKey();
|
|
459
|
+
return createDeviceEdgeIdentity(keyring, key);
|
|
460
|
+
};
|
|
461
|
+
var createTestHaloEdgeIdentity = async (signer, identityKey, deviceKey) => {
|
|
462
|
+
const deviceAdmission = await createCredential({
|
|
463
|
+
assertion: {
|
|
464
|
+
"@type": "dxos.halo.credentials.AuthorizedDevice",
|
|
465
|
+
deviceKey,
|
|
466
|
+
identityKey
|
|
467
|
+
},
|
|
468
|
+
issuer: identityKey,
|
|
469
|
+
subject: deviceKey,
|
|
470
|
+
signer
|
|
471
|
+
});
|
|
472
|
+
return createChainEdgeIdentity(signer, identityKey, deviceKey, {
|
|
473
|
+
credential: deviceAdmission
|
|
474
|
+
}, [
|
|
475
|
+
await createCredential({
|
|
476
|
+
assertion: {
|
|
477
|
+
"@type": "dxos.halo.credentials.Auth"
|
|
478
|
+
},
|
|
479
|
+
issuer: identityKey,
|
|
480
|
+
subject: identityKey,
|
|
481
|
+
signer
|
|
482
|
+
})
|
|
483
|
+
]);
|
|
484
|
+
};
|
|
485
|
+
var createStubEdgeIdentity = () => {
|
|
486
|
+
const identityKey = PublicKey.random();
|
|
487
|
+
const deviceKey = PublicKey.random();
|
|
488
|
+
return {
|
|
489
|
+
identityKey: identityKey.toHex(),
|
|
490
|
+
peerKey: deviceKey.toHex(),
|
|
491
|
+
presentCredentials: async () => {
|
|
492
|
+
throw new Error("Stub identity does not support authentication.");
|
|
493
|
+
}
|
|
494
|
+
};
|
|
495
|
+
};
|
|
496
|
+
|
|
497
|
+
// packages/core/mesh/edge-client/src/edge-http-client.ts
|
|
498
|
+
import { sleep as sleep2 } from "@dxos/async";
|
|
499
|
+
import { Context as Context2 } from "@dxos/context";
|
|
500
|
+
import { log as log3 } from "@dxos/log";
|
|
501
|
+
import { EdgeCallFailedError } from "@dxos/protocols";
|
|
502
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-http-client.ts";
|
|
503
|
+
var DEFAULT_RETRY_TIMEOUT = 1500;
|
|
504
|
+
var DEFAULT_RETRY_JITTER = 500;
|
|
505
|
+
var DEFAULT_MAX_RETRIES_COUNT = 3;
|
|
506
|
+
var EdgeHttpClient = class {
|
|
507
|
+
constructor(baseUrl) {
|
|
508
|
+
const url = new URL(baseUrl);
|
|
509
|
+
url.protocol = "https";
|
|
510
|
+
this._baseUrl = url.toString();
|
|
511
|
+
log3("created", {
|
|
512
|
+
url: this._baseUrl
|
|
513
|
+
}, {
|
|
514
|
+
F: __dxlog_file3,
|
|
515
|
+
L: 27,
|
|
516
|
+
S: this,
|
|
517
|
+
C: (f, a) => f(...a)
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
getCredentialsForNotarization(spaceId, args) {
|
|
521
|
+
return this._call(`/spaces/${spaceId}/notarization`, {
|
|
522
|
+
...args,
|
|
523
|
+
method: "GET"
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
async notarizeCredentials(spaceId, body, args) {
|
|
527
|
+
await this._call(`/spaces/${spaceId}/notarization`, {
|
|
528
|
+
...args,
|
|
529
|
+
body,
|
|
530
|
+
method: "POST"
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
async _call(path, args) {
|
|
534
|
+
const requestContext = args.context ?? new Context2(void 0, {
|
|
535
|
+
F: __dxlog_file3,
|
|
536
|
+
L: 43
|
|
537
|
+
});
|
|
538
|
+
const shouldRetry = createRetryHandler(args);
|
|
539
|
+
const request = createRequest(args);
|
|
540
|
+
const url = `${this._baseUrl}${path.startsWith("/") ? path.slice(1) : path}`;
|
|
541
|
+
log3.info("call", {
|
|
542
|
+
method: args.method,
|
|
543
|
+
path
|
|
544
|
+
}, {
|
|
545
|
+
F: __dxlog_file3,
|
|
546
|
+
L: 48,
|
|
547
|
+
S: this,
|
|
548
|
+
C: (f, a) => f(...a)
|
|
549
|
+
});
|
|
550
|
+
while (true) {
|
|
551
|
+
let processingError;
|
|
552
|
+
let retryAfterHeaderValue = Number.NaN;
|
|
553
|
+
try {
|
|
554
|
+
const response = await fetch(url, request);
|
|
555
|
+
retryAfterHeaderValue = Number(response.headers.get("Retry-After"));
|
|
556
|
+
if (response.ok) {
|
|
557
|
+
const body = await response.json();
|
|
558
|
+
if (body.success) {
|
|
559
|
+
return body.data;
|
|
560
|
+
}
|
|
561
|
+
const isNonRetryable = body.errorData != null;
|
|
562
|
+
if (isNonRetryable) {
|
|
563
|
+
throw new EdgeCallFailedError(body.reason, body.errorData);
|
|
564
|
+
}
|
|
565
|
+
processingError = new EdgeCallFailedError(body.reason);
|
|
566
|
+
} else {
|
|
567
|
+
processingError = EdgeCallFailedError.fromFailureResponse(response);
|
|
568
|
+
if (!isRetryable(response.status)) {
|
|
569
|
+
throw processingError;
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
} catch (error) {
|
|
573
|
+
processingError = EdgeCallFailedError.fromProcessingFailureCause(error);
|
|
574
|
+
}
|
|
575
|
+
if (await shouldRetry(requestContext, retryAfterHeaderValue)) {
|
|
576
|
+
log3.info("retrying edge request", {
|
|
577
|
+
path,
|
|
578
|
+
processingError
|
|
579
|
+
}, {
|
|
580
|
+
F: __dxlog_file3,
|
|
581
|
+
L: 81,
|
|
582
|
+
S: this,
|
|
583
|
+
C: (f, a) => f(...a)
|
|
584
|
+
});
|
|
585
|
+
} else {
|
|
586
|
+
throw processingError;
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
};
|
|
591
|
+
var createRequest = (args) => {
|
|
592
|
+
return {
|
|
593
|
+
method: args.method,
|
|
594
|
+
body: args.body && JSON.stringify(args.body)
|
|
595
|
+
};
|
|
596
|
+
};
|
|
597
|
+
var isRetryable = (status) => {
|
|
598
|
+
if (status === 501) {
|
|
599
|
+
return false;
|
|
600
|
+
}
|
|
601
|
+
return !(status >= 400 && status < 500);
|
|
602
|
+
};
|
|
603
|
+
var createRetryHandler = (args) => {
|
|
604
|
+
if (!args.retry || args.retry.count < 1) {
|
|
605
|
+
return async () => false;
|
|
606
|
+
}
|
|
607
|
+
let retries = 0;
|
|
608
|
+
const maxRetries = args.retry.count ?? DEFAULT_MAX_RETRIES_COUNT;
|
|
609
|
+
const baseTimeout = args.retry.timeout ?? DEFAULT_RETRY_TIMEOUT;
|
|
610
|
+
const jitter = args.retry.jitter ?? DEFAULT_RETRY_JITTER;
|
|
611
|
+
return async (ctx, retryAfter) => {
|
|
612
|
+
if (++retries > maxRetries || ctx.disposed) {
|
|
613
|
+
return false;
|
|
614
|
+
}
|
|
615
|
+
if (retryAfter) {
|
|
616
|
+
await sleep2(retryAfter);
|
|
617
|
+
} else {
|
|
618
|
+
const timeout = baseTimeout + Math.random() * jitter;
|
|
619
|
+
await sleep2(timeout);
|
|
620
|
+
}
|
|
621
|
+
return true;
|
|
622
|
+
};
|
|
623
|
+
};
|
|
368
624
|
export {
|
|
369
625
|
EdgeClient,
|
|
370
626
|
EdgeConnectionClosedError,
|
|
627
|
+
EdgeHttpClient,
|
|
371
628
|
EdgeIdentityChangedError,
|
|
372
629
|
Protocol,
|
|
630
|
+
createChainEdgeIdentity,
|
|
631
|
+
createDeviceEdgeIdentity,
|
|
632
|
+
createEphemeralEdgeIdentity,
|
|
633
|
+
createStubEdgeIdentity,
|
|
634
|
+
createTestHaloEdgeIdentity,
|
|
373
635
|
getTypename,
|
|
374
636
|
protocol,
|
|
375
637
|
toUint8Array
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/index.ts", "../../../src/edge-client.ts", "../../../src/errors.ts", "../../../src/persistent-lifecycle.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nexport * from '@dxos/protocols/buf/dxos/edge/messenger_pb';\n\nexport * from './edge-client';\nexport * from './defs';\nexport * from './protocol';\nexport * from './errors';\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport WebSocket from 'isomorphic-ws';\n\nimport { Trigger, Event, scheduleTaskInterval, scheduleTask, TriggerState } from '@dxos/async';\nimport { Context, LifecycleState, Resource, type Lifecycle } from '@dxos/context';\nimport { log } from '@dxos/log';\nimport { buf } from '@dxos/protocols/buf';\nimport { type Message, MessageSchema } from '@dxos/protocols/buf/dxos/edge/messenger_pb';\n\nimport { protocol } from './defs';\nimport { EdgeConnectionClosedError, EdgeIdentityChangedError } from './errors';\nimport { PersistentLifecycle } from './persistent-lifecycle';\nimport { type Protocol, toUint8Array } from './protocol';\n\nconst DEFAULT_TIMEOUT = 10_000;\nconst SIGNAL_KEEPALIVE_INTERVAL = 5_000;\n\nexport type MessageListener = (message: Message) => void | Promise<void>;\n\nexport interface EdgeConnection extends Required<Lifecycle> {\n connected: Event;\n reconnect: Event;\n\n get info(): any;\n get identityKey(): string;\n get peerKey(): string;\n get isOpen(): boolean;\n setIdentity(params: { peerKey: string; identityKey: string }): void;\n addListener(listener: MessageListener): () => void;\n send(message: Message): Promise<void>;\n}\n\nexport type MessengerConfig = {\n socketEndpoint: string;\n timeout?: number;\n protocol?: Protocol;\n};\n\n/**\n * Messenger client.\n */\nexport class EdgeClient extends Resource implements EdgeConnection {\n public readonly reconnect = new Event();\n public readonly connected = new Event();\n private readonly _persistentLifecycle = new PersistentLifecycle({\n start: async () => this._openWebSocket(),\n stop: async () => this._closeWebSocket(),\n onRestart: async () => this.reconnect.emit(),\n });\n\n private readonly _listeners = new Set<MessageListener>();\n private _ready = new Trigger();\n private _ws?: WebSocket = undefined;\n private _keepaliveCtx?: Context = undefined;\n private _heartBeatContext?: Context = undefined;\n\n constructor(\n private _identityKey: string,\n private _peerKey: string,\n private readonly _config: MessengerConfig,\n ) {\n super();\n }\n\n // TODO(burdon): Attach logging.\n public get info() {\n return {\n open: this.isOpen,\n identity: this._identityKey,\n device: this._peerKey,\n };\n }\n\n get identityKey() {\n return this._identityKey;\n }\n\n get peerKey() {\n return this._peerKey;\n }\n\n setIdentity({ peerKey, identityKey }: { peerKey: string; identityKey: string }) {\n this._peerKey = peerKey;\n this._identityKey = identityKey;\n this._persistentLifecycle.scheduleRestart();\n }\n\n public addListener(listener: MessageListener): () => void {\n this._listeners.add(listener);\n return () => this._listeners.delete(listener);\n }\n\n /**\n * Open connection to messaging service.\n */\n protected override async _open() {\n log('opening...', { info: this.info });\n this._persistentLifecycle.open().catch((err) => {\n log.warn('Error while opening connection', { err });\n });\n }\n\n /**\n * Close connection and free resources.\n */\n protected override async _close() {\n log('closing...', { peerKey: this._peerKey });\n await this._persistentLifecycle.close();\n }\n\n private async _openWebSocket() {\n const url = new URL(`/ws/${this._identityKey}/${this._peerKey}`, this._config.socketEndpoint);\n this._ws = new WebSocket(url);\n\n this._ws.onopen = () => {\n log('opened', this.info);\n this._ready.wake();\n this.connected.emit();\n };\n this._ws.onclose = () => {\n log('closed', this.info);\n this._persistentLifecycle.scheduleRestart();\n };\n this._ws.onerror = (event) => {\n log.warn('EdgeClient socket error', { error: event.error, info: event.message });\n this._persistentLifecycle.scheduleRestart();\n };\n /**\n * https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent/data\n */\n this._ws.onmessage = async (event) => {\n if (event.data === '__pong__') {\n this._onHeartbeat();\n return;\n }\n const data = await toUint8Array(event.data);\n const message = buf.fromBinary(MessageSchema, data);\n log('received', { peerKey: this._peerKey, payload: protocol.getPayloadType(message) });\n if (message) {\n for (const listener of this._listeners) {\n try {\n await listener(message);\n } catch (err) {\n log.error('processing', { err, payload: protocol.getPayloadType(message) });\n }\n }\n }\n };\n\n await this._ready.wait({ timeout: this._config.timeout ?? DEFAULT_TIMEOUT });\n this._keepaliveCtx = new Context();\n scheduleTaskInterval(\n this._keepaliveCtx,\n async () => {\n // TODO(mykola): use RFC6455 ping/pong once implemented in the browser?\n // Cloudflare's worker responds to this `without interrupting hibernation`. https://developers.cloudflare.com/durable-objects/api/websockets/#setwebsocketautoresponse\n this._ws?.send('__ping__');\n },\n SIGNAL_KEEPALIVE_INTERVAL,\n );\n this._ws.send('__ping__');\n this._onHeartbeat();\n }\n\n private async _closeWebSocket() {\n if (!this._ws) {\n return;\n }\n try {\n this._ready.throw(this.isOpen ? new EdgeIdentityChangedError() : new EdgeConnectionClosedError());\n this._ready.reset();\n void this._keepaliveCtx?.dispose();\n this._keepaliveCtx = undefined;\n void this._heartBeatContext?.dispose();\n this._heartBeatContext = undefined;\n\n // NOTE: Remove event handlers to avoid scheduling restart.\n this._ws.onopen = () => {};\n this._ws.onclose = () => {};\n this._ws.onerror = () => {};\n this._ws.close();\n this._ws = undefined;\n } catch (err) {\n if (err instanceof Error && err.message.includes('WebSocket is closed before the connection is established.')) {\n return;\n }\n log.warn('Error closing websocket', { err });\n }\n }\n\n /**\n * Send message.\n * NOTE: The message is guaranteed to be delivered but the service must respond with a message to confirm processing.\n */\n public async send(message: Message): Promise<void> {\n if (this._ready.state !== TriggerState.RESOLVED) {\n log('waiting for websocket to become ready');\n await this._ready.wait({ timeout: this._config.timeout ?? DEFAULT_TIMEOUT });\n }\n if (!this._ws) {\n throw new EdgeConnectionClosedError();\n }\n if (\n message.source &&\n (message.source.peerKey !== this._peerKey || message.source.identityKey !== this.identityKey)\n ) {\n throw new EdgeIdentityChangedError();\n }\n\n log('sending...', { peerKey: this._peerKey, payload: protocol.getPayloadType(message) });\n this._ws.send(buf.toBinary(MessageSchema, message));\n }\n\n private _onHeartbeat() {\n if (this._lifecycleState !== LifecycleState.OPEN) {\n return;\n }\n void this._heartBeatContext?.dispose();\n this._heartBeatContext = new Context();\n scheduleTask(\n this._heartBeatContext,\n () => {\n this._persistentLifecycle.scheduleRestart();\n },\n 2 * SIGNAL_KEEPALIVE_INTERVAL,\n );\n }\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nexport class EdgeConnectionClosedError extends Error {\n constructor() {\n super('Edge connection closed.');\n }\n}\n\nexport class EdgeIdentityChangedError extends Error {\n constructor() {\n super('Edge identity changed.');\n }\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { DeferredTask, sleep, synchronized } from '@dxos/async';\nimport { cancelWithContext, LifecycleState, Resource } from '@dxos/context';\nimport { warnAfterTimeout } from '@dxos/debug';\nimport { log } from '@dxos/log';\n\nconst INIT_RESTART_DELAY = 100;\nconst DEFAULT_MAX_RESTART_DELAY = 5000;\n\nexport type PersistentLifecycleParams = {\n /**\n * Create connection.\n * If promise resolves successfully, connection is considered established.\n */\n start: () => Promise<void>;\n\n /**\n * Reset connection to initial state.\n */\n stop: () => Promise<void>;\n\n /**\n * Called after successful start.\n */\n onRestart?: () => Promise<void>;\n\n /**\n * Maximum delay between restartion attempts.\n * Default: 5000ms\n */\n maxRestartDelay?: number;\n};\n\n/**\n * Handles restarts (e.g. persists connection).\n * Restarts are scheduled with exponential backoff.\n */\nexport class PersistentLifecycle extends Resource {\n private readonly _start: () => Promise<void>;\n private readonly _stop: () => Promise<void>;\n private readonly _onRestart?: () => Promise<void>;\n private readonly _maxRestartDelay: number;\n\n private _restartTask?: DeferredTask = undefined;\n private _restartAfter = 0;\n\n constructor({ start, stop, onRestart, maxRestartDelay = DEFAULT_MAX_RESTART_DELAY }: PersistentLifecycleParams) {\n super();\n this._start = start;\n this._stop = stop;\n this._onRestart = onRestart;\n this._maxRestartDelay = maxRestartDelay;\n }\n\n @synchronized\n protected override async _open() {\n this._restartTask = new DeferredTask(this._ctx, async () => {\n try {\n await this._restart();\n } catch (err) {\n log.warn('Restart failed', { err });\n this._restartTask?.schedule();\n }\n });\n await this._start().catch((err) => {\n log.warn('Start failed', { err });\n this._restartTask?.schedule();\n });\n }\n\n protected override async _close() {\n await this._restartTask?.join();\n await this._stop();\n this._restartTask = undefined;\n }\n\n private async _restart() {\n log(`restarting in ${this._restartAfter}ms`, { state: this._lifecycleState });\n await this._stop();\n if (this._lifecycleState !== LifecycleState.OPEN) {\n return;\n }\n await cancelWithContext(this._ctx!, sleep(this._restartAfter));\n this._restartAfter = Math.min(Math.max(this._restartAfter * 2, INIT_RESTART_DELAY), this._maxRestartDelay);\n\n // May fail if the connection is not established.\n await warnAfterTimeout(5_000, 'Connection establishment takes too long', () => this._start());\n\n this._restartAfter = 0;\n await this._onRestart?.();\n }\n\n /**\n * Scheduling restart should be done from outside.\n */\n @synchronized\n scheduleRestart() {\n if (this._lifecycleState !== LifecycleState.OPEN) {\n return;\n }\n this._restartTask!.schedule();\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;AAIA,cAAc;;;ACAd,OAAOA,eAAe;AAEtB,SAASC,SAASC,OAAOC,sBAAsBC,cAAcC,oBAAoB;AACjF,SAASC,SAASC,kBAAAA,iBAAgBC,YAAAA,iBAAgC;AAClE,SAASC,OAAAA,YAAW;AACpB,SAASC,WAAW;AACpB,SAAuBC,qBAAqB;;;
|
|
6
|
-
"names": ["WebSocket", "Trigger", "Event", "scheduleTaskInterval", "scheduleTask", "TriggerState", "Context", "LifecycleState", "Resource", "log", "buf", "MessageSchema", "EdgeConnectionClosedError", "Error", "constructor", "EdgeIdentityChangedError", "DeferredTask", "sleep", "synchronized", "cancelWithContext", "LifecycleState", "Resource", "warnAfterTimeout", "log", "INIT_RESTART_DELAY", "DEFAULT_MAX_RESTART_DELAY", "PersistentLifecycle", "constructor", "start", "stop", "onRestart", "maxRestartDelay", "_restartTask", "undefined", "_restartAfter", "_start", "_stop", "_onRestart", "_maxRestartDelay", "_open", "_ctx", "_restart", "err", "warn", "schedule", "catch", "_close", "join", "state", "_lifecycleState", "OPEN", "Math", "min", "max", "scheduleRestart", "DEFAULT_TIMEOUT", "SIGNAL_KEEPALIVE_INTERVAL", "
|
|
3
|
+
"sources": ["../../../src/index.ts", "../../../src/edge-client.ts", "../../../src/errors.ts", "../../../src/persistent-lifecycle.ts", "../../../src/auth.ts", "../../../src/edge-http-client.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nexport * from '@dxos/protocols/buf/dxos/edge/messenger_pb';\n\nexport * from './edge-client';\nexport * from './defs';\nexport * from './protocol';\nexport * from './errors';\nexport * from './auth';\nexport * from './edge-http-client';\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport WebSocket from 'isomorphic-ws';\n\nimport { Trigger, Event, scheduleTaskInterval, scheduleTask, TriggerState } from '@dxos/async';\nimport { Context, LifecycleState, Resource, type Lifecycle } from '@dxos/context';\nimport { randomBytes } from '@dxos/crypto';\nimport { log } from '@dxos/log';\nimport { buf } from '@dxos/protocols/buf';\nimport { type Message, MessageSchema } from '@dxos/protocols/buf/dxos/edge/messenger_pb';\nimport { schema } from '@dxos/protocols/proto';\nimport { type Presentation } from '@dxos/protocols/proto/dxos/halo/credentials';\n\nimport { protocol } from './defs';\nimport { EdgeConnectionClosedError, EdgeIdentityChangedError } from './errors';\nimport { PersistentLifecycle } from './persistent-lifecycle';\nimport { type Protocol, toUint8Array } from './protocol';\n\nconst DEFAULT_TIMEOUT = 10_000;\nconst SIGNAL_KEEPALIVE_INTERVAL = 5_000;\n\nexport type MessageListener = (message: Message) => void | Promise<void>;\n\nexport interface EdgeConnection extends Required<Lifecycle> {\n connected: Event;\n reconnect: Event;\n\n get info(): any;\n get identityKey(): string;\n get peerKey(): string;\n get isOpen(): boolean;\n get isConnected(): boolean;\n setIdentity(identity: EdgeIdentity): void;\n addListener(listener: MessageListener): () => void;\n send(message: Message): Promise<void>;\n}\n\nexport type MessengerConfig = {\n socketEndpoint: string;\n timeout?: number;\n protocol?: Protocol;\n};\n\nexport interface EdgeIdentity {\n peerKey: string;\n identityKey: string;\n /**\n * Returns credential presentation issued by the identity key.\n * Presentation must have the provided challenge.\n * Presentation may include ServiceAccess credentials.\n */\n presentCredentials({ challenge }: { challenge: Uint8Array }): Promise<Presentation>;\n}\n\nconst DISABLE_AUTH = true;\n\n/**\n * Messenger client.\n */\nexport class EdgeClient extends Resource implements EdgeConnection {\n public readonly reconnect = new Event();\n public readonly connected = new Event();\n private readonly _persistentLifecycle = new PersistentLifecycle({\n start: async () => this._openWebSocket(),\n stop: async () => this._closeWebSocket(),\n onRestart: async () => this.reconnect.emit(),\n });\n\n private readonly _listeners = new Set<MessageListener>();\n private _ready = new Trigger();\n private _ws?: WebSocket = undefined;\n private _keepaliveCtx?: Context = undefined;\n private _heartBeatContext?: Context = undefined;\n\n constructor(\n private _identity: EdgeIdentity,\n private readonly _config: MessengerConfig,\n ) {\n super();\n }\n\n // TODO(burdon): Attach logging.\n public get info() {\n return {\n open: this.isOpen,\n identity: this._identity.identityKey,\n device: this._identity.peerKey,\n };\n }\n\n get isConnected() {\n return Boolean(this._ws) && this._ready.state === TriggerState.RESOLVED;\n }\n\n get identityKey() {\n return this._identity.identityKey;\n }\n\n get peerKey() {\n return this._identity.peerKey;\n }\n\n setIdentity(identity: EdgeIdentity) {\n this._identity = identity;\n this._persistentLifecycle.scheduleRestart();\n }\n\n public addListener(listener: MessageListener): () => void {\n this._listeners.add(listener);\n return () => this._listeners.delete(listener);\n }\n\n /**\n * Open connection to messaging service.\n */\n protected override async _open() {\n log('opening...', { info: this.info });\n this._persistentLifecycle.open().catch((err) => {\n log.warn('Error while opening connection', { err });\n });\n }\n\n /**\n * Close connection and free resources.\n */\n protected override async _close() {\n log('closing...', { peerKey: this._identity.peerKey });\n await this._persistentLifecycle.close();\n }\n\n private async _openWebSocket() {\n let protocolHeader: string | undefined;\n\n if (!DISABLE_AUTH) {\n // TODO(dmaretskyi): Get challenge from the WWW-Authenticate header returned by the endpoint.\n const challenge = randomBytes(32);\n const credential = await this._identity.presentCredentials({ challenge });\n protocolHeader = encodePresentationIntoAuthHeader(credential);\n }\n\n const url = new URL(`/ws/${this._identity.identityKey}/${this._identity.peerKey}`, this._config.socketEndpoint);\n log('Opening websocket', { url: url.toString(), protocolHeader });\n this._ws = new WebSocket(url, protocolHeader ? [protocolHeader] : []);\n\n this._ws.onopen = () => {\n log('opened', this.info);\n this._ready.wake();\n this.connected.emit();\n };\n this._ws.onclose = () => {\n log('closed', this.info);\n this._persistentLifecycle.scheduleRestart();\n };\n this._ws.onerror = (event) => {\n log.warn('EdgeClient socket error', { error: event.error, info: event.message });\n this._persistentLifecycle.scheduleRestart();\n };\n /**\n * https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent/data\n */\n this._ws.onmessage = async (event) => {\n if (event.data === '__pong__') {\n this._onHeartbeat();\n return;\n }\n const data = await toUint8Array(event.data);\n const message = buf.fromBinary(MessageSchema, data);\n log('received', { peerKey: this._identity.peerKey, payload: protocol.getPayloadType(message) });\n if (message) {\n for (const listener of this._listeners) {\n try {\n await listener(message);\n } catch (err) {\n log.error('processing', { err, payload: protocol.getPayloadType(message) });\n }\n }\n }\n };\n\n // TODO(dmaretskyi): Potential race condition here since web socket errors don't resolve this trigger.\n await this._ready.wait({ timeout: this._config.timeout ?? DEFAULT_TIMEOUT });\n\n // TODO(dmaretskyi): Potential leak: context re-assigned without disposing the previous one.\n this._keepaliveCtx = new Context();\n scheduleTaskInterval(\n this._keepaliveCtx,\n async () => {\n // TODO(mykola): use RFC6455 ping/pong once implemented in the browser?\n // Cloudflare's worker responds to this `without interrupting hibernation`. https://developers.cloudflare.com/durable-objects/api/websockets/#setwebsocketautoresponse\n this._ws?.send('__ping__');\n },\n SIGNAL_KEEPALIVE_INTERVAL,\n );\n this._ws.send('__ping__');\n this._onHeartbeat();\n }\n\n private async _closeWebSocket() {\n if (!this._ws) {\n return;\n }\n try {\n this._ready.throw(this.isOpen ? new EdgeIdentityChangedError() : new EdgeConnectionClosedError());\n this._ready.reset();\n void this._keepaliveCtx?.dispose();\n this._keepaliveCtx = undefined;\n void this._heartBeatContext?.dispose();\n this._heartBeatContext = undefined;\n\n // NOTE: Remove event handlers to avoid scheduling restart.\n this._ws.onopen = () => {};\n this._ws.onclose = () => {};\n this._ws.onerror = () => {};\n this._ws.close();\n this._ws = undefined;\n } catch (err) {\n if (err instanceof Error && err.message.includes('WebSocket is closed before the connection is established.')) {\n return;\n }\n log.warn('Error closing websocket', { err });\n }\n }\n\n /**\n * Send message.\n * NOTE: The message is guaranteed to be delivered but the service must respond with a message to confirm processing.\n */\n public async send(message: Message): Promise<void> {\n if (this._ready.state !== TriggerState.RESOLVED) {\n log('waiting for websocket to become ready');\n await this._ready.wait({ timeout: this._config.timeout ?? DEFAULT_TIMEOUT });\n }\n if (!this._ws) {\n throw new EdgeConnectionClosedError();\n }\n if (\n message.source &&\n (message.source.peerKey !== this._identity.peerKey || message.source.identityKey !== this.identityKey)\n ) {\n throw new EdgeIdentityChangedError();\n }\n\n log('sending...', { peerKey: this._identity.peerKey, payload: protocol.getPayloadType(message) });\n this._ws.send(buf.toBinary(MessageSchema, message));\n }\n\n private _onHeartbeat() {\n if (this._lifecycleState !== LifecycleState.OPEN) {\n return;\n }\n void this._heartBeatContext?.dispose();\n this._heartBeatContext = new Context();\n scheduleTask(\n this._heartBeatContext,\n () => {\n this._persistentLifecycle.scheduleRestart();\n },\n 2 * SIGNAL_KEEPALIVE_INTERVAL,\n );\n }\n}\n\nconst encodePresentationIntoAuthHeader = (presentation: Presentation): string => {\n const encoded = schema.getCodecForType('dxos.halo.credentials.Presentation').encode(presentation);\n // = and / characters are not allowed in the WebSocket subprotocol header.\n const encodedToken = Buffer.from(encoded).toString('base64').replace(/=*$/, '').replaceAll('/', '|');\n\n return `base64url.bearer.authorization.dxos.org.${encodedToken}`;\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nexport class EdgeConnectionClosedError extends Error {\n constructor() {\n super('Edge connection closed.');\n }\n}\n\nexport class EdgeIdentityChangedError extends Error {\n constructor() {\n super('Edge identity changed.');\n }\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { DeferredTask, sleep, synchronized } from '@dxos/async';\nimport { cancelWithContext, LifecycleState, Resource } from '@dxos/context';\nimport { warnAfterTimeout } from '@dxos/debug';\nimport { log } from '@dxos/log';\n\nconst INIT_RESTART_DELAY = 100;\nconst DEFAULT_MAX_RESTART_DELAY = 5000;\n\nexport type PersistentLifecycleParams = {\n /**\n * Create connection.\n * If promise resolves successfully, connection is considered established.\n */\n start: () => Promise<void>;\n\n /**\n * Reset connection to initial state.\n */\n stop: () => Promise<void>;\n\n /**\n * Called after successful start.\n */\n onRestart?: () => Promise<void>;\n\n /**\n * Maximum delay between restartion attempts.\n * Default: 5000ms\n */\n maxRestartDelay?: number;\n};\n\n/**\n * Handles restarts (e.g. persists connection).\n * Restarts are scheduled with exponential backoff.\n */\nexport class PersistentLifecycle extends Resource {\n private readonly _start: () => Promise<void>;\n private readonly _stop: () => Promise<void>;\n private readonly _onRestart?: () => Promise<void>;\n private readonly _maxRestartDelay: number;\n\n private _restartTask?: DeferredTask = undefined;\n private _restartAfter = 0;\n\n constructor({ start, stop, onRestart, maxRestartDelay = DEFAULT_MAX_RESTART_DELAY }: PersistentLifecycleParams) {\n super();\n this._start = start;\n this._stop = stop;\n this._onRestart = onRestart;\n this._maxRestartDelay = maxRestartDelay;\n }\n\n @synchronized\n protected override async _open() {\n this._restartTask = new DeferredTask(this._ctx, async () => {\n try {\n await this._restart();\n } catch (err) {\n log.warn('Restart failed', { err });\n this._restartTask?.schedule();\n }\n });\n await this._start().catch((err) => {\n log.warn('Start failed', { err });\n this._restartTask?.schedule();\n });\n }\n\n protected override async _close() {\n await this._restartTask?.join();\n await this._stop();\n this._restartTask = undefined;\n }\n\n private async _restart() {\n log(`restarting in ${this._restartAfter}ms`, { state: this._lifecycleState });\n await this._stop();\n if (this._lifecycleState !== LifecycleState.OPEN) {\n return;\n }\n await cancelWithContext(this._ctx!, sleep(this._restartAfter));\n this._restartAfter = Math.min(Math.max(this._restartAfter * 2, INIT_RESTART_DELAY), this._maxRestartDelay);\n\n // May fail if the connection is not established.\n await warnAfterTimeout(5_000, 'Connection establishment takes too long', () => this._start());\n\n this._restartAfter = 0;\n await this._onRestart?.();\n }\n\n /**\n * Scheduling restart should be done from outside.\n */\n @synchronized\n scheduleRestart() {\n if (this._lifecycleState !== LifecycleState.OPEN) {\n return;\n }\n this._restartTask!.schedule();\n }\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { createCredential, signPresentation } from '@dxos/credentials';\nimport { type Signer } from '@dxos/crypto';\nimport { Keyring } from '@dxos/keyring';\nimport { PublicKey } from '@dxos/keys';\nimport { type Chain, type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';\n\nimport type { EdgeIdentity } from './edge-client';\n\n/**\n * Edge identity backed by a device key without a credential chain.\n */\nexport const createDeviceEdgeIdentity = async (signer: Signer, key: PublicKey): Promise<EdgeIdentity> => {\n return {\n identityKey: key.toHex(),\n peerKey: key.toHex(),\n presentCredentials: async ({ challenge }) => {\n return signPresentation({\n presentation: {\n credentials: [\n // Verifier requires at least one credential in the presentation to establish the subject.\n await createCredential({\n assertion: {\n '@type': 'dxos.halo.credentials.Auth',\n },\n issuer: key,\n subject: key,\n signer,\n }),\n ],\n },\n signer,\n signerKey: key,\n nonce: challenge,\n });\n },\n };\n};\n\n/**\n * Edge identity backed by a chain of credentials.\n */\nexport const createChainEdgeIdentity = async (\n signer: Signer,\n identityKey: PublicKey,\n peerKey: PublicKey,\n chain: Chain,\n credentials: Credential[],\n): Promise<EdgeIdentity> => {\n const credentialsToSign =\n credentials.length > 0\n ? credentials\n : [\n await createCredential({\n assertion: {\n '@type': 'dxos.halo.credentials.Auth',\n },\n issuer: identityKey,\n subject: identityKey,\n signer,\n chain,\n signingKey: peerKey,\n }),\n ];\n\n return {\n identityKey: identityKey.toHex(),\n peerKey: peerKey.toHex(),\n presentCredentials: async ({ challenge }) => {\n return signPresentation({\n presentation: {\n credentials: credentialsToSign,\n },\n signer,\n nonce: challenge,\n signerKey: peerKey,\n chain,\n });\n },\n };\n};\n\n/**\n * Edge identity backed by a random ephemeral key without HALO.\n */\nexport const createEphemeralEdgeIdentity = async (): Promise<EdgeIdentity> => {\n const keyring = new Keyring();\n const key = await keyring.createKey();\n return createDeviceEdgeIdentity(keyring, key);\n};\n\n/**\n * Creates a HALO chain of credentials to act as an edge identity.\n */\nexport const createTestHaloEdgeIdentity = async (\n signer: Signer,\n identityKey: PublicKey,\n deviceKey: PublicKey,\n): Promise<EdgeIdentity> => {\n const deviceAdmission = await createCredential({\n assertion: {\n '@type': 'dxos.halo.credentials.AuthorizedDevice',\n deviceKey,\n identityKey,\n },\n issuer: identityKey,\n subject: deviceKey,\n signer,\n });\n return createChainEdgeIdentity(signer, identityKey, deviceKey, { credential: deviceAdmission }, [\n await createCredential({\n assertion: {\n '@type': 'dxos.halo.credentials.Auth',\n },\n issuer: identityKey,\n subject: identityKey,\n signer,\n }),\n ]);\n};\n\nexport const createStubEdgeIdentity = (): EdgeIdentity => {\n const identityKey = PublicKey.random();\n const deviceKey = PublicKey.random();\n return {\n identityKey: identityKey.toHex(),\n peerKey: deviceKey.toHex(),\n presentCredentials: async () => {\n throw new Error('Stub identity does not support authentication.');\n },\n };\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { sleep } from '@dxos/async';\nimport { Context } from '@dxos/context';\nimport { type SpaceId } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport {\n EdgeCallFailedError,\n type EdgeHttpResponse,\n type GetNotarizationResponseBody,\n type PostNotarizationRequestBody,\n} from '@dxos/protocols';\n\nconst DEFAULT_RETRY_TIMEOUT = 1500;\nconst DEFAULT_RETRY_JITTER = 500;\nconst DEFAULT_MAX_RETRIES_COUNT = 3;\n\nexport class EdgeHttpClient {\n private readonly _baseUrl: string;\n\n constructor(baseUrl: string) {\n const url = new URL(baseUrl);\n url.protocol = 'https';\n this._baseUrl = url.toString();\n log('created', { url: this._baseUrl });\n }\n\n public getCredentialsForNotarization(spaceId: SpaceId, args?: EdgeHttpGetArgs): Promise<GetNotarizationResponseBody> {\n return this._call(`/spaces/${spaceId}/notarization`, { ...args, method: 'GET' });\n }\n\n public async notarizeCredentials(\n spaceId: SpaceId,\n body: PostNotarizationRequestBody,\n args?: EdgeHttpGetArgs,\n ): Promise<void> {\n await this._call(`/spaces/${spaceId}/notarization`, { ...args, body, method: 'POST' });\n }\n\n private async _call<T>(path: string, args: EdgeHttpCallArgs): Promise<T> {\n const requestContext = args.context ?? new Context();\n const shouldRetry = createRetryHandler(args);\n const request = createRequest(args);\n const url = `${this._baseUrl}${path.startsWith('/') ? path.slice(1) : path}`;\n\n log.info('call', { method: args.method, path });\n\n while (true) {\n let processingError: EdgeCallFailedError;\n let retryAfterHeaderValue: number = Number.NaN;\n try {\n const response = await fetch(url, request);\n\n retryAfterHeaderValue = Number(response.headers.get('Retry-After'));\n\n if (response.ok) {\n const body = (await response.json()) as EdgeHttpResponse<T>;\n if (body.success) {\n return body.data;\n }\n\n const isNonRetryable = body.errorData != null;\n if (isNonRetryable) {\n throw new EdgeCallFailedError(body.reason, body.errorData);\n }\n\n processingError = new EdgeCallFailedError(body.reason);\n } else {\n processingError = EdgeCallFailedError.fromFailureResponse(response);\n if (!isRetryable(response.status)) {\n throw processingError;\n }\n }\n } catch (error: any) {\n processingError = EdgeCallFailedError.fromProcessingFailureCause(error);\n }\n\n if (await shouldRetry(requestContext, retryAfterHeaderValue)) {\n log.info('retrying edge request', { path, processingError });\n } else {\n throw processingError;\n }\n }\n }\n}\n\nconst createRequest = (args: EdgeHttpCallArgs): RequestInit => {\n return {\n method: args.method,\n body: args.body && JSON.stringify(args.body),\n };\n};\n\nconst isRetryable = (status: number) => {\n if (status === 501) {\n // Not Implemented\n return false;\n }\n // TODO: handle 401 Not Authorized\n return !(status >= 400 && status < 500);\n};\n\nconst createRetryHandler = (args: EdgeHttpCallArgs) => {\n if (!args.retry || args.retry.count < 1) {\n return async () => false;\n }\n let retries = 0;\n const maxRetries = args.retry.count ?? DEFAULT_MAX_RETRIES_COUNT;\n const baseTimeout = args.retry.timeout ?? DEFAULT_RETRY_TIMEOUT;\n const jitter = args.retry.jitter ?? DEFAULT_RETRY_JITTER;\n return async (ctx: Context, retryAfter: number) => {\n if (++retries > maxRetries || ctx.disposed) {\n return false;\n }\n\n if (retryAfter) {\n await sleep(retryAfter);\n } else {\n const timeout = baseTimeout + Math.random() * jitter;\n await sleep(timeout);\n }\n\n return true;\n };\n};\n\nexport type RetryConfig = {\n /**\n * A number of call retries, not counting the initial request.\n */\n count: number;\n /**\n * Delay before retries in ms.\n */\n timeout?: number;\n /**\n * A random amount of time before retrying to help prevent large bursts of requests.\n */\n jitter?: number;\n};\n\nexport type EdgeHttpGetArgs = { context?: Context; retry?: RetryConfig };\n\nexport type EdgeHttpPostArgs = { context?: Context; body?: any; retry?: RetryConfig };\n\ntype EdgeHttpCallArgs = {\n method: string;\n body?: any;\n context?: Context;\n retry?: RetryConfig;\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;AAIA,cAAc;;;ACAd,OAAOA,eAAe;AAEtB,SAASC,SAASC,OAAOC,sBAAsBC,cAAcC,oBAAoB;AACjF,SAASC,SAASC,kBAAAA,iBAAgBC,YAAAA,iBAAgC;AAClE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OAAAA;IACd;AAEA,WAAO;EACT;AACF;",
|
|
6
|
+
"names": ["WebSocket", "Trigger", "Event", "scheduleTaskInterval", "scheduleTask", "TriggerState", "Context", "LifecycleState", "Resource", "randomBytes", "log", "buf", "MessageSchema", "schema", "EdgeConnectionClosedError", "Error", "constructor", "EdgeIdentityChangedError", "DeferredTask", "sleep", "synchronized", "cancelWithContext", "LifecycleState", "Resource", "warnAfterTimeout", "log", "INIT_RESTART_DELAY", "DEFAULT_MAX_RESTART_DELAY", "PersistentLifecycle", "constructor", "start", "stop", "onRestart", "maxRestartDelay", "_restartTask", "undefined", "_restartAfter", "_start", "_stop", "_onRestart", "_maxRestartDelay", "_open", "_ctx", "_restart", "err", "warn", "schedule", "catch", "_close", "join", "state", "_lifecycleState", "OPEN", "Math", "min", "max", "scheduleRestart", "DEFAULT_TIMEOUT", "SIGNAL_KEEPALIVE_INTERVAL", "DISABLE_AUTH", "EdgeClient", "Resource", "constructor", "_identity", "_config", "reconnect", "Event", "connected", "_persistentLifecycle", "PersistentLifecycle", "start", "_openWebSocket", "stop", "_closeWebSocket", "onRestart", "emit", "_listeners", "Set", "_ready", "Trigger", "_ws", "undefined", "_keepaliveCtx", "_heartBeatContext", "info", "open", "isOpen", "identity", "identityKey", "device", "peerKey", "isConnected", "Boolean", "state", "TriggerState", "RESOLVED", "setIdentity", "scheduleRestart", "addListener", "listener", "add", "delete", "_open", "log", "catch", "err", "warn", "_close", "close", "protocolHeader", "challenge", "randomBytes", "credential", "presentCredentials", "encodePresentationIntoAuthHeader", "url", "URL", "socketEndpoint", "toString", "WebSocket", "onopen", "wake", "onclose", "onerror", "event", "error", "message", "onmessage", "data", "_onHeartbeat", "toUint8Array", "buf", "fromBinary", "MessageSchema", "payload", "protocol", "getPayloadType", "wait", "timeout", "Context", "scheduleTaskInterval", "send", "throw", "EdgeIdentityChangedError", "EdgeConnectionClosedError", "reset", "dispose", "Error", "includes", "source", "toBinary", "_lifecycleState", "LifecycleState", "OPEN", "scheduleTask", "presentation", "encoded", "schema", "getCodecForType", "encode", "encodedToken", "Buffer", "from", "replace", "replaceAll", "createCredential", "signPresentation", "Keyring", "PublicKey", "createDeviceEdgeIdentity", "signer", "key", "identityKey", "toHex", "peerKey", "presentCredentials", "challenge", "signPresentation", "presentation", "credentials", "createCredential", "assertion", "issuer", "subject", "signerKey", "nonce", "createChainEdgeIdentity", "chain", "credentialsToSign", "length", "signingKey", "createEphemeralEdgeIdentity", "keyring", "Keyring", "createKey", "createTestHaloEdgeIdentity", "deviceKey", "deviceAdmission", "credential", "createStubEdgeIdentity", "PublicKey", "random", "Error", "sleep", "Context", "log", "EdgeCallFailedError", "DEFAULT_RETRY_TIMEOUT", "DEFAULT_RETRY_JITTER", "DEFAULT_MAX_RETRIES_COUNT", "EdgeHttpClient", "constructor", "baseUrl", "url", "URL", "protocol", "_baseUrl", "toString", "getCredentialsForNotarization", "spaceId", "args", "_call", "method", "notarizeCredentials", "body", "path", "requestContext", "context", "shouldRetry", "createRetryHandler", "request", "createRequest", "startsWith", "slice", "info", "processingError", "retryAfterHeaderValue", "Number", "NaN", "response", "fetch", "headers", "get", "ok", "json", "success", "data", "isNonRetryable", "errorData", "reason", "fromFailureResponse", "isRetryable", "status", "error", "fromProcessingFailureCause", "JSON", "stringify", "retry", "count", "retries", "maxRetries", "baseTimeout", "timeout", "jitter", "ctx", "retryAfter", "disposed", "Math", "random"]
|
|
7
7
|
}
|