@dxos/client-services 0.5.1-main.c37e119 → 0.5.1-main.c4f37e4
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/{chunk-RQIV4DQ6.mjs → chunk-NSJ3IC2K.mjs} +1383 -1006
- package/dist/lib/browser/chunk-NSJ3IC2K.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +31 -2
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/packlets/testing/index.mjs +29 -9
- package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
- package/dist/lib/node/{chunk-ND5EXSJK.cjs → chunk-RRKPYRVS.cjs} +1576 -1207
- package/dist/lib/node/chunk-RRKPYRVS.cjs.map +7 -0
- package/dist/lib/node/index.cjs +73 -44
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/packlets/testing/index.cjs +35 -15
- package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
- package/dist/types/src/packlets/diagnostics/diagnostics-collector.d.ts.map +1 -1
- package/dist/types/src/packlets/diagnostics/diagnostics.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts +2 -1
- package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitation-guest-extenstion.d.ts +39 -0
- package/dist/types/src/packlets/invitations/invitation-guest-extenstion.d.ts.map +1 -0
- package/dist/types/src/packlets/invitations/{invitation-extension.d.ts → invitation-host-extension.d.ts} +17 -31
- package/dist/types/src/packlets/invitations/invitation-host-extension.d.ts.map +1 -0
- package/dist/types/src/packlets/invitations/invitation-protocol.d.ts +6 -1
- package/dist/types/src/packlets/invitations/invitation-protocol.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitation-topology.d.ts +37 -0
- package/dist/types/src/packlets/invitations/invitation-topology.d.ts.map +1 -0
- package/dist/types/src/packlets/invitations/invitations-handler.d.ts +19 -10
- package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitations-handler.test.d.ts +2 -0
- package/dist/types/src/packlets/invitations/invitations-handler.test.d.ts.map +1 -0
- package/dist/types/src/packlets/invitations/invitations-manager.d.ts +2 -1
- package/dist/types/src/packlets/invitations/invitations-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts +1 -0
- package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/utils.d.ts +6 -0
- package/dist/types/src/packlets/invitations/utils.d.ts.map +1 -0
- package/dist/types/src/packlets/services/service-context.d.ts +8 -5
- package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-host.d.ts +1 -1
- package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/spaces-service.d.ts +2 -1
- package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
- package/dist/types/src/packlets/storage/level.d.ts +1 -2
- package/dist/types/src/packlets/storage/level.d.ts.map +1 -1
- package/dist/types/src/packlets/testing/invitation-utils.d.ts +2 -1
- package/dist/types/src/packlets/testing/invitation-utils.d.ts.map +1 -1
- package/dist/types/src/packlets/testing/test-builder.d.ts +2 -1
- package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
- package/dist/types/src/packlets/vault/shell-runtime.d.ts +10 -2
- package/dist/types/src/packlets/vault/shell-runtime.d.ts.map +1 -1
- package/dist/types/src/version.d.ts +1 -1
- package/package.json +36 -35
- package/src/packlets/diagnostics/diagnostics-collector.ts +14 -9
- package/src/packlets/diagnostics/diagnostics.ts +78 -68
- package/src/packlets/invitations/device-invitation-protocol.ts +5 -1
- package/src/packlets/invitations/invitation-guest-extenstion.ts +126 -0
- package/src/packlets/invitations/{invitation-extension.ts → invitation-host-extension.ts} +99 -105
- package/src/packlets/invitations/invitation-protocol.ts +7 -1
- package/src/packlets/invitations/invitation-topology.ts +87 -0
- package/src/packlets/invitations/invitations-handler.test.ts +361 -0
- package/src/packlets/invitations/invitations-handler.ts +246 -149
- package/src/packlets/invitations/invitations-manager.ts +45 -3
- package/src/packlets/invitations/space-invitation-protocol.ts +23 -3
- package/src/packlets/invitations/utils.ts +27 -0
- package/src/packlets/services/automerge-host.test.ts +3 -1
- package/src/packlets/services/service-context.ts +7 -6
- package/src/packlets/services/service-host.ts +7 -8
- package/src/packlets/spaces/data-space.ts +4 -2
- package/src/packlets/spaces/genesis.ts +1 -1
- package/src/packlets/spaces/spaces-service.ts +12 -6
- package/src/packlets/storage/level.ts +2 -2
- package/src/packlets/testing/invitation-utils.ts +23 -3
- package/src/packlets/testing/test-builder.ts +6 -3
- package/src/packlets/vault/shell-runtime.ts +40 -2
- package/src/version.ts +1 -1
- package/dist/lib/browser/chunk-RQIV4DQ6.mjs.map +0 -7
- package/dist/lib/node/chunk-ND5EXSJK.cjs.map +0 -7
- package/dist/types/src/packlets/invitations/invitation-extension.d.ts.map +0 -1
|
@@ -1196,13 +1196,16 @@ var DeviceInvitationProtocol = class {
|
|
|
1196
1196
|
kind: Invitation.Kind.DEVICE
|
|
1197
1197
|
};
|
|
1198
1198
|
}
|
|
1199
|
-
async delegate(
|
|
1199
|
+
async delegate() {
|
|
1200
|
+
throw new Error("delegation not supported");
|
|
1201
|
+
}
|
|
1202
|
+
async cancelDelegation() {
|
|
1200
1203
|
throw new Error("delegation not supported");
|
|
1201
1204
|
}
|
|
1202
1205
|
async admit(_, request) {
|
|
1203
1206
|
invariant4(request.device, void 0, {
|
|
1204
1207
|
F: __dxlog_file5,
|
|
1205
|
-
L:
|
|
1208
|
+
L: 46,
|
|
1206
1209
|
S: this,
|
|
1207
1210
|
A: [
|
|
1208
1211
|
"request.device",
|
|
@@ -1248,7 +1251,7 @@ var DeviceInvitationProtocol = class {
|
|
|
1248
1251
|
async accept(response, request) {
|
|
1249
1252
|
invariant4(response.device, void 0, {
|
|
1250
1253
|
F: __dxlog_file5,
|
|
1251
|
-
L:
|
|
1254
|
+
L: 91,
|
|
1252
1255
|
S: this,
|
|
1253
1256
|
A: [
|
|
1254
1257
|
"response.device",
|
|
@@ -1258,7 +1261,7 @@ var DeviceInvitationProtocol = class {
|
|
|
1258
1261
|
const { identityKey, haloSpaceKey, genesisFeedKey, controlTimeframe } = response.device;
|
|
1259
1262
|
invariant4(request.device, void 0, {
|
|
1260
1263
|
F: __dxlog_file5,
|
|
1261
|
-
L:
|
|
1264
|
+
L: 94,
|
|
1262
1265
|
S: this,
|
|
1263
1266
|
A: [
|
|
1264
1267
|
"request.device",
|
|
@@ -1283,34 +1286,53 @@ var DeviceInvitationProtocol = class {
|
|
|
1283
1286
|
};
|
|
1284
1287
|
|
|
1285
1288
|
// packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
|
|
1286
|
-
import {
|
|
1287
|
-
import {
|
|
1288
|
-
import {
|
|
1289
|
+
import { Mutex, scheduleTask as scheduleTask3, TimeoutError } from "@dxos/async";
|
|
1290
|
+
import { INVITATION_TIMEOUT } from "@dxos/client-protocol";
|
|
1291
|
+
import { ContextDisposedError as ContextDisposedError2 } from "@dxos/context";
|
|
1289
1292
|
import { createKeyPair, sign } from "@dxos/crypto";
|
|
1290
|
-
import { invariant as
|
|
1291
|
-
import { PublicKey as
|
|
1292
|
-
import { log as
|
|
1293
|
-
import { createTeleportProtocolFactory
|
|
1294
|
-
import { InvalidInvitationExtensionRoleError as
|
|
1295
|
-
import { Invitation as
|
|
1293
|
+
import { invariant as invariant8 } from "@dxos/invariant";
|
|
1294
|
+
import { PublicKey as PublicKey7 } from "@dxos/keys";
|
|
1295
|
+
import { log as log7 } from "@dxos/log";
|
|
1296
|
+
import { createTeleportProtocolFactory } from "@dxos/network-manager";
|
|
1297
|
+
import { InvalidInvitationExtensionRoleError as InvalidInvitationExtensionRoleError3, trace as trace4 } from "@dxos/protocols";
|
|
1298
|
+
import { Invitation as Invitation4 } from "@dxos/protocols/proto/dxos/client/services";
|
|
1296
1299
|
import { AuthenticationResponse as AuthenticationResponse2 } from "@dxos/protocols/proto/dxos/halo/invitations";
|
|
1300
|
+
import { Options as Options4 } from "@dxos/protocols/proto/dxos/halo/invitations";
|
|
1301
|
+
import { ComplexSet as ComplexSet3 } from "@dxos/util";
|
|
1297
1302
|
|
|
1298
|
-
// packages/sdk/client-services/src/packlets/invitations/invitation-
|
|
1303
|
+
// packages/sdk/client-services/src/packlets/invitations/invitation-guest-extenstion.ts
|
|
1299
1304
|
import { Trigger as Trigger2 } from "@dxos/async";
|
|
1300
|
-
import { cancelWithContext, Context as Context4 } from "@dxos/context";
|
|
1301
|
-
import { randomBytes, verify } from "@dxos/crypto";
|
|
1305
|
+
import { cancelWithContext as cancelWithContext2, Context as Context4 } from "@dxos/context";
|
|
1302
1306
|
import { invariant as invariant5 } from "@dxos/invariant";
|
|
1303
|
-
import { PublicKey as PublicKey5 } from "@dxos/keys";
|
|
1304
1307
|
import { log as log4 } from "@dxos/log";
|
|
1305
|
-
import { InvalidInvitationExtensionRoleError, schema as schema2
|
|
1306
|
-
import {
|
|
1307
|
-
import { AuthenticationResponse, Options } from "@dxos/protocols/proto/dxos/halo/invitations";
|
|
1308
|
+
import { InvalidInvitationExtensionRoleError, schema as schema2 } from "@dxos/protocols";
|
|
1309
|
+
import { Options } from "@dxos/protocols/proto/dxos/halo/invitations";
|
|
1308
1310
|
import { RpcExtension } from "@dxos/teleport";
|
|
1309
|
-
|
|
1311
|
+
|
|
1312
|
+
// packages/sdk/client-services/src/packlets/invitations/utils.ts
|
|
1313
|
+
import { cancelWithContext, ContextDisposedError } from "@dxos/context";
|
|
1314
|
+
import { Invitation as Invitation2 } from "@dxos/protocols/proto/dxos/client/services";
|
|
1315
|
+
var stateToString = (state) => {
|
|
1316
|
+
return Object.entries(Invitation2.State).find(([key, val]) => val === state)?.[0] ?? "unknown";
|
|
1317
|
+
};
|
|
1318
|
+
var tryAcquireBeforeContextDisposed = async (ctx, mutex) => {
|
|
1319
|
+
let guard;
|
|
1320
|
+
return cancelWithContext(ctx, (async () => {
|
|
1321
|
+
guard = await mutex.acquire();
|
|
1322
|
+
if (ctx.disposed) {
|
|
1323
|
+
guard.release();
|
|
1324
|
+
guard = void 0;
|
|
1325
|
+
throw new ContextDisposedError();
|
|
1326
|
+
}
|
|
1327
|
+
return guard;
|
|
1328
|
+
})());
|
|
1329
|
+
};
|
|
1330
|
+
|
|
1331
|
+
// packages/sdk/client-services/src/packlets/invitations/invitation-guest-extenstion.ts
|
|
1332
|
+
var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-guest-extenstion.ts";
|
|
1310
1333
|
var OPTIONS_TIMEOUT = 1e4;
|
|
1311
|
-
var
|
|
1312
|
-
|
|
1313
|
-
constructor(_callbacks) {
|
|
1334
|
+
var InvitationGuestExtension = class extends RpcExtension {
|
|
1335
|
+
constructor(_invitationFlowMutex, _callbacks) {
|
|
1314
1336
|
super({
|
|
1315
1337
|
requested: {
|
|
1316
1338
|
InvitationHostService: schema2.getService("dxos.halo.invitations.InvitationHostService")
|
|
@@ -1319,15 +1341,152 @@ var InvitationHostExtension = class extends RpcExtension {
|
|
|
1319
1341
|
InvitationHostService: schema2.getService("dxos.halo.invitations.InvitationHostService")
|
|
1320
1342
|
}
|
|
1321
1343
|
});
|
|
1344
|
+
this._invitationFlowMutex = _invitationFlowMutex;
|
|
1322
1345
|
this._callbacks = _callbacks;
|
|
1323
1346
|
this._ctx = new Context4();
|
|
1324
1347
|
this._remoteOptionsTrigger = new Trigger2();
|
|
1348
|
+
this._invitationFlowLock = null;
|
|
1349
|
+
}
|
|
1350
|
+
hasFlowLock() {
|
|
1351
|
+
return this._invitationFlowLock != null;
|
|
1352
|
+
}
|
|
1353
|
+
async getHandlers() {
|
|
1354
|
+
return {
|
|
1355
|
+
InvitationHostService: {
|
|
1356
|
+
options: async (options) => {
|
|
1357
|
+
invariant5(!this._remoteOptions, "Remote options already set.", {
|
|
1358
|
+
F: __dxlog_file6,
|
|
1359
|
+
L: 63,
|
|
1360
|
+
S: this,
|
|
1361
|
+
A: [
|
|
1362
|
+
"!this._remoteOptions",
|
|
1363
|
+
"'Remote options already set.'"
|
|
1364
|
+
]
|
|
1365
|
+
});
|
|
1366
|
+
this._remoteOptions = options;
|
|
1367
|
+
this._remoteOptionsTrigger.wake();
|
|
1368
|
+
},
|
|
1369
|
+
introduce: () => {
|
|
1370
|
+
throw new Error("Method not allowed.");
|
|
1371
|
+
},
|
|
1372
|
+
authenticate: () => {
|
|
1373
|
+
throw new Error("Method not allowed.");
|
|
1374
|
+
},
|
|
1375
|
+
admit: () => {
|
|
1376
|
+
throw new Error("Method not allowed.");
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
};
|
|
1380
|
+
}
|
|
1381
|
+
async onOpen(context) {
|
|
1382
|
+
await super.onOpen(context);
|
|
1383
|
+
try {
|
|
1384
|
+
log4("guest acquire lock", void 0, {
|
|
1385
|
+
F: __dxlog_file6,
|
|
1386
|
+
L: 84,
|
|
1387
|
+
S: this,
|
|
1388
|
+
C: (f, a) => f(...a)
|
|
1389
|
+
});
|
|
1390
|
+
this._invitationFlowLock = await tryAcquireBeforeContextDisposed(this._ctx, this._invitationFlowMutex);
|
|
1391
|
+
log4("guest lock acquired", void 0, {
|
|
1392
|
+
F: __dxlog_file6,
|
|
1393
|
+
L: 86,
|
|
1394
|
+
S: this,
|
|
1395
|
+
C: (f, a) => f(...a)
|
|
1396
|
+
});
|
|
1397
|
+
await cancelWithContext2(this._ctx, this.rpc.InvitationHostService.options({
|
|
1398
|
+
role: Options.Role.GUEST
|
|
1399
|
+
}));
|
|
1400
|
+
log4("options sent", void 0, {
|
|
1401
|
+
F: __dxlog_file6,
|
|
1402
|
+
L: 88,
|
|
1403
|
+
S: this,
|
|
1404
|
+
C: (f, a) => f(...a)
|
|
1405
|
+
});
|
|
1406
|
+
await cancelWithContext2(this._ctx, this._remoteOptionsTrigger.wait({
|
|
1407
|
+
timeout: OPTIONS_TIMEOUT
|
|
1408
|
+
}));
|
|
1409
|
+
log4("options received", void 0, {
|
|
1410
|
+
F: __dxlog_file6,
|
|
1411
|
+
L: 90,
|
|
1412
|
+
S: this,
|
|
1413
|
+
C: (f, a) => f(...a)
|
|
1414
|
+
});
|
|
1415
|
+
if (this._remoteOptions?.role !== Options.Role.HOST) {
|
|
1416
|
+
throw new InvalidInvitationExtensionRoleError(void 0, {
|
|
1417
|
+
expected: Options.Role.HOST,
|
|
1418
|
+
remoteOptions: this._remoteOptions,
|
|
1419
|
+
remotePeerId: context.remotePeerId
|
|
1420
|
+
});
|
|
1421
|
+
}
|
|
1422
|
+
this._callbacks.onOpen(this._ctx, context);
|
|
1423
|
+
} catch (err) {
|
|
1424
|
+
if (this._invitationFlowLock != null) {
|
|
1425
|
+
this._callbacks.onError(err);
|
|
1426
|
+
}
|
|
1427
|
+
if (!this._ctx.disposed) {
|
|
1428
|
+
context.close(err);
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
async onClose() {
|
|
1433
|
+
await this._destroy();
|
|
1434
|
+
}
|
|
1435
|
+
async onAbort() {
|
|
1436
|
+
await this._destroy();
|
|
1437
|
+
}
|
|
1438
|
+
async _destroy() {
|
|
1439
|
+
await this._ctx.dispose();
|
|
1440
|
+
if (this._invitationFlowLock != null) {
|
|
1441
|
+
this._invitationFlowLock.release();
|
|
1442
|
+
this._invitationFlowLock = null;
|
|
1443
|
+
log4("invitation flow lock released", void 0, {
|
|
1444
|
+
F: __dxlog_file6,
|
|
1445
|
+
L: 123,
|
|
1446
|
+
S: this,
|
|
1447
|
+
C: (f, a) => f(...a)
|
|
1448
|
+
});
|
|
1449
|
+
}
|
|
1450
|
+
}
|
|
1451
|
+
};
|
|
1452
|
+
|
|
1453
|
+
// packages/sdk/client-services/src/packlets/invitations/invitation-host-extension.ts
|
|
1454
|
+
import { Trigger as Trigger3, scheduleTask as scheduleTask2 } from "@dxos/async";
|
|
1455
|
+
import { cancelWithContext as cancelWithContext3, Context as Context5 } from "@dxos/context";
|
|
1456
|
+
import { randomBytes, verify } from "@dxos/crypto";
|
|
1457
|
+
import { invariant as invariant6, InvariantViolation } from "@dxos/invariant";
|
|
1458
|
+
import { PublicKey as PublicKey5 } from "@dxos/keys";
|
|
1459
|
+
import { log as log5 } from "@dxos/log";
|
|
1460
|
+
import { InvalidInvitationExtensionRoleError as InvalidInvitationExtensionRoleError2, schema as schema3, trace as trace3 } from "@dxos/protocols";
|
|
1461
|
+
import { Invitation as Invitation3 } from "@dxos/protocols/proto/dxos/client/services";
|
|
1462
|
+
import { AuthenticationResponse, Options as Options2 } from "@dxos/protocols/proto/dxos/halo/invitations";
|
|
1463
|
+
import { RpcExtension as RpcExtension2 } from "@dxos/teleport";
|
|
1464
|
+
var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-host-extension.ts";
|
|
1465
|
+
var OPTIONS_TIMEOUT2 = 1e4;
|
|
1466
|
+
var MAX_OTP_ATTEMPTS = 3;
|
|
1467
|
+
var InvitationHostExtension = class extends RpcExtension2 {
|
|
1468
|
+
constructor(_invitationFlowMutex, _callbacks) {
|
|
1469
|
+
super({
|
|
1470
|
+
requested: {
|
|
1471
|
+
InvitationHostService: schema3.getService("dxos.halo.invitations.InvitationHostService")
|
|
1472
|
+
},
|
|
1473
|
+
exposed: {
|
|
1474
|
+
InvitationHostService: schema3.getService("dxos.halo.invitations.InvitationHostService")
|
|
1475
|
+
}
|
|
1476
|
+
});
|
|
1477
|
+
this._invitationFlowMutex = _invitationFlowMutex;
|
|
1478
|
+
this._callbacks = _callbacks;
|
|
1479
|
+
this._ctx = new Context5();
|
|
1480
|
+
this._remoteOptionsTrigger = new Trigger3();
|
|
1325
1481
|
this._challenge = void 0;
|
|
1326
|
-
this.invitation = void 0;
|
|
1327
1482
|
this.guestProfile = void 0;
|
|
1328
1483
|
this.authenticationPassed = false;
|
|
1329
1484
|
this.authenticationRetry = 0;
|
|
1330
|
-
this.completedTrigger = new
|
|
1485
|
+
this.completedTrigger = new Trigger3();
|
|
1486
|
+
this._invitationFlowLock = null;
|
|
1487
|
+
}
|
|
1488
|
+
hasFlowLock() {
|
|
1489
|
+
return this._invitationFlowLock != null;
|
|
1331
1490
|
}
|
|
1332
1491
|
async getHandlers() {
|
|
1333
1492
|
return {
|
|
@@ -1335,9 +1494,9 @@ var InvitationHostExtension = class extends RpcExtension {
|
|
|
1335
1494
|
// Perhaps in the future we will have more complex logic here.
|
|
1336
1495
|
InvitationHostService: {
|
|
1337
1496
|
options: async (options) => {
|
|
1338
|
-
|
|
1339
|
-
F:
|
|
1340
|
-
L:
|
|
1497
|
+
invariant6(!this._remoteOptions, "Remote options already set.", {
|
|
1498
|
+
F: __dxlog_file7,
|
|
1499
|
+
L: 101,
|
|
1341
1500
|
S: this,
|
|
1342
1501
|
A: [
|
|
1343
1502
|
"!this._remoteOptions",
|
|
@@ -1350,90 +1509,86 @@ var InvitationHostExtension = class extends RpcExtension {
|
|
|
1350
1509
|
introduce: async (request) => {
|
|
1351
1510
|
const { profile, invitationId } = request;
|
|
1352
1511
|
const traceId = PublicKey5.random().toHex();
|
|
1353
|
-
|
|
1512
|
+
log5.trace("dxos.sdk.invitation-handler.host.introduce", trace3.begin({
|
|
1354
1513
|
id: traceId
|
|
1355
1514
|
}), {
|
|
1356
|
-
F:
|
|
1357
|
-
L:
|
|
1515
|
+
F: __dxlog_file7,
|
|
1516
|
+
L: 110,
|
|
1358
1517
|
S: this,
|
|
1359
1518
|
C: (f, a) => f(...a)
|
|
1360
1519
|
});
|
|
1361
|
-
const invitation =
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1520
|
+
const invitation = this._requireActiveInvitation();
|
|
1521
|
+
this._assertInvitationState(Invitation3.State.CONNECTED);
|
|
1522
|
+
if (invitationId !== invitation?.invitationId) {
|
|
1523
|
+
log5.warn("incorrect invitationId", {
|
|
1524
|
+
expected: invitation.invitationId,
|
|
1525
|
+
actual: invitationId
|
|
1365
1526
|
}, {
|
|
1366
|
-
F:
|
|
1367
|
-
L:
|
|
1527
|
+
F: __dxlog_file7,
|
|
1528
|
+
L: 116,
|
|
1368
1529
|
S: this,
|
|
1369
1530
|
C: (f, a) => f(...a)
|
|
1370
1531
|
});
|
|
1371
|
-
this._callbacks.onError(new Error("
|
|
1532
|
+
this._callbacks.onError(new Error("Incorrect invitationId."));
|
|
1533
|
+
scheduleTask2(this._ctx, () => this.close());
|
|
1372
1534
|
return {
|
|
1373
|
-
authMethod:
|
|
1535
|
+
authMethod: Invitation3.AuthMethod.NONE
|
|
1374
1536
|
};
|
|
1375
1537
|
}
|
|
1376
|
-
|
|
1377
|
-
log4("guest introduced itself", {
|
|
1538
|
+
log5("guest introduced themselves", {
|
|
1378
1539
|
guestProfile: profile
|
|
1379
1540
|
}, {
|
|
1380
|
-
F:
|
|
1381
|
-
L:
|
|
1541
|
+
F: __dxlog_file7,
|
|
1542
|
+
L: 125,
|
|
1382
1543
|
S: this,
|
|
1383
1544
|
C: (f, a) => f(...a)
|
|
1384
1545
|
});
|
|
1385
1546
|
this.guestProfile = profile;
|
|
1386
|
-
this._callbacks.onStateUpdate(
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
});
|
|
1390
|
-
this._challenge = this.invitation.authMethod === Invitation2.AuthMethod.KNOWN_PUBLIC_KEY ? randomBytes(32) : void 0;
|
|
1391
|
-
log4.trace("dxos.sdk.invitation-handler.host.introduce", trace3.end({
|
|
1547
|
+
this._callbacks.onStateUpdate(Invitation3.State.READY_FOR_AUTHENTICATION);
|
|
1548
|
+
this._challenge = invitation.authMethod === Invitation3.AuthMethod.KNOWN_PUBLIC_KEY ? randomBytes(32) : void 0;
|
|
1549
|
+
log5.trace("dxos.sdk.invitation-handler.host.introduce", trace3.end({
|
|
1392
1550
|
id: traceId
|
|
1393
1551
|
}), {
|
|
1394
|
-
F:
|
|
1395
|
-
L:
|
|
1552
|
+
F: __dxlog_file7,
|
|
1553
|
+
L: 132,
|
|
1396
1554
|
S: this,
|
|
1397
1555
|
C: (f, a) => f(...a)
|
|
1398
1556
|
});
|
|
1399
1557
|
return {
|
|
1400
|
-
authMethod:
|
|
1558
|
+
authMethod: invitation.authMethod,
|
|
1401
1559
|
challenge: this._challenge
|
|
1402
1560
|
};
|
|
1403
1561
|
},
|
|
1404
1562
|
authenticate: async ({ authCode: code, signedChallenge }) => {
|
|
1405
1563
|
const traceId = PublicKey5.random().toHex();
|
|
1406
|
-
|
|
1564
|
+
log5.trace("dxos.sdk.invitation-handler.host.authenticate", trace3.begin({
|
|
1407
1565
|
id: traceId
|
|
1408
1566
|
}), {
|
|
1409
|
-
F:
|
|
1410
|
-
L:
|
|
1567
|
+
F: __dxlog_file7,
|
|
1568
|
+
L: 141,
|
|
1411
1569
|
S: this,
|
|
1412
1570
|
C: (f, a) => f(...a)
|
|
1413
1571
|
});
|
|
1414
|
-
|
|
1572
|
+
const invitation = this._requireActiveInvitation();
|
|
1573
|
+
log5("received authentication request", {
|
|
1415
1574
|
authCode: code
|
|
1416
1575
|
}, {
|
|
1417
|
-
F:
|
|
1418
|
-
L:
|
|
1576
|
+
F: __dxlog_file7,
|
|
1577
|
+
L: 144,
|
|
1419
1578
|
S: this,
|
|
1420
1579
|
C: (f, a) => f(...a)
|
|
1421
1580
|
});
|
|
1422
1581
|
let status = AuthenticationResponse.Status.OK;
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
case Invitation2.AuthMethod.NONE: {
|
|
1434
|
-
log4("authentication not required", void 0, {
|
|
1435
|
-
F: __dxlog_file6,
|
|
1436
|
-
L: 138,
|
|
1582
|
+
this._assertInvitationState([
|
|
1583
|
+
Invitation3.State.AUTHENTICATING,
|
|
1584
|
+
Invitation3.State.READY_FOR_AUTHENTICATION
|
|
1585
|
+
]);
|
|
1586
|
+
this._callbacks.onStateUpdate(Invitation3.State.AUTHENTICATING);
|
|
1587
|
+
switch (invitation.authMethod) {
|
|
1588
|
+
case Invitation3.AuthMethod.NONE: {
|
|
1589
|
+
log5("authentication not required", void 0, {
|
|
1590
|
+
F: __dxlog_file7,
|
|
1591
|
+
L: 152,
|
|
1437
1592
|
S: this,
|
|
1438
1593
|
C: (f, a) => f(...a)
|
|
1439
1594
|
});
|
|
@@ -1441,11 +1596,11 @@ var InvitationHostExtension = class extends RpcExtension {
|
|
|
1441
1596
|
status: AuthenticationResponse.Status.OK
|
|
1442
1597
|
};
|
|
1443
1598
|
}
|
|
1444
|
-
case
|
|
1445
|
-
if (
|
|
1599
|
+
case Invitation3.AuthMethod.SHARED_SECRET: {
|
|
1600
|
+
if (invitation.authCode) {
|
|
1446
1601
|
if (this.authenticationRetry++ > MAX_OTP_ATTEMPTS) {
|
|
1447
1602
|
status = AuthenticationResponse.Status.INVALID_OPT_ATTEMPTS;
|
|
1448
|
-
} else if (code !==
|
|
1603
|
+
} else if (code !== invitation.authCode) {
|
|
1449
1604
|
status = AuthenticationResponse.Status.INVALID_OTP;
|
|
1450
1605
|
} else {
|
|
1451
1606
|
this.authenticationPassed = true;
|
|
@@ -1453,12 +1608,12 @@ var InvitationHostExtension = class extends RpcExtension {
|
|
|
1453
1608
|
}
|
|
1454
1609
|
break;
|
|
1455
1610
|
}
|
|
1456
|
-
case
|
|
1457
|
-
if (!
|
|
1611
|
+
case Invitation3.AuthMethod.KNOWN_PUBLIC_KEY: {
|
|
1612
|
+
if (!invitation.guestKeypair) {
|
|
1458
1613
|
status = AuthenticationResponse.Status.INTERNAL_ERROR;
|
|
1459
1614
|
break;
|
|
1460
1615
|
}
|
|
1461
|
-
const isSignatureValid = this._challenge && verify(this._challenge, Buffer.from(signedChallenge ?? []),
|
|
1616
|
+
const isSignatureValid = this._challenge && verify(this._challenge, Buffer.from(signedChallenge ?? []), invitation.guestKeypair.publicKey.asBuffer());
|
|
1462
1617
|
if (isSignatureValid) {
|
|
1463
1618
|
this.authenticationPassed = true;
|
|
1464
1619
|
} else {
|
|
@@ -1467,11 +1622,11 @@ var InvitationHostExtension = class extends RpcExtension {
|
|
|
1467
1622
|
break;
|
|
1468
1623
|
}
|
|
1469
1624
|
default: {
|
|
1470
|
-
|
|
1471
|
-
authMethod:
|
|
1625
|
+
log5.error("invalid authentication method", {
|
|
1626
|
+
authMethod: invitation.authMethod
|
|
1472
1627
|
}, {
|
|
1473
|
-
F:
|
|
1474
|
-
L:
|
|
1628
|
+
F: __dxlog_file7,
|
|
1629
|
+
L: 190,
|
|
1475
1630
|
S: this,
|
|
1476
1631
|
C: (f, a) => f(...a)
|
|
1477
1632
|
});
|
|
@@ -1479,14 +1634,24 @@ var InvitationHostExtension = class extends RpcExtension {
|
|
|
1479
1634
|
break;
|
|
1480
1635
|
}
|
|
1481
1636
|
}
|
|
1482
|
-
|
|
1637
|
+
if (![
|
|
1638
|
+
AuthenticationResponse.Status.OK,
|
|
1639
|
+
AuthenticationResponse.Status.INVALID_OTP
|
|
1640
|
+
].includes(status)) {
|
|
1641
|
+
this._callbacks.onError(new Error(`Authentication failed, with status=${status}`));
|
|
1642
|
+
scheduleTask2(this._ctx, () => this.close());
|
|
1643
|
+
return {
|
|
1644
|
+
status
|
|
1645
|
+
};
|
|
1646
|
+
}
|
|
1647
|
+
log5.trace("dxos.sdk.invitation-handler.host.authenticate", trace3.end({
|
|
1483
1648
|
id: traceId,
|
|
1484
1649
|
data: {
|
|
1485
1650
|
status
|
|
1486
1651
|
}
|
|
1487
1652
|
}), {
|
|
1488
|
-
F:
|
|
1489
|
-
L:
|
|
1653
|
+
F: __dxlog_file7,
|
|
1654
|
+
L: 202,
|
|
1490
1655
|
S: this,
|
|
1491
1656
|
C: (f, a) => f(...a)
|
|
1492
1657
|
});
|
|
@@ -1496,33 +1661,28 @@ var InvitationHostExtension = class extends RpcExtension {
|
|
|
1496
1661
|
},
|
|
1497
1662
|
admit: async (request) => {
|
|
1498
1663
|
const traceId = PublicKey5.random().toHex();
|
|
1499
|
-
|
|
1664
|
+
log5.trace("dxos.sdk.invitation-handler.host.admit", trace3.begin({
|
|
1500
1665
|
id: traceId
|
|
1501
1666
|
}), {
|
|
1502
|
-
F:
|
|
1503
|
-
L:
|
|
1667
|
+
F: __dxlog_file7,
|
|
1668
|
+
L: 208,
|
|
1504
1669
|
S: this,
|
|
1505
1670
|
C: (f, a) => f(...a)
|
|
1506
1671
|
});
|
|
1672
|
+
const invitation = this._requireActiveInvitation();
|
|
1507
1673
|
try {
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
"this.invitation",
|
|
1514
|
-
"'Invitation is not set.'"
|
|
1515
|
-
]
|
|
1516
|
-
});
|
|
1517
|
-
if (isAuthenticationRequired(this.invitation) && !this.authenticationPassed) {
|
|
1518
|
-
throw new Error("Not authenticated");
|
|
1674
|
+
if (isAuthenticationRequired(invitation)) {
|
|
1675
|
+
this._assertInvitationState(Invitation3.State.AUTHENTICATING);
|
|
1676
|
+
if (!this.authenticationPassed) {
|
|
1677
|
+
throw new Error("Not authenticated");
|
|
1678
|
+
}
|
|
1519
1679
|
}
|
|
1520
1680
|
const response = await this._callbacks.admit(request);
|
|
1521
|
-
|
|
1681
|
+
log5.trace("dxos.sdk.invitation-handler.host.admit", trace3.end({
|
|
1522
1682
|
id: traceId
|
|
1523
1683
|
}), {
|
|
1524
|
-
F:
|
|
1525
|
-
L:
|
|
1684
|
+
F: __dxlog_file7,
|
|
1685
|
+
L: 222,
|
|
1526
1686
|
S: this,
|
|
1527
1687
|
C: (f, a) => f(...a)
|
|
1528
1688
|
});
|
|
@@ -1538,149 +1698,204 @@ var InvitationHostExtension = class extends RpcExtension {
|
|
|
1538
1698
|
async onOpen(context) {
|
|
1539
1699
|
await super.onOpen(context);
|
|
1540
1700
|
try {
|
|
1701
|
+
log5("host acquire lock", void 0, {
|
|
1702
|
+
F: __dxlog_file7,
|
|
1703
|
+
L: 237,
|
|
1704
|
+
S: this,
|
|
1705
|
+
C: (f, a) => f(...a)
|
|
1706
|
+
});
|
|
1707
|
+
this._invitationFlowLock = await tryAcquireBeforeContextDisposed(this._ctx, this._invitationFlowMutex);
|
|
1708
|
+
log5("host lock acquired", void 0, {
|
|
1709
|
+
F: __dxlog_file7,
|
|
1710
|
+
L: 239,
|
|
1711
|
+
S: this,
|
|
1712
|
+
C: (f, a) => f(...a)
|
|
1713
|
+
});
|
|
1714
|
+
const lastState = this._requireActiveInvitation().state;
|
|
1715
|
+
this._callbacks.onStateUpdate(Invitation3.State.CONNECTING);
|
|
1541
1716
|
await this.rpc.InvitationHostService.options({
|
|
1542
|
-
role:
|
|
1717
|
+
role: Options2.Role.HOST
|
|
1543
1718
|
});
|
|
1544
|
-
|
|
1545
|
-
|
|
1719
|
+
log5("options sent", void 0, {
|
|
1720
|
+
F: __dxlog_file7,
|
|
1721
|
+
L: 243,
|
|
1722
|
+
S: this,
|
|
1723
|
+
C: (f, a) => f(...a)
|
|
1724
|
+
});
|
|
1725
|
+
await cancelWithContext3(this._ctx, this._remoteOptionsTrigger.wait({
|
|
1726
|
+
timeout: OPTIONS_TIMEOUT2
|
|
1546
1727
|
}));
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1728
|
+
log5("options received", void 0, {
|
|
1729
|
+
F: __dxlog_file7,
|
|
1730
|
+
L: 245,
|
|
1731
|
+
S: this,
|
|
1732
|
+
C: (f, a) => f(...a)
|
|
1733
|
+
});
|
|
1734
|
+
if (this._remoteOptions?.role !== Options2.Role.GUEST) {
|
|
1735
|
+
this._callbacks.onStateUpdate(lastState);
|
|
1736
|
+
throw new InvalidInvitationExtensionRoleError2(void 0, {
|
|
1737
|
+
expected: Options2.Role.GUEST,
|
|
1738
|
+
remoteOptions: this._remoteOptions,
|
|
1739
|
+
remotePeerId: context.remotePeerId
|
|
1551
1740
|
});
|
|
1552
1741
|
}
|
|
1553
|
-
this._callbacks.
|
|
1742
|
+
this._callbacks.onStateUpdate(Invitation3.State.CONNECTED);
|
|
1743
|
+
this._callbacks.onOpen(this._ctx, context);
|
|
1554
1744
|
} catch (err) {
|
|
1555
|
-
this.
|
|
1745
|
+
if (this._invitationFlowLock != null) {
|
|
1746
|
+
this._callbacks.onError(err);
|
|
1747
|
+
}
|
|
1748
|
+
if (!this._ctx.disposed) {
|
|
1749
|
+
context.close(err);
|
|
1750
|
+
}
|
|
1556
1751
|
}
|
|
1557
1752
|
}
|
|
1558
|
-
|
|
1559
|
-
|
|
1753
|
+
_requireActiveInvitation() {
|
|
1754
|
+
const invitation = this._callbacks.activeInvitation;
|
|
1755
|
+
if (invitation == null) {
|
|
1756
|
+
scheduleTask2(this._ctx, () => this.close());
|
|
1757
|
+
throw new Error("Active invitation not found");
|
|
1758
|
+
}
|
|
1759
|
+
return invitation;
|
|
1560
1760
|
}
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
}
|
|
1571
|
-
});
|
|
1572
|
-
this._callbacks = _callbacks;
|
|
1573
|
-
this._ctx = new Context4();
|
|
1574
|
-
this._remoteOptionsTrigger = new Trigger2();
|
|
1761
|
+
_assertInvitationState(stateOrMany) {
|
|
1762
|
+
const invitation = this._requireActiveInvitation();
|
|
1763
|
+
const validStates = Array.isArray(stateOrMany) ? stateOrMany : [
|
|
1764
|
+
stateOrMany
|
|
1765
|
+
];
|
|
1766
|
+
if (!validStates.includes(invitation.state)) {
|
|
1767
|
+
scheduleTask2(this._ctx, () => this.close());
|
|
1768
|
+
throw new InvariantViolation(`Expected ${stateToString(invitation.state)} to be one of [${validStates.map(stateToString).join(", ")}]`);
|
|
1769
|
+
}
|
|
1575
1770
|
}
|
|
1576
|
-
async
|
|
1577
|
-
|
|
1578
|
-
InvitationHostService: {
|
|
1579
|
-
options: async (options) => {
|
|
1580
|
-
invariant5(!this._remoteOptions, "Remote options already set.", {
|
|
1581
|
-
F: __dxlog_file6,
|
|
1582
|
-
L: 266,
|
|
1583
|
-
S: this,
|
|
1584
|
-
A: [
|
|
1585
|
-
"!this._remoteOptions",
|
|
1586
|
-
"'Remote options already set.'"
|
|
1587
|
-
]
|
|
1588
|
-
});
|
|
1589
|
-
this._remoteOptions = options;
|
|
1590
|
-
this._remoteOptionsTrigger.wake();
|
|
1591
|
-
},
|
|
1592
|
-
introduce: () => {
|
|
1593
|
-
throw new Error("Method not allowed.");
|
|
1594
|
-
},
|
|
1595
|
-
authenticate: () => {
|
|
1596
|
-
throw new Error("Method not allowed.");
|
|
1597
|
-
},
|
|
1598
|
-
admit: () => {
|
|
1599
|
-
throw new Error("Method not allowed.");
|
|
1600
|
-
}
|
|
1601
|
-
}
|
|
1602
|
-
};
|
|
1771
|
+
async onClose() {
|
|
1772
|
+
await this._destroy();
|
|
1603
1773
|
}
|
|
1604
|
-
async
|
|
1605
|
-
await
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
}));
|
|
1616
|
-
await cancelWithContext(this._ctx, this._remoteOptionsTrigger.wait({
|
|
1617
|
-
timeout: OPTIONS_TIMEOUT
|
|
1618
|
-
}));
|
|
1619
|
-
log4("end options", void 0, {
|
|
1620
|
-
F: __dxlog_file6,
|
|
1621
|
-
L: 290,
|
|
1774
|
+
async onAbort() {
|
|
1775
|
+
await this._destroy();
|
|
1776
|
+
}
|
|
1777
|
+
async _destroy() {
|
|
1778
|
+
await this._ctx.dispose();
|
|
1779
|
+
if (this._invitationFlowLock != null) {
|
|
1780
|
+
this._invitationFlowLock?.release();
|
|
1781
|
+
this._invitationFlowLock = null;
|
|
1782
|
+
log5("invitation flow lock released", void 0, {
|
|
1783
|
+
F: __dxlog_file7,
|
|
1784
|
+
L: 300,
|
|
1622
1785
|
S: this,
|
|
1623
1786
|
C: (f, a) => f(...a)
|
|
1624
1787
|
});
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1788
|
+
}
|
|
1789
|
+
}
|
|
1790
|
+
};
|
|
1791
|
+
var isAuthenticationRequired = (invitation) => invitation.authMethod !== Invitation3.AuthMethod.NONE;
|
|
1792
|
+
|
|
1793
|
+
// packages/sdk/client-services/src/packlets/invitations/invitation-topology.ts
|
|
1794
|
+
import { invariant as invariant7 } from "@dxos/invariant";
|
|
1795
|
+
import { PublicKey as PublicKey6 } from "@dxos/keys";
|
|
1796
|
+
import { log as log6 } from "@dxos/log";
|
|
1797
|
+
import { Options as Options3 } from "@dxos/protocols/proto/dxos/halo/invitations";
|
|
1798
|
+
import { ComplexSet as ComplexSet2 } from "@dxos/util";
|
|
1799
|
+
var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-topology.ts";
|
|
1800
|
+
var InvitationTopology = class {
|
|
1801
|
+
constructor(_role) {
|
|
1802
|
+
this._role = _role;
|
|
1803
|
+
this._seenPeers = new ComplexSet2(PublicKey6.hash);
|
|
1804
|
+
}
|
|
1805
|
+
init(controller) {
|
|
1806
|
+
invariant7(!this._controller, "Already initialized.", {
|
|
1807
|
+
F: __dxlog_file8,
|
|
1808
|
+
L: 42,
|
|
1809
|
+
S: this,
|
|
1810
|
+
A: [
|
|
1811
|
+
"!this._controller",
|
|
1812
|
+
"'Already initialized.'"
|
|
1813
|
+
]
|
|
1814
|
+
});
|
|
1815
|
+
this._controller = controller;
|
|
1816
|
+
}
|
|
1817
|
+
update() {
|
|
1818
|
+
invariant7(this._controller, "Not initialized.", {
|
|
1819
|
+
F: __dxlog_file8,
|
|
1820
|
+
L: 47,
|
|
1821
|
+
S: this,
|
|
1822
|
+
A: [
|
|
1823
|
+
"this._controller",
|
|
1824
|
+
"'Not initialized.'"
|
|
1825
|
+
]
|
|
1826
|
+
});
|
|
1827
|
+
const { ownPeerId, candidates, connected, allPeers } = this._controller.getState();
|
|
1828
|
+
if (this._role === Options3.Role.GUEST) {
|
|
1829
|
+
return;
|
|
1830
|
+
}
|
|
1831
|
+
if (connected.length > 0) {
|
|
1832
|
+
connected.forEach((c) => this._seenPeers.add(c));
|
|
1833
|
+
return;
|
|
1834
|
+
}
|
|
1835
|
+
const firstUnknownPeer = candidates.find((peerId) => !this._seenPeers.has(peerId));
|
|
1836
|
+
this._seenPeers = new ComplexSet2(PublicKey6.hash, allPeers.filter((peerId) => this._seenPeers.has(peerId)));
|
|
1837
|
+
if (firstUnknownPeer != null) {
|
|
1838
|
+
log6("invitation connect", {
|
|
1839
|
+
ownPeerId,
|
|
1840
|
+
remotePeerId: firstUnknownPeer
|
|
1841
|
+
}, {
|
|
1842
|
+
F: __dxlog_file8,
|
|
1843
|
+
L: 69,
|
|
1636
1844
|
S: this,
|
|
1637
1845
|
C: (f, a) => f(...a)
|
|
1638
1846
|
});
|
|
1639
|
-
this.
|
|
1847
|
+
this._controller.connect(firstUnknownPeer);
|
|
1848
|
+
this._seenPeers.add(firstUnknownPeer);
|
|
1640
1849
|
}
|
|
1641
1850
|
}
|
|
1642
|
-
async
|
|
1643
|
-
|
|
1644
|
-
F:
|
|
1645
|
-
L:
|
|
1851
|
+
async onOffer(peer) {
|
|
1852
|
+
invariant7(this._controller, "Not initialized.", {
|
|
1853
|
+
F: __dxlog_file8,
|
|
1854
|
+
L: 76,
|
|
1646
1855
|
S: this,
|
|
1647
|
-
|
|
1856
|
+
A: [
|
|
1857
|
+
"this._controller",
|
|
1858
|
+
"'Not initialized.'"
|
|
1859
|
+
]
|
|
1648
1860
|
});
|
|
1649
|
-
|
|
1861
|
+
return !this._seenPeers.has(peer);
|
|
1862
|
+
}
|
|
1863
|
+
async destroy() {
|
|
1864
|
+
this._seenPeers.clear();
|
|
1865
|
+
}
|
|
1866
|
+
toString() {
|
|
1867
|
+
return `InvitationTopology(${this._role === Options3.Role.GUEST ? "guest" : "host"})`;
|
|
1650
1868
|
}
|
|
1651
1869
|
};
|
|
1652
|
-
var isAuthenticationRequired = (invitation) => invitation.authMethod !== Invitation2.AuthMethod.NONE;
|
|
1653
1870
|
|
|
1654
1871
|
// packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
|
|
1655
|
-
var
|
|
1872
|
+
var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts";
|
|
1873
|
+
var MAX_DELEGATED_INVITATION_HOST_TRIES = 3;
|
|
1656
1874
|
var InvitationsHandler = class {
|
|
1657
1875
|
/**
|
|
1658
1876
|
* @internal
|
|
1659
1877
|
*/
|
|
1660
|
-
constructor(_networkManager) {
|
|
1878
|
+
constructor(_networkManager, _defaultTeleportParams) {
|
|
1661
1879
|
this._networkManager = _networkManager;
|
|
1880
|
+
this._defaultTeleportParams = _defaultTeleportParams;
|
|
1662
1881
|
}
|
|
1663
1882
|
handleInvitationFlow(ctx, stream, protocol, invitation) {
|
|
1883
|
+
const guardedState = this._createGuardedState(ctx, invitation, stream);
|
|
1664
1884
|
const createExtension = () => {
|
|
1665
|
-
const extension = new InvitationHostExtension({
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
...invitation2,
|
|
1669
|
-
state: Invitation3.State.READY_FOR_AUTHENTICATION
|
|
1670
|
-
});
|
|
1885
|
+
const extension = new InvitationHostExtension(guardedState.mutex, {
|
|
1886
|
+
get activeInvitation() {
|
|
1887
|
+
return ctx.disposed ? null : guardedState.current;
|
|
1671
1888
|
},
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
}
|
|
1676
|
-
return invitation;
|
|
1889
|
+
onStateUpdate: (newState) => {
|
|
1890
|
+
guardedState.set(extension, newState);
|
|
1891
|
+
return guardedState.current;
|
|
1677
1892
|
},
|
|
1678
1893
|
admit: async (admissionRequest) => {
|
|
1679
1894
|
try {
|
|
1680
1895
|
const deviceKey = admissionRequest.device?.deviceKey ?? admissionRequest.space?.deviceKey;
|
|
1681
|
-
|
|
1682
|
-
F:
|
|
1683
|
-
L:
|
|
1896
|
+
invariant8(deviceKey, void 0, {
|
|
1897
|
+
F: __dxlog_file9,
|
|
1898
|
+
L: 90,
|
|
1684
1899
|
S: this,
|
|
1685
1900
|
A: [
|
|
1686
1901
|
"deviceKey",
|
|
@@ -1691,123 +1906,128 @@ var InvitationsHandler = class {
|
|
|
1691
1906
|
extension.completedTrigger.wake(deviceKey);
|
|
1692
1907
|
return admissionResponse;
|
|
1693
1908
|
} catch (err) {
|
|
1694
|
-
|
|
1909
|
+
guardedState.error(extension, err);
|
|
1695
1910
|
throw err;
|
|
1696
1911
|
}
|
|
1697
1912
|
},
|
|
1698
|
-
onOpen: () => {
|
|
1699
|
-
|
|
1700
|
-
|
|
1913
|
+
onOpen: (connectionCtx, extensionsCtx) => {
|
|
1914
|
+
let admitted = false;
|
|
1915
|
+
connectionCtx.onDispose(() => {
|
|
1916
|
+
if (!admitted) {
|
|
1917
|
+
guardedState.error(extension, new ContextDisposedError2());
|
|
1918
|
+
}
|
|
1919
|
+
});
|
|
1920
|
+
scheduleTask3(connectionCtx, async () => {
|
|
1921
|
+
const traceId = PublicKey7.random().toHex();
|
|
1701
1922
|
try {
|
|
1702
|
-
|
|
1923
|
+
log7.trace("dxos.sdk.invitations-handler.host.onOpen", trace4.begin({
|
|
1703
1924
|
id: traceId
|
|
1704
1925
|
}), {
|
|
1705
|
-
F:
|
|
1706
|
-
L:
|
|
1926
|
+
F: __dxlog_file9,
|
|
1927
|
+
L: 115,
|
|
1707
1928
|
S: this,
|
|
1708
1929
|
C: (f, a) => f(...a)
|
|
1709
1930
|
});
|
|
1710
|
-
|
|
1931
|
+
log7("connected", {
|
|
1711
1932
|
...protocol.toJSON()
|
|
1712
1933
|
}, {
|
|
1713
|
-
F:
|
|
1714
|
-
L:
|
|
1934
|
+
F: __dxlog_file9,
|
|
1935
|
+
L: 116,
|
|
1715
1936
|
S: this,
|
|
1716
1937
|
C: (f, a) => f(...a)
|
|
1717
1938
|
});
|
|
1718
|
-
stream.next({
|
|
1719
|
-
...invitation,
|
|
1720
|
-
state: Invitation3.State.CONNECTED
|
|
1721
|
-
});
|
|
1722
1939
|
const deviceKey = await extension.completedTrigger.wait({
|
|
1723
1940
|
timeout: invitation.timeout
|
|
1724
1941
|
});
|
|
1725
|
-
|
|
1942
|
+
log7("admitted guest", {
|
|
1726
1943
|
guest: deviceKey,
|
|
1727
1944
|
...protocol.toJSON()
|
|
1728
1945
|
}, {
|
|
1729
|
-
F:
|
|
1730
|
-
L:
|
|
1946
|
+
F: __dxlog_file9,
|
|
1947
|
+
L: 118,
|
|
1731
1948
|
S: this,
|
|
1732
1949
|
C: (f, a) => f(...a)
|
|
1733
1950
|
});
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
state: Invitation3.State.SUCCESS
|
|
1737
|
-
});
|
|
1738
|
-
log5.trace("dxos.sdk.invitations-handler.host.onOpen", trace4.end({
|
|
1951
|
+
guardedState.set(extension, Invitation4.State.SUCCESS);
|
|
1952
|
+
log7.trace("dxos.sdk.invitations-handler.host.onOpen", trace4.end({
|
|
1739
1953
|
id: traceId
|
|
1740
1954
|
}), {
|
|
1741
|
-
F:
|
|
1742
|
-
L:
|
|
1955
|
+
F: __dxlog_file9,
|
|
1956
|
+
L: 120,
|
|
1743
1957
|
S: this,
|
|
1744
1958
|
C: (f, a) => f(...a)
|
|
1745
1959
|
});
|
|
1960
|
+
admitted = true;
|
|
1961
|
+
if (!invitation.multiUse) {
|
|
1962
|
+
await ctx.dispose();
|
|
1963
|
+
}
|
|
1746
1964
|
} catch (err) {
|
|
1747
1965
|
if (err instanceof TimeoutError) {
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
state: Invitation3.State.TIMEOUT
|
|
1759
|
-
});
|
|
1966
|
+
if (guardedState.set(extension, Invitation4.State.TIMEOUT)) {
|
|
1967
|
+
log7("timeout", {
|
|
1968
|
+
...protocol.toJSON()
|
|
1969
|
+
}, {
|
|
1970
|
+
F: __dxlog_file9,
|
|
1971
|
+
L: 129,
|
|
1972
|
+
S: this,
|
|
1973
|
+
C: (f, a) => f(...a)
|
|
1974
|
+
});
|
|
1975
|
+
}
|
|
1760
1976
|
} else {
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1977
|
+
if (guardedState.error(extension, err)) {
|
|
1978
|
+
log7.error("failed", err, {
|
|
1979
|
+
F: __dxlog_file9,
|
|
1980
|
+
L: 133,
|
|
1981
|
+
S: this,
|
|
1982
|
+
C: (f, a) => f(...a)
|
|
1983
|
+
});
|
|
1984
|
+
}
|
|
1768
1985
|
}
|
|
1769
|
-
|
|
1986
|
+
log7.trace("dxos.sdk.invitations-handler.host.onOpen", trace4.error({
|
|
1770
1987
|
id: traceId,
|
|
1771
1988
|
error: err
|
|
1772
1989
|
}), {
|
|
1773
|
-
F:
|
|
1774
|
-
L:
|
|
1990
|
+
F: __dxlog_file9,
|
|
1991
|
+
L: 136,
|
|
1775
1992
|
S: this,
|
|
1776
1993
|
C: (f, a) => f(...a)
|
|
1777
1994
|
});
|
|
1778
|
-
|
|
1779
|
-
if (!invitation.multiUse) {
|
|
1780
|
-
await swarmConnection.close();
|
|
1781
|
-
await ctx.dispose();
|
|
1782
|
-
}
|
|
1995
|
+
extensionsCtx.close(err);
|
|
1783
1996
|
}
|
|
1784
1997
|
});
|
|
1785
1998
|
},
|
|
1786
1999
|
onError: (err) => {
|
|
1787
|
-
if (err instanceof
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
if (err instanceof TimeoutError) {
|
|
1791
|
-
log5("timeout", {
|
|
1792
|
-
...protocol.toJSON()
|
|
2000
|
+
if (err instanceof InvalidInvitationExtensionRoleError3) {
|
|
2001
|
+
log7("invalid role", {
|
|
2002
|
+
...err.context
|
|
1793
2003
|
}, {
|
|
1794
|
-
F:
|
|
1795
|
-
L:
|
|
2004
|
+
F: __dxlog_file9,
|
|
2005
|
+
L: 144,
|
|
1796
2006
|
S: this,
|
|
1797
2007
|
C: (f, a) => f(...a)
|
|
1798
2008
|
});
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
2009
|
+
return;
|
|
2010
|
+
}
|
|
2011
|
+
if (err instanceof TimeoutError) {
|
|
2012
|
+
if (guardedState.set(extension, Invitation4.State.TIMEOUT)) {
|
|
2013
|
+
log7("timeout", {
|
|
2014
|
+
err
|
|
2015
|
+
}, {
|
|
2016
|
+
F: __dxlog_file9,
|
|
2017
|
+
L: 149,
|
|
2018
|
+
S: this,
|
|
2019
|
+
C: (f, a) => f(...a)
|
|
2020
|
+
});
|
|
2021
|
+
}
|
|
1803
2022
|
} else {
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
2023
|
+
if (guardedState.error(extension, err)) {
|
|
2024
|
+
log7.error("failed", err, {
|
|
2025
|
+
F: __dxlog_file9,
|
|
2026
|
+
L: 153,
|
|
2027
|
+
S: this,
|
|
2028
|
+
C: (f, a) => f(...a)
|
|
2029
|
+
});
|
|
2030
|
+
}
|
|
1811
2031
|
}
|
|
1812
2032
|
}
|
|
1813
2033
|
});
|
|
@@ -1815,58 +2035,32 @@ var InvitationsHandler = class {
|
|
|
1815
2035
|
};
|
|
1816
2036
|
if (invitation.lifetime && invitation.created) {
|
|
1817
2037
|
if (invitation.created.getTime() + invitation.lifetime * 1e3 < Date.now()) {
|
|
1818
|
-
|
|
1819
|
-
F:
|
|
1820
|
-
L:
|
|
2038
|
+
log7.warn("invitation has already expired", void 0, {
|
|
2039
|
+
F: __dxlog_file9,
|
|
2040
|
+
L: 164,
|
|
1821
2041
|
S: this,
|
|
1822
2042
|
C: (f, a) => f(...a)
|
|
1823
2043
|
});
|
|
1824
2044
|
} else {
|
|
1825
|
-
|
|
2045
|
+
scheduleTask3(ctx, async () => {
|
|
1826
2046
|
await swarmConnection.close();
|
|
1827
|
-
|
|
1828
|
-
...invitation,
|
|
1829
|
-
state: Invitation3.State.EXPIRED
|
|
1830
|
-
});
|
|
2047
|
+
guardedState.set(null, Invitation4.State.EXPIRED);
|
|
1831
2048
|
await ctx.dispose();
|
|
1832
2049
|
}, invitation.created.getTime() + invitation.lifetime * 1e3 - Date.now());
|
|
1833
2050
|
}
|
|
1834
2051
|
}
|
|
1835
2052
|
let swarmConnection;
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
swarmConnection = await this._networkManager.joinSwarm({
|
|
1840
|
-
topic,
|
|
1841
|
-
peerId: topic,
|
|
1842
|
-
protocolProvider: createTeleportProtocolFactory(async (teleport) => {
|
|
1843
|
-
teleport.addExtension("dxos.halo.invitations", createExtension());
|
|
1844
|
-
}),
|
|
1845
|
-
topology: new StarTopology(topic),
|
|
1846
|
-
label: invitationLabel
|
|
1847
|
-
});
|
|
1848
|
-
ctx.onDispose(() => swarmConnection.close());
|
|
1849
|
-
stream.next({
|
|
1850
|
-
...invitation,
|
|
1851
|
-
state: Invitation3.State.CONNECTING
|
|
1852
|
-
});
|
|
2053
|
+
scheduleTask3(ctx, async () => {
|
|
2054
|
+
swarmConnection = await this._joinSwarm(ctx, invitation, Options4.Role.HOST, createExtension);
|
|
2055
|
+
guardedState.set(null, Invitation4.State.CONNECTING);
|
|
1853
2056
|
});
|
|
1854
2057
|
}
|
|
1855
|
-
acceptInvitation(protocol, invitation, deviceProfile) {
|
|
2058
|
+
acceptInvitation(ctx, stream, protocol, invitation, otpEnteredTrigger, deviceProfile) {
|
|
1856
2059
|
const { timeout = INVITATION_TIMEOUT } = invitation;
|
|
1857
|
-
invariant6(protocol, void 0, {
|
|
1858
|
-
F: __dxlog_file7,
|
|
1859
|
-
L: 191,
|
|
1860
|
-
S: this,
|
|
1861
|
-
A: [
|
|
1862
|
-
"protocol",
|
|
1863
|
-
""
|
|
1864
|
-
]
|
|
1865
|
-
});
|
|
1866
2060
|
if (deviceProfile) {
|
|
1867
|
-
|
|
1868
|
-
F:
|
|
1869
|
-
L:
|
|
2061
|
+
invariant8(invitation.kind === Invitation4.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
|
|
2062
|
+
F: __dxlog_file9,
|
|
2063
|
+
L: 197,
|
|
1870
2064
|
S: this,
|
|
1871
2065
|
A: [
|
|
1872
2066
|
"invitation.kind === Invitation.Kind.DEVICE",
|
|
@@ -1874,142 +2068,117 @@ var InvitationsHandler = class {
|
|
|
1874
2068
|
]
|
|
1875
2069
|
});
|
|
1876
2070
|
}
|
|
1877
|
-
const
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
S: this,
|
|
1886
|
-
A: [
|
|
1887
|
-
"newData.state !== undefined",
|
|
1888
|
-
""
|
|
1889
|
-
]
|
|
1890
|
-
});
|
|
1891
|
-
currentState = newData.state;
|
|
1892
|
-
stream.next({
|
|
1893
|
-
...invitation,
|
|
1894
|
-
...newData
|
|
1895
|
-
});
|
|
1896
|
-
};
|
|
1897
|
-
const ctx = new Context5({
|
|
1898
|
-
onError: (err) => {
|
|
1899
|
-
if (err instanceof TimeoutError) {
|
|
1900
|
-
log5("timeout", {
|
|
1901
|
-
...protocol.toJSON()
|
|
1902
|
-
}, {
|
|
1903
|
-
F: __dxlog_file7,
|
|
1904
|
-
L: 213,
|
|
1905
|
-
S: this,
|
|
1906
|
-
C: (f, a) => f(...a)
|
|
1907
|
-
});
|
|
1908
|
-
setState({
|
|
1909
|
-
state: Invitation3.State.TIMEOUT
|
|
1910
|
-
});
|
|
1911
|
-
} else {
|
|
1912
|
-
log5.warn("auth failed", err, {
|
|
1913
|
-
F: __dxlog_file7,
|
|
1914
|
-
L: 216,
|
|
1915
|
-
S: this,
|
|
1916
|
-
C: (f, a) => f(...a)
|
|
1917
|
-
});
|
|
1918
|
-
stream.error(err);
|
|
1919
|
-
}
|
|
1920
|
-
void ctx.dispose();
|
|
1921
|
-
}
|
|
1922
|
-
});
|
|
1923
|
-
ctx.onDispose(() => {
|
|
1924
|
-
log5("complete", {
|
|
1925
|
-
...protocol.toJSON()
|
|
2071
|
+
const triedPeersIds = new ComplexSet3(PublicKey7.hash);
|
|
2072
|
+
const guardedState = this._createGuardedState(ctx, invitation, stream);
|
|
2073
|
+
const shouldCancelInvitationFlow = (extension) => {
|
|
2074
|
+
const isLockedByAnotherConnection = guardedState.mutex.isLocked() && !extension.hasFlowLock();
|
|
2075
|
+
log7("should cancel invitation flow", {
|
|
2076
|
+
isLockedByAnotherConnection,
|
|
2077
|
+
invitationType: Invitation4.Type.DELEGATED,
|
|
2078
|
+
triedPeers: triedPeersIds.size
|
|
1926
2079
|
}, {
|
|
1927
|
-
F:
|
|
1928
|
-
L:
|
|
2080
|
+
F: __dxlog_file9,
|
|
2081
|
+
L: 205,
|
|
1929
2082
|
S: this,
|
|
1930
2083
|
C: (f, a) => f(...a)
|
|
1931
2084
|
});
|
|
1932
|
-
|
|
1933
|
-
|
|
2085
|
+
if (isLockedByAnotherConnection) {
|
|
2086
|
+
return false;
|
|
2087
|
+
}
|
|
2088
|
+
return invitation.type !== Invitation4.Type.DELEGATED || triedPeersIds.size >= MAX_DELEGATED_INVITATION_HOST_TRIES;
|
|
2089
|
+
};
|
|
2090
|
+
let admitted = false;
|
|
1934
2091
|
const createExtension = () => {
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
2092
|
+
const extension = new InvitationGuestExtension(guardedState.mutex, {
|
|
2093
|
+
onStateUpdate: (newState) => {
|
|
2094
|
+
guardedState.set(extension, newState);
|
|
2095
|
+
},
|
|
2096
|
+
onOpen: (connectionCtx, extensionCtx) => {
|
|
2097
|
+
triedPeersIds.add(extensionCtx.remotePeerId);
|
|
2098
|
+
if (admitted) {
|
|
2099
|
+
extensionCtx.close();
|
|
2100
|
+
return;
|
|
2101
|
+
}
|
|
2102
|
+
connectionCtx.onDispose(async () => {
|
|
2103
|
+
log7("extension disposed", {
|
|
2104
|
+
admitted,
|
|
2105
|
+
currentState: guardedState.current.state
|
|
1941
2106
|
}, {
|
|
1942
|
-
F:
|
|
1943
|
-
L:
|
|
2107
|
+
F: __dxlog_file9,
|
|
2108
|
+
L: 233,
|
|
1944
2109
|
S: this,
|
|
1945
2110
|
C: (f, a) => f(...a)
|
|
1946
2111
|
});
|
|
1947
2112
|
if (!admitted) {
|
|
1948
|
-
|
|
2113
|
+
guardedState.error(extension, new ContextDisposedError2());
|
|
2114
|
+
if (shouldCancelInvitationFlow(extension)) {
|
|
2115
|
+
await ctx.dispose();
|
|
2116
|
+
}
|
|
1949
2117
|
}
|
|
1950
2118
|
});
|
|
1951
|
-
|
|
1952
|
-
const traceId =
|
|
2119
|
+
scheduleTask3(connectionCtx, async () => {
|
|
2120
|
+
const traceId = PublicKey7.random().toHex();
|
|
1953
2121
|
try {
|
|
1954
|
-
|
|
2122
|
+
log7.trace("dxos.sdk.invitations-handler.guest.onOpen", trace4.begin({
|
|
1955
2123
|
id: traceId
|
|
1956
2124
|
}), {
|
|
1957
|
-
F:
|
|
1958
|
-
L:
|
|
2125
|
+
F: __dxlog_file9,
|
|
2126
|
+
L: 245,
|
|
1959
2127
|
S: this,
|
|
1960
2128
|
C: (f, a) => f(...a)
|
|
1961
2129
|
});
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
2130
|
+
scheduleTask3(connectionCtx, () => {
|
|
2131
|
+
guardedState.set(extension, Invitation4.State.TIMEOUT);
|
|
2132
|
+
extensionCtx.close();
|
|
2133
|
+
}, timeout);
|
|
2134
|
+
log7("connected", {
|
|
1967
2135
|
...protocol.toJSON()
|
|
1968
2136
|
}, {
|
|
1969
|
-
F:
|
|
1970
|
-
L:
|
|
2137
|
+
F: __dxlog_file9,
|
|
2138
|
+
L: 256,
|
|
1971
2139
|
S: this,
|
|
1972
2140
|
C: (f, a) => f(...a)
|
|
1973
2141
|
});
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
});
|
|
1977
|
-
log5("introduce", {
|
|
2142
|
+
guardedState.set(extension, Invitation4.State.CONNECTED);
|
|
2143
|
+
log7("introduce", {
|
|
1978
2144
|
...protocol.toJSON()
|
|
1979
2145
|
}, {
|
|
1980
|
-
F:
|
|
1981
|
-
L:
|
|
2146
|
+
F: __dxlog_file9,
|
|
2147
|
+
L: 260,
|
|
1982
2148
|
S: this,
|
|
1983
2149
|
C: (f, a) => f(...a)
|
|
1984
2150
|
});
|
|
1985
|
-
const introductionResponse = await extension.rpc.InvitationHostService.introduce(
|
|
1986
|
-
|
|
2151
|
+
const introductionResponse = await extension.rpc.InvitationHostService.introduce({
|
|
2152
|
+
invitationId: invitation.invitationId,
|
|
2153
|
+
...protocol.createIntroduction()
|
|
2154
|
+
});
|
|
2155
|
+
log7("introduce response", {
|
|
1987
2156
|
...protocol.toJSON(),
|
|
1988
2157
|
response: introductionResponse
|
|
1989
2158
|
}, {
|
|
1990
|
-
F:
|
|
1991
|
-
L:
|
|
2159
|
+
F: __dxlog_file9,
|
|
2160
|
+
L: 265,
|
|
1992
2161
|
S: this,
|
|
1993
2162
|
C: (f, a) => f(...a)
|
|
1994
2163
|
});
|
|
1995
2164
|
invitation.authMethod = introductionResponse.authMethod;
|
|
1996
2165
|
if (isAuthenticationRequired(invitation)) {
|
|
1997
2166
|
switch (invitation.authMethod) {
|
|
1998
|
-
case
|
|
1999
|
-
await this._handleGuestOtpAuth(extension,
|
|
2167
|
+
case Invitation4.AuthMethod.SHARED_SECRET:
|
|
2168
|
+
await this._handleGuestOtpAuth(extension, (state) => guardedState.set(extension, state), otpEnteredTrigger, {
|
|
2000
2169
|
timeout
|
|
2001
2170
|
});
|
|
2002
2171
|
break;
|
|
2003
|
-
case
|
|
2004
|
-
await this._handleGuestKpkAuth(extension,
|
|
2172
|
+
case Invitation4.AuthMethod.KNOWN_PUBLIC_KEY:
|
|
2173
|
+
await this._handleGuestKpkAuth(extension, (state) => guardedState.set(extension, state), invitation, introductionResponse);
|
|
2005
2174
|
break;
|
|
2006
2175
|
}
|
|
2007
2176
|
}
|
|
2008
|
-
|
|
2177
|
+
log7("request admission", {
|
|
2009
2178
|
...protocol.toJSON()
|
|
2010
2179
|
}, {
|
|
2011
|
-
F:
|
|
2012
|
-
L:
|
|
2180
|
+
F: __dxlog_file9,
|
|
2181
|
+
L: 291,
|
|
2013
2182
|
S: this,
|
|
2014
2183
|
C: (f, a) => f(...a)
|
|
2015
2184
|
});
|
|
@@ -2017,158 +2186,225 @@ var InvitationsHandler = class {
|
|
|
2017
2186
|
const admissionResponse = await extension.rpc.InvitationHostService.admit(admissionRequest);
|
|
2018
2187
|
admitted = true;
|
|
2019
2188
|
const result = await protocol.accept(admissionResponse, admissionRequest);
|
|
2020
|
-
|
|
2189
|
+
log7("admitted by host", {
|
|
2021
2190
|
...protocol.toJSON()
|
|
2022
2191
|
}, {
|
|
2023
|
-
F:
|
|
2024
|
-
L:
|
|
2192
|
+
F: __dxlog_file9,
|
|
2193
|
+
L: 302,
|
|
2025
2194
|
S: this,
|
|
2026
2195
|
C: (f, a) => f(...a)
|
|
2027
2196
|
});
|
|
2028
|
-
|
|
2197
|
+
await guardedState.complete({
|
|
2198
|
+
...guardedState.current,
|
|
2029
2199
|
...result,
|
|
2030
|
-
|
|
2031
|
-
state: Invitation3.State.SUCCESS
|
|
2200
|
+
state: Invitation4.State.SUCCESS
|
|
2032
2201
|
});
|
|
2033
|
-
|
|
2202
|
+
log7.trace("dxos.sdk.invitations-handler.guest.onOpen", trace4.end({
|
|
2034
2203
|
id: traceId
|
|
2035
2204
|
}), {
|
|
2036
|
-
F:
|
|
2037
|
-
L:
|
|
2205
|
+
F: __dxlog_file9,
|
|
2206
|
+
L: 308,
|
|
2038
2207
|
S: this,
|
|
2039
2208
|
C: (f, a) => f(...a)
|
|
2040
2209
|
});
|
|
2041
2210
|
} catch (err) {
|
|
2042
2211
|
if (err instanceof TimeoutError) {
|
|
2043
|
-
|
|
2212
|
+
log7("timeout", {
|
|
2044
2213
|
...protocol.toJSON()
|
|
2045
2214
|
}, {
|
|
2046
|
-
F:
|
|
2047
|
-
L:
|
|
2215
|
+
F: __dxlog_file9,
|
|
2216
|
+
L: 311,
|
|
2048
2217
|
S: this,
|
|
2049
2218
|
C: (f, a) => f(...a)
|
|
2050
2219
|
});
|
|
2051
|
-
|
|
2052
|
-
state: Invitation3.State.TIMEOUT
|
|
2053
|
-
});
|
|
2220
|
+
guardedState.set(extension, Invitation4.State.TIMEOUT);
|
|
2054
2221
|
} else {
|
|
2055
|
-
|
|
2056
|
-
F:
|
|
2057
|
-
L:
|
|
2222
|
+
log7("auth failed", err, {
|
|
2223
|
+
F: __dxlog_file9,
|
|
2224
|
+
L: 314,
|
|
2058
2225
|
S: this,
|
|
2059
2226
|
C: (f, a) => f(...a)
|
|
2060
2227
|
});
|
|
2061
|
-
|
|
2228
|
+
guardedState.error(extension, err);
|
|
2062
2229
|
}
|
|
2063
|
-
|
|
2230
|
+
extensionCtx.close(err);
|
|
2231
|
+
log7.trace("dxos.sdk.invitations-handler.guest.onOpen", trace4.error({
|
|
2064
2232
|
id: traceId,
|
|
2065
2233
|
error: err
|
|
2066
2234
|
}), {
|
|
2067
|
-
F:
|
|
2068
|
-
L:
|
|
2235
|
+
F: __dxlog_file9,
|
|
2236
|
+
L: 318,
|
|
2069
2237
|
S: this,
|
|
2070
2238
|
C: (f, a) => f(...a)
|
|
2071
2239
|
});
|
|
2072
|
-
} finally {
|
|
2073
|
-
await ctx.dispose();
|
|
2074
2240
|
}
|
|
2075
2241
|
});
|
|
2076
2242
|
},
|
|
2077
2243
|
onError: (err) => {
|
|
2078
|
-
if (err instanceof
|
|
2244
|
+
if (err instanceof InvalidInvitationExtensionRoleError3) {
|
|
2079
2245
|
return;
|
|
2080
2246
|
}
|
|
2081
2247
|
if (err instanceof TimeoutError) {
|
|
2082
|
-
|
|
2248
|
+
log7("timeout", {
|
|
2083
2249
|
...protocol.toJSON()
|
|
2084
2250
|
}, {
|
|
2085
|
-
F:
|
|
2086
|
-
L:
|
|
2251
|
+
F: __dxlog_file9,
|
|
2252
|
+
L: 327,
|
|
2087
2253
|
S: this,
|
|
2088
2254
|
C: (f, a) => f(...a)
|
|
2089
2255
|
});
|
|
2090
|
-
|
|
2091
|
-
state: Invitation3.State.TIMEOUT
|
|
2092
|
-
});
|
|
2256
|
+
guardedState.set(extension, Invitation4.State.TIMEOUT);
|
|
2093
2257
|
} else {
|
|
2094
|
-
|
|
2095
|
-
F:
|
|
2096
|
-
L:
|
|
2258
|
+
log7("auth failed", err, {
|
|
2259
|
+
F: __dxlog_file9,
|
|
2260
|
+
L: 330,
|
|
2097
2261
|
S: this,
|
|
2098
2262
|
C: (f, a) => f(...a)
|
|
2099
2263
|
});
|
|
2100
|
-
|
|
2264
|
+
guardedState.error(extension, err);
|
|
2101
2265
|
}
|
|
2102
2266
|
}
|
|
2103
2267
|
});
|
|
2104
2268
|
return extension;
|
|
2105
2269
|
};
|
|
2106
|
-
|
|
2270
|
+
scheduleTask3(ctx, async () => {
|
|
2107
2271
|
const error = protocol.checkInvitation(invitation);
|
|
2108
2272
|
if (error) {
|
|
2109
2273
|
stream.error(error);
|
|
2274
|
+
await ctx.dispose();
|
|
2110
2275
|
} else {
|
|
2111
|
-
|
|
2112
|
-
F:
|
|
2113
|
-
L:
|
|
2276
|
+
invariant8(invitation.swarmKey, void 0, {
|
|
2277
|
+
F: __dxlog_file9,
|
|
2278
|
+
L: 345,
|
|
2114
2279
|
S: this,
|
|
2115
2280
|
A: [
|
|
2116
2281
|
"invitation.swarmKey",
|
|
2117
2282
|
""
|
|
2118
2283
|
]
|
|
2119
2284
|
});
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
topic,
|
|
2123
|
-
peerId: PublicKey6.random(),
|
|
2124
|
-
protocolProvider: createTeleportProtocolFactory(async (teleport) => {
|
|
2125
|
-
teleport.addExtension("dxos.halo.invitations", createExtension());
|
|
2126
|
-
}),
|
|
2127
|
-
topology: new StarTopology(topic),
|
|
2128
|
-
label: "invitation guest"
|
|
2129
|
-
});
|
|
2130
|
-
ctx.onDispose(() => swarmConnection.close());
|
|
2131
|
-
setState({
|
|
2132
|
-
state: Invitation3.State.CONNECTING
|
|
2133
|
-
});
|
|
2285
|
+
await this._joinSwarm(ctx, invitation, Options4.Role.GUEST, createExtension);
|
|
2286
|
+
guardedState.set(null, Invitation4.State.CONNECTING);
|
|
2134
2287
|
}
|
|
2135
2288
|
});
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2289
|
+
}
|
|
2290
|
+
async _joinSwarm(ctx, invitation, role, extensionFactory) {
|
|
2291
|
+
let label;
|
|
2292
|
+
if (role === Options4.Role.GUEST) {
|
|
2293
|
+
label = "invitation guest";
|
|
2294
|
+
} else if (invitation.kind === Invitation4.Kind.DEVICE) {
|
|
2295
|
+
label = "invitation host for device";
|
|
2296
|
+
} else {
|
|
2297
|
+
label = `invitation host for space ${invitation.spaceKey?.truncate()}`;
|
|
2298
|
+
}
|
|
2299
|
+
const swarmConnection = await this._networkManager.joinSwarm({
|
|
2300
|
+
topic: invitation.swarmKey,
|
|
2301
|
+
peerId: PublicKey7.random(),
|
|
2302
|
+
protocolProvider: createTeleportProtocolFactory(async (teleport) => {
|
|
2303
|
+
teleport.addExtension("dxos.halo.invitations", extensionFactory());
|
|
2304
|
+
}, this._defaultTeleportParams),
|
|
2305
|
+
topology: new InvitationTopology(role),
|
|
2306
|
+
label
|
|
2307
|
+
});
|
|
2308
|
+
ctx.onDispose(() => swarmConnection.close());
|
|
2309
|
+
return swarmConnection;
|
|
2310
|
+
}
|
|
2311
|
+
/**
|
|
2312
|
+
* A utility object for serializing invitation state changes by multiple concurrent
|
|
2313
|
+
* invitation flow connections.
|
|
2314
|
+
*/
|
|
2315
|
+
_createGuardedState(ctx, invitation, stream) {
|
|
2316
|
+
const mutex = new Mutex();
|
|
2317
|
+
let lastActiveExtension = null;
|
|
2318
|
+
let currentInvitation = {
|
|
2319
|
+
...invitation
|
|
2320
|
+
};
|
|
2321
|
+
const isStateChangeAllowed = (extension) => {
|
|
2322
|
+
if (ctx.disposed || extension !== null && mutex.isLocked() && !extension.hasFlowLock()) {
|
|
2323
|
+
return false;
|
|
2324
|
+
}
|
|
2325
|
+
return extension == null || lastActiveExtension !== extension || this._isNotTerminal(currentInvitation.state);
|
|
2326
|
+
};
|
|
2327
|
+
return {
|
|
2328
|
+
mutex,
|
|
2329
|
+
get current() {
|
|
2330
|
+
return currentInvitation;
|
|
2144
2331
|
},
|
|
2145
|
-
|
|
2146
|
-
|
|
2332
|
+
// disposing context prevents any further state updates
|
|
2333
|
+
complete: (newState) => {
|
|
2334
|
+
currentInvitation = {
|
|
2335
|
+
...currentInvitation,
|
|
2336
|
+
...newState
|
|
2337
|
+
};
|
|
2338
|
+
stream.next(currentInvitation);
|
|
2339
|
+
return ctx.dispose();
|
|
2340
|
+
},
|
|
2341
|
+
set: (extension, newState) => {
|
|
2342
|
+
if (isStateChangeAllowed(extension)) {
|
|
2343
|
+
this._logStateUpdate(currentInvitation, extension, newState);
|
|
2344
|
+
currentInvitation = {
|
|
2345
|
+
...currentInvitation,
|
|
2346
|
+
state: newState
|
|
2347
|
+
};
|
|
2348
|
+
stream.next(currentInvitation);
|
|
2349
|
+
lastActiveExtension = extension;
|
|
2350
|
+
return true;
|
|
2351
|
+
}
|
|
2352
|
+
return false;
|
|
2353
|
+
},
|
|
2354
|
+
error: (extension, error) => {
|
|
2355
|
+
if (isStateChangeAllowed(extension)) {
|
|
2356
|
+
this._logStateUpdate(currentInvitation, extension, Invitation4.State.ERROR);
|
|
2357
|
+
currentInvitation = {
|
|
2358
|
+
...currentInvitation,
|
|
2359
|
+
state: Invitation4.State.ERROR
|
|
2360
|
+
};
|
|
2361
|
+
stream.next(currentInvitation);
|
|
2362
|
+
stream.error(error);
|
|
2363
|
+
lastActiveExtension = extension;
|
|
2364
|
+
return true;
|
|
2365
|
+
}
|
|
2366
|
+
return false;
|
|
2147
2367
|
}
|
|
2368
|
+
};
|
|
2369
|
+
}
|
|
2370
|
+
_logStateUpdate(invitation, actor, newState) {
|
|
2371
|
+
log7("invitation state update", {
|
|
2372
|
+
actor: actor?.constructor.name,
|
|
2373
|
+
newState: stateToString(newState),
|
|
2374
|
+
oldState: stateToString(invitation.state)
|
|
2375
|
+
}, {
|
|
2376
|
+
F: __dxlog_file9,
|
|
2377
|
+
L: 438,
|
|
2378
|
+
S: this,
|
|
2379
|
+
C: (f, a) => f(...a)
|
|
2148
2380
|
});
|
|
2149
|
-
|
|
2381
|
+
}
|
|
2382
|
+
_isNotTerminal(currentState) {
|
|
2383
|
+
return ![
|
|
2384
|
+
Invitation4.State.SUCCESS,
|
|
2385
|
+
Invitation4.State.ERROR,
|
|
2386
|
+
Invitation4.State.CANCELLED,
|
|
2387
|
+
Invitation4.State.TIMEOUT,
|
|
2388
|
+
Invitation4.State.EXPIRED
|
|
2389
|
+
].includes(currentState);
|
|
2150
2390
|
}
|
|
2151
2391
|
async _handleGuestOtpAuth(extension, setState, authenticated, options) {
|
|
2152
2392
|
for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
|
|
2153
|
-
|
|
2154
|
-
F:
|
|
2155
|
-
L:
|
|
2393
|
+
log7("guest waiting for authentication code...", void 0, {
|
|
2394
|
+
F: __dxlog_file9,
|
|
2395
|
+
L: 462,
|
|
2156
2396
|
S: this,
|
|
2157
2397
|
C: (f, a) => f(...a)
|
|
2158
2398
|
});
|
|
2159
|
-
setState(
|
|
2160
|
-
state: Invitation3.State.READY_FOR_AUTHENTICATION
|
|
2161
|
-
});
|
|
2399
|
+
setState(Invitation4.State.READY_FOR_AUTHENTICATION);
|
|
2162
2400
|
const authCode = await authenticated.wait(options);
|
|
2163
|
-
|
|
2164
|
-
F:
|
|
2165
|
-
L:
|
|
2401
|
+
log7("sending authentication request", void 0, {
|
|
2402
|
+
F: __dxlog_file9,
|
|
2403
|
+
L: 466,
|
|
2166
2404
|
S: this,
|
|
2167
2405
|
C: (f, a) => f(...a)
|
|
2168
2406
|
});
|
|
2169
|
-
setState(
|
|
2170
|
-
state: Invitation3.State.AUTHENTICATING
|
|
2171
|
-
});
|
|
2407
|
+
setState(Invitation4.State.AUTHENTICATING);
|
|
2172
2408
|
const response = await extension.rpc.InvitationHostService.authenticate({
|
|
2173
2409
|
authCode
|
|
2174
2410
|
});
|
|
@@ -2179,11 +2415,11 @@ var InvitationsHandler = class {
|
|
|
2179
2415
|
if (attempt === MAX_OTP_ATTEMPTS) {
|
|
2180
2416
|
throw new Error(`Maximum retry attempts: ${MAX_OTP_ATTEMPTS}`);
|
|
2181
2417
|
} else {
|
|
2182
|
-
|
|
2418
|
+
log7("retrying invalid code", {
|
|
2183
2419
|
attempt
|
|
2184
2420
|
}, {
|
|
2185
|
-
F:
|
|
2186
|
-
L:
|
|
2421
|
+
F: __dxlog_file9,
|
|
2422
|
+
L: 477,
|
|
2187
2423
|
S: this,
|
|
2188
2424
|
C: (f, a) => f(...a)
|
|
2189
2425
|
});
|
|
@@ -2199,15 +2435,13 @@ var InvitationsHandler = class {
|
|
|
2199
2435
|
if (introductionResponse.challenge == null) {
|
|
2200
2436
|
throw new Error("challenge missing in the introduction");
|
|
2201
2437
|
}
|
|
2202
|
-
|
|
2203
|
-
F:
|
|
2204
|
-
L:
|
|
2438
|
+
log7("sending authentication request", void 0, {
|
|
2439
|
+
F: __dxlog_file9,
|
|
2440
|
+
L: 496,
|
|
2205
2441
|
S: this,
|
|
2206
2442
|
C: (f, a) => f(...a)
|
|
2207
2443
|
});
|
|
2208
|
-
setState(
|
|
2209
|
-
state: Invitation3.State.AUTHENTICATING
|
|
2210
|
-
});
|
|
2444
|
+
setState(Invitation4.State.AUTHENTICATING);
|
|
2211
2445
|
const signature = sign(Buffer.from(introductionResponse.challenge), invitation.guestKeypair.privateKey);
|
|
2212
2446
|
const response = await extension.rpc.InvitationHostService.authenticate({
|
|
2213
2447
|
signedChallenge: signature
|
|
@@ -2220,7 +2454,7 @@ var InvitationsHandler = class {
|
|
|
2220
2454
|
var createAdmissionKeypair = () => {
|
|
2221
2455
|
const keypair = createKeyPair();
|
|
2222
2456
|
return {
|
|
2223
|
-
publicKey:
|
|
2457
|
+
publicKey: PublicKey7.from(keypair.publicKey),
|
|
2224
2458
|
privateKey: keypair.secretKey
|
|
2225
2459
|
};
|
|
2226
2460
|
};
|
|
@@ -2323,14 +2557,14 @@ var InvitationsServiceImpl = class {
|
|
|
2323
2557
|
};
|
|
2324
2558
|
|
|
2325
2559
|
// packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts
|
|
2326
|
-
import { createAdmissionCredentials, createDelegatedSpaceInvitationCredential, getCredentialAssertion } from "@dxos/credentials";
|
|
2560
|
+
import { createAdmissionCredentials, createCancelDelegatedSpaceInvitationCredential, createDelegatedSpaceInvitationCredential, getCredentialAssertion } from "@dxos/credentials";
|
|
2327
2561
|
import { writeMessages as writeMessages2 } from "@dxos/feed-store";
|
|
2328
|
-
import { invariant as
|
|
2329
|
-
import { log as
|
|
2562
|
+
import { invariant as invariant9 } from "@dxos/invariant";
|
|
2563
|
+
import { log as log8 } from "@dxos/log";
|
|
2330
2564
|
import { AlreadyJoinedError as AlreadyJoinedError2 } from "@dxos/protocols";
|
|
2331
|
-
import { Invitation as
|
|
2565
|
+
import { Invitation as Invitation5 } from "@dxos/protocols/proto/dxos/client/services";
|
|
2332
2566
|
import { SpaceMember } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
2333
|
-
var
|
|
2567
|
+
var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
|
|
2334
2568
|
var SpaceInvitationProtocol = class {
|
|
2335
2569
|
constructor(_spaceManager, _signingContext, _keyring, _spaceKey) {
|
|
2336
2570
|
this._spaceManager = _spaceManager;
|
|
@@ -2346,33 +2580,33 @@ var SpaceInvitationProtocol = class {
|
|
|
2346
2580
|
}
|
|
2347
2581
|
getInvitationContext() {
|
|
2348
2582
|
return {
|
|
2349
|
-
kind:
|
|
2583
|
+
kind: Invitation5.Kind.SPACE,
|
|
2350
2584
|
spaceKey: this._spaceKey
|
|
2351
2585
|
};
|
|
2352
2586
|
}
|
|
2353
2587
|
async admit(invitation, request, guestProfile) {
|
|
2354
|
-
|
|
2355
|
-
F:
|
|
2356
|
-
L:
|
|
2588
|
+
invariant9(this._spaceKey, void 0, {
|
|
2589
|
+
F: __dxlog_file10,
|
|
2590
|
+
L: 56,
|
|
2357
2591
|
S: this,
|
|
2358
2592
|
A: [
|
|
2359
2593
|
"this._spaceKey",
|
|
2360
2594
|
""
|
|
2361
2595
|
]
|
|
2362
2596
|
});
|
|
2363
|
-
const space =
|
|
2364
|
-
|
|
2365
|
-
F:
|
|
2366
|
-
L:
|
|
2597
|
+
const space = this._spaceManager.spaces.get(this._spaceKey);
|
|
2598
|
+
invariant9(space, void 0, {
|
|
2599
|
+
F: __dxlog_file10,
|
|
2600
|
+
L: 58,
|
|
2367
2601
|
S: this,
|
|
2368
2602
|
A: [
|
|
2369
2603
|
"space",
|
|
2370
2604
|
""
|
|
2371
2605
|
]
|
|
2372
2606
|
});
|
|
2373
|
-
|
|
2374
|
-
F:
|
|
2375
|
-
L:
|
|
2607
|
+
invariant9(request.space, void 0, {
|
|
2608
|
+
F: __dxlog_file10,
|
|
2609
|
+
L: 60,
|
|
2376
2610
|
S: this,
|
|
2377
2611
|
A: [
|
|
2378
2612
|
"request.space",
|
|
@@ -2380,19 +2614,19 @@ var SpaceInvitationProtocol = class {
|
|
|
2380
2614
|
]
|
|
2381
2615
|
});
|
|
2382
2616
|
const { identityKey, deviceKey } = request.space;
|
|
2383
|
-
|
|
2617
|
+
log8("writing guest credentials", {
|
|
2384
2618
|
host: this._signingContext.deviceKey,
|
|
2385
2619
|
guest: deviceKey
|
|
2386
2620
|
}, {
|
|
2387
|
-
F:
|
|
2388
|
-
L:
|
|
2621
|
+
F: __dxlog_file10,
|
|
2622
|
+
L: 63,
|
|
2389
2623
|
S: this,
|
|
2390
2624
|
C: (f, a) => f(...a)
|
|
2391
2625
|
});
|
|
2392
|
-
const credentials = await createAdmissionCredentials(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, guestProfile, invitation.delegationCredentialId);
|
|
2393
|
-
|
|
2394
|
-
F:
|
|
2395
|
-
L:
|
|
2626
|
+
const credentials = await createAdmissionCredentials(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, invitation.role ?? SpaceMember.Role.ADMIN, space.inner.spaceState.membershipChainHeads, guestProfile, invitation.delegationCredentialId);
|
|
2627
|
+
invariant9(credentials[0].credential, void 0, {
|
|
2628
|
+
F: __dxlog_file10,
|
|
2629
|
+
L: 77,
|
|
2396
2630
|
S: this,
|
|
2397
2631
|
A: [
|
|
2398
2632
|
"credentials[0].credential",
|
|
@@ -2400,9 +2634,9 @@ var SpaceInvitationProtocol = class {
|
|
|
2400
2634
|
]
|
|
2401
2635
|
});
|
|
2402
2636
|
const spaceMemberCredential = credentials[0].credential.credential;
|
|
2403
|
-
|
|
2404
|
-
F:
|
|
2405
|
-
L:
|
|
2637
|
+
invariant9(getCredentialAssertion(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
|
|
2638
|
+
F: __dxlog_file10,
|
|
2639
|
+
L: 79,
|
|
2406
2640
|
S: this,
|
|
2407
2641
|
A: [
|
|
2408
2642
|
"getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
|
|
@@ -2418,29 +2652,29 @@ var SpaceInvitationProtocol = class {
|
|
|
2418
2652
|
};
|
|
2419
2653
|
}
|
|
2420
2654
|
async delegate(invitation) {
|
|
2421
|
-
|
|
2422
|
-
F:
|
|
2423
|
-
L:
|
|
2655
|
+
invariant9(this._spaceKey, void 0, {
|
|
2656
|
+
F: __dxlog_file10,
|
|
2657
|
+
L: 92,
|
|
2424
2658
|
S: this,
|
|
2425
2659
|
A: [
|
|
2426
2660
|
"this._spaceKey",
|
|
2427
2661
|
""
|
|
2428
2662
|
]
|
|
2429
2663
|
});
|
|
2430
|
-
const space =
|
|
2431
|
-
|
|
2432
|
-
F:
|
|
2433
|
-
L:
|
|
2664
|
+
const space = this._spaceManager.spaces.get(this._spaceKey);
|
|
2665
|
+
invariant9(space, void 0, {
|
|
2666
|
+
F: __dxlog_file10,
|
|
2667
|
+
L: 94,
|
|
2434
2668
|
S: this,
|
|
2435
2669
|
A: [
|
|
2436
2670
|
"space",
|
|
2437
2671
|
""
|
|
2438
2672
|
]
|
|
2439
2673
|
});
|
|
2440
|
-
if (invitation.authMethod ===
|
|
2441
|
-
|
|
2442
|
-
F:
|
|
2443
|
-
L:
|
|
2674
|
+
if (invitation.authMethod === Invitation5.AuthMethod.KNOWN_PUBLIC_KEY) {
|
|
2675
|
+
invariant9(invitation.guestKeypair?.publicKey, void 0, {
|
|
2676
|
+
F: __dxlog_file10,
|
|
2677
|
+
L: 96,
|
|
2444
2678
|
S: this,
|
|
2445
2679
|
A: [
|
|
2446
2680
|
"invitation.guestKeypair?.publicKey",
|
|
@@ -2448,12 +2682,12 @@ var SpaceInvitationProtocol = class {
|
|
|
2448
2682
|
]
|
|
2449
2683
|
});
|
|
2450
2684
|
}
|
|
2451
|
-
|
|
2685
|
+
log8("writing delegate space invitation", {
|
|
2452
2686
|
host: this._signingContext.deviceKey,
|
|
2453
2687
|
id: invitation.invitationId
|
|
2454
2688
|
}, {
|
|
2455
|
-
F:
|
|
2456
|
-
L:
|
|
2689
|
+
F: __dxlog_file10,
|
|
2690
|
+
L: 99,
|
|
2457
2691
|
S: this,
|
|
2458
2692
|
C: (f, a) => f(...a)
|
|
2459
2693
|
});
|
|
@@ -2461,14 +2695,14 @@ var SpaceInvitationProtocol = class {
|
|
|
2461
2695
|
invitationId: invitation.invitationId,
|
|
2462
2696
|
authMethod: invitation.authMethod,
|
|
2463
2697
|
swarmKey: invitation.swarmKey,
|
|
2464
|
-
role: SpaceMember.Role.ADMIN,
|
|
2698
|
+
role: invitation.role ?? SpaceMember.Role.ADMIN,
|
|
2465
2699
|
expiresOn: invitation.lifetime ? new Date((invitation.created?.getTime() ?? Date.now()) + invitation.lifetime) : void 0,
|
|
2466
2700
|
multiUse: invitation.multiUse ?? false,
|
|
2467
|
-
guestKey: invitation.authMethod ===
|
|
2701
|
+
guestKey: invitation.authMethod === Invitation5.AuthMethod.KNOWN_PUBLIC_KEY ? invitation.guestKeypair.publicKey : void 0
|
|
2468
2702
|
});
|
|
2469
|
-
|
|
2470
|
-
F:
|
|
2471
|
-
L:
|
|
2703
|
+
invariant9(credential.credential, void 0, {
|
|
2704
|
+
F: __dxlog_file10,
|
|
2705
|
+
L: 119,
|
|
2472
2706
|
S: this,
|
|
2473
2707
|
A: [
|
|
2474
2708
|
"credential.credential",
|
|
@@ -2480,6 +2714,58 @@ var SpaceInvitationProtocol = class {
|
|
|
2480
2714
|
]);
|
|
2481
2715
|
return credential.credential.credential.id;
|
|
2482
2716
|
}
|
|
2717
|
+
async cancelDelegation(invitation) {
|
|
2718
|
+
invariant9(this._spaceKey, void 0, {
|
|
2719
|
+
F: __dxlog_file10,
|
|
2720
|
+
L: 125,
|
|
2721
|
+
S: this,
|
|
2722
|
+
A: [
|
|
2723
|
+
"this._spaceKey",
|
|
2724
|
+
""
|
|
2725
|
+
]
|
|
2726
|
+
});
|
|
2727
|
+
invariant9(invitation.type === Invitation5.Type.DELEGATED && invitation.delegationCredentialId, void 0, {
|
|
2728
|
+
F: __dxlog_file10,
|
|
2729
|
+
L: 126,
|
|
2730
|
+
S: this,
|
|
2731
|
+
A: [
|
|
2732
|
+
"invitation.type === Invitation.Type.DELEGATED && invitation.delegationCredentialId",
|
|
2733
|
+
""
|
|
2734
|
+
]
|
|
2735
|
+
});
|
|
2736
|
+
const space = this._spaceManager.spaces.get(this._spaceKey);
|
|
2737
|
+
invariant9(space, void 0, {
|
|
2738
|
+
F: __dxlog_file10,
|
|
2739
|
+
L: 128,
|
|
2740
|
+
S: this,
|
|
2741
|
+
A: [
|
|
2742
|
+
"space",
|
|
2743
|
+
""
|
|
2744
|
+
]
|
|
2745
|
+
});
|
|
2746
|
+
log8("cancelling delegated space invitation", {
|
|
2747
|
+
host: this._signingContext.deviceKey,
|
|
2748
|
+
id: invitation.invitationId
|
|
2749
|
+
}, {
|
|
2750
|
+
F: __dxlog_file10,
|
|
2751
|
+
L: 130,
|
|
2752
|
+
S: this,
|
|
2753
|
+
C: (f, a) => f(...a)
|
|
2754
|
+
});
|
|
2755
|
+
const credential = await createCancelDelegatedSpaceInvitationCredential(this._signingContext.credentialSigner, space.key, invitation.delegationCredentialId);
|
|
2756
|
+
invariant9(credential.credential, void 0, {
|
|
2757
|
+
F: __dxlog_file10,
|
|
2758
|
+
L: 137,
|
|
2759
|
+
S: this,
|
|
2760
|
+
A: [
|
|
2761
|
+
"credential.credential",
|
|
2762
|
+
""
|
|
2763
|
+
]
|
|
2764
|
+
});
|
|
2765
|
+
await writeMessages2(space.inner.controlPipeline.writer, [
|
|
2766
|
+
credential
|
|
2767
|
+
]);
|
|
2768
|
+
}
|
|
2483
2769
|
checkInvitation(invitation) {
|
|
2484
2770
|
if (invitation.spaceKey && this._spaceManager.spaces.has(invitation.spaceKey)) {
|
|
2485
2771
|
return new AlreadyJoinedError2("Already joined space.");
|
|
@@ -2503,9 +2789,9 @@ var SpaceInvitationProtocol = class {
|
|
|
2503
2789
|
};
|
|
2504
2790
|
}
|
|
2505
2791
|
async accept(response) {
|
|
2506
|
-
|
|
2507
|
-
F:
|
|
2508
|
-
L:
|
|
2792
|
+
invariant9(response.space, void 0, {
|
|
2793
|
+
F: __dxlog_file10,
|
|
2794
|
+
L: 169,
|
|
2509
2795
|
S: this,
|
|
2510
2796
|
A: [
|
|
2511
2797
|
"response.space",
|
|
@@ -2514,18 +2800,18 @@ var SpaceInvitationProtocol = class {
|
|
|
2514
2800
|
});
|
|
2515
2801
|
const { credential, controlTimeframe, dataTimeframe } = response.space;
|
|
2516
2802
|
const assertion = getCredentialAssertion(credential);
|
|
2517
|
-
|
|
2518
|
-
F:
|
|
2519
|
-
L:
|
|
2803
|
+
invariant9(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
|
|
2804
|
+
F: __dxlog_file10,
|
|
2805
|
+
L: 172,
|
|
2520
2806
|
S: this,
|
|
2521
2807
|
A: [
|
|
2522
2808
|
"assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
|
|
2523
2809
|
"'Invalid credential'"
|
|
2524
2810
|
]
|
|
2525
2811
|
});
|
|
2526
|
-
|
|
2527
|
-
F:
|
|
2528
|
-
L:
|
|
2812
|
+
invariant9(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
|
|
2813
|
+
F: __dxlog_file10,
|
|
2814
|
+
L: 173,
|
|
2529
2815
|
S: this,
|
|
2530
2816
|
A: [
|
|
2531
2817
|
"credential.subject.id.equals(this._signingContext.identityKey)",
|
|
@@ -2549,16 +2835,17 @@ var SpaceInvitationProtocol = class {
|
|
|
2549
2835
|
};
|
|
2550
2836
|
|
|
2551
2837
|
// packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts
|
|
2552
|
-
import { Event as Event3, PushStream as
|
|
2553
|
-
import { AUTHENTICATION_CODE_LENGTH, CancellableInvitation, INVITATION_TIMEOUT as INVITATION_TIMEOUT2 } from "@dxos/client-protocol";
|
|
2838
|
+
import { Event as Event3, PushStream, TimeoutError as TimeoutError2, Trigger as Trigger4 } from "@dxos/async";
|
|
2839
|
+
import { AuthenticatingInvitation, AUTHENTICATION_CODE_LENGTH, CancellableInvitation, INVITATION_TIMEOUT as INVITATION_TIMEOUT2 } from "@dxos/client-protocol";
|
|
2554
2840
|
import { Context as Context6 } from "@dxos/context";
|
|
2555
|
-
import { generatePasscode } from "@dxos/credentials";
|
|
2556
|
-
import { hasInvitationExpired } from "@dxos/echo-pipeline";
|
|
2557
|
-
import { invariant as
|
|
2558
|
-
import { PublicKey as
|
|
2559
|
-
import { log as
|
|
2560
|
-
import { Invitation as
|
|
2561
|
-
|
|
2841
|
+
import { generatePasscode } from "@dxos/credentials";
|
|
2842
|
+
import { hasInvitationExpired } from "@dxos/echo-pipeline";
|
|
2843
|
+
import { invariant as invariant10 } from "@dxos/invariant";
|
|
2844
|
+
import { PublicKey as PublicKey8 } from "@dxos/keys";
|
|
2845
|
+
import { log as log9 } from "@dxos/log";
|
|
2846
|
+
import { Invitation as Invitation6 } from "@dxos/protocols/proto/dxos/client/services";
|
|
2847
|
+
import { SpaceMember as SpaceMember2 } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
2848
|
+
var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts";
|
|
2562
2849
|
var InvitationsManager = class {
|
|
2563
2850
|
constructor(_invitationsHandler, _getHandler, _metadataStore) {
|
|
2564
2851
|
this._invitationsHandler = _invitationsHandler;
|
|
@@ -2596,9 +2883,9 @@ var InvitationsManager = class {
|
|
|
2596
2883
|
try {
|
|
2597
2884
|
await this._persistIfRequired(handler, stream, invitation);
|
|
2598
2885
|
} catch (err) {
|
|
2599
|
-
|
|
2600
|
-
F:
|
|
2601
|
-
L:
|
|
2886
|
+
log9.catch(err, void 0, {
|
|
2887
|
+
F: __dxlog_file11,
|
|
2888
|
+
L: 77,
|
|
2602
2889
|
S: this,
|
|
2603
2890
|
C: (f, a) => f(...a)
|
|
2604
2891
|
});
|
|
@@ -2619,9 +2906,9 @@ var InvitationsManager = class {
|
|
|
2619
2906
|
const persistentInvitations = this._metadataStore.getInvitations();
|
|
2620
2907
|
const freshInvitations = persistentInvitations.filter((invitation) => !hasInvitationExpired(invitation));
|
|
2621
2908
|
const loadTasks = freshInvitations.map((persistentInvitation) => {
|
|
2622
|
-
|
|
2623
|
-
F:
|
|
2624
|
-
L:
|
|
2909
|
+
invariant10(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
|
|
2910
|
+
F: __dxlog_file11,
|
|
2911
|
+
L: 98,
|
|
2625
2912
|
S: this,
|
|
2626
2913
|
A: [
|
|
2627
2914
|
"!this._createInvitations.get(persistentInvitation.invitationId)",
|
|
@@ -2638,9 +2925,9 @@ var InvitationsManager = class {
|
|
|
2638
2925
|
invitations: cInvitations.map((invitation) => invitation.get())
|
|
2639
2926
|
};
|
|
2640
2927
|
} catch (err) {
|
|
2641
|
-
|
|
2642
|
-
F:
|
|
2643
|
-
L:
|
|
2928
|
+
log9.catch(err, void 0, {
|
|
2929
|
+
F: __dxlog_file11,
|
|
2930
|
+
L: 105,
|
|
2644
2931
|
S: this,
|
|
2645
2932
|
C: (f, a) => f(...a)
|
|
2646
2933
|
});
|
|
@@ -2659,7 +2946,8 @@ var InvitationsManager = class {
|
|
|
2659
2946
|
return existingInvitation;
|
|
2660
2947
|
}
|
|
2661
2948
|
const handler = this._getHandler(options);
|
|
2662
|
-
const invitation = this.
|
|
2949
|
+
const { ctx, invitation, stream, otpEnteredTrigger } = this._createObservableAcceptingInvitation(handler, options);
|
|
2950
|
+
this._invitationsHandler.acceptInvitation(ctx, stream, handler, options, otpEnteredTrigger, request.deviceProfile);
|
|
2663
2951
|
this._acceptInvitations.set(invitation.get().invitationId, invitation);
|
|
2664
2952
|
this.invitationAccepted.emit(invitation.get());
|
|
2665
2953
|
this._onInvitationComplete(invitation, () => {
|
|
@@ -2669,15 +2957,15 @@ var InvitationsManager = class {
|
|
|
2669
2957
|
return invitation;
|
|
2670
2958
|
}
|
|
2671
2959
|
async authenticate({ invitationId, authCode }) {
|
|
2672
|
-
|
|
2673
|
-
F:
|
|
2674
|
-
L:
|
|
2960
|
+
log9("authenticating...", void 0, {
|
|
2961
|
+
F: __dxlog_file11,
|
|
2962
|
+
L: 135,
|
|
2675
2963
|
S: this,
|
|
2676
2964
|
C: (f, a) => f(...a)
|
|
2677
2965
|
});
|
|
2678
|
-
|
|
2679
|
-
F:
|
|
2680
|
-
L:
|
|
2966
|
+
invariant10(invitationId, void 0, {
|
|
2967
|
+
F: __dxlog_file11,
|
|
2968
|
+
L: 136,
|
|
2681
2969
|
S: this,
|
|
2682
2970
|
A: [
|
|
2683
2971
|
"invitationId",
|
|
@@ -2686,11 +2974,11 @@ var InvitationsManager = class {
|
|
|
2686
2974
|
});
|
|
2687
2975
|
const observable = this._acceptInvitations.get(invitationId);
|
|
2688
2976
|
if (!observable) {
|
|
2689
|
-
|
|
2977
|
+
log9.warn("invalid invitation", {
|
|
2690
2978
|
invitationId
|
|
2691
2979
|
}, {
|
|
2692
|
-
F:
|
|
2693
|
-
L:
|
|
2980
|
+
F: __dxlog_file11,
|
|
2981
|
+
L: 139,
|
|
2694
2982
|
S: this,
|
|
2695
2983
|
C: (f, a) => f(...a)
|
|
2696
2984
|
});
|
|
@@ -2699,17 +2987,17 @@ var InvitationsManager = class {
|
|
|
2699
2987
|
}
|
|
2700
2988
|
}
|
|
2701
2989
|
async cancelInvitation({ invitationId }) {
|
|
2702
|
-
|
|
2990
|
+
log9("cancelInvitation...", {
|
|
2703
2991
|
invitationId
|
|
2704
2992
|
}, {
|
|
2705
|
-
F:
|
|
2706
|
-
L:
|
|
2993
|
+
F: __dxlog_file11,
|
|
2994
|
+
L: 146,
|
|
2707
2995
|
S: this,
|
|
2708
2996
|
C: (f, a) => f(...a)
|
|
2709
2997
|
});
|
|
2710
|
-
|
|
2711
|
-
F:
|
|
2712
|
-
L:
|
|
2998
|
+
invariant10(invitationId, void 0, {
|
|
2999
|
+
F: __dxlog_file11,
|
|
3000
|
+
L: 147,
|
|
2713
3001
|
S: this,
|
|
2714
3002
|
A: [
|
|
2715
3003
|
"invitationId",
|
|
@@ -2721,6 +3009,10 @@ var InvitationsManager = class {
|
|
|
2721
3009
|
if (created.get().persistent) {
|
|
2722
3010
|
await this._metadataStore.removeInvitation(invitationId);
|
|
2723
3011
|
}
|
|
3012
|
+
if (created.get().type === Invitation6.Type.DELEGATED) {
|
|
3013
|
+
const handler = this._getHandler(created.get());
|
|
3014
|
+
await handler.cancelDelegation(created.get());
|
|
3015
|
+
}
|
|
2724
3016
|
await created.cancel();
|
|
2725
3017
|
this._createInvitations.delete(invitationId);
|
|
2726
3018
|
this.removedCreated.emit(created.get());
|
|
@@ -2751,8 +3043,8 @@ var InvitationsManager = class {
|
|
|
2751
3043
|
}
|
|
2752
3044
|
}
|
|
2753
3045
|
_createInvitation(protocol, options) {
|
|
2754
|
-
const { invitationId =
|
|
2755
|
-
const authCode = options?.authCode ?? (authMethod ===
|
|
3046
|
+
const { invitationId = PublicKey8.random().toHex(), type = Invitation6.Type.INTERACTIVE, authMethod = Invitation6.AuthMethod.SHARED_SECRET, state = Invitation6.State.INIT, timeout = INVITATION_TIMEOUT2, swarmKey = PublicKey8.random(), persistent = options?.authMethod !== Invitation6.AuthMethod.KNOWN_PUBLIC_KEY, created = /* @__PURE__ */ new Date(), guestKeypair = void 0, role = SpaceMember2.Role.ADMIN, lifetime = 86400, multiUse = false } = options ?? {};
|
|
3047
|
+
const authCode = options?.authCode ?? (authMethod === Invitation6.AuthMethod.SHARED_SECRET ? generatePasscode(AUTHENTICATION_CODE_LENGTH) : void 0);
|
|
2756
3048
|
return {
|
|
2757
3049
|
invitationId,
|
|
2758
3050
|
type,
|
|
@@ -2761,17 +3053,18 @@ var InvitationsManager = class {
|
|
|
2761
3053
|
swarmKey,
|
|
2762
3054
|
authCode,
|
|
2763
3055
|
timeout,
|
|
2764
|
-
persistent: persistent && type !==
|
|
2765
|
-
guestKeypair: guestKeypair ?? (authMethod ===
|
|
3056
|
+
persistent: persistent && type !== Invitation6.Type.DELEGATED,
|
|
3057
|
+
guestKeypair: guestKeypair ?? (authMethod === Invitation6.AuthMethod.KNOWN_PUBLIC_KEY ? createAdmissionKeypair() : void 0),
|
|
2766
3058
|
created,
|
|
2767
3059
|
lifetime,
|
|
3060
|
+
role,
|
|
2768
3061
|
multiUse,
|
|
2769
3062
|
delegationCredentialId: options?.delegationCredentialId,
|
|
2770
3063
|
...protocol.getInvitationContext()
|
|
2771
3064
|
};
|
|
2772
3065
|
}
|
|
2773
3066
|
_createObservableInvitation(handler, invitation) {
|
|
2774
|
-
const stream = new
|
|
3067
|
+
const stream = new PushStream();
|
|
2775
3068
|
const ctx = new Context6({
|
|
2776
3069
|
onError: (err) => {
|
|
2777
3070
|
stream.error(err);
|
|
@@ -2779,11 +3072,11 @@ var InvitationsManager = class {
|
|
|
2779
3072
|
}
|
|
2780
3073
|
});
|
|
2781
3074
|
ctx.onDispose(() => {
|
|
2782
|
-
|
|
3075
|
+
log9("complete", {
|
|
2783
3076
|
...handler.toJSON()
|
|
2784
3077
|
}, {
|
|
2785
|
-
F:
|
|
2786
|
-
L:
|
|
3078
|
+
F: __dxlog_file11,
|
|
3079
|
+
L: 236,
|
|
2787
3080
|
S: this,
|
|
2788
3081
|
C: (f, a) => f(...a)
|
|
2789
3082
|
});
|
|
@@ -2795,7 +3088,7 @@ var InvitationsManager = class {
|
|
|
2795
3088
|
onCancel: async () => {
|
|
2796
3089
|
stream.next({
|
|
2797
3090
|
...invitation,
|
|
2798
|
-
state:
|
|
3091
|
+
state: Invitation6.State.CANCELLED
|
|
2799
3092
|
});
|
|
2800
3093
|
await ctx.dispose();
|
|
2801
3094
|
}
|
|
@@ -2806,8 +3099,73 @@ var InvitationsManager = class {
|
|
|
2806
3099
|
observableInvitation
|
|
2807
3100
|
};
|
|
2808
3101
|
}
|
|
3102
|
+
_createObservableAcceptingInvitation(handler, initialState) {
|
|
3103
|
+
const otpEnteredTrigger = new Trigger4();
|
|
3104
|
+
const stream = new PushStream();
|
|
3105
|
+
const ctx = new Context6({
|
|
3106
|
+
onError: (err) => {
|
|
3107
|
+
if (err instanceof TimeoutError2) {
|
|
3108
|
+
log9("timeout", {
|
|
3109
|
+
...handler.toJSON()
|
|
3110
|
+
}, {
|
|
3111
|
+
F: __dxlog_file11,
|
|
3112
|
+
L: 256,
|
|
3113
|
+
S: this,
|
|
3114
|
+
C: (f, a) => f(...a)
|
|
3115
|
+
});
|
|
3116
|
+
stream.next({
|
|
3117
|
+
...initialState,
|
|
3118
|
+
state: Invitation6.State.TIMEOUT
|
|
3119
|
+
});
|
|
3120
|
+
} else {
|
|
3121
|
+
log9.warn("auth failed", err, {
|
|
3122
|
+
F: __dxlog_file11,
|
|
3123
|
+
L: 259,
|
|
3124
|
+
S: this,
|
|
3125
|
+
C: (f, a) => f(...a)
|
|
3126
|
+
});
|
|
3127
|
+
stream.next({
|
|
3128
|
+
...initialState,
|
|
3129
|
+
state: Invitation6.State.ERROR
|
|
3130
|
+
});
|
|
3131
|
+
}
|
|
3132
|
+
void ctx.dispose();
|
|
3133
|
+
}
|
|
3134
|
+
});
|
|
3135
|
+
ctx.onDispose(() => {
|
|
3136
|
+
log9("complete", {
|
|
3137
|
+
...handler.toJSON()
|
|
3138
|
+
}, {
|
|
3139
|
+
F: __dxlog_file11,
|
|
3140
|
+
L: 266,
|
|
3141
|
+
S: this,
|
|
3142
|
+
C: (f, a) => f(...a)
|
|
3143
|
+
});
|
|
3144
|
+
stream.complete();
|
|
3145
|
+
});
|
|
3146
|
+
const invitation = new AuthenticatingInvitation({
|
|
3147
|
+
initialInvitation: initialState,
|
|
3148
|
+
subscriber: stream.observable,
|
|
3149
|
+
onCancel: async () => {
|
|
3150
|
+
stream.next({
|
|
3151
|
+
...initialState,
|
|
3152
|
+
state: Invitation6.State.CANCELLED
|
|
3153
|
+
});
|
|
3154
|
+
await ctx.dispose();
|
|
3155
|
+
},
|
|
3156
|
+
onAuthenticate: async (code) => {
|
|
3157
|
+
otpEnteredTrigger.wake(code);
|
|
3158
|
+
}
|
|
3159
|
+
});
|
|
3160
|
+
return {
|
|
3161
|
+
ctx,
|
|
3162
|
+
invitation,
|
|
3163
|
+
stream,
|
|
3164
|
+
otpEnteredTrigger
|
|
3165
|
+
};
|
|
3166
|
+
}
|
|
2809
3167
|
async _persistIfRequired(handler, changeStream, invitation) {
|
|
2810
|
-
if (invitation.type ===
|
|
3168
|
+
if (invitation.type === Invitation6.Type.DELEGATED && invitation.delegationCredentialId == null) {
|
|
2811
3169
|
const delegationCredentialId = await handler.delegate(invitation);
|
|
2812
3170
|
changeStream.next({
|
|
2813
3171
|
...invitation,
|
|
@@ -2822,9 +3180,9 @@ var InvitationsManager = class {
|
|
|
2822
3180
|
try {
|
|
2823
3181
|
await this._metadataStore.removeInvitation(invitation.invitationId);
|
|
2824
3182
|
} catch (err) {
|
|
2825
|
-
|
|
2826
|
-
F:
|
|
2827
|
-
L:
|
|
3183
|
+
log9.catch(err, void 0, {
|
|
3184
|
+
F: __dxlog_file11,
|
|
3185
|
+
L: 302,
|
|
2828
3186
|
S: this,
|
|
2829
3187
|
C: (f, a) => f(...a)
|
|
2830
3188
|
});
|
|
@@ -2919,22 +3277,23 @@ ClientRpcServer = _ts_decorate3([
|
|
|
2919
3277
|
], ClientRpcServer);
|
|
2920
3278
|
|
|
2921
3279
|
// packages/sdk/client-services/src/packlets/spaces/data-space.ts
|
|
2922
|
-
import { Event as Event6, asyncTimeout, scheduleTask as
|
|
3280
|
+
import { Event as Event6, asyncTimeout, scheduleTask as scheduleTask5, sleep as sleep2, synchronized, trackLeaks } from "@dxos/async";
|
|
2923
3281
|
import { AUTH_TIMEOUT as AUTH_TIMEOUT2 } from "@dxos/client-protocol";
|
|
2924
|
-
import { cancelWithContext as
|
|
3282
|
+
import { cancelWithContext as cancelWithContext4, Context as Context8, ContextDisposedError as ContextDisposedError3 } from "@dxos/context";
|
|
2925
3283
|
import { timed, warnAfterTimeout } from "@dxos/debug";
|
|
2926
3284
|
import { createMappedFeedWriter } from "@dxos/echo-pipeline";
|
|
2927
3285
|
import { AutomergeDocumentLoaderImpl } from "@dxos/echo-pipeline";
|
|
2928
3286
|
import { TYPE_PROPERTIES } from "@dxos/echo-schema";
|
|
2929
|
-
import { failedInvariant, invariant as
|
|
2930
|
-
import { PublicKey as
|
|
2931
|
-
import { log as
|
|
3287
|
+
import { failedInvariant, invariant as invariant12 } from "@dxos/invariant";
|
|
3288
|
+
import { PublicKey as PublicKey10 } from "@dxos/keys";
|
|
3289
|
+
import { log as log11 } from "@dxos/log";
|
|
2932
3290
|
import { CancelledError, SystemError } from "@dxos/protocols";
|
|
2933
3291
|
import { SpaceState, CreateEpochRequest } from "@dxos/protocols/proto/dxos/client/services";
|
|
3292
|
+
import { SpaceMember as SpaceMember3 } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
2934
3293
|
import { AdmittedFeed as AdmittedFeed3 } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
2935
3294
|
import { Timeframe as Timeframe2 } from "@dxos/timeframe";
|
|
2936
3295
|
import { trace as trace6 } from "@dxos/tracing";
|
|
2937
|
-
import { ComplexSet as
|
|
3296
|
+
import { ComplexSet as ComplexSet5, assignDeep } from "@dxos/util";
|
|
2938
3297
|
|
|
2939
3298
|
// packages/sdk/client-services/src/packlets/spaces/automerge-space-state.ts
|
|
2940
3299
|
import { Event as Event4 } from "@dxos/async";
|
|
@@ -2975,15 +3334,15 @@ var AutomergeSpaceState = class {
|
|
|
2975
3334
|
};
|
|
2976
3335
|
|
|
2977
3336
|
// packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
|
|
2978
|
-
import { DeferredTask, Event as Event5, scheduleTask as
|
|
3337
|
+
import { DeferredTask, Event as Event5, scheduleTask as scheduleTask4, sleep, TimeoutError as TimeoutError3, Trigger as Trigger5 } from "@dxos/async";
|
|
2979
3338
|
import { Context as Context7, rejectOnDispose } from "@dxos/context";
|
|
2980
|
-
import { invariant as
|
|
2981
|
-
import { PublicKey as
|
|
2982
|
-
import { log as
|
|
2983
|
-
import { schema as
|
|
2984
|
-
import { RpcExtension as
|
|
2985
|
-
import { ComplexMap as ComplexMap2, ComplexSet as
|
|
2986
|
-
var
|
|
3339
|
+
import { invariant as invariant11 } from "@dxos/invariant";
|
|
3340
|
+
import { PublicKey as PublicKey9 } from "@dxos/keys";
|
|
3341
|
+
import { log as log10 } from "@dxos/log";
|
|
3342
|
+
import { schema as schema4 } from "@dxos/protocols";
|
|
3343
|
+
import { RpcExtension as RpcExtension3 } from "@dxos/teleport";
|
|
3344
|
+
import { ComplexMap as ComplexMap2, ComplexSet as ComplexSet4, entry } from "@dxos/util";
|
|
3345
|
+
var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
|
|
2987
3346
|
var DEFAULT_RETRY_TIMEOUT = 1e3;
|
|
2988
3347
|
var DEFAULT_SUCCESS_DELAY = 1e3;
|
|
2989
3348
|
var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
|
|
@@ -2993,8 +3352,8 @@ var NotarizationPlugin = class {
|
|
|
2993
3352
|
this._ctx = new Context7();
|
|
2994
3353
|
this._extensionOpened = new Event5();
|
|
2995
3354
|
this._extensions = /* @__PURE__ */ new Set();
|
|
2996
|
-
this._processedCredentials = new
|
|
2997
|
-
this._processCredentialsTriggers = new ComplexMap2(
|
|
3355
|
+
this._processedCredentials = new ComplexSet4(PublicKey9.hash);
|
|
3356
|
+
this._processCredentialsTriggers = new ComplexMap2(PublicKey9.hash);
|
|
2998
3357
|
}
|
|
2999
3358
|
get hasWriter() {
|
|
3000
3359
|
return !!this._writer;
|
|
@@ -3008,16 +3367,16 @@ var NotarizationPlugin = class {
|
|
|
3008
3367
|
* Request credentials to be notarized.
|
|
3009
3368
|
*/
|
|
3010
3369
|
async notarize({ ctx: opCtx, credentials, timeout = DEFAULT_NOTARIZE_TIMEOUT, retryTimeout = DEFAULT_RETRY_TIMEOUT, successDelay = DEFAULT_SUCCESS_DELAY }) {
|
|
3011
|
-
|
|
3370
|
+
log10("notarize", {
|
|
3012
3371
|
credentials
|
|
3013
3372
|
}, {
|
|
3014
|
-
F:
|
|
3373
|
+
F: __dxlog_file12,
|
|
3015
3374
|
L: 90,
|
|
3016
3375
|
S: this,
|
|
3017
3376
|
C: (f, a) => f(...a)
|
|
3018
3377
|
});
|
|
3019
|
-
|
|
3020
|
-
F:
|
|
3378
|
+
invariant11(credentials.every((credential) => credential.id), "Credentials must have an id", {
|
|
3379
|
+
F: __dxlog_file12,
|
|
3021
3380
|
L: 91,
|
|
3022
3381
|
S: this,
|
|
3023
3382
|
A: [
|
|
@@ -3025,13 +3384,13 @@ var NotarizationPlugin = class {
|
|
|
3025
3384
|
"'Credentials must have an id'"
|
|
3026
3385
|
]
|
|
3027
3386
|
});
|
|
3028
|
-
const errors = new
|
|
3387
|
+
const errors = new Trigger5();
|
|
3029
3388
|
const ctx = this._ctx.derive({
|
|
3030
3389
|
onError: (err) => {
|
|
3031
|
-
|
|
3390
|
+
log10.warn("Notarization error", {
|
|
3032
3391
|
err
|
|
3033
3392
|
}, {
|
|
3034
|
-
F:
|
|
3393
|
+
F: __dxlog_file12,
|
|
3035
3394
|
L: 99,
|
|
3036
3395
|
S: this,
|
|
3037
3396
|
C: (f, a) => f(...a)
|
|
@@ -3042,18 +3401,18 @@ var NotarizationPlugin = class {
|
|
|
3042
3401
|
});
|
|
3043
3402
|
opCtx?.onDispose(() => ctx.dispose());
|
|
3044
3403
|
if (timeout !== 0) {
|
|
3045
|
-
|
|
3046
|
-
|
|
3404
|
+
scheduleTask4(ctx, () => {
|
|
3405
|
+
log10.warn("Notarization timeout", {
|
|
3047
3406
|
timeout,
|
|
3048
3407
|
peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
|
|
3049
3408
|
}, {
|
|
3050
|
-
F:
|
|
3409
|
+
F: __dxlog_file12,
|
|
3051
3410
|
L: 111,
|
|
3052
3411
|
S: this,
|
|
3053
3412
|
C: (f, a) => f(...a)
|
|
3054
3413
|
});
|
|
3055
3414
|
void ctx.dispose();
|
|
3056
|
-
errors.throw(new
|
|
3415
|
+
errors.throw(new TimeoutError3(timeout, "Notarization timed out"));
|
|
3057
3416
|
}, timeout);
|
|
3058
3417
|
}
|
|
3059
3418
|
const allNotarized = Promise.all(credentials.map((credential) => this._waitUntilProcessed(credential.id)));
|
|
@@ -3067,24 +3426,24 @@ var NotarizationPlugin = class {
|
|
|
3067
3426
|
...this._extensions
|
|
3068
3427
|
].find((peer2) => !peersTried.has(peer2));
|
|
3069
3428
|
if (!peer) {
|
|
3070
|
-
|
|
3429
|
+
log10.info("Exhausted all peers to notarize with", {
|
|
3071
3430
|
retryIn: retryTimeout
|
|
3072
3431
|
}, {
|
|
3073
|
-
F:
|
|
3432
|
+
F: __dxlog_file12,
|
|
3074
3433
|
L: 136,
|
|
3075
3434
|
S: this,
|
|
3076
3435
|
C: (f, a) => f(...a)
|
|
3077
3436
|
});
|
|
3078
3437
|
peersTried.clear();
|
|
3079
|
-
|
|
3438
|
+
scheduleTask4(ctx, () => notarizeTask.schedule(), retryTimeout);
|
|
3080
3439
|
return;
|
|
3081
3440
|
}
|
|
3082
3441
|
peersTried.add(peer);
|
|
3083
|
-
|
|
3442
|
+
log10("try notarizing", {
|
|
3084
3443
|
peer: peer.localPeerId,
|
|
3085
3444
|
credentialId: credentials.map((credential) => credential.id)
|
|
3086
3445
|
}, {
|
|
3087
|
-
F:
|
|
3446
|
+
F: __dxlog_file12,
|
|
3088
3447
|
L: 143,
|
|
3089
3448
|
S: this,
|
|
3090
3449
|
C: (f, a) => f(...a)
|
|
@@ -3092,8 +3451,8 @@ var NotarizationPlugin = class {
|
|
|
3092
3451
|
await peer.rpc.NotarizationService.notarize({
|
|
3093
3452
|
credentials: credentials.filter((credential) => !this._processedCredentials.has(credential.id))
|
|
3094
3453
|
});
|
|
3095
|
-
|
|
3096
|
-
F:
|
|
3454
|
+
log10("success", void 0, {
|
|
3455
|
+
F: __dxlog_file12,
|
|
3097
3456
|
L: 147,
|
|
3098
3457
|
S: this,
|
|
3099
3458
|
C: (f, a) => f(...a)
|
|
@@ -3101,8 +3460,8 @@ var NotarizationPlugin = class {
|
|
|
3101
3460
|
await sleep(successDelay);
|
|
3102
3461
|
} catch (err) {
|
|
3103
3462
|
if (!ctx.disposed && !err.message.includes(WRITER_NOT_SET_ERROR_CODE)) {
|
|
3104
|
-
|
|
3105
|
-
F:
|
|
3463
|
+
log10.info("error notarizing (recoverable)", err, {
|
|
3464
|
+
F: __dxlog_file12,
|
|
3106
3465
|
L: 151,
|
|
3107
3466
|
S: this,
|
|
3108
3467
|
C: (f, a) => f(...a)
|
|
@@ -3119,8 +3478,8 @@ var NotarizationPlugin = class {
|
|
|
3119
3478
|
allNotarized,
|
|
3120
3479
|
errors.wait()
|
|
3121
3480
|
]);
|
|
3122
|
-
|
|
3123
|
-
F:
|
|
3481
|
+
log10("done", void 0, {
|
|
3482
|
+
F: __dxlog_file12,
|
|
3124
3483
|
L: 162,
|
|
3125
3484
|
S: this,
|
|
3126
3485
|
C: (f, a) => f(...a)
|
|
@@ -3141,8 +3500,8 @@ var NotarizationPlugin = class {
|
|
|
3141
3500
|
this._processCredentialsTriggers.delete(credential.id);
|
|
3142
3501
|
}
|
|
3143
3502
|
setWriter(writer) {
|
|
3144
|
-
|
|
3145
|
-
F:
|
|
3503
|
+
invariant11(!this._writer, "Writer already set.", {
|
|
3504
|
+
F: __dxlog_file12,
|
|
3146
3505
|
L: 181,
|
|
3147
3506
|
S: this,
|
|
3148
3507
|
A: [
|
|
@@ -3156,7 +3515,7 @@ var NotarizationPlugin = class {
|
|
|
3156
3515
|
if (this._processedCredentials.has(id)) {
|
|
3157
3516
|
return;
|
|
3158
3517
|
}
|
|
3159
|
-
await entry(this._processCredentialsTriggers, id).orInsert(new
|
|
3518
|
+
await entry(this._processCredentialsTriggers, id).orInsert(new Trigger5()).value.wait();
|
|
3160
3519
|
}
|
|
3161
3520
|
/**
|
|
3162
3521
|
* Requests from other peers to notarize credentials.
|
|
@@ -3166,8 +3525,8 @@ var NotarizationPlugin = class {
|
|
|
3166
3525
|
throw new Error(WRITER_NOT_SET_ERROR_CODE);
|
|
3167
3526
|
}
|
|
3168
3527
|
for (const credential of request.credentials ?? []) {
|
|
3169
|
-
|
|
3170
|
-
F:
|
|
3528
|
+
invariant11(credential.id, "Credential must have an id", {
|
|
3529
|
+
F: __dxlog_file12,
|
|
3171
3530
|
L: 200,
|
|
3172
3531
|
S: this,
|
|
3173
3532
|
A: [
|
|
@@ -3184,10 +3543,10 @@ var NotarizationPlugin = class {
|
|
|
3184
3543
|
createExtension() {
|
|
3185
3544
|
const extension = new NotarizationTeleportExtension({
|
|
3186
3545
|
onOpen: async () => {
|
|
3187
|
-
|
|
3546
|
+
log10("extension opened", {
|
|
3188
3547
|
peer: extension.localPeerId
|
|
3189
3548
|
}, {
|
|
3190
|
-
F:
|
|
3549
|
+
F: __dxlog_file12,
|
|
3191
3550
|
L: 211,
|
|
3192
3551
|
S: this,
|
|
3193
3552
|
C: (f, a) => f(...a)
|
|
@@ -3196,10 +3555,10 @@ var NotarizationPlugin = class {
|
|
|
3196
3555
|
this._extensionOpened.emit();
|
|
3197
3556
|
},
|
|
3198
3557
|
onClose: async () => {
|
|
3199
|
-
|
|
3558
|
+
log10("extension closed", {
|
|
3200
3559
|
peer: extension.localPeerId
|
|
3201
3560
|
}, {
|
|
3202
|
-
F:
|
|
3561
|
+
F: __dxlog_file12,
|
|
3203
3562
|
L: 216,
|
|
3204
3563
|
S: this,
|
|
3205
3564
|
C: (f, a) => f(...a)
|
|
@@ -3211,14 +3570,14 @@ var NotarizationPlugin = class {
|
|
|
3211
3570
|
return extension;
|
|
3212
3571
|
}
|
|
3213
3572
|
};
|
|
3214
|
-
var NotarizationTeleportExtension = class extends
|
|
3573
|
+
var NotarizationTeleportExtension = class extends RpcExtension3 {
|
|
3215
3574
|
constructor(_params) {
|
|
3216
3575
|
super({
|
|
3217
3576
|
requested: {
|
|
3218
|
-
NotarizationService:
|
|
3577
|
+
NotarizationService: schema4.getService("dxos.mesh.teleport.notarization.NotarizationService")
|
|
3219
3578
|
},
|
|
3220
3579
|
exposed: {
|
|
3221
|
-
NotarizationService:
|
|
3580
|
+
NotarizationService: schema4.getService("dxos.mesh.teleport.notarization.NotarizationService")
|
|
3222
3581
|
}
|
|
3223
3582
|
});
|
|
3224
3583
|
this._params = _params;
|
|
@@ -3253,7 +3612,7 @@ function _ts_decorate4(decorators, target, key, desc) {
|
|
|
3253
3612
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
3254
3613
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3255
3614
|
}
|
|
3256
|
-
var
|
|
3615
|
+
var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
|
|
3257
3616
|
var DataSpace = class {
|
|
3258
3617
|
constructor(params) {
|
|
3259
3618
|
this._ctx = new Context8();
|
|
@@ -3279,17 +3638,17 @@ var DataSpace = class {
|
|
|
3279
3638
|
this._callbacks = params.callbacks ?? {};
|
|
3280
3639
|
this._echoHost = params.echoHost;
|
|
3281
3640
|
this.authVerifier = new TrustedKeySetAuthVerifier({
|
|
3282
|
-
trustedKeysProvider: () => new
|
|
3641
|
+
trustedKeysProvider: () => new ComplexSet5(PublicKey10.hash, Array.from(this._inner.spaceState.members.values()).filter((member) => member.role !== SpaceMember3.Role.REMOVED).map((member) => member.key)),
|
|
3283
3642
|
update: this._inner.stateUpdate,
|
|
3284
3643
|
authTimeout: AUTH_TIMEOUT2
|
|
3285
3644
|
});
|
|
3286
3645
|
this._cache = params.cache;
|
|
3287
3646
|
this._state = params.initialState;
|
|
3288
|
-
|
|
3647
|
+
log11("new state", {
|
|
3289
3648
|
state: SpaceState[this._state]
|
|
3290
3649
|
}, {
|
|
3291
|
-
F:
|
|
3292
|
-
L:
|
|
3650
|
+
F: __dxlog_file13,
|
|
3651
|
+
L: 137,
|
|
3293
3652
|
S: this,
|
|
3294
3653
|
C: (f, a) => f(...a)
|
|
3295
3654
|
});
|
|
@@ -3335,11 +3694,11 @@ var DataSpace = class {
|
|
|
3335
3694
|
await this._inner.spaceState.addCredentialProcessor(this._automergeSpaceState);
|
|
3336
3695
|
await this._inner.open(new Context8());
|
|
3337
3696
|
this._state = SpaceState.CONTROL_ONLY;
|
|
3338
|
-
|
|
3697
|
+
log11("new state", {
|
|
3339
3698
|
state: SpaceState[this._state]
|
|
3340
3699
|
}, {
|
|
3341
|
-
F:
|
|
3342
|
-
L:
|
|
3700
|
+
F: __dxlog_file13,
|
|
3701
|
+
L: 195,
|
|
3343
3702
|
S: this,
|
|
3344
3703
|
C: (f, a) => f(...a)
|
|
3345
3704
|
});
|
|
@@ -3353,11 +3712,11 @@ var DataSpace = class {
|
|
|
3353
3712
|
async _close() {
|
|
3354
3713
|
await this._callbacks.beforeClose?.();
|
|
3355
3714
|
this._state = SpaceState.CLOSED;
|
|
3356
|
-
|
|
3715
|
+
log11("new state", {
|
|
3357
3716
|
state: SpaceState[this._state]
|
|
3358
3717
|
}, {
|
|
3359
|
-
F:
|
|
3360
|
-
L:
|
|
3718
|
+
F: __dxlog_file13,
|
|
3719
|
+
L: 209,
|
|
3361
3720
|
S: this,
|
|
3362
3721
|
C: (f, a) => f(...a)
|
|
3363
3722
|
});
|
|
@@ -3381,32 +3740,32 @@ var DataSpace = class {
|
|
|
3381
3740
|
* Initialize the data pipeline in a separate task.
|
|
3382
3741
|
*/
|
|
3383
3742
|
initializeDataPipelineAsync() {
|
|
3384
|
-
|
|
3743
|
+
scheduleTask5(this._ctx, async () => {
|
|
3385
3744
|
try {
|
|
3386
3745
|
this.metrics.pipelineInitBegin = /* @__PURE__ */ new Date();
|
|
3387
3746
|
await this.initializeDataPipeline();
|
|
3388
3747
|
} catch (err) {
|
|
3389
|
-
if (err instanceof CancelledError || err instanceof
|
|
3390
|
-
|
|
3391
|
-
F:
|
|
3392
|
-
L:
|
|
3748
|
+
if (err instanceof CancelledError || err instanceof ContextDisposedError3) {
|
|
3749
|
+
log11("data pipeline initialization cancelled", err, {
|
|
3750
|
+
F: __dxlog_file13,
|
|
3751
|
+
L: 242,
|
|
3393
3752
|
S: this,
|
|
3394
3753
|
C: (f, a) => f(...a)
|
|
3395
3754
|
});
|
|
3396
3755
|
return;
|
|
3397
3756
|
}
|
|
3398
|
-
|
|
3399
|
-
F:
|
|
3400
|
-
L:
|
|
3757
|
+
log11.error("Error initializing data pipeline", err, {
|
|
3758
|
+
F: __dxlog_file13,
|
|
3759
|
+
L: 246,
|
|
3401
3760
|
S: this,
|
|
3402
3761
|
C: (f, a) => f(...a)
|
|
3403
3762
|
});
|
|
3404
3763
|
this._state = SpaceState.ERROR;
|
|
3405
|
-
|
|
3764
|
+
log11("new state", {
|
|
3406
3765
|
state: SpaceState[this._state]
|
|
3407
3766
|
}, {
|
|
3408
|
-
F:
|
|
3409
|
-
L:
|
|
3767
|
+
F: __dxlog_file13,
|
|
3768
|
+
L: 248,
|
|
3410
3769
|
S: this,
|
|
3411
3770
|
C: (f, a) => f(...a)
|
|
3412
3771
|
});
|
|
@@ -3422,31 +3781,31 @@ var DataSpace = class {
|
|
|
3422
3781
|
throw new SystemError("Invalid operation");
|
|
3423
3782
|
}
|
|
3424
3783
|
this._state = SpaceState.INITIALIZING;
|
|
3425
|
-
|
|
3784
|
+
log11("new state", {
|
|
3426
3785
|
state: SpaceState[this._state]
|
|
3427
3786
|
}, {
|
|
3428
|
-
F:
|
|
3429
|
-
L:
|
|
3787
|
+
F: __dxlog_file13,
|
|
3788
|
+
L: 264,
|
|
3430
3789
|
S: this,
|
|
3431
3790
|
C: (f, a) => f(...a)
|
|
3432
3791
|
});
|
|
3433
3792
|
await this._initializeAndReadControlPipeline();
|
|
3434
3793
|
await sleep2(1);
|
|
3435
3794
|
this._automergeSpaceState.startProcessingRootDocs();
|
|
3436
|
-
await
|
|
3437
|
-
|
|
3438
|
-
F:
|
|
3439
|
-
L:
|
|
3795
|
+
await cancelWithContext4(this._ctx, this.automergeSpaceState.ensureEpochInitialized());
|
|
3796
|
+
log11("data pipeline ready", void 0, {
|
|
3797
|
+
F: __dxlog_file13,
|
|
3798
|
+
L: 276,
|
|
3440
3799
|
S: this,
|
|
3441
3800
|
C: (f, a) => f(...a)
|
|
3442
3801
|
});
|
|
3443
3802
|
await this._callbacks.beforeReady?.();
|
|
3444
3803
|
this._state = SpaceState.READY;
|
|
3445
|
-
|
|
3804
|
+
log11("new state", {
|
|
3446
3805
|
state: SpaceState[this._state]
|
|
3447
3806
|
}, {
|
|
3448
|
-
F:
|
|
3449
|
-
L:
|
|
3807
|
+
F: __dxlog_file13,
|
|
3808
|
+
L: 280,
|
|
3450
3809
|
S: this,
|
|
3451
3810
|
C: (f, a) => f(...a)
|
|
3452
3811
|
});
|
|
@@ -3460,9 +3819,9 @@ var DataSpace = class {
|
|
|
3460
3819
|
});
|
|
3461
3820
|
this.metrics.controlPipelineReady = /* @__PURE__ */ new Date();
|
|
3462
3821
|
await this._createWritableFeeds();
|
|
3463
|
-
|
|
3464
|
-
F:
|
|
3465
|
-
L:
|
|
3822
|
+
log11("writable feeds created", void 0, {
|
|
3823
|
+
F: __dxlog_file13,
|
|
3824
|
+
L: 296,
|
|
3466
3825
|
S: this,
|
|
3467
3826
|
C: (f, a) => f(...a)
|
|
3468
3827
|
});
|
|
@@ -3520,12 +3879,12 @@ var DataSpace = class {
|
|
|
3520
3879
|
}
|
|
3521
3880
|
}
|
|
3522
3881
|
_onNewAutomergeRoot(rootUrl) {
|
|
3523
|
-
|
|
3882
|
+
log11("loading automerge root doc for space", {
|
|
3524
3883
|
space: this.key,
|
|
3525
3884
|
rootUrl
|
|
3526
3885
|
}, {
|
|
3527
|
-
F:
|
|
3528
|
-
L:
|
|
3886
|
+
F: __dxlog_file13,
|
|
3887
|
+
L: 362,
|
|
3529
3888
|
S: this,
|
|
3530
3889
|
C: (f, a) => f(...a)
|
|
3531
3890
|
});
|
|
@@ -3534,7 +3893,7 @@ var DataSpace = class {
|
|
|
3534
3893
|
queueMicrotask(async () => {
|
|
3535
3894
|
try {
|
|
3536
3895
|
await warnAfterTimeout(5e3, "Automerge root doc load timeout (DataSpace)", async () => {
|
|
3537
|
-
await
|
|
3896
|
+
await cancelWithContext4(this._ctx, handle.whenReady());
|
|
3538
3897
|
});
|
|
3539
3898
|
if (this._ctx.disposed) {
|
|
3540
3899
|
return;
|
|
@@ -3548,16 +3907,16 @@ var DataSpace = class {
|
|
|
3548
3907
|
});
|
|
3549
3908
|
}
|
|
3550
3909
|
} catch (err) {
|
|
3551
|
-
if (err instanceof
|
|
3910
|
+
if (err instanceof ContextDisposedError3) {
|
|
3552
3911
|
return;
|
|
3553
3912
|
}
|
|
3554
|
-
|
|
3913
|
+
log11.warn("error loading automerge root doc", {
|
|
3555
3914
|
space: this.key,
|
|
3556
3915
|
rootUrl,
|
|
3557
3916
|
err
|
|
3558
3917
|
}, {
|
|
3559
|
-
F:
|
|
3560
|
-
L:
|
|
3918
|
+
F: __dxlog_file13,
|
|
3919
|
+
L: 385,
|
|
3561
3920
|
S: this,
|
|
3562
3921
|
C: (f, a) => f(...a)
|
|
3563
3922
|
});
|
|
@@ -3608,11 +3967,11 @@ var DataSpace = class {
|
|
|
3608
3967
|
{
|
|
3609
3968
|
const currentRootUrl = this._automergeSpaceState.rootUrl;
|
|
3610
3969
|
const rootHandle = this._echoHost.automergeRepo.find(currentRootUrl);
|
|
3611
|
-
await
|
|
3970
|
+
await cancelWithContext4(this._ctx, asyncTimeout(rootHandle.whenReady(), 1e4));
|
|
3612
3971
|
const newRoot = this._echoHost.automergeRepo.create(rootHandle.docSync());
|
|
3613
|
-
|
|
3614
|
-
F:
|
|
3615
|
-
L:
|
|
3972
|
+
invariant12(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
|
|
3973
|
+
F: __dxlog_file13,
|
|
3974
|
+
L: 435,
|
|
3616
3975
|
S: this,
|
|
3617
3976
|
A: [
|
|
3618
3977
|
"typeof newRoot.url === 'string' && newRoot.url.length > 0",
|
|
@@ -3629,21 +3988,21 @@ var DataSpace = class {
|
|
|
3629
3988
|
break;
|
|
3630
3989
|
case CreateEpochRequest.Migration.FRAGMENT_AUTOMERGE_ROOT:
|
|
3631
3990
|
{
|
|
3632
|
-
|
|
3633
|
-
F:
|
|
3634
|
-
L:
|
|
3991
|
+
log11.info("Fragmenting", void 0, {
|
|
3992
|
+
F: __dxlog_file13,
|
|
3993
|
+
L: 447,
|
|
3635
3994
|
S: this,
|
|
3636
3995
|
C: (f, a) => f(...a)
|
|
3637
3996
|
});
|
|
3638
3997
|
const currentRootUrl = this._automergeSpaceState.rootUrl;
|
|
3639
3998
|
const rootHandle = this._echoHost.automergeRepo.find(currentRootUrl);
|
|
3640
|
-
await
|
|
3999
|
+
await cancelWithContext4(this._ctx, asyncTimeout(rootHandle.whenReady(), 1e4));
|
|
3641
4000
|
const objects = Object.entries(rootHandle.docSync().objects);
|
|
3642
4001
|
const properties = objects.find(([_, value]) => value.system.type?.itemId === TYPE_PROPERTIES);
|
|
3643
4002
|
const otherObjects = objects.filter(([key]) => key !== properties?.[0]);
|
|
3644
|
-
|
|
3645
|
-
F:
|
|
3646
|
-
L:
|
|
4003
|
+
invariant12(properties, "Properties not found", {
|
|
4004
|
+
F: __dxlog_file13,
|
|
4005
|
+
L: 457,
|
|
3647
4006
|
S: this,
|
|
3648
4007
|
A: [
|
|
3649
4008
|
"properties",
|
|
@@ -3657,9 +4016,9 @@ var DataSpace = class {
|
|
|
3657
4016
|
])
|
|
3658
4017
|
};
|
|
3659
4018
|
const newRoot = this._echoHost.automergeRepo.create(newSpaceDoc);
|
|
3660
|
-
|
|
3661
|
-
F:
|
|
3662
|
-
L:
|
|
4019
|
+
invariant12(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
|
|
4020
|
+
F: __dxlog_file13,
|
|
4021
|
+
L: 462,
|
|
3663
4022
|
S: this,
|
|
3664
4023
|
A: [
|
|
3665
4024
|
"typeof newRoot.url === 'string' && newRoot.url.length > 0",
|
|
@@ -3724,11 +4083,11 @@ var DataSpace = class {
|
|
|
3724
4083
|
await this._metadataStore.setSpaceState(this.key, SpaceState.INACTIVE);
|
|
3725
4084
|
await this._close();
|
|
3726
4085
|
this._state = SpaceState.INACTIVE;
|
|
3727
|
-
|
|
4086
|
+
log11("new state", {
|
|
3728
4087
|
state: SpaceState[this._state]
|
|
3729
4088
|
}, {
|
|
3730
|
-
F:
|
|
3731
|
-
L:
|
|
4089
|
+
F: __dxlog_file13,
|
|
4090
|
+
L: 528,
|
|
3732
4091
|
S: this,
|
|
3733
4092
|
C: (f, a) => f(...a)
|
|
3734
4093
|
});
|
|
@@ -3783,20 +4142,20 @@ DataSpace = _ts_decorate4([
|
|
|
3783
4142
|
|
|
3784
4143
|
// packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
|
|
3785
4144
|
import { Event as Event7, synchronized as synchronized2, trackLeaks as trackLeaks2 } from "@dxos/async";
|
|
3786
|
-
import { Context as Context9, cancelWithContext as
|
|
4145
|
+
import { Context as Context9, cancelWithContext as cancelWithContext5 } from "@dxos/context";
|
|
3787
4146
|
import { getCredentialAssertion as getCredentialAssertion2 } from "@dxos/credentials";
|
|
3788
|
-
import { invariant as
|
|
3789
|
-
import { PublicKey as
|
|
3790
|
-
import { log as
|
|
4147
|
+
import { invariant as invariant13 } from "@dxos/invariant";
|
|
4148
|
+
import { PublicKey as PublicKey11 } from "@dxos/keys";
|
|
4149
|
+
import { log as log12 } from "@dxos/log";
|
|
3791
4150
|
import { trace as trace7 } from "@dxos/protocols";
|
|
3792
|
-
import { Invitation as
|
|
4151
|
+
import { Invitation as Invitation7, SpaceState as SpaceState2 } from "@dxos/protocols/proto/dxos/client/services";
|
|
3793
4152
|
import { Gossip as Gossip2, Presence as Presence2 } from "@dxos/teleport-extension-gossip";
|
|
3794
4153
|
import { ComplexMap as ComplexMap3, deferFunction as deferFunction2, forEachAsync } from "@dxos/util";
|
|
3795
4154
|
|
|
3796
4155
|
// packages/sdk/client-services/src/packlets/spaces/genesis.ts
|
|
3797
4156
|
import { createCredential } from "@dxos/credentials";
|
|
3798
4157
|
import { failUndefined } from "@dxos/debug";
|
|
3799
|
-
import { AdmittedFeed as AdmittedFeed4, SpaceMember as
|
|
4158
|
+
import { AdmittedFeed as AdmittedFeed4, SpaceMember as SpaceMember4 } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
3800
4159
|
import { Timeframe as Timeframe3 } from "@dxos/timeframe";
|
|
3801
4160
|
var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
|
|
3802
4161
|
const credentials = [
|
|
@@ -3816,7 +4175,7 @@ var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
|
|
|
3816
4175
|
assertion: {
|
|
3817
4176
|
"@type": "dxos.halo.credentials.SpaceMember",
|
|
3818
4177
|
spaceKey: space.key,
|
|
3819
|
-
role:
|
|
4178
|
+
role: SpaceMember4.Role.OWNER,
|
|
3820
4179
|
profile: signingContext.getProfile(),
|
|
3821
4180
|
genesisFeedKey: space.controlFeedKey ?? failUndefined()
|
|
3822
4181
|
}
|
|
@@ -3874,7 +4233,7 @@ function _ts_decorate5(decorators, target, key, desc) {
|
|
|
3874
4233
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
3875
4234
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3876
4235
|
}
|
|
3877
|
-
var
|
|
4236
|
+
var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
|
|
3878
4237
|
var PRESENCE_ANNOUNCE_INTERVAL = 1e4;
|
|
3879
4238
|
var PRESENCE_OFFLINE_TIMEOUT = 2e4;
|
|
3880
4239
|
var DataSpaceManager = class {
|
|
@@ -3888,9 +4247,9 @@ var DataSpaceManager = class {
|
|
|
3888
4247
|
this._invitationsManager = _invitationsManager;
|
|
3889
4248
|
this._ctx = new Context9();
|
|
3890
4249
|
this.updated = new Event7();
|
|
3891
|
-
this._spaces = new ComplexMap3(
|
|
4250
|
+
this._spaces = new ComplexMap3(PublicKey11.hash);
|
|
3892
4251
|
this._isOpen = false;
|
|
3893
|
-
this._instanceId =
|
|
4252
|
+
this._instanceId = PublicKey11.random().toHex();
|
|
3894
4253
|
const { spaceMemberPresenceAnnounceInterval = PRESENCE_ANNOUNCE_INTERVAL, spaceMemberPresenceOfflineTimeout = PRESENCE_OFFLINE_TIMEOUT } = params ?? {};
|
|
3895
4254
|
this._spaceMemberPresenceAnnounceInterval = spaceMemberPresenceAnnounceInterval;
|
|
3896
4255
|
this._spaceMemberPresenceOfflineTimeout = spaceMemberPresenceOfflineTimeout;
|
|
@@ -3900,45 +4259,45 @@ var DataSpaceManager = class {
|
|
|
3900
4259
|
return this._spaces;
|
|
3901
4260
|
}
|
|
3902
4261
|
async open() {
|
|
3903
|
-
|
|
3904
|
-
F:
|
|
4262
|
+
log12("open", void 0, {
|
|
4263
|
+
F: __dxlog_file14,
|
|
3905
4264
|
L: 102,
|
|
3906
4265
|
S: this,
|
|
3907
4266
|
C: (f, a) => f(...a)
|
|
3908
4267
|
});
|
|
3909
|
-
|
|
4268
|
+
log12.trace("dxos.echo.data-space-manager.open", trace7.begin({
|
|
3910
4269
|
id: this._instanceId
|
|
3911
4270
|
}), {
|
|
3912
|
-
F:
|
|
4271
|
+
F: __dxlog_file14,
|
|
3913
4272
|
L: 103,
|
|
3914
4273
|
S: this,
|
|
3915
4274
|
C: (f, a) => f(...a)
|
|
3916
4275
|
});
|
|
3917
|
-
|
|
4276
|
+
log12("metadata loaded", {
|
|
3918
4277
|
spaces: this._metadataStore.spaces.length
|
|
3919
4278
|
}, {
|
|
3920
|
-
F:
|
|
4279
|
+
F: __dxlog_file14,
|
|
3921
4280
|
L: 104,
|
|
3922
4281
|
S: this,
|
|
3923
4282
|
C: (f, a) => f(...a)
|
|
3924
4283
|
});
|
|
3925
4284
|
await forEachAsync(this._metadataStore.spaces, async (spaceMetadata) => {
|
|
3926
4285
|
try {
|
|
3927
|
-
|
|
4286
|
+
log12("load space", {
|
|
3928
4287
|
spaceMetadata
|
|
3929
4288
|
}, {
|
|
3930
|
-
F:
|
|
4289
|
+
F: __dxlog_file14,
|
|
3931
4290
|
L: 108,
|
|
3932
4291
|
S: this,
|
|
3933
4292
|
C: (f, a) => f(...a)
|
|
3934
4293
|
});
|
|
3935
4294
|
await this._constructSpace(spaceMetadata);
|
|
3936
4295
|
} catch (err) {
|
|
3937
|
-
|
|
4296
|
+
log12.error("Error loading space", {
|
|
3938
4297
|
spaceMetadata,
|
|
3939
4298
|
err
|
|
3940
4299
|
}, {
|
|
3941
|
-
F:
|
|
4300
|
+
F: __dxlog_file14,
|
|
3942
4301
|
L: 111,
|
|
3943
4302
|
S: this,
|
|
3944
4303
|
C: (f, a) => f(...a)
|
|
@@ -3952,18 +4311,18 @@ var DataSpaceManager = class {
|
|
|
3952
4311
|
space.initializeDataPipelineAsync();
|
|
3953
4312
|
}
|
|
3954
4313
|
}
|
|
3955
|
-
|
|
4314
|
+
log12.trace("dxos.echo.data-space-manager.open", trace7.end({
|
|
3956
4315
|
id: this._instanceId
|
|
3957
4316
|
}), {
|
|
3958
|
-
F:
|
|
4317
|
+
F: __dxlog_file14,
|
|
3959
4318
|
L: 124,
|
|
3960
4319
|
S: this,
|
|
3961
4320
|
C: (f, a) => f(...a)
|
|
3962
4321
|
});
|
|
3963
4322
|
}
|
|
3964
4323
|
async close() {
|
|
3965
|
-
|
|
3966
|
-
F:
|
|
4324
|
+
log12("close", void 0, {
|
|
4325
|
+
F: __dxlog_file14,
|
|
3967
4326
|
L: 129,
|
|
3968
4327
|
S: this,
|
|
3969
4328
|
C: (f, a) => f(...a)
|
|
@@ -3978,8 +4337,8 @@ var DataSpaceManager = class {
|
|
|
3978
4337
|
* Creates a new space writing the genesis credentials to the control feed.
|
|
3979
4338
|
*/
|
|
3980
4339
|
async createSpace() {
|
|
3981
|
-
|
|
3982
|
-
F:
|
|
4340
|
+
invariant13(this._isOpen, "Not open.", {
|
|
4341
|
+
F: __dxlog_file14,
|
|
3983
4342
|
L: 142,
|
|
3984
4343
|
S: this,
|
|
3985
4344
|
A: [
|
|
@@ -3997,10 +4356,10 @@ var DataSpaceManager = class {
|
|
|
3997
4356
|
dataFeedKey,
|
|
3998
4357
|
state: SpaceState2.ACTIVE
|
|
3999
4358
|
};
|
|
4000
|
-
|
|
4359
|
+
log12("creating space...", {
|
|
4001
4360
|
spaceKey
|
|
4002
4361
|
}, {
|
|
4003
|
-
F:
|
|
4362
|
+
F: __dxlog_file14,
|
|
4004
4363
|
L: 154,
|
|
4005
4364
|
S: this,
|
|
4006
4365
|
C: (f, a) => f(...a)
|
|
@@ -4010,8 +4369,8 @@ var DataSpaceManager = class {
|
|
|
4010
4369
|
const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner, automergeRootUrl);
|
|
4011
4370
|
await this._metadataStore.addSpace(metadata);
|
|
4012
4371
|
const memberCredential = credentials[1];
|
|
4013
|
-
|
|
4014
|
-
F:
|
|
4372
|
+
invariant13(getCredentialAssertion2(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
|
|
4373
|
+
F: __dxlog_file14,
|
|
4015
4374
|
L: 163,
|
|
4016
4375
|
S: this,
|
|
4017
4376
|
A: [
|
|
@@ -4026,16 +4385,16 @@ var DataSpaceManager = class {
|
|
|
4026
4385
|
}
|
|
4027
4386
|
// TODO(burdon): Rename join space.
|
|
4028
4387
|
async acceptSpace(opts) {
|
|
4029
|
-
|
|
4388
|
+
log12("accept space", {
|
|
4030
4389
|
opts
|
|
4031
4390
|
}, {
|
|
4032
|
-
F:
|
|
4391
|
+
F: __dxlog_file14,
|
|
4033
4392
|
L: 175,
|
|
4034
4393
|
S: this,
|
|
4035
4394
|
C: (f, a) => f(...a)
|
|
4036
4395
|
});
|
|
4037
|
-
|
|
4038
|
-
F:
|
|
4396
|
+
invariant13(this._isOpen, "Not open.", {
|
|
4397
|
+
F: __dxlog_file14,
|
|
4039
4398
|
L: 176,
|
|
4040
4399
|
S: this,
|
|
4041
4400
|
A: [
|
|
@@ -4043,8 +4402,8 @@ var DataSpaceManager = class {
|
|
|
4043
4402
|
"'Not open.'"
|
|
4044
4403
|
]
|
|
4045
4404
|
});
|
|
4046
|
-
|
|
4047
|
-
F:
|
|
4405
|
+
invariant13(!this._spaces.has(opts.spaceKey), "Space already exists.", {
|
|
4406
|
+
F: __dxlog_file14,
|
|
4048
4407
|
L: 177,
|
|
4049
4408
|
S: this,
|
|
4050
4409
|
A: [
|
|
@@ -4070,16 +4429,16 @@ var DataSpaceManager = class {
|
|
|
4070
4429
|
* TODO(dmaretskyi): Consider removing.
|
|
4071
4430
|
*/
|
|
4072
4431
|
async waitUntilSpaceReady(spaceKey) {
|
|
4073
|
-
await
|
|
4432
|
+
await cancelWithContext5(this._ctx, this.updated.waitForCondition(() => {
|
|
4074
4433
|
const space = this._spaces.get(spaceKey);
|
|
4075
4434
|
return !!space && space.state === SpaceState2.READY;
|
|
4076
4435
|
}));
|
|
4077
4436
|
}
|
|
4078
4437
|
async _constructSpace(metadata) {
|
|
4079
|
-
|
|
4438
|
+
log12("construct space", {
|
|
4080
4439
|
metadata
|
|
4081
4440
|
}, {
|
|
4082
|
-
F:
|
|
4441
|
+
F: __dxlog_file14,
|
|
4083
4442
|
L: 210,
|
|
4084
4443
|
S: this,
|
|
4085
4444
|
C: (f, a) => f(...a)
|
|
@@ -4116,8 +4475,8 @@ var DataSpaceManager = class {
|
|
|
4116
4475
|
session.addExtension("dxos.mesh.teleport.automerge", this._echoHost.createReplicationExtension());
|
|
4117
4476
|
},
|
|
4118
4477
|
onAuthFailure: () => {
|
|
4119
|
-
|
|
4120
|
-
F:
|
|
4478
|
+
log12.warn("auth failure", void 0, {
|
|
4479
|
+
F: __dxlog_file14,
|
|
4121
4480
|
L: 247,
|
|
4122
4481
|
S: this,
|
|
4123
4482
|
C: (f, a) => f(...a)
|
|
@@ -4142,21 +4501,21 @@ var DataSpaceManager = class {
|
|
|
4142
4501
|
signingContext: this._signingContext,
|
|
4143
4502
|
callbacks: {
|
|
4144
4503
|
beforeReady: async () => {
|
|
4145
|
-
|
|
4504
|
+
log12("before space ready", {
|
|
4146
4505
|
space: space.key
|
|
4147
4506
|
}, {
|
|
4148
|
-
F:
|
|
4507
|
+
F: __dxlog_file14,
|
|
4149
4508
|
L: 269,
|
|
4150
4509
|
S: this,
|
|
4151
4510
|
C: (f, a) => f(...a)
|
|
4152
4511
|
});
|
|
4153
4512
|
},
|
|
4154
4513
|
afterReady: async () => {
|
|
4155
|
-
|
|
4514
|
+
log12("after space ready", {
|
|
4156
4515
|
space: space.key,
|
|
4157
4516
|
open: this._isOpen
|
|
4158
4517
|
}, {
|
|
4159
|
-
F:
|
|
4518
|
+
F: __dxlog_file14,
|
|
4160
4519
|
L: 272,
|
|
4161
4520
|
S: this,
|
|
4162
4521
|
C: (f, a) => f(...a)
|
|
@@ -4169,10 +4528,10 @@ var DataSpaceManager = class {
|
|
|
4169
4528
|
}
|
|
4170
4529
|
},
|
|
4171
4530
|
beforeClose: async () => {
|
|
4172
|
-
|
|
4531
|
+
log12("before space close", {
|
|
4173
4532
|
space: space.key
|
|
4174
4533
|
}, {
|
|
4175
|
-
F:
|
|
4534
|
+
F: __dxlog_file14,
|
|
4176
4535
|
L: 279,
|
|
4177
4536
|
S: this,
|
|
4178
4537
|
C: (f, a) => f(...a)
|
|
@@ -4208,8 +4567,8 @@ var DataSpaceManager = class {
|
|
|
4208
4567
|
async _createDelegatedInvitations(space, invitations) {
|
|
4209
4568
|
const tasks = invitations.map(([credentialId, invitation]) => {
|
|
4210
4569
|
return this._invitationsManager.createInvitation({
|
|
4211
|
-
type:
|
|
4212
|
-
kind:
|
|
4570
|
+
type: Invitation7.Type.DELEGATED,
|
|
4571
|
+
kind: Invitation7.Kind.SPACE,
|
|
4213
4572
|
spaceKey: space.key,
|
|
4214
4573
|
authMethod: invitation.authMethod,
|
|
4215
4574
|
invitationId: invitation.invitationId,
|
|
@@ -4243,14 +4602,15 @@ DataSpaceManager = _ts_decorate5([
|
|
|
4243
4602
|
], DataSpaceManager);
|
|
4244
4603
|
|
|
4245
4604
|
// packages/sdk/client-services/src/packlets/spaces/spaces-service.ts
|
|
4246
|
-
import { EventSubscriptions as EventSubscriptions2, UpdateScheduler, scheduleTask as
|
|
4605
|
+
import { EventSubscriptions as EventSubscriptions2, UpdateScheduler, scheduleTask as scheduleTask6 } from "@dxos/async";
|
|
4247
4606
|
import { Stream as Stream10 } from "@dxos/codec-protobuf";
|
|
4248
4607
|
import { raise as raise2 } from "@dxos/debug";
|
|
4249
|
-
import { invariant as
|
|
4250
|
-
import { log as
|
|
4608
|
+
import { invariant as invariant14 } from "@dxos/invariant";
|
|
4609
|
+
import { log as log13 } from "@dxos/log";
|
|
4251
4610
|
import { ApiError, SpaceNotFoundError, encodeError } from "@dxos/protocols";
|
|
4252
|
-
import { SpaceMember as
|
|
4253
|
-
|
|
4611
|
+
import { SpaceMember as SpaceMember5, SpaceState as SpaceState3 } from "@dxos/protocols/proto/dxos/client/services";
|
|
4612
|
+
import { SpaceMember as HaloSpaceMember } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
4613
|
+
var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
|
|
4254
4614
|
var SpacesServiceImpl = class {
|
|
4255
4615
|
constructor(_identityManager, _spaceManager, _getDataSpaceManager) {
|
|
4256
4616
|
this._identityManager = _identityManager;
|
|
@@ -4281,16 +4641,19 @@ var SpacesServiceImpl = class {
|
|
|
4281
4641
|
}
|
|
4282
4642
|
}
|
|
4283
4643
|
}
|
|
4644
|
+
async updateMemberRole(_) {
|
|
4645
|
+
throw new Error("not implemented");
|
|
4646
|
+
}
|
|
4284
4647
|
querySpaces() {
|
|
4285
4648
|
return new Stream10(({ next, ctx }) => {
|
|
4286
4649
|
const scheduler = new UpdateScheduler(ctx, async () => {
|
|
4287
4650
|
const dataSpaceManager = await this._getDataSpaceManager();
|
|
4288
4651
|
const spaces = Array.from(dataSpaceManager.spaces.values()).map((space) => this._serializeSpace(space));
|
|
4289
|
-
|
|
4652
|
+
log13("update", {
|
|
4290
4653
|
spaces
|
|
4291
4654
|
}, {
|
|
4292
|
-
F:
|
|
4293
|
-
L:
|
|
4655
|
+
F: __dxlog_file15,
|
|
4656
|
+
L: 82,
|
|
4294
4657
|
S: this,
|
|
4295
4658
|
C: (f, a) => f(...a)
|
|
4296
4659
|
});
|
|
@@ -4300,7 +4663,7 @@ var SpacesServiceImpl = class {
|
|
|
4300
4663
|
}, {
|
|
4301
4664
|
maxFrequency: false ? void 0 : 2
|
|
4302
4665
|
});
|
|
4303
|
-
|
|
4666
|
+
scheduleTask6(ctx, async () => {
|
|
4304
4667
|
const dataSpaceManager = await this._getDataSpaceManager();
|
|
4305
4668
|
const subscriptions = new EventSubscriptions2();
|
|
4306
4669
|
ctx.onDispose(() => subscriptions.clear());
|
|
@@ -4334,7 +4697,7 @@ var SpacesServiceImpl = class {
|
|
|
4334
4697
|
}
|
|
4335
4698
|
subscribeMessages({ spaceKey, channel }) {
|
|
4336
4699
|
return new Stream10(({ ctx, next }) => {
|
|
4337
|
-
|
|
4700
|
+
scheduleTask6(ctx, async () => {
|
|
4338
4701
|
const dataSpaceManager = await this._getDataSpaceManager();
|
|
4339
4702
|
const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError(spaceKey));
|
|
4340
4703
|
const handle = space.listen(getChannelId(channel), (message) => {
|
|
@@ -4353,7 +4716,7 @@ var SpacesServiceImpl = class {
|
|
|
4353
4716
|
}
|
|
4354
4717
|
};
|
|
4355
4718
|
ctx.onDispose(() => space.spaceState.removeCredentialProcessor(processor));
|
|
4356
|
-
|
|
4719
|
+
scheduleTask6(ctx, async () => {
|
|
4357
4720
|
await space.spaceState.addCredentialProcessor(processor);
|
|
4358
4721
|
if (noTail) {
|
|
4359
4722
|
close();
|
|
@@ -4371,18 +4734,18 @@ var SpacesServiceImpl = class {
|
|
|
4371
4734
|
}
|
|
4372
4735
|
});
|
|
4373
4736
|
} else {
|
|
4374
|
-
|
|
4375
|
-
F:
|
|
4376
|
-
L:
|
|
4737
|
+
invariant14(!credential.id, "Id on unsigned credentials is not allowed", {
|
|
4738
|
+
F: __dxlog_file15,
|
|
4739
|
+
L: 169,
|
|
4377
4740
|
S: this,
|
|
4378
4741
|
A: [
|
|
4379
4742
|
"!credential.id",
|
|
4380
4743
|
"'Id on unsigned credentials is not allowed'"
|
|
4381
4744
|
]
|
|
4382
4745
|
});
|
|
4383
|
-
|
|
4384
|
-
F:
|
|
4385
|
-
L:
|
|
4746
|
+
invariant14(this._identityManager.identity, "Identity is not available", {
|
|
4747
|
+
F: __dxlog_file15,
|
|
4748
|
+
L: 170,
|
|
4386
4749
|
S: this,
|
|
4387
4750
|
A: [
|
|
4388
4751
|
"this._identityManager.identity",
|
|
@@ -4390,9 +4753,9 @@ var SpacesServiceImpl = class {
|
|
|
4390
4753
|
]
|
|
4391
4754
|
});
|
|
4392
4755
|
const signer = this._identityManager.identity.getIdentityCredentialSigner();
|
|
4393
|
-
|
|
4394
|
-
F:
|
|
4395
|
-
L:
|
|
4756
|
+
invariant14(credential.issuer.equals(signer.getIssuer()), void 0, {
|
|
4757
|
+
F: __dxlog_file15,
|
|
4758
|
+
L: 172,
|
|
4396
4759
|
S: this,
|
|
4397
4760
|
A: [
|
|
4398
4761
|
"credential.issuer.equals(signer.getIssuer())",
|
|
@@ -4447,7 +4810,7 @@ var SpacesServiceImpl = class {
|
|
|
4447
4810
|
identityKey: member.key,
|
|
4448
4811
|
profile: member.profile ?? {}
|
|
4449
4812
|
},
|
|
4450
|
-
presence: member.
|
|
4813
|
+
presence: member.role === HaloSpaceMember.Role.REMOVED ? SpaceMember5.PresenceState.REMOVED : isMe || peers.length > 0 ? SpaceMember5.PresenceState.ONLINE : SpaceMember5.PresenceState.OFFLINE,
|
|
4451
4814
|
peerStates: peers
|
|
4452
4815
|
};
|
|
4453
4816
|
}),
|
|
@@ -4460,19 +4823,19 @@ var SpacesServiceImpl = class {
|
|
|
4460
4823
|
var getChannelId = (channel) => `user-channel/${channel}`;
|
|
4461
4824
|
|
|
4462
4825
|
// packages/sdk/client-services/src/packlets/services/service-context.ts
|
|
4463
|
-
import { Trigger as
|
|
4826
|
+
import { Trigger as Trigger6 } from "@dxos/async";
|
|
4464
4827
|
import { Context as Context10, Resource } from "@dxos/context";
|
|
4465
4828
|
import { getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
|
|
4466
4829
|
import { failUndefined as failUndefined2 } from "@dxos/debug";
|
|
4467
4830
|
import { EchoHost } from "@dxos/echo-db";
|
|
4468
4831
|
import { MetadataStore, SnapshotStore, SpaceManager, valueEncoding } from "@dxos/echo-pipeline";
|
|
4469
4832
|
import { FeedFactory, FeedStore } from "@dxos/feed-store";
|
|
4470
|
-
import { invariant as
|
|
4833
|
+
import { invariant as invariant15 } from "@dxos/invariant";
|
|
4471
4834
|
import { Keyring } from "@dxos/keyring";
|
|
4472
|
-
import { PublicKey as
|
|
4473
|
-
import { log as
|
|
4835
|
+
import { PublicKey as PublicKey12 } from "@dxos/keys";
|
|
4836
|
+
import { log as log14 } from "@dxos/log";
|
|
4474
4837
|
import { InvalidStorageVersionError, STORAGE_VERSION, trace as trace8 } from "@dxos/protocols";
|
|
4475
|
-
import { Invitation as
|
|
4838
|
+
import { Invitation as Invitation8 } from "@dxos/protocols/proto/dxos/client/services";
|
|
4476
4839
|
import { BlobStore } from "@dxos/teleport-extension-object-sync";
|
|
4477
4840
|
import { trace as Trace2 } from "@dxos/tracing";
|
|
4478
4841
|
import { safeInstanceof } from "@dxos/util";
|
|
@@ -4486,7 +4849,7 @@ function _ts_decorate6(decorators, target, key, desc) {
|
|
|
4486
4849
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
4487
4850
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
4488
4851
|
}
|
|
4489
|
-
var
|
|
4852
|
+
var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
|
|
4490
4853
|
var ServiceContext = class extends Resource {
|
|
4491
4854
|
constructor(storage, level, networkManager, signalManager, _runtimeParams) {
|
|
4492
4855
|
super();
|
|
@@ -4495,9 +4858,9 @@ var ServiceContext = class extends Resource {
|
|
|
4495
4858
|
this.networkManager = networkManager;
|
|
4496
4859
|
this.signalManager = signalManager;
|
|
4497
4860
|
this._runtimeParams = _runtimeParams;
|
|
4498
|
-
this.initialized = new
|
|
4861
|
+
this.initialized = new Trigger6();
|
|
4499
4862
|
this._handlerFactories = /* @__PURE__ */ new Map();
|
|
4500
|
-
this._instanceId =
|
|
4863
|
+
this._instanceId = PublicKey12.random().toHex();
|
|
4501
4864
|
this.metadataStore = new MetadataStore(storage.createDirectory("metadata"));
|
|
4502
4865
|
this.snapshotStore = new SnapshotStore(storage.createDirectory("snapshots"));
|
|
4503
4866
|
this.blobStore = new BlobStore(storage.createDirectory("blobs"));
|
|
@@ -4524,23 +4887,23 @@ var ServiceContext = class extends Resource {
|
|
|
4524
4887
|
kv: this.level,
|
|
4525
4888
|
storage: this.storage
|
|
4526
4889
|
});
|
|
4527
|
-
this.invitations = new InvitationsHandler(this.networkManager);
|
|
4890
|
+
this.invitations = new InvitationsHandler(this.networkManager, _runtimeParams?.invitationConnectionDefaultParams);
|
|
4528
4891
|
this.invitationsManager = new InvitationsManager(this.invitations, (invitation) => this.getInvitationHandler(invitation), this.metadataStore);
|
|
4529
|
-
this._handlerFactories.set(
|
|
4892
|
+
this._handlerFactories.set(Invitation8.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? failUndefined2(), this._acceptIdentity.bind(this)));
|
|
4530
4893
|
}
|
|
4531
4894
|
async _open(ctx) {
|
|
4532
4895
|
await this._checkStorageVersion();
|
|
4533
|
-
|
|
4534
|
-
F:
|
|
4535
|
-
L:
|
|
4896
|
+
log14("opening...", void 0, {
|
|
4897
|
+
F: __dxlog_file16,
|
|
4898
|
+
L: 152,
|
|
4536
4899
|
S: this,
|
|
4537
4900
|
C: (f, a) => f(...a)
|
|
4538
4901
|
});
|
|
4539
|
-
|
|
4902
|
+
log14.trace("dxos.sdk.service-context.open", trace8.begin({
|
|
4540
4903
|
id: this._instanceId
|
|
4541
4904
|
}), {
|
|
4542
|
-
F:
|
|
4543
|
-
L:
|
|
4905
|
+
F: __dxlog_file16,
|
|
4906
|
+
L: 153,
|
|
4544
4907
|
S: this,
|
|
4545
4908
|
C: (f, a) => f(...a)
|
|
4546
4909
|
});
|
|
@@ -4554,33 +4917,33 @@ var ServiceContext = class extends Resource {
|
|
|
4554
4917
|
await this._initialize(ctx);
|
|
4555
4918
|
}
|
|
4556
4919
|
const loadedInvitations = await this.invitationsManager.loadPersistentInvitations();
|
|
4557
|
-
|
|
4920
|
+
log14("loaded persistent invitations", {
|
|
4558
4921
|
count: loadedInvitations.invitations?.length
|
|
4559
4922
|
}, {
|
|
4560
|
-
F:
|
|
4561
|
-
L:
|
|
4923
|
+
F: __dxlog_file16,
|
|
4924
|
+
L: 166,
|
|
4562
4925
|
S: this,
|
|
4563
4926
|
C: (f, a) => f(...a)
|
|
4564
4927
|
});
|
|
4565
|
-
|
|
4928
|
+
log14.trace("dxos.sdk.service-context.open", trace8.end({
|
|
4566
4929
|
id: this._instanceId
|
|
4567
4930
|
}), {
|
|
4568
|
-
F:
|
|
4569
|
-
L:
|
|
4931
|
+
F: __dxlog_file16,
|
|
4932
|
+
L: 168,
|
|
4570
4933
|
S: this,
|
|
4571
4934
|
C: (f, a) => f(...a)
|
|
4572
4935
|
});
|
|
4573
|
-
|
|
4574
|
-
F:
|
|
4575
|
-
L:
|
|
4936
|
+
log14("opened", void 0, {
|
|
4937
|
+
F: __dxlog_file16,
|
|
4938
|
+
L: 169,
|
|
4576
4939
|
S: this,
|
|
4577
4940
|
C: (f, a) => f(...a)
|
|
4578
4941
|
});
|
|
4579
4942
|
}
|
|
4580
4943
|
async _close(ctx) {
|
|
4581
|
-
|
|
4582
|
-
F:
|
|
4583
|
-
L:
|
|
4944
|
+
log14("closing...", void 0, {
|
|
4945
|
+
F: __dxlog_file16,
|
|
4946
|
+
L: 173,
|
|
4584
4947
|
S: this,
|
|
4585
4948
|
C: (f, a) => f(...a)
|
|
4586
4949
|
});
|
|
@@ -4595,9 +4958,9 @@ var ServiceContext = class extends Resource {
|
|
|
4595
4958
|
await this.echoHost.close(ctx);
|
|
4596
4959
|
await this.networkManager.close();
|
|
4597
4960
|
await this.signalManager.close();
|
|
4598
|
-
|
|
4599
|
-
F:
|
|
4600
|
-
L:
|
|
4961
|
+
log14("closed", void 0, {
|
|
4962
|
+
F: __dxlog_file16,
|
|
4963
|
+
L: 185,
|
|
4601
4964
|
S: this,
|
|
4602
4965
|
C: (f, a) => f(...a)
|
|
4603
4966
|
});
|
|
@@ -4609,9 +4972,9 @@ var ServiceContext = class extends Resource {
|
|
|
4609
4972
|
}
|
|
4610
4973
|
getInvitationHandler(invitation) {
|
|
4611
4974
|
const factory = this._handlerFactories.get(invitation.kind);
|
|
4612
|
-
|
|
4613
|
-
F:
|
|
4614
|
-
L:
|
|
4975
|
+
invariant15(factory, `Unknown invitation kind: ${invitation.kind}`, {
|
|
4976
|
+
F: __dxlog_file16,
|
|
4977
|
+
L: 196,
|
|
4615
4978
|
S: this,
|
|
4616
4979
|
A: [
|
|
4617
4980
|
"factory",
|
|
@@ -4641,9 +5004,9 @@ var ServiceContext = class extends Resource {
|
|
|
4641
5004
|
}
|
|
4642
5005
|
// Called when identity is created.
|
|
4643
5006
|
async _initialize(ctx) {
|
|
4644
|
-
|
|
4645
|
-
F:
|
|
4646
|
-
L:
|
|
5007
|
+
log14("initializing spaces...", void 0, {
|
|
5008
|
+
F: __dxlog_file16,
|
|
5009
|
+
L: 227,
|
|
4647
5010
|
S: this,
|
|
4648
5011
|
C: (f, a) => f(...a)
|
|
4649
5012
|
});
|
|
@@ -4663,10 +5026,10 @@ var ServiceContext = class extends Resource {
|
|
|
4663
5026
|
};
|
|
4664
5027
|
this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.keyring, signingContext, this.feedStore, this.echoHost, this.invitationsManager, this._runtimeParams);
|
|
4665
5028
|
await this.dataSpaceManager.open();
|
|
4666
|
-
this._handlerFactories.set(
|
|
4667
|
-
|
|
4668
|
-
F:
|
|
4669
|
-
L:
|
|
5029
|
+
this._handlerFactories.set(Invitation8.Kind.SPACE, (invitation) => {
|
|
5030
|
+
invariant15(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
|
|
5031
|
+
F: __dxlog_file16,
|
|
5032
|
+
L: 252,
|
|
4670
5033
|
S: this,
|
|
4671
5034
|
A: [
|
|
4672
5035
|
"this.dataSpaceManager",
|
|
@@ -4686,33 +5049,33 @@ var ServiceContext = class extends Resource {
|
|
|
4686
5049
|
return;
|
|
4687
5050
|
}
|
|
4688
5051
|
if (!this.dataSpaceManager) {
|
|
4689
|
-
|
|
5052
|
+
log14("dataSpaceManager not initialized yet, ignoring space admission", {
|
|
4690
5053
|
details: assertion
|
|
4691
5054
|
}, {
|
|
4692
|
-
F:
|
|
4693
|
-
L:
|
|
5055
|
+
F: __dxlog_file16,
|
|
5056
|
+
L: 268,
|
|
4694
5057
|
S: this,
|
|
4695
5058
|
C: (f, a) => f(...a)
|
|
4696
5059
|
});
|
|
4697
5060
|
return;
|
|
4698
5061
|
}
|
|
4699
5062
|
if (this.dataSpaceManager.spaces.has(assertion.spaceKey)) {
|
|
4700
|
-
|
|
5063
|
+
log14("space already exists, ignoring space admission", {
|
|
4701
5064
|
details: assertion
|
|
4702
5065
|
}, {
|
|
4703
|
-
F:
|
|
4704
|
-
L:
|
|
5066
|
+
F: __dxlog_file16,
|
|
5067
|
+
L: 272,
|
|
4705
5068
|
S: this,
|
|
4706
5069
|
C: (f, a) => f(...a)
|
|
4707
5070
|
});
|
|
4708
5071
|
return;
|
|
4709
5072
|
}
|
|
4710
5073
|
try {
|
|
4711
|
-
|
|
5074
|
+
log14("accepting space recorded in halo", {
|
|
4712
5075
|
details: assertion
|
|
4713
5076
|
}, {
|
|
4714
|
-
F:
|
|
4715
|
-
L:
|
|
5077
|
+
F: __dxlog_file16,
|
|
5078
|
+
L: 277,
|
|
4716
5079
|
S: this,
|
|
4717
5080
|
C: (f, a) => f(...a)
|
|
4718
5081
|
});
|
|
@@ -4721,9 +5084,9 @@ var ServiceContext = class extends Resource {
|
|
|
4721
5084
|
genesisFeedKey: assertion.genesisFeedKey
|
|
4722
5085
|
});
|
|
4723
5086
|
} catch (err) {
|
|
4724
|
-
|
|
4725
|
-
F:
|
|
4726
|
-
L:
|
|
5087
|
+
log14.catch(err, void 0, {
|
|
5088
|
+
F: __dxlog_file16,
|
|
5089
|
+
L: 283,
|
|
4727
5090
|
S: this,
|
|
4728
5091
|
C: (f, a) => f(...a)
|
|
4729
5092
|
});
|
|
@@ -4769,15 +5132,16 @@ var ServiceRegistry = class {
|
|
|
4769
5132
|
};
|
|
4770
5133
|
|
|
4771
5134
|
// packages/sdk/client-services/src/packlets/diagnostics/diagnostics.ts
|
|
5135
|
+
import { asyncTimeout as asyncTimeout2 } from "@dxos/async";
|
|
4772
5136
|
import { getFirstStreamValue } from "@dxos/codec-protobuf";
|
|
4773
5137
|
import { credentialTypeFilter } from "@dxos/credentials";
|
|
4774
|
-
import { invariant as
|
|
5138
|
+
import { invariant as invariant16 } from "@dxos/invariant";
|
|
4775
5139
|
import { STORAGE_VERSION as STORAGE_VERSION2 } from "@dxos/protocols";
|
|
4776
|
-
import { SpaceMember as
|
|
5140
|
+
import { SpaceMember as SpaceMember6 } from "@dxos/protocols/proto/dxos/client/services";
|
|
4777
5141
|
import { TRACE_PROCESSOR } from "@dxos/tracing";
|
|
4778
5142
|
|
|
4779
5143
|
// packages/sdk/client-services/src/version.ts
|
|
4780
|
-
var DXOS_VERSION = "0.5.1-main.
|
|
5144
|
+
var DXOS_VERSION = "0.5.1-main.c4f37e4";
|
|
4781
5145
|
|
|
4782
5146
|
// packages/sdk/client-services/src/packlets/services/platform.ts
|
|
4783
5147
|
import { Platform } from "@dxos/protocols/proto/dxos/client/services";
|
|
@@ -4810,7 +5174,7 @@ var getPlatform = () => {
|
|
|
4810
5174
|
};
|
|
4811
5175
|
|
|
4812
5176
|
// packages/sdk/client-services/src/packlets/diagnostics/diagnostics.ts
|
|
4813
|
-
var
|
|
5177
|
+
var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/diagnostics/diagnostics.ts";
|
|
4814
5178
|
var DEFAULT_TIMEOUT = 1e3;
|
|
4815
5179
|
var createDiagnostics = async (clientServices, serviceContext, config) => {
|
|
4816
5180
|
const diagnostics = {
|
|
@@ -4824,63 +5188,55 @@ var createDiagnostics = async (clientServices, serviceContext, config) => {
|
|
|
4824
5188
|
},
|
|
4825
5189
|
trace: TRACE_PROCESSOR.getDiagnostics()
|
|
4826
5190
|
};
|
|
4827
|
-
|
|
4828
|
-
|
|
4829
|
-
|
|
4830
|
-
|
|
4831
|
-
|
|
4832
|
-
|
|
4833
|
-
|
|
4834
|
-
|
|
4835
|
-
|
|
4836
|
-
|
|
4837
|
-
|
|
4838
|
-
|
|
4839
|
-
|
|
4840
|
-
|
|
4841
|
-
|
|
4842
|
-
|
|
4843
|
-
|
|
4844
|
-
|
|
4845
|
-
|
|
4846
|
-
|
|
4847
|
-
|
|
5191
|
+
await Promise.all([
|
|
5192
|
+
(async () => {
|
|
5193
|
+
invariant16(clientServices.LoggingService, "SystemService is not available.", {
|
|
5194
|
+
F: __dxlog_file17,
|
|
5195
|
+
L: 110,
|
|
5196
|
+
S: void 0,
|
|
5197
|
+
A: [
|
|
5198
|
+
"clientServices.LoggingService",
|
|
5199
|
+
"'SystemService is not available.'"
|
|
5200
|
+
]
|
|
5201
|
+
});
|
|
5202
|
+
diagnostics.metrics = await getFirstStreamValue(clientServices.LoggingService.queryMetrics({}), {
|
|
5203
|
+
timeout: DEFAULT_TIMEOUT
|
|
5204
|
+
}).catch(() => void 0);
|
|
5205
|
+
})(),
|
|
5206
|
+
(async () => {
|
|
5207
|
+
diagnostics.storage = await asyncTimeout2(getStorageDiagnostics(), DEFAULT_TIMEOUT).catch(() => void 0);
|
|
5208
|
+
})(),
|
|
5209
|
+
async () => {
|
|
5210
|
+
const identity = serviceContext.identityManager.identity;
|
|
5211
|
+
if (identity) {
|
|
5212
|
+
diagnostics.identity = {
|
|
5213
|
+
identityKey: identity.identityKey,
|
|
5214
|
+
spaceKey: identity.space.key,
|
|
5215
|
+
profile: identity.profileDocument
|
|
5216
|
+
};
|
|
5217
|
+
const { devices } = await getFirstStreamValue(clientServices.DevicesService.queryDevices(), {
|
|
5218
|
+
timeout: DEFAULT_TIMEOUT
|
|
5219
|
+
}).catch(() => void 0) ?? {};
|
|
5220
|
+
diagnostics.devices = devices;
|
|
5221
|
+
if (serviceContext.dataSpaceManager) {
|
|
5222
|
+
diagnostics.spaces = await Promise.all(Array.from(serviceContext.dataSpaceManager.spaces.values()).map((space) => getSpaceStats(space)) ?? []);
|
|
5223
|
+
}
|
|
5224
|
+
const { feeds = [] } = await getFirstStreamValue(clientServices.DevtoolsHost.subscribeToFeeds({}), {
|
|
5225
|
+
timeout: DEFAULT_TIMEOUT
|
|
5226
|
+
}).catch(() => void 0) ?? {};
|
|
5227
|
+
diagnostics.feeds = feeds.map(({ feedKey, bytes, length }) => ({
|
|
5228
|
+
feedKey,
|
|
5229
|
+
bytes,
|
|
5230
|
+
length
|
|
5231
|
+
}));
|
|
5232
|
+
const status = await getFirstStreamValue(clientServices.NetworkService.queryStatus(), {
|
|
5233
|
+
timeout: DEFAULT_TIMEOUT
|
|
5234
|
+
}).catch(() => void 0);
|
|
5235
|
+
diagnostics.networkStatus = status;
|
|
5236
|
+
diagnostics.swarms = serviceContext.networkManager.connectionLog?.swarms;
|
|
4848
5237
|
}
|
|
4849
|
-
map.set(filename.slice(0, idx), (map.get(filename.slice(0, idx)) ?? 0) + 1);
|
|
4850
|
-
}
|
|
4851
|
-
diagnostics.storage = Array.from(map.entries()).sort((a, b) => b[1] - a[1]).map(([file, count]) => ({
|
|
4852
|
-
file,
|
|
4853
|
-
count
|
|
4854
|
-
}));
|
|
4855
|
-
}
|
|
4856
|
-
const identity = serviceContext.identityManager.identity;
|
|
4857
|
-
if (identity) {
|
|
4858
|
-
diagnostics.identity = {
|
|
4859
|
-
identityKey: identity.identityKey,
|
|
4860
|
-
spaceKey: identity.space.key,
|
|
4861
|
-
profile: identity.profileDocument
|
|
4862
|
-
};
|
|
4863
|
-
const { devices } = await getFirstStreamValue(clientServices.DevicesService.queryDevices(), {
|
|
4864
|
-
timeout: DEFAULT_TIMEOUT
|
|
4865
|
-
}).catch(() => void 0) ?? {};
|
|
4866
|
-
diagnostics.devices = devices;
|
|
4867
|
-
if (serviceContext.dataSpaceManager) {
|
|
4868
|
-
diagnostics.spaces = await Promise.all(Array.from(serviceContext.dataSpaceManager.spaces.values()).map((space) => getSpaceStats(space)) ?? []);
|
|
4869
5238
|
}
|
|
4870
|
-
|
|
4871
|
-
timeout: DEFAULT_TIMEOUT
|
|
4872
|
-
}).catch(() => void 0) ?? {};
|
|
4873
|
-
diagnostics.feeds = feeds.map(({ feedKey, bytes, length }) => ({
|
|
4874
|
-
feedKey,
|
|
4875
|
-
bytes,
|
|
4876
|
-
length
|
|
4877
|
-
}));
|
|
4878
|
-
const status = await getFirstStreamValue(clientServices.NetworkService.queryStatus(), {
|
|
4879
|
-
timeout: DEFAULT_TIMEOUT
|
|
4880
|
-
}).catch(() => void 0);
|
|
4881
|
-
diagnostics.networkStatus = status;
|
|
4882
|
-
diagnostics.swarms = serviceContext.networkManager.connectionLog?.swarms;
|
|
4883
|
-
}
|
|
5239
|
+
]);
|
|
4884
5240
|
diagnostics.config = config.values;
|
|
4885
5241
|
return diagnostics;
|
|
4886
5242
|
};
|
|
@@ -4899,7 +5255,7 @@ var getSpaceStats = async (space) => {
|
|
|
4899
5255
|
displayName: member.assertion.profile?.displayName
|
|
4900
5256
|
}
|
|
4901
5257
|
},
|
|
4902
|
-
presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ?
|
|
5258
|
+
presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? SpaceMember6.PresenceState.ONLINE : SpaceMember6.PresenceState.OFFLINE
|
|
4903
5259
|
})),
|
|
4904
5260
|
pipeline: {
|
|
4905
5261
|
// TODO(burdon): Pick properties from credentials if needed.
|
|
@@ -4917,11 +5273,29 @@ var getSpaceStats = async (space) => {
|
|
|
4917
5273
|
}
|
|
4918
5274
|
return stats;
|
|
4919
5275
|
};
|
|
5276
|
+
var getStorageDiagnostics = async () => {
|
|
5277
|
+
if (typeof navigator === "undefined" || !navigator.storage) {
|
|
5278
|
+
return void 0;
|
|
5279
|
+
}
|
|
5280
|
+
const map = /* @__PURE__ */ new Map();
|
|
5281
|
+
const dir = await navigator.storage.getDirectory();
|
|
5282
|
+
for await (const filename of dir?.keys()) {
|
|
5283
|
+
const idx = filename.indexOf("-", filename.indexOf("-") + 1);
|
|
5284
|
+
if (idx === -1) {
|
|
5285
|
+
continue;
|
|
5286
|
+
}
|
|
5287
|
+
map.set(filename.slice(0, idx), (map.get(filename.slice(0, idx)) ?? 0) + 1);
|
|
5288
|
+
}
|
|
5289
|
+
return Array.from(map.entries()).sort((a, b) => b[1] - a[1]).map(([file, count]) => ({
|
|
5290
|
+
file,
|
|
5291
|
+
count
|
|
5292
|
+
}));
|
|
5293
|
+
};
|
|
4920
5294
|
|
|
4921
5295
|
// packages/sdk/client-services/src/packlets/diagnostics/browser-diagnostics-broadcast.ts
|
|
4922
|
-
import { Trigger as
|
|
4923
|
-
import { log as
|
|
4924
|
-
var
|
|
5296
|
+
import { Trigger as Trigger7 } from "@dxos/async";
|
|
5297
|
+
import { log as log15 } from "@dxos/log";
|
|
5298
|
+
var __dxlog_file18 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/diagnostics/browser-diagnostics-broadcast.ts";
|
|
4925
5299
|
var CHANNEL_NAME = "dxos.diagnostics.broadcast";
|
|
4926
5300
|
var MessageType;
|
|
4927
5301
|
(function(MessageType2) {
|
|
@@ -4936,7 +5310,7 @@ var createCollectDiagnosticsBroadcastSender = () => {
|
|
|
4936
5310
|
let expectedResponse = "probe-ack";
|
|
4937
5311
|
let channel;
|
|
4938
5312
|
try {
|
|
4939
|
-
const trigger = new
|
|
5313
|
+
const trigger = new Trigger7();
|
|
4940
5314
|
channel = new BroadcastChannel(CHANNEL_NAME);
|
|
4941
5315
|
channel.onmessage = (msg) => {
|
|
4942
5316
|
if (expectedResponse === msg.data.type) {
|
|
@@ -4989,8 +5363,8 @@ var createCollectDiagnosticsBroadcastHandler = (systemService) => {
|
|
|
4989
5363
|
});
|
|
4990
5364
|
}
|
|
4991
5365
|
} catch (error) {
|
|
4992
|
-
|
|
4993
|
-
F:
|
|
5366
|
+
log15.catch(error, void 0, {
|
|
5367
|
+
F: __dxlog_file18,
|
|
4994
5368
|
L: 77,
|
|
4995
5369
|
S: void 0,
|
|
4996
5370
|
C: (f, a) => f(...a)
|
|
@@ -5021,11 +5395,11 @@ import { jsonKeyReplacer as jsonKeyReplacer2, nonNullable } from "@dxos/util";
|
|
|
5021
5395
|
import { Event as Event9, synchronized as synchronized3 } from "@dxos/async";
|
|
5022
5396
|
import { clientServiceBundle, defaultKey, Properties } from "@dxos/client-protocol";
|
|
5023
5397
|
import { Context as Context11 } from "@dxos/context";
|
|
5024
|
-
import { encodeReference } from "@dxos/echo-
|
|
5398
|
+
import { encodeReference } from "@dxos/echo-protocol";
|
|
5025
5399
|
import { getTypeReference } from "@dxos/echo-schema";
|
|
5026
|
-
import { invariant as
|
|
5027
|
-
import { PublicKey as
|
|
5028
|
-
import { log as
|
|
5400
|
+
import { invariant as invariant18 } from "@dxos/invariant";
|
|
5401
|
+
import { PublicKey as PublicKey15 } from "@dxos/keys";
|
|
5402
|
+
import { log as log18 } from "@dxos/log";
|
|
5029
5403
|
import { WebsocketSignalManager } from "@dxos/messaging";
|
|
5030
5404
|
import { NetworkManager, createSimplePeerTransportFactory } from "@dxos/network-manager";
|
|
5031
5405
|
import { trace as trace9 } from "@dxos/protocols";
|
|
@@ -5037,9 +5411,9 @@ import { WebsocketRpcClient } from "@dxos/websocket-rpc";
|
|
|
5037
5411
|
// packages/sdk/client-services/src/packlets/devices/devices-service.ts
|
|
5038
5412
|
import { EventSubscriptions as EventSubscriptions3 } from "@dxos/async";
|
|
5039
5413
|
import { Stream as Stream11 } from "@dxos/codec-protobuf";
|
|
5040
|
-
import { invariant as
|
|
5414
|
+
import { invariant as invariant17 } from "@dxos/invariant";
|
|
5041
5415
|
import { Device as Device2, DeviceKind as DeviceKind2 } from "@dxos/protocols/proto/dxos/client/services";
|
|
5042
|
-
var
|
|
5416
|
+
var __dxlog_file19 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
|
|
5043
5417
|
var DevicesServiceImpl = class {
|
|
5044
5418
|
constructor(_identityManager) {
|
|
5045
5419
|
this._identityManager = _identityManager;
|
|
@@ -5056,8 +5430,8 @@ var DevicesServiceImpl = class {
|
|
|
5056
5430
|
devices: []
|
|
5057
5431
|
});
|
|
5058
5432
|
} else {
|
|
5059
|
-
|
|
5060
|
-
F:
|
|
5433
|
+
invariant17(this._identityManager.identity?.presence, "presence not present", {
|
|
5434
|
+
F: __dxlog_file19,
|
|
5061
5435
|
L: 32,
|
|
5062
5436
|
S: this,
|
|
5063
5437
|
A: [
|
|
@@ -5117,9 +5491,9 @@ var DevicesServiceImpl = class {
|
|
|
5117
5491
|
};
|
|
5118
5492
|
|
|
5119
5493
|
// packages/sdk/client-services/src/packlets/locks/browser.ts
|
|
5120
|
-
import { asyncTimeout as
|
|
5494
|
+
import { asyncTimeout as asyncTimeout3, Trigger as Trigger8 } from "@dxos/async";
|
|
5121
5495
|
import { RESOURCE_LOCK_TIMEOUT } from "@dxos/client-protocol";
|
|
5122
|
-
import { log as
|
|
5496
|
+
import { log as log16, logInfo } from "@dxos/log";
|
|
5123
5497
|
function _ts_decorate7(decorators, target, key, desc) {
|
|
5124
5498
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
5125
5499
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -5130,7 +5504,7 @@ function _ts_decorate7(decorators, target, key, desc) {
|
|
|
5130
5504
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5131
5505
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
5132
5506
|
}
|
|
5133
|
-
var
|
|
5507
|
+
var __dxlog_file20 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
|
|
5134
5508
|
var Message;
|
|
5135
5509
|
(function(Message2) {
|
|
5136
5510
|
Message2["ACQUIRING"] = "acquiring";
|
|
@@ -5138,7 +5512,7 @@ var Message;
|
|
|
5138
5512
|
var Lock = class {
|
|
5139
5513
|
constructor({ lockKey, onAcquire, onRelease }) {
|
|
5140
5514
|
this._broadcastChannel = new BroadcastChannel("vault-resource-lock");
|
|
5141
|
-
this._releaseTrigger = new
|
|
5515
|
+
this._releaseTrigger = new Trigger8();
|
|
5142
5516
|
this._lockKey = lockKey;
|
|
5143
5517
|
this._onAcquire = onAcquire;
|
|
5144
5518
|
this._onRelease = onRelease;
|
|
@@ -5152,29 +5526,29 @@ var Lock = class {
|
|
|
5152
5526
|
message: "acquiring"
|
|
5153
5527
|
});
|
|
5154
5528
|
try {
|
|
5155
|
-
|
|
5156
|
-
F:
|
|
5529
|
+
log16("aquiring lock...", void 0, {
|
|
5530
|
+
F: __dxlog_file20,
|
|
5157
5531
|
L: 42,
|
|
5158
5532
|
S: this,
|
|
5159
5533
|
C: (f, a) => f(...a)
|
|
5160
5534
|
});
|
|
5161
|
-
await
|
|
5162
|
-
|
|
5163
|
-
F:
|
|
5535
|
+
await asyncTimeout3(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
|
|
5536
|
+
log16("acquired lock", void 0, {
|
|
5537
|
+
F: __dxlog_file20,
|
|
5164
5538
|
L: 44,
|
|
5165
5539
|
S: this,
|
|
5166
5540
|
C: (f, a) => f(...a)
|
|
5167
5541
|
});
|
|
5168
5542
|
} catch {
|
|
5169
|
-
|
|
5170
|
-
F:
|
|
5543
|
+
log16("stealing lock...", void 0, {
|
|
5544
|
+
F: __dxlog_file20,
|
|
5171
5545
|
L: 46,
|
|
5172
5546
|
S: this,
|
|
5173
5547
|
C: (f, a) => f(...a)
|
|
5174
5548
|
});
|
|
5175
5549
|
await this._requestLock(true);
|
|
5176
|
-
|
|
5177
|
-
F:
|
|
5550
|
+
log16("stolen lock", void 0, {
|
|
5551
|
+
F: __dxlog_file20,
|
|
5178
5552
|
L: 48,
|
|
5179
5553
|
S: this,
|
|
5180
5554
|
C: (f, a) => f(...a)
|
|
@@ -5190,31 +5564,31 @@ var Lock = class {
|
|
|
5190
5564
|
}
|
|
5191
5565
|
}
|
|
5192
5566
|
async _requestLock(steal = false) {
|
|
5193
|
-
|
|
5567
|
+
log16("requesting lock...", {
|
|
5194
5568
|
steal
|
|
5195
5569
|
}, {
|
|
5196
|
-
F:
|
|
5570
|
+
F: __dxlog_file20,
|
|
5197
5571
|
L: 63,
|
|
5198
5572
|
S: this,
|
|
5199
5573
|
C: (f, a) => f(...a)
|
|
5200
5574
|
});
|
|
5201
|
-
const acquired = new
|
|
5575
|
+
const acquired = new Trigger8();
|
|
5202
5576
|
void navigator.locks.request(this._lockKey, {
|
|
5203
5577
|
steal
|
|
5204
5578
|
}, async () => {
|
|
5205
5579
|
await this._onAcquire?.();
|
|
5206
5580
|
acquired.wake();
|
|
5207
|
-
this._releaseTrigger = new
|
|
5581
|
+
this._releaseTrigger = new Trigger8();
|
|
5208
5582
|
await this._releaseTrigger.wait();
|
|
5209
|
-
|
|
5210
|
-
F:
|
|
5583
|
+
log16("releasing lock...", void 0, {
|
|
5584
|
+
F: __dxlog_file20,
|
|
5211
5585
|
L: 72,
|
|
5212
5586
|
S: this,
|
|
5213
5587
|
C: (f, a) => f(...a)
|
|
5214
5588
|
});
|
|
5215
5589
|
await this._onRelease?.();
|
|
5216
|
-
|
|
5217
|
-
F:
|
|
5590
|
+
log16("released lock", void 0, {
|
|
5591
|
+
F: __dxlog_file20,
|
|
5218
5592
|
L: 74,
|
|
5219
5593
|
S: this,
|
|
5220
5594
|
C: (f, a) => f(...a)
|
|
@@ -5223,10 +5597,10 @@ var Lock = class {
|
|
|
5223
5597
|
await this._onRelease?.();
|
|
5224
5598
|
});
|
|
5225
5599
|
await acquired.wait();
|
|
5226
|
-
|
|
5600
|
+
log16("recieved lock", {
|
|
5227
5601
|
steal
|
|
5228
5602
|
}, {
|
|
5229
|
-
F:
|
|
5603
|
+
F: __dxlog_file20,
|
|
5230
5604
|
L: 81,
|
|
5231
5605
|
S: this,
|
|
5232
5606
|
C: (f, a) => f(...a)
|
|
@@ -5243,25 +5617,25 @@ var isLocked = (lockPath) => {
|
|
|
5243
5617
|
// packages/sdk/client-services/src/packlets/logging/logging-service.ts
|
|
5244
5618
|
import { Event as Event8 } from "@dxos/async";
|
|
5245
5619
|
import { Stream as Stream12 } from "@dxos/codec-protobuf";
|
|
5246
|
-
import { PublicKey as
|
|
5247
|
-
import { getContextFromEntry, log as
|
|
5620
|
+
import { PublicKey as PublicKey13 } from "@dxos/keys";
|
|
5621
|
+
import { getContextFromEntry, log as log17 } from "@dxos/log";
|
|
5248
5622
|
import { QueryLogsRequest } from "@dxos/protocols/proto/dxos/client/services";
|
|
5249
5623
|
import { getDebugName, jsonify, numericalValues, tracer } from "@dxos/util";
|
|
5250
5624
|
var LoggingServiceImpl = class {
|
|
5251
5625
|
constructor() {
|
|
5252
5626
|
this._logs = new Event8();
|
|
5253
5627
|
this._started = Date.now();
|
|
5254
|
-
this._sessionId =
|
|
5628
|
+
this._sessionId = PublicKey13.random().toHex();
|
|
5255
5629
|
this._logProcessor = (_config, entry2) => {
|
|
5256
5630
|
this._logs.emit(entry2);
|
|
5257
5631
|
};
|
|
5258
5632
|
}
|
|
5259
5633
|
async open() {
|
|
5260
|
-
|
|
5634
|
+
log17.runtimeConfig.processors.push(this._logProcessor);
|
|
5261
5635
|
}
|
|
5262
5636
|
async close() {
|
|
5263
|
-
const index =
|
|
5264
|
-
|
|
5637
|
+
const index = log17.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
|
|
5638
|
+
log17.runtimeConfig.processors.splice(index, 1);
|
|
5265
5639
|
}
|
|
5266
5640
|
async controlMetrics({ reset, record }) {
|
|
5267
5641
|
if (reset) {
|
|
@@ -5460,13 +5834,13 @@ var toStorageType = (type) => {
|
|
|
5460
5834
|
};
|
|
5461
5835
|
|
|
5462
5836
|
// packages/sdk/client-services/src/packlets/storage/level.ts
|
|
5463
|
-
import { Level } from "level";
|
|
5464
5837
|
import path from "@dxos/node-std/path";
|
|
5465
|
-
import { PublicKey as
|
|
5838
|
+
import { PublicKey as PublicKey14 } from "@dxos/keys";
|
|
5839
|
+
import { createLevel as createKV } from "@dxos/kv-store";
|
|
5466
5840
|
var createLevel = async (config) => {
|
|
5467
5841
|
const persistent = isPersistent(config);
|
|
5468
|
-
const storagePath = persistent ? path.join(getRootPath(config), "level") : `/tmp/dxos-${
|
|
5469
|
-
const level =
|
|
5842
|
+
const storagePath = persistent ? path.join(getRootPath(config), "level") : `/tmp/dxos-${PublicKey14.random().toHex()}`;
|
|
5843
|
+
const level = createKV(storagePath);
|
|
5470
5844
|
await level.open();
|
|
5471
5845
|
return level;
|
|
5472
5846
|
};
|
|
@@ -5539,7 +5913,7 @@ function _ts_decorate8(decorators, target, key, desc) {
|
|
|
5539
5913
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5540
5914
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
5541
5915
|
}
|
|
5542
|
-
var
|
|
5916
|
+
var __dxlog_file21 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
|
|
5543
5917
|
var ClientServicesHost = class {
|
|
5544
5918
|
constructor({
|
|
5545
5919
|
config,
|
|
@@ -5627,25 +6001,25 @@ var ClientServicesHost = class {
|
|
|
5627
6001
|
* Can only be called once.
|
|
5628
6002
|
*/
|
|
5629
6003
|
initialize({ config, ...options }) {
|
|
5630
|
-
|
|
5631
|
-
F:
|
|
5632
|
-
L:
|
|
6004
|
+
invariant18(!this._open, "service host is open", {
|
|
6005
|
+
F: __dxlog_file21,
|
|
6006
|
+
L: 189,
|
|
5633
6007
|
S: this,
|
|
5634
6008
|
A: [
|
|
5635
6009
|
"!this._open",
|
|
5636
6010
|
"'service host is open'"
|
|
5637
6011
|
]
|
|
5638
6012
|
});
|
|
5639
|
-
|
|
5640
|
-
F:
|
|
5641
|
-
L:
|
|
6013
|
+
log18("initializing...", void 0, {
|
|
6014
|
+
F: __dxlog_file21,
|
|
6015
|
+
L: 190,
|
|
5642
6016
|
S: this,
|
|
5643
6017
|
C: (f, a) => f(...a)
|
|
5644
6018
|
});
|
|
5645
6019
|
if (config) {
|
|
5646
|
-
|
|
5647
|
-
F:
|
|
5648
|
-
L:
|
|
6020
|
+
invariant18(!this._config, "config already set", {
|
|
6021
|
+
F: __dxlog_file21,
|
|
6022
|
+
L: 193,
|
|
5649
6023
|
S: this,
|
|
5650
6024
|
A: [
|
|
5651
6025
|
"!this._config",
|
|
@@ -5658,9 +6032,9 @@ var ClientServicesHost = class {
|
|
|
5658
6032
|
}
|
|
5659
6033
|
}
|
|
5660
6034
|
if (!options.signalManager) {
|
|
5661
|
-
|
|
5662
|
-
F:
|
|
5663
|
-
L:
|
|
6035
|
+
log18.warn("running signaling without telemetry metadata.", void 0, {
|
|
6036
|
+
F: __dxlog_file21,
|
|
6037
|
+
L: 201,
|
|
5664
6038
|
S: this,
|
|
5665
6039
|
C: (f, a) => f(...a)
|
|
5666
6040
|
});
|
|
@@ -5669,9 +6043,9 @@ var ClientServicesHost = class {
|
|
|
5669
6043
|
iceServers: this._config?.get("runtime.services.ice")
|
|
5670
6044
|
}), signalManager = new WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
|
|
5671
6045
|
this._signalManager = signalManager;
|
|
5672
|
-
|
|
5673
|
-
F:
|
|
5674
|
-
L:
|
|
6046
|
+
invariant18(!this._networkManager, "network manager already set", {
|
|
6047
|
+
F: __dxlog_file21,
|
|
6048
|
+
L: 212,
|
|
5675
6049
|
S: this,
|
|
5676
6050
|
A: [
|
|
5677
6051
|
"!this._networkManager",
|
|
@@ -5683,9 +6057,9 @@ var ClientServicesHost = class {
|
|
|
5683
6057
|
transportFactory,
|
|
5684
6058
|
signalManager
|
|
5685
6059
|
});
|
|
5686
|
-
|
|
5687
|
-
F:
|
|
5688
|
-
L:
|
|
6060
|
+
log18("initialized", void 0, {
|
|
6061
|
+
F: __dxlog_file21,
|
|
6062
|
+
L: 219,
|
|
5689
6063
|
S: this,
|
|
5690
6064
|
C: (f, a) => f(...a)
|
|
5691
6065
|
});
|
|
@@ -5694,45 +6068,45 @@ var ClientServicesHost = class {
|
|
|
5694
6068
|
if (this._open) {
|
|
5695
6069
|
return;
|
|
5696
6070
|
}
|
|
5697
|
-
const traceId =
|
|
5698
|
-
|
|
6071
|
+
const traceId = PublicKey15.random().toHex();
|
|
6072
|
+
log18.trace("dxos.client-services.host.open", trace9.begin({
|
|
5699
6073
|
id: traceId
|
|
5700
6074
|
}), {
|
|
5701
|
-
F:
|
|
5702
|
-
L:
|
|
6075
|
+
F: __dxlog_file21,
|
|
6076
|
+
L: 230,
|
|
5703
6077
|
S: this,
|
|
5704
6078
|
C: (f, a) => f(...a)
|
|
5705
6079
|
});
|
|
5706
|
-
|
|
5707
|
-
F:
|
|
5708
|
-
L:
|
|
6080
|
+
invariant18(this._config, "config not set", {
|
|
6081
|
+
F: __dxlog_file21,
|
|
6082
|
+
L: 232,
|
|
5709
6083
|
S: this,
|
|
5710
6084
|
A: [
|
|
5711
6085
|
"this._config",
|
|
5712
6086
|
"'config not set'"
|
|
5713
6087
|
]
|
|
5714
6088
|
});
|
|
5715
|
-
|
|
5716
|
-
F:
|
|
5717
|
-
L:
|
|
6089
|
+
invariant18(this._storage, "storage not set", {
|
|
6090
|
+
F: __dxlog_file21,
|
|
6091
|
+
L: 233,
|
|
5718
6092
|
S: this,
|
|
5719
6093
|
A: [
|
|
5720
6094
|
"this._storage",
|
|
5721
6095
|
"'storage not set'"
|
|
5722
6096
|
]
|
|
5723
6097
|
});
|
|
5724
|
-
|
|
5725
|
-
F:
|
|
5726
|
-
L:
|
|
6098
|
+
invariant18(this._signalManager, "signal manager not set", {
|
|
6099
|
+
F: __dxlog_file21,
|
|
6100
|
+
L: 234,
|
|
5727
6101
|
S: this,
|
|
5728
6102
|
A: [
|
|
5729
6103
|
"this._signalManager",
|
|
5730
6104
|
"'signal manager not set'"
|
|
5731
6105
|
]
|
|
5732
6106
|
});
|
|
5733
|
-
|
|
5734
|
-
F:
|
|
5735
|
-
L:
|
|
6107
|
+
invariant18(this._networkManager, "network manager not set", {
|
|
6108
|
+
F: __dxlog_file21,
|
|
6109
|
+
L: 235,
|
|
5736
6110
|
S: this,
|
|
5737
6111
|
A: [
|
|
5738
6112
|
"this._networkManager",
|
|
@@ -5740,19 +6114,19 @@ var ClientServicesHost = class {
|
|
|
5740
6114
|
]
|
|
5741
6115
|
});
|
|
5742
6116
|
this._opening = true;
|
|
5743
|
-
|
|
6117
|
+
log18("opening...", {
|
|
5744
6118
|
lockKey: this._resourceLock?.lockKey
|
|
5745
6119
|
}, {
|
|
5746
|
-
F:
|
|
5747
|
-
L:
|
|
6120
|
+
F: __dxlog_file21,
|
|
6121
|
+
L: 238,
|
|
5748
6122
|
S: this,
|
|
5749
6123
|
C: (f, a) => f(...a)
|
|
5750
6124
|
});
|
|
6125
|
+
await this._resourceLock?.acquire();
|
|
5751
6126
|
if (!this._level) {
|
|
5752
6127
|
this._level = await createLevel(this._config.get("runtime.client.storage", {}));
|
|
5753
6128
|
}
|
|
5754
6129
|
await this._level.open();
|
|
5755
|
-
await this._resourceLock?.acquire();
|
|
5756
6130
|
await this._loggingService.open();
|
|
5757
6131
|
this._serviceContext = new ServiceContext(this._storage, this._level, this._networkManager, this._signalManager, this._runtimeParams);
|
|
5758
6132
|
this._serviceRegistry.setServices({
|
|
@@ -5792,19 +6166,19 @@ var ClientServicesHost = class {
|
|
|
5792
6166
|
this._open = true;
|
|
5793
6167
|
this._statusUpdate.emit();
|
|
5794
6168
|
const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
|
|
5795
|
-
|
|
6169
|
+
log18("opened", {
|
|
5796
6170
|
deviceKey
|
|
5797
6171
|
}, {
|
|
5798
|
-
F:
|
|
5799
|
-
L:
|
|
6172
|
+
F: __dxlog_file21,
|
|
6173
|
+
L: 314,
|
|
5800
6174
|
S: this,
|
|
5801
6175
|
C: (f, a) => f(...a)
|
|
5802
6176
|
});
|
|
5803
|
-
|
|
6177
|
+
log18.trace("dxos.client-services.host.open", trace9.end({
|
|
5804
6178
|
id: traceId
|
|
5805
6179
|
}), {
|
|
5806
|
-
F:
|
|
5807
|
-
L:
|
|
6180
|
+
F: __dxlog_file21,
|
|
6181
|
+
L: 315,
|
|
5808
6182
|
S: this,
|
|
5809
6183
|
C: (f, a) => f(...a)
|
|
5810
6184
|
});
|
|
@@ -5814,11 +6188,11 @@ var ClientServicesHost = class {
|
|
|
5814
6188
|
return;
|
|
5815
6189
|
}
|
|
5816
6190
|
const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
|
|
5817
|
-
|
|
6191
|
+
log18("closing...", {
|
|
5818
6192
|
deviceKey
|
|
5819
6193
|
}, {
|
|
5820
|
-
F:
|
|
5821
|
-
L:
|
|
6194
|
+
F: __dxlog_file21,
|
|
6195
|
+
L: 326,
|
|
5822
6196
|
S: this,
|
|
5823
6197
|
C: (f, a) => f(...a)
|
|
5824
6198
|
});
|
|
@@ -5832,44 +6206,44 @@ var ClientServicesHost = class {
|
|
|
5832
6206
|
await this._level?.close();
|
|
5833
6207
|
this._open = false;
|
|
5834
6208
|
this._statusUpdate.emit();
|
|
5835
|
-
|
|
6209
|
+
log18("closed", {
|
|
5836
6210
|
deviceKey
|
|
5837
6211
|
}, {
|
|
5838
|
-
F:
|
|
5839
|
-
L:
|
|
6212
|
+
F: __dxlog_file21,
|
|
6213
|
+
L: 335,
|
|
5840
6214
|
S: this,
|
|
5841
6215
|
C: (f, a) => f(...a)
|
|
5842
6216
|
});
|
|
5843
6217
|
}
|
|
5844
6218
|
async reset() {
|
|
5845
|
-
const traceId =
|
|
5846
|
-
|
|
6219
|
+
const traceId = PublicKey15.random().toHex();
|
|
6220
|
+
log18.trace("dxos.sdk.client-services-host.reset", trace9.begin({
|
|
5847
6221
|
id: traceId
|
|
5848
6222
|
}), {
|
|
5849
|
-
F:
|
|
5850
|
-
L:
|
|
6223
|
+
F: __dxlog_file21,
|
|
6224
|
+
L: 340,
|
|
5851
6225
|
S: this,
|
|
5852
6226
|
C: (f, a) => f(...a)
|
|
5853
6227
|
});
|
|
5854
|
-
|
|
5855
|
-
F:
|
|
5856
|
-
L:
|
|
6228
|
+
log18.info("resetting...", void 0, {
|
|
6229
|
+
F: __dxlog_file21,
|
|
6230
|
+
L: 342,
|
|
5857
6231
|
S: this,
|
|
5858
6232
|
C: (f, a) => f(...a)
|
|
5859
6233
|
});
|
|
5860
6234
|
await this._serviceContext?.close();
|
|
5861
6235
|
await this._storage.reset();
|
|
5862
|
-
|
|
5863
|
-
F:
|
|
5864
|
-
L:
|
|
6236
|
+
log18.info("reset", void 0, {
|
|
6237
|
+
F: __dxlog_file21,
|
|
6238
|
+
L: 345,
|
|
5865
6239
|
S: this,
|
|
5866
6240
|
C: (f, a) => f(...a)
|
|
5867
6241
|
});
|
|
5868
|
-
|
|
6242
|
+
log18.trace("dxos.sdk.client-services-host.reset", trace9.end({
|
|
5869
6243
|
id: traceId
|
|
5870
6244
|
}), {
|
|
5871
|
-
F:
|
|
5872
|
-
L:
|
|
6245
|
+
F: __dxlog_file21,
|
|
6246
|
+
L: 346,
|
|
5873
6247
|
S: this,
|
|
5874
6248
|
C: (f, a) => f(...a)
|
|
5875
6249
|
});
|
|
@@ -5880,9 +6254,9 @@ var ClientServicesHost = class {
|
|
|
5880
6254
|
await this._serviceContext.initialized.wait();
|
|
5881
6255
|
const space = await this._serviceContext.dataSpaceManager.createSpace();
|
|
5882
6256
|
const automergeIndex = space.automergeSpaceState.rootUrl;
|
|
5883
|
-
|
|
5884
|
-
F:
|
|
5885
|
-
L:
|
|
6257
|
+
invariant18(automergeIndex, void 0, {
|
|
6258
|
+
F: __dxlog_file21,
|
|
6259
|
+
L: 358,
|
|
5886
6260
|
S: this,
|
|
5887
6261
|
A: [
|
|
5888
6262
|
"automergeIndex",
|
|
@@ -5902,7 +6276,7 @@ var ClientServicesHost = class {
|
|
|
5902
6276
|
keys: []
|
|
5903
6277
|
}
|
|
5904
6278
|
};
|
|
5905
|
-
const propertiesId =
|
|
6279
|
+
const propertiesId = PublicKey15.random().toHex();
|
|
5906
6280
|
document.change((doc) => {
|
|
5907
6281
|
assignDeep2(doc, [
|
|
5908
6282
|
"objects",
|
|
@@ -5932,11 +6306,12 @@ ClientServicesHost = _ts_decorate8([
|
|
|
5932
6306
|
], ClientServicesHost);
|
|
5933
6307
|
|
|
5934
6308
|
// packages/sdk/client-services/src/packlets/services/util.ts
|
|
5935
|
-
import { PublicKey as
|
|
6309
|
+
import { PublicKey as PublicKey16 } from "@dxos/keys";
|
|
5936
6310
|
import { humanize } from "@dxos/util";
|
|
5937
6311
|
var ClientServicesProviderResource = Symbol.for("dxos.resource.ClientServices");
|
|
5938
6312
|
|
|
5939
6313
|
// packages/sdk/client-services/src/packlets/diagnostics/diagnostics-collector.ts
|
|
6314
|
+
var GET_DIAGNOSTICS_RPC_TIMEOUT = 1e4;
|
|
5940
6315
|
var DiagnosticsCollector = class {
|
|
5941
6316
|
static {
|
|
5942
6317
|
this.broadcastSender = createCollectDiagnosticsBroadcastSender();
|
|
@@ -5944,6 +6319,8 @@ var DiagnosticsCollector = class {
|
|
|
5944
6319
|
static async collect(config = findConfigs(), services = findSystemServiceProvider(), options = {}) {
|
|
5945
6320
|
const serviceDiagnostics = await services?.services?.SystemService?.getDiagnostics({
|
|
5946
6321
|
keys: options.humanize ? GetDiagnosticsRequest2.KEY_OPTION.HUMANIZE : options.truncate ? GetDiagnosticsRequest2.KEY_OPTION.TRUNCATE : void 0
|
|
6322
|
+
}, {
|
|
6323
|
+
timeout: GET_DIAGNOSTICS_RPC_TIMEOUT
|
|
5947
6324
|
});
|
|
5948
6325
|
const clientDiagnostics = {
|
|
5949
6326
|
config,
|
|
@@ -5960,12 +6337,12 @@ var DiagnosticsCollector = class {
|
|
|
5960
6337
|
}
|
|
5961
6338
|
};
|
|
5962
6339
|
var findSystemServiceProvider = () => {
|
|
5963
|
-
const serviceProviders = TRACE_PROCESSOR3.
|
|
6340
|
+
const serviceProviders = TRACE_PROCESSOR3.findResourcesByAnnotation(ClientServicesProviderResource);
|
|
5964
6341
|
const providerResource = serviceProviders.find((r) => r.instance.deref()?.services?.SystemService != null);
|
|
5965
6342
|
return providerResource?.instance?.deref() ?? null;
|
|
5966
6343
|
};
|
|
5967
6344
|
var findConfigs = () => {
|
|
5968
|
-
const configs = TRACE_PROCESSOR3.
|
|
6345
|
+
const configs = TRACE_PROCESSOR3.findResourcesByAnnotation(ConfigResource);
|
|
5969
6346
|
return configs.map((r) => r.instance.deref()).filter(nonNullable);
|
|
5970
6347
|
};
|
|
5971
6348
|
|
|
@@ -6009,4 +6386,4 @@ export {
|
|
|
6009
6386
|
ClientServicesHost,
|
|
6010
6387
|
ClientServicesProviderResource
|
|
6011
6388
|
};
|
|
6012
|
-
//# sourceMappingURL=chunk-
|
|
6389
|
+
//# sourceMappingURL=chunk-NSJ3IC2K.mjs.map
|