@dxos/client-services 0.8.4-main.fffef41 → 0.8.4-staging.60fe92afc8
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-I2RGLVJF.mjs → chunk-HPR4MJ4W.mjs} +2870 -3767
- package/dist/lib/browser/chunk-HPR4MJ4W.mjs.map +7 -0
- package/dist/lib/browser/chunk-QCWEHHJW.mjs +24 -0
- package/dist/lib/browser/chunk-QCWEHHJW.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 +576 -139
- 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 +58 -53
- 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-QTUURCR4.mjs → chunk-JW6QHPRJ.mjs} +2810 -3576
- package/dist/lib/node-esm/chunk-JW6QHPRJ.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +576 -139
- 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 +58 -53
- 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 +2 -1
- 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 +7 -3
- 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 +2 -2
- 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.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.map +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 +2 -3
- 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 +3 -3
- 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 +10 -10
- package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity-recovery-manager.d.ts +14 -9
- package/dist/types/src/packlets/identity/identity-recovery-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity-service.d.ts +7 -11
- package/dist/types/src/packlets/identity/identity-service.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity.d.ts +10 -13
- package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts +7 -6
- 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 +1 -1
- package/dist/types/src/packlets/invitations/edge-invitation-handler.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 +7 -4
- 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 +5 -5
- package/dist/types/src/packlets/invitations/invitations-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitations-service.d.ts +3 -3
- package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts +6 -5
- 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 +1 -1
- 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 +4 -0
- package/dist/types/src/packlets/logging/logging-service.d.ts.map +1 -1
- package/dist/types/src/packlets/network/network-service.d.ts +5 -4
- 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 +75 -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/index.d.ts +1 -0
- package/dist/types/src/packlets/services/index.d.ts.map +1 -1
- package/dist/types/src/packlets/services/platform.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-context.d.ts +22 -19
- package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-host.d.ts +20 -13
- 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/sqlite-storage.d.ts +27 -0
- package/dist/types/src/packlets/services/sqlite-storage.d.ts.map +1 -0
- 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 +7 -1
- 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.map +1 -1
- package/dist/types/src/packlets/spaces/data-space-manager.d.ts +49 -22
- package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/data-space.d.ts +38 -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 +1 -1
- package/dist/types/src/packlets/spaces/epoch-migrations.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/genesis.d.ts +4 -3
- 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 +10 -7
- package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
- package/dist/types/src/packlets/storage/index.d.ts +1 -0
- package/dist/types/src/packlets/storage/index.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-sqlite.d.ts +24 -0
- package/dist/types/src/packlets/storage/profile-archive-sqlite.d.ts.map +1 -0
- package/dist/types/src/packlets/storage/profile-archive-sqlite.test.d.ts +2 -0
- package/dist/types/src/packlets/storage/profile-archive-sqlite.test.d.ts.map +1 -0
- 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 +1 -1
- 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 +20 -22
- 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 +71 -57
- package/src/index.ts +1 -0
- package/src/packlets/agents/edge-agent-manager.ts +8 -5
- package/src/packlets/agents/edge-agent-service.ts +4 -2
- package/src/packlets/devices/devices-service.test.ts +0 -1
- package/src/packlets/devtools/devtools.ts +28 -7
- package/src/packlets/devtools/feeds.ts +1 -1
- package/src/packlets/devtools/keys.ts +2 -2
- package/src/packlets/devtools/spaces.ts +1 -1
- package/src/packlets/diagnostics/diagnostics.ts +1 -2
- package/src/packlets/diagnostics/index.ts +1 -1
- package/src/packlets/identity/authenticator.ts +3 -3
- package/src/packlets/identity/contacts-service.ts +1 -2
- package/src/packlets/identity/identity-manager.test.ts +6 -6
- package/src/packlets/identity/identity-manager.ts +29 -28
- package/src/packlets/identity/identity-recovery-manager.ts +31 -22
- package/src/packlets/identity/identity-service.test.ts +6 -27
- package/src/packlets/identity/identity-service.ts +17 -83
- package/src/packlets/identity/identity.test.ts +3 -3
- package/src/packlets/identity/identity.ts +12 -35
- package/src/packlets/invitations/device-invitation-protocol.ts +10 -9
- package/src/packlets/invitations/edge-invitation-handler.ts +9 -5
- package/src/packlets/invitations/invitation-guest-extenstion.ts +6 -4
- package/src/packlets/invitations/invitation-host-extension.ts +13 -14
- package/src/packlets/invitations/invitation-protocol.ts +7 -4
- package/src/packlets/invitations/invitation-state.ts +1 -15
- package/src/packlets/invitations/invitations-handler.test.ts +4 -5
- package/src/packlets/invitations/invitations-handler.ts +74 -22
- package/src/packlets/invitations/invitations-manager.ts +42 -17
- package/src/packlets/invitations/invitations-service.ts +9 -9
- package/src/packlets/invitations/space-invitation-protocol.test.ts +17 -16
- package/src/packlets/invitations/space-invitation-protocol.ts +13 -18
- package/src/packlets/locks/index.ts +1 -1
- package/src/packlets/logging/logging-service.ts +19 -15
- package/src/packlets/network/network-service.test.ts +0 -1
- package/src/packlets/network/network-service.ts +10 -8
- package/src/packlets/services/client-rpc-server.ts +19 -16
- package/src/packlets/services/feed-syncer.test.ts +376 -0
- package/src/packlets/services/feed-syncer.ts +536 -0
- package/src/packlets/services/index.ts +1 -0
- package/src/packlets/services/platform.ts +7 -1
- package/src/packlets/services/service-context.test.ts +3 -2
- package/src/packlets/services/service-context.ts +215 -78
- package/src/packlets/services/service-host.test.ts +8 -10
- package/src/packlets/services/service-host.ts +102 -70
- package/src/packlets/services/service-registry.test.ts +0 -1
- package/src/packlets/services/sqlite-storage.ts +390 -0
- 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 +129 -0
- package/src/packlets/space-export/serialized-space-writer.ts +260 -0
- package/src/packlets/space-export/space-archive-reader.ts +64 -3
- package/src/packlets/space-export/space-archive-writer.ts +41 -4
- package/src/packlets/space-export/space-archive.test.ts +482 -0
- package/src/packlets/spaces/data-space-manager.test.ts +169 -14
- package/src/packlets/spaces/data-space-manager.ts +192 -127
- package/src/packlets/spaces/data-space.ts +89 -43
- package/src/packlets/spaces/edge-feed-replicator.test.ts +2 -2
- package/src/packlets/spaces/edge-feed-replicator.ts +11 -9
- package/src/packlets/spaces/epoch-migrations.ts +7 -6
- package/src/packlets/spaces/genesis.ts +9 -4
- package/src/packlets/spaces/notarization-plugin.test.ts +2 -2
- package/src/packlets/spaces/notarization-plugin.ts +10 -9
- package/src/packlets/spaces/spaces-service.test.ts +18 -11
- package/src/packlets/spaces/spaces-service.ts +130 -24
- package/src/packlets/storage/index.ts +1 -0
- package/src/packlets/storage/profile-archive-sqlite.test.ts +79 -0
- package/src/packlets/storage/profile-archive-sqlite.ts +100 -0
- package/src/packlets/storage/profile-archive.ts +3 -0
- package/src/packlets/storage/storage.ts +4 -4
- package/src/packlets/testing/invitation-utils.ts +10 -6
- package/src/packlets/testing/test-builder.ts +59 -40
- package/src/packlets/worker/worker-runtime.ts +173 -17
- package/src/packlets/worker/worker-session.ts +12 -18
- package/src/version.ts +1 -1
- package/dist/lib/browser/chunk-I2RGLVJF.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-QTUURCR4.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
|
@@ -2,62 +2,75 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import * as SqlClient from '@effect/sql/SqlClient';
|
|
6
|
+
import * as Effect from 'effect/Effect';
|
|
7
|
+
|
|
5
8
|
import { Mutex, Trigger } from '@dxos/async';
|
|
6
9
|
import { Context, Resource } from '@dxos/context';
|
|
7
10
|
import { type CredentialProcessor, getCredentialAssertion } from '@dxos/credentials';
|
|
8
11
|
import { failUndefined, warnAfterTimeout } from '@dxos/debug';
|
|
9
12
|
import {
|
|
10
13
|
EchoEdgeReplicator,
|
|
14
|
+
EchoEdgeSubductionReplicator,
|
|
11
15
|
EchoHost,
|
|
16
|
+
type EdgeAutomergeReplicator,
|
|
12
17
|
MeshEchoReplicator,
|
|
13
|
-
|
|
18
|
+
runSqliteHealthCheck,
|
|
19
|
+
SqliteMetadataStore,
|
|
14
20
|
SpaceManager,
|
|
15
21
|
valueEncoding,
|
|
16
|
-
} from '@dxos/echo-
|
|
22
|
+
} from '@dxos/echo-host';
|
|
17
23
|
import { createChainEdgeIdentity, createEphemeralEdgeIdentity } from '@dxos/edge-client';
|
|
18
24
|
import type { EdgeConnection, EdgeHttpClient, EdgeIdentity } from '@dxos/edge-client';
|
|
25
|
+
import { RuntimeProvider } from '@dxos/effect';
|
|
19
26
|
import { FeedFactory, FeedStore } from '@dxos/feed-store';
|
|
20
27
|
import { invariant } from '@dxos/invariant';
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import { type LevelDB } from '@dxos/kv-store';
|
|
28
|
+
import { SqliteKeyring } from '@dxos/keyring';
|
|
29
|
+
import { type SpaceId } from '@dxos/keys';
|
|
24
30
|
import { log } from '@dxos/log';
|
|
25
31
|
import { type SignalManager } from '@dxos/messaging';
|
|
26
32
|
import { type SwarmNetworkManager } from '@dxos/network-manager';
|
|
27
|
-
import { InvalidStorageVersionError, STORAGE_VERSION
|
|
33
|
+
import { InvalidStorageVersionError, STORAGE_VERSION } from '@dxos/protocols';
|
|
34
|
+
import { FeedProtocol } from '@dxos/protocols';
|
|
28
35
|
import { Invitation } from '@dxos/protocols/proto/dxos/client/services';
|
|
29
36
|
import { type Runtime } from '@dxos/protocols/proto/dxos/config';
|
|
30
37
|
import type { FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';
|
|
31
38
|
import { type Credential, type ProfileDocument } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
32
|
-
import {
|
|
33
|
-
import {
|
|
39
|
+
import { SqlTransaction } from '@dxos/sql-sqlite';
|
|
40
|
+
import { SqliteBlobStore } from '@dxos/teleport-extension-object-sync';
|
|
34
41
|
import { trace as Trace } from '@dxos/tracing';
|
|
35
42
|
import { safeInstanceof } from '@dxos/util';
|
|
36
43
|
|
|
44
|
+
// SqlTransaction.SqlTransaction is the Tag class exported from the SqlTransaction namespace.
|
|
45
|
+
type SqlTransactionTag = SqlTransaction.SqlTransaction;
|
|
46
|
+
|
|
37
47
|
import { EdgeAgentManager } from '../agents';
|
|
38
48
|
import {
|
|
39
49
|
type CreateIdentityOptions,
|
|
50
|
+
type Identity,
|
|
40
51
|
IdentityManager,
|
|
41
|
-
type
|
|
42
|
-
type
|
|
52
|
+
type IdentityManagerProps,
|
|
53
|
+
type JoinIdentityProps,
|
|
43
54
|
} from '../identity';
|
|
44
55
|
import { EdgeIdentityRecoveryManager } from '../identity/identity-recovery-manager';
|
|
45
56
|
import {
|
|
46
57
|
DeviceInvitationProtocol,
|
|
47
|
-
type
|
|
58
|
+
type InvitationConnectionProps,
|
|
48
59
|
type InvitationProtocol,
|
|
49
60
|
InvitationsHandler,
|
|
50
61
|
InvitationsManager,
|
|
51
62
|
SpaceInvitationProtocol,
|
|
52
63
|
} from '../invitations';
|
|
53
|
-
import { DataSpaceManager, type
|
|
64
|
+
import { DataSpaceManager, type DataSpaceManagerRuntimeProps, type SigningContext } from '../spaces';
|
|
65
|
+
import { FeedSyncer } from './feed-syncer';
|
|
66
|
+
import { SqliteStorage } from './sqlite-storage';
|
|
54
67
|
|
|
55
|
-
export type
|
|
56
|
-
|
|
68
|
+
export type ServiceContextRuntimeProps = Pick<
|
|
69
|
+
IdentityManagerProps,
|
|
57
70
|
'devicePresenceOfflineTimeout' | 'devicePresenceAnnounceInterval'
|
|
58
71
|
> &
|
|
59
|
-
|
|
60
|
-
|
|
72
|
+
DataSpaceManagerRuntimeProps & {
|
|
73
|
+
invitationConnectionDefaultProps?: InvitationConnectionProps;
|
|
61
74
|
disableP2pReplication?: boolean;
|
|
62
75
|
enableVectorIndexing?: boolean;
|
|
63
76
|
};
|
|
@@ -67,15 +80,15 @@ export type ServiceContextRuntimeParams = Pick<
|
|
|
67
80
|
// TODO(burdon): Rename/break-up into smaller components. And/or make members private.
|
|
68
81
|
// TODO(dmaretskyi): Gets duplicated in CJS build between normal and testing bundles.
|
|
69
82
|
@safeInstanceof('dxos.client-services.ServiceContext')
|
|
70
|
-
@Trace.resource()
|
|
83
|
+
@Trace.resource({ lifecycle: true })
|
|
71
84
|
export class ServiceContext extends Resource {
|
|
72
85
|
private readonly _edgeIdentityUpdateMutex = new Mutex();
|
|
73
86
|
|
|
74
87
|
public readonly initialized = new Trigger();
|
|
75
|
-
public readonly metadataStore:
|
|
76
|
-
public readonly blobStore:
|
|
88
|
+
public readonly metadataStore: SqliteMetadataStore;
|
|
89
|
+
public readonly blobStore: SqliteBlobStore;
|
|
77
90
|
public readonly feedStore: FeedStore<FeedMessage>;
|
|
78
|
-
public readonly keyring:
|
|
91
|
+
public readonly keyring: SqliteKeyring;
|
|
79
92
|
public readonly spaceManager: SpaceManager;
|
|
80
93
|
public readonly identityManager: IdentityManager;
|
|
81
94
|
public readonly recoveryManager: EdgeIdentityRecoveryManager;
|
|
@@ -83,7 +96,9 @@ export class ServiceContext extends Resource {
|
|
|
83
96
|
public readonly invitationsManager: InvitationsManager;
|
|
84
97
|
public readonly echoHost: EchoHost;
|
|
85
98
|
private readonly _meshReplicator?: MeshEchoReplicator = undefined;
|
|
86
|
-
private readonly _echoEdgeReplicator?:
|
|
99
|
+
private readonly _echoEdgeReplicator?: EdgeAutomergeReplicator = undefined;
|
|
100
|
+
private readonly _feedSyncer?: FeedSyncer = undefined;
|
|
101
|
+
private readonly _feedStorage: SqliteStorage;
|
|
87
102
|
|
|
88
103
|
// Initialized after identity is initialized.
|
|
89
104
|
public dataSpaceManager?: DataSpaceManager;
|
|
@@ -96,28 +111,28 @@ export class ServiceContext extends Resource {
|
|
|
96
111
|
|
|
97
112
|
private _deviceSpaceSync?: CredentialProcessor;
|
|
98
113
|
|
|
99
|
-
private readonly _instanceId = PublicKey.random().toHex();
|
|
100
|
-
|
|
101
114
|
constructor(
|
|
102
|
-
public readonly storage: Storage,
|
|
103
|
-
public readonly level: LevelDB,
|
|
104
115
|
public readonly networkManager: SwarmNetworkManager,
|
|
105
116
|
public readonly signalManager: SignalManager,
|
|
106
117
|
private readonly _edgeConnection: EdgeConnection | undefined,
|
|
107
118
|
private readonly _edgeHttpClient: EdgeHttpClient | undefined,
|
|
108
|
-
|
|
119
|
+
private readonly _runtime: RuntimeProvider.RuntimeProvider<SqlClient.SqlClient | SqlTransactionTag>,
|
|
120
|
+
public readonly _runtimeProps?: ServiceContextRuntimeProps,
|
|
109
121
|
private readonly _edgeFeatures?: Runtime.Client.EdgeFeatures,
|
|
110
122
|
) {
|
|
111
123
|
super();
|
|
112
124
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
this.blobStore = new BlobStore(storage.createDirectory('blobs'));
|
|
125
|
+
log('runtimeProps', this._runtimeProps);
|
|
126
|
+
log('edgeFeatures', this._edgeFeatures);
|
|
116
127
|
|
|
117
|
-
this.
|
|
128
|
+
this.metadataStore = new SqliteMetadataStore({ runtime: this._runtime });
|
|
129
|
+
this.blobStore = new SqliteBlobStore({ runtime: this._runtime });
|
|
130
|
+
this.keyring = new SqliteKeyring({ runtime: this._runtime });
|
|
131
|
+
this._feedStorage = new SqliteStorage({ runtime: this._runtime });
|
|
132
|
+
const feedStorage = this._feedStorage;
|
|
118
133
|
this.feedStore = new FeedStore<FeedMessage>({
|
|
119
134
|
factory: new FeedFactory<FeedMessage>({
|
|
120
|
-
root:
|
|
135
|
+
root: feedStorage.createDirectory('feeds'),
|
|
121
136
|
signer: this.keyring,
|
|
122
137
|
hypercore: {
|
|
123
138
|
valueEncoding,
|
|
@@ -131,7 +146,7 @@ export class ServiceContext extends Resource {
|
|
|
131
146
|
networkManager: this.networkManager,
|
|
132
147
|
blobStore: this.blobStore,
|
|
133
148
|
metadataStore: this.metadataStore,
|
|
134
|
-
disableP2pReplication: this.
|
|
149
|
+
disableP2pReplication: this._runtimeProps?.disableP2pReplication,
|
|
135
150
|
});
|
|
136
151
|
|
|
137
152
|
this.identityManager = new IdentityManager({
|
|
@@ -139,8 +154,8 @@ export class ServiceContext extends Resource {
|
|
|
139
154
|
keyring: this.keyring,
|
|
140
155
|
feedStore: this.feedStore,
|
|
141
156
|
spaceManager: this.spaceManager,
|
|
142
|
-
devicePresenceOfflineTimeout: this.
|
|
143
|
-
devicePresenceAnnounceInterval: this.
|
|
157
|
+
devicePresenceOfflineTimeout: this._runtimeProps?.devicePresenceOfflineTimeout,
|
|
158
|
+
devicePresenceAnnounceInterval: this._runtimeProps?.devicePresenceAnnounceInterval,
|
|
144
159
|
edgeConnection: this._edgeConnection,
|
|
145
160
|
edgeFeatures: this._edgeFeatures,
|
|
146
161
|
});
|
|
@@ -153,20 +168,33 @@ export class ServiceContext extends Resource {
|
|
|
153
168
|
);
|
|
154
169
|
|
|
155
170
|
this.echoHost = new EchoHost({
|
|
156
|
-
kv: this.level,
|
|
157
171
|
peerIdProvider: () => this.identityManager.identity?.deviceKey?.toHex(),
|
|
158
172
|
getSpaceKeyByRootDocumentId: (documentId) => this.spaceManager.findSpaceByRootDocumentId(documentId)?.key,
|
|
159
|
-
|
|
160
|
-
|
|
173
|
+
runtime: this._runtime,
|
|
174
|
+
useSubduction: this._edgeFeatures?.subductionReplicator,
|
|
175
|
+
syncQueue: async (ctx, request) => {
|
|
176
|
+
return this._feedSyncer?.syncBlocking(ctx, {
|
|
177
|
+
spaceId: request.spaceId as SpaceId,
|
|
178
|
+
subspaceTag: request.subspaceTag,
|
|
179
|
+
shouldPush: request.shouldPush,
|
|
180
|
+
shouldPull: request.shouldPull,
|
|
181
|
+
});
|
|
182
|
+
},
|
|
183
|
+
getSyncState: async (ctx, request) => {
|
|
184
|
+
// Mirror `syncQueue` above: in non-edge / partially-initialised modes the
|
|
185
|
+
// feed syncer is absent. Return an empty state instead of throwing so
|
|
186
|
+
// callers (e.g. devtools sync panel) keep working.
|
|
187
|
+
if (!this._feedSyncer) {
|
|
188
|
+
return { namespaces: [] };
|
|
189
|
+
}
|
|
190
|
+
return this._feedSyncer.getSyncState(ctx, request);
|
|
161
191
|
},
|
|
162
192
|
});
|
|
163
193
|
|
|
164
|
-
this._meshReplicator = new MeshEchoReplicator();
|
|
165
|
-
|
|
166
194
|
this.invitations = new InvitationsHandler(
|
|
167
195
|
this.networkManager, //
|
|
168
196
|
this._edgeHttpClient,
|
|
169
|
-
|
|
197
|
+
_runtimeProps?.invitationConnectionDefaultProps,
|
|
170
198
|
);
|
|
171
199
|
this.invitationsManager = new InvitationsManager(
|
|
172
200
|
this.invitations,
|
|
@@ -186,68 +214,130 @@ export class ServiceContext extends Resource {
|
|
|
186
214
|
),
|
|
187
215
|
);
|
|
188
216
|
|
|
189
|
-
if (!this.
|
|
217
|
+
if (!this._runtimeProps?.disableP2pReplication) {
|
|
190
218
|
this._meshReplicator = new MeshEchoReplicator();
|
|
191
219
|
}
|
|
192
|
-
if (this._edgeConnection && this.
|
|
193
|
-
this.
|
|
194
|
-
|
|
195
|
-
|
|
220
|
+
if (this._edgeConnection && this._edgeHttpClient) {
|
|
221
|
+
if (this._edgeFeatures?.subductionReplicator) {
|
|
222
|
+
this._echoEdgeReplicator = new EchoEdgeSubductionReplicator({
|
|
223
|
+
edgeConnection: this._edgeConnection,
|
|
224
|
+
edgeHttpClient: this._edgeHttpClient,
|
|
225
|
+
});
|
|
226
|
+
} else if (this._edgeFeatures?.echoReplicator) {
|
|
227
|
+
this._echoEdgeReplicator = new EchoEdgeReplicator({
|
|
228
|
+
edgeConnection: this._edgeConnection,
|
|
229
|
+
edgeHttpClient: this._edgeHttpClient,
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (this.echoHost.feedStore && this._edgeConnection) {
|
|
235
|
+
this._feedSyncer = new FeedSyncer({
|
|
236
|
+
runtime: this._runtime,
|
|
237
|
+
feedStore: this.echoHost.feedStore,
|
|
238
|
+
edgeClient: this._edgeConnection,
|
|
239
|
+
peerId: this.identityManager.identity?.deviceKey?.toHex() ?? '',
|
|
240
|
+
getSpaceIds: () => this.echoHost!.spaceIds,
|
|
241
|
+
syncNamespaces: [FeedProtocol.WellKnownNamespaces.data, FeedProtocol.WellKnownNamespaces.trace],
|
|
196
242
|
});
|
|
197
243
|
}
|
|
198
244
|
}
|
|
199
245
|
|
|
200
|
-
@Trace.span()
|
|
246
|
+
@Trace.span({ op: 'lifecycle' })
|
|
201
247
|
protected override async _open(ctx: Context): Promise<void> {
|
|
248
|
+
await RuntimeProvider.runPromise(this._runtime)(
|
|
249
|
+
Effect.all([this.metadataStore.migrate, this.blobStore.migrate, this.keyring.migrate, this._feedStorage.migrate]),
|
|
250
|
+
);
|
|
251
|
+
|
|
202
252
|
await this._checkStorageVersion();
|
|
203
253
|
|
|
254
|
+
log('running sqlite health check...');
|
|
255
|
+
await runSqliteHealthCheck(this._runtime);
|
|
256
|
+
log('sqlite health check passed');
|
|
257
|
+
|
|
204
258
|
log('opening...');
|
|
205
|
-
log.trace('dxos.sdk.service-context.open', trace.begin({ id: this._instanceId }));
|
|
206
259
|
|
|
260
|
+
log('opening identityManager...');
|
|
207
261
|
await this.identityManager.open(ctx);
|
|
262
|
+
log('identityManager opened', { hasIdentity: !!this.identityManager.identity });
|
|
208
263
|
|
|
209
|
-
|
|
264
|
+
log('setting network identity...');
|
|
265
|
+
await this._setNetworkIdentity({ identity: this.identityManager.identity });
|
|
266
|
+
log('network identity set');
|
|
210
267
|
|
|
211
|
-
|
|
212
|
-
await this.
|
|
268
|
+
log('opening edge connection...');
|
|
269
|
+
await this._edgeConnection?.open(ctx);
|
|
270
|
+
log('edge connection opened');
|
|
271
|
+
|
|
272
|
+
log('opening signal manager...');
|
|
273
|
+
await this.signalManager.open(ctx);
|
|
274
|
+
log('signal manager opened');
|
|
275
|
+
|
|
276
|
+
log('opening network manager...');
|
|
213
277
|
await this.networkManager.open();
|
|
278
|
+
log('network manager opened');
|
|
214
279
|
|
|
280
|
+
log('opening echo host...');
|
|
215
281
|
await this.echoHost.open(ctx);
|
|
282
|
+
log('echo host opened');
|
|
216
283
|
|
|
217
284
|
if (this._meshReplicator) {
|
|
218
|
-
|
|
285
|
+
log('adding mesh replicator...');
|
|
286
|
+
await this.echoHost.addReplicator(ctx, this._meshReplicator);
|
|
287
|
+
log('mesh replicator added');
|
|
219
288
|
}
|
|
220
289
|
if (this._echoEdgeReplicator) {
|
|
221
|
-
|
|
290
|
+
log('adding edge replicator...');
|
|
291
|
+
await this.echoHost.addReplicator(ctx, this._echoEdgeReplicator);
|
|
292
|
+
log('edge replicator added');
|
|
222
293
|
}
|
|
223
294
|
|
|
295
|
+
log('loading metadata store...');
|
|
224
296
|
await this.metadataStore.load();
|
|
297
|
+
log('metadata store loaded');
|
|
298
|
+
|
|
299
|
+
log('opening space manager...');
|
|
225
300
|
await this.spaceManager.open();
|
|
301
|
+
log('space manager opened');
|
|
226
302
|
|
|
227
303
|
if (this.identityManager.identity) {
|
|
228
|
-
|
|
304
|
+
log('joining network...');
|
|
305
|
+
await this.identityManager.identity.joinNetwork(ctx);
|
|
306
|
+
log('network joined');
|
|
307
|
+
|
|
308
|
+
log('initializing spaces...(calling _initialize)');
|
|
229
309
|
await this._initialize(ctx);
|
|
310
|
+
log('spaces initialized');
|
|
311
|
+
} else {
|
|
312
|
+
log('no identity, skipping network join and space initialization');
|
|
230
313
|
}
|
|
231
314
|
|
|
232
|
-
|
|
315
|
+
log('opening feed syncer...');
|
|
316
|
+
await this._feedSyncer?.open(ctx);
|
|
317
|
+
log('feed syncer opened');
|
|
318
|
+
|
|
319
|
+
log('loading persistent invitations...');
|
|
320
|
+
const loadedInvitations = await this.invitationsManager.loadPersistentInvitations(ctx);
|
|
233
321
|
log('loaded persistent invitations', { count: loadedInvitations.invitations?.length });
|
|
234
322
|
|
|
235
|
-
log.trace('dxos.sdk.service-context.open', trace.end({ id: this._instanceId }));
|
|
236
323
|
log('opened');
|
|
237
324
|
}
|
|
238
325
|
|
|
239
326
|
protected override async _close(ctx: Context): Promise<void> {
|
|
240
327
|
log('closing...');
|
|
328
|
+
|
|
329
|
+
await this._feedSyncer?.close();
|
|
330
|
+
|
|
241
331
|
if (this._deviceSpaceSync && this.identityManager.identity) {
|
|
242
332
|
await this.identityManager.identity.space.spaceState.removeCredentialProcessor(this._deviceSpaceSync);
|
|
243
333
|
}
|
|
244
|
-
await this.dataSpaceManager?.close();
|
|
334
|
+
await this.dataSpaceManager?.close(ctx);
|
|
245
335
|
await this.edgeAgentManager?.close();
|
|
246
|
-
await this.identityManager.close();
|
|
336
|
+
await this.identityManager.close(ctx);
|
|
247
337
|
await this.spaceManager.close();
|
|
248
338
|
await this.echoHost.close(ctx);
|
|
249
339
|
|
|
250
|
-
await this.networkManager.close();
|
|
340
|
+
await this.networkManager.close(ctx);
|
|
251
341
|
await this.signalManager.close();
|
|
252
342
|
await this._edgeConnection?.close();
|
|
253
343
|
await this.feedStore.close();
|
|
@@ -256,11 +346,12 @@ export class ServiceContext extends Resource {
|
|
|
256
346
|
log('closed');
|
|
257
347
|
}
|
|
258
348
|
|
|
259
|
-
async createIdentity(params: CreateIdentityOptions = {}) {
|
|
260
|
-
|
|
261
|
-
await this.
|
|
262
|
-
await
|
|
263
|
-
await
|
|
349
|
+
async createIdentity(params: CreateIdentityOptions = {}, ctx?: Context) {
|
|
350
|
+
ctx ??= this._ctx;
|
|
351
|
+
const identity = await this.identityManager.createIdentity(params, ctx);
|
|
352
|
+
await this._setNetworkIdentity({ identity });
|
|
353
|
+
await identity.joinNetwork(ctx);
|
|
354
|
+
await this._initialize(ctx);
|
|
264
355
|
return identity;
|
|
265
356
|
}
|
|
266
357
|
|
|
@@ -283,12 +374,12 @@ export class ServiceContext extends Resource {
|
|
|
283
374
|
}
|
|
284
375
|
}
|
|
285
376
|
|
|
286
|
-
private async _acceptIdentity(params:
|
|
287
|
-
const { identity, identityRecord } = await this.identityManager.prepareIdentity(params);
|
|
288
|
-
await this._setNetworkIdentity({ deviceCredential: params.authorizedDeviceCredential
|
|
289
|
-
await identity.joinNetwork();
|
|
377
|
+
private async _acceptIdentity(params: JoinIdentityProps) {
|
|
378
|
+
const { identity, identityRecord } = await this.identityManager.prepareIdentity(params, this._ctx);
|
|
379
|
+
await this._setNetworkIdentity({ deviceCredential: params.authorizedDeviceCredential!, identity });
|
|
380
|
+
await identity.joinNetwork(this._ctx);
|
|
290
381
|
await this.identityManager.acceptIdentity(identity, identityRecord, params.deviceProfile);
|
|
291
|
-
await this._initialize(
|
|
382
|
+
await this._initialize(this._ctx);
|
|
292
383
|
return identity;
|
|
293
384
|
}
|
|
294
385
|
|
|
@@ -303,7 +394,7 @@ export class ServiceContext extends Resource {
|
|
|
303
394
|
// Called when identity is created.
|
|
304
395
|
@Trace.span()
|
|
305
396
|
private async _initialize(ctx: Context): Promise<void> {
|
|
306
|
-
log('
|
|
397
|
+
log('_initialize: start');
|
|
307
398
|
const identity = this.identityManager.identity ?? failUndefined();
|
|
308
399
|
const signingContext: SigningContext = {
|
|
309
400
|
credentialSigner: identity.getIdentityCredentialSigner(),
|
|
@@ -315,6 +406,7 @@ export class ServiceContext extends Resource {
|
|
|
315
406
|
},
|
|
316
407
|
};
|
|
317
408
|
|
|
409
|
+
log('_initialize: creating DataSpaceManager');
|
|
318
410
|
this.dataSpaceManager = new DataSpaceManager({
|
|
319
411
|
spaceManager: this.spaceManager,
|
|
320
412
|
metadataStore: this.metadataStore,
|
|
@@ -327,10 +419,12 @@ export class ServiceContext extends Resource {
|
|
|
327
419
|
edgeHttpClient: this._edgeHttpClient,
|
|
328
420
|
echoEdgeReplicator: this._echoEdgeReplicator,
|
|
329
421
|
meshReplicator: this._meshReplicator,
|
|
330
|
-
|
|
422
|
+
runtimeProps: this._runtimeProps as DataSpaceManagerRuntimeProps,
|
|
331
423
|
edgeFeatures: this._edgeFeatures,
|
|
332
424
|
});
|
|
333
|
-
|
|
425
|
+
log('_initialize: opening DataSpaceManager...');
|
|
426
|
+
await this.dataSpaceManager.open(ctx);
|
|
427
|
+
log('_initialize: DataSpaceManager opened');
|
|
334
428
|
|
|
335
429
|
this.edgeAgentManager = new EdgeAgentManager(
|
|
336
430
|
this._edgeFeatures,
|
|
@@ -338,17 +432,41 @@ export class ServiceContext extends Resource {
|
|
|
338
432
|
this.dataSpaceManager,
|
|
339
433
|
identity,
|
|
340
434
|
);
|
|
341
|
-
|
|
435
|
+
log('_initialize: opening EdgeAgentManager...');
|
|
436
|
+
await this.edgeAgentManager.open(ctx);
|
|
437
|
+
log('_initialize: EdgeAgentManager opened');
|
|
342
438
|
|
|
343
439
|
this._handlerFactories.set(Invitation.Kind.SPACE, (invitation) => {
|
|
344
440
|
invariant(this.dataSpaceManager, 'dataSpaceManager not initialized yet');
|
|
345
441
|
return new SpaceInvitationProtocol(this.dataSpaceManager, signingContext, this.keyring, invitation.spaceKey);
|
|
346
442
|
});
|
|
347
443
|
this.initialized.wake();
|
|
444
|
+
log('_initialize: initialized.wake() called');
|
|
348
445
|
|
|
349
446
|
this._deviceSpaceSync = {
|
|
350
447
|
processCredential: async (credential: Credential) => {
|
|
351
448
|
const assertion = getCredentialAssertion(credential);
|
|
449
|
+
|
|
450
|
+
// A space was tombstoned on another device: replicate the deletion locally.
|
|
451
|
+
if (assertion['@type'] === 'dxos.halo.credentials.SpaceDeleted') {
|
|
452
|
+
if (assertion.spaceKey.equals(identity.space.key)) {
|
|
453
|
+
// ignore halo space
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
if (!this.dataSpaceManager) {
|
|
457
|
+
log('dataSpaceManager not initialized yet, ignoring space deletion', { details: assertion });
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
try {
|
|
462
|
+
log('tombstoning space recorded in halo', { details: assertion });
|
|
463
|
+
await this.dataSpaceManager.handleRemoteSpaceDeleted(this._ctx, assertion.spaceKey);
|
|
464
|
+
} catch (err) {
|
|
465
|
+
log.catch(err);
|
|
466
|
+
}
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
|
|
352
470
|
if (assertion['@type'] !== 'dxos.halo.credentials.SpaceMember') {
|
|
353
471
|
return;
|
|
354
472
|
}
|
|
@@ -360,6 +478,11 @@ export class ServiceContext extends Resource {
|
|
|
360
478
|
log('dataSpaceManager not initialized yet, ignoring space admission', { details: assertion });
|
|
361
479
|
return;
|
|
362
480
|
}
|
|
481
|
+
// Do not re-accept a space that has been tombstoned (handles out-of-order credential replay).
|
|
482
|
+
if (this.dataSpaceManager.isSpaceDeleted(assertion.spaceKey)) {
|
|
483
|
+
log('space is deleted, ignoring space admission', { details: assertion });
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
363
486
|
if (this.dataSpaceManager.spaces.has(assertion.spaceKey)) {
|
|
364
487
|
log('space already exists, ignoring space admission', { details: assertion });
|
|
365
488
|
return;
|
|
@@ -367,9 +490,10 @@ export class ServiceContext extends Resource {
|
|
|
367
490
|
|
|
368
491
|
try {
|
|
369
492
|
log('accepting space recorded in halo', { details: assertion });
|
|
370
|
-
await this.dataSpaceManager.acceptSpace({
|
|
493
|
+
await this.dataSpaceManager.acceptSpace(this._ctx, {
|
|
371
494
|
spaceKey: assertion.spaceKey,
|
|
372
495
|
genesisFeedKey: assertion.genesisFeedKey,
|
|
496
|
+
tags: assertion.tags,
|
|
373
497
|
});
|
|
374
498
|
} catch (err) {
|
|
375
499
|
log.catch(err);
|
|
@@ -380,33 +504,42 @@ export class ServiceContext extends Resource {
|
|
|
380
504
|
await identity.space.spaceState.addCredentialProcessor(this._deviceSpaceSync);
|
|
381
505
|
}
|
|
382
506
|
|
|
383
|
-
private async _setNetworkIdentity(params?: { deviceCredential
|
|
507
|
+
private async _setNetworkIdentity(params?: { deviceCredential?: Credential; identity?: Identity }): Promise<void> {
|
|
508
|
+
log('_setNetworkIdentity: acquiring mutex...');
|
|
384
509
|
using _ = await this._edgeIdentityUpdateMutex.acquire();
|
|
510
|
+
log('_setNetworkIdentity: mutex acquired');
|
|
385
511
|
|
|
386
512
|
let edgeIdentity: EdgeIdentity;
|
|
387
|
-
const identity =
|
|
513
|
+
const identity = params?.identity;
|
|
388
514
|
if (identity) {
|
|
389
|
-
log('
|
|
515
|
+
log('_setNetworkIdentity: has identity', {
|
|
390
516
|
identity: identity.identityKey.toHex(),
|
|
391
|
-
|
|
517
|
+
hasDeviceCredential: !!params?.deviceCredential,
|
|
392
518
|
});
|
|
393
519
|
|
|
394
520
|
if (params?.deviceCredential) {
|
|
521
|
+
log('_setNetworkIdentity: creating chain edge identity with device credential...');
|
|
395
522
|
edgeIdentity = await createChainEdgeIdentity(
|
|
396
523
|
identity.signer,
|
|
397
524
|
identity.identityKey,
|
|
398
525
|
identity.deviceKey,
|
|
399
|
-
|
|
526
|
+
{ credential: params.deviceCredential },
|
|
400
527
|
[], // TODO(dmaretskyi): Service access credentials.
|
|
401
528
|
);
|
|
529
|
+
log('_setNetworkIdentity: chain edge identity created');
|
|
402
530
|
} else {
|
|
531
|
+
log('_setNetworkIdentity: waiting for identity.ready()...');
|
|
403
532
|
// TODO: throw here or from identity if device chain can't be loaded, to avoid indefinite hangup
|
|
404
533
|
await warnAfterTimeout(10_000, 'Waiting for identity to be ready for edge connection', async () => {
|
|
405
534
|
await identity.ready();
|
|
406
535
|
});
|
|
536
|
+
log('_setNetworkIdentity: identity.ready() resolved', {
|
|
537
|
+
hasDeviceCredentialChain: !!identity.deviceCredentialChain,
|
|
538
|
+
});
|
|
407
539
|
|
|
408
540
|
invariant(identity.deviceCredentialChain);
|
|
409
541
|
|
|
542
|
+
log('_setNetworkIdentity: creating chain edge identity...');
|
|
410
543
|
edgeIdentity = await createChainEdgeIdentity(
|
|
411
544
|
identity.signer,
|
|
412
545
|
identity.identityKey,
|
|
@@ -414,9 +547,12 @@ export class ServiceContext extends Resource {
|
|
|
414
547
|
identity.deviceCredentialChain,
|
|
415
548
|
[], // TODO(dmaretskyi): Service access credentials.
|
|
416
549
|
);
|
|
550
|
+
log('_setNetworkIdentity: chain edge identity created');
|
|
417
551
|
}
|
|
418
552
|
} else {
|
|
553
|
+
log('_setNetworkIdentity: no identity, creating ephemeral edge identity...');
|
|
419
554
|
edgeIdentity = await createEphemeralEdgeIdentity();
|
|
555
|
+
log('_setNetworkIdentity: ephemeral edge identity created');
|
|
420
556
|
}
|
|
421
557
|
|
|
422
558
|
this._edgeConnection?.setIdentity(edgeIdentity);
|
|
@@ -425,5 +561,6 @@ export class ServiceContext extends Resource {
|
|
|
425
561
|
identityKey: edgeIdentity.identityKey,
|
|
426
562
|
peerKey: edgeIdentity.peerKey,
|
|
427
563
|
});
|
|
564
|
+
log('_setNetworkIdentity: done');
|
|
428
565
|
}
|
|
429
566
|
}
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { rmSync } from 'node:fs';
|
|
6
|
-
|
|
7
6
|
import { afterEach, describe, expect, onTestFinished, test } from 'vitest';
|
|
8
7
|
|
|
9
8
|
import { Trigger, asyncTimeout, latch } from '@dxos/async';
|
|
@@ -13,6 +12,7 @@ import { verifyPresentation } from '@dxos/credentials';
|
|
|
13
12
|
import { type PublicKey } from '@dxos/keys';
|
|
14
13
|
import { MemorySignalManagerContext } from '@dxos/messaging';
|
|
15
14
|
import { type Identity } from '@dxos/protocols/proto/dxos/client/services';
|
|
15
|
+
import { MembershipPolicy } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
16
16
|
import { type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
17
17
|
import { isNode } from '@dxos/util';
|
|
18
18
|
|
|
@@ -29,16 +29,16 @@ describe('ClientServicesHost', () => {
|
|
|
29
29
|
test('open and close', async () => {
|
|
30
30
|
const host = createServiceHost(new Config(), new MemorySignalManagerContext());
|
|
31
31
|
await host.open(new Context());
|
|
32
|
-
await host.close();
|
|
32
|
+
await host.close(Context.default());
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
test('queryCredentials', async () => {
|
|
36
36
|
const host = createServiceHost(new Config(), new MemorySignalManagerContext());
|
|
37
37
|
await host.open(new Context());
|
|
38
|
-
onTestFinished(() => host.close());
|
|
38
|
+
onTestFinished(() => host.close(Context.default()));
|
|
39
39
|
|
|
40
40
|
await host.services.IdentityService!.createIdentity({});
|
|
41
|
-
const { spaceKey } = await host.services.SpacesService!.createSpace();
|
|
41
|
+
const { spaceKey } = await host.services.SpacesService!.createSpace({ membershipPolicy: MembershipPolicy.INVITE });
|
|
42
42
|
|
|
43
43
|
const stream = host.services.SpacesService!.queryCredentials({ spaceKey });
|
|
44
44
|
const [done, tick] = latch({ count: 3 });
|
|
@@ -54,7 +54,7 @@ describe('ClientServicesHost', () => {
|
|
|
54
54
|
test('write and query credentials', async () => {
|
|
55
55
|
const host = createServiceHost(new Config(), new MemorySignalManagerContext());
|
|
56
56
|
await host.open(new Context());
|
|
57
|
-
onTestFinished(() => host.close());
|
|
57
|
+
onTestFinished(() => host.close(Context.default()));
|
|
58
58
|
|
|
59
59
|
await host.services.IdentityService!.createIdentity({});
|
|
60
60
|
|
|
@@ -91,7 +91,7 @@ describe('ClientServicesHost', () => {
|
|
|
91
91
|
test('sign presentation', async () => {
|
|
92
92
|
const host = createServiceHost(new Config(), new MemorySignalManagerContext());
|
|
93
93
|
await host.open(new Context());
|
|
94
|
-
onTestFinished(() => host.close());
|
|
94
|
+
onTestFinished(() => host.close(Context.default()));
|
|
95
95
|
|
|
96
96
|
await host.services.IdentityService!.createIdentity({});
|
|
97
97
|
|
|
@@ -125,10 +125,8 @@ describe('ClientServicesHost', () => {
|
|
|
125
125
|
|
|
126
126
|
await host.services.IdentityService?.createIdentity({});
|
|
127
127
|
|
|
128
|
-
expect(host.context.storage.size).to.exist;
|
|
129
|
-
|
|
130
128
|
await asyncTimeout(host.reset(), 1000);
|
|
131
|
-
await host.close();
|
|
129
|
+
await host.close(Context.default());
|
|
132
130
|
}
|
|
133
131
|
|
|
134
132
|
{
|
|
@@ -146,7 +144,7 @@ describe('ClientServicesHost', () => {
|
|
|
146
144
|
});
|
|
147
145
|
await expect(asyncTimeout(trigger.wait(), 200)).rejects.toBeInstanceOf(Error);
|
|
148
146
|
await stream?.close();
|
|
149
|
-
await host.close();
|
|
147
|
+
await host.close(Context.default());
|
|
150
148
|
}
|
|
151
149
|
});
|
|
152
150
|
});
|