@dxos/client-services 0.5.8 → 0.5.9-main.2d0a5e6
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-JECXTGZA.mjs → chunk-5SOW3KZQ.mjs} +1141 -1134
- package/dist/lib/browser/chunk-5SOW3KZQ.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +55 -363
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/packlets/testing/index.mjs +4 -4
- package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
- package/dist/lib/node/{chunk-OR7LRWDY.cjs → chunk-KYH2GPWL.cjs} +1145 -1138
- package/dist/lib/node/chunk-KYH2GPWL.cjs.map +7 -0
- package/dist/lib/node/index.cjs +93 -396
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/packlets/testing/index.cjs +10 -10
- package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
- package/dist/types/src/index.d.ts +3 -3
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/packlets/devtools/network.d.ts +4 -4
- package/dist/types/src/packlets/devtools/network.d.ts.map +1 -1
- package/dist/types/src/packlets/network/network-service.d.ts +2 -2
- package/dist/types/src/packlets/network/network-service.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-context.d.ts +4 -5
- package/dist/types/src/packlets/services/service-context.d.ts.map +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 +1 -0
- package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
- package/dist/types/src/packlets/testing/test-builder.d.ts +3 -3
- package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
- package/dist/types/src/packlets/worker/index.d.ts +3 -0
- package/dist/types/src/packlets/worker/index.d.ts.map +1 -0
- package/dist/types/src/packlets/worker/worker-runtime.d.ts.map +1 -0
- package/dist/types/src/packlets/worker/worker-session.d.ts.map +1 -0
- package/dist/types/src/version.d.ts +1 -1
- package/dist/types/src/version.d.ts.map +1 -1
- package/package.json +36 -36
- package/src/index.ts +3 -3
- package/src/packlets/devtools/network.ts +4 -4
- package/src/packlets/identity/identity-manager.test.ts +2 -2
- package/src/packlets/identity/identity.test.ts +8 -4
- package/src/packlets/invitations/invitations-handler.ts +2 -2
- package/src/packlets/network/network-service.ts +2 -2
- package/src/packlets/services/service-context.ts +3 -3
- package/src/packlets/services/service-host.ts +6 -7
- package/src/packlets/spaces/data-space.ts +11 -1
- package/src/packlets/spaces/spaces-service.ts +1 -0
- package/src/packlets/testing/test-builder.ts +4 -4
- package/src/packlets/worker/index.ts +6 -0
- package/src/version.ts +1 -5
- package/dist/lib/browser/chunk-JECXTGZA.mjs.map +0 -7
- package/dist/lib/node/chunk-OR7LRWDY.cjs.map +0 -7
- package/dist/types/src/packlets/vault/iframe-host-runtime.d.ts +0 -37
- package/dist/types/src/packlets/vault/iframe-host-runtime.d.ts.map +0 -1
- package/dist/types/src/packlets/vault/index.d.ts +0 -6
- package/dist/types/src/packlets/vault/index.d.ts.map +0 -1
- package/dist/types/src/packlets/vault/shared-worker-connection.d.ts +0 -36
- package/dist/types/src/packlets/vault/shared-worker-connection.d.ts.map +0 -1
- package/dist/types/src/packlets/vault/shell-runtime.d.ts +0 -33
- package/dist/types/src/packlets/vault/shell-runtime.d.ts.map +0 -1
- package/dist/types/src/packlets/vault/worker-runtime.d.ts.map +0 -1
- package/dist/types/src/packlets/vault/worker-session.d.ts.map +0 -1
- package/src/packlets/vault/iframe-host-runtime.ts +0 -130
- package/src/packlets/vault/index.ts +0 -9
- package/src/packlets/vault/shared-worker-connection.ts +0 -115
- package/src/packlets/vault/shell-runtime.ts +0 -111
- /package/dist/types/src/packlets/{vault → worker}/worker-runtime.d.ts +0 -0
- /package/dist/types/src/packlets/{vault → worker}/worker-session.d.ts +0 -0
- /package/src/packlets/{vault → worker}/worker-runtime.ts +0 -0
- /package/src/packlets/{vault → worker}/worker-session.ts +0 -0
|
@@ -345,13 +345,349 @@ var DevtoolsServiceImpl = class {
|
|
|
345
345
|
}
|
|
346
346
|
};
|
|
347
347
|
|
|
348
|
-
// packages/sdk/client-services/src/packlets/
|
|
348
|
+
// packages/sdk/client-services/src/packlets/diagnostics/diagnostics.ts
|
|
349
|
+
import { asyncTimeout } from "@dxos/async";
|
|
350
|
+
import { getFirstStreamValue } from "@dxos/codec-protobuf";
|
|
351
|
+
import { credentialTypeFilter } from "@dxos/credentials";
|
|
352
|
+
import { invariant } from "@dxos/invariant";
|
|
353
|
+
import { STORAGE_VERSION } from "@dxos/protocols";
|
|
354
|
+
import { SpaceMember } from "@dxos/protocols/proto/dxos/client/services";
|
|
355
|
+
import { TRACE_PROCESSOR } from "@dxos/tracing";
|
|
356
|
+
|
|
357
|
+
// packages/sdk/client-services/src/version.ts
|
|
358
|
+
var DXOS_VERSION = "0.5.9-main.2d0a5e6";
|
|
359
|
+
|
|
360
|
+
// packages/sdk/client-services/src/packlets/services/platform.ts
|
|
361
|
+
import { Platform } from "@dxos/protocols/proto/dxos/client/services";
|
|
362
|
+
var getPlatform = () => {
|
|
363
|
+
if (process.browser) {
|
|
364
|
+
if (typeof window !== "undefined") {
|
|
365
|
+
const { userAgent } = window.navigator;
|
|
366
|
+
return {
|
|
367
|
+
type: Platform.PLATFORM_TYPE.BROWSER,
|
|
368
|
+
userAgent,
|
|
369
|
+
uptime: Math.floor((Date.now() - window.performance.timeOrigin) / 1e3)
|
|
370
|
+
};
|
|
371
|
+
} else {
|
|
372
|
+
return {
|
|
373
|
+
type: Platform.PLATFORM_TYPE.SHARED_WORKER,
|
|
374
|
+
uptime: Math.floor((Date.now() - performance.timeOrigin) / 1e3)
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
} else {
|
|
378
|
+
const { platform: platform2, version, arch } = process;
|
|
379
|
+
return {
|
|
380
|
+
type: Platform.PLATFORM_TYPE.NODE,
|
|
381
|
+
platform: platform2,
|
|
382
|
+
arch,
|
|
383
|
+
runtime: version,
|
|
384
|
+
uptime: Math.floor(process.uptime()),
|
|
385
|
+
memory: process.memoryUsage()
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
// packages/sdk/client-services/src/packlets/diagnostics/diagnostics.ts
|
|
391
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/diagnostics/diagnostics.ts";
|
|
392
|
+
var DEFAULT_TIMEOUT = 1e3;
|
|
393
|
+
var createDiagnostics = async (clientServices, serviceContext, config) => {
|
|
394
|
+
const diagnostics = {
|
|
395
|
+
created: (/* @__PURE__ */ new Date()).toISOString(),
|
|
396
|
+
platform: getPlatform(),
|
|
397
|
+
client: {
|
|
398
|
+
version: DXOS_VERSION,
|
|
399
|
+
storage: {
|
|
400
|
+
version: STORAGE_VERSION
|
|
401
|
+
}
|
|
402
|
+
},
|
|
403
|
+
trace: TRACE_PROCESSOR.getDiagnostics()
|
|
404
|
+
};
|
|
405
|
+
await Promise.all([
|
|
406
|
+
(async () => {
|
|
407
|
+
invariant(clientServices.LoggingService, "SystemService is not available.", {
|
|
408
|
+
F: __dxlog_file,
|
|
409
|
+
L: 110,
|
|
410
|
+
S: void 0,
|
|
411
|
+
A: [
|
|
412
|
+
"clientServices.LoggingService",
|
|
413
|
+
"'SystemService is not available.'"
|
|
414
|
+
]
|
|
415
|
+
});
|
|
416
|
+
diagnostics.metrics = await getFirstStreamValue(clientServices.LoggingService.queryMetrics({}), {
|
|
417
|
+
timeout: DEFAULT_TIMEOUT
|
|
418
|
+
}).catch(() => void 0);
|
|
419
|
+
})(),
|
|
420
|
+
(async () => {
|
|
421
|
+
diagnostics.storage = await asyncTimeout(getStorageDiagnostics(), DEFAULT_TIMEOUT).catch(() => void 0);
|
|
422
|
+
})(),
|
|
423
|
+
async () => {
|
|
424
|
+
const identity = serviceContext.identityManager.identity;
|
|
425
|
+
if (identity) {
|
|
426
|
+
diagnostics.identity = {
|
|
427
|
+
identityKey: identity.identityKey,
|
|
428
|
+
spaceKey: identity.space.key,
|
|
429
|
+
profile: identity.profileDocument
|
|
430
|
+
};
|
|
431
|
+
const { devices } = await getFirstStreamValue(clientServices.DevicesService.queryDevices(), {
|
|
432
|
+
timeout: DEFAULT_TIMEOUT
|
|
433
|
+
}).catch(() => void 0) ?? {};
|
|
434
|
+
diagnostics.devices = devices;
|
|
435
|
+
if (serviceContext.dataSpaceManager) {
|
|
436
|
+
diagnostics.spaces = await Promise.all(Array.from(serviceContext.dataSpaceManager.spaces.values()).map((space) => getSpaceStats(space)) ?? []);
|
|
437
|
+
}
|
|
438
|
+
const { feeds = [] } = await getFirstStreamValue(clientServices.DevtoolsHost.subscribeToFeeds({}), {
|
|
439
|
+
timeout: DEFAULT_TIMEOUT
|
|
440
|
+
}).catch(() => void 0) ?? {};
|
|
441
|
+
diagnostics.feeds = feeds.map(({ feedKey, bytes, length }) => ({
|
|
442
|
+
feedKey,
|
|
443
|
+
bytes,
|
|
444
|
+
length
|
|
445
|
+
}));
|
|
446
|
+
const status = await getFirstStreamValue(clientServices.NetworkService.queryStatus(), {
|
|
447
|
+
timeout: DEFAULT_TIMEOUT
|
|
448
|
+
}).catch(() => void 0);
|
|
449
|
+
diagnostics.networkStatus = status;
|
|
450
|
+
diagnostics.swarms = serviceContext.networkManager.connectionLog?.swarms;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
]);
|
|
454
|
+
diagnostics.config = config.values;
|
|
455
|
+
return diagnostics;
|
|
456
|
+
};
|
|
457
|
+
var getSpaceStats = async (space) => {
|
|
458
|
+
const stats = {
|
|
459
|
+
key: space.key,
|
|
460
|
+
metrics: space.metrics,
|
|
461
|
+
epochs: space.inner.spaceState.credentials.filter(credentialTypeFilter("dxos.halo.credentials.Epoch")).map((credential) => ({
|
|
462
|
+
...credential.subject.assertion,
|
|
463
|
+
id: credential.id
|
|
464
|
+
})),
|
|
465
|
+
members: Array.from(space.inner.spaceState.members.values()).map((member) => ({
|
|
466
|
+
role: member.role,
|
|
467
|
+
identity: {
|
|
468
|
+
identityKey: member.key,
|
|
469
|
+
profile: {
|
|
470
|
+
displayName: member.assertion.profile?.displayName
|
|
471
|
+
}
|
|
472
|
+
},
|
|
473
|
+
presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? SpaceMember.PresenceState.ONLINE : SpaceMember.PresenceState.OFFLINE
|
|
474
|
+
})),
|
|
475
|
+
pipeline: {
|
|
476
|
+
// TODO(burdon): Pick properties from credentials if needed.
|
|
477
|
+
currentEpoch: space.automergeSpaceState.lastEpoch,
|
|
478
|
+
appliedEpoch: space.automergeSpaceState.lastEpoch,
|
|
479
|
+
controlFeeds: space.inner.controlPipeline.state.feeds.map((feed) => feed.key),
|
|
480
|
+
currentControlTimeframe: space.inner.controlPipeline.state.timeframe,
|
|
481
|
+
targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
|
|
482
|
+
totalControlTimeframe: space.inner.controlPipeline.state.endTimeframe
|
|
483
|
+
}
|
|
484
|
+
};
|
|
485
|
+
if (stats.metrics) {
|
|
486
|
+
const { open, ready } = stats.metrics;
|
|
487
|
+
stats.metrics.startupTime = open && ready && ready.getTime() - open.getTime();
|
|
488
|
+
}
|
|
489
|
+
return stats;
|
|
490
|
+
};
|
|
491
|
+
var getStorageDiagnostics = async () => {
|
|
492
|
+
if (typeof navigator === "undefined" || !navigator.storage) {
|
|
493
|
+
return void 0;
|
|
494
|
+
}
|
|
495
|
+
const map = /* @__PURE__ */ new Map();
|
|
496
|
+
const dir = await navigator.storage.getDirectory();
|
|
497
|
+
for await (const filename of dir?.keys()) {
|
|
498
|
+
const idx = filename.indexOf("-", filename.indexOf("-") + 1);
|
|
499
|
+
if (idx === -1) {
|
|
500
|
+
continue;
|
|
501
|
+
}
|
|
502
|
+
map.set(filename.slice(0, idx), (map.get(filename.slice(0, idx)) ?? 0) + 1);
|
|
503
|
+
}
|
|
504
|
+
return Array.from(map.entries()).sort((a, b) => b[1] - a[1]).map(([file, count]) => ({
|
|
505
|
+
file,
|
|
506
|
+
count
|
|
507
|
+
}));
|
|
508
|
+
};
|
|
509
|
+
|
|
510
|
+
// packages/sdk/client-services/src/packlets/diagnostics/browser-diagnostics-broadcast.ts
|
|
349
511
|
import { Trigger } from "@dxos/async";
|
|
512
|
+
import { log } from "@dxos/log";
|
|
513
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/diagnostics/browser-diagnostics-broadcast.ts";
|
|
514
|
+
var CHANNEL_NAME = "dxos.diagnostics.broadcast";
|
|
515
|
+
var MessageType;
|
|
516
|
+
(function(MessageType2) {
|
|
517
|
+
MessageType2["PROBE"] = "probe";
|
|
518
|
+
MessageType2["PROBE_ACK"] = "probe-ack";
|
|
519
|
+
MessageType2["REQUEST_DIAGNOSTICS"] = "request-diagnostics";
|
|
520
|
+
MessageType2["RECEIVE_DIAGNOSTICS"] = "receive-diagnostics";
|
|
521
|
+
})(MessageType || (MessageType = {}));
|
|
522
|
+
var createCollectDiagnosticsBroadcastSender = () => {
|
|
523
|
+
return {
|
|
524
|
+
broadcastDiagnosticsRequest: async () => {
|
|
525
|
+
let expectedResponse = "probe-ack";
|
|
526
|
+
let channel;
|
|
527
|
+
try {
|
|
528
|
+
const trigger = new Trigger();
|
|
529
|
+
channel = new BroadcastChannel(CHANNEL_NAME);
|
|
530
|
+
channel.onmessage = (msg) => {
|
|
531
|
+
if (expectedResponse === msg.data.type) {
|
|
532
|
+
trigger.wake(msg.data);
|
|
533
|
+
}
|
|
534
|
+
};
|
|
535
|
+
channel.postMessage({
|
|
536
|
+
type: "probe"
|
|
537
|
+
});
|
|
538
|
+
await trigger.wait({
|
|
539
|
+
timeout: 200
|
|
540
|
+
});
|
|
541
|
+
expectedResponse = "receive-diagnostics";
|
|
542
|
+
trigger.reset();
|
|
543
|
+
channel.postMessage({
|
|
544
|
+
type: "request-diagnostics"
|
|
545
|
+
});
|
|
546
|
+
const diagnostics = await trigger.wait({
|
|
547
|
+
timeout: 5e3
|
|
548
|
+
});
|
|
549
|
+
return diagnostics.payload;
|
|
550
|
+
} catch (e) {
|
|
551
|
+
const errorDescription = e instanceof Error ? e.message : JSON.stringify(e);
|
|
552
|
+
return {
|
|
553
|
+
expectedResponse,
|
|
554
|
+
errorDescription
|
|
555
|
+
};
|
|
556
|
+
} finally {
|
|
557
|
+
safeClose(channel);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
};
|
|
561
|
+
};
|
|
562
|
+
var createCollectDiagnosticsBroadcastHandler = (systemService) => {
|
|
563
|
+
let channel;
|
|
564
|
+
return {
|
|
565
|
+
start: () => {
|
|
566
|
+
channel = new BroadcastChannel(CHANNEL_NAME);
|
|
567
|
+
channel.onmessage = async (message) => {
|
|
568
|
+
try {
|
|
569
|
+
if (message.data.type === "probe") {
|
|
570
|
+
channel?.postMessage({
|
|
571
|
+
type: "probe-ack"
|
|
572
|
+
});
|
|
573
|
+
} else if (message.data.type === "request-diagnostics") {
|
|
574
|
+
const diagnostics = await systemService.getDiagnostics({});
|
|
575
|
+
channel?.postMessage({
|
|
576
|
+
type: "receive-diagnostics",
|
|
577
|
+
payload: diagnostics
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
} catch (error) {
|
|
581
|
+
log.catch(error, void 0, {
|
|
582
|
+
F: __dxlog_file2,
|
|
583
|
+
L: 77,
|
|
584
|
+
S: void 0,
|
|
585
|
+
C: (f, a) => f(...a)
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
};
|
|
589
|
+
},
|
|
590
|
+
stop: () => {
|
|
591
|
+
safeClose(channel);
|
|
592
|
+
channel = void 0;
|
|
593
|
+
}
|
|
594
|
+
};
|
|
595
|
+
};
|
|
596
|
+
var safeClose = (channel) => {
|
|
597
|
+
try {
|
|
598
|
+
channel?.close();
|
|
599
|
+
} catch (e) {
|
|
600
|
+
}
|
|
601
|
+
};
|
|
602
|
+
|
|
603
|
+
// packages/sdk/client-services/src/packlets/services/client-rpc-server.ts
|
|
604
|
+
import { Stream as Stream7 } from "@dxos/codec-protobuf";
|
|
605
|
+
import { raise } from "@dxos/debug";
|
|
606
|
+
import { parseMethodName, RpcPeer } from "@dxos/rpc";
|
|
607
|
+
import { MapCounter, trace } from "@dxos/tracing";
|
|
608
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
609
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
610
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
611
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
612
|
+
else
|
|
613
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
614
|
+
if (d = decorators[i])
|
|
615
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
616
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
617
|
+
}
|
|
618
|
+
var ClientRpcServer = class {
|
|
619
|
+
constructor(params) {
|
|
620
|
+
this._handlerCache = /* @__PURE__ */ new Map();
|
|
621
|
+
this._callMetrics = new MapCounter();
|
|
622
|
+
const { serviceRegistry, handleCall, handleStream, ...rpcOptions } = params;
|
|
623
|
+
this._handleCall = handleCall;
|
|
624
|
+
this._handleStream = handleStream;
|
|
625
|
+
this._serviceRegistry = serviceRegistry;
|
|
626
|
+
this._rpcPeer = new RpcPeer({
|
|
627
|
+
...rpcOptions,
|
|
628
|
+
callHandler: (method, params2) => {
|
|
629
|
+
const [serviceName, methodName] = parseMethodName(method);
|
|
630
|
+
const handler = (method2, params3) => this._getServiceHandler(serviceName).call(method2, params3);
|
|
631
|
+
this._callMetrics.inc(`${serviceName}.${methodName} request`);
|
|
632
|
+
if (this._handleCall) {
|
|
633
|
+
return this._handleCall(methodName, params2, handler);
|
|
634
|
+
} else {
|
|
635
|
+
return handler(methodName, params2);
|
|
636
|
+
}
|
|
637
|
+
},
|
|
638
|
+
streamHandler: (method, params2) => {
|
|
639
|
+
const [serviceName, methodName] = parseMethodName(method);
|
|
640
|
+
const handler = (method2, params3) => this._getServiceHandler(serviceName).callStream(method2, params3);
|
|
641
|
+
this._callMetrics.inc(`${serviceName}.${methodName} request stream`);
|
|
642
|
+
if (this._handleStream) {
|
|
643
|
+
return Stream7.map(Stream7.unwrapPromise(this._handleStream(methodName, params2, handler)), (data) => {
|
|
644
|
+
this._callMetrics.inc(`${serviceName}.${methodName} response stream`);
|
|
645
|
+
return data;
|
|
646
|
+
});
|
|
647
|
+
} else {
|
|
648
|
+
return handler(methodName, params2);
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
});
|
|
652
|
+
}
|
|
653
|
+
get _services() {
|
|
654
|
+
return Object.keys(this._serviceRegistry.services);
|
|
655
|
+
}
|
|
656
|
+
async open() {
|
|
657
|
+
await this._rpcPeer.open();
|
|
658
|
+
}
|
|
659
|
+
async close() {
|
|
660
|
+
await this._rpcPeer.close();
|
|
661
|
+
}
|
|
662
|
+
_getServiceHandler(serviceName) {
|
|
663
|
+
if (!this._handlerCache.has(serviceName)) {
|
|
664
|
+
const [key, descriptor] = Object.entries(this._serviceRegistry.descriptors).find(([key2, descriptor2]) => descriptor2.name === serviceName) ?? raise(new Error(`Service not available: ${serviceName}`));
|
|
665
|
+
const service = this._serviceRegistry.services[key];
|
|
666
|
+
if (!service) {
|
|
667
|
+
throw new Error(`Service not available: ${serviceName}`);
|
|
668
|
+
}
|
|
669
|
+
this._handlerCache.set(serviceName, descriptor.createServer(service));
|
|
670
|
+
}
|
|
671
|
+
return this._handlerCache.get(serviceName);
|
|
672
|
+
}
|
|
673
|
+
};
|
|
674
|
+
_ts_decorate([
|
|
675
|
+
trace.metricsCounter()
|
|
676
|
+
], ClientRpcServer.prototype, "_callMetrics", void 0);
|
|
677
|
+
_ts_decorate([
|
|
678
|
+
trace.info()
|
|
679
|
+
], ClientRpcServer.prototype, "_services", null);
|
|
680
|
+
ClientRpcServer = _ts_decorate([
|
|
681
|
+
trace.resource()
|
|
682
|
+
], ClientRpcServer);
|
|
683
|
+
|
|
684
|
+
// packages/sdk/client-services/src/packlets/identity/authenticator.ts
|
|
685
|
+
import { Trigger as Trigger2 } from "@dxos/async";
|
|
350
686
|
import { Context as Context2 } from "@dxos/context";
|
|
351
687
|
import { verifyCredential } from "@dxos/credentials";
|
|
352
|
-
import { log } from "@dxos/log";
|
|
688
|
+
import { log as log2 } from "@dxos/log";
|
|
353
689
|
import { schema } from "@dxos/protocols";
|
|
354
|
-
var
|
|
690
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/authenticator.ts";
|
|
355
691
|
var Credential = schema.getCodecForType("dxos.halo.credentials.Credential");
|
|
356
692
|
var createAuthProvider = (signer) => async (nonce) => {
|
|
357
693
|
const credential = await signer.createCredential({
|
|
@@ -374,20 +710,20 @@ var TrustedKeySetAuthVerifier = class {
|
|
|
374
710
|
get verifier() {
|
|
375
711
|
return async (nonce, auth) => {
|
|
376
712
|
const credential = Credential.decode(auth);
|
|
377
|
-
|
|
713
|
+
log2("authenticating...", {
|
|
378
714
|
credential
|
|
379
715
|
}, {
|
|
380
|
-
F:
|
|
716
|
+
F: __dxlog_file3,
|
|
381
717
|
L: 56,
|
|
382
718
|
S: this,
|
|
383
719
|
C: (f, a) => f(...a)
|
|
384
720
|
});
|
|
385
721
|
const result = await verifyCredential(credential);
|
|
386
722
|
if (result.kind === "fail") {
|
|
387
|
-
|
|
723
|
+
log2("Invalid credential", {
|
|
388
724
|
result
|
|
389
725
|
}, {
|
|
390
|
-
F:
|
|
726
|
+
F: __dxlog_file3,
|
|
391
727
|
L: 60,
|
|
392
728
|
S: this,
|
|
393
729
|
C: (f, a) => f(...a)
|
|
@@ -395,11 +731,11 @@ var TrustedKeySetAuthVerifier = class {
|
|
|
395
731
|
return false;
|
|
396
732
|
}
|
|
397
733
|
if (!credential.proof.nonce || !Buffer.from(nonce).equals(credential.proof.nonce)) {
|
|
398
|
-
|
|
734
|
+
log2("Invalid nonce", {
|
|
399
735
|
nonce,
|
|
400
736
|
credential
|
|
401
737
|
}, {
|
|
402
|
-
F:
|
|
738
|
+
F: __dxlog_file3,
|
|
403
739
|
L: 65,
|
|
404
740
|
S: this,
|
|
405
741
|
C: (f, a) => f(...a)
|
|
@@ -407,36 +743,36 @@ var TrustedKeySetAuthVerifier = class {
|
|
|
407
743
|
return false;
|
|
408
744
|
}
|
|
409
745
|
if (this._isTrustedKey(credential.issuer)) {
|
|
410
|
-
|
|
746
|
+
log2("key is not currently in trusted set, waiting...", {
|
|
411
747
|
key: credential.issuer
|
|
412
748
|
}, {
|
|
413
|
-
F:
|
|
749
|
+
F: __dxlog_file3,
|
|
414
750
|
L: 70,
|
|
415
751
|
S: this,
|
|
416
752
|
C: (f, a) => f(...a)
|
|
417
753
|
});
|
|
418
754
|
return true;
|
|
419
755
|
}
|
|
420
|
-
const trigger = new
|
|
756
|
+
const trigger = new Trigger2();
|
|
421
757
|
this._ctx.onDispose(() => {
|
|
422
758
|
trigger.wake(false);
|
|
423
759
|
});
|
|
424
760
|
const clear = this._params.update.on(this._ctx, () => {
|
|
425
761
|
if (this._isTrustedKey(credential.issuer)) {
|
|
426
|
-
|
|
762
|
+
log2("auth success", {
|
|
427
763
|
key: credential.issuer
|
|
428
764
|
}, {
|
|
429
|
-
F:
|
|
765
|
+
F: __dxlog_file3,
|
|
430
766
|
L: 81,
|
|
431
767
|
S: this,
|
|
432
768
|
C: (f, a) => f(...a)
|
|
433
769
|
});
|
|
434
770
|
trigger.wake(true);
|
|
435
771
|
} else {
|
|
436
|
-
|
|
772
|
+
log2("key is not currently in trusted set, waiting...", {
|
|
437
773
|
key: credential.issuer
|
|
438
774
|
}, {
|
|
439
|
-
F:
|
|
775
|
+
F: __dxlog_file3,
|
|
440
776
|
L: 84,
|
|
441
777
|
S: this,
|
|
442
778
|
C: (f, a) => f(...a)
|
|
@@ -465,13 +801,13 @@ import { Event } from "@dxos/async";
|
|
|
465
801
|
import { AUTH_TIMEOUT, LOAD_CONTROL_FEEDS_TIMEOUT } from "@dxos/client-protocol";
|
|
466
802
|
import { DeviceStateMachine, createCredentialSignerWithKey, createCredentialSignerWithChain, ProfileStateMachine } from "@dxos/credentials";
|
|
467
803
|
import { writeMessages } from "@dxos/feed-store";
|
|
468
|
-
import { invariant } from "@dxos/invariant";
|
|
804
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
469
805
|
import { PublicKey as PublicKey3 } from "@dxos/keys";
|
|
470
|
-
import { log as
|
|
806
|
+
import { log as log3 } from "@dxos/log";
|
|
471
807
|
import { AdmittedFeed } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
472
|
-
import { trace } from "@dxos/tracing";
|
|
808
|
+
import { trace as trace2 } from "@dxos/tracing";
|
|
473
809
|
import { ComplexSet } from "@dxos/util";
|
|
474
|
-
function
|
|
810
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
475
811
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
476
812
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
477
813
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -481,7 +817,7 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
481
817
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
482
818
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
483
819
|
}
|
|
484
|
-
var
|
|
820
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity.ts";
|
|
485
821
|
var Identity = class {
|
|
486
822
|
constructor({ space, signer, identityKey, deviceKey, presence }) {
|
|
487
823
|
this.stateUpdate = new Event();
|
|
@@ -490,10 +826,10 @@ var Identity = class {
|
|
|
490
826
|
this._presence = presence;
|
|
491
827
|
this.identityKey = identityKey;
|
|
492
828
|
this.deviceKey = deviceKey;
|
|
493
|
-
|
|
829
|
+
log3.trace("dxos.halo.device", {
|
|
494
830
|
deviceKey
|
|
495
831
|
}, {
|
|
496
|
-
F:
|
|
832
|
+
F: __dxlog_file4,
|
|
497
833
|
L: 67,
|
|
498
834
|
S: this,
|
|
499
835
|
C: (f, a) => f(...a)
|
|
@@ -561,8 +897,8 @@ var Identity = class {
|
|
|
561
897
|
* Requires identity to be ready.
|
|
562
898
|
*/
|
|
563
899
|
getIdentityCredentialSigner() {
|
|
564
|
-
|
|
565
|
-
F:
|
|
900
|
+
invariant2(this._deviceStateMachine.deviceCredentialChain, "Device credential chain is not ready.", {
|
|
901
|
+
F: __dxlog_file4,
|
|
566
902
|
L: 145,
|
|
567
903
|
S: this,
|
|
568
904
|
A: [
|
|
@@ -579,14 +915,14 @@ var Identity = class {
|
|
|
579
915
|
return createCredentialSignerWithKey(this._signer, this.deviceKey);
|
|
580
916
|
}
|
|
581
917
|
async admitDevice({ deviceKey, controlFeedKey, dataFeedKey }) {
|
|
582
|
-
|
|
918
|
+
log3("Admitting device:", {
|
|
583
919
|
identityKey: this.identityKey,
|
|
584
920
|
hostDevice: this.deviceKey,
|
|
585
921
|
deviceKey,
|
|
586
922
|
controlFeedKey,
|
|
587
923
|
dataFeedKey
|
|
588
924
|
}, {
|
|
589
|
-
F:
|
|
925
|
+
F: __dxlog_file4,
|
|
590
926
|
L: 161,
|
|
591
927
|
S: this,
|
|
592
928
|
C: (f, a) => f(...a)
|
|
@@ -628,14 +964,14 @@ var Identity = class {
|
|
|
628
964
|
})));
|
|
629
965
|
}
|
|
630
966
|
};
|
|
631
|
-
|
|
632
|
-
|
|
967
|
+
_ts_decorate2([
|
|
968
|
+
trace2.span()
|
|
633
969
|
], Identity.prototype, "open", null);
|
|
634
|
-
|
|
635
|
-
|
|
970
|
+
_ts_decorate2([
|
|
971
|
+
trace2.span()
|
|
636
972
|
], Identity.prototype, "close", null);
|
|
637
|
-
Identity =
|
|
638
|
-
|
|
973
|
+
Identity = _ts_decorate2([
|
|
974
|
+
trace2.resource()
|
|
639
975
|
], Identity);
|
|
640
976
|
|
|
641
977
|
// packages/sdk/client-services/src/packlets/identity/identity-manager.ts
|
|
@@ -643,17 +979,17 @@ import platform from "platform";
|
|
|
643
979
|
import { Event as Event2 } from "@dxos/async";
|
|
644
980
|
import { Context as Context3 } from "@dxos/context";
|
|
645
981
|
import { createCredentialSignerWithKey as createCredentialSignerWithKey2, CredentialGenerator } from "@dxos/credentials";
|
|
646
|
-
import { invariant as
|
|
982
|
+
import { invariant as invariant3 } from "@dxos/invariant";
|
|
647
983
|
import { PublicKey as PublicKey4 } from "@dxos/keys";
|
|
648
|
-
import { log as
|
|
649
|
-
import { trace as
|
|
984
|
+
import { log as log4 } from "@dxos/log";
|
|
985
|
+
import { trace as trace3 } from "@dxos/protocols";
|
|
650
986
|
import { Device, DeviceKind } from "@dxos/protocols/proto/dxos/client/services";
|
|
651
987
|
import { AdmittedFeed as AdmittedFeed2, DeviceType } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
652
988
|
import { Gossip, Presence } from "@dxos/teleport-extension-gossip";
|
|
653
989
|
import { Timeframe } from "@dxos/timeframe";
|
|
654
990
|
import { trace as Trace } from "@dxos/tracing";
|
|
655
991
|
import { isNode, deferFunction } from "@dxos/util";
|
|
656
|
-
function
|
|
992
|
+
function _ts_decorate3(decorators, target, key, desc) {
|
|
657
993
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
658
994
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
659
995
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -663,7 +999,7 @@ function _ts_decorate2(decorators, target, key, desc) {
|
|
|
663
999
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
664
1000
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
665
1001
|
}
|
|
666
|
-
var
|
|
1002
|
+
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-manager.ts";
|
|
667
1003
|
var DEVICE_PRESENCE_ANNOUNCE_INTERVAL = 1e4;
|
|
668
1004
|
var DEVICE_PRESENCE_OFFLINE_TIMEOUT = 2e4;
|
|
669
1005
|
var IdentityManager = class {
|
|
@@ -684,19 +1020,19 @@ var IdentityManager = class {
|
|
|
684
1020
|
}
|
|
685
1021
|
async open(ctx) {
|
|
686
1022
|
const traceId = PublicKey4.random().toHex();
|
|
687
|
-
|
|
1023
|
+
log4.trace("dxos.halo.identity-manager.open", trace3.begin({
|
|
688
1024
|
id: traceId
|
|
689
1025
|
}), {
|
|
690
|
-
F:
|
|
1026
|
+
F: __dxlog_file5,
|
|
691
1027
|
L: 104,
|
|
692
1028
|
S: this,
|
|
693
1029
|
C: (f, a) => f(...a)
|
|
694
1030
|
});
|
|
695
1031
|
const identityRecord = this._metadataStore.getIdentityRecord();
|
|
696
|
-
|
|
1032
|
+
log4("identity record", {
|
|
697
1033
|
identityRecord
|
|
698
1034
|
}, {
|
|
699
|
-
F:
|
|
1035
|
+
F: __dxlog_file5,
|
|
700
1036
|
L: 107,
|
|
701
1037
|
S: this,
|
|
702
1038
|
C: (f, a) => f(...a)
|
|
@@ -705,21 +1041,21 @@ var IdentityManager = class {
|
|
|
705
1041
|
this._identity = await this._constructIdentity(identityRecord);
|
|
706
1042
|
await this._identity.open(ctx);
|
|
707
1043
|
await this._identity.ready();
|
|
708
|
-
|
|
1044
|
+
log4.trace("dxos.halo.identity", {
|
|
709
1045
|
identityKey: identityRecord.identityKey,
|
|
710
1046
|
displayName: this._identity.profileDocument?.displayName
|
|
711
1047
|
}, {
|
|
712
|
-
F:
|
|
1048
|
+
F: __dxlog_file5,
|
|
713
1049
|
L: 112,
|
|
714
1050
|
S: this,
|
|
715
1051
|
C: (f, a) => f(...a)
|
|
716
1052
|
});
|
|
717
1053
|
this.stateUpdate.emit();
|
|
718
1054
|
}
|
|
719
|
-
|
|
1055
|
+
log4.trace("dxos.halo.identity-manager.open", trace3.end({
|
|
720
1056
|
id: traceId
|
|
721
1057
|
}), {
|
|
722
|
-
F:
|
|
1058
|
+
F: __dxlog_file5,
|
|
723
1059
|
L: 119,
|
|
724
1060
|
S: this,
|
|
725
1061
|
C: (f, a) => f(...a)
|
|
@@ -729,8 +1065,8 @@ var IdentityManager = class {
|
|
|
729
1065
|
await this._identity?.close(new Context3());
|
|
730
1066
|
}
|
|
731
1067
|
async createIdentity({ displayName, deviceProfile } = {}) {
|
|
732
|
-
|
|
733
|
-
F:
|
|
1068
|
+
invariant3(!this._identity, "Identity already exists.", {
|
|
1069
|
+
F: __dxlog_file5,
|
|
734
1070
|
L: 128,
|
|
735
1071
|
S: this,
|
|
736
1072
|
A: [
|
|
@@ -738,8 +1074,8 @@ var IdentityManager = class {
|
|
|
738
1074
|
"'Identity already exists.'"
|
|
739
1075
|
]
|
|
740
1076
|
});
|
|
741
|
-
|
|
742
|
-
F:
|
|
1077
|
+
log4("creating identity...", void 0, {
|
|
1078
|
+
F: __dxlog_file5,
|
|
743
1079
|
L: 129,
|
|
744
1080
|
S: this,
|
|
745
1081
|
C: (f, a) => f(...a)
|
|
@@ -759,8 +1095,8 @@ var IdentityManager = class {
|
|
|
759
1095
|
await identity.open(new Context3());
|
|
760
1096
|
{
|
|
761
1097
|
const generator = new CredentialGenerator(this._keyring, identityRecord.identityKey, identityRecord.deviceKey);
|
|
762
|
-
|
|
763
|
-
F:
|
|
1098
|
+
invariant3(identityRecord.haloSpace.genesisFeedKey, "Genesis feed key is required.", {
|
|
1099
|
+
F: __dxlog_file5,
|
|
764
1100
|
L: 148,
|
|
765
1101
|
S: this,
|
|
766
1102
|
A: [
|
|
@@ -768,8 +1104,8 @@ var IdentityManager = class {
|
|
|
768
1104
|
"'Genesis feed key is required.'"
|
|
769
1105
|
]
|
|
770
1106
|
});
|
|
771
|
-
|
|
772
|
-
F:
|
|
1107
|
+
invariant3(identityRecord.haloSpace.dataFeedKey, "Data feed key is required.", {
|
|
1108
|
+
F: __dxlog_file5,
|
|
773
1109
|
L: 149,
|
|
774
1110
|
S: this,
|
|
775
1111
|
A: [
|
|
@@ -804,22 +1140,22 @@ var IdentityManager = class {
|
|
|
804
1140
|
await this._metadataStore.setIdentityRecord(identityRecord);
|
|
805
1141
|
this._identity = identity;
|
|
806
1142
|
await this._identity.ready();
|
|
807
|
-
|
|
1143
|
+
log4.trace("dxos.halo.identity", {
|
|
808
1144
|
identityKey: identityRecord.identityKey,
|
|
809
1145
|
displayName: this._identity.profileDocument?.displayName
|
|
810
1146
|
}, {
|
|
811
|
-
F:
|
|
1147
|
+
F: __dxlog_file5,
|
|
812
1148
|
L: 191,
|
|
813
1149
|
S: this,
|
|
814
1150
|
C: (f, a) => f(...a)
|
|
815
1151
|
});
|
|
816
1152
|
this.stateUpdate.emit();
|
|
817
|
-
|
|
1153
|
+
log4("created identity", {
|
|
818
1154
|
identityKey: identity.identityKey,
|
|
819
1155
|
deviceKey: identity.deviceKey,
|
|
820
1156
|
profile: identity.profileDocument
|
|
821
1157
|
}, {
|
|
822
|
-
F:
|
|
1158
|
+
F: __dxlog_file5,
|
|
823
1159
|
L: 197,
|
|
824
1160
|
S: this,
|
|
825
1161
|
C: (f, a) => f(...a)
|
|
@@ -853,16 +1189,16 @@ var IdentityManager = class {
|
|
|
853
1189
|
* Accept an existing identity. Expects its device key to be authorized (now or later).
|
|
854
1190
|
*/
|
|
855
1191
|
async acceptIdentity(params) {
|
|
856
|
-
|
|
1192
|
+
log4("accepting identity", {
|
|
857
1193
|
params
|
|
858
1194
|
}, {
|
|
859
|
-
F:
|
|
1195
|
+
F: __dxlog_file5,
|
|
860
1196
|
L: 235,
|
|
861
1197
|
S: this,
|
|
862
1198
|
C: (f, a) => f(...a)
|
|
863
1199
|
});
|
|
864
|
-
|
|
865
|
-
F:
|
|
1200
|
+
invariant3(!this._identity, "Identity already exists.", {
|
|
1201
|
+
F: __dxlog_file5,
|
|
866
1202
|
L: 236,
|
|
867
1203
|
S: this,
|
|
868
1204
|
A: [
|
|
@@ -886,11 +1222,11 @@ var IdentityManager = class {
|
|
|
886
1222
|
this._identity = identity;
|
|
887
1223
|
await this._metadataStore.setIdentityRecord(identityRecord);
|
|
888
1224
|
await this._identity.ready();
|
|
889
|
-
|
|
1225
|
+
log4.trace("dxos.halo.identity", {
|
|
890
1226
|
identityKey: identityRecord.identityKey,
|
|
891
1227
|
displayName: this._identity.profileDocument?.displayName
|
|
892
1228
|
}, {
|
|
893
|
-
F:
|
|
1229
|
+
F: __dxlog_file5,
|
|
894
1230
|
L: 255,
|
|
895
1231
|
S: this,
|
|
896
1232
|
C: (f, a) => f(...a)
|
|
@@ -900,11 +1236,11 @@ var IdentityManager = class {
|
|
|
900
1236
|
...params.deviceProfile
|
|
901
1237
|
});
|
|
902
1238
|
this.stateUpdate.emit();
|
|
903
|
-
|
|
1239
|
+
log4("accepted identity", {
|
|
904
1240
|
identityKey: identity.identityKey,
|
|
905
1241
|
deviceKey: identity.deviceKey
|
|
906
1242
|
}, {
|
|
907
|
-
F:
|
|
1243
|
+
F: __dxlog_file5,
|
|
908
1244
|
L: 265,
|
|
909
1245
|
S: this,
|
|
910
1246
|
C: (f, a) => f(...a)
|
|
@@ -915,8 +1251,8 @@ var IdentityManager = class {
|
|
|
915
1251
|
* Update the profile document of an existing identity.
|
|
916
1252
|
*/
|
|
917
1253
|
async updateProfile(profile) {
|
|
918
|
-
|
|
919
|
-
F:
|
|
1254
|
+
invariant3(this._identity, "Identity not initialized.", {
|
|
1255
|
+
F: __dxlog_file5,
|
|
920
1256
|
L: 273,
|
|
921
1257
|
S: this,
|
|
922
1258
|
A: [
|
|
@@ -946,8 +1282,8 @@ var IdentityManager = class {
|
|
|
946
1282
|
return profile;
|
|
947
1283
|
}
|
|
948
1284
|
async updateDeviceProfile(profile) {
|
|
949
|
-
|
|
950
|
-
F:
|
|
1285
|
+
invariant3(this._identity, "Identity not initialized.", {
|
|
1286
|
+
F: __dxlog_file5,
|
|
951
1287
|
L: 290,
|
|
952
1288
|
S: this,
|
|
953
1289
|
A: [
|
|
@@ -982,8 +1318,8 @@ var IdentityManager = class {
|
|
|
982
1318
|
};
|
|
983
1319
|
}
|
|
984
1320
|
async _constructIdentity(identityRecord) {
|
|
985
|
-
|
|
986
|
-
F:
|
|
1321
|
+
invariant3(!this._identity, void 0, {
|
|
1322
|
+
F: __dxlog_file5,
|
|
987
1323
|
L: 316,
|
|
988
1324
|
S: this,
|
|
989
1325
|
A: [
|
|
@@ -991,10 +1327,10 @@ var IdentityManager = class {
|
|
|
991
1327
|
""
|
|
992
1328
|
]
|
|
993
1329
|
});
|
|
994
|
-
|
|
1330
|
+
log4("constructing identity", {
|
|
995
1331
|
identityRecord
|
|
996
1332
|
}, {
|
|
997
|
-
F:
|
|
1333
|
+
F: __dxlog_file5,
|
|
998
1334
|
L: 317,
|
|
999
1335
|
S: this,
|
|
1000
1336
|
C: (f, a) => f(...a)
|
|
@@ -1008,8 +1344,8 @@ var IdentityManager = class {
|
|
|
1008
1344
|
identityKey: identityRecord.deviceKey,
|
|
1009
1345
|
gossip
|
|
1010
1346
|
});
|
|
1011
|
-
|
|
1012
|
-
F:
|
|
1347
|
+
invariant3(identityRecord.haloSpace.controlFeedKey, void 0, {
|
|
1348
|
+
F: __dxlog_file5,
|
|
1013
1349
|
L: 330,
|
|
1014
1350
|
S: this,
|
|
1015
1351
|
A: [
|
|
@@ -1020,8 +1356,8 @@ var IdentityManager = class {
|
|
|
1020
1356
|
const controlFeed = await this._feedStore.openFeed(identityRecord.haloSpace.controlFeedKey, {
|
|
1021
1357
|
writable: true
|
|
1022
1358
|
});
|
|
1023
|
-
|
|
1024
|
-
F:
|
|
1359
|
+
invariant3(identityRecord.haloSpace.dataFeedKey, void 0, {
|
|
1360
|
+
F: __dxlog_file5,
|
|
1025
1361
|
L: 334,
|
|
1026
1362
|
S: this,
|
|
1027
1363
|
A: [
|
|
@@ -1052,10 +1388,10 @@ var IdentityManager = class {
|
|
|
1052
1388
|
identityKey: identityRecord.identityKey,
|
|
1053
1389
|
deviceKey: identityRecord.deviceKey
|
|
1054
1390
|
});
|
|
1055
|
-
|
|
1391
|
+
log4("done", {
|
|
1056
1392
|
identityKey: identityRecord.identityKey
|
|
1057
1393
|
}, {
|
|
1058
|
-
F:
|
|
1394
|
+
F: __dxlog_file5,
|
|
1059
1395
|
L: 360,
|
|
1060
1396
|
S: this,
|
|
1061
1397
|
C: (f, a) => f(...a)
|
|
@@ -1079,8 +1415,8 @@ var IdentityManager = class {
|
|
|
1079
1415
|
}));
|
|
1080
1416
|
},
|
|
1081
1417
|
onAuthFailure: () => {
|
|
1082
|
-
|
|
1083
|
-
F:
|
|
1418
|
+
log4.warn("auth failure", void 0, {
|
|
1419
|
+
F: __dxlog_file5,
|
|
1084
1420
|
L: 385,
|
|
1085
1421
|
S: this,
|
|
1086
1422
|
C: (f, a) => f(...a)
|
|
@@ -1094,21 +1430,21 @@ var IdentityManager = class {
|
|
|
1094
1430
|
});
|
|
1095
1431
|
}
|
|
1096
1432
|
};
|
|
1097
|
-
|
|
1433
|
+
_ts_decorate3([
|
|
1098
1434
|
Trace.span({
|
|
1099
1435
|
showInBrowserTimeline: true
|
|
1100
1436
|
})
|
|
1101
1437
|
], IdentityManager.prototype, "open", null);
|
|
1102
|
-
IdentityManager =
|
|
1438
|
+
IdentityManager = _ts_decorate3([
|
|
1103
1439
|
Trace.resource()
|
|
1104
1440
|
], IdentityManager);
|
|
1105
1441
|
|
|
1106
1442
|
// packages/sdk/client-services/src/packlets/identity/identity-service.ts
|
|
1107
|
-
import { Stream as
|
|
1443
|
+
import { Stream as Stream8 } from "@dxos/codec-protobuf";
|
|
1108
1444
|
import { signPresentation } from "@dxos/credentials";
|
|
1109
1445
|
import { todo } from "@dxos/debug";
|
|
1110
|
-
import { invariant as
|
|
1111
|
-
var
|
|
1446
|
+
import { invariant as invariant4 } from "@dxos/invariant";
|
|
1447
|
+
var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-service.ts";
|
|
1112
1448
|
var IdentityServiceImpl = class {
|
|
1113
1449
|
constructor(_createIdentity, _identityManager, _keyring, _onProfileUpdate) {
|
|
1114
1450
|
this._createIdentity = _createIdentity;
|
|
@@ -1127,7 +1463,7 @@ var IdentityServiceImpl = class {
|
|
|
1127
1463
|
return todo();
|
|
1128
1464
|
}
|
|
1129
1465
|
queryIdentity() {
|
|
1130
|
-
return new
|
|
1466
|
+
return new Stream8(({ next }) => {
|
|
1131
1467
|
const emitNext = () => next({
|
|
1132
1468
|
identity: this._getIdentity()
|
|
1133
1469
|
});
|
|
@@ -1146,8 +1482,8 @@ var IdentityServiceImpl = class {
|
|
|
1146
1482
|
};
|
|
1147
1483
|
}
|
|
1148
1484
|
async updateProfile(profile) {
|
|
1149
|
-
|
|
1150
|
-
F:
|
|
1485
|
+
invariant4(this._identityManager.identity, "Identity not initialized.", {
|
|
1486
|
+
F: __dxlog_file6,
|
|
1151
1487
|
L: 61,
|
|
1152
1488
|
S: this,
|
|
1153
1489
|
A: [
|
|
@@ -1160,8 +1496,8 @@ var IdentityServiceImpl = class {
|
|
|
1160
1496
|
return this._getIdentity();
|
|
1161
1497
|
}
|
|
1162
1498
|
async signPresentation({ presentation, nonce }) {
|
|
1163
|
-
|
|
1164
|
-
F:
|
|
1499
|
+
invariant4(this._identityManager.identity, "Identity not initialized.", {
|
|
1500
|
+
F: __dxlog_file6,
|
|
1165
1501
|
L: 68,
|
|
1166
1502
|
S: this,
|
|
1167
1503
|
A: [
|
|
@@ -1180,10 +1516,10 @@ var IdentityServiceImpl = class {
|
|
|
1180
1516
|
};
|
|
1181
1517
|
|
|
1182
1518
|
// packages/sdk/client-services/src/packlets/invitations/device-invitation-protocol.ts
|
|
1183
|
-
import { invariant as
|
|
1519
|
+
import { invariant as invariant5 } from "@dxos/invariant";
|
|
1184
1520
|
import { AlreadyJoinedError } from "@dxos/protocols";
|
|
1185
1521
|
import { Invitation } from "@dxos/protocols/proto/dxos/client/services";
|
|
1186
|
-
var
|
|
1522
|
+
var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/device-invitation-protocol.ts";
|
|
1187
1523
|
var DeviceInvitationProtocol = class {
|
|
1188
1524
|
constructor(_keyring, _getIdentity, _acceptIdentity) {
|
|
1189
1525
|
this._keyring = _keyring;
|
|
@@ -1208,8 +1544,8 @@ var DeviceInvitationProtocol = class {
|
|
|
1208
1544
|
throw new Error("delegation not supported");
|
|
1209
1545
|
}
|
|
1210
1546
|
async admit(_, request) {
|
|
1211
|
-
|
|
1212
|
-
F:
|
|
1547
|
+
invariant5(request.device, void 0, {
|
|
1548
|
+
F: __dxlog_file7,
|
|
1213
1549
|
L: 50,
|
|
1214
1550
|
S: this,
|
|
1215
1551
|
A: [
|
|
@@ -1254,8 +1590,8 @@ var DeviceInvitationProtocol = class {
|
|
|
1254
1590
|
};
|
|
1255
1591
|
}
|
|
1256
1592
|
async accept(response, request) {
|
|
1257
|
-
|
|
1258
|
-
F:
|
|
1593
|
+
invariant5(response.device, void 0, {
|
|
1594
|
+
F: __dxlog_file7,
|
|
1259
1595
|
L: 95,
|
|
1260
1596
|
S: this,
|
|
1261
1597
|
A: [
|
|
@@ -1264,8 +1600,8 @@ var DeviceInvitationProtocol = class {
|
|
|
1264
1600
|
]
|
|
1265
1601
|
});
|
|
1266
1602
|
const { identityKey, haloSpaceKey, genesisFeedKey, controlTimeframe } = response.device;
|
|
1267
|
-
|
|
1268
|
-
F:
|
|
1603
|
+
invariant5(request.device, void 0, {
|
|
1604
|
+
F: __dxlog_file7,
|
|
1269
1605
|
L: 98,
|
|
1270
1606
|
S: this,
|
|
1271
1607
|
A: [
|
|
@@ -1295,21 +1631,21 @@ import { Mutex, scheduleTask as scheduleTask3, TimeoutError } from "@dxos/async"
|
|
|
1295
1631
|
import { INVITATION_TIMEOUT } from "@dxos/client-protocol";
|
|
1296
1632
|
import { ContextDisposedError as ContextDisposedError2 } from "@dxos/context";
|
|
1297
1633
|
import { createKeyPair, sign } from "@dxos/crypto";
|
|
1298
|
-
import { invariant as
|
|
1634
|
+
import { invariant as invariant9 } from "@dxos/invariant";
|
|
1299
1635
|
import { PublicKey as PublicKey7 } from "@dxos/keys";
|
|
1300
|
-
import { log as
|
|
1636
|
+
import { log as log8 } from "@dxos/log";
|
|
1301
1637
|
import { createTeleportProtocolFactory } from "@dxos/network-manager";
|
|
1302
|
-
import { InvalidInvitationExtensionRoleError as InvalidInvitationExtensionRoleError3, trace as
|
|
1638
|
+
import { InvalidInvitationExtensionRoleError as InvalidInvitationExtensionRoleError3, trace as trace5 } from "@dxos/protocols";
|
|
1303
1639
|
import { Invitation as Invitation4 } from "@dxos/protocols/proto/dxos/client/services";
|
|
1304
1640
|
import { AuthenticationResponse as AuthenticationResponse2 } from "@dxos/protocols/proto/dxos/halo/invitations";
|
|
1305
1641
|
import { Options as Options4 } from "@dxos/protocols/proto/dxos/halo/invitations";
|
|
1306
1642
|
import { ComplexSet as ComplexSet3 } from "@dxos/util";
|
|
1307
1643
|
|
|
1308
1644
|
// packages/sdk/client-services/src/packlets/invitations/invitation-guest-extenstion.ts
|
|
1309
|
-
import { Trigger as
|
|
1645
|
+
import { Trigger as Trigger3 } from "@dxos/async";
|
|
1310
1646
|
import { cancelWithContext as cancelWithContext2, Context as Context4 } from "@dxos/context";
|
|
1311
|
-
import { invariant as
|
|
1312
|
-
import { log as
|
|
1647
|
+
import { invariant as invariant6 } from "@dxos/invariant";
|
|
1648
|
+
import { log as log5 } from "@dxos/log";
|
|
1313
1649
|
import { InvalidInvitationExtensionRoleError, schema as schema2 } from "@dxos/protocols";
|
|
1314
1650
|
import { Options } from "@dxos/protocols/proto/dxos/halo/invitations";
|
|
1315
1651
|
import { RpcExtension } from "@dxos/teleport";
|
|
@@ -1334,7 +1670,7 @@ var tryAcquireBeforeContextDisposed = async (ctx, mutex) => {
|
|
|
1334
1670
|
};
|
|
1335
1671
|
|
|
1336
1672
|
// packages/sdk/client-services/src/packlets/invitations/invitation-guest-extenstion.ts
|
|
1337
|
-
var
|
|
1673
|
+
var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-guest-extenstion.ts";
|
|
1338
1674
|
var OPTIONS_TIMEOUT = 1e4;
|
|
1339
1675
|
var InvitationGuestExtension = class extends RpcExtension {
|
|
1340
1676
|
constructor(_invitationFlowMutex, _callbacks) {
|
|
@@ -1349,7 +1685,7 @@ var InvitationGuestExtension = class extends RpcExtension {
|
|
|
1349
1685
|
this._invitationFlowMutex = _invitationFlowMutex;
|
|
1350
1686
|
this._callbacks = _callbacks;
|
|
1351
1687
|
this._ctx = new Context4();
|
|
1352
|
-
this._remoteOptionsTrigger = new
|
|
1688
|
+
this._remoteOptionsTrigger = new Trigger3();
|
|
1353
1689
|
this._invitationFlowLock = null;
|
|
1354
1690
|
}
|
|
1355
1691
|
hasFlowLock() {
|
|
@@ -1359,8 +1695,8 @@ var InvitationGuestExtension = class extends RpcExtension {
|
|
|
1359
1695
|
return {
|
|
1360
1696
|
InvitationHostService: {
|
|
1361
1697
|
options: async (options) => {
|
|
1362
|
-
|
|
1363
|
-
F:
|
|
1698
|
+
invariant6(!this._remoteOptions, "Remote options already set.", {
|
|
1699
|
+
F: __dxlog_file8,
|
|
1364
1700
|
L: 63,
|
|
1365
1701
|
S: this,
|
|
1366
1702
|
A: [
|
|
@@ -1386,15 +1722,15 @@ var InvitationGuestExtension = class extends RpcExtension {
|
|
|
1386
1722
|
async onOpen(context) {
|
|
1387
1723
|
await super.onOpen(context);
|
|
1388
1724
|
try {
|
|
1389
|
-
|
|
1390
|
-
F:
|
|
1725
|
+
log5("guest acquire lock", void 0, {
|
|
1726
|
+
F: __dxlog_file8,
|
|
1391
1727
|
L: 84,
|
|
1392
1728
|
S: this,
|
|
1393
1729
|
C: (f, a) => f(...a)
|
|
1394
1730
|
});
|
|
1395
1731
|
this._invitationFlowLock = await tryAcquireBeforeContextDisposed(this._ctx, this._invitationFlowMutex);
|
|
1396
|
-
|
|
1397
|
-
F:
|
|
1732
|
+
log5("guest lock acquired", void 0, {
|
|
1733
|
+
F: __dxlog_file8,
|
|
1398
1734
|
L: 86,
|
|
1399
1735
|
S: this,
|
|
1400
1736
|
C: (f, a) => f(...a)
|
|
@@ -1402,8 +1738,8 @@ var InvitationGuestExtension = class extends RpcExtension {
|
|
|
1402
1738
|
await cancelWithContext2(this._ctx, this.rpc.InvitationHostService.options({
|
|
1403
1739
|
role: Options.Role.GUEST
|
|
1404
1740
|
}));
|
|
1405
|
-
|
|
1406
|
-
F:
|
|
1741
|
+
log5("options sent", void 0, {
|
|
1742
|
+
F: __dxlog_file8,
|
|
1407
1743
|
L: 88,
|
|
1408
1744
|
S: this,
|
|
1409
1745
|
C: (f, a) => f(...a)
|
|
@@ -1411,8 +1747,8 @@ var InvitationGuestExtension = class extends RpcExtension {
|
|
|
1411
1747
|
await cancelWithContext2(this._ctx, this._remoteOptionsTrigger.wait({
|
|
1412
1748
|
timeout: OPTIONS_TIMEOUT
|
|
1413
1749
|
}));
|
|
1414
|
-
|
|
1415
|
-
F:
|
|
1750
|
+
log5("options received", void 0, {
|
|
1751
|
+
F: __dxlog_file8,
|
|
1416
1752
|
L: 90,
|
|
1417
1753
|
S: this,
|
|
1418
1754
|
C: (f, a) => f(...a)
|
|
@@ -1445,8 +1781,8 @@ var InvitationGuestExtension = class extends RpcExtension {
|
|
|
1445
1781
|
if (this._invitationFlowLock != null) {
|
|
1446
1782
|
this._invitationFlowLock.release();
|
|
1447
1783
|
this._invitationFlowLock = null;
|
|
1448
|
-
|
|
1449
|
-
F:
|
|
1784
|
+
log5("invitation flow lock released", void 0, {
|
|
1785
|
+
F: __dxlog_file8,
|
|
1450
1786
|
L: 123,
|
|
1451
1787
|
S: this,
|
|
1452
1788
|
C: (f, a) => f(...a)
|
|
@@ -1456,17 +1792,17 @@ var InvitationGuestExtension = class extends RpcExtension {
|
|
|
1456
1792
|
};
|
|
1457
1793
|
|
|
1458
1794
|
// packages/sdk/client-services/src/packlets/invitations/invitation-host-extension.ts
|
|
1459
|
-
import { Trigger as
|
|
1795
|
+
import { Trigger as Trigger4, scheduleTask as scheduleTask2 } from "@dxos/async";
|
|
1460
1796
|
import { cancelWithContext as cancelWithContext3, Context as Context5 } from "@dxos/context";
|
|
1461
1797
|
import { randomBytes, verify } from "@dxos/crypto";
|
|
1462
|
-
import { invariant as
|
|
1798
|
+
import { invariant as invariant7, InvariantViolation } from "@dxos/invariant";
|
|
1463
1799
|
import { PublicKey as PublicKey5 } from "@dxos/keys";
|
|
1464
|
-
import { log as
|
|
1465
|
-
import { InvalidInvitationExtensionRoleError as InvalidInvitationExtensionRoleError2, schema as schema3, trace as
|
|
1800
|
+
import { log as log6 } from "@dxos/log";
|
|
1801
|
+
import { InvalidInvitationExtensionRoleError as InvalidInvitationExtensionRoleError2, schema as schema3, trace as trace4 } from "@dxos/protocols";
|
|
1466
1802
|
import { Invitation as Invitation3 } from "@dxos/protocols/proto/dxos/client/services";
|
|
1467
1803
|
import { AuthenticationResponse, Options as Options2 } from "@dxos/protocols/proto/dxos/halo/invitations";
|
|
1468
1804
|
import { RpcExtension as RpcExtension2 } from "@dxos/teleport";
|
|
1469
|
-
var
|
|
1805
|
+
var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-host-extension.ts";
|
|
1470
1806
|
var OPTIONS_TIMEOUT2 = 1e4;
|
|
1471
1807
|
var MAX_OTP_ATTEMPTS = 3;
|
|
1472
1808
|
var InvitationHostExtension = class extends RpcExtension2 {
|
|
@@ -1482,12 +1818,12 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1482
1818
|
this._invitationFlowMutex = _invitationFlowMutex;
|
|
1483
1819
|
this._callbacks = _callbacks;
|
|
1484
1820
|
this._ctx = new Context5();
|
|
1485
|
-
this._remoteOptionsTrigger = new
|
|
1821
|
+
this._remoteOptionsTrigger = new Trigger4();
|
|
1486
1822
|
this._challenge = void 0;
|
|
1487
1823
|
this.guestProfile = void 0;
|
|
1488
1824
|
this.authenticationPassed = false;
|
|
1489
1825
|
this.authenticationRetry = 0;
|
|
1490
|
-
this.completedTrigger = new
|
|
1826
|
+
this.completedTrigger = new Trigger4();
|
|
1491
1827
|
this._invitationFlowLock = null;
|
|
1492
1828
|
}
|
|
1493
1829
|
hasFlowLock() {
|
|
@@ -1499,8 +1835,8 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1499
1835
|
// Perhaps in the future we will have more complex logic here.
|
|
1500
1836
|
InvitationHostService: {
|
|
1501
1837
|
options: async (options) => {
|
|
1502
|
-
|
|
1503
|
-
F:
|
|
1838
|
+
invariant7(!this._remoteOptions, "Remote options already set.", {
|
|
1839
|
+
F: __dxlog_file9,
|
|
1504
1840
|
L: 101,
|
|
1505
1841
|
S: this,
|
|
1506
1842
|
A: [
|
|
@@ -1514,10 +1850,10 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1514
1850
|
introduce: async (request) => {
|
|
1515
1851
|
const { profile, invitationId } = request;
|
|
1516
1852
|
const traceId = PublicKey5.random().toHex();
|
|
1517
|
-
|
|
1853
|
+
log6.trace("dxos.sdk.invitation-handler.host.introduce", trace4.begin({
|
|
1518
1854
|
id: traceId
|
|
1519
1855
|
}), {
|
|
1520
|
-
F:
|
|
1856
|
+
F: __dxlog_file9,
|
|
1521
1857
|
L: 110,
|
|
1522
1858
|
S: this,
|
|
1523
1859
|
C: (f, a) => f(...a)
|
|
@@ -1525,11 +1861,11 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1525
1861
|
const invitation = this._requireActiveInvitation();
|
|
1526
1862
|
this._assertInvitationState(Invitation3.State.CONNECTED);
|
|
1527
1863
|
if (invitationId !== invitation?.invitationId) {
|
|
1528
|
-
|
|
1864
|
+
log6.warn("incorrect invitationId", {
|
|
1529
1865
|
expected: invitation.invitationId,
|
|
1530
1866
|
actual: invitationId
|
|
1531
1867
|
}, {
|
|
1532
|
-
F:
|
|
1868
|
+
F: __dxlog_file9,
|
|
1533
1869
|
L: 116,
|
|
1534
1870
|
S: this,
|
|
1535
1871
|
C: (f, a) => f(...a)
|
|
@@ -1540,10 +1876,10 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1540
1876
|
authMethod: Invitation3.AuthMethod.NONE
|
|
1541
1877
|
};
|
|
1542
1878
|
}
|
|
1543
|
-
|
|
1879
|
+
log6("guest introduced themselves", {
|
|
1544
1880
|
guestProfile: profile
|
|
1545
1881
|
}, {
|
|
1546
|
-
F:
|
|
1882
|
+
F: __dxlog_file9,
|
|
1547
1883
|
L: 125,
|
|
1548
1884
|
S: this,
|
|
1549
1885
|
C: (f, a) => f(...a)
|
|
@@ -1551,10 +1887,10 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1551
1887
|
this.guestProfile = profile;
|
|
1552
1888
|
this._callbacks.onStateUpdate(Invitation3.State.READY_FOR_AUTHENTICATION);
|
|
1553
1889
|
this._challenge = invitation.authMethod === Invitation3.AuthMethod.KNOWN_PUBLIC_KEY ? randomBytes(32) : void 0;
|
|
1554
|
-
|
|
1890
|
+
log6.trace("dxos.sdk.invitation-handler.host.introduce", trace4.end({
|
|
1555
1891
|
id: traceId
|
|
1556
1892
|
}), {
|
|
1557
|
-
F:
|
|
1893
|
+
F: __dxlog_file9,
|
|
1558
1894
|
L: 132,
|
|
1559
1895
|
S: this,
|
|
1560
1896
|
C: (f, a) => f(...a)
|
|
@@ -1566,19 +1902,19 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1566
1902
|
},
|
|
1567
1903
|
authenticate: async ({ authCode: code, signedChallenge }) => {
|
|
1568
1904
|
const traceId = PublicKey5.random().toHex();
|
|
1569
|
-
|
|
1905
|
+
log6.trace("dxos.sdk.invitation-handler.host.authenticate", trace4.begin({
|
|
1570
1906
|
id: traceId
|
|
1571
1907
|
}), {
|
|
1572
|
-
F:
|
|
1908
|
+
F: __dxlog_file9,
|
|
1573
1909
|
L: 141,
|
|
1574
1910
|
S: this,
|
|
1575
1911
|
C: (f, a) => f(...a)
|
|
1576
1912
|
});
|
|
1577
1913
|
const invitation = this._requireActiveInvitation();
|
|
1578
|
-
|
|
1914
|
+
log6("received authentication request", {
|
|
1579
1915
|
authCode: code
|
|
1580
1916
|
}, {
|
|
1581
|
-
F:
|
|
1917
|
+
F: __dxlog_file9,
|
|
1582
1918
|
L: 144,
|
|
1583
1919
|
S: this,
|
|
1584
1920
|
C: (f, a) => f(...a)
|
|
@@ -1591,8 +1927,8 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1591
1927
|
this._callbacks.onStateUpdate(Invitation3.State.AUTHENTICATING);
|
|
1592
1928
|
switch (invitation.authMethod) {
|
|
1593
1929
|
case Invitation3.AuthMethod.NONE: {
|
|
1594
|
-
|
|
1595
|
-
F:
|
|
1930
|
+
log6("authentication not required", void 0, {
|
|
1931
|
+
F: __dxlog_file9,
|
|
1596
1932
|
L: 152,
|
|
1597
1933
|
S: this,
|
|
1598
1934
|
C: (f, a) => f(...a)
|
|
@@ -1627,10 +1963,10 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1627
1963
|
break;
|
|
1628
1964
|
}
|
|
1629
1965
|
default: {
|
|
1630
|
-
|
|
1966
|
+
log6.error("invalid authentication method", {
|
|
1631
1967
|
authMethod: invitation.authMethod
|
|
1632
1968
|
}, {
|
|
1633
|
-
F:
|
|
1969
|
+
F: __dxlog_file9,
|
|
1634
1970
|
L: 190,
|
|
1635
1971
|
S: this,
|
|
1636
1972
|
C: (f, a) => f(...a)
|
|
@@ -1649,13 +1985,13 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1649
1985
|
status
|
|
1650
1986
|
};
|
|
1651
1987
|
}
|
|
1652
|
-
|
|
1988
|
+
log6.trace("dxos.sdk.invitation-handler.host.authenticate", trace4.end({
|
|
1653
1989
|
id: traceId,
|
|
1654
1990
|
data: {
|
|
1655
1991
|
status
|
|
1656
1992
|
}
|
|
1657
1993
|
}), {
|
|
1658
|
-
F:
|
|
1994
|
+
F: __dxlog_file9,
|
|
1659
1995
|
L: 202,
|
|
1660
1996
|
S: this,
|
|
1661
1997
|
C: (f, a) => f(...a)
|
|
@@ -1666,10 +2002,10 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1666
2002
|
},
|
|
1667
2003
|
admit: async (request) => {
|
|
1668
2004
|
const traceId = PublicKey5.random().toHex();
|
|
1669
|
-
|
|
2005
|
+
log6.trace("dxos.sdk.invitation-handler.host.admit", trace4.begin({
|
|
1670
2006
|
id: traceId
|
|
1671
2007
|
}), {
|
|
1672
|
-
F:
|
|
2008
|
+
F: __dxlog_file9,
|
|
1673
2009
|
L: 208,
|
|
1674
2010
|
S: this,
|
|
1675
2011
|
C: (f, a) => f(...a)
|
|
@@ -1683,10 +2019,10 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1683
2019
|
}
|
|
1684
2020
|
}
|
|
1685
2021
|
const response = await this._callbacks.admit(request);
|
|
1686
|
-
|
|
2022
|
+
log6.trace("dxos.sdk.invitation-handler.host.admit", trace4.end({
|
|
1687
2023
|
id: traceId
|
|
1688
2024
|
}), {
|
|
1689
|
-
F:
|
|
2025
|
+
F: __dxlog_file9,
|
|
1690
2026
|
L: 222,
|
|
1691
2027
|
S: this,
|
|
1692
2028
|
C: (f, a) => f(...a)
|
|
@@ -1703,15 +2039,15 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1703
2039
|
async onOpen(context) {
|
|
1704
2040
|
await super.onOpen(context);
|
|
1705
2041
|
try {
|
|
1706
|
-
|
|
1707
|
-
F:
|
|
2042
|
+
log6("host acquire lock", void 0, {
|
|
2043
|
+
F: __dxlog_file9,
|
|
1708
2044
|
L: 237,
|
|
1709
2045
|
S: this,
|
|
1710
2046
|
C: (f, a) => f(...a)
|
|
1711
2047
|
});
|
|
1712
2048
|
this._invitationFlowLock = await tryAcquireBeforeContextDisposed(this._ctx, this._invitationFlowMutex);
|
|
1713
|
-
|
|
1714
|
-
F:
|
|
2049
|
+
log6("host lock acquired", void 0, {
|
|
2050
|
+
F: __dxlog_file9,
|
|
1715
2051
|
L: 239,
|
|
1716
2052
|
S: this,
|
|
1717
2053
|
C: (f, a) => f(...a)
|
|
@@ -1721,8 +2057,8 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1721
2057
|
await this.rpc.InvitationHostService.options({
|
|
1722
2058
|
role: Options2.Role.HOST
|
|
1723
2059
|
});
|
|
1724
|
-
|
|
1725
|
-
F:
|
|
2060
|
+
log6("options sent", void 0, {
|
|
2061
|
+
F: __dxlog_file9,
|
|
1726
2062
|
L: 243,
|
|
1727
2063
|
S: this,
|
|
1728
2064
|
C: (f, a) => f(...a)
|
|
@@ -1730,8 +2066,8 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1730
2066
|
await cancelWithContext3(this._ctx, this._remoteOptionsTrigger.wait({
|
|
1731
2067
|
timeout: OPTIONS_TIMEOUT2
|
|
1732
2068
|
}));
|
|
1733
|
-
|
|
1734
|
-
F:
|
|
2069
|
+
log6("options received", void 0, {
|
|
2070
|
+
F: __dxlog_file9,
|
|
1735
2071
|
L: 245,
|
|
1736
2072
|
S: this,
|
|
1737
2073
|
C: (f, a) => f(...a)
|
|
@@ -1784,8 +2120,8 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1784
2120
|
if (this._invitationFlowLock != null) {
|
|
1785
2121
|
this._invitationFlowLock?.release();
|
|
1786
2122
|
this._invitationFlowLock = null;
|
|
1787
|
-
|
|
1788
|
-
F:
|
|
2123
|
+
log6("invitation flow lock released", void 0, {
|
|
2124
|
+
F: __dxlog_file9,
|
|
1789
2125
|
L: 300,
|
|
1790
2126
|
S: this,
|
|
1791
2127
|
C: (f, a) => f(...a)
|
|
@@ -1796,20 +2132,20 @@ var InvitationHostExtension = class extends RpcExtension2 {
|
|
|
1796
2132
|
var isAuthenticationRequired = (invitation) => invitation.authMethod !== Invitation3.AuthMethod.NONE;
|
|
1797
2133
|
|
|
1798
2134
|
// packages/sdk/client-services/src/packlets/invitations/invitation-topology.ts
|
|
1799
|
-
import { invariant as
|
|
2135
|
+
import { invariant as invariant8 } from "@dxos/invariant";
|
|
1800
2136
|
import { PublicKey as PublicKey6 } from "@dxos/keys";
|
|
1801
|
-
import { log as
|
|
2137
|
+
import { log as log7 } from "@dxos/log";
|
|
1802
2138
|
import { Options as Options3 } from "@dxos/protocols/proto/dxos/halo/invitations";
|
|
1803
2139
|
import { ComplexSet as ComplexSet2 } from "@dxos/util";
|
|
1804
|
-
var
|
|
2140
|
+
var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-topology.ts";
|
|
1805
2141
|
var InvitationTopology = class {
|
|
1806
2142
|
constructor(_role) {
|
|
1807
2143
|
this._role = _role;
|
|
1808
2144
|
this._seenPeers = new ComplexSet2(PublicKey6.hash);
|
|
1809
2145
|
}
|
|
1810
2146
|
init(controller) {
|
|
1811
|
-
|
|
1812
|
-
F:
|
|
2147
|
+
invariant8(!this._controller, "Already initialized.", {
|
|
2148
|
+
F: __dxlog_file10,
|
|
1813
2149
|
L: 42,
|
|
1814
2150
|
S: this,
|
|
1815
2151
|
A: [
|
|
@@ -1820,8 +2156,8 @@ var InvitationTopology = class {
|
|
|
1820
2156
|
this._controller = controller;
|
|
1821
2157
|
}
|
|
1822
2158
|
update() {
|
|
1823
|
-
|
|
1824
|
-
F:
|
|
2159
|
+
invariant8(this._controller, "Not initialized.", {
|
|
2160
|
+
F: __dxlog_file10,
|
|
1825
2161
|
L: 47,
|
|
1826
2162
|
S: this,
|
|
1827
2163
|
A: [
|
|
@@ -1840,11 +2176,11 @@ var InvitationTopology = class {
|
|
|
1840
2176
|
const firstUnknownPeer = candidates.find((peerId) => !this._seenPeers.has(peerId));
|
|
1841
2177
|
this._seenPeers = new ComplexSet2(PublicKey6.hash, allPeers.filter((peerId) => this._seenPeers.has(peerId)));
|
|
1842
2178
|
if (firstUnknownPeer != null) {
|
|
1843
|
-
|
|
2179
|
+
log7("invitation connect", {
|
|
1844
2180
|
ownPeerId,
|
|
1845
2181
|
remotePeerId: firstUnknownPeer
|
|
1846
2182
|
}, {
|
|
1847
|
-
F:
|
|
2183
|
+
F: __dxlog_file10,
|
|
1848
2184
|
L: 69,
|
|
1849
2185
|
S: this,
|
|
1850
2186
|
C: (f, a) => f(...a)
|
|
@@ -1854,8 +2190,8 @@ var InvitationTopology = class {
|
|
|
1854
2190
|
}
|
|
1855
2191
|
}
|
|
1856
2192
|
async onOffer(peer) {
|
|
1857
|
-
|
|
1858
|
-
F:
|
|
2193
|
+
invariant8(this._controller, "Not initialized.", {
|
|
2194
|
+
F: __dxlog_file10,
|
|
1859
2195
|
L: 76,
|
|
1860
2196
|
S: this,
|
|
1861
2197
|
A: [
|
|
@@ -1874,7 +2210,7 @@ var InvitationTopology = class {
|
|
|
1874
2210
|
};
|
|
1875
2211
|
|
|
1876
2212
|
// packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
|
|
1877
|
-
var
|
|
2213
|
+
var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts";
|
|
1878
2214
|
var MAX_DELEGATED_INVITATION_HOST_TRIES = 3;
|
|
1879
2215
|
var InvitationsHandler = class {
|
|
1880
2216
|
/**
|
|
@@ -1898,8 +2234,8 @@ var InvitationsHandler = class {
|
|
|
1898
2234
|
admit: async (admissionRequest) => {
|
|
1899
2235
|
try {
|
|
1900
2236
|
const deviceKey = admissionRequest.device?.deviceKey ?? admissionRequest.space?.deviceKey;
|
|
1901
|
-
|
|
1902
|
-
F:
|
|
2237
|
+
invariant9(deviceKey, void 0, {
|
|
2238
|
+
F: __dxlog_file11,
|
|
1903
2239
|
L: 90,
|
|
1904
2240
|
S: this,
|
|
1905
2241
|
A: [
|
|
@@ -1925,18 +2261,18 @@ var InvitationsHandler = class {
|
|
|
1925
2261
|
scheduleTask3(connectionCtx, async () => {
|
|
1926
2262
|
const traceId = PublicKey7.random().toHex();
|
|
1927
2263
|
try {
|
|
1928
|
-
|
|
2264
|
+
log8.trace("dxos.sdk.invitations-handler.host.onOpen", trace5.begin({
|
|
1929
2265
|
id: traceId
|
|
1930
2266
|
}), {
|
|
1931
|
-
F:
|
|
2267
|
+
F: __dxlog_file11,
|
|
1932
2268
|
L: 115,
|
|
1933
2269
|
S: this,
|
|
1934
2270
|
C: (f, a) => f(...a)
|
|
1935
2271
|
});
|
|
1936
|
-
|
|
2272
|
+
log8("connected", {
|
|
1937
2273
|
...protocol.toJSON()
|
|
1938
2274
|
}, {
|
|
1939
|
-
F:
|
|
2275
|
+
F: __dxlog_file11,
|
|
1940
2276
|
L: 116,
|
|
1941
2277
|
S: this,
|
|
1942
2278
|
C: (f, a) => f(...a)
|
|
@@ -1944,20 +2280,20 @@ var InvitationsHandler = class {
|
|
|
1944
2280
|
const deviceKey = await extension.completedTrigger.wait({
|
|
1945
2281
|
timeout: invitation.timeout
|
|
1946
2282
|
});
|
|
1947
|
-
|
|
2283
|
+
log8("admitted guest", {
|
|
1948
2284
|
guest: deviceKey,
|
|
1949
2285
|
...protocol.toJSON()
|
|
1950
2286
|
}, {
|
|
1951
|
-
F:
|
|
2287
|
+
F: __dxlog_file11,
|
|
1952
2288
|
L: 118,
|
|
1953
2289
|
S: this,
|
|
1954
2290
|
C: (f, a) => f(...a)
|
|
1955
2291
|
});
|
|
1956
2292
|
guardedState.set(extension, Invitation4.State.SUCCESS);
|
|
1957
|
-
|
|
2293
|
+
log8.trace("dxos.sdk.invitations-handler.host.onOpen", trace5.end({
|
|
1958
2294
|
id: traceId
|
|
1959
2295
|
}), {
|
|
1960
|
-
F:
|
|
2296
|
+
F: __dxlog_file11,
|
|
1961
2297
|
L: 120,
|
|
1962
2298
|
S: this,
|
|
1963
2299
|
C: (f, a) => f(...a)
|
|
@@ -1969,10 +2305,10 @@ var InvitationsHandler = class {
|
|
|
1969
2305
|
} catch (err) {
|
|
1970
2306
|
if (err instanceof TimeoutError) {
|
|
1971
2307
|
if (guardedState.set(extension, Invitation4.State.TIMEOUT)) {
|
|
1972
|
-
|
|
2308
|
+
log8("timeout", {
|
|
1973
2309
|
...protocol.toJSON()
|
|
1974
2310
|
}, {
|
|
1975
|
-
F:
|
|
2311
|
+
F: __dxlog_file11,
|
|
1976
2312
|
L: 129,
|
|
1977
2313
|
S: this,
|
|
1978
2314
|
C: (f, a) => f(...a)
|
|
@@ -1980,19 +2316,19 @@ var InvitationsHandler = class {
|
|
|
1980
2316
|
}
|
|
1981
2317
|
} else {
|
|
1982
2318
|
if (guardedState.error(extension, err)) {
|
|
1983
|
-
|
|
1984
|
-
F:
|
|
2319
|
+
log8.error("failed", err, {
|
|
2320
|
+
F: __dxlog_file11,
|
|
1985
2321
|
L: 133,
|
|
1986
2322
|
S: this,
|
|
1987
2323
|
C: (f, a) => f(...a)
|
|
1988
2324
|
});
|
|
1989
2325
|
}
|
|
1990
2326
|
}
|
|
1991
|
-
|
|
2327
|
+
log8.trace("dxos.sdk.invitations-handler.host.onOpen", trace5.error({
|
|
1992
2328
|
id: traceId,
|
|
1993
2329
|
error: err
|
|
1994
2330
|
}), {
|
|
1995
|
-
F:
|
|
2331
|
+
F: __dxlog_file11,
|
|
1996
2332
|
L: 136,
|
|
1997
2333
|
S: this,
|
|
1998
2334
|
C: (f, a) => f(...a)
|
|
@@ -2003,10 +2339,10 @@ var InvitationsHandler = class {
|
|
|
2003
2339
|
},
|
|
2004
2340
|
onError: (err) => {
|
|
2005
2341
|
if (err instanceof InvalidInvitationExtensionRoleError3) {
|
|
2006
|
-
|
|
2342
|
+
log8("invalid role", {
|
|
2007
2343
|
...err.context
|
|
2008
2344
|
}, {
|
|
2009
|
-
F:
|
|
2345
|
+
F: __dxlog_file11,
|
|
2010
2346
|
L: 144,
|
|
2011
2347
|
S: this,
|
|
2012
2348
|
C: (f, a) => f(...a)
|
|
@@ -2015,10 +2351,10 @@ var InvitationsHandler = class {
|
|
|
2015
2351
|
}
|
|
2016
2352
|
if (err instanceof TimeoutError) {
|
|
2017
2353
|
if (guardedState.set(extension, Invitation4.State.TIMEOUT)) {
|
|
2018
|
-
|
|
2354
|
+
log8("timeout", {
|
|
2019
2355
|
err
|
|
2020
2356
|
}, {
|
|
2021
|
-
F:
|
|
2357
|
+
F: __dxlog_file11,
|
|
2022
2358
|
L: 149,
|
|
2023
2359
|
S: this,
|
|
2024
2360
|
C: (f, a) => f(...a)
|
|
@@ -2026,8 +2362,8 @@ var InvitationsHandler = class {
|
|
|
2026
2362
|
}
|
|
2027
2363
|
} else {
|
|
2028
2364
|
if (guardedState.error(extension, err)) {
|
|
2029
|
-
|
|
2030
|
-
F:
|
|
2365
|
+
log8.error("failed", err, {
|
|
2366
|
+
F: __dxlog_file11,
|
|
2031
2367
|
L: 153,
|
|
2032
2368
|
S: this,
|
|
2033
2369
|
C: (f, a) => f(...a)
|
|
@@ -2040,8 +2376,8 @@ var InvitationsHandler = class {
|
|
|
2040
2376
|
};
|
|
2041
2377
|
if (invitation.lifetime && invitation.created) {
|
|
2042
2378
|
if (invitation.created.getTime() + invitation.lifetime * 1e3 < Date.now()) {
|
|
2043
|
-
|
|
2044
|
-
F:
|
|
2379
|
+
log8.warn("invitation has already expired", void 0, {
|
|
2380
|
+
F: __dxlog_file11,
|
|
2045
2381
|
L: 164,
|
|
2046
2382
|
S: this,
|
|
2047
2383
|
C: (f, a) => f(...a)
|
|
@@ -2063,8 +2399,8 @@ var InvitationsHandler = class {
|
|
|
2063
2399
|
acceptInvitation(ctx, stream, protocol, invitation, otpEnteredTrigger, deviceProfile) {
|
|
2064
2400
|
const { timeout = INVITATION_TIMEOUT } = invitation;
|
|
2065
2401
|
if (deviceProfile) {
|
|
2066
|
-
|
|
2067
|
-
F:
|
|
2402
|
+
invariant9(invitation.kind === Invitation4.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
|
|
2403
|
+
F: __dxlog_file11,
|
|
2068
2404
|
L: 197,
|
|
2069
2405
|
S: this,
|
|
2070
2406
|
A: [
|
|
@@ -2077,12 +2413,12 @@ var InvitationsHandler = class {
|
|
|
2077
2413
|
const guardedState = this._createGuardedState(ctx, invitation, stream);
|
|
2078
2414
|
const shouldCancelInvitationFlow = (extension) => {
|
|
2079
2415
|
const isLockedByAnotherConnection = guardedState.mutex.isLocked() && !extension.hasFlowLock();
|
|
2080
|
-
|
|
2416
|
+
log8("should cancel invitation flow", {
|
|
2081
2417
|
isLockedByAnotherConnection,
|
|
2082
2418
|
invitationType: Invitation4.Type.DELEGATED,
|
|
2083
2419
|
triedPeers: triedPeersIds.size
|
|
2084
2420
|
}, {
|
|
2085
|
-
F:
|
|
2421
|
+
F: __dxlog_file11,
|
|
2086
2422
|
L: 205,
|
|
2087
2423
|
S: this,
|
|
2088
2424
|
C: (f, a) => f(...a)
|
|
@@ -2105,11 +2441,11 @@ var InvitationsHandler = class {
|
|
|
2105
2441
|
return;
|
|
2106
2442
|
}
|
|
2107
2443
|
connectionCtx.onDispose(async () => {
|
|
2108
|
-
|
|
2444
|
+
log8("extension disposed", {
|
|
2109
2445
|
admitted,
|
|
2110
2446
|
currentState: guardedState.current.state
|
|
2111
2447
|
}, {
|
|
2112
|
-
F:
|
|
2448
|
+
F: __dxlog_file11,
|
|
2113
2449
|
L: 233,
|
|
2114
2450
|
S: this,
|
|
2115
2451
|
C: (f, a) => f(...a)
|
|
@@ -2124,10 +2460,10 @@ var InvitationsHandler = class {
|
|
|
2124
2460
|
scheduleTask3(connectionCtx, async () => {
|
|
2125
2461
|
const traceId = PublicKey7.random().toHex();
|
|
2126
2462
|
try {
|
|
2127
|
-
|
|
2463
|
+
log8.trace("dxos.sdk.invitations-handler.guest.onOpen", trace5.begin({
|
|
2128
2464
|
id: traceId
|
|
2129
2465
|
}), {
|
|
2130
|
-
F:
|
|
2466
|
+
F: __dxlog_file11,
|
|
2131
2467
|
L: 245,
|
|
2132
2468
|
S: this,
|
|
2133
2469
|
C: (f, a) => f(...a)
|
|
@@ -2136,19 +2472,19 @@ var InvitationsHandler = class {
|
|
|
2136
2472
|
guardedState.set(extension, Invitation4.State.TIMEOUT);
|
|
2137
2473
|
extensionCtx.close();
|
|
2138
2474
|
}, timeout);
|
|
2139
|
-
|
|
2475
|
+
log8("connected", {
|
|
2140
2476
|
...protocol.toJSON()
|
|
2141
2477
|
}, {
|
|
2142
|
-
F:
|
|
2478
|
+
F: __dxlog_file11,
|
|
2143
2479
|
L: 256,
|
|
2144
2480
|
S: this,
|
|
2145
2481
|
C: (f, a) => f(...a)
|
|
2146
2482
|
});
|
|
2147
2483
|
guardedState.set(extension, Invitation4.State.CONNECTED);
|
|
2148
|
-
|
|
2484
|
+
log8("introduce", {
|
|
2149
2485
|
...protocol.toJSON()
|
|
2150
2486
|
}, {
|
|
2151
|
-
F:
|
|
2487
|
+
F: __dxlog_file11,
|
|
2152
2488
|
L: 260,
|
|
2153
2489
|
S: this,
|
|
2154
2490
|
C: (f, a) => f(...a)
|
|
@@ -2157,11 +2493,11 @@ var InvitationsHandler = class {
|
|
|
2157
2493
|
invitationId: invitation.invitationId,
|
|
2158
2494
|
...protocol.createIntroduction()
|
|
2159
2495
|
});
|
|
2160
|
-
|
|
2496
|
+
log8("introduce response", {
|
|
2161
2497
|
...protocol.toJSON(),
|
|
2162
2498
|
response: introductionResponse
|
|
2163
2499
|
}, {
|
|
2164
|
-
F:
|
|
2500
|
+
F: __dxlog_file11,
|
|
2165
2501
|
L: 265,
|
|
2166
2502
|
S: this,
|
|
2167
2503
|
C: (f, a) => f(...a)
|
|
@@ -2179,10 +2515,10 @@ var InvitationsHandler = class {
|
|
|
2179
2515
|
break;
|
|
2180
2516
|
}
|
|
2181
2517
|
}
|
|
2182
|
-
|
|
2518
|
+
log8("request admission", {
|
|
2183
2519
|
...protocol.toJSON()
|
|
2184
2520
|
}, {
|
|
2185
|
-
F:
|
|
2521
|
+
F: __dxlog_file11,
|
|
2186
2522
|
L: 291,
|
|
2187
2523
|
S: this,
|
|
2188
2524
|
C: (f, a) => f(...a)
|
|
@@ -2191,10 +2527,10 @@ var InvitationsHandler = class {
|
|
|
2191
2527
|
const admissionResponse = await extension.rpc.InvitationHostService.admit(admissionRequest);
|
|
2192
2528
|
admitted = true;
|
|
2193
2529
|
const result = await protocol.accept(admissionResponse, admissionRequest);
|
|
2194
|
-
|
|
2530
|
+
log8("admitted by host", {
|
|
2195
2531
|
...protocol.toJSON()
|
|
2196
2532
|
}, {
|
|
2197
|
-
F:
|
|
2533
|
+
F: __dxlog_file11,
|
|
2198
2534
|
L: 302,
|
|
2199
2535
|
S: this,
|
|
2200
2536
|
C: (f, a) => f(...a)
|
|
@@ -2204,28 +2540,28 @@ var InvitationsHandler = class {
|
|
|
2204
2540
|
...result,
|
|
2205
2541
|
state: Invitation4.State.SUCCESS
|
|
2206
2542
|
});
|
|
2207
|
-
|
|
2543
|
+
log8.trace("dxos.sdk.invitations-handler.guest.onOpen", trace5.end({
|
|
2208
2544
|
id: traceId
|
|
2209
2545
|
}), {
|
|
2210
|
-
F:
|
|
2546
|
+
F: __dxlog_file11,
|
|
2211
2547
|
L: 308,
|
|
2212
2548
|
S: this,
|
|
2213
2549
|
C: (f, a) => f(...a)
|
|
2214
2550
|
});
|
|
2215
2551
|
} catch (err) {
|
|
2216
2552
|
if (err instanceof TimeoutError) {
|
|
2217
|
-
|
|
2553
|
+
log8("timeout", {
|
|
2218
2554
|
...protocol.toJSON()
|
|
2219
2555
|
}, {
|
|
2220
|
-
F:
|
|
2556
|
+
F: __dxlog_file11,
|
|
2221
2557
|
L: 311,
|
|
2222
2558
|
S: this,
|
|
2223
2559
|
C: (f, a) => f(...a)
|
|
2224
2560
|
});
|
|
2225
2561
|
guardedState.set(extension, Invitation4.State.TIMEOUT);
|
|
2226
2562
|
} else {
|
|
2227
|
-
|
|
2228
|
-
F:
|
|
2563
|
+
log8("auth failed", err, {
|
|
2564
|
+
F: __dxlog_file11,
|
|
2229
2565
|
L: 314,
|
|
2230
2566
|
S: this,
|
|
2231
2567
|
C: (f, a) => f(...a)
|
|
@@ -2233,11 +2569,11 @@ var InvitationsHandler = class {
|
|
|
2233
2569
|
guardedState.error(extension, err);
|
|
2234
2570
|
}
|
|
2235
2571
|
extensionCtx.close(err);
|
|
2236
|
-
|
|
2572
|
+
log8.trace("dxos.sdk.invitations-handler.guest.onOpen", trace5.error({
|
|
2237
2573
|
id: traceId,
|
|
2238
2574
|
error: err
|
|
2239
2575
|
}), {
|
|
2240
|
-
F:
|
|
2576
|
+
F: __dxlog_file11,
|
|
2241
2577
|
L: 318,
|
|
2242
2578
|
S: this,
|
|
2243
2579
|
C: (f, a) => f(...a)
|
|
@@ -2250,18 +2586,18 @@ var InvitationsHandler = class {
|
|
|
2250
2586
|
return;
|
|
2251
2587
|
}
|
|
2252
2588
|
if (err instanceof TimeoutError) {
|
|
2253
|
-
|
|
2589
|
+
log8("timeout", {
|
|
2254
2590
|
...protocol.toJSON()
|
|
2255
2591
|
}, {
|
|
2256
|
-
F:
|
|
2592
|
+
F: __dxlog_file11,
|
|
2257
2593
|
L: 327,
|
|
2258
2594
|
S: this,
|
|
2259
2595
|
C: (f, a) => f(...a)
|
|
2260
2596
|
});
|
|
2261
2597
|
guardedState.set(extension, Invitation4.State.TIMEOUT);
|
|
2262
2598
|
} else {
|
|
2263
|
-
|
|
2264
|
-
F:
|
|
2599
|
+
log8("auth failed", err, {
|
|
2600
|
+
F: __dxlog_file11,
|
|
2265
2601
|
L: 330,
|
|
2266
2602
|
S: this,
|
|
2267
2603
|
C: (f, a) => f(...a)
|
|
@@ -2278,8 +2614,8 @@ var InvitationsHandler = class {
|
|
|
2278
2614
|
stream.error(error);
|
|
2279
2615
|
await ctx.dispose();
|
|
2280
2616
|
} else {
|
|
2281
|
-
|
|
2282
|
-
F:
|
|
2617
|
+
invariant9(invitation.swarmKey, void 0, {
|
|
2618
|
+
F: __dxlog_file11,
|
|
2283
2619
|
L: 345,
|
|
2284
2620
|
S: this,
|
|
2285
2621
|
A: [
|
|
@@ -2373,12 +2709,12 @@ var InvitationsHandler = class {
|
|
|
2373
2709
|
};
|
|
2374
2710
|
}
|
|
2375
2711
|
_logStateUpdate(invitation, actor, newState) {
|
|
2376
|
-
|
|
2712
|
+
log8("invitation state update", {
|
|
2377
2713
|
actor: actor?.constructor.name,
|
|
2378
2714
|
newState: stateToString(newState),
|
|
2379
2715
|
oldState: stateToString(invitation.state)
|
|
2380
2716
|
}, {
|
|
2381
|
-
F:
|
|
2717
|
+
F: __dxlog_file11,
|
|
2382
2718
|
L: 438,
|
|
2383
2719
|
S: this,
|
|
2384
2720
|
C: (f, a) => f(...a)
|
|
@@ -2395,16 +2731,16 @@ var InvitationsHandler = class {
|
|
|
2395
2731
|
}
|
|
2396
2732
|
async _handleGuestOtpAuth(extension, setState, authenticated, options) {
|
|
2397
2733
|
for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
|
|
2398
|
-
|
|
2399
|
-
F:
|
|
2734
|
+
log8("guest waiting for authentication code...", void 0, {
|
|
2735
|
+
F: __dxlog_file11,
|
|
2400
2736
|
L: 462,
|
|
2401
2737
|
S: this,
|
|
2402
2738
|
C: (f, a) => f(...a)
|
|
2403
2739
|
});
|
|
2404
2740
|
setState(Invitation4.State.READY_FOR_AUTHENTICATION);
|
|
2405
2741
|
const authCode = await authenticated.wait(options);
|
|
2406
|
-
|
|
2407
|
-
F:
|
|
2742
|
+
log8("sending authentication request", void 0, {
|
|
2743
|
+
F: __dxlog_file11,
|
|
2408
2744
|
L: 466,
|
|
2409
2745
|
S: this,
|
|
2410
2746
|
C: (f, a) => f(...a)
|
|
@@ -2420,10 +2756,10 @@ var InvitationsHandler = class {
|
|
|
2420
2756
|
if (attempt === MAX_OTP_ATTEMPTS) {
|
|
2421
2757
|
throw new Error(`Maximum retry attempts: ${MAX_OTP_ATTEMPTS}`);
|
|
2422
2758
|
} else {
|
|
2423
|
-
|
|
2759
|
+
log8("retrying invalid code", {
|
|
2424
2760
|
attempt
|
|
2425
2761
|
}, {
|
|
2426
|
-
F:
|
|
2762
|
+
F: __dxlog_file11,
|
|
2427
2763
|
L: 477,
|
|
2428
2764
|
S: this,
|
|
2429
2765
|
C: (f, a) => f(...a)
|
|
@@ -2440,8 +2776,8 @@ var InvitationsHandler = class {
|
|
|
2440
2776
|
if (introductionResponse.challenge == null) {
|
|
2441
2777
|
throw new Error("challenge missing in the introduction");
|
|
2442
2778
|
}
|
|
2443
|
-
|
|
2444
|
-
F:
|
|
2779
|
+
log8("sending authentication request", void 0, {
|
|
2780
|
+
F: __dxlog_file11,
|
|
2445
2781
|
L: 496,
|
|
2446
2782
|
S: this,
|
|
2447
2783
|
C: (f, a) => f(...a)
|
|
@@ -2465,7 +2801,7 @@ var createAdmissionKeypair = () => {
|
|
|
2465
2801
|
};
|
|
2466
2802
|
|
|
2467
2803
|
// packages/sdk/client-services/src/packlets/invitations/invitations-service.ts
|
|
2468
|
-
import { Stream as
|
|
2804
|
+
import { Stream as Stream9 } from "@dxos/codec-protobuf";
|
|
2469
2805
|
import { QueryInvitationsResponse } from "@dxos/protocols/proto/dxos/client/services";
|
|
2470
2806
|
var InvitationsServiceImpl = class {
|
|
2471
2807
|
constructor(_invitationsManager) {
|
|
@@ -2476,13 +2812,13 @@ var InvitationsServiceImpl = class {
|
|
|
2476
2812
|
return {};
|
|
2477
2813
|
}
|
|
2478
2814
|
createInvitation(options) {
|
|
2479
|
-
return new
|
|
2815
|
+
return new Stream9(({ next, close }) => {
|
|
2480
2816
|
void this._invitationsManager.createInvitation(options).then((invitation) => invitation.subscribe(next, close, close)).catch(close);
|
|
2481
2817
|
});
|
|
2482
2818
|
}
|
|
2483
2819
|
acceptInvitation(request) {
|
|
2484
2820
|
const invitation = this._invitationsManager.acceptInvitation(request);
|
|
2485
|
-
return new
|
|
2821
|
+
return new Stream9(({ next, close }) => {
|
|
2486
2822
|
invitation.subscribe(next, close, close);
|
|
2487
2823
|
});
|
|
2488
2824
|
}
|
|
@@ -2493,7 +2829,7 @@ var InvitationsServiceImpl = class {
|
|
|
2493
2829
|
return this._invitationsManager.cancelInvitation(request);
|
|
2494
2830
|
}
|
|
2495
2831
|
queryInvitations() {
|
|
2496
|
-
return new
|
|
2832
|
+
return new Stream9(({ next, ctx }) => {
|
|
2497
2833
|
this._invitationsManager.invitationCreated.on(ctx, (invitation) => {
|
|
2498
2834
|
next({
|
|
2499
2835
|
action: QueryInvitationsResponse.Action.ADDED,
|
|
@@ -2564,12 +2900,12 @@ var InvitationsServiceImpl = class {
|
|
|
2564
2900
|
// packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts
|
|
2565
2901
|
import { createAdmissionCredentials, createCancelDelegatedSpaceInvitationCredential, createDelegatedSpaceInvitationCredential, getCredentialAssertion } from "@dxos/credentials";
|
|
2566
2902
|
import { writeMessages as writeMessages2 } from "@dxos/feed-store";
|
|
2567
|
-
import { invariant as
|
|
2568
|
-
import { log as
|
|
2903
|
+
import { invariant as invariant10 } from "@dxos/invariant";
|
|
2904
|
+
import { log as log9 } from "@dxos/log";
|
|
2569
2905
|
import { AlreadyJoinedError as AlreadyJoinedError2, AuthorizationError, InvalidInvitationError, SpaceNotFoundError } from "@dxos/protocols";
|
|
2570
2906
|
import { Invitation as Invitation5 } from "@dxos/protocols/proto/dxos/client/services";
|
|
2571
|
-
import { SpaceMember } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
2572
|
-
var
|
|
2907
|
+
import { SpaceMember as SpaceMember2 } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
2908
|
+
var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
|
|
2573
2909
|
var SpaceInvitationProtocol = class {
|
|
2574
2910
|
constructor(_spaceManager, _signingContext, _keyring, _spaceKey) {
|
|
2575
2911
|
this._spaceManager = _spaceManager;
|
|
@@ -2603,8 +2939,8 @@ var SpaceInvitationProtocol = class {
|
|
|
2603
2939
|
};
|
|
2604
2940
|
}
|
|
2605
2941
|
async admit(invitation, request, guestProfile) {
|
|
2606
|
-
|
|
2607
|
-
F:
|
|
2942
|
+
invariant10(this._spaceKey, void 0, {
|
|
2943
|
+
F: __dxlog_file12,
|
|
2608
2944
|
L: 76,
|
|
2609
2945
|
S: this,
|
|
2610
2946
|
A: [
|
|
@@ -2613,8 +2949,8 @@ var SpaceInvitationProtocol = class {
|
|
|
2613
2949
|
]
|
|
2614
2950
|
});
|
|
2615
2951
|
const space = this._spaceManager.spaces.get(this._spaceKey);
|
|
2616
|
-
|
|
2617
|
-
F:
|
|
2952
|
+
invariant10(space, void 0, {
|
|
2953
|
+
F: __dxlog_file12,
|
|
2618
2954
|
L: 78,
|
|
2619
2955
|
S: this,
|
|
2620
2956
|
A: [
|
|
@@ -2622,8 +2958,8 @@ var SpaceInvitationProtocol = class {
|
|
|
2622
2958
|
""
|
|
2623
2959
|
]
|
|
2624
2960
|
});
|
|
2625
|
-
|
|
2626
|
-
F:
|
|
2961
|
+
invariant10(request.space, void 0, {
|
|
2962
|
+
F: __dxlog_file12,
|
|
2627
2963
|
L: 80,
|
|
2628
2964
|
S: this,
|
|
2629
2965
|
A: [
|
|
@@ -2632,21 +2968,21 @@ var SpaceInvitationProtocol = class {
|
|
|
2632
2968
|
]
|
|
2633
2969
|
});
|
|
2634
2970
|
const { identityKey, deviceKey } = request.space;
|
|
2635
|
-
if (space.inner.spaceState.getMemberRole(identityKey) !==
|
|
2971
|
+
if (space.inner.spaceState.getMemberRole(identityKey) !== SpaceMember2.Role.REMOVED) {
|
|
2636
2972
|
throw new AlreadyJoinedError2();
|
|
2637
2973
|
}
|
|
2638
|
-
|
|
2974
|
+
log9("writing guest credentials", {
|
|
2639
2975
|
host: this._signingContext.deviceKey,
|
|
2640
2976
|
guest: deviceKey
|
|
2641
2977
|
}, {
|
|
2642
|
-
F:
|
|
2978
|
+
F: __dxlog_file12,
|
|
2643
2979
|
L: 87,
|
|
2644
2980
|
S: this,
|
|
2645
2981
|
C: (f, a) => f(...a)
|
|
2646
2982
|
});
|
|
2647
|
-
const credentials = await createAdmissionCredentials(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, invitation.role ??
|
|
2648
|
-
|
|
2649
|
-
F:
|
|
2983
|
+
const credentials = await createAdmissionCredentials(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, invitation.role ?? SpaceMember2.Role.ADMIN, space.inner.spaceState.membershipChainHeads, guestProfile, invitation.delegationCredentialId);
|
|
2984
|
+
invariant10(credentials[0].credential, void 0, {
|
|
2985
|
+
F: __dxlog_file12,
|
|
2650
2986
|
L: 101,
|
|
2651
2987
|
S: this,
|
|
2652
2988
|
A: [
|
|
@@ -2655,8 +2991,8 @@ var SpaceInvitationProtocol = class {
|
|
|
2655
2991
|
]
|
|
2656
2992
|
});
|
|
2657
2993
|
const spaceMemberCredential = credentials[0].credential.credential;
|
|
2658
|
-
|
|
2659
|
-
F:
|
|
2994
|
+
invariant10(getCredentialAssertion(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
|
|
2995
|
+
F: __dxlog_file12,
|
|
2660
2996
|
L: 103,
|
|
2661
2997
|
S: this,
|
|
2662
2998
|
A: [
|
|
@@ -2673,8 +3009,8 @@ var SpaceInvitationProtocol = class {
|
|
|
2673
3009
|
};
|
|
2674
3010
|
}
|
|
2675
3011
|
async delegate(invitation) {
|
|
2676
|
-
|
|
2677
|
-
F:
|
|
3012
|
+
invariant10(this._spaceKey, void 0, {
|
|
3013
|
+
F: __dxlog_file12,
|
|
2678
3014
|
L: 116,
|
|
2679
3015
|
S: this,
|
|
2680
3016
|
A: [
|
|
@@ -2683,8 +3019,8 @@ var SpaceInvitationProtocol = class {
|
|
|
2683
3019
|
]
|
|
2684
3020
|
});
|
|
2685
3021
|
const space = this._spaceManager.spaces.get(this._spaceKey);
|
|
2686
|
-
|
|
2687
|
-
F:
|
|
3022
|
+
invariant10(space, void 0, {
|
|
3023
|
+
F: __dxlog_file12,
|
|
2688
3024
|
L: 118,
|
|
2689
3025
|
S: this,
|
|
2690
3026
|
A: [
|
|
@@ -2693,8 +3029,8 @@ var SpaceInvitationProtocol = class {
|
|
|
2693
3029
|
]
|
|
2694
3030
|
});
|
|
2695
3031
|
if (invitation.authMethod === Invitation5.AuthMethod.KNOWN_PUBLIC_KEY) {
|
|
2696
|
-
|
|
2697
|
-
F:
|
|
3032
|
+
invariant10(invitation.guestKeypair?.publicKey, void 0, {
|
|
3033
|
+
F: __dxlog_file12,
|
|
2698
3034
|
L: 120,
|
|
2699
3035
|
S: this,
|
|
2700
3036
|
A: [
|
|
@@ -2703,11 +3039,11 @@ var SpaceInvitationProtocol = class {
|
|
|
2703
3039
|
]
|
|
2704
3040
|
});
|
|
2705
3041
|
}
|
|
2706
|
-
|
|
3042
|
+
log9("writing delegate space invitation", {
|
|
2707
3043
|
host: this._signingContext.deviceKey,
|
|
2708
3044
|
id: invitation.invitationId
|
|
2709
3045
|
}, {
|
|
2710
|
-
F:
|
|
3046
|
+
F: __dxlog_file12,
|
|
2711
3047
|
L: 123,
|
|
2712
3048
|
S: this,
|
|
2713
3049
|
C: (f, a) => f(...a)
|
|
@@ -2716,13 +3052,13 @@ var SpaceInvitationProtocol = class {
|
|
|
2716
3052
|
invitationId: invitation.invitationId,
|
|
2717
3053
|
authMethod: invitation.authMethod,
|
|
2718
3054
|
swarmKey: invitation.swarmKey,
|
|
2719
|
-
role: invitation.role ??
|
|
3055
|
+
role: invitation.role ?? SpaceMember2.Role.ADMIN,
|
|
2720
3056
|
expiresOn: invitation.lifetime ? new Date((invitation.created?.getTime() ?? Date.now()) + invitation.lifetime) : void 0,
|
|
2721
3057
|
multiUse: invitation.multiUse ?? false,
|
|
2722
3058
|
guestKey: invitation.authMethod === Invitation5.AuthMethod.KNOWN_PUBLIC_KEY ? invitation.guestKeypair.publicKey : void 0
|
|
2723
3059
|
});
|
|
2724
|
-
|
|
2725
|
-
F:
|
|
3060
|
+
invariant10(credential.credential, void 0, {
|
|
3061
|
+
F: __dxlog_file12,
|
|
2726
3062
|
L: 143,
|
|
2727
3063
|
S: this,
|
|
2728
3064
|
A: [
|
|
@@ -2736,8 +3072,8 @@ var SpaceInvitationProtocol = class {
|
|
|
2736
3072
|
return credential.credential.credential.id;
|
|
2737
3073
|
}
|
|
2738
3074
|
async cancelDelegation(invitation) {
|
|
2739
|
-
|
|
2740
|
-
F:
|
|
3075
|
+
invariant10(this._spaceKey, void 0, {
|
|
3076
|
+
F: __dxlog_file12,
|
|
2741
3077
|
L: 149,
|
|
2742
3078
|
S: this,
|
|
2743
3079
|
A: [
|
|
@@ -2745,8 +3081,8 @@ var SpaceInvitationProtocol = class {
|
|
|
2745
3081
|
""
|
|
2746
3082
|
]
|
|
2747
3083
|
});
|
|
2748
|
-
|
|
2749
|
-
F:
|
|
3084
|
+
invariant10(invitation.type === Invitation5.Type.DELEGATED && invitation.delegationCredentialId, void 0, {
|
|
3085
|
+
F: __dxlog_file12,
|
|
2750
3086
|
L: 150,
|
|
2751
3087
|
S: this,
|
|
2752
3088
|
A: [
|
|
@@ -2755,8 +3091,8 @@ var SpaceInvitationProtocol = class {
|
|
|
2755
3091
|
]
|
|
2756
3092
|
});
|
|
2757
3093
|
const space = this._spaceManager.spaces.get(this._spaceKey);
|
|
2758
|
-
|
|
2759
|
-
F:
|
|
3094
|
+
invariant10(space, void 0, {
|
|
3095
|
+
F: __dxlog_file12,
|
|
2760
3096
|
L: 152,
|
|
2761
3097
|
S: this,
|
|
2762
3098
|
A: [
|
|
@@ -2764,18 +3100,18 @@ var SpaceInvitationProtocol = class {
|
|
|
2764
3100
|
""
|
|
2765
3101
|
]
|
|
2766
3102
|
});
|
|
2767
|
-
|
|
3103
|
+
log9("cancelling delegated space invitation", {
|
|
2768
3104
|
host: this._signingContext.deviceKey,
|
|
2769
3105
|
id: invitation.invitationId
|
|
2770
3106
|
}, {
|
|
2771
|
-
F:
|
|
3107
|
+
F: __dxlog_file12,
|
|
2772
3108
|
L: 154,
|
|
2773
3109
|
S: this,
|
|
2774
3110
|
C: (f, a) => f(...a)
|
|
2775
3111
|
});
|
|
2776
3112
|
const credential = await createCancelDelegatedSpaceInvitationCredential(this._signingContext.credentialSigner, space.key, invitation.delegationCredentialId);
|
|
2777
|
-
|
|
2778
|
-
F:
|
|
3113
|
+
invariant10(credential.credential, void 0, {
|
|
3114
|
+
F: __dxlog_file12,
|
|
2779
3115
|
L: 161,
|
|
2780
3116
|
S: this,
|
|
2781
3117
|
A: [
|
|
@@ -2813,8 +3149,8 @@ var SpaceInvitationProtocol = class {
|
|
|
2813
3149
|
};
|
|
2814
3150
|
}
|
|
2815
3151
|
async accept(response) {
|
|
2816
|
-
|
|
2817
|
-
F:
|
|
3152
|
+
invariant10(response.space, void 0, {
|
|
3153
|
+
F: __dxlog_file12,
|
|
2818
3154
|
L: 196,
|
|
2819
3155
|
S: this,
|
|
2820
3156
|
A: [
|
|
@@ -2824,8 +3160,8 @@ var SpaceInvitationProtocol = class {
|
|
|
2824
3160
|
});
|
|
2825
3161
|
const { credential, controlTimeframe, dataTimeframe } = response.space;
|
|
2826
3162
|
const assertion = getCredentialAssertion(credential);
|
|
2827
|
-
|
|
2828
|
-
F:
|
|
3163
|
+
invariant10(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
|
|
3164
|
+
F: __dxlog_file12,
|
|
2829
3165
|
L: 199,
|
|
2830
3166
|
S: this,
|
|
2831
3167
|
A: [
|
|
@@ -2833,8 +3169,8 @@ var SpaceInvitationProtocol = class {
|
|
|
2833
3169
|
"'Invalid credential'"
|
|
2834
3170
|
]
|
|
2835
3171
|
});
|
|
2836
|
-
|
|
2837
|
-
F:
|
|
3172
|
+
invariant10(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
|
|
3173
|
+
F: __dxlog_file12,
|
|
2838
3174
|
L: 200,
|
|
2839
3175
|
S: this,
|
|
2840
3176
|
A: [
|
|
@@ -2859,17 +3195,17 @@ var SpaceInvitationProtocol = class {
|
|
|
2859
3195
|
};
|
|
2860
3196
|
|
|
2861
3197
|
// packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts
|
|
2862
|
-
import { Event as Event3, PushStream, TimeoutError as TimeoutError2, Trigger as
|
|
3198
|
+
import { Event as Event3, PushStream, TimeoutError as TimeoutError2, Trigger as Trigger5 } from "@dxos/async";
|
|
2863
3199
|
import { AuthenticatingInvitation, AUTHENTICATION_CODE_LENGTH, CancellableInvitation, INVITATION_TIMEOUT as INVITATION_TIMEOUT2 } from "@dxos/client-protocol";
|
|
2864
3200
|
import { Context as Context6 } from "@dxos/context";
|
|
2865
3201
|
import { generatePasscode } from "@dxos/credentials";
|
|
2866
3202
|
import { hasInvitationExpired } from "@dxos/echo-pipeline";
|
|
2867
|
-
import { invariant as
|
|
3203
|
+
import { invariant as invariant11 } from "@dxos/invariant";
|
|
2868
3204
|
import { PublicKey as PublicKey8 } from "@dxos/keys";
|
|
2869
|
-
import { log as
|
|
3205
|
+
import { log as log10 } from "@dxos/log";
|
|
2870
3206
|
import { Invitation as Invitation6 } from "@dxos/protocols/proto/dxos/client/services";
|
|
2871
|
-
import { SpaceMember as
|
|
2872
|
-
var
|
|
3207
|
+
import { SpaceMember as SpaceMember3 } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
3208
|
+
var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts";
|
|
2873
3209
|
var InvitationsManager = class {
|
|
2874
3210
|
constructor(_invitationsHandler, _getHandler, _metadataStore) {
|
|
2875
3211
|
this._invitationsHandler = _invitationsHandler;
|
|
@@ -2911,8 +3247,8 @@ var InvitationsManager = class {
|
|
|
2911
3247
|
try {
|
|
2912
3248
|
await this._persistIfRequired(handler, stream, invitation);
|
|
2913
3249
|
} catch (err) {
|
|
2914
|
-
|
|
2915
|
-
F:
|
|
3250
|
+
log10.catch(err, void 0, {
|
|
3251
|
+
F: __dxlog_file13,
|
|
2916
3252
|
L: 82,
|
|
2917
3253
|
S: this,
|
|
2918
3254
|
C: (f, a) => f(...a)
|
|
@@ -2934,8 +3270,8 @@ var InvitationsManager = class {
|
|
|
2934
3270
|
const persistentInvitations = this._metadataStore.getInvitations();
|
|
2935
3271
|
const freshInvitations = persistentInvitations.filter((invitation) => !hasInvitationExpired(invitation));
|
|
2936
3272
|
const loadTasks = freshInvitations.map((persistentInvitation) => {
|
|
2937
|
-
|
|
2938
|
-
F:
|
|
3273
|
+
invariant11(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
|
|
3274
|
+
F: __dxlog_file13,
|
|
2939
3275
|
L: 103,
|
|
2940
3276
|
S: this,
|
|
2941
3277
|
A: [
|
|
@@ -2953,8 +3289,8 @@ var InvitationsManager = class {
|
|
|
2953
3289
|
invitations: cInvitations.map((invitation) => invitation.get())
|
|
2954
3290
|
};
|
|
2955
3291
|
} catch (err) {
|
|
2956
|
-
|
|
2957
|
-
F:
|
|
3292
|
+
log10.catch(err, void 0, {
|
|
3293
|
+
F: __dxlog_file13,
|
|
2958
3294
|
L: 110,
|
|
2959
3295
|
S: this,
|
|
2960
3296
|
C: (f, a) => f(...a)
|
|
@@ -2985,14 +3321,14 @@ var InvitationsManager = class {
|
|
|
2985
3321
|
return invitation;
|
|
2986
3322
|
}
|
|
2987
3323
|
async authenticate({ invitationId, authCode }) {
|
|
2988
|
-
|
|
2989
|
-
F:
|
|
3324
|
+
log10("authenticating...", void 0, {
|
|
3325
|
+
F: __dxlog_file13,
|
|
2990
3326
|
L: 140,
|
|
2991
3327
|
S: this,
|
|
2992
3328
|
C: (f, a) => f(...a)
|
|
2993
3329
|
});
|
|
2994
|
-
|
|
2995
|
-
F:
|
|
3330
|
+
invariant11(invitationId, void 0, {
|
|
3331
|
+
F: __dxlog_file13,
|
|
2996
3332
|
L: 141,
|
|
2997
3333
|
S: this,
|
|
2998
3334
|
A: [
|
|
@@ -3002,10 +3338,10 @@ var InvitationsManager = class {
|
|
|
3002
3338
|
});
|
|
3003
3339
|
const observable = this._acceptInvitations.get(invitationId);
|
|
3004
3340
|
if (!observable) {
|
|
3005
|
-
|
|
3341
|
+
log10.warn("invalid invitation", {
|
|
3006
3342
|
invitationId
|
|
3007
3343
|
}, {
|
|
3008
|
-
F:
|
|
3344
|
+
F: __dxlog_file13,
|
|
3009
3345
|
L: 144,
|
|
3010
3346
|
S: this,
|
|
3011
3347
|
C: (f, a) => f(...a)
|
|
@@ -3015,16 +3351,16 @@ var InvitationsManager = class {
|
|
|
3015
3351
|
}
|
|
3016
3352
|
}
|
|
3017
3353
|
async cancelInvitation({ invitationId }) {
|
|
3018
|
-
|
|
3354
|
+
log10("cancelInvitation...", {
|
|
3019
3355
|
invitationId
|
|
3020
3356
|
}, {
|
|
3021
|
-
F:
|
|
3357
|
+
F: __dxlog_file13,
|
|
3022
3358
|
L: 151,
|
|
3023
3359
|
S: this,
|
|
3024
3360
|
C: (f, a) => f(...a)
|
|
3025
3361
|
});
|
|
3026
|
-
|
|
3027
|
-
F:
|
|
3362
|
+
invariant11(invitationId, void 0, {
|
|
3363
|
+
F: __dxlog_file13,
|
|
3028
3364
|
L: 152,
|
|
3029
3365
|
S: this,
|
|
3030
3366
|
A: [
|
|
@@ -3071,7 +3407,7 @@ var InvitationsManager = class {
|
|
|
3071
3407
|
}
|
|
3072
3408
|
}
|
|
3073
3409
|
_createInvitation(protocol, options) {
|
|
3074
|
-
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 =
|
|
3410
|
+
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 = SpaceMember3.Role.ADMIN, lifetime = 86400, multiUse = false } = options ?? {};
|
|
3075
3411
|
const authCode = options?.authCode ?? (authMethod === Invitation6.AuthMethod.SHARED_SECRET ? generatePasscode(AUTHENTICATION_CODE_LENGTH) : void 0);
|
|
3076
3412
|
return {
|
|
3077
3413
|
invitationId,
|
|
@@ -3100,10 +3436,10 @@ var InvitationsManager = class {
|
|
|
3100
3436
|
}
|
|
3101
3437
|
});
|
|
3102
3438
|
ctx.onDispose(() => {
|
|
3103
|
-
|
|
3439
|
+
log10("complete", {
|
|
3104
3440
|
...handler.toJSON()
|
|
3105
3441
|
}, {
|
|
3106
|
-
F:
|
|
3442
|
+
F: __dxlog_file13,
|
|
3107
3443
|
L: 241,
|
|
3108
3444
|
S: this,
|
|
3109
3445
|
C: (f, a) => f(...a)
|
|
@@ -3128,15 +3464,15 @@ var InvitationsManager = class {
|
|
|
3128
3464
|
};
|
|
3129
3465
|
}
|
|
3130
3466
|
_createObservableAcceptingInvitation(handler, initialState) {
|
|
3131
|
-
const otpEnteredTrigger = new
|
|
3467
|
+
const otpEnteredTrigger = new Trigger5();
|
|
3132
3468
|
const stream = new PushStream();
|
|
3133
3469
|
const ctx = new Context6({
|
|
3134
3470
|
onError: (err) => {
|
|
3135
3471
|
if (err instanceof TimeoutError2) {
|
|
3136
|
-
|
|
3472
|
+
log10("timeout", {
|
|
3137
3473
|
...handler.toJSON()
|
|
3138
3474
|
}, {
|
|
3139
|
-
F:
|
|
3475
|
+
F: __dxlog_file13,
|
|
3140
3476
|
L: 261,
|
|
3141
3477
|
S: this,
|
|
3142
3478
|
C: (f, a) => f(...a)
|
|
@@ -3146,8 +3482,8 @@ var InvitationsManager = class {
|
|
|
3146
3482
|
state: Invitation6.State.TIMEOUT
|
|
3147
3483
|
});
|
|
3148
3484
|
} else {
|
|
3149
|
-
|
|
3150
|
-
F:
|
|
3485
|
+
log10.warn("auth failed", err, {
|
|
3486
|
+
F: __dxlog_file13,
|
|
3151
3487
|
L: 264,
|
|
3152
3488
|
S: this,
|
|
3153
3489
|
C: (f, a) => f(...a)
|
|
@@ -3161,10 +3497,10 @@ var InvitationsManager = class {
|
|
|
3161
3497
|
}
|
|
3162
3498
|
});
|
|
3163
3499
|
ctx.onDispose(() => {
|
|
3164
|
-
|
|
3500
|
+
log10("complete", {
|
|
3165
3501
|
...handler.toJSON()
|
|
3166
3502
|
}, {
|
|
3167
|
-
F:
|
|
3503
|
+
F: __dxlog_file13,
|
|
3168
3504
|
L: 271,
|
|
3169
3505
|
S: this,
|
|
3170
3506
|
C: (f, a) => f(...a)
|
|
@@ -3208,8 +3544,8 @@ var InvitationsManager = class {
|
|
|
3208
3544
|
try {
|
|
3209
3545
|
await this._metadataStore.removeInvitation(invitation.invitationId);
|
|
3210
3546
|
} catch (err) {
|
|
3211
|
-
|
|
3212
|
-
F:
|
|
3547
|
+
log10.catch(err, void 0, {
|
|
3548
|
+
F: __dxlog_file13,
|
|
3213
3549
|
L: 307,
|
|
3214
3550
|
S: this,
|
|
3215
3551
|
C: (f, a) => f(...a)
|
|
@@ -3223,100 +3559,19 @@ var InvitationsManager = class {
|
|
|
3223
3559
|
}
|
|
3224
3560
|
};
|
|
3225
3561
|
|
|
3226
|
-
// packages/sdk/client-services/src/packlets/services/client-rpc-server.ts
|
|
3227
|
-
import { Stream as Stream9 } from "@dxos/codec-protobuf";
|
|
3228
|
-
import { raise } from "@dxos/debug";
|
|
3229
|
-
import { parseMethodName, RpcPeer } from "@dxos/rpc";
|
|
3230
|
-
import { MapCounter, trace as trace5 } from "@dxos/tracing";
|
|
3231
|
-
function _ts_decorate3(decorators, target, key, desc) {
|
|
3232
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3233
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
3234
|
-
r = Reflect.decorate(decorators, target, key, desc);
|
|
3235
|
-
else
|
|
3236
|
-
for (var i = decorators.length - 1; i >= 0; i--)
|
|
3237
|
-
if (d = decorators[i])
|
|
3238
|
-
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
3239
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3240
|
-
}
|
|
3241
|
-
var ClientRpcServer = class {
|
|
3242
|
-
constructor(params) {
|
|
3243
|
-
this._handlerCache = /* @__PURE__ */ new Map();
|
|
3244
|
-
this._callMetrics = new MapCounter();
|
|
3245
|
-
const { serviceRegistry, handleCall, handleStream, ...rpcOptions } = params;
|
|
3246
|
-
this._handleCall = handleCall;
|
|
3247
|
-
this._handleStream = handleStream;
|
|
3248
|
-
this._serviceRegistry = serviceRegistry;
|
|
3249
|
-
this._rpcPeer = new RpcPeer({
|
|
3250
|
-
...rpcOptions,
|
|
3251
|
-
callHandler: (method, params2) => {
|
|
3252
|
-
const [serviceName, methodName] = parseMethodName(method);
|
|
3253
|
-
const handler = (method2, params3) => this._getServiceHandler(serviceName).call(method2, params3);
|
|
3254
|
-
this._callMetrics.inc(`${serviceName}.${methodName} request`);
|
|
3255
|
-
if (this._handleCall) {
|
|
3256
|
-
return this._handleCall(methodName, params2, handler);
|
|
3257
|
-
} else {
|
|
3258
|
-
return handler(methodName, params2);
|
|
3259
|
-
}
|
|
3260
|
-
},
|
|
3261
|
-
streamHandler: (method, params2) => {
|
|
3262
|
-
const [serviceName, methodName] = parseMethodName(method);
|
|
3263
|
-
const handler = (method2, params3) => this._getServiceHandler(serviceName).callStream(method2, params3);
|
|
3264
|
-
this._callMetrics.inc(`${serviceName}.${methodName} request stream`);
|
|
3265
|
-
if (this._handleStream) {
|
|
3266
|
-
return Stream9.map(Stream9.unwrapPromise(this._handleStream(methodName, params2, handler)), (data) => {
|
|
3267
|
-
this._callMetrics.inc(`${serviceName}.${methodName} response stream`);
|
|
3268
|
-
return data;
|
|
3269
|
-
});
|
|
3270
|
-
} else {
|
|
3271
|
-
return handler(methodName, params2);
|
|
3272
|
-
}
|
|
3273
|
-
}
|
|
3274
|
-
});
|
|
3275
|
-
}
|
|
3276
|
-
get _services() {
|
|
3277
|
-
return Object.keys(this._serviceRegistry.services);
|
|
3278
|
-
}
|
|
3279
|
-
async open() {
|
|
3280
|
-
await this._rpcPeer.open();
|
|
3281
|
-
}
|
|
3282
|
-
async close() {
|
|
3283
|
-
await this._rpcPeer.close();
|
|
3284
|
-
}
|
|
3285
|
-
_getServiceHandler(serviceName) {
|
|
3286
|
-
if (!this._handlerCache.has(serviceName)) {
|
|
3287
|
-
const [key, descriptor] = Object.entries(this._serviceRegistry.descriptors).find(([key2, descriptor2]) => descriptor2.name === serviceName) ?? raise(new Error(`Service not available: ${serviceName}`));
|
|
3288
|
-
const service = this._serviceRegistry.services[key];
|
|
3289
|
-
if (!service) {
|
|
3290
|
-
throw new Error(`Service not available: ${serviceName}`);
|
|
3291
|
-
}
|
|
3292
|
-
this._handlerCache.set(serviceName, descriptor.createServer(service));
|
|
3293
|
-
}
|
|
3294
|
-
return this._handlerCache.get(serviceName);
|
|
3295
|
-
}
|
|
3296
|
-
};
|
|
3297
|
-
_ts_decorate3([
|
|
3298
|
-
trace5.metricsCounter()
|
|
3299
|
-
], ClientRpcServer.prototype, "_callMetrics", void 0);
|
|
3300
|
-
_ts_decorate3([
|
|
3301
|
-
trace5.info()
|
|
3302
|
-
], ClientRpcServer.prototype, "_services", null);
|
|
3303
|
-
ClientRpcServer = _ts_decorate3([
|
|
3304
|
-
trace5.resource()
|
|
3305
|
-
], ClientRpcServer);
|
|
3306
|
-
|
|
3307
3562
|
// packages/sdk/client-services/src/packlets/spaces/data-space.ts
|
|
3308
|
-
import { Event as Event6, asyncTimeout, scheduleTask as scheduleTask5, sleep as sleep2, synchronized, trackLeaks } from "@dxos/async";
|
|
3563
|
+
import { Event as Event6, asyncTimeout as asyncTimeout2, scheduleTask as scheduleTask5, sleep as sleep2, synchronized, trackLeaks } from "@dxos/async";
|
|
3309
3564
|
import { AUTH_TIMEOUT as AUTH_TIMEOUT2 } from "@dxos/client-protocol";
|
|
3310
3565
|
import { Context as Context8, ContextDisposedError as ContextDisposedError3, cancelWithContext as cancelWithContext4 } from "@dxos/context";
|
|
3311
3566
|
import { timed, warnAfterTimeout } from "@dxos/debug";
|
|
3312
|
-
import { AutomergeDocumentLoaderImpl, createMappedFeedWriter } from "@dxos/echo-pipeline";
|
|
3567
|
+
import { AutomergeDocumentLoaderImpl, createIdFromSpaceKey, createMappedFeedWriter } from "@dxos/echo-pipeline";
|
|
3313
3568
|
import { TYPE_PROPERTIES } from "@dxos/echo-schema";
|
|
3314
|
-
import { failedInvariant, invariant as
|
|
3569
|
+
import { failedInvariant, invariant as invariant13 } from "@dxos/invariant";
|
|
3315
3570
|
import { PublicKey as PublicKey10 } from "@dxos/keys";
|
|
3316
|
-
import { log as
|
|
3571
|
+
import { log as log12 } from "@dxos/log";
|
|
3317
3572
|
import { CancelledError, SystemError } from "@dxos/protocols";
|
|
3318
3573
|
import { CreateEpochRequest, SpaceState } from "@dxos/protocols/proto/dxos/client/services";
|
|
3319
|
-
import { AdmittedFeed as AdmittedFeed3, SpaceMember as
|
|
3574
|
+
import { AdmittedFeed as AdmittedFeed3, SpaceMember as SpaceMember4 } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
3320
3575
|
import { Timeframe as Timeframe2 } from "@dxos/timeframe";
|
|
3321
3576
|
import { trace as trace6 } from "@dxos/tracing";
|
|
3322
3577
|
import { ComplexSet as ComplexSet5, assignDeep } from "@dxos/util";
|
|
@@ -3360,15 +3615,15 @@ var AutomergeSpaceState = class {
|
|
|
3360
3615
|
};
|
|
3361
3616
|
|
|
3362
3617
|
// packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
|
|
3363
|
-
import { DeferredTask, Event as Event5, scheduleTask as scheduleTask4, sleep, TimeoutError as TimeoutError3, Trigger as
|
|
3618
|
+
import { DeferredTask, Event as Event5, scheduleTask as scheduleTask4, sleep, TimeoutError as TimeoutError3, Trigger as Trigger6 } from "@dxos/async";
|
|
3364
3619
|
import { Context as Context7, rejectOnDispose } from "@dxos/context";
|
|
3365
|
-
import { invariant as
|
|
3620
|
+
import { invariant as invariant12 } from "@dxos/invariant";
|
|
3366
3621
|
import { PublicKey as PublicKey9 } from "@dxos/keys";
|
|
3367
|
-
import { log as
|
|
3622
|
+
import { log as log11 } from "@dxos/log";
|
|
3368
3623
|
import { schema as schema4 } from "@dxos/protocols";
|
|
3369
3624
|
import { RpcExtension as RpcExtension3 } from "@dxos/teleport";
|
|
3370
3625
|
import { ComplexMap as ComplexMap2, ComplexSet as ComplexSet4, entry } from "@dxos/util";
|
|
3371
|
-
var
|
|
3626
|
+
var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
|
|
3372
3627
|
var DEFAULT_RETRY_TIMEOUT = 1e3;
|
|
3373
3628
|
var DEFAULT_SUCCESS_DELAY = 1e3;
|
|
3374
3629
|
var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
|
|
@@ -3393,16 +3648,16 @@ var NotarizationPlugin = class {
|
|
|
3393
3648
|
* Request credentials to be notarized.
|
|
3394
3649
|
*/
|
|
3395
3650
|
async notarize({ ctx: opCtx, credentials, timeout = DEFAULT_NOTARIZE_TIMEOUT, retryTimeout = DEFAULT_RETRY_TIMEOUT, successDelay = DEFAULT_SUCCESS_DELAY }) {
|
|
3396
|
-
|
|
3651
|
+
log11("notarize", {
|
|
3397
3652
|
credentials
|
|
3398
3653
|
}, {
|
|
3399
|
-
F:
|
|
3654
|
+
F: __dxlog_file14,
|
|
3400
3655
|
L: 90,
|
|
3401
3656
|
S: this,
|
|
3402
3657
|
C: (f, a) => f(...a)
|
|
3403
3658
|
});
|
|
3404
|
-
|
|
3405
|
-
F:
|
|
3659
|
+
invariant12(credentials.every((credential) => credential.id), "Credentials must have an id", {
|
|
3660
|
+
F: __dxlog_file14,
|
|
3406
3661
|
L: 91,
|
|
3407
3662
|
S: this,
|
|
3408
3663
|
A: [
|
|
@@ -3410,13 +3665,13 @@ var NotarizationPlugin = class {
|
|
|
3410
3665
|
"'Credentials must have an id'"
|
|
3411
3666
|
]
|
|
3412
3667
|
});
|
|
3413
|
-
const errors = new
|
|
3668
|
+
const errors = new Trigger6();
|
|
3414
3669
|
const ctx = this._ctx.derive({
|
|
3415
3670
|
onError: (err) => {
|
|
3416
|
-
|
|
3671
|
+
log11.warn("Notarization error", {
|
|
3417
3672
|
err
|
|
3418
3673
|
}, {
|
|
3419
|
-
F:
|
|
3674
|
+
F: __dxlog_file14,
|
|
3420
3675
|
L: 99,
|
|
3421
3676
|
S: this,
|
|
3422
3677
|
C: (f, a) => f(...a)
|
|
@@ -3428,11 +3683,11 @@ var NotarizationPlugin = class {
|
|
|
3428
3683
|
opCtx?.onDispose(() => ctx.dispose());
|
|
3429
3684
|
if (timeout !== 0) {
|
|
3430
3685
|
scheduleTask4(ctx, () => {
|
|
3431
|
-
|
|
3686
|
+
log11.warn("Notarization timeout", {
|
|
3432
3687
|
timeout,
|
|
3433
3688
|
peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
|
|
3434
3689
|
}, {
|
|
3435
|
-
F:
|
|
3690
|
+
F: __dxlog_file14,
|
|
3436
3691
|
L: 111,
|
|
3437
3692
|
S: this,
|
|
3438
3693
|
C: (f, a) => f(...a)
|
|
@@ -3452,10 +3707,10 @@ var NotarizationPlugin = class {
|
|
|
3452
3707
|
...this._extensions
|
|
3453
3708
|
].find((peer2) => !peersTried.has(peer2));
|
|
3454
3709
|
if (!peer) {
|
|
3455
|
-
|
|
3710
|
+
log11.info("Exhausted all peers to notarize with", {
|
|
3456
3711
|
retryIn: retryTimeout
|
|
3457
3712
|
}, {
|
|
3458
|
-
F:
|
|
3713
|
+
F: __dxlog_file14,
|
|
3459
3714
|
L: 136,
|
|
3460
3715
|
S: this,
|
|
3461
3716
|
C: (f, a) => f(...a)
|
|
@@ -3465,11 +3720,11 @@ var NotarizationPlugin = class {
|
|
|
3465
3720
|
return;
|
|
3466
3721
|
}
|
|
3467
3722
|
peersTried.add(peer);
|
|
3468
|
-
|
|
3723
|
+
log11("try notarizing", {
|
|
3469
3724
|
peer: peer.localPeerId,
|
|
3470
3725
|
credentialId: credentials.map((credential) => credential.id)
|
|
3471
3726
|
}, {
|
|
3472
|
-
F:
|
|
3727
|
+
F: __dxlog_file14,
|
|
3473
3728
|
L: 143,
|
|
3474
3729
|
S: this,
|
|
3475
3730
|
C: (f, a) => f(...a)
|
|
@@ -3477,8 +3732,8 @@ var NotarizationPlugin = class {
|
|
|
3477
3732
|
await peer.rpc.NotarizationService.notarize({
|
|
3478
3733
|
credentials: credentials.filter((credential) => !this._processedCredentials.has(credential.id))
|
|
3479
3734
|
});
|
|
3480
|
-
|
|
3481
|
-
F:
|
|
3735
|
+
log11("success", void 0, {
|
|
3736
|
+
F: __dxlog_file14,
|
|
3482
3737
|
L: 147,
|
|
3483
3738
|
S: this,
|
|
3484
3739
|
C: (f, a) => f(...a)
|
|
@@ -3486,8 +3741,8 @@ var NotarizationPlugin = class {
|
|
|
3486
3741
|
await sleep(successDelay);
|
|
3487
3742
|
} catch (err) {
|
|
3488
3743
|
if (!ctx.disposed && !err.message.includes(WRITER_NOT_SET_ERROR_CODE)) {
|
|
3489
|
-
|
|
3490
|
-
F:
|
|
3744
|
+
log11.info("error notarizing (recoverable)", err, {
|
|
3745
|
+
F: __dxlog_file14,
|
|
3491
3746
|
L: 151,
|
|
3492
3747
|
S: this,
|
|
3493
3748
|
C: (f, a) => f(...a)
|
|
@@ -3504,8 +3759,8 @@ var NotarizationPlugin = class {
|
|
|
3504
3759
|
allNotarized,
|
|
3505
3760
|
errors.wait()
|
|
3506
3761
|
]);
|
|
3507
|
-
|
|
3508
|
-
F:
|
|
3762
|
+
log11("done", void 0, {
|
|
3763
|
+
F: __dxlog_file14,
|
|
3509
3764
|
L: 162,
|
|
3510
3765
|
S: this,
|
|
3511
3766
|
C: (f, a) => f(...a)
|
|
@@ -3526,8 +3781,8 @@ var NotarizationPlugin = class {
|
|
|
3526
3781
|
this._processCredentialsTriggers.delete(credential.id);
|
|
3527
3782
|
}
|
|
3528
3783
|
setWriter(writer) {
|
|
3529
|
-
|
|
3530
|
-
F:
|
|
3784
|
+
invariant12(!this._writer, "Writer already set.", {
|
|
3785
|
+
F: __dxlog_file14,
|
|
3531
3786
|
L: 181,
|
|
3532
3787
|
S: this,
|
|
3533
3788
|
A: [
|
|
@@ -3541,7 +3796,7 @@ var NotarizationPlugin = class {
|
|
|
3541
3796
|
if (this._processedCredentials.has(id)) {
|
|
3542
3797
|
return;
|
|
3543
3798
|
}
|
|
3544
|
-
await entry(this._processCredentialsTriggers, id).orInsert(new
|
|
3799
|
+
await entry(this._processCredentialsTriggers, id).orInsert(new Trigger6()).value.wait();
|
|
3545
3800
|
}
|
|
3546
3801
|
/**
|
|
3547
3802
|
* Requests from other peers to notarize credentials.
|
|
@@ -3551,8 +3806,8 @@ var NotarizationPlugin = class {
|
|
|
3551
3806
|
throw new Error(WRITER_NOT_SET_ERROR_CODE);
|
|
3552
3807
|
}
|
|
3553
3808
|
for (const credential of request.credentials ?? []) {
|
|
3554
|
-
|
|
3555
|
-
F:
|
|
3809
|
+
invariant12(credential.id, "Credential must have an id", {
|
|
3810
|
+
F: __dxlog_file14,
|
|
3556
3811
|
L: 200,
|
|
3557
3812
|
S: this,
|
|
3558
3813
|
A: [
|
|
@@ -3569,10 +3824,10 @@ var NotarizationPlugin = class {
|
|
|
3569
3824
|
createExtension() {
|
|
3570
3825
|
const extension = new NotarizationTeleportExtension({
|
|
3571
3826
|
onOpen: async () => {
|
|
3572
|
-
|
|
3827
|
+
log11("extension opened", {
|
|
3573
3828
|
peer: extension.localPeerId
|
|
3574
3829
|
}, {
|
|
3575
|
-
F:
|
|
3830
|
+
F: __dxlog_file14,
|
|
3576
3831
|
L: 211,
|
|
3577
3832
|
S: this,
|
|
3578
3833
|
C: (f, a) => f(...a)
|
|
@@ -3581,10 +3836,10 @@ var NotarizationPlugin = class {
|
|
|
3581
3836
|
this._extensionOpened.emit();
|
|
3582
3837
|
},
|
|
3583
3838
|
onClose: async () => {
|
|
3584
|
-
|
|
3839
|
+
log11("extension closed", {
|
|
3585
3840
|
peer: extension.localPeerId
|
|
3586
3841
|
}, {
|
|
3587
|
-
F:
|
|
3842
|
+
F: __dxlog_file14,
|
|
3588
3843
|
L: 216,
|
|
3589
3844
|
S: this,
|
|
3590
3845
|
C: (f, a) => f(...a)
|
|
@@ -3638,7 +3893,7 @@ function _ts_decorate4(decorators, target, key, desc) {
|
|
|
3638
3893
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
3639
3894
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3640
3895
|
}
|
|
3641
|
-
var
|
|
3896
|
+
var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
|
|
3642
3897
|
var DataSpace = class {
|
|
3643
3898
|
constructor(params) {
|
|
3644
3899
|
this._ctx = new Context8();
|
|
@@ -3664,21 +3919,24 @@ var DataSpace = class {
|
|
|
3664
3919
|
this._callbacks = params.callbacks ?? {};
|
|
3665
3920
|
this._echoHost = params.echoHost;
|
|
3666
3921
|
this.authVerifier = new TrustedKeySetAuthVerifier({
|
|
3667
|
-
trustedKeysProvider: () => new ComplexSet5(PublicKey10.hash, Array.from(this._inner.spaceState.members.values()).filter((member) => member.role !==
|
|
3922
|
+
trustedKeysProvider: () => new ComplexSet5(PublicKey10.hash, Array.from(this._inner.spaceState.members.values()).filter((member) => member.role !== SpaceMember4.Role.REMOVED).map((member) => member.key)),
|
|
3668
3923
|
update: this._inner.stateUpdate,
|
|
3669
3924
|
authTimeout: AUTH_TIMEOUT2
|
|
3670
3925
|
});
|
|
3671
3926
|
this._cache = params.cache;
|
|
3672
3927
|
this._state = params.initialState;
|
|
3673
|
-
|
|
3928
|
+
log12("new state", {
|
|
3674
3929
|
state: SpaceState[this._state]
|
|
3675
3930
|
}, {
|
|
3676
|
-
F:
|
|
3677
|
-
L:
|
|
3931
|
+
F: __dxlog_file15,
|
|
3932
|
+
L: 142,
|
|
3678
3933
|
S: this,
|
|
3679
3934
|
C: (f, a) => f(...a)
|
|
3680
3935
|
});
|
|
3681
3936
|
}
|
|
3937
|
+
get id() {
|
|
3938
|
+
return this._inner.id;
|
|
3939
|
+
}
|
|
3682
3940
|
get key() {
|
|
3683
3941
|
return this._inner.key;
|
|
3684
3942
|
}
|
|
@@ -3720,11 +3978,11 @@ var DataSpace = class {
|
|
|
3720
3978
|
await this._inner.spaceState.addCredentialProcessor(this._automergeSpaceState);
|
|
3721
3979
|
await this._inner.open(new Context8());
|
|
3722
3980
|
this._state = SpaceState.CONTROL_ONLY;
|
|
3723
|
-
|
|
3981
|
+
log12("new state", {
|
|
3724
3982
|
state: SpaceState[this._state]
|
|
3725
3983
|
}, {
|
|
3726
|
-
F:
|
|
3727
|
-
L:
|
|
3984
|
+
F: __dxlog_file15,
|
|
3985
|
+
L: 205,
|
|
3728
3986
|
S: this,
|
|
3729
3987
|
C: (f, a) => f(...a)
|
|
3730
3988
|
});
|
|
@@ -3738,11 +3996,11 @@ var DataSpace = class {
|
|
|
3738
3996
|
async _close() {
|
|
3739
3997
|
await this._callbacks.beforeClose?.();
|
|
3740
3998
|
this._state = SpaceState.CLOSED;
|
|
3741
|
-
|
|
3999
|
+
log12("new state", {
|
|
3742
4000
|
state: SpaceState[this._state]
|
|
3743
4001
|
}, {
|
|
3744
|
-
F:
|
|
3745
|
-
L:
|
|
4002
|
+
F: __dxlog_file15,
|
|
4003
|
+
L: 219,
|
|
3746
4004
|
S: this,
|
|
3747
4005
|
C: (f, a) => f(...a)
|
|
3748
4006
|
});
|
|
@@ -3772,26 +4030,26 @@ var DataSpace = class {
|
|
|
3772
4030
|
await this.initializeDataPipeline();
|
|
3773
4031
|
} catch (err) {
|
|
3774
4032
|
if (err instanceof CancelledError || err instanceof ContextDisposedError3) {
|
|
3775
|
-
|
|
3776
|
-
F:
|
|
3777
|
-
L:
|
|
4033
|
+
log12("data pipeline initialization cancelled", err, {
|
|
4034
|
+
F: __dxlog_file15,
|
|
4035
|
+
L: 252,
|
|
3778
4036
|
S: this,
|
|
3779
4037
|
C: (f, a) => f(...a)
|
|
3780
4038
|
});
|
|
3781
4039
|
return;
|
|
3782
4040
|
}
|
|
3783
|
-
|
|
3784
|
-
F:
|
|
3785
|
-
L:
|
|
4041
|
+
log12.error("Error initializing data pipeline", err, {
|
|
4042
|
+
F: __dxlog_file15,
|
|
4043
|
+
L: 256,
|
|
3786
4044
|
S: this,
|
|
3787
4045
|
C: (f, a) => f(...a)
|
|
3788
4046
|
});
|
|
3789
4047
|
this._state = SpaceState.ERROR;
|
|
3790
|
-
|
|
4048
|
+
log12("new state", {
|
|
3791
4049
|
state: SpaceState[this._state]
|
|
3792
4050
|
}, {
|
|
3793
|
-
F:
|
|
3794
|
-
L:
|
|
4051
|
+
F: __dxlog_file15,
|
|
4052
|
+
L: 258,
|
|
3795
4053
|
S: this,
|
|
3796
4054
|
C: (f, a) => f(...a)
|
|
3797
4055
|
});
|
|
@@ -3807,11 +4065,11 @@ var DataSpace = class {
|
|
|
3807
4065
|
throw new SystemError("Invalid operation");
|
|
3808
4066
|
}
|
|
3809
4067
|
this._state = SpaceState.INITIALIZING;
|
|
3810
|
-
|
|
4068
|
+
log12("new state", {
|
|
3811
4069
|
state: SpaceState[this._state]
|
|
3812
4070
|
}, {
|
|
3813
|
-
F:
|
|
3814
|
-
L:
|
|
4071
|
+
F: __dxlog_file15,
|
|
4072
|
+
L: 274,
|
|
3815
4073
|
S: this,
|
|
3816
4074
|
C: (f, a) => f(...a)
|
|
3817
4075
|
});
|
|
@@ -3819,19 +4077,19 @@ var DataSpace = class {
|
|
|
3819
4077
|
await sleep2(1);
|
|
3820
4078
|
this._automergeSpaceState.startProcessingRootDocs();
|
|
3821
4079
|
await cancelWithContext4(this._ctx, this.automergeSpaceState.ensureEpochInitialized());
|
|
3822
|
-
|
|
3823
|
-
F:
|
|
3824
|
-
L:
|
|
4080
|
+
log12("data pipeline ready", void 0, {
|
|
4081
|
+
F: __dxlog_file15,
|
|
4082
|
+
L: 286,
|
|
3825
4083
|
S: this,
|
|
3826
4084
|
C: (f, a) => f(...a)
|
|
3827
4085
|
});
|
|
3828
4086
|
await this._callbacks.beforeReady?.();
|
|
3829
4087
|
this._state = SpaceState.READY;
|
|
3830
|
-
|
|
4088
|
+
log12("new state", {
|
|
3831
4089
|
state: SpaceState[this._state]
|
|
3832
4090
|
}, {
|
|
3833
|
-
F:
|
|
3834
|
-
L:
|
|
4091
|
+
F: __dxlog_file15,
|
|
4092
|
+
L: 290,
|
|
3835
4093
|
S: this,
|
|
3836
4094
|
C: (f, a) => f(...a)
|
|
3837
4095
|
});
|
|
@@ -3845,9 +4103,9 @@ var DataSpace = class {
|
|
|
3845
4103
|
});
|
|
3846
4104
|
this.metrics.controlPipelineReady = /* @__PURE__ */ new Date();
|
|
3847
4105
|
await this._createWritableFeeds();
|
|
3848
|
-
|
|
3849
|
-
F:
|
|
3850
|
-
L:
|
|
4106
|
+
log12("writable feeds created", void 0, {
|
|
4107
|
+
F: __dxlog_file15,
|
|
4108
|
+
L: 306,
|
|
3851
4109
|
S: this,
|
|
3852
4110
|
C: (f, a) => f(...a)
|
|
3853
4111
|
});
|
|
@@ -3905,12 +4163,12 @@ var DataSpace = class {
|
|
|
3905
4163
|
}
|
|
3906
4164
|
}
|
|
3907
4165
|
_onNewAutomergeRoot(rootUrl) {
|
|
3908
|
-
|
|
4166
|
+
log12("loading automerge root doc for space", {
|
|
3909
4167
|
space: this.key,
|
|
3910
4168
|
rootUrl
|
|
3911
4169
|
}, {
|
|
3912
|
-
F:
|
|
3913
|
-
L:
|
|
4170
|
+
F: __dxlog_file15,
|
|
4171
|
+
L: 372,
|
|
3914
4172
|
S: this,
|
|
3915
4173
|
C: (f, a) => f(...a)
|
|
3916
4174
|
});
|
|
@@ -3935,12 +4193,12 @@ var DataSpace = class {
|
|
|
3935
4193
|
if (!this._echoHost.roots.has(handle.documentId)) {
|
|
3936
4194
|
await this._echoHost.openSpaceRoot(handle.url);
|
|
3937
4195
|
} else {
|
|
3938
|
-
|
|
4196
|
+
log12.warn("echo database root already exists", {
|
|
3939
4197
|
space: this.key,
|
|
3940
4198
|
rootUrl
|
|
3941
4199
|
}, {
|
|
3942
|
-
F:
|
|
3943
|
-
L:
|
|
4200
|
+
F: __dxlog_file15,
|
|
4201
|
+
L: 399,
|
|
3944
4202
|
S: this,
|
|
3945
4203
|
C: (f, a) => f(...a)
|
|
3946
4204
|
});
|
|
@@ -3949,13 +4207,13 @@ var DataSpace = class {
|
|
|
3949
4207
|
if (err instanceof ContextDisposedError3) {
|
|
3950
4208
|
return;
|
|
3951
4209
|
}
|
|
3952
|
-
|
|
4210
|
+
log12.warn("error loading automerge root doc", {
|
|
3953
4211
|
space: this.key,
|
|
3954
4212
|
rootUrl,
|
|
3955
4213
|
err
|
|
3956
4214
|
}, {
|
|
3957
|
-
F:
|
|
3958
|
-
L:
|
|
4215
|
+
F: __dxlog_file15,
|
|
4216
|
+
L: 405,
|
|
3959
4217
|
S: this,
|
|
3960
4218
|
C: (f, a) => f(...a)
|
|
3961
4219
|
});
|
|
@@ -4006,11 +4264,11 @@ var DataSpace = class {
|
|
|
4006
4264
|
{
|
|
4007
4265
|
const currentRootUrl = this._automergeSpaceState.rootUrl;
|
|
4008
4266
|
const rootHandle = this._echoHost.automergeRepo.find(currentRootUrl);
|
|
4009
|
-
await cancelWithContext4(this._ctx,
|
|
4267
|
+
await cancelWithContext4(this._ctx, asyncTimeout2(rootHandle.whenReady(), 1e4));
|
|
4010
4268
|
const newRoot = this._echoHost.automergeRepo.create(rootHandle.docSync());
|
|
4011
|
-
|
|
4012
|
-
F:
|
|
4013
|
-
L:
|
|
4269
|
+
invariant13(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
|
|
4270
|
+
F: __dxlog_file15,
|
|
4271
|
+
L: 455,
|
|
4014
4272
|
S: this,
|
|
4015
4273
|
A: [
|
|
4016
4274
|
"typeof newRoot.url === 'string' && newRoot.url.length > 0",
|
|
@@ -4027,21 +4285,21 @@ var DataSpace = class {
|
|
|
4027
4285
|
break;
|
|
4028
4286
|
case CreateEpochRequest.Migration.FRAGMENT_AUTOMERGE_ROOT:
|
|
4029
4287
|
{
|
|
4030
|
-
|
|
4031
|
-
F:
|
|
4032
|
-
L:
|
|
4288
|
+
log12.info("Fragmenting", void 0, {
|
|
4289
|
+
F: __dxlog_file15,
|
|
4290
|
+
L: 467,
|
|
4033
4291
|
S: this,
|
|
4034
4292
|
C: (f, a) => f(...a)
|
|
4035
4293
|
});
|
|
4036
4294
|
const currentRootUrl = this._automergeSpaceState.rootUrl;
|
|
4037
4295
|
const rootHandle = this._echoHost.automergeRepo.find(currentRootUrl);
|
|
4038
|
-
await cancelWithContext4(this._ctx,
|
|
4296
|
+
await cancelWithContext4(this._ctx, asyncTimeout2(rootHandle.whenReady(), 1e4));
|
|
4039
4297
|
const objects = Object.entries(rootHandle.docSync().objects);
|
|
4040
4298
|
const properties = findPropertiesObject(rootHandle.docSync());
|
|
4041
4299
|
const otherObjects = objects.filter(([key]) => key !== properties?.[0]);
|
|
4042
|
-
|
|
4043
|
-
F:
|
|
4044
|
-
L:
|
|
4300
|
+
invariant13(properties, "Properties not found", {
|
|
4301
|
+
F: __dxlog_file15,
|
|
4302
|
+
L: 477,
|
|
4045
4303
|
S: this,
|
|
4046
4304
|
A: [
|
|
4047
4305
|
"properties",
|
|
@@ -4055,16 +4313,16 @@ var DataSpace = class {
|
|
|
4055
4313
|
])
|
|
4056
4314
|
};
|
|
4057
4315
|
const newRoot = this._echoHost.automergeRepo.create(newSpaceDoc);
|
|
4058
|
-
|
|
4059
|
-
F:
|
|
4060
|
-
L:
|
|
4316
|
+
invariant13(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
|
|
4317
|
+
F: __dxlog_file15,
|
|
4318
|
+
L: 482,
|
|
4061
4319
|
S: this,
|
|
4062
4320
|
A: [
|
|
4063
4321
|
"typeof newRoot.url === 'string' && newRoot.url.length > 0",
|
|
4064
4322
|
""
|
|
4065
4323
|
]
|
|
4066
4324
|
});
|
|
4067
|
-
const docLoader = new AutomergeDocumentLoaderImpl(this.key, this._echoHost.automergeRepo);
|
|
4325
|
+
const docLoader = new AutomergeDocumentLoaderImpl(await createIdFromSpaceKey(this.key), this._echoHost.automergeRepo, this.key);
|
|
4068
4326
|
await docLoader.loadSpaceRootDocHandle(this._ctx, {
|
|
4069
4327
|
rootUrl: newRoot.url
|
|
4070
4328
|
});
|
|
@@ -4122,11 +4380,11 @@ var DataSpace = class {
|
|
|
4122
4380
|
await this._metadataStore.setSpaceState(this.key, SpaceState.INACTIVE);
|
|
4123
4381
|
await this._close();
|
|
4124
4382
|
this._state = SpaceState.INACTIVE;
|
|
4125
|
-
|
|
4383
|
+
log12("new state", {
|
|
4126
4384
|
state: SpaceState[this._state]
|
|
4127
4385
|
}, {
|
|
4128
|
-
F:
|
|
4129
|
-
L:
|
|
4386
|
+
F: __dxlog_file15,
|
|
4387
|
+
L: 552,
|
|
4130
4388
|
S: this,
|
|
4131
4389
|
C: (f, a) => f(...a)
|
|
4132
4390
|
});
|
|
@@ -4136,6 +4394,9 @@ var DataSpace = class {
|
|
|
4136
4394
|
_ts_decorate4([
|
|
4137
4395
|
trace6.info()
|
|
4138
4396
|
], DataSpace.prototype, "_inner", void 0);
|
|
4397
|
+
_ts_decorate4([
|
|
4398
|
+
trace6.info()
|
|
4399
|
+
], DataSpace.prototype, "id", null);
|
|
4139
4400
|
_ts_decorate4([
|
|
4140
4401
|
trace6.info()
|
|
4141
4402
|
], DataSpace.prototype, "key", null);
|
|
@@ -4196,12 +4457,12 @@ import { Event as Event7, synchronized as synchronized2, trackLeaks as trackLeak
|
|
|
4196
4457
|
import { cancelWithContext as cancelWithContext5, Context as Context9 } from "@dxos/context";
|
|
4197
4458
|
import { getCredentialAssertion as getCredentialAssertion2 } from "@dxos/credentials";
|
|
4198
4459
|
import { AuthStatus } from "@dxos/echo-pipeline";
|
|
4199
|
-
import { invariant as
|
|
4460
|
+
import { invariant as invariant14 } from "@dxos/invariant";
|
|
4200
4461
|
import { PublicKey as PublicKey11 } from "@dxos/keys";
|
|
4201
|
-
import { log as
|
|
4462
|
+
import { log as log13 } from "@dxos/log";
|
|
4202
4463
|
import { trace as Trace2 } from "@dxos/protocols";
|
|
4203
4464
|
import { Invitation as Invitation7, SpaceState as SpaceState2 } from "@dxos/protocols/proto/dxos/client/services";
|
|
4204
|
-
import { SpaceMember as
|
|
4465
|
+
import { SpaceMember as SpaceMember6 } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
4205
4466
|
import { Gossip as Gossip2, Presence as Presence2 } from "@dxos/teleport-extension-gossip";
|
|
4206
4467
|
import { trace as trace7 } from "@dxos/tracing";
|
|
4207
4468
|
import { ComplexMap as ComplexMap3, deferFunction as deferFunction2, forEachAsync } from "@dxos/util";
|
|
@@ -4209,7 +4470,7 @@ import { ComplexMap as ComplexMap3, deferFunction as deferFunction2, forEachAsyn
|
|
|
4209
4470
|
// packages/sdk/client-services/src/packlets/spaces/genesis.ts
|
|
4210
4471
|
import { createCredential } from "@dxos/credentials";
|
|
4211
4472
|
import { failUndefined } from "@dxos/debug";
|
|
4212
|
-
import { AdmittedFeed as AdmittedFeed4, SpaceMember as
|
|
4473
|
+
import { AdmittedFeed as AdmittedFeed4, SpaceMember as SpaceMember5 } from "@dxos/protocols/proto/dxos/halo/credentials";
|
|
4213
4474
|
import { Timeframe as Timeframe3 } from "@dxos/timeframe";
|
|
4214
4475
|
var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
|
|
4215
4476
|
const credentials = [
|
|
@@ -4229,7 +4490,7 @@ var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
|
|
|
4229
4490
|
assertion: {
|
|
4230
4491
|
"@type": "dxos.halo.credentials.SpaceMember",
|
|
4231
4492
|
spaceKey: space.key,
|
|
4232
|
-
role:
|
|
4493
|
+
role: SpaceMember5.Role.OWNER,
|
|
4233
4494
|
profile: signingContext.getProfile(),
|
|
4234
4495
|
genesisFeedKey: space.controlFeedKey ?? failUndefined()
|
|
4235
4496
|
}
|
|
@@ -4287,7 +4548,7 @@ function _ts_decorate5(decorators, target, key, desc) {
|
|
|
4287
4548
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
4288
4549
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
4289
4550
|
}
|
|
4290
|
-
var
|
|
4551
|
+
var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
|
|
4291
4552
|
var PRESENCE_ANNOUNCE_INTERVAL = 1e4;
|
|
4292
4553
|
var PRESENCE_OFFLINE_TIMEOUT = 2e4;
|
|
4293
4554
|
var DataSpaceManager = class {
|
|
@@ -4335,45 +4596,45 @@ var DataSpaceManager = class {
|
|
|
4335
4596
|
return this._spaces;
|
|
4336
4597
|
}
|
|
4337
4598
|
async open() {
|
|
4338
|
-
|
|
4339
|
-
F:
|
|
4599
|
+
log13("open", void 0, {
|
|
4600
|
+
F: __dxlog_file16,
|
|
4340
4601
|
L: 144,
|
|
4341
4602
|
S: this,
|
|
4342
4603
|
C: (f, a) => f(...a)
|
|
4343
4604
|
});
|
|
4344
|
-
|
|
4605
|
+
log13.trace("dxos.echo.data-space-manager.open", Trace2.begin({
|
|
4345
4606
|
id: this._instanceId
|
|
4346
4607
|
}), {
|
|
4347
|
-
F:
|
|
4608
|
+
F: __dxlog_file16,
|
|
4348
4609
|
L: 145,
|
|
4349
4610
|
S: this,
|
|
4350
4611
|
C: (f, a) => f(...a)
|
|
4351
4612
|
});
|
|
4352
|
-
|
|
4613
|
+
log13("metadata loaded", {
|
|
4353
4614
|
spaces: this._metadataStore.spaces.length
|
|
4354
4615
|
}, {
|
|
4355
|
-
F:
|
|
4616
|
+
F: __dxlog_file16,
|
|
4356
4617
|
L: 146,
|
|
4357
4618
|
S: this,
|
|
4358
4619
|
C: (f, a) => f(...a)
|
|
4359
4620
|
});
|
|
4360
4621
|
await forEachAsync(this._metadataStore.spaces, async (spaceMetadata) => {
|
|
4361
4622
|
try {
|
|
4362
|
-
|
|
4623
|
+
log13("load space", {
|
|
4363
4624
|
spaceMetadata
|
|
4364
4625
|
}, {
|
|
4365
|
-
F:
|
|
4626
|
+
F: __dxlog_file16,
|
|
4366
4627
|
L: 150,
|
|
4367
4628
|
S: this,
|
|
4368
4629
|
C: (f, a) => f(...a)
|
|
4369
4630
|
});
|
|
4370
4631
|
await this._constructSpace(spaceMetadata);
|
|
4371
4632
|
} catch (err) {
|
|
4372
|
-
|
|
4633
|
+
log13.error("Error loading space", {
|
|
4373
4634
|
spaceMetadata,
|
|
4374
4635
|
err
|
|
4375
4636
|
}, {
|
|
4376
|
-
F:
|
|
4637
|
+
F: __dxlog_file16,
|
|
4377
4638
|
L: 153,
|
|
4378
4639
|
S: this,
|
|
4379
4640
|
C: (f, a) => f(...a)
|
|
@@ -4387,18 +4648,18 @@ var DataSpaceManager = class {
|
|
|
4387
4648
|
space.initializeDataPipelineAsync();
|
|
4388
4649
|
}
|
|
4389
4650
|
}
|
|
4390
|
-
|
|
4651
|
+
log13.trace("dxos.echo.data-space-manager.open", Trace2.end({
|
|
4391
4652
|
id: this._instanceId
|
|
4392
4653
|
}), {
|
|
4393
|
-
F:
|
|
4654
|
+
F: __dxlog_file16,
|
|
4394
4655
|
L: 166,
|
|
4395
4656
|
S: this,
|
|
4396
4657
|
C: (f, a) => f(...a)
|
|
4397
4658
|
});
|
|
4398
4659
|
}
|
|
4399
4660
|
async close() {
|
|
4400
|
-
|
|
4401
|
-
F:
|
|
4661
|
+
log13("close", void 0, {
|
|
4662
|
+
F: __dxlog_file16,
|
|
4402
4663
|
L: 171,
|
|
4403
4664
|
S: this,
|
|
4404
4665
|
C: (f, a) => f(...a)
|
|
@@ -4413,8 +4674,8 @@ var DataSpaceManager = class {
|
|
|
4413
4674
|
* Creates a new space writing the genesis credentials to the control feed.
|
|
4414
4675
|
*/
|
|
4415
4676
|
async createSpace() {
|
|
4416
|
-
|
|
4417
|
-
F:
|
|
4677
|
+
invariant14(this._isOpen, "Not open.", {
|
|
4678
|
+
F: __dxlog_file16,
|
|
4418
4679
|
L: 184,
|
|
4419
4680
|
S: this,
|
|
4420
4681
|
A: [
|
|
@@ -4432,10 +4693,10 @@ var DataSpaceManager = class {
|
|
|
4432
4693
|
dataFeedKey,
|
|
4433
4694
|
state: SpaceState2.ACTIVE
|
|
4434
4695
|
};
|
|
4435
|
-
|
|
4696
|
+
log13("creating space...", {
|
|
4436
4697
|
spaceKey
|
|
4437
4698
|
}, {
|
|
4438
|
-
F:
|
|
4699
|
+
F: __dxlog_file16,
|
|
4439
4700
|
L: 196,
|
|
4440
4701
|
S: this,
|
|
4441
4702
|
C: (f, a) => f(...a)
|
|
@@ -4445,8 +4706,8 @@ var DataSpaceManager = class {
|
|
|
4445
4706
|
const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner, root.url);
|
|
4446
4707
|
await this._metadataStore.addSpace(metadata);
|
|
4447
4708
|
const memberCredential = credentials[1];
|
|
4448
|
-
|
|
4449
|
-
F:
|
|
4709
|
+
invariant14(getCredentialAssertion2(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
|
|
4710
|
+
F: __dxlog_file16,
|
|
4450
4711
|
L: 205,
|
|
4451
4712
|
S: this,
|
|
4452
4713
|
A: [
|
|
@@ -4461,16 +4722,16 @@ var DataSpaceManager = class {
|
|
|
4461
4722
|
}
|
|
4462
4723
|
// TODO(burdon): Rename join space.
|
|
4463
4724
|
async acceptSpace(opts) {
|
|
4464
|
-
|
|
4725
|
+
log13("accept space", {
|
|
4465
4726
|
opts
|
|
4466
4727
|
}, {
|
|
4467
|
-
F:
|
|
4728
|
+
F: __dxlog_file16,
|
|
4468
4729
|
L: 217,
|
|
4469
4730
|
S: this,
|
|
4470
4731
|
C: (f, a) => f(...a)
|
|
4471
4732
|
});
|
|
4472
|
-
|
|
4473
|
-
F:
|
|
4733
|
+
invariant14(this._isOpen, "Not open.", {
|
|
4734
|
+
F: __dxlog_file16,
|
|
4474
4735
|
L: 218,
|
|
4475
4736
|
S: this,
|
|
4476
4737
|
A: [
|
|
@@ -4478,8 +4739,8 @@ var DataSpaceManager = class {
|
|
|
4478
4739
|
"'Not open.'"
|
|
4479
4740
|
]
|
|
4480
4741
|
});
|
|
4481
|
-
|
|
4482
|
-
F:
|
|
4742
|
+
invariant14(!this._spaces.has(opts.spaceKey), "Space already exists.", {
|
|
4743
|
+
F: __dxlog_file16,
|
|
4483
4744
|
L: 219,
|
|
4484
4745
|
S: this,
|
|
4485
4746
|
A: [
|
|
@@ -4511,10 +4772,10 @@ var DataSpaceManager = class {
|
|
|
4511
4772
|
}));
|
|
4512
4773
|
}
|
|
4513
4774
|
async _constructSpace(metadata) {
|
|
4514
|
-
|
|
4775
|
+
log13("construct space", {
|
|
4515
4776
|
metadata
|
|
4516
4777
|
}, {
|
|
4517
|
-
F:
|
|
4778
|
+
F: __dxlog_file16,
|
|
4518
4779
|
L: 252,
|
|
4519
4780
|
S: this,
|
|
4520
4781
|
C: (f, a) => f(...a)
|
|
@@ -4551,8 +4812,8 @@ var DataSpaceManager = class {
|
|
|
4551
4812
|
session.addExtension("dxos.mesh.teleport.automerge", this._echoHost.createReplicationExtension());
|
|
4552
4813
|
},
|
|
4553
4814
|
onAuthFailure: () => {
|
|
4554
|
-
|
|
4555
|
-
F:
|
|
4815
|
+
log13.warn("auth failure", void 0, {
|
|
4816
|
+
F: __dxlog_file16,
|
|
4556
4817
|
L: 289,
|
|
4557
4818
|
S: this,
|
|
4558
4819
|
C: (f, a) => f(...a)
|
|
@@ -4582,21 +4843,21 @@ var DataSpaceManager = class {
|
|
|
4582
4843
|
signingContext: this._signingContext,
|
|
4583
4844
|
callbacks: {
|
|
4584
4845
|
beforeReady: async () => {
|
|
4585
|
-
|
|
4846
|
+
log13("before space ready", {
|
|
4586
4847
|
space: space.key
|
|
4587
4848
|
}, {
|
|
4588
|
-
F:
|
|
4849
|
+
F: __dxlog_file16,
|
|
4589
4850
|
L: 316,
|
|
4590
4851
|
S: this,
|
|
4591
4852
|
C: (f, a) => f(...a)
|
|
4592
4853
|
});
|
|
4593
4854
|
},
|
|
4594
4855
|
afterReady: async () => {
|
|
4595
|
-
|
|
4856
|
+
log13("after space ready", {
|
|
4596
4857
|
space: space.key,
|
|
4597
4858
|
open: this._isOpen
|
|
4598
4859
|
}, {
|
|
4599
|
-
F:
|
|
4860
|
+
F: __dxlog_file16,
|
|
4600
4861
|
L: 319,
|
|
4601
4862
|
S: this,
|
|
4602
4863
|
C: (f, a) => f(...a)
|
|
@@ -4612,10 +4873,10 @@ var DataSpaceManager = class {
|
|
|
4612
4873
|
}
|
|
4613
4874
|
},
|
|
4614
4875
|
beforeClose: async () => {
|
|
4615
|
-
|
|
4876
|
+
log13("before space close", {
|
|
4616
4877
|
space: space.key
|
|
4617
4878
|
}, {
|
|
4618
|
-
F:
|
|
4879
|
+
F: __dxlog_file16,
|
|
4619
4880
|
L: 327,
|
|
4620
4881
|
S: this,
|
|
4621
4882
|
C: (f, a) => f(...a)
|
|
@@ -4647,19 +4908,19 @@ var DataSpaceManager = class {
|
|
|
4647
4908
|
const peers = presence.getPeersByIdentityKey(member.key);
|
|
4648
4909
|
const sessions = peers.map((p) => p.peerId && spaceProtocol.sessions.get(p.peerId));
|
|
4649
4910
|
const sessionsToClose = sessions.filter((s) => {
|
|
4650
|
-
return (s && member.role ===
|
|
4911
|
+
return (s && member.role === SpaceMember6.Role.REMOVED !== (s.authStatus === AuthStatus.FAILURE)) ?? false;
|
|
4651
4912
|
});
|
|
4652
4913
|
sessionsToClose.forEach((session) => {
|
|
4653
|
-
void session.close().catch(
|
|
4914
|
+
void session.close().catch(log13.error);
|
|
4654
4915
|
});
|
|
4655
4916
|
closedSessions += sessionsToClose.length;
|
|
4656
4917
|
}
|
|
4657
|
-
|
|
4918
|
+
log13("processed member role changes", {
|
|
4658
4919
|
roleChangeCount: memberInfo.length,
|
|
4659
4920
|
peersOnline: presence.getPeersOnline().length,
|
|
4660
4921
|
closedSessions
|
|
4661
4922
|
}, {
|
|
4662
|
-
F:
|
|
4923
|
+
F: __dxlog_file16,
|
|
4663
4924
|
L: 367,
|
|
4664
4925
|
S: this,
|
|
4665
4926
|
C: (f, a) => f(...a)
|
|
@@ -4668,18 +4929,18 @@ var DataSpaceManager = class {
|
|
|
4668
4929
|
}
|
|
4669
4930
|
_handleNewPeerConnected(space, peerState) {
|
|
4670
4931
|
const role = space.spaceState.getMemberRole(peerState.identityKey);
|
|
4671
|
-
if (role ===
|
|
4932
|
+
if (role === SpaceMember6.Role.REMOVED) {
|
|
4672
4933
|
const session = peerState.peerId && space.protocol.sessions.get(peerState.peerId);
|
|
4673
4934
|
if (session != null) {
|
|
4674
|
-
|
|
4935
|
+
log13("closing a session with a removed peer", {
|
|
4675
4936
|
peerId: peerState.peerId
|
|
4676
4937
|
}, {
|
|
4677
|
-
F:
|
|
4938
|
+
F: __dxlog_file16,
|
|
4678
4939
|
L: 381,
|
|
4679
4940
|
S: this,
|
|
4680
4941
|
C: (f, a) => f(...a)
|
|
4681
4942
|
});
|
|
4682
|
-
void session.close().catch(
|
|
4943
|
+
void session.close().catch(log13.error);
|
|
4683
4944
|
}
|
|
4684
4945
|
}
|
|
4685
4946
|
}
|
|
@@ -4741,12 +5002,12 @@ import { Stream as Stream10 } from "@dxos/codec-protobuf";
|
|
|
4741
5002
|
import { createAdmissionCredentials as createAdmissionCredentials2, getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
|
|
4742
5003
|
import { raise as raise2 } from "@dxos/debug";
|
|
4743
5004
|
import { writeMessages as writeMessages3 } from "@dxos/feed-store";
|
|
4744
|
-
import { invariant as
|
|
4745
|
-
import { log as
|
|
5005
|
+
import { invariant as invariant15 } from "@dxos/invariant";
|
|
5006
|
+
import { log as log14 } from "@dxos/log";
|
|
4746
5007
|
import { ApiError, SpaceNotFoundError as SpaceNotFoundError2, encodeError, IdentityNotInitializedError, AuthorizationError as AuthorizationError2 } from "@dxos/protocols";
|
|
4747
|
-
import { SpaceMember as
|
|
5008
|
+
import { SpaceMember as SpaceMember7, SpaceState as SpaceState3 } from "@dxos/protocols/proto/dxos/client/services";
|
|
4748
5009
|
import { trace as trace8 } from "@dxos/tracing";
|
|
4749
|
-
var
|
|
5010
|
+
var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
|
|
4750
5011
|
var SpacesServiceImpl = class {
|
|
4751
5012
|
constructor(_identityManager, _spaceManager, _getDataSpaceManager) {
|
|
4752
5013
|
this._identityManager = _identityManager;
|
|
@@ -4789,8 +5050,8 @@ var SpacesServiceImpl = class {
|
|
|
4789
5050
|
});
|
|
4790
5051
|
}
|
|
4791
5052
|
const credentials = await createAdmissionCredentials2(identity.getIdentityCredentialSigner(), request.memberKey, space.key, space.genesisFeedKey, request.newRole, space.spaceState.membershipChainHeads);
|
|
4792
|
-
|
|
4793
|
-
F:
|
|
5053
|
+
invariant15(credentials[0].credential, void 0, {
|
|
5054
|
+
F: __dxlog_file17,
|
|
4794
5055
|
L: 97,
|
|
4795
5056
|
S: this,
|
|
4796
5057
|
A: [
|
|
@@ -4799,8 +5060,8 @@ var SpacesServiceImpl = class {
|
|
|
4799
5060
|
]
|
|
4800
5061
|
});
|
|
4801
5062
|
const spaceMemberCredential = credentials[0].credential.credential;
|
|
4802
|
-
|
|
4803
|
-
F:
|
|
5063
|
+
invariant15(getCredentialAssertion3(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
|
|
5064
|
+
F: __dxlog_file17,
|
|
4804
5065
|
L: 99,
|
|
4805
5066
|
S: this,
|
|
4806
5067
|
A: [
|
|
@@ -4815,10 +5076,10 @@ var SpacesServiceImpl = class {
|
|
|
4815
5076
|
const scheduler = new UpdateScheduler(ctx, async () => {
|
|
4816
5077
|
const dataSpaceManager = await this._getDataSpaceManager();
|
|
4817
5078
|
const spaces = Array.from(dataSpaceManager.spaces.values()).map((space) => this._serializeSpace(space));
|
|
4818
|
-
|
|
5079
|
+
log14("update", {
|
|
4819
5080
|
spaces
|
|
4820
5081
|
}, {
|
|
4821
|
-
F:
|
|
5082
|
+
F: __dxlog_file17,
|
|
4822
5083
|
L: 110,
|
|
4823
5084
|
S: this,
|
|
4824
5085
|
C: (f, a) => f(...a)
|
|
@@ -4901,8 +5162,8 @@ var SpacesServiceImpl = class {
|
|
|
4901
5162
|
}
|
|
4902
5163
|
});
|
|
4903
5164
|
} else {
|
|
4904
|
-
|
|
4905
|
-
F:
|
|
5165
|
+
invariant15(!credential.id, "Id on unsigned credentials is not allowed", {
|
|
5166
|
+
F: __dxlog_file17,
|
|
4906
5167
|
L: 198,
|
|
4907
5168
|
S: this,
|
|
4908
5169
|
A: [
|
|
@@ -4910,8 +5171,8 @@ var SpacesServiceImpl = class {
|
|
|
4910
5171
|
"'Id on unsigned credentials is not allowed'"
|
|
4911
5172
|
]
|
|
4912
5173
|
});
|
|
4913
|
-
|
|
4914
|
-
F:
|
|
5174
|
+
invariant15(this._identityManager.identity, "Identity is not available", {
|
|
5175
|
+
F: __dxlog_file17,
|
|
4915
5176
|
L: 199,
|
|
4916
5177
|
S: this,
|
|
4917
5178
|
A: [
|
|
@@ -4920,8 +5181,8 @@ var SpacesServiceImpl = class {
|
|
|
4920
5181
|
]
|
|
4921
5182
|
});
|
|
4922
5183
|
const signer = this._identityManager.identity.getIdentityCredentialSigner();
|
|
4923
|
-
|
|
4924
|
-
F:
|
|
5184
|
+
invariant15(credential.issuer.equals(signer.getIssuer()), void 0, {
|
|
5185
|
+
F: __dxlog_file17,
|
|
4925
5186
|
L: 201,
|
|
4926
5187
|
S: this,
|
|
4927
5188
|
A: [
|
|
@@ -4950,6 +5211,7 @@ var SpacesServiceImpl = class {
|
|
|
4950
5211
|
}
|
|
4951
5212
|
_serializeSpace(space) {
|
|
4952
5213
|
return {
|
|
5214
|
+
id: space.id,
|
|
4953
5215
|
spaceKey: space.key,
|
|
4954
5216
|
state: space.state,
|
|
4955
5217
|
error: space.error ? encodeError(space.error) : void 0,
|
|
@@ -4978,7 +5240,7 @@ var SpacesServiceImpl = class {
|
|
|
4978
5240
|
profile: member.profile ?? {}
|
|
4979
5241
|
},
|
|
4980
5242
|
role: member.role,
|
|
4981
|
-
presence: peers.length > 0 ?
|
|
5243
|
+
presence: peers.length > 0 ? SpaceMember7.PresenceState.ONLINE : SpaceMember7.PresenceState.OFFLINE,
|
|
4982
5244
|
peerStates: peers
|
|
4983
5245
|
};
|
|
4984
5246
|
}),
|
|
@@ -5008,18 +5270,18 @@ var SpacesServiceImpl = class {
|
|
|
5008
5270
|
var getChannelId = (channel) => `user-channel/${channel}`;
|
|
5009
5271
|
|
|
5010
5272
|
// packages/sdk/client-services/src/packlets/services/service-context.ts
|
|
5011
|
-
import { Trigger as
|
|
5273
|
+
import { Trigger as Trigger7 } from "@dxos/async";
|
|
5012
5274
|
import { Context as Context10, Resource } from "@dxos/context";
|
|
5013
5275
|
import { getCredentialAssertion as getCredentialAssertion4 } from "@dxos/credentials";
|
|
5014
5276
|
import { failUndefined as failUndefined2 } from "@dxos/debug";
|
|
5015
5277
|
import { EchoHost } from "@dxos/echo-db";
|
|
5016
5278
|
import { MetadataStore, SnapshotStore, SpaceManager, valueEncoding } from "@dxos/echo-pipeline";
|
|
5017
5279
|
import { FeedFactory, FeedStore } from "@dxos/feed-store";
|
|
5018
|
-
import { invariant as
|
|
5280
|
+
import { invariant as invariant16 } from "@dxos/invariant";
|
|
5019
5281
|
import { Keyring } from "@dxos/keyring";
|
|
5020
5282
|
import { PublicKey as PublicKey12 } from "@dxos/keys";
|
|
5021
|
-
import { log as
|
|
5022
|
-
import { InvalidStorageVersionError, STORAGE_VERSION, trace as trace9 } from "@dxos/protocols";
|
|
5283
|
+
import { log as log15 } from "@dxos/log";
|
|
5284
|
+
import { InvalidStorageVersionError, STORAGE_VERSION as STORAGE_VERSION2, trace as trace9 } from "@dxos/protocols";
|
|
5023
5285
|
import { Invitation as Invitation8 } from "@dxos/protocols/proto/dxos/client/services";
|
|
5024
5286
|
import { BlobStore } from "@dxos/teleport-extension-object-sync";
|
|
5025
5287
|
import { trace as Trace3 } from "@dxos/tracing";
|
|
@@ -5034,7 +5296,7 @@ function _ts_decorate6(decorators, target, key, desc) {
|
|
|
5034
5296
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5035
5297
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
5036
5298
|
}
|
|
5037
|
-
var
|
|
5299
|
+
var __dxlog_file18 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
|
|
5038
5300
|
var ServiceContext = class extends Resource {
|
|
5039
5301
|
constructor(storage, level, networkManager, signalManager, _runtimeParams) {
|
|
5040
5302
|
super();
|
|
@@ -5043,7 +5305,7 @@ var ServiceContext = class extends Resource {
|
|
|
5043
5305
|
this.networkManager = networkManager;
|
|
5044
5306
|
this.signalManager = signalManager;
|
|
5045
5307
|
this._runtimeParams = _runtimeParams;
|
|
5046
|
-
this.initialized = new
|
|
5308
|
+
this.initialized = new Trigger7();
|
|
5047
5309
|
this._handlerFactories = /* @__PURE__ */ new Map();
|
|
5048
5310
|
this._instanceId = PublicKey12.random().toHex();
|
|
5049
5311
|
this.metadataStore = new MetadataStore(storage.createDirectory("metadata"));
|
|
@@ -5078,16 +5340,16 @@ var ServiceContext = class extends Resource {
|
|
|
5078
5340
|
}
|
|
5079
5341
|
async _open(ctx) {
|
|
5080
5342
|
await this._checkStorageVersion();
|
|
5081
|
-
|
|
5082
|
-
F:
|
|
5343
|
+
log15("opening...", void 0, {
|
|
5344
|
+
F: __dxlog_file18,
|
|
5083
5345
|
L: 152,
|
|
5084
5346
|
S: this,
|
|
5085
5347
|
C: (f, a) => f(...a)
|
|
5086
5348
|
});
|
|
5087
|
-
|
|
5349
|
+
log15.trace("dxos.sdk.service-context.open", trace9.begin({
|
|
5088
5350
|
id: this._instanceId
|
|
5089
5351
|
}), {
|
|
5090
|
-
F:
|
|
5352
|
+
F: __dxlog_file18,
|
|
5091
5353
|
L: 153,
|
|
5092
5354
|
S: this,
|
|
5093
5355
|
C: (f, a) => f(...a)
|
|
@@ -5102,32 +5364,32 @@ var ServiceContext = class extends Resource {
|
|
|
5102
5364
|
await this._initialize(ctx);
|
|
5103
5365
|
}
|
|
5104
5366
|
const loadedInvitations = await this.invitationsManager.loadPersistentInvitations();
|
|
5105
|
-
|
|
5367
|
+
log15("loaded persistent invitations", {
|
|
5106
5368
|
count: loadedInvitations.invitations?.length
|
|
5107
5369
|
}, {
|
|
5108
|
-
F:
|
|
5370
|
+
F: __dxlog_file18,
|
|
5109
5371
|
L: 166,
|
|
5110
5372
|
S: this,
|
|
5111
5373
|
C: (f, a) => f(...a)
|
|
5112
5374
|
});
|
|
5113
|
-
|
|
5375
|
+
log15.trace("dxos.sdk.service-context.open", trace9.end({
|
|
5114
5376
|
id: this._instanceId
|
|
5115
5377
|
}), {
|
|
5116
|
-
F:
|
|
5378
|
+
F: __dxlog_file18,
|
|
5117
5379
|
L: 168,
|
|
5118
5380
|
S: this,
|
|
5119
5381
|
C: (f, a) => f(...a)
|
|
5120
5382
|
});
|
|
5121
|
-
|
|
5122
|
-
F:
|
|
5383
|
+
log15("opened", void 0, {
|
|
5384
|
+
F: __dxlog_file18,
|
|
5123
5385
|
L: 169,
|
|
5124
5386
|
S: this,
|
|
5125
5387
|
C: (f, a) => f(...a)
|
|
5126
5388
|
});
|
|
5127
5389
|
}
|
|
5128
5390
|
async _close(ctx) {
|
|
5129
|
-
|
|
5130
|
-
F:
|
|
5391
|
+
log15("closing...", void 0, {
|
|
5392
|
+
F: __dxlog_file18,
|
|
5131
5393
|
L: 173,
|
|
5132
5394
|
S: this,
|
|
5133
5395
|
C: (f, a) => f(...a)
|
|
@@ -5143,8 +5405,8 @@ var ServiceContext = class extends Resource {
|
|
|
5143
5405
|
await this.echoHost.close(ctx);
|
|
5144
5406
|
await this.networkManager.close();
|
|
5145
5407
|
await this.signalManager.close();
|
|
5146
|
-
|
|
5147
|
-
F:
|
|
5408
|
+
log15("closed", void 0, {
|
|
5409
|
+
F: __dxlog_file18,
|
|
5148
5410
|
L: 185,
|
|
5149
5411
|
S: this,
|
|
5150
5412
|
C: (f, a) => f(...a)
|
|
@@ -5157,8 +5419,8 @@ var ServiceContext = class extends Resource {
|
|
|
5157
5419
|
}
|
|
5158
5420
|
getInvitationHandler(invitation) {
|
|
5159
5421
|
const factory = this._handlerFactories.get(invitation.kind);
|
|
5160
|
-
|
|
5161
|
-
F:
|
|
5422
|
+
invariant16(factory, `Unknown invitation kind: ${invitation.kind}`, {
|
|
5423
|
+
F: __dxlog_file18,
|
|
5162
5424
|
L: 196,
|
|
5163
5425
|
S: this,
|
|
5164
5426
|
A: [
|
|
@@ -5183,14 +5445,14 @@ var ServiceContext = class extends Resource {
|
|
|
5183
5445
|
}
|
|
5184
5446
|
async _checkStorageVersion() {
|
|
5185
5447
|
await this.metadataStore.load();
|
|
5186
|
-
if (this.metadataStore.version !==
|
|
5187
|
-
throw new InvalidStorageVersionError(
|
|
5448
|
+
if (this.metadataStore.version !== STORAGE_VERSION2) {
|
|
5449
|
+
throw new InvalidStorageVersionError(STORAGE_VERSION2, this.metadataStore.version);
|
|
5188
5450
|
}
|
|
5189
5451
|
}
|
|
5190
5452
|
// Called when identity is created.
|
|
5191
5453
|
async _initialize(ctx) {
|
|
5192
|
-
|
|
5193
|
-
F:
|
|
5454
|
+
log15("initializing spaces...", void 0, {
|
|
5455
|
+
F: __dxlog_file18,
|
|
5194
5456
|
L: 227,
|
|
5195
5457
|
S: this,
|
|
5196
5458
|
C: (f, a) => f(...a)
|
|
@@ -5212,8 +5474,8 @@ var ServiceContext = class extends Resource {
|
|
|
5212
5474
|
this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.keyring, signingContext, this.feedStore, this.echoHost, this.invitationsManager, this._runtimeParams);
|
|
5213
5475
|
await this.dataSpaceManager.open();
|
|
5214
5476
|
this._handlerFactories.set(Invitation8.Kind.SPACE, (invitation) => {
|
|
5215
|
-
|
|
5216
|
-
F:
|
|
5477
|
+
invariant16(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
|
|
5478
|
+
F: __dxlog_file18,
|
|
5217
5479
|
L: 252,
|
|
5218
5480
|
S: this,
|
|
5219
5481
|
A: [
|
|
@@ -5234,10 +5496,10 @@ var ServiceContext = class extends Resource {
|
|
|
5234
5496
|
return;
|
|
5235
5497
|
}
|
|
5236
5498
|
if (!this.dataSpaceManager) {
|
|
5237
|
-
|
|
5499
|
+
log15("dataSpaceManager not initialized yet, ignoring space admission", {
|
|
5238
5500
|
details: assertion
|
|
5239
5501
|
}, {
|
|
5240
|
-
F:
|
|
5502
|
+
F: __dxlog_file18,
|
|
5241
5503
|
L: 268,
|
|
5242
5504
|
S: this,
|
|
5243
5505
|
C: (f, a) => f(...a)
|
|
@@ -5245,10 +5507,10 @@ var ServiceContext = class extends Resource {
|
|
|
5245
5507
|
return;
|
|
5246
5508
|
}
|
|
5247
5509
|
if (this.dataSpaceManager.spaces.has(assertion.spaceKey)) {
|
|
5248
|
-
|
|
5510
|
+
log15("space already exists, ignoring space admission", {
|
|
5249
5511
|
details: assertion
|
|
5250
5512
|
}, {
|
|
5251
|
-
F:
|
|
5513
|
+
F: __dxlog_file18,
|
|
5252
5514
|
L: 272,
|
|
5253
5515
|
S: this,
|
|
5254
5516
|
C: (f, a) => f(...a)
|
|
@@ -5256,10 +5518,10 @@ var ServiceContext = class extends Resource {
|
|
|
5256
5518
|
return;
|
|
5257
5519
|
}
|
|
5258
5520
|
try {
|
|
5259
|
-
|
|
5521
|
+
log15("accepting space recorded in halo", {
|
|
5260
5522
|
details: assertion
|
|
5261
5523
|
}, {
|
|
5262
|
-
F:
|
|
5524
|
+
F: __dxlog_file18,
|
|
5263
5525
|
L: 277,
|
|
5264
5526
|
S: this,
|
|
5265
5527
|
C: (f, a) => f(...a)
|
|
@@ -5269,8 +5531,8 @@ var ServiceContext = class extends Resource {
|
|
|
5269
5531
|
genesisFeedKey: assertion.genesisFeedKey
|
|
5270
5532
|
});
|
|
5271
5533
|
} catch (err) {
|
|
5272
|
-
|
|
5273
|
-
F:
|
|
5534
|
+
log15.catch(err, void 0, {
|
|
5535
|
+
F: __dxlog_file18,
|
|
5274
5536
|
L: 283,
|
|
5275
5537
|
S: this,
|
|
5276
5538
|
C: (f, a) => f(...a)
|
|
@@ -5316,281 +5578,218 @@ var ServiceRegistry = class {
|
|
|
5316
5578
|
}
|
|
5317
5579
|
};
|
|
5318
5580
|
|
|
5319
|
-
// packages/sdk/client-services/src/packlets/
|
|
5320
|
-
import { asyncTimeout as
|
|
5321
|
-
import {
|
|
5322
|
-
import {
|
|
5323
|
-
|
|
5324
|
-
|
|
5325
|
-
|
|
5326
|
-
|
|
5327
|
-
|
|
5328
|
-
|
|
5329
|
-
|
|
5330
|
-
|
|
5331
|
-
|
|
5332
|
-
|
|
5333
|
-
var
|
|
5334
|
-
|
|
5335
|
-
|
|
5336
|
-
|
|
5337
|
-
|
|
5338
|
-
|
|
5339
|
-
|
|
5340
|
-
|
|
5341
|
-
|
|
5342
|
-
|
|
5343
|
-
|
|
5344
|
-
|
|
5345
|
-
|
|
5346
|
-
};
|
|
5347
|
-
}
|
|
5348
|
-
} else {
|
|
5349
|
-
const { platform: platform2, version, arch } = process;
|
|
5350
|
-
return {
|
|
5351
|
-
type: Platform.PLATFORM_TYPE.NODE,
|
|
5352
|
-
platform: platform2,
|
|
5353
|
-
arch,
|
|
5354
|
-
runtime: version,
|
|
5355
|
-
uptime: Math.floor(process.uptime()),
|
|
5356
|
-
memory: process.memoryUsage()
|
|
5357
|
-
};
|
|
5581
|
+
// packages/sdk/client-services/src/packlets/locks/browser.ts
|
|
5582
|
+
import { asyncTimeout as asyncTimeout3, Trigger as Trigger8 } from "@dxos/async";
|
|
5583
|
+
import { RESOURCE_LOCK_TIMEOUT } from "@dxos/client-protocol";
|
|
5584
|
+
import { log as log16, logInfo } from "@dxos/log";
|
|
5585
|
+
function _ts_decorate7(decorators, target, key, desc) {
|
|
5586
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
5587
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
5588
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
5589
|
+
else
|
|
5590
|
+
for (var i = decorators.length - 1; i >= 0; i--)
|
|
5591
|
+
if (d = decorators[i])
|
|
5592
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5593
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
5594
|
+
}
|
|
5595
|
+
var __dxlog_file19 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
|
|
5596
|
+
var Message;
|
|
5597
|
+
(function(Message2) {
|
|
5598
|
+
Message2["ACQUIRING"] = "acquiring";
|
|
5599
|
+
})(Message || (Message = {}));
|
|
5600
|
+
var Lock = class {
|
|
5601
|
+
constructor({ lockKey, onAcquire, onRelease }) {
|
|
5602
|
+
this._broadcastChannel = new BroadcastChannel("vault-resource-lock");
|
|
5603
|
+
this._releaseTrigger = new Trigger8();
|
|
5604
|
+
this._lockKey = lockKey;
|
|
5605
|
+
this._onAcquire = onAcquire;
|
|
5606
|
+
this._onRelease = onRelease;
|
|
5607
|
+
this._broadcastChannel.onmessage = this._onMessage.bind(this);
|
|
5358
5608
|
}
|
|
5359
|
-
|
|
5360
|
-
|
|
5361
|
-
|
|
5362
|
-
|
|
5363
|
-
|
|
5364
|
-
|
|
5365
|
-
|
|
5366
|
-
|
|
5367
|
-
|
|
5368
|
-
|
|
5369
|
-
|
|
5370
|
-
|
|
5371
|
-
|
|
5372
|
-
}
|
|
5373
|
-
|
|
5374
|
-
|
|
5375
|
-
|
|
5376
|
-
|
|
5377
|
-
|
|
5378
|
-
|
|
5379
|
-
|
|
5380
|
-
|
|
5381
|
-
|
|
5382
|
-
|
|
5383
|
-
|
|
5384
|
-
|
|
5385
|
-
|
|
5609
|
+
get lockKey() {
|
|
5610
|
+
return this._lockKey;
|
|
5611
|
+
}
|
|
5612
|
+
async acquire() {
|
|
5613
|
+
this._broadcastChannel.postMessage({
|
|
5614
|
+
message: "acquiring"
|
|
5615
|
+
});
|
|
5616
|
+
try {
|
|
5617
|
+
log16("aquiring lock...", void 0, {
|
|
5618
|
+
F: __dxlog_file19,
|
|
5619
|
+
L: 42,
|
|
5620
|
+
S: this,
|
|
5621
|
+
C: (f, a) => f(...a)
|
|
5622
|
+
});
|
|
5623
|
+
await asyncTimeout3(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
|
|
5624
|
+
log16("acquired lock", void 0, {
|
|
5625
|
+
F: __dxlog_file19,
|
|
5626
|
+
L: 44,
|
|
5627
|
+
S: this,
|
|
5628
|
+
C: (f, a) => f(...a)
|
|
5629
|
+
});
|
|
5630
|
+
} catch {
|
|
5631
|
+
log16("stealing lock...", void 0, {
|
|
5632
|
+
F: __dxlog_file19,
|
|
5633
|
+
L: 46,
|
|
5634
|
+
S: this,
|
|
5635
|
+
C: (f, a) => f(...a)
|
|
5636
|
+
});
|
|
5637
|
+
await this._requestLock(true);
|
|
5638
|
+
log16("stolen lock", void 0, {
|
|
5639
|
+
F: __dxlog_file19,
|
|
5640
|
+
L: 48,
|
|
5641
|
+
S: this,
|
|
5642
|
+
C: (f, a) => f(...a)
|
|
5386
5643
|
});
|
|
5387
|
-
diagnostics.metrics = await getFirstStreamValue(clientServices.LoggingService.queryMetrics({}), {
|
|
5388
|
-
timeout: DEFAULT_TIMEOUT
|
|
5389
|
-
}).catch(() => void 0);
|
|
5390
|
-
})(),
|
|
5391
|
-
(async () => {
|
|
5392
|
-
diagnostics.storage = await asyncTimeout2(getStorageDiagnostics(), DEFAULT_TIMEOUT).catch(() => void 0);
|
|
5393
|
-
})(),
|
|
5394
|
-
async () => {
|
|
5395
|
-
const identity = serviceContext.identityManager.identity;
|
|
5396
|
-
if (identity) {
|
|
5397
|
-
diagnostics.identity = {
|
|
5398
|
-
identityKey: identity.identityKey,
|
|
5399
|
-
spaceKey: identity.space.key,
|
|
5400
|
-
profile: identity.profileDocument
|
|
5401
|
-
};
|
|
5402
|
-
const { devices } = await getFirstStreamValue(clientServices.DevicesService.queryDevices(), {
|
|
5403
|
-
timeout: DEFAULT_TIMEOUT
|
|
5404
|
-
}).catch(() => void 0) ?? {};
|
|
5405
|
-
diagnostics.devices = devices;
|
|
5406
|
-
if (serviceContext.dataSpaceManager) {
|
|
5407
|
-
diagnostics.spaces = await Promise.all(Array.from(serviceContext.dataSpaceManager.spaces.values()).map((space) => getSpaceStats(space)) ?? []);
|
|
5408
|
-
}
|
|
5409
|
-
const { feeds = [] } = await getFirstStreamValue(clientServices.DevtoolsHost.subscribeToFeeds({}), {
|
|
5410
|
-
timeout: DEFAULT_TIMEOUT
|
|
5411
|
-
}).catch(() => void 0) ?? {};
|
|
5412
|
-
diagnostics.feeds = feeds.map(({ feedKey, bytes, length }) => ({
|
|
5413
|
-
feedKey,
|
|
5414
|
-
bytes,
|
|
5415
|
-
length
|
|
5416
|
-
}));
|
|
5417
|
-
const status = await getFirstStreamValue(clientServices.NetworkService.queryStatus(), {
|
|
5418
|
-
timeout: DEFAULT_TIMEOUT
|
|
5419
|
-
}).catch(() => void 0);
|
|
5420
|
-
diagnostics.networkStatus = status;
|
|
5421
|
-
diagnostics.swarms = serviceContext.networkManager.connectionLog?.swarms;
|
|
5422
|
-
}
|
|
5423
5644
|
}
|
|
5424
|
-
|
|
5425
|
-
|
|
5426
|
-
|
|
5427
|
-
}
|
|
5428
|
-
|
|
5429
|
-
|
|
5430
|
-
|
|
5431
|
-
metrics: space.metrics,
|
|
5432
|
-
epochs: space.inner.spaceState.credentials.filter(credentialTypeFilter("dxos.halo.credentials.Epoch")).map((credential) => ({
|
|
5433
|
-
...credential.subject.assertion,
|
|
5434
|
-
id: credential.id
|
|
5435
|
-
})),
|
|
5436
|
-
members: Array.from(space.inner.spaceState.members.values()).map((member) => ({
|
|
5437
|
-
role: member.role,
|
|
5438
|
-
identity: {
|
|
5439
|
-
identityKey: member.key,
|
|
5440
|
-
profile: {
|
|
5441
|
-
displayName: member.assertion.profile?.displayName
|
|
5442
|
-
}
|
|
5443
|
-
},
|
|
5444
|
-
presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? SpaceMember7.PresenceState.ONLINE : SpaceMember7.PresenceState.OFFLINE
|
|
5445
|
-
})),
|
|
5446
|
-
pipeline: {
|
|
5447
|
-
// TODO(burdon): Pick properties from credentials if needed.
|
|
5448
|
-
currentEpoch: space.automergeSpaceState.lastEpoch,
|
|
5449
|
-
appliedEpoch: space.automergeSpaceState.lastEpoch,
|
|
5450
|
-
controlFeeds: space.inner.controlPipeline.state.feeds.map((feed) => feed.key),
|
|
5451
|
-
currentControlTimeframe: space.inner.controlPipeline.state.timeframe,
|
|
5452
|
-
targetControlTimeframe: space.inner.controlPipeline.state.targetTimeframe,
|
|
5453
|
-
totalControlTimeframe: space.inner.controlPipeline.state.endTimeframe
|
|
5645
|
+
}
|
|
5646
|
+
async release() {
|
|
5647
|
+
this._releaseTrigger.wake();
|
|
5648
|
+
}
|
|
5649
|
+
_onMessage(event) {
|
|
5650
|
+
if (event.data.message === "acquiring") {
|
|
5651
|
+
this._releaseTrigger.wake();
|
|
5454
5652
|
}
|
|
5455
|
-
};
|
|
5456
|
-
if (stats.metrics) {
|
|
5457
|
-
const { open, ready } = stats.metrics;
|
|
5458
|
-
stats.metrics.startupTime = open && ready && ready.getTime() - open.getTime();
|
|
5459
5653
|
}
|
|
5460
|
-
|
|
5654
|
+
async _requestLock(steal = false) {
|
|
5655
|
+
log16("requesting lock...", {
|
|
5656
|
+
steal
|
|
5657
|
+
}, {
|
|
5658
|
+
F: __dxlog_file19,
|
|
5659
|
+
L: 63,
|
|
5660
|
+
S: this,
|
|
5661
|
+
C: (f, a) => f(...a)
|
|
5662
|
+
});
|
|
5663
|
+
const acquired = new Trigger8();
|
|
5664
|
+
void navigator.locks.request(this._lockKey, {
|
|
5665
|
+
steal
|
|
5666
|
+
}, async () => {
|
|
5667
|
+
await this._onAcquire?.();
|
|
5668
|
+
acquired.wake();
|
|
5669
|
+
this._releaseTrigger = new Trigger8();
|
|
5670
|
+
await this._releaseTrigger.wait();
|
|
5671
|
+
log16("releasing lock...", void 0, {
|
|
5672
|
+
F: __dxlog_file19,
|
|
5673
|
+
L: 72,
|
|
5674
|
+
S: this,
|
|
5675
|
+
C: (f, a) => f(...a)
|
|
5676
|
+
});
|
|
5677
|
+
await this._onRelease?.();
|
|
5678
|
+
log16("released lock", void 0, {
|
|
5679
|
+
F: __dxlog_file19,
|
|
5680
|
+
L: 74,
|
|
5681
|
+
S: this,
|
|
5682
|
+
C: (f, a) => f(...a)
|
|
5683
|
+
});
|
|
5684
|
+
}).catch(async () => {
|
|
5685
|
+
await this._onRelease?.();
|
|
5686
|
+
});
|
|
5687
|
+
await acquired.wait();
|
|
5688
|
+
log16("recieved lock", {
|
|
5689
|
+
steal
|
|
5690
|
+
}, {
|
|
5691
|
+
F: __dxlog_file19,
|
|
5692
|
+
L: 81,
|
|
5693
|
+
S: this,
|
|
5694
|
+
C: (f, a) => f(...a)
|
|
5695
|
+
});
|
|
5696
|
+
}
|
|
5461
5697
|
};
|
|
5462
|
-
|
|
5463
|
-
|
|
5464
|
-
|
|
5465
|
-
|
|
5466
|
-
|
|
5467
|
-
const dir = await navigator.storage.getDirectory();
|
|
5468
|
-
for await (const filename of dir?.keys()) {
|
|
5469
|
-
const idx = filename.indexOf("-", filename.indexOf("-") + 1);
|
|
5470
|
-
if (idx === -1) {
|
|
5471
|
-
continue;
|
|
5472
|
-
}
|
|
5473
|
-
map.set(filename.slice(0, idx), (map.get(filename.slice(0, idx)) ?? 0) + 1);
|
|
5474
|
-
}
|
|
5475
|
-
return Array.from(map.entries()).sort((a, b) => b[1] - a[1]).map(([file, count]) => ({
|
|
5476
|
-
file,
|
|
5477
|
-
count
|
|
5478
|
-
}));
|
|
5698
|
+
_ts_decorate7([
|
|
5699
|
+
logInfo
|
|
5700
|
+
], Lock.prototype, "lockKey", null);
|
|
5701
|
+
var isLocked = (lockPath) => {
|
|
5702
|
+
throw new Error("Not implemented");
|
|
5479
5703
|
};
|
|
5480
5704
|
|
|
5481
|
-
// packages/sdk/client-services/src/packlets/
|
|
5482
|
-
import {
|
|
5483
|
-
import {
|
|
5484
|
-
|
|
5485
|
-
|
|
5486
|
-
|
|
5487
|
-
|
|
5488
|
-
|
|
5489
|
-
|
|
5490
|
-
|
|
5491
|
-
|
|
5492
|
-
|
|
5493
|
-
var createCollectDiagnosticsBroadcastSender = () => {
|
|
5494
|
-
return {
|
|
5495
|
-
broadcastDiagnosticsRequest: async () => {
|
|
5496
|
-
let expectedResponse = "probe-ack";
|
|
5497
|
-
let channel;
|
|
5498
|
-
try {
|
|
5499
|
-
const trigger = new Trigger7();
|
|
5500
|
-
channel = new BroadcastChannel(CHANNEL_NAME);
|
|
5501
|
-
channel.onmessage = (msg) => {
|
|
5502
|
-
if (expectedResponse === msg.data.type) {
|
|
5503
|
-
trigger.wake(msg.data);
|
|
5504
|
-
}
|
|
5505
|
-
};
|
|
5506
|
-
channel.postMessage({
|
|
5507
|
-
type: "probe"
|
|
5508
|
-
});
|
|
5509
|
-
await trigger.wait({
|
|
5510
|
-
timeout: 200
|
|
5511
|
-
});
|
|
5512
|
-
expectedResponse = "receive-diagnostics";
|
|
5513
|
-
trigger.reset();
|
|
5514
|
-
channel.postMessage({
|
|
5515
|
-
type: "request-diagnostics"
|
|
5516
|
-
});
|
|
5517
|
-
const diagnostics = await trigger.wait({
|
|
5518
|
-
timeout: 5e3
|
|
5519
|
-
});
|
|
5520
|
-
return diagnostics.payload;
|
|
5521
|
-
} catch (e) {
|
|
5522
|
-
const errorDescription = e instanceof Error ? e.message : JSON.stringify(e);
|
|
5523
|
-
return {
|
|
5524
|
-
expectedResponse,
|
|
5525
|
-
errorDescription
|
|
5526
|
-
};
|
|
5527
|
-
} finally {
|
|
5528
|
-
safeClose(channel);
|
|
5529
|
-
}
|
|
5530
|
-
}
|
|
5531
|
-
};
|
|
5705
|
+
// packages/sdk/client-services/src/packlets/storage/storage.ts
|
|
5706
|
+
import { InvalidConfigError } from "@dxos/protocols";
|
|
5707
|
+
import { Runtime as Runtime2 } from "@dxos/protocols/proto/dxos/config";
|
|
5708
|
+
import { createStorage, StorageType } from "@dxos/random-access-storage";
|
|
5709
|
+
|
|
5710
|
+
// packages/sdk/client-services/src/packlets/storage/util.ts
|
|
5711
|
+
import { DX_DATA } from "@dxos/client-protocol";
|
|
5712
|
+
import { Runtime } from "@dxos/protocols/proto/dxos/config";
|
|
5713
|
+
import { isNode as isNode2 } from "@dxos/util";
|
|
5714
|
+
var getRootPath = (config) => {
|
|
5715
|
+
const { dataRoot = isNode2() ? DX_DATA : "dxos/storage" } = config ?? {};
|
|
5716
|
+
return `${dataRoot}/`;
|
|
5532
5717
|
};
|
|
5533
|
-
var
|
|
5534
|
-
|
|
5718
|
+
var isPersistent = (config) => {
|
|
5719
|
+
const { persistent = false } = config ?? {};
|
|
5720
|
+
return config.dataStore !== void 0 && config.dataStore !== Runtime.Client.Storage.StorageDriver.RAM || persistent;
|
|
5721
|
+
};
|
|
5722
|
+
|
|
5723
|
+
// packages/sdk/client-services/src/packlets/storage/storage.ts
|
|
5724
|
+
var StorageDriver = Runtime2.Client.Storage.StorageDriver;
|
|
5725
|
+
var createStorageObjects = (config) => {
|
|
5726
|
+
const { persistent = false, keyStore, dataStore } = config ?? {};
|
|
5727
|
+
if (persistent && dataStore === StorageDriver.RAM) {
|
|
5728
|
+
throw new InvalidConfigError("RAM storage cannot be used in persistent mode.");
|
|
5729
|
+
}
|
|
5730
|
+
if (!persistent && dataStore !== void 0 && dataStore !== StorageDriver.RAM) {
|
|
5731
|
+
throw new InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
|
|
5732
|
+
}
|
|
5733
|
+
if (persistent && keyStore === StorageDriver.RAM) {
|
|
5734
|
+
throw new InvalidConfigError("RAM key storage cannot be used in persistent mode.");
|
|
5735
|
+
}
|
|
5736
|
+
if (!persistent && keyStore !== StorageDriver.RAM && keyStore !== void 0) {
|
|
5737
|
+
throw new InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
|
|
5738
|
+
}
|
|
5535
5739
|
return {
|
|
5536
|
-
|
|
5537
|
-
|
|
5538
|
-
|
|
5539
|
-
|
|
5540
|
-
if (message.data.type === "probe") {
|
|
5541
|
-
channel?.postMessage({
|
|
5542
|
-
type: "probe-ack"
|
|
5543
|
-
});
|
|
5544
|
-
} else if (message.data.type === "request-diagnostics") {
|
|
5545
|
-
const diagnostics = await systemService.getDiagnostics({});
|
|
5546
|
-
channel?.postMessage({
|
|
5547
|
-
type: "receive-diagnostics",
|
|
5548
|
-
payload: diagnostics
|
|
5549
|
-
});
|
|
5550
|
-
}
|
|
5551
|
-
} catch (error) {
|
|
5552
|
-
log15.catch(error, void 0, {
|
|
5553
|
-
F: __dxlog_file18,
|
|
5554
|
-
L: 77,
|
|
5555
|
-
S: void 0,
|
|
5556
|
-
C: (f, a) => f(...a)
|
|
5557
|
-
});
|
|
5558
|
-
}
|
|
5559
|
-
};
|
|
5560
|
-
},
|
|
5561
|
-
stop: () => {
|
|
5562
|
-
safeClose(channel);
|
|
5563
|
-
channel = void 0;
|
|
5564
|
-
}
|
|
5740
|
+
storage: createStorage({
|
|
5741
|
+
type: persistent ? toStorageType(dataStore) : StorageType.RAM,
|
|
5742
|
+
root: getRootPath(config)
|
|
5743
|
+
})
|
|
5565
5744
|
};
|
|
5566
5745
|
};
|
|
5567
|
-
var
|
|
5568
|
-
|
|
5569
|
-
|
|
5570
|
-
|
|
5746
|
+
var toStorageType = (type) => {
|
|
5747
|
+
switch (type) {
|
|
5748
|
+
case void 0:
|
|
5749
|
+
return void 0;
|
|
5750
|
+
case StorageDriver.RAM:
|
|
5751
|
+
return StorageType.RAM;
|
|
5752
|
+
case StorageDriver.CHROME:
|
|
5753
|
+
return StorageType.CHROME;
|
|
5754
|
+
case StorageDriver.FIREFOX:
|
|
5755
|
+
return StorageType.FIREFOX;
|
|
5756
|
+
case StorageDriver.IDB:
|
|
5757
|
+
return StorageType.IDB;
|
|
5758
|
+
case StorageDriver.NODE:
|
|
5759
|
+
return StorageType.NODE;
|
|
5760
|
+
case StorageDriver.WEBFS:
|
|
5761
|
+
return StorageType.WEBFS;
|
|
5762
|
+
default:
|
|
5763
|
+
throw new Error(`Invalid storage type: ${StorageDriver[type]}`);
|
|
5571
5764
|
}
|
|
5572
5765
|
};
|
|
5573
5766
|
|
|
5574
|
-
// packages/sdk/client-services/src/packlets/
|
|
5575
|
-
import
|
|
5576
|
-
import {
|
|
5577
|
-
import {
|
|
5578
|
-
|
|
5767
|
+
// packages/sdk/client-services/src/packlets/storage/level.ts
|
|
5768
|
+
import path from "@dxos/node-std/path";
|
|
5769
|
+
import { PublicKey as PublicKey13 } from "@dxos/keys";
|
|
5770
|
+
import { createLevel as createKV } from "@dxos/kv-store";
|
|
5771
|
+
var createLevel = async (config) => {
|
|
5772
|
+
const persistent = isPersistent(config);
|
|
5773
|
+
const storagePath = persistent ? path.join(getRootPath(config), "level") : `/tmp/dxos-${PublicKey13.random().toHex()}`;
|
|
5774
|
+
const level = createKV(storagePath);
|
|
5775
|
+
await level.open();
|
|
5776
|
+
return level;
|
|
5777
|
+
};
|
|
5579
5778
|
|
|
5580
5779
|
// packages/sdk/client-services/src/packlets/services/service-host.ts
|
|
5581
5780
|
import { Event as Event9, synchronized as synchronized3 } from "@dxos/async";
|
|
5582
|
-
import { clientServiceBundle, defaultKey,
|
|
5781
|
+
import { clientServiceBundle, defaultKey, PropertiesType } from "@dxos/client-protocol";
|
|
5583
5782
|
import { Context as Context11 } from "@dxos/context";
|
|
5584
5783
|
import { encodeReference } from "@dxos/echo-protocol";
|
|
5585
5784
|
import { getTypeReference } from "@dxos/echo-schema";
|
|
5586
5785
|
import { invariant as invariant18 } from "@dxos/invariant";
|
|
5587
|
-
import { PublicKey as
|
|
5786
|
+
import { PublicKey as PublicKey16 } from "@dxos/keys";
|
|
5588
5787
|
import { log as log18 } from "@dxos/log";
|
|
5589
5788
|
import { WebsocketSignalManager } from "@dxos/messaging";
|
|
5590
|
-
import {
|
|
5789
|
+
import { SwarmNetworkManager, createSimplePeerTransportFactory } from "@dxos/network-manager";
|
|
5591
5790
|
import { trace as trace10 } from "@dxos/protocols";
|
|
5592
5791
|
import { SystemStatus } from "@dxos/protocols/proto/dxos/client/services";
|
|
5593
|
-
import { TRACE_PROCESSOR as
|
|
5792
|
+
import { TRACE_PROCESSOR as TRACE_PROCESSOR3, trace as Trace4 } from "@dxos/tracing";
|
|
5594
5793
|
import { assignDeep as assignDeep2 } from "@dxos/util";
|
|
5595
5794
|
import { WebsocketRpcClient } from "@dxos/websocket-rpc";
|
|
5596
5795
|
|
|
@@ -5599,7 +5798,7 @@ import { EventSubscriptions as EventSubscriptions3 } from "@dxos/async";
|
|
|
5599
5798
|
import { Stream as Stream11 } from "@dxos/codec-protobuf";
|
|
5600
5799
|
import { invariant as invariant17 } from "@dxos/invariant";
|
|
5601
5800
|
import { Device as Device2, DeviceKind as DeviceKind2 } from "@dxos/protocols/proto/dxos/client/services";
|
|
5602
|
-
var
|
|
5801
|
+
var __dxlog_file20 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
|
|
5603
5802
|
var DevicesServiceImpl = class {
|
|
5604
5803
|
constructor(_identityManager) {
|
|
5605
5804
|
this._identityManager = _identityManager;
|
|
@@ -5617,7 +5816,7 @@ var DevicesServiceImpl = class {
|
|
|
5617
5816
|
});
|
|
5618
5817
|
} else {
|
|
5619
5818
|
invariant17(this._identityManager.identity?.presence, "presence not present", {
|
|
5620
|
-
F:
|
|
5819
|
+
F: __dxlog_file20,
|
|
5621
5820
|
L: 32,
|
|
5622
5821
|
S: this,
|
|
5623
5822
|
A: [
|
|
@@ -5645,165 +5844,88 @@ var DevicesServiceImpl = class {
|
|
|
5645
5844
|
const subscribeIdentity = () => {
|
|
5646
5845
|
if (!identitySubscribed) {
|
|
5647
5846
|
this._identityManager.identity?.stateUpdate.on(() => {
|
|
5648
|
-
update();
|
|
5649
|
-
});
|
|
5650
|
-
identitySubscribed = true;
|
|
5651
|
-
}
|
|
5652
|
-
};
|
|
5653
|
-
const subscribePresence = () => {
|
|
5654
|
-
if (!presenceSubscribed) {
|
|
5655
|
-
this._identityManager.identity?.presence?.updated.on(() => {
|
|
5656
|
-
update();
|
|
5657
|
-
});
|
|
5658
|
-
presenceSubscribed = true;
|
|
5659
|
-
}
|
|
5660
|
-
};
|
|
5661
|
-
const subscriptions = new EventSubscriptions3();
|
|
5662
|
-
if (this._identityManager.identity) {
|
|
5663
|
-
subscribeIdentity();
|
|
5664
|
-
subscribePresence();
|
|
5665
|
-
}
|
|
5666
|
-
subscriptions.add(this._identityManager.stateUpdate.on(() => {
|
|
5667
|
-
update();
|
|
5668
|
-
if (this._identityManager.identity) {
|
|
5669
|
-
subscribeIdentity();
|
|
5670
|
-
subscribePresence();
|
|
5671
|
-
}
|
|
5672
|
-
}));
|
|
5673
|
-
update();
|
|
5674
|
-
return () => subscriptions.clear();
|
|
5675
|
-
});
|
|
5676
|
-
}
|
|
5677
|
-
};
|
|
5678
|
-
|
|
5679
|
-
// packages/sdk/client-services/src/packlets/locks/browser.ts
|
|
5680
|
-
import { asyncTimeout as asyncTimeout3, Trigger as Trigger8 } from "@dxos/async";
|
|
5681
|
-
import { RESOURCE_LOCK_TIMEOUT } from "@dxos/client-protocol";
|
|
5682
|
-
import { log as log16, logInfo } from "@dxos/log";
|
|
5683
|
-
function _ts_decorate7(decorators, target, key, desc) {
|
|
5684
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
5685
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
5686
|
-
r = Reflect.decorate(decorators, target, key, desc);
|
|
5687
|
-
else
|
|
5688
|
-
for (var i = decorators.length - 1; i >= 0; i--)
|
|
5689
|
-
if (d = decorators[i])
|
|
5690
|
-
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5691
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
5692
|
-
}
|
|
5693
|
-
var __dxlog_file20 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
|
|
5694
|
-
var Message;
|
|
5695
|
-
(function(Message2) {
|
|
5696
|
-
Message2["ACQUIRING"] = "acquiring";
|
|
5697
|
-
})(Message || (Message = {}));
|
|
5698
|
-
var Lock = class {
|
|
5699
|
-
constructor({ lockKey, onAcquire, onRelease }) {
|
|
5700
|
-
this._broadcastChannel = new BroadcastChannel("vault-resource-lock");
|
|
5701
|
-
this._releaseTrigger = new Trigger8();
|
|
5702
|
-
this._lockKey = lockKey;
|
|
5703
|
-
this._onAcquire = onAcquire;
|
|
5704
|
-
this._onRelease = onRelease;
|
|
5705
|
-
this._broadcastChannel.onmessage = this._onMessage.bind(this);
|
|
5706
|
-
}
|
|
5707
|
-
get lockKey() {
|
|
5708
|
-
return this._lockKey;
|
|
5709
|
-
}
|
|
5710
|
-
async acquire() {
|
|
5711
|
-
this._broadcastChannel.postMessage({
|
|
5712
|
-
message: "acquiring"
|
|
5847
|
+
update();
|
|
5848
|
+
});
|
|
5849
|
+
identitySubscribed = true;
|
|
5850
|
+
}
|
|
5851
|
+
};
|
|
5852
|
+
const subscribePresence = () => {
|
|
5853
|
+
if (!presenceSubscribed) {
|
|
5854
|
+
this._identityManager.identity?.presence?.updated.on(() => {
|
|
5855
|
+
update();
|
|
5856
|
+
});
|
|
5857
|
+
presenceSubscribed = true;
|
|
5858
|
+
}
|
|
5859
|
+
};
|
|
5860
|
+
const subscriptions = new EventSubscriptions3();
|
|
5861
|
+
if (this._identityManager.identity) {
|
|
5862
|
+
subscribeIdentity();
|
|
5863
|
+
subscribePresence();
|
|
5864
|
+
}
|
|
5865
|
+
subscriptions.add(this._identityManager.stateUpdate.on(() => {
|
|
5866
|
+
update();
|
|
5867
|
+
if (this._identityManager.identity) {
|
|
5868
|
+
subscribeIdentity();
|
|
5869
|
+
subscribePresence();
|
|
5870
|
+
}
|
|
5871
|
+
}));
|
|
5872
|
+
update();
|
|
5873
|
+
return () => subscriptions.clear();
|
|
5713
5874
|
});
|
|
5714
|
-
try {
|
|
5715
|
-
log16("aquiring lock...", void 0, {
|
|
5716
|
-
F: __dxlog_file20,
|
|
5717
|
-
L: 42,
|
|
5718
|
-
S: this,
|
|
5719
|
-
C: (f, a) => f(...a)
|
|
5720
|
-
});
|
|
5721
|
-
await asyncTimeout3(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
|
|
5722
|
-
log16("acquired lock", void 0, {
|
|
5723
|
-
F: __dxlog_file20,
|
|
5724
|
-
L: 44,
|
|
5725
|
-
S: this,
|
|
5726
|
-
C: (f, a) => f(...a)
|
|
5727
|
-
});
|
|
5728
|
-
} catch {
|
|
5729
|
-
log16("stealing lock...", void 0, {
|
|
5730
|
-
F: __dxlog_file20,
|
|
5731
|
-
L: 46,
|
|
5732
|
-
S: this,
|
|
5733
|
-
C: (f, a) => f(...a)
|
|
5734
|
-
});
|
|
5735
|
-
await this._requestLock(true);
|
|
5736
|
-
log16("stolen lock", void 0, {
|
|
5737
|
-
F: __dxlog_file20,
|
|
5738
|
-
L: 48,
|
|
5739
|
-
S: this,
|
|
5740
|
-
C: (f, a) => f(...a)
|
|
5741
|
-
});
|
|
5742
|
-
}
|
|
5743
5875
|
}
|
|
5744
|
-
|
|
5745
|
-
|
|
5746
|
-
|
|
5747
|
-
|
|
5748
|
-
|
|
5749
|
-
|
|
5750
|
-
|
|
5876
|
+
};
|
|
5877
|
+
|
|
5878
|
+
// packages/sdk/client-services/src/packlets/diagnostics/diagnostics-collector.ts
|
|
5879
|
+
import { ConfigResource } from "@dxos/config";
|
|
5880
|
+
import { GetDiagnosticsRequest } from "@dxos/protocols/proto/dxos/client/services";
|
|
5881
|
+
import { TRACE_PROCESSOR as TRACE_PROCESSOR2 } from "@dxos/tracing";
|
|
5882
|
+
import { jsonKeyReplacer, nonNullable } from "@dxos/util";
|
|
5883
|
+
|
|
5884
|
+
// packages/sdk/client-services/src/packlets/services/util.ts
|
|
5885
|
+
import { PublicKey as PublicKey14 } from "@dxos/keys";
|
|
5886
|
+
import { humanize } from "@dxos/util";
|
|
5887
|
+
var ClientServicesProviderResource = Symbol.for("dxos.resource.ClientServices");
|
|
5888
|
+
|
|
5889
|
+
// packages/sdk/client-services/src/packlets/diagnostics/diagnostics-collector.ts
|
|
5890
|
+
var GET_DIAGNOSTICS_RPC_TIMEOUT = 1e4;
|
|
5891
|
+
var DiagnosticsCollector = class {
|
|
5892
|
+
static {
|
|
5893
|
+
this.broadcastSender = createCollectDiagnosticsBroadcastSender();
|
|
5751
5894
|
}
|
|
5752
|
-
async
|
|
5753
|
-
|
|
5754
|
-
|
|
5755
|
-
}, {
|
|
5756
|
-
F: __dxlog_file20,
|
|
5757
|
-
L: 63,
|
|
5758
|
-
S: this,
|
|
5759
|
-
C: (f, a) => f(...a)
|
|
5760
|
-
});
|
|
5761
|
-
const acquired = new Trigger8();
|
|
5762
|
-
void navigator.locks.request(this._lockKey, {
|
|
5763
|
-
steal
|
|
5764
|
-
}, async () => {
|
|
5765
|
-
await this._onAcquire?.();
|
|
5766
|
-
acquired.wake();
|
|
5767
|
-
this._releaseTrigger = new Trigger8();
|
|
5768
|
-
await this._releaseTrigger.wait();
|
|
5769
|
-
log16("releasing lock...", void 0, {
|
|
5770
|
-
F: __dxlog_file20,
|
|
5771
|
-
L: 72,
|
|
5772
|
-
S: this,
|
|
5773
|
-
C: (f, a) => f(...a)
|
|
5774
|
-
});
|
|
5775
|
-
await this._onRelease?.();
|
|
5776
|
-
log16("released lock", void 0, {
|
|
5777
|
-
F: __dxlog_file20,
|
|
5778
|
-
L: 74,
|
|
5779
|
-
S: this,
|
|
5780
|
-
C: (f, a) => f(...a)
|
|
5781
|
-
});
|
|
5782
|
-
}).catch(async () => {
|
|
5783
|
-
await this._onRelease?.();
|
|
5784
|
-
});
|
|
5785
|
-
await acquired.wait();
|
|
5786
|
-
log16("recieved lock", {
|
|
5787
|
-
steal
|
|
5895
|
+
static async collect(config = findConfigs(), services = findSystemServiceProvider(), options = {}) {
|
|
5896
|
+
const serviceDiagnostics = await services?.services?.SystemService?.getDiagnostics({
|
|
5897
|
+
keys: options.humanize ? GetDiagnosticsRequest.KEY_OPTION.HUMANIZE : options.truncate ? GetDiagnosticsRequest.KEY_OPTION.TRUNCATE : void 0
|
|
5788
5898
|
}, {
|
|
5789
|
-
|
|
5790
|
-
L: 81,
|
|
5791
|
-
S: this,
|
|
5792
|
-
C: (f, a) => f(...a)
|
|
5899
|
+
timeout: GET_DIAGNOSTICS_RPC_TIMEOUT
|
|
5793
5900
|
});
|
|
5901
|
+
const clientDiagnostics = {
|
|
5902
|
+
config,
|
|
5903
|
+
trace: TRACE_PROCESSOR2.getDiagnostics()
|
|
5904
|
+
};
|
|
5905
|
+
const diagnostics = serviceDiagnostics != null ? {
|
|
5906
|
+
client: clientDiagnostics,
|
|
5907
|
+
services: serviceDiagnostics
|
|
5908
|
+
} : {
|
|
5909
|
+
client: clientDiagnostics,
|
|
5910
|
+
broadcast: await this.broadcastSender.broadcastDiagnosticsRequest()
|
|
5911
|
+
};
|
|
5912
|
+
return JSON.parse(JSON.stringify(diagnostics, jsonKeyReplacer(options)));
|
|
5794
5913
|
}
|
|
5795
5914
|
};
|
|
5796
|
-
|
|
5797
|
-
|
|
5798
|
-
|
|
5799
|
-
|
|
5800
|
-
|
|
5915
|
+
var findSystemServiceProvider = () => {
|
|
5916
|
+
const serviceProviders = TRACE_PROCESSOR2.findResourcesByAnnotation(ClientServicesProviderResource);
|
|
5917
|
+
const providerResource = serviceProviders.find((r) => r.instance.deref()?.services?.SystemService != null);
|
|
5918
|
+
return providerResource?.instance?.deref() ?? null;
|
|
5919
|
+
};
|
|
5920
|
+
var findConfigs = () => {
|
|
5921
|
+
const configs = TRACE_PROCESSOR2.findResourcesByAnnotation(ConfigResource);
|
|
5922
|
+
return configs.map((r) => r.instance.deref()).filter(nonNullable);
|
|
5801
5923
|
};
|
|
5802
5924
|
|
|
5803
5925
|
// packages/sdk/client-services/src/packlets/logging/logging-service.ts
|
|
5804
5926
|
import { Event as Event8 } from "@dxos/async";
|
|
5805
5927
|
import { Stream as Stream12 } from "@dxos/codec-protobuf";
|
|
5806
|
-
import { PublicKey as
|
|
5928
|
+
import { PublicKey as PublicKey15 } from "@dxos/keys";
|
|
5807
5929
|
import { getContextFromEntry, log as log17 } from "@dxos/log";
|
|
5808
5930
|
import { QueryLogsRequest } from "@dxos/protocols/proto/dxos/client/services";
|
|
5809
5931
|
import { getDebugName, jsonify, numericalValues, tracer } from "@dxos/util";
|
|
@@ -5811,7 +5933,7 @@ var LoggingServiceImpl = class {
|
|
|
5811
5933
|
constructor() {
|
|
5812
5934
|
this._logs = new Event8();
|
|
5813
5935
|
this._started = Date.now();
|
|
5814
|
-
this._sessionId =
|
|
5936
|
+
this._sessionId = PublicKey15.random().toHex();
|
|
5815
5937
|
this._logProcessor = (_config, entry2) => {
|
|
5816
5938
|
this._logs.emit(entry2);
|
|
5817
5939
|
};
|
|
@@ -5957,84 +6079,10 @@ var NetworkServiceImpl = class {
|
|
|
5957
6079
|
}
|
|
5958
6080
|
};
|
|
5959
6081
|
|
|
5960
|
-
// packages/sdk/client-services/src/packlets/storage/storage.ts
|
|
5961
|
-
import { InvalidConfigError } from "@dxos/protocols";
|
|
5962
|
-
import { Runtime as Runtime2 } from "@dxos/protocols/proto/dxos/config";
|
|
5963
|
-
import { createStorage, StorageType } from "@dxos/random-access-storage";
|
|
5964
|
-
|
|
5965
|
-
// packages/sdk/client-services/src/packlets/storage/util.ts
|
|
5966
|
-
import { DX_DATA } from "@dxos/client-protocol";
|
|
5967
|
-
import { Runtime } from "@dxos/protocols/proto/dxos/config";
|
|
5968
|
-
import { isNode as isNode2 } from "@dxos/util";
|
|
5969
|
-
var getRootPath = (config) => {
|
|
5970
|
-
const { dataRoot = isNode2() ? DX_DATA : "dxos/storage" } = config ?? {};
|
|
5971
|
-
return `${dataRoot}/`;
|
|
5972
|
-
};
|
|
5973
|
-
var isPersistent = (config) => {
|
|
5974
|
-
const { persistent = false } = config ?? {};
|
|
5975
|
-
return config.dataStore !== void 0 && config.dataStore !== Runtime.Client.Storage.StorageDriver.RAM || persistent;
|
|
5976
|
-
};
|
|
5977
|
-
|
|
5978
|
-
// packages/sdk/client-services/src/packlets/storage/storage.ts
|
|
5979
|
-
var StorageDriver = Runtime2.Client.Storage.StorageDriver;
|
|
5980
|
-
var createStorageObjects = (config) => {
|
|
5981
|
-
const { persistent = false, keyStore, dataStore } = config ?? {};
|
|
5982
|
-
if (persistent && dataStore === StorageDriver.RAM) {
|
|
5983
|
-
throw new InvalidConfigError("RAM storage cannot be used in persistent mode.");
|
|
5984
|
-
}
|
|
5985
|
-
if (!persistent && dataStore !== void 0 && dataStore !== StorageDriver.RAM) {
|
|
5986
|
-
throw new InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
|
|
5987
|
-
}
|
|
5988
|
-
if (persistent && keyStore === StorageDriver.RAM) {
|
|
5989
|
-
throw new InvalidConfigError("RAM key storage cannot be used in persistent mode.");
|
|
5990
|
-
}
|
|
5991
|
-
if (!persistent && keyStore !== StorageDriver.RAM && keyStore !== void 0) {
|
|
5992
|
-
throw new InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
|
|
5993
|
-
}
|
|
5994
|
-
return {
|
|
5995
|
-
storage: createStorage({
|
|
5996
|
-
type: persistent ? toStorageType(dataStore) : StorageType.RAM,
|
|
5997
|
-
root: getRootPath(config)
|
|
5998
|
-
})
|
|
5999
|
-
};
|
|
6000
|
-
};
|
|
6001
|
-
var toStorageType = (type) => {
|
|
6002
|
-
switch (type) {
|
|
6003
|
-
case void 0:
|
|
6004
|
-
return void 0;
|
|
6005
|
-
case StorageDriver.RAM:
|
|
6006
|
-
return StorageType.RAM;
|
|
6007
|
-
case StorageDriver.CHROME:
|
|
6008
|
-
return StorageType.CHROME;
|
|
6009
|
-
case StorageDriver.FIREFOX:
|
|
6010
|
-
return StorageType.FIREFOX;
|
|
6011
|
-
case StorageDriver.IDB:
|
|
6012
|
-
return StorageType.IDB;
|
|
6013
|
-
case StorageDriver.NODE:
|
|
6014
|
-
return StorageType.NODE;
|
|
6015
|
-
case StorageDriver.WEBFS:
|
|
6016
|
-
return StorageType.WEBFS;
|
|
6017
|
-
default:
|
|
6018
|
-
throw new Error(`Invalid storage type: ${StorageDriver[type]}`);
|
|
6019
|
-
}
|
|
6020
|
-
};
|
|
6021
|
-
|
|
6022
|
-
// packages/sdk/client-services/src/packlets/storage/level.ts
|
|
6023
|
-
import path from "@dxos/node-std/path";
|
|
6024
|
-
import { PublicKey as PublicKey14 } from "@dxos/keys";
|
|
6025
|
-
import { createLevel as createKV } from "@dxos/kv-store";
|
|
6026
|
-
var createLevel = async (config) => {
|
|
6027
|
-
const persistent = isPersistent(config);
|
|
6028
|
-
const storagePath = persistent ? path.join(getRootPath(config), "level") : `/tmp/dxos-${PublicKey14.random().toHex()}`;
|
|
6029
|
-
const level = createKV(storagePath);
|
|
6030
|
-
await level.open();
|
|
6031
|
-
return level;
|
|
6032
|
-
};
|
|
6033
|
-
|
|
6034
6082
|
// packages/sdk/client-services/src/packlets/system/system-service.ts
|
|
6035
6083
|
import { Stream as Stream14 } from "@dxos/codec-protobuf";
|
|
6036
|
-
import { GetDiagnosticsRequest } from "@dxos/protocols/proto/dxos/client/services";
|
|
6037
|
-
import { jsonKeyReplacer } from "@dxos/util";
|
|
6084
|
+
import { GetDiagnosticsRequest as GetDiagnosticsRequest2 } from "@dxos/protocols/proto/dxos/client/services";
|
|
6085
|
+
import { jsonKeyReplacer as jsonKeyReplacer2 } from "@dxos/util";
|
|
6038
6086
|
var SystemServiceImpl = class {
|
|
6039
6087
|
constructor({ config, statusUpdate, getDiagnostics, onUpdateStatus, getCurrentStatus, onReset }) {
|
|
6040
6088
|
this._config = config;
|
|
@@ -6054,9 +6102,9 @@ var SystemServiceImpl = class {
|
|
|
6054
6102
|
const diagnostics = await this._getDiagnostics();
|
|
6055
6103
|
return {
|
|
6056
6104
|
timestamp: /* @__PURE__ */ new Date(),
|
|
6057
|
-
diagnostics: JSON.parse(JSON.stringify(diagnostics,
|
|
6058
|
-
truncate: keys ===
|
|
6059
|
-
humanize: keys ===
|
|
6105
|
+
diagnostics: JSON.parse(JSON.stringify(diagnostics, jsonKeyReplacer2({
|
|
6106
|
+
truncate: keys === GetDiagnosticsRequest2.KEY_OPTION.TRUNCATE,
|
|
6107
|
+
humanize: keys === GetDiagnosticsRequest2.KEY_OPTION.HUMANIZE
|
|
6060
6108
|
})))
|
|
6061
6109
|
};
|
|
6062
6110
|
}
|
|
@@ -6112,7 +6160,7 @@ var ClientServicesHost = class {
|
|
|
6112
6160
|
callbacks,
|
|
6113
6161
|
runtimeParams
|
|
6114
6162
|
} = {}) {
|
|
6115
|
-
this._tracingService =
|
|
6163
|
+
this._tracingService = TRACE_PROCESSOR3.createTraceSender();
|
|
6116
6164
|
this._statusUpdate = new Event9();
|
|
6117
6165
|
this._opening = false;
|
|
6118
6166
|
this._open = false;
|
|
@@ -6238,7 +6286,7 @@ var ClientServicesHost = class {
|
|
|
6238
6286
|
"'network manager already set'"
|
|
6239
6287
|
]
|
|
6240
6288
|
});
|
|
6241
|
-
this._networkManager = new
|
|
6289
|
+
this._networkManager = new SwarmNetworkManager({
|
|
6242
6290
|
log: connectionLog,
|
|
6243
6291
|
transportFactory,
|
|
6244
6292
|
signalManager
|
|
@@ -6254,7 +6302,7 @@ var ClientServicesHost = class {
|
|
|
6254
6302
|
if (this._open) {
|
|
6255
6303
|
return;
|
|
6256
6304
|
}
|
|
6257
|
-
const traceId =
|
|
6305
|
+
const traceId = PublicKey16.random().toHex();
|
|
6258
6306
|
log18.trace("dxos.client-services.host.open", trace10.begin({
|
|
6259
6307
|
id: traceId
|
|
6260
6308
|
}), {
|
|
@@ -6402,7 +6450,7 @@ var ClientServicesHost = class {
|
|
|
6402
6450
|
});
|
|
6403
6451
|
}
|
|
6404
6452
|
async reset() {
|
|
6405
|
-
const traceId =
|
|
6453
|
+
const traceId = PublicKey16.random().toHex();
|
|
6406
6454
|
log18.trace("dxos.sdk.client-services-host.reset", trace10.begin({
|
|
6407
6455
|
id: traceId
|
|
6408
6456
|
}), {
|
|
@@ -6449,11 +6497,11 @@ var ClientServicesHost = class {
|
|
|
6449
6497
|
""
|
|
6450
6498
|
]
|
|
6451
6499
|
});
|
|
6452
|
-
const document =
|
|
6500
|
+
const document = this._serviceContext.echoHost.automergeRepo.find(automergeIndex);
|
|
6453
6501
|
await document.whenReady();
|
|
6454
6502
|
const properties = {
|
|
6455
6503
|
system: {
|
|
6456
|
-
type: encodeReference(getTypeReference(
|
|
6504
|
+
type: encodeReference(getTypeReference(PropertiesType))
|
|
6457
6505
|
},
|
|
6458
6506
|
data: {
|
|
6459
6507
|
[defaultKey]: identity.identityKey.toHex()
|
|
@@ -6462,7 +6510,7 @@ var ClientServicesHost = class {
|
|
|
6462
6510
|
keys: []
|
|
6463
6511
|
}
|
|
6464
6512
|
};
|
|
6465
|
-
const propertiesId =
|
|
6513
|
+
const propertiesId = PublicKey16.random().toHex();
|
|
6466
6514
|
document.change((doc) => {
|
|
6467
6515
|
assignDeep2(doc, [
|
|
6468
6516
|
"objects",
|
|
@@ -6491,47 +6539,6 @@ ClientServicesHost = _ts_decorate8([
|
|
|
6491
6539
|
Trace4.resource()
|
|
6492
6540
|
], ClientServicesHost);
|
|
6493
6541
|
|
|
6494
|
-
// packages/sdk/client-services/src/packlets/services/util.ts
|
|
6495
|
-
import { PublicKey as PublicKey16 } from "@dxos/keys";
|
|
6496
|
-
import { humanize } from "@dxos/util";
|
|
6497
|
-
var ClientServicesProviderResource = Symbol.for("dxos.resource.ClientServices");
|
|
6498
|
-
|
|
6499
|
-
// packages/sdk/client-services/src/packlets/diagnostics/diagnostics-collector.ts
|
|
6500
|
-
var GET_DIAGNOSTICS_RPC_TIMEOUT = 1e4;
|
|
6501
|
-
var DiagnosticsCollector = class {
|
|
6502
|
-
static {
|
|
6503
|
-
this.broadcastSender = createCollectDiagnosticsBroadcastSender();
|
|
6504
|
-
}
|
|
6505
|
-
static async collect(config = findConfigs(), services = findSystemServiceProvider(), options = {}) {
|
|
6506
|
-
const serviceDiagnostics = await services?.services?.SystemService?.getDiagnostics({
|
|
6507
|
-
keys: options.humanize ? GetDiagnosticsRequest2.KEY_OPTION.HUMANIZE : options.truncate ? GetDiagnosticsRequest2.KEY_OPTION.TRUNCATE : void 0
|
|
6508
|
-
}, {
|
|
6509
|
-
timeout: GET_DIAGNOSTICS_RPC_TIMEOUT
|
|
6510
|
-
});
|
|
6511
|
-
const clientDiagnostics = {
|
|
6512
|
-
config,
|
|
6513
|
-
trace: TRACE_PROCESSOR3.getDiagnostics()
|
|
6514
|
-
};
|
|
6515
|
-
const diagnostics = serviceDiagnostics != null ? {
|
|
6516
|
-
client: clientDiagnostics,
|
|
6517
|
-
services: serviceDiagnostics
|
|
6518
|
-
} : {
|
|
6519
|
-
client: clientDiagnostics,
|
|
6520
|
-
broadcast: await this.broadcastSender.broadcastDiagnosticsRequest()
|
|
6521
|
-
};
|
|
6522
|
-
return JSON.parse(JSON.stringify(diagnostics, jsonKeyReplacer2(options)));
|
|
6523
|
-
}
|
|
6524
|
-
};
|
|
6525
|
-
var findSystemServiceProvider = () => {
|
|
6526
|
-
const serviceProviders = TRACE_PROCESSOR3.findResourcesByAnnotation(ClientServicesProviderResource);
|
|
6527
|
-
const providerResource = serviceProviders.find((r) => r.instance.deref()?.services?.SystemService != null);
|
|
6528
|
-
return providerResource?.instance?.deref() ?? null;
|
|
6529
|
-
};
|
|
6530
|
-
var findConfigs = () => {
|
|
6531
|
-
const configs = TRACE_PROCESSOR3.findResourcesByAnnotation(ConfigResource);
|
|
6532
|
-
return configs.map((r) => r.instance.deref()).filter(nonNullable);
|
|
6533
|
-
};
|
|
6534
|
-
|
|
6535
6542
|
export {
|
|
6536
6543
|
Buffer,
|
|
6537
6544
|
subscribeToFeeds,
|
|
@@ -6544,6 +6551,10 @@ export {
|
|
|
6544
6551
|
subscribeToSpaces,
|
|
6545
6552
|
DevtoolsHostEvents,
|
|
6546
6553
|
DevtoolsServiceImpl,
|
|
6554
|
+
createDiagnostics,
|
|
6555
|
+
createCollectDiagnosticsBroadcastSender,
|
|
6556
|
+
createCollectDiagnosticsBroadcastHandler,
|
|
6557
|
+
ClientRpcServer,
|
|
6547
6558
|
createAuthProvider,
|
|
6548
6559
|
TrustedKeySetAuthVerifier,
|
|
6549
6560
|
Identity,
|
|
@@ -6555,22 +6566,18 @@ export {
|
|
|
6555
6566
|
InvitationsServiceImpl,
|
|
6556
6567
|
SpaceInvitationProtocol,
|
|
6557
6568
|
InvitationsManager,
|
|
6558
|
-
ClientRpcServer,
|
|
6559
6569
|
DataSpace,
|
|
6560
6570
|
findPropertiesObject,
|
|
6561
6571
|
DataSpaceManager,
|
|
6562
6572
|
SpacesServiceImpl,
|
|
6563
6573
|
ServiceContext,
|
|
6564
6574
|
ServiceRegistry,
|
|
6565
|
-
createDiagnostics,
|
|
6566
|
-
createCollectDiagnosticsBroadcastSender,
|
|
6567
|
-
createCollectDiagnosticsBroadcastHandler,
|
|
6568
|
-
DiagnosticsCollector,
|
|
6569
6575
|
Lock,
|
|
6570
6576
|
isLocked,
|
|
6571
6577
|
createStorageObjects,
|
|
6572
6578
|
createLevel,
|
|
6573
6579
|
ClientServicesHost,
|
|
6574
|
-
ClientServicesProviderResource
|
|
6580
|
+
ClientServicesProviderResource,
|
|
6581
|
+
DiagnosticsCollector
|
|
6575
6582
|
};
|
|
6576
|
-
//# sourceMappingURL=chunk-
|
|
6583
|
+
//# sourceMappingURL=chunk-5SOW3KZQ.mjs.map
|