@dxos/client-services 0.8.3 → 0.8.4-main.05e74ebcff
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/LICENSE +102 -5
- package/README.md +1 -1
- package/dist/lib/browser/chunk-QCWEHHJW.mjs +24 -0
- package/dist/lib/browser/chunk-QCWEHHJW.mjs.map +7 -0
- package/dist/lib/browser/{chunk-LBG3C332.mjs → chunk-U2YFOK57.mjs} +3848 -5128
- package/dist/lib/browser/chunk-U2YFOK57.mjs.map +7 -0
- package/dist/lib/browser/chunk-XJRPB3GA.mjs +22 -0
- package/dist/lib/browser/chunk-XJRPB3GA.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +454 -148
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/packlets/diagnostics/browser-diagnostics-broadcast.mjs +88 -0
- package/dist/lib/browser/packlets/diagnostics/browser-diagnostics-broadcast.mjs.map +7 -0
- package/dist/lib/browser/packlets/diagnostics/diagnostics-broadcast.mjs +11 -0
- package/dist/lib/browser/packlets/diagnostics/diagnostics-broadcast.mjs.map +7 -0
- package/dist/lib/browser/packlets/locks/browser.mjs +86 -0
- package/dist/lib/browser/packlets/locks/browser.mjs.map +7 -0
- package/dist/lib/browser/packlets/locks/node.mjs +48 -0
- package/dist/lib/browser/packlets/locks/node.mjs.map +7 -0
- package/dist/lib/browser/testing/index.mjs +40 -41
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/chunk-2DT3MZRL.mjs +22 -0
- package/dist/lib/node-esm/chunk-2DT3MZRL.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-2SZHAWBN.mjs +24 -0
- package/dist/lib/node-esm/chunk-2SZHAWBN.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-SKGQLRKS.mjs → chunk-OMK2O7UD.mjs} +3247 -4395
- package/dist/lib/node-esm/chunk-OMK2O7UD.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +454 -148
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/packlets/diagnostics/browser-diagnostics-broadcast.mjs +88 -0
- package/dist/lib/node-esm/packlets/diagnostics/browser-diagnostics-broadcast.mjs.map +7 -0
- package/dist/lib/node-esm/packlets/diagnostics/diagnostics-broadcast.mjs +11 -0
- package/dist/lib/node-esm/packlets/diagnostics/diagnostics-broadcast.mjs.map +7 -0
- package/dist/lib/node-esm/packlets/locks/browser.mjs +86 -0
- package/dist/lib/node-esm/packlets/locks/browser.mjs.map +7 -0
- package/dist/lib/node-esm/packlets/locks/node.mjs +48 -0
- package/dist/lib/node-esm/packlets/locks/node.mjs.map +7 -0
- package/dist/lib/node-esm/testing/index.mjs +40 -41
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/packlets/agents/edge-agent-manager.d.ts +3 -2
- package/dist/types/src/packlets/agents/edge-agent-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/agents/edge-agent-service.d.ts +3 -2
- package/dist/types/src/packlets/agents/edge-agent-service.d.ts.map +1 -1
- package/dist/types/src/packlets/devices/devices-service.d.ts.map +1 -1
- package/dist/types/src/packlets/devtools/devtools.d.ts +20 -20
- package/dist/types/src/packlets/devtools/devtools.d.ts.map +1 -1
- package/dist/types/src/packlets/devtools/feeds.d.ts +1 -1
- package/dist/types/src/packlets/devtools/feeds.d.ts.map +1 -1
- package/dist/types/src/packlets/devtools/keys.d.ts.map +1 -1
- package/dist/types/src/packlets/devtools/metadata.d.ts.map +1 -1
- package/dist/types/src/packlets/devtools/network.d.ts +1 -1
- package/dist/types/src/packlets/devtools/network.d.ts.map +1 -1
- package/dist/types/src/packlets/devtools/spaces.d.ts.map +1 -1
- package/dist/types/src/packlets/diagnostics/browser-diagnostics-broadcast.d.ts +1 -1
- package/dist/types/src/packlets/diagnostics/browser-diagnostics-broadcast.d.ts.map +1 -1
- package/dist/types/src/packlets/diagnostics/diagnostics-broadcast.d.ts +1 -1
- package/dist/types/src/packlets/diagnostics/diagnostics-broadcast.d.ts.map +1 -1
- package/dist/types/src/packlets/diagnostics/diagnostics-collector.d.ts.map +1 -1
- package/dist/types/src/packlets/diagnostics/diagnostics.d.ts +3 -4
- package/dist/types/src/packlets/diagnostics/diagnostics.d.ts.map +1 -1
- package/dist/types/src/packlets/diagnostics/index.d.ts +1 -1
- package/dist/types/src/packlets/diagnostics/index.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/authenticator.d.ts +2 -2
- package/dist/types/src/packlets/identity/authenticator.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/contacts-service.d.ts +1 -1
- package/dist/types/src/packlets/identity/contacts-service.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity-manager.d.ts +7 -7
- package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity-recovery-manager.d.ts +8 -7
- package/dist/types/src/packlets/identity/identity-recovery-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity-service.d.ts +6 -10
- package/dist/types/src/packlets/identity/identity-service.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity.d.ts +9 -12
- package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts +6 -5
- package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/edge-invitation-handler.d.ts +2 -2
- package/dist/types/src/packlets/invitations/edge-invitation-handler.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/index.d.ts +1 -1
- package/dist/types/src/packlets/invitations/index.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitation-guest-extenstion.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitation-host-extension.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitation-protocol.d.ts +8 -5
- package/dist/types/src/packlets/invitations/invitation-protocol.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitation-state.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitation-topology.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitations-handler.d.ts +4 -4
- package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitations-manager.d.ts +3 -3
- package/dist/types/src/packlets/invitations/invitations-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitations-service.d.ts +4 -4
- package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts +5 -4
- package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/utils.d.ts.map +1 -1
- package/dist/types/src/packlets/locks/browser.d.ts.map +1 -1
- package/dist/types/src/packlets/locks/index.d.ts +2 -2
- package/dist/types/src/packlets/locks/index.d.ts.map +1 -1
- package/dist/types/src/packlets/locks/node.d.ts.map +1 -1
- package/dist/types/src/packlets/logging/logging-service.d.ts +5 -1
- package/dist/types/src/packlets/logging/logging-service.d.ts.map +1 -1
- package/dist/types/src/packlets/network/network-service.d.ts +7 -6
- package/dist/types/src/packlets/network/network-service.d.ts.map +1 -1
- package/dist/types/src/packlets/services/client-rpc-server.d.ts +5 -5
- package/dist/types/src/packlets/services/client-rpc-server.d.ts.map +1 -1
- package/dist/types/src/packlets/services/feed-syncer.d.ts +59 -0
- package/dist/types/src/packlets/services/feed-syncer.d.ts.map +1 -0
- package/dist/types/src/packlets/services/feed-syncer.test.d.ts +2 -0
- package/dist/types/src/packlets/services/feed-syncer.test.d.ts.map +1 -0
- package/dist/types/src/packlets/services/platform.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-context.d.ts +14 -10
- package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-host.d.ts +21 -8
- package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-registry.d.ts.map +1 -1
- package/dist/types/src/packlets/services/util.d.ts.map +1 -1
- package/dist/types/src/packlets/space-export/archive-format.d.ts +9 -0
- package/dist/types/src/packlets/space-export/archive-format.d.ts.map +1 -0
- package/dist/types/src/packlets/space-export/index.d.ts +4 -1
- package/dist/types/src/packlets/space-export/index.d.ts.map +1 -1
- package/dist/types/src/packlets/space-export/serialized-space-reader.d.ts +23 -0
- package/dist/types/src/packlets/space-export/serialized-space-reader.d.ts.map +1 -0
- package/dist/types/src/packlets/space-export/serialized-space-writer.d.ts +36 -0
- package/dist/types/src/packlets/space-export/serialized-space-writer.d.ts.map +1 -0
- package/dist/types/src/packlets/space-export/space-archive-reader.d.ts +9 -1
- package/dist/types/src/packlets/space-export/space-archive-reader.d.ts.map +1 -1
- package/dist/types/src/packlets/space-export/space-archive-writer.d.ts +8 -2
- package/dist/types/src/packlets/space-export/space-archive-writer.d.ts.map +1 -1
- package/dist/types/src/packlets/space-export/space-archive.test.d.ts +2 -0
- package/dist/types/src/packlets/space-export/space-archive.test.d.ts.map +1 -0
- package/dist/types/src/packlets/spaces/automerge-space-state.d.ts +1 -1
- package/dist/types/src/packlets/spaces/automerge-space-state.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/data-space-manager.d.ts +31 -20
- package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/data-space.d.ts +30 -13
- package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/edge-feed-replicator.d.ts +2 -2
- package/dist/types/src/packlets/spaces/edge-feed-replicator.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/epoch-migrations.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/genesis.d.ts +2 -1
- package/dist/types/src/packlets/spaces/genesis.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/notarization-plugin.d.ts +6 -9
- package/dist/types/src/packlets/spaces/notarization-plugin.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/spaces-service.d.ts +11 -8
- package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
- package/dist/types/src/packlets/storage/level.d.ts.map +1 -1
- package/dist/types/src/packlets/storage/profile-archive.d.ts.map +1 -1
- package/dist/types/src/packlets/storage/storage.d.ts.map +1 -1
- package/dist/types/src/packlets/storage/util.d.ts.map +1 -1
- package/dist/types/src/packlets/system/system-service.d.ts +2 -2
- package/dist/types/src/packlets/system/system-service.d.ts.map +1 -1
- package/dist/types/src/packlets/testing/credential-utils.d.ts.map +1 -1
- package/dist/types/src/packlets/testing/invitation-utils.d.ts +6 -3
- package/dist/types/src/packlets/testing/invitation-utils.d.ts.map +1 -1
- package/dist/types/src/packlets/testing/test-builder.d.ts +8 -7
- package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
- package/dist/types/src/packlets/worker/worker-runtime.d.ts +41 -4
- package/dist/types/src/packlets/worker/worker-runtime.d.ts.map +1 -1
- package/dist/types/src/packlets/worker/worker-session.d.ts +2 -4
- package/dist/types/src/packlets/worker/worker-session.d.ts.map +1 -1
- package/dist/types/src/testing/setup.d.ts.map +1 -1
- package/dist/types/src/version.d.ts +1 -1
- package/dist/types/src/version.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +73 -56
- package/src/index.ts +1 -0
- package/src/packlets/agents/edge-agent-manager.ts +10 -7
- package/src/packlets/agents/edge-agent-service.ts +17 -5
- package/src/packlets/devices/devices-service.test.ts +3 -3
- package/src/packlets/devices/devices-service.ts +2 -2
- package/src/packlets/devtools/devtools.ts +29 -29
- package/src/packlets/devtools/feeds.ts +2 -2
- package/src/packlets/devtools/network.ts +1 -1
- package/src/packlets/diagnostics/browser-diagnostics-broadcast.ts +1 -1
- package/src/packlets/diagnostics/diagnostics-broadcast.ts +1 -1
- package/src/packlets/diagnostics/diagnostics-collector.ts +1 -1
- package/src/packlets/diagnostics/diagnostics.ts +2 -3
- package/src/packlets/diagnostics/index.ts +1 -1
- package/src/packlets/identity/authenticator.node.test.ts +1 -1
- package/src/packlets/identity/authenticator.ts +3 -3
- package/src/packlets/identity/contacts-service.ts +2 -2
- package/src/packlets/identity/identity-manager.test.ts +8 -8
- package/src/packlets/identity/identity-manager.ts +25 -24
- package/src/packlets/identity/identity-recovery-manager.ts +22 -18
- package/src/packlets/identity/identity-service.test.ts +8 -28
- package/src/packlets/identity/identity-service.ts +13 -80
- package/src/packlets/identity/identity.test.ts +11 -11
- package/src/packlets/identity/identity.ts +17 -39
- package/src/packlets/invitations/device-invitation-protocol.test.ts +4 -4
- package/src/packlets/invitations/device-invitation-protocol.ts +8 -6
- package/src/packlets/invitations/edge-invitation-handler.ts +10 -6
- package/src/packlets/invitations/index.ts +1 -1
- package/src/packlets/invitations/invitation-guest-extenstion.ts +7 -5
- package/src/packlets/invitations/invitation-host-extension.ts +15 -16
- package/src/packlets/invitations/invitation-protocol.ts +8 -5
- package/src/packlets/invitations/invitation-state.ts +1 -15
- package/src/packlets/invitations/invitations-handler.test.ts +301 -292
- package/src/packlets/invitations/invitations-handler.ts +77 -25
- package/src/packlets/invitations/invitations-manager.ts +43 -18
- package/src/packlets/invitations/invitations-service.ts +10 -10
- package/src/packlets/invitations/space-invitation-protocol.test.ts +26 -25
- package/src/packlets/invitations/space-invitation-protocol.ts +13 -17
- package/src/packlets/invitations/utils.ts +1 -1
- package/src/packlets/locks/browser.ts +1 -1
- package/src/packlets/locks/index.ts +2 -2
- package/src/packlets/logging/logging-service.ts +22 -17
- package/src/packlets/logging/logging.test.ts +1 -1
- package/src/packlets/network/network-service.test.ts +3 -3
- package/src/packlets/network/network-service.ts +12 -10
- package/src/packlets/services/client-rpc-server.ts +20 -17
- package/src/packlets/services/feed-syncer.test.ts +340 -0
- package/src/packlets/services/feed-syncer.ts +377 -0
- package/src/packlets/services/platform.ts +7 -1
- package/src/packlets/services/service-context.test.ts +4 -3
- package/src/packlets/services/service-context.ts +160 -67
- package/src/packlets/services/service-host.test.ts +10 -9
- package/src/packlets/services/service-host.ts +88 -49
- package/src/packlets/services/service-registry.test.ts +1 -1
- package/src/packlets/space-export/archive-format.ts +42 -0
- package/src/packlets/space-export/index.ts +4 -1
- package/src/packlets/space-export/serialized-space-reader.ts +111 -0
- package/src/packlets/space-export/serialized-space-writer.ts +252 -0
- package/src/packlets/space-export/space-archive-reader.ts +65 -4
- package/src/packlets/space-export/space-archive-writer.ts +44 -6
- package/src/packlets/space-export/space-archive.test.ts +461 -0
- package/src/packlets/space-export/tar.test.ts +1 -1
- package/src/packlets/spaces/automerge-space-state.ts +1 -1
- package/src/packlets/spaces/data-space-manager.test.ts +79 -13
- package/src/packlets/spaces/data-space-manager.ts +134 -129
- package/src/packlets/spaces/data-space.ts +71 -42
- package/src/packlets/spaces/edge-feed-replicator.test.ts +4 -4
- package/src/packlets/spaces/edge-feed-replicator.ts +13 -11
- package/src/packlets/spaces/epoch-migrations.ts +6 -5
- package/src/packlets/spaces/genesis.ts +6 -1
- package/src/packlets/spaces/notarization-plugin.test.ts +3 -3
- package/src/packlets/spaces/notarization-plugin.ts +13 -12
- package/src/packlets/spaces/spaces-service.test.ts +20 -12
- package/src/packlets/spaces/spaces-service.ts +140 -38
- package/src/packlets/storage/profile-archive.ts +1 -1
- package/src/packlets/storage/storage.ts +7 -8
- package/src/packlets/system/system-service.test.ts +1 -1
- package/src/packlets/system/system-service.ts +4 -4
- package/src/packlets/testing/invitation-utils.ts +11 -7
- package/src/packlets/testing/test-builder.ts +39 -13
- package/src/packlets/worker/worker-runtime.ts +189 -17
- package/src/packlets/worker/worker-session.ts +15 -21
- package/src/version.ts +1 -5
- package/README.yml +0 -5
- package/dist/lib/browser/chunk-LBG3C332.mjs.map +0 -7
- package/dist/lib/node/chunk-LMGLGOUU.cjs +0 -9311
- package/dist/lib/node/chunk-LMGLGOUU.cjs.map +0 -7
- package/dist/lib/node/index.cjs +0 -437
- package/dist/lib/node/index.cjs.map +0 -7
- package/dist/lib/node/meta.json +0 -1
- package/dist/lib/node/testing/index.cjs +0 -452
- package/dist/lib/node/testing/index.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-SKGQLRKS.mjs.map +0 -7
- package/dist/types/src/packlets/identity/default-space-state-machine.d.ts +0 -19
- package/dist/types/src/packlets/identity/default-space-state-machine.d.ts.map +0 -1
- package/src/packlets/identity/default-space-state-machine.ts +0 -44
|
@@ -14,12 +14,18 @@ export const getPlatform = (): Platform => {
|
|
|
14
14
|
userAgent,
|
|
15
15
|
uptime: Math.floor((Date.now() - window.performance.timeOrigin) / 1_000),
|
|
16
16
|
};
|
|
17
|
-
} else {
|
|
17
|
+
} else if (typeof SharedWorkerGlobalScope !== 'undefined') {
|
|
18
18
|
// Shared worker.
|
|
19
19
|
return {
|
|
20
20
|
type: Platform.PLATFORM_TYPE.SHARED_WORKER,
|
|
21
21
|
uptime: Math.floor((Date.now() - performance.timeOrigin) / 1_000),
|
|
22
22
|
};
|
|
23
|
+
} else {
|
|
24
|
+
// Dedicated worker.
|
|
25
|
+
return {
|
|
26
|
+
type: Platform.PLATFORM_TYPE.DEDICATED_WORKER,
|
|
27
|
+
uptime: Math.floor((Date.now() - performance.timeOrigin) / 1_000),
|
|
28
|
+
};
|
|
23
29
|
}
|
|
24
30
|
} else {
|
|
25
31
|
// Node.
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
import { describe, test } from 'vitest';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { Context } from '@dxos/context';
|
|
8
|
+
import { MemorySignalManager, MemorySignalManagerContext } from '@dxos/messaging';
|
|
8
9
|
import { Invitation } from '@dxos/protocols/proto/dxos/client/services';
|
|
9
10
|
import { openAndClose } from '@dxos/test-utils';
|
|
10
11
|
|
|
@@ -19,7 +20,7 @@ describe('services/ServiceContext', () => {
|
|
|
19
20
|
const device2 = await createOpenServiceContext(networkContext);
|
|
20
21
|
await Promise.all(performInvitation({ host: device1, guest: device2, options: { kind: Invitation.Kind.DEVICE } }));
|
|
21
22
|
|
|
22
|
-
const space1 = await device1.dataSpaceManager!.createSpace();
|
|
23
|
+
const space1 = await device1.dataSpaceManager!.createSpace(new Context());
|
|
23
24
|
await device2.dataSpaceManager!.waitUntilSpaceReady(space1!.key);
|
|
24
25
|
const space2 = await device2.dataSpaceManager!.spaces.get(space1.key);
|
|
25
26
|
await space2!.inner.controlPipeline.state.waitUntilTimeframe(space1.inner.controlPipeline.state.timeframe);
|
|
@@ -35,7 +36,7 @@ describe('services/ServiceContext', () => {
|
|
|
35
36
|
|
|
36
37
|
const identity2 = await createOpenServiceContext(networkContext);
|
|
37
38
|
await identity2.createIdentity();
|
|
38
|
-
const space1 = await identity2.dataSpaceManager!.createSpace();
|
|
39
|
+
const space1 = await identity2.dataSpaceManager!.createSpace(new Context());
|
|
39
40
|
await Promise.all(
|
|
40
41
|
performInvitation({
|
|
41
42
|
host: identity2,
|
|
@@ -2,62 +2,71 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import type * as SqlClient from '@effect/sql/SqlClient';
|
|
6
|
+
|
|
5
7
|
import { Mutex, Trigger } from '@dxos/async';
|
|
6
8
|
import { Context, Resource } from '@dxos/context';
|
|
7
|
-
import {
|
|
9
|
+
import { type CredentialProcessor, getCredentialAssertion } from '@dxos/credentials';
|
|
8
10
|
import { failUndefined, warnAfterTimeout } from '@dxos/debug';
|
|
9
11
|
import {
|
|
10
12
|
EchoEdgeReplicator,
|
|
13
|
+
EchoEdgeSubductionReplicator,
|
|
11
14
|
EchoHost,
|
|
15
|
+
type EdgeAutomergeReplicator,
|
|
12
16
|
MeshEchoReplicator,
|
|
13
17
|
MetadataStore,
|
|
14
18
|
SpaceManager,
|
|
15
19
|
valueEncoding,
|
|
16
20
|
} from '@dxos/echo-pipeline';
|
|
17
21
|
import { createChainEdgeIdentity, createEphemeralEdgeIdentity } from '@dxos/edge-client';
|
|
18
|
-
import type {
|
|
22
|
+
import type { EdgeConnection, EdgeHttpClient, EdgeIdentity } from '@dxos/edge-client';
|
|
23
|
+
import { type RuntimeProvider } from '@dxos/effect';
|
|
19
24
|
import { FeedFactory, FeedStore } from '@dxos/feed-store';
|
|
20
25
|
import { invariant } from '@dxos/invariant';
|
|
21
26
|
import { Keyring } from '@dxos/keyring';
|
|
22
|
-
import {
|
|
27
|
+
import { type SpaceId } from '@dxos/keys';
|
|
23
28
|
import { type LevelDB } from '@dxos/kv-store';
|
|
24
29
|
import { log } from '@dxos/log';
|
|
25
30
|
import { type SignalManager } from '@dxos/messaging';
|
|
26
31
|
import { type SwarmNetworkManager } from '@dxos/network-manager';
|
|
27
|
-
import { InvalidStorageVersionError, STORAGE_VERSION
|
|
32
|
+
import { InvalidStorageVersionError, STORAGE_VERSION } from '@dxos/protocols';
|
|
33
|
+
import { FeedProtocol } from '@dxos/protocols';
|
|
28
34
|
import { Invitation } from '@dxos/protocols/proto/dxos/client/services';
|
|
29
35
|
import { type Runtime } from '@dxos/protocols/proto/dxos/config';
|
|
30
36
|
import type { FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';
|
|
31
37
|
import { type Credential, type ProfileDocument } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
32
38
|
import { type Storage } from '@dxos/random-access-storage';
|
|
39
|
+
import type * as SqlTransaction from '@dxos/sql-sqlite/SqlTransaction';
|
|
33
40
|
import { BlobStore } from '@dxos/teleport-extension-object-sync';
|
|
34
41
|
import { trace as Trace } from '@dxos/tracing';
|
|
35
42
|
import { safeInstanceof } from '@dxos/util';
|
|
36
43
|
|
|
37
44
|
import { EdgeAgentManager } from '../agents';
|
|
38
45
|
import {
|
|
39
|
-
IdentityManager,
|
|
40
46
|
type CreateIdentityOptions,
|
|
41
|
-
type
|
|
42
|
-
|
|
47
|
+
type Identity,
|
|
48
|
+
IdentityManager,
|
|
49
|
+
type IdentityManagerProps,
|
|
50
|
+
type JoinIdentityProps,
|
|
43
51
|
} from '../identity';
|
|
44
52
|
import { EdgeIdentityRecoveryManager } from '../identity/identity-recovery-manager';
|
|
45
53
|
import {
|
|
46
54
|
DeviceInvitationProtocol,
|
|
47
|
-
type
|
|
55
|
+
type InvitationConnectionProps,
|
|
56
|
+
type InvitationProtocol,
|
|
48
57
|
InvitationsHandler,
|
|
49
58
|
InvitationsManager,
|
|
50
59
|
SpaceInvitationProtocol,
|
|
51
|
-
type InvitationProtocol,
|
|
52
60
|
} from '../invitations';
|
|
53
|
-
import { DataSpaceManager, type
|
|
61
|
+
import { DataSpaceManager, type DataSpaceManagerRuntimeProps, type SigningContext } from '../spaces';
|
|
62
|
+
import { FeedSyncer } from './feed-syncer';
|
|
54
63
|
|
|
55
|
-
export type
|
|
56
|
-
|
|
64
|
+
export type ServiceContextRuntimeProps = Pick<
|
|
65
|
+
IdentityManagerProps,
|
|
57
66
|
'devicePresenceOfflineTimeout' | 'devicePresenceAnnounceInterval'
|
|
58
67
|
> &
|
|
59
|
-
|
|
60
|
-
|
|
68
|
+
DataSpaceManagerRuntimeProps & {
|
|
69
|
+
invitationConnectionDefaultProps?: InvitationConnectionProps;
|
|
61
70
|
disableP2pReplication?: boolean;
|
|
62
71
|
enableVectorIndexing?: boolean;
|
|
63
72
|
};
|
|
@@ -67,7 +76,7 @@ export type ServiceContextRuntimeParams = Pick<
|
|
|
67
76
|
// TODO(burdon): Rename/break-up into smaller components. And/or make members private.
|
|
68
77
|
// TODO(dmaretskyi): Gets duplicated in CJS build between normal and testing bundles.
|
|
69
78
|
@safeInstanceof('dxos.client-services.ServiceContext')
|
|
70
|
-
@Trace.resource()
|
|
79
|
+
@Trace.resource({ lifecycle: true })
|
|
71
80
|
export class ServiceContext extends Resource {
|
|
72
81
|
private readonly _edgeIdentityUpdateMutex = new Mutex();
|
|
73
82
|
|
|
@@ -83,7 +92,8 @@ export class ServiceContext extends Resource {
|
|
|
83
92
|
public readonly invitationsManager: InvitationsManager;
|
|
84
93
|
public readonly echoHost: EchoHost;
|
|
85
94
|
private readonly _meshReplicator?: MeshEchoReplicator = undefined;
|
|
86
|
-
private readonly _echoEdgeReplicator?:
|
|
95
|
+
private readonly _echoEdgeReplicator?: EdgeAutomergeReplicator = undefined;
|
|
96
|
+
private readonly _feedSyncer?: FeedSyncer = undefined;
|
|
87
97
|
|
|
88
98
|
// Initialized after identity is initialized.
|
|
89
99
|
public dataSpaceManager?: DataSpaceManager;
|
|
@@ -96,8 +106,6 @@ export class ServiceContext extends Resource {
|
|
|
96
106
|
|
|
97
107
|
private _deviceSpaceSync?: CredentialProcessor;
|
|
98
108
|
|
|
99
|
-
private readonly _instanceId = PublicKey.random().toHex();
|
|
100
|
-
|
|
101
109
|
constructor(
|
|
102
110
|
public readonly storage: Storage,
|
|
103
111
|
public readonly level: LevelDB,
|
|
@@ -105,11 +113,15 @@ export class ServiceContext extends Resource {
|
|
|
105
113
|
public readonly signalManager: SignalManager,
|
|
106
114
|
private readonly _edgeConnection: EdgeConnection | undefined,
|
|
107
115
|
private readonly _edgeHttpClient: EdgeHttpClient | undefined,
|
|
108
|
-
|
|
116
|
+
private readonly _runtime: RuntimeProvider.RuntimeProvider<SqlClient.SqlClient | SqlTransaction.SqlTransaction>,
|
|
117
|
+
public readonly _runtimeProps?: ServiceContextRuntimeProps,
|
|
109
118
|
private readonly _edgeFeatures?: Runtime.Client.EdgeFeatures,
|
|
110
119
|
) {
|
|
111
120
|
super();
|
|
112
121
|
|
|
122
|
+
log('runtimeProps', this._runtimeProps);
|
|
123
|
+
log('edgeFeatures', this._edgeFeatures);
|
|
124
|
+
|
|
113
125
|
// TODO(burdon): Move strings to constants.
|
|
114
126
|
this.metadataStore = new MetadataStore(storage.createDirectory('metadata'));
|
|
115
127
|
this.blobStore = new BlobStore(storage.createDirectory('blobs'));
|
|
@@ -131,7 +143,7 @@ export class ServiceContext extends Resource {
|
|
|
131
143
|
networkManager: this.networkManager,
|
|
132
144
|
blobStore: this.blobStore,
|
|
133
145
|
metadataStore: this.metadataStore,
|
|
134
|
-
disableP2pReplication: this.
|
|
146
|
+
disableP2pReplication: this._runtimeProps?.disableP2pReplication,
|
|
135
147
|
});
|
|
136
148
|
|
|
137
149
|
this.identityManager = new IdentityManager({
|
|
@@ -139,8 +151,8 @@ export class ServiceContext extends Resource {
|
|
|
139
151
|
keyring: this.keyring,
|
|
140
152
|
feedStore: this.feedStore,
|
|
141
153
|
spaceManager: this.spaceManager,
|
|
142
|
-
devicePresenceOfflineTimeout: this.
|
|
143
|
-
devicePresenceAnnounceInterval: this.
|
|
154
|
+
devicePresenceOfflineTimeout: this._runtimeProps?.devicePresenceOfflineTimeout,
|
|
155
|
+
devicePresenceAnnounceInterval: this._runtimeProps?.devicePresenceAnnounceInterval,
|
|
144
156
|
edgeConnection: this._edgeConnection,
|
|
145
157
|
edgeFeatures: this._edgeFeatures,
|
|
146
158
|
});
|
|
@@ -156,17 +168,22 @@ export class ServiceContext extends Resource {
|
|
|
156
168
|
kv: this.level,
|
|
157
169
|
peerIdProvider: () => this.identityManager.identity?.deviceKey?.toHex(),
|
|
158
170
|
getSpaceKeyByRootDocumentId: (documentId) => this.spaceManager.findSpaceByRootDocumentId(documentId)?.key,
|
|
159
|
-
|
|
160
|
-
|
|
171
|
+
runtime: this._runtime,
|
|
172
|
+
useSubduction: this._edgeFeatures?.subductionReplicator,
|
|
173
|
+
syncQueue: async (ctx, request) => {
|
|
174
|
+
return this._feedSyncer?.syncBlocking(ctx, {
|
|
175
|
+
spaceId: request.spaceId as SpaceId,
|
|
176
|
+
subspaceTag: request.subspaceTag,
|
|
177
|
+
shouldPush: request.shouldPush,
|
|
178
|
+
shouldPull: request.shouldPull,
|
|
179
|
+
});
|
|
161
180
|
},
|
|
162
181
|
});
|
|
163
182
|
|
|
164
|
-
this._meshReplicator = new MeshEchoReplicator();
|
|
165
|
-
|
|
166
183
|
this.invitations = new InvitationsHandler(
|
|
167
184
|
this.networkManager, //
|
|
168
185
|
this._edgeHttpClient,
|
|
169
|
-
|
|
186
|
+
_runtimeProps?.invitationConnectionDefaultProps,
|
|
170
187
|
);
|
|
171
188
|
this.invitationsManager = new InvitationsManager(
|
|
172
189
|
this.invitations,
|
|
@@ -186,80 +203,136 @@ export class ServiceContext extends Resource {
|
|
|
186
203
|
),
|
|
187
204
|
);
|
|
188
205
|
|
|
189
|
-
if (!this.
|
|
206
|
+
if (!this._runtimeProps?.disableP2pReplication) {
|
|
190
207
|
this._meshReplicator = new MeshEchoReplicator();
|
|
191
208
|
}
|
|
192
|
-
if (this._edgeConnection && this.
|
|
193
|
-
this.
|
|
194
|
-
|
|
209
|
+
if (this._edgeConnection && this._edgeHttpClient) {
|
|
210
|
+
if (this._edgeFeatures?.subductionReplicator) {
|
|
211
|
+
this._echoEdgeReplicator = new EchoEdgeSubductionReplicator({
|
|
212
|
+
edgeConnection: this._edgeConnection,
|
|
213
|
+
edgeHttpClient: this._edgeHttpClient,
|
|
214
|
+
});
|
|
215
|
+
} else if (this._edgeFeatures?.echoReplicator) {
|
|
216
|
+
this._echoEdgeReplicator = new EchoEdgeReplicator({
|
|
217
|
+
edgeConnection: this._edgeConnection,
|
|
218
|
+
edgeHttpClient: this._edgeHttpClient,
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (this.echoHost.feedStore && this._edgeConnection) {
|
|
224
|
+
this._feedSyncer = new FeedSyncer({
|
|
225
|
+
runtime: this._runtime,
|
|
226
|
+
feedStore: this.echoHost.feedStore,
|
|
227
|
+
edgeClient: this._edgeConnection,
|
|
228
|
+
peerId: this.identityManager.identity?.deviceKey?.toHex() ?? '',
|
|
229
|
+
getSpaceIds: () => this.echoHost!.spaceIds,
|
|
230
|
+
syncNamespaces: [FeedProtocol.WellKnownNamespaces.data, FeedProtocol.WellKnownNamespaces.trace],
|
|
195
231
|
});
|
|
196
232
|
}
|
|
197
233
|
}
|
|
198
234
|
|
|
199
|
-
@Trace.span()
|
|
235
|
+
@Trace.span({ op: 'lifecycle' })
|
|
200
236
|
protected override async _open(ctx: Context): Promise<void> {
|
|
201
237
|
await this._checkStorageVersion();
|
|
202
238
|
|
|
203
239
|
log('opening...');
|
|
204
|
-
log.trace('dxos.sdk.service-context.open', trace.begin({ id: this._instanceId }));
|
|
205
240
|
|
|
241
|
+
log('opening identityManager...');
|
|
206
242
|
await this.identityManager.open(ctx);
|
|
243
|
+
log('identityManager opened', { hasIdentity: !!this.identityManager.identity });
|
|
207
244
|
|
|
208
|
-
|
|
245
|
+
log('setting network identity...');
|
|
246
|
+
await this._setNetworkIdentity({ identity: this.identityManager.identity });
|
|
247
|
+
log('network identity set');
|
|
209
248
|
|
|
210
|
-
|
|
211
|
-
await this.
|
|
249
|
+
log('opening edge connection...');
|
|
250
|
+
await this._edgeConnection?.open(ctx);
|
|
251
|
+
log('edge connection opened');
|
|
252
|
+
|
|
253
|
+
log('opening signal manager...');
|
|
254
|
+
await this.signalManager.open(ctx);
|
|
255
|
+
log('signal manager opened');
|
|
256
|
+
|
|
257
|
+
log('opening network manager...');
|
|
212
258
|
await this.networkManager.open();
|
|
259
|
+
log('network manager opened');
|
|
213
260
|
|
|
261
|
+
log('opening echo host...');
|
|
214
262
|
await this.echoHost.open(ctx);
|
|
263
|
+
log('echo host opened');
|
|
215
264
|
|
|
216
265
|
if (this._meshReplicator) {
|
|
217
|
-
|
|
266
|
+
log('adding mesh replicator...');
|
|
267
|
+
await this.echoHost.addReplicator(ctx, this._meshReplicator);
|
|
268
|
+
log('mesh replicator added');
|
|
218
269
|
}
|
|
219
270
|
if (this._echoEdgeReplicator) {
|
|
220
|
-
|
|
271
|
+
log('adding edge replicator...');
|
|
272
|
+
await this.echoHost.addReplicator(ctx, this._echoEdgeReplicator);
|
|
273
|
+
log('edge replicator added');
|
|
221
274
|
}
|
|
222
275
|
|
|
276
|
+
log('loading metadata store...');
|
|
223
277
|
await this.metadataStore.load();
|
|
278
|
+
log('metadata store loaded');
|
|
279
|
+
|
|
280
|
+
log('opening space manager...');
|
|
224
281
|
await this.spaceManager.open();
|
|
282
|
+
log('space manager opened');
|
|
225
283
|
|
|
226
284
|
if (this.identityManager.identity) {
|
|
227
|
-
|
|
285
|
+
log('joining network...');
|
|
286
|
+
await this.identityManager.identity.joinNetwork(ctx);
|
|
287
|
+
log('network joined');
|
|
288
|
+
|
|
289
|
+
log('initializing spaces...(calling _initialize)');
|
|
228
290
|
await this._initialize(ctx);
|
|
291
|
+
log('spaces initialized');
|
|
292
|
+
} else {
|
|
293
|
+
log('no identity, skipping network join and space initialization');
|
|
229
294
|
}
|
|
230
295
|
|
|
231
|
-
|
|
296
|
+
log('opening feed syncer...');
|
|
297
|
+
await this._feedSyncer?.open(ctx);
|
|
298
|
+
log('feed syncer opened');
|
|
299
|
+
|
|
300
|
+
log('loading persistent invitations...');
|
|
301
|
+
const loadedInvitations = await this.invitationsManager.loadPersistentInvitations(ctx);
|
|
232
302
|
log('loaded persistent invitations', { count: loadedInvitations.invitations?.length });
|
|
233
303
|
|
|
234
|
-
log.trace('dxos.sdk.service-context.open', trace.end({ id: this._instanceId }));
|
|
235
304
|
log('opened');
|
|
236
305
|
}
|
|
237
306
|
|
|
238
307
|
protected override async _close(ctx: Context): Promise<void> {
|
|
239
308
|
log('closing...');
|
|
309
|
+
|
|
310
|
+
await this._feedSyncer?.close();
|
|
311
|
+
|
|
240
312
|
if (this._deviceSpaceSync && this.identityManager.identity) {
|
|
241
313
|
await this.identityManager.identity.space.spaceState.removeCredentialProcessor(this._deviceSpaceSync);
|
|
242
314
|
}
|
|
243
|
-
await this.dataSpaceManager?.close();
|
|
315
|
+
await this.dataSpaceManager?.close(ctx);
|
|
244
316
|
await this.edgeAgentManager?.close();
|
|
245
|
-
await this.identityManager.close();
|
|
317
|
+
await this.identityManager.close(ctx);
|
|
246
318
|
await this.spaceManager.close();
|
|
247
|
-
await this.feedStore.close();
|
|
248
|
-
await this.metadataStore.close();
|
|
249
|
-
|
|
250
319
|
await this.echoHost.close(ctx);
|
|
251
|
-
|
|
320
|
+
|
|
321
|
+
await this.networkManager.close(ctx);
|
|
252
322
|
await this.signalManager.close();
|
|
253
323
|
await this._edgeConnection?.close();
|
|
324
|
+
await this.feedStore.close();
|
|
325
|
+
await this.metadataStore.close();
|
|
254
326
|
|
|
255
327
|
log('closed');
|
|
256
328
|
}
|
|
257
329
|
|
|
258
|
-
async createIdentity(params: CreateIdentityOptions = {}) {
|
|
259
|
-
|
|
260
|
-
await this.
|
|
261
|
-
await
|
|
262
|
-
await
|
|
330
|
+
async createIdentity(params: CreateIdentityOptions = {}, ctx?: Context) {
|
|
331
|
+
ctx ??= this._ctx;
|
|
332
|
+
const identity = await this.identityManager.createIdentity(params, ctx);
|
|
333
|
+
await this._setNetworkIdentity({ identity });
|
|
334
|
+
await identity.joinNetwork(ctx);
|
|
335
|
+
await this._initialize(ctx);
|
|
263
336
|
return identity;
|
|
264
337
|
}
|
|
265
338
|
|
|
@@ -282,12 +355,12 @@ export class ServiceContext extends Resource {
|
|
|
282
355
|
}
|
|
283
356
|
}
|
|
284
357
|
|
|
285
|
-
private async _acceptIdentity(params:
|
|
286
|
-
const { identity, identityRecord } = await this.identityManager.prepareIdentity(params);
|
|
287
|
-
await this._setNetworkIdentity({ deviceCredential: params.authorizedDeviceCredential
|
|
288
|
-
await identity.joinNetwork();
|
|
358
|
+
private async _acceptIdentity(params: JoinIdentityProps) {
|
|
359
|
+
const { identity, identityRecord } = await this.identityManager.prepareIdentity(params, this._ctx);
|
|
360
|
+
await this._setNetworkIdentity({ deviceCredential: params.authorizedDeviceCredential!, identity });
|
|
361
|
+
await identity.joinNetwork(this._ctx);
|
|
289
362
|
await this.identityManager.acceptIdentity(identity, identityRecord, params.deviceProfile);
|
|
290
|
-
await this._initialize(
|
|
363
|
+
await this._initialize(this._ctx);
|
|
291
364
|
return identity;
|
|
292
365
|
}
|
|
293
366
|
|
|
@@ -302,7 +375,7 @@ export class ServiceContext extends Resource {
|
|
|
302
375
|
// Called when identity is created.
|
|
303
376
|
@Trace.span()
|
|
304
377
|
private async _initialize(ctx: Context): Promise<void> {
|
|
305
|
-
log('
|
|
378
|
+
log('_initialize: start');
|
|
306
379
|
const identity = this.identityManager.identity ?? failUndefined();
|
|
307
380
|
const signingContext: SigningContext = {
|
|
308
381
|
credentialSigner: identity.getIdentityCredentialSigner(),
|
|
@@ -314,6 +387,7 @@ export class ServiceContext extends Resource {
|
|
|
314
387
|
},
|
|
315
388
|
};
|
|
316
389
|
|
|
390
|
+
log('_initialize: creating DataSpaceManager');
|
|
317
391
|
this.dataSpaceManager = new DataSpaceManager({
|
|
318
392
|
spaceManager: this.spaceManager,
|
|
319
393
|
metadataStore: this.metadataStore,
|
|
@@ -326,10 +400,12 @@ export class ServiceContext extends Resource {
|
|
|
326
400
|
edgeHttpClient: this._edgeHttpClient,
|
|
327
401
|
echoEdgeReplicator: this._echoEdgeReplicator,
|
|
328
402
|
meshReplicator: this._meshReplicator,
|
|
329
|
-
|
|
403
|
+
runtimeProps: this._runtimeProps as DataSpaceManagerRuntimeProps,
|
|
330
404
|
edgeFeatures: this._edgeFeatures,
|
|
331
405
|
});
|
|
332
|
-
|
|
406
|
+
log('_initialize: opening DataSpaceManager...');
|
|
407
|
+
await this.dataSpaceManager.open(ctx);
|
|
408
|
+
log('_initialize: DataSpaceManager opened');
|
|
333
409
|
|
|
334
410
|
this.edgeAgentManager = new EdgeAgentManager(
|
|
335
411
|
this._edgeFeatures,
|
|
@@ -337,13 +413,16 @@ export class ServiceContext extends Resource {
|
|
|
337
413
|
this.dataSpaceManager,
|
|
338
414
|
identity,
|
|
339
415
|
);
|
|
340
|
-
|
|
416
|
+
log('_initialize: opening EdgeAgentManager...');
|
|
417
|
+
await this.edgeAgentManager.open(ctx);
|
|
418
|
+
log('_initialize: EdgeAgentManager opened');
|
|
341
419
|
|
|
342
420
|
this._handlerFactories.set(Invitation.Kind.SPACE, (invitation) => {
|
|
343
421
|
invariant(this.dataSpaceManager, 'dataSpaceManager not initialized yet');
|
|
344
422
|
return new SpaceInvitationProtocol(this.dataSpaceManager, signingContext, this.keyring, invitation.spaceKey);
|
|
345
423
|
});
|
|
346
424
|
this.initialized.wake();
|
|
425
|
+
log('_initialize: initialized.wake() called');
|
|
347
426
|
|
|
348
427
|
this._deviceSpaceSync = {
|
|
349
428
|
processCredential: async (credential: Credential) => {
|
|
@@ -366,9 +445,10 @@ export class ServiceContext extends Resource {
|
|
|
366
445
|
|
|
367
446
|
try {
|
|
368
447
|
log('accepting space recorded in halo', { details: assertion });
|
|
369
|
-
await this.dataSpaceManager.acceptSpace({
|
|
448
|
+
await this.dataSpaceManager.acceptSpace(this._ctx, {
|
|
370
449
|
spaceKey: assertion.spaceKey,
|
|
371
450
|
genesisFeedKey: assertion.genesisFeedKey,
|
|
451
|
+
tags: assertion.tags,
|
|
372
452
|
});
|
|
373
453
|
} catch (err) {
|
|
374
454
|
log.catch(err);
|
|
@@ -379,33 +459,42 @@ export class ServiceContext extends Resource {
|
|
|
379
459
|
await identity.space.spaceState.addCredentialProcessor(this._deviceSpaceSync);
|
|
380
460
|
}
|
|
381
461
|
|
|
382
|
-
private async _setNetworkIdentity(params?: { deviceCredential
|
|
462
|
+
private async _setNetworkIdentity(params?: { deviceCredential?: Credential; identity?: Identity }): Promise<void> {
|
|
463
|
+
log('_setNetworkIdentity: acquiring mutex...');
|
|
383
464
|
using _ = await this._edgeIdentityUpdateMutex.acquire();
|
|
465
|
+
log('_setNetworkIdentity: mutex acquired');
|
|
384
466
|
|
|
385
467
|
let edgeIdentity: EdgeIdentity;
|
|
386
|
-
const identity =
|
|
468
|
+
const identity = params?.identity;
|
|
387
469
|
if (identity) {
|
|
388
|
-
log('
|
|
470
|
+
log('_setNetworkIdentity: has identity', {
|
|
389
471
|
identity: identity.identityKey.toHex(),
|
|
390
|
-
|
|
472
|
+
hasDeviceCredential: !!params?.deviceCredential,
|
|
391
473
|
});
|
|
392
474
|
|
|
393
475
|
if (params?.deviceCredential) {
|
|
476
|
+
log('_setNetworkIdentity: creating chain edge identity with device credential...');
|
|
394
477
|
edgeIdentity = await createChainEdgeIdentity(
|
|
395
478
|
identity.signer,
|
|
396
479
|
identity.identityKey,
|
|
397
480
|
identity.deviceKey,
|
|
398
|
-
|
|
481
|
+
{ credential: params.deviceCredential },
|
|
399
482
|
[], // TODO(dmaretskyi): Service access credentials.
|
|
400
483
|
);
|
|
484
|
+
log('_setNetworkIdentity: chain edge identity created');
|
|
401
485
|
} else {
|
|
486
|
+
log('_setNetworkIdentity: waiting for identity.ready()...');
|
|
402
487
|
// TODO: throw here or from identity if device chain can't be loaded, to avoid indefinite hangup
|
|
403
488
|
await warnAfterTimeout(10_000, 'Waiting for identity to be ready for edge connection', async () => {
|
|
404
489
|
await identity.ready();
|
|
405
490
|
});
|
|
491
|
+
log('_setNetworkIdentity: identity.ready() resolved', {
|
|
492
|
+
hasDeviceCredentialChain: !!identity.deviceCredentialChain,
|
|
493
|
+
});
|
|
406
494
|
|
|
407
495
|
invariant(identity.deviceCredentialChain);
|
|
408
496
|
|
|
497
|
+
log('_setNetworkIdentity: creating chain edge identity...');
|
|
409
498
|
edgeIdentity = await createChainEdgeIdentity(
|
|
410
499
|
identity.signer,
|
|
411
500
|
identity.identityKey,
|
|
@@ -413,9 +502,12 @@ export class ServiceContext extends Resource {
|
|
|
413
502
|
identity.deviceCredentialChain,
|
|
414
503
|
[], // TODO(dmaretskyi): Service access credentials.
|
|
415
504
|
);
|
|
505
|
+
log('_setNetworkIdentity: chain edge identity created');
|
|
416
506
|
}
|
|
417
507
|
} else {
|
|
508
|
+
log('_setNetworkIdentity: no identity, creating ephemeral edge identity...');
|
|
418
509
|
edgeIdentity = await createEphemeralEdgeIdentity();
|
|
510
|
+
log('_setNetworkIdentity: ephemeral edge identity created');
|
|
419
511
|
}
|
|
420
512
|
|
|
421
513
|
this._edgeConnection?.setIdentity(edgeIdentity);
|
|
@@ -424,5 +516,6 @@ export class ServiceContext extends Resource {
|
|
|
424
516
|
identityKey: edgeIdentity.identityKey,
|
|
425
517
|
peerKey: edgeIdentity.peerKey,
|
|
426
518
|
});
|
|
519
|
+
log('_setNetworkIdentity: done');
|
|
427
520
|
}
|
|
428
521
|
}
|
|
@@ -3,15 +3,16 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { rmSync } from 'node:fs';
|
|
6
|
-
import { afterEach,
|
|
6
|
+
import { afterEach, describe, expect, onTestFinished, test } from 'vitest';
|
|
7
7
|
|
|
8
|
-
import { asyncTimeout, latch
|
|
8
|
+
import { Trigger, asyncTimeout, latch } from '@dxos/async';
|
|
9
9
|
import { Config } from '@dxos/config';
|
|
10
10
|
import { Context } from '@dxos/context';
|
|
11
11
|
import { verifyPresentation } from '@dxos/credentials';
|
|
12
12
|
import { type PublicKey } from '@dxos/keys';
|
|
13
13
|
import { MemorySignalManagerContext } from '@dxos/messaging';
|
|
14
14
|
import { type Identity } from '@dxos/protocols/proto/dxos/client/services';
|
|
15
|
+
import { MembershipPolicy } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
15
16
|
import { type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
16
17
|
import { isNode } from '@dxos/util';
|
|
17
18
|
|
|
@@ -28,16 +29,16 @@ describe('ClientServicesHost', () => {
|
|
|
28
29
|
test('open and close', async () => {
|
|
29
30
|
const host = createServiceHost(new Config(), new MemorySignalManagerContext());
|
|
30
31
|
await host.open(new Context());
|
|
31
|
-
await host.close();
|
|
32
|
+
await host.close(Context.default());
|
|
32
33
|
});
|
|
33
34
|
|
|
34
35
|
test('queryCredentials', async () => {
|
|
35
36
|
const host = createServiceHost(new Config(), new MemorySignalManagerContext());
|
|
36
37
|
await host.open(new Context());
|
|
37
|
-
onTestFinished(() => host.close());
|
|
38
|
+
onTestFinished(() => host.close(Context.default()));
|
|
38
39
|
|
|
39
40
|
await host.services.IdentityService!.createIdentity({});
|
|
40
|
-
const { spaceKey } = await host.services.SpacesService!.createSpace();
|
|
41
|
+
const { spaceKey } = await host.services.SpacesService!.createSpace({ membershipPolicy: MembershipPolicy.INVITE });
|
|
41
42
|
|
|
42
43
|
const stream = host.services.SpacesService!.queryCredentials({ spaceKey });
|
|
43
44
|
const [done, tick] = latch({ count: 3 });
|
|
@@ -53,7 +54,7 @@ describe('ClientServicesHost', () => {
|
|
|
53
54
|
test('write and query credentials', async () => {
|
|
54
55
|
const host = createServiceHost(new Config(), new MemorySignalManagerContext());
|
|
55
56
|
await host.open(new Context());
|
|
56
|
-
onTestFinished(() => host.close());
|
|
57
|
+
onTestFinished(() => host.close(Context.default()));
|
|
57
58
|
|
|
58
59
|
await host.services.IdentityService!.createIdentity({});
|
|
59
60
|
|
|
@@ -90,7 +91,7 @@ describe('ClientServicesHost', () => {
|
|
|
90
91
|
test('sign presentation', async () => {
|
|
91
92
|
const host = createServiceHost(new Config(), new MemorySignalManagerContext());
|
|
92
93
|
await host.open(new Context());
|
|
93
|
-
onTestFinished(() => host.close());
|
|
94
|
+
onTestFinished(() => host.close(Context.default()));
|
|
94
95
|
|
|
95
96
|
await host.services.IdentityService!.createIdentity({});
|
|
96
97
|
|
|
@@ -127,7 +128,7 @@ describe('ClientServicesHost', () => {
|
|
|
127
128
|
expect(host.context.storage.size).to.exist;
|
|
128
129
|
|
|
129
130
|
await asyncTimeout(host.reset(), 1000);
|
|
130
|
-
await host.close();
|
|
131
|
+
await host.close(Context.default());
|
|
131
132
|
}
|
|
132
133
|
|
|
133
134
|
{
|
|
@@ -145,7 +146,7 @@ describe('ClientServicesHost', () => {
|
|
|
145
146
|
});
|
|
146
147
|
await expect(asyncTimeout(trigger.wait(), 200)).rejects.toBeInstanceOf(Error);
|
|
147
148
|
await stream?.close();
|
|
148
|
-
await host.close();
|
|
149
|
+
await host.close(Context.default());
|
|
149
150
|
}
|
|
150
151
|
});
|
|
151
152
|
});
|