@dxos/client-services 0.6.13-main.ed424a1 → 0.6.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/{chunk-IPWEAPT2.mjs → chunk-CRXXOI45.mjs} +5186 -6222
- package/dist/lib/browser/chunk-CRXXOI45.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +3 -7
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +7 -12
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node/{chunk-DJIOUOAF.cjs → chunk-PZ3JJJ3K.cjs} +5137 -6167
- package/dist/lib/node/chunk-PZ3JJJ3K.cjs.map +7 -0
- package/dist/lib/node/index.cjs +46 -50
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +13 -18
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/types/src/index.d.ts +0 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/packlets/diagnostics/diagnostics-broadcast.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/authenticator.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/authenticator.test.d.ts +2 -0
- package/dist/types/src/packlets/identity/authenticator.test.d.ts.map +1 -0
- 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 +9 -25
- package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity.d.ts +3 -12
- package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitation-guest-extenstion.d.ts +1 -2
- 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 +1 -2
- package/dist/types/src/packlets/invitations/invitation-host-extension.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitations-handler.d.ts +8 -8
- package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
- package/dist/types/src/packlets/services/automerge-host.test.d.ts +2 -0
- package/dist/types/src/packlets/services/automerge-host.test.d.ts.map +1 -0
- package/dist/types/src/packlets/services/service-context.d.ts +9 -12
- package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-host.d.ts +0 -1
- package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/data-space-manager.d.ts +3 -7
- package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/data-space.d.ts +3 -5
- package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/edge-feed-replicator.d.ts +0 -3
- 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/notarization-plugin.d.ts +6 -35
- package/dist/types/src/packlets/spaces/notarization-plugin.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/spaces-service.d.ts +1 -1
- package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
- package/dist/types/src/packlets/storage/storage.d.ts.map +1 -1
- package/dist/types/src/packlets/testing/test-builder.d.ts +2 -1
- package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
- package/dist/types/src/packlets/worker/worker-runtime.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/package.json +39 -43
- package/src/index.ts +0 -1
- package/src/packlets/devices/devices-service.test.ts +5 -4
- package/src/packlets/diagnostics/diagnostics-broadcast.ts +0 -1
- package/src/packlets/identity/{authenticator.node.test.ts → authenticator.test.ts} +3 -2
- package/src/packlets/identity/authenticator.ts +2 -5
- package/src/packlets/identity/contacts-service.ts +1 -1
- package/src/packlets/identity/identity-manager.test.ts +16 -31
- package/src/packlets/identity/identity-manager.ts +31 -47
- package/src/packlets/identity/identity-service.test.ts +8 -4
- package/src/packlets/identity/identity.test.ts +239 -130
- package/src/packlets/identity/identity.ts +17 -60
- package/src/packlets/invitations/device-invitation-protocol.test.ts +4 -7
- package/src/packlets/invitations/device-invitation-protocol.ts +1 -5
- package/src/packlets/invitations/invitation-guest-extenstion.ts +4 -8
- package/src/packlets/invitations/invitation-host-extension.ts +7 -8
- package/src/packlets/invitations/invitations-handler.test.ts +9 -16
- package/src/packlets/invitations/invitations-handler.ts +93 -23
- package/src/packlets/invitations/space-invitation-protocol.test.ts +3 -4
- package/src/packlets/invitations/space-invitation-protocol.ts +0 -4
- package/src/packlets/logging/logging.test.ts +2 -1
- package/src/packlets/network/network-service.test.ts +3 -2
- package/src/packlets/services/automerge-host.test.ts +60 -0
- package/src/packlets/services/service-context.test.ts +1 -3
- package/src/packlets/services/service-context.ts +37 -104
- package/src/packlets/services/service-host.test.ts +12 -8
- package/src/packlets/services/service-host.ts +6 -16
- package/src/packlets/services/service-registry.test.ts +2 -1
- package/src/packlets/spaces/data-space-manager.test.ts +2 -2
- package/src/packlets/spaces/data-space-manager.ts +7 -44
- package/src/packlets/spaces/data-space.ts +6 -37
- package/src/packlets/spaces/edge-feed-replicator.ts +22 -80
- package/src/packlets/spaces/epoch-migrations.ts +2 -2
- package/src/packlets/spaces/notarization-plugin.test.ts +7 -10
- package/src/packlets/spaces/notarization-plugin.ts +29 -196
- package/src/packlets/spaces/spaces-service.test.ts +9 -5
- package/src/packlets/spaces/spaces-service.ts +1 -6
- package/src/packlets/storage/storage.ts +1 -0
- package/src/packlets/system/system-service.test.ts +2 -1
- package/src/packlets/testing/test-builder.ts +4 -7
- package/src/packlets/worker/worker-runtime.ts +2 -2
- package/src/version.ts +5 -1
- package/dist/lib/browser/chunk-IPWEAPT2.mjs.map +0 -7
- package/dist/lib/node/chunk-DJIOUOAF.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-MMU5KC57.mjs +0 -8752
- package/dist/lib/node-esm/chunk-MMU5KC57.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -420
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/testing/index.mjs +0 -424
- package/dist/lib/node-esm/testing/index.mjs.map +0 -7
- package/dist/types/src/packlets/agents/edge-agent-manager.d.ts +0 -35
- package/dist/types/src/packlets/agents/edge-agent-manager.d.ts.map +0 -1
- package/dist/types/src/packlets/agents/edge-agent-service.d.ts +0 -10
- package/dist/types/src/packlets/agents/edge-agent-service.d.ts.map +0 -1
- package/dist/types/src/packlets/agents/index.d.ts +0 -3
- package/dist/types/src/packlets/agents/index.d.ts.map +0 -1
- package/dist/types/src/packlets/identity/authenticator.node.test.d.ts +0 -2
- package/dist/types/src/packlets/identity/authenticator.node.test.d.ts.map +0 -1
- package/dist/types/src/packlets/invitations/edge-invitation-handler.d.ts +0 -30
- package/dist/types/src/packlets/invitations/edge-invitation-handler.d.ts.map +0 -1
- package/dist/types/src/packlets/invitations/invitation-state.d.ts +0 -19
- package/dist/types/src/packlets/invitations/invitation-state.d.ts.map +0 -1
- package/dist/types/src/packlets/spaces/edge-feed-replicator.test.d.ts +0 -2
- package/dist/types/src/packlets/spaces/edge-feed-replicator.test.d.ts.map +0 -1
- package/dist/types/src/testing/setup.d.ts +0 -3
- package/dist/types/src/testing/setup.d.ts.map +0 -1
- package/src/packlets/agents/edge-agent-manager.ts +0 -163
- package/src/packlets/agents/edge-agent-service.ts +0 -42
- package/src/packlets/agents/index.ts +0 -6
- package/src/packlets/invitations/edge-invitation-handler.ts +0 -185
- package/src/packlets/invitations/invitation-state.ts +0 -111
- package/src/packlets/spaces/edge-feed-replicator.test.ts +0 -252
- package/src/testing/setup.ts +0 -11
|
@@ -2,20 +2,13 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { Trigger } from '@dxos/async';
|
|
6
6
|
import { Context, Resource } from '@dxos/context';
|
|
7
7
|
import { getCredentialAssertion, type CredentialProcessor } from '@dxos/credentials';
|
|
8
|
-
import { failUndefined
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
MeshEchoReplicator,
|
|
13
|
-
MetadataStore,
|
|
14
|
-
SpaceManager,
|
|
15
|
-
valueEncoding,
|
|
16
|
-
} from '@dxos/echo-pipeline';
|
|
17
|
-
import { createChainEdgeIdentity, createEphemeralEdgeIdentity } from '@dxos/edge-client';
|
|
18
|
-
import type { EdgeHttpClient, EdgeConnection, EdgeIdentity } from '@dxos/edge-client';
|
|
8
|
+
import { failUndefined } from '@dxos/debug';
|
|
9
|
+
import { EchoEdgeReplicator, EchoHost } from '@dxos/echo-db';
|
|
10
|
+
import { MeshEchoReplicator, MetadataStore, SpaceManager, valueEncoding } from '@dxos/echo-pipeline';
|
|
11
|
+
import type { EdgeConnection } from '@dxos/edge-client';
|
|
19
12
|
import { FeedFactory, FeedStore } from '@dxos/feed-store';
|
|
20
13
|
import { invariant } from '@dxos/invariant';
|
|
21
14
|
import { Keyring } from '@dxos/keyring';
|
|
@@ -30,20 +23,19 @@ import { type Runtime } from '@dxos/protocols/proto/dxos/config';
|
|
|
30
23
|
import type { FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';
|
|
31
24
|
import { type Credential, type ProfileDocument } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
32
25
|
import { type Storage } from '@dxos/random-access-storage';
|
|
26
|
+
import type { TeleportParams } from '@dxos/teleport';
|
|
33
27
|
import { BlobStore } from '@dxos/teleport-extension-object-sync';
|
|
34
28
|
import { trace as Trace } from '@dxos/tracing';
|
|
35
29
|
import { safeInstanceof } from '@dxos/util';
|
|
36
30
|
|
|
37
|
-
import { EdgeAgentManager } from '../agents';
|
|
38
31
|
import {
|
|
39
32
|
IdentityManager,
|
|
40
33
|
type CreateIdentityOptions,
|
|
41
|
-
type
|
|
34
|
+
type IdentityManagerRuntimeParams,
|
|
42
35
|
type JoinIdentityParams,
|
|
43
36
|
} from '../identity';
|
|
44
37
|
import {
|
|
45
38
|
DeviceInvitationProtocol,
|
|
46
|
-
type InvitationConnectionParams,
|
|
47
39
|
InvitationsHandler,
|
|
48
40
|
InvitationsManager,
|
|
49
41
|
SpaceInvitationProtocol,
|
|
@@ -51,12 +43,9 @@ import {
|
|
|
51
43
|
} from '../invitations';
|
|
52
44
|
import { DataSpaceManager, type DataSpaceManagerRuntimeParams, type SigningContext } from '../spaces';
|
|
53
45
|
|
|
54
|
-
export type ServiceContextRuntimeParams =
|
|
55
|
-
IdentityManagerParams,
|
|
56
|
-
'devicePresenceOfflineTimeout' | 'devicePresenceAnnounceInterval'
|
|
57
|
-
> &
|
|
46
|
+
export type ServiceContextRuntimeParams = IdentityManagerRuntimeParams &
|
|
58
47
|
DataSpaceManagerRuntimeParams & {
|
|
59
|
-
invitationConnectionDefaultParams?:
|
|
48
|
+
invitationConnectionDefaultParams?: Partial<TeleportParams>;
|
|
60
49
|
disableP2pReplication?: boolean;
|
|
61
50
|
};
|
|
62
51
|
/**
|
|
@@ -67,8 +56,6 @@ export type ServiceContextRuntimeParams = Pick<
|
|
|
67
56
|
@safeInstanceof('dxos.client-services.ServiceContext')
|
|
68
57
|
@Trace.resource()
|
|
69
58
|
export class ServiceContext extends Resource {
|
|
70
|
-
private readonly _edgeIdentityUpdateMutex = new Mutex();
|
|
71
|
-
|
|
72
59
|
public readonly initialized = new Trigger();
|
|
73
60
|
public readonly metadataStore: MetadataStore;
|
|
74
61
|
public readonly blobStore: BlobStore;
|
|
@@ -84,7 +71,6 @@ export class ServiceContext extends Resource {
|
|
|
84
71
|
|
|
85
72
|
// Initialized after identity is initialized.
|
|
86
73
|
public dataSpaceManager?: DataSpaceManager;
|
|
87
|
-
public edgeAgentManager?: EdgeAgentManager;
|
|
88
74
|
|
|
89
75
|
private readonly _handlerFactories = new Map<
|
|
90
76
|
Invitation.Kind,
|
|
@@ -101,7 +87,6 @@ export class ServiceContext extends Resource {
|
|
|
101
87
|
public readonly networkManager: SwarmNetworkManager,
|
|
102
88
|
public readonly signalManager: SignalManager,
|
|
103
89
|
private readonly _edgeConnection: EdgeConnection | undefined,
|
|
104
|
-
private readonly _edgeHttpClient: EdgeHttpClient | undefined,
|
|
105
90
|
public readonly _runtimeParams?: ServiceContextRuntimeParams,
|
|
106
91
|
private readonly _edgeFeatures?: Runtime.Client.EdgeFeatures,
|
|
107
92
|
) {
|
|
@@ -131,16 +116,32 @@ export class ServiceContext extends Resource {
|
|
|
131
116
|
disableP2pReplication: this._runtimeParams?.disableP2pReplication,
|
|
132
117
|
});
|
|
133
118
|
|
|
134
|
-
this.identityManager = new IdentityManager(
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
119
|
+
this.identityManager = new IdentityManager(
|
|
120
|
+
this.metadataStore,
|
|
121
|
+
this.keyring,
|
|
122
|
+
this.feedStore,
|
|
123
|
+
this.spaceManager,
|
|
124
|
+
this._runtimeParams as IdentityManagerRuntimeParams,
|
|
125
|
+
{
|
|
126
|
+
onIdentityConstruction: (identity) => {
|
|
127
|
+
if (this._edgeConnection) {
|
|
128
|
+
log.info('Setting identity on edge connection', {
|
|
129
|
+
identity: identity.identityKey.toHex(),
|
|
130
|
+
oldIdentity: this._edgeConnection.identityKey,
|
|
131
|
+
swarms: this.networkManager.topics,
|
|
132
|
+
});
|
|
133
|
+
this._edgeConnection.setIdentity({
|
|
134
|
+
peerKey: identity.deviceKey.toHex(),
|
|
135
|
+
identityKey: identity.identityKey.toHex(),
|
|
136
|
+
});
|
|
137
|
+
this.networkManager.setPeerInfo({
|
|
138
|
+
identityKey: identity.identityKey.toHex(),
|
|
139
|
+
peerKey: identity.deviceKey.toHex(),
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
);
|
|
144
145
|
|
|
145
146
|
this.echoHost = new EchoHost({ kv: this.level });
|
|
146
147
|
|
|
@@ -148,7 +149,6 @@ export class ServiceContext extends Resource {
|
|
|
148
149
|
|
|
149
150
|
this.invitations = new InvitationsHandler(
|
|
150
151
|
this.networkManager, //
|
|
151
|
-
this._edgeHttpClient,
|
|
152
152
|
_runtimeParams?.invitationConnectionDefaultParams,
|
|
153
153
|
);
|
|
154
154
|
this.invitationsManager = new InvitationsManager(
|
|
@@ -185,11 +185,6 @@ export class ServiceContext extends Resource {
|
|
|
185
185
|
|
|
186
186
|
log('opening...');
|
|
187
187
|
log.trace('dxos.sdk.service-context.open', trace.begin({ id: this._instanceId }));
|
|
188
|
-
|
|
189
|
-
await this.identityManager.open(ctx);
|
|
190
|
-
|
|
191
|
-
await this._setNetworkIdentity();
|
|
192
|
-
|
|
193
188
|
await this._edgeConnection?.open();
|
|
194
189
|
await this.signalManager.open();
|
|
195
190
|
await this.networkManager.open();
|
|
@@ -205,9 +200,9 @@ export class ServiceContext extends Resource {
|
|
|
205
200
|
|
|
206
201
|
await this.metadataStore.load();
|
|
207
202
|
await this.spaceManager.open();
|
|
203
|
+
await this.identityManager.open(ctx);
|
|
208
204
|
|
|
209
205
|
if (this.identityManager.identity) {
|
|
210
|
-
await this.identityManager.identity.joinNetwork();
|
|
211
206
|
await this._initialize(ctx);
|
|
212
207
|
}
|
|
213
208
|
|
|
@@ -224,7 +219,6 @@ export class ServiceContext extends Resource {
|
|
|
224
219
|
await this.identityManager.identity.space.spaceState.removeCredentialProcessor(this._deviceSpaceSync);
|
|
225
220
|
}
|
|
226
221
|
await this.dataSpaceManager?.close();
|
|
227
|
-
await this.edgeAgentManager?.close();
|
|
228
222
|
await this.identityManager.close();
|
|
229
223
|
await this.spaceManager.close();
|
|
230
224
|
await this.feedStore.close();
|
|
@@ -240,8 +234,6 @@ export class ServiceContext extends Resource {
|
|
|
240
234
|
|
|
241
235
|
async createIdentity(params: CreateIdentityOptions = {}) {
|
|
242
236
|
const identity = await this.identityManager.createIdentity(params);
|
|
243
|
-
await this._setNetworkIdentity();
|
|
244
|
-
await identity.joinNetwork();
|
|
245
237
|
await this._initialize(new Context());
|
|
246
238
|
return identity;
|
|
247
239
|
}
|
|
@@ -263,10 +255,7 @@ export class ServiceContext extends Resource {
|
|
|
263
255
|
}
|
|
264
256
|
|
|
265
257
|
private async _acceptIdentity(params: JoinIdentityParams) {
|
|
266
|
-
const
|
|
267
|
-
await this._setNetworkIdentity({ deviceCredential: params.authorizedDeviceCredential! });
|
|
268
|
-
await identity.joinNetwork();
|
|
269
|
-
await this.identityManager.acceptIdentity(identity, identityRecord, params.deviceProfile);
|
|
258
|
+
const identity = await this.identityManager.acceptIdentity(params);
|
|
270
259
|
await this._initialize(new Context());
|
|
271
260
|
return identity;
|
|
272
261
|
}
|
|
@@ -303,7 +292,6 @@ export class ServiceContext extends Resource {
|
|
|
303
292
|
echoHost: this.echoHost,
|
|
304
293
|
invitationsManager: this.invitationsManager,
|
|
305
294
|
edgeConnection: this._edgeConnection,
|
|
306
|
-
edgeHttpClient: this._edgeHttpClient,
|
|
307
295
|
echoEdgeReplicator: this._echoEdgeReplicator,
|
|
308
296
|
meshReplicator: this._meshReplicator,
|
|
309
297
|
runtimeParams: this._runtimeParams as DataSpaceManagerRuntimeParams,
|
|
@@ -311,14 +299,6 @@ export class ServiceContext extends Resource {
|
|
|
311
299
|
});
|
|
312
300
|
await this.dataSpaceManager.open();
|
|
313
301
|
|
|
314
|
-
this.edgeAgentManager = new EdgeAgentManager(
|
|
315
|
-
this._edgeFeatures,
|
|
316
|
-
this._edgeHttpClient,
|
|
317
|
-
this.dataSpaceManager,
|
|
318
|
-
identity,
|
|
319
|
-
);
|
|
320
|
-
await this.edgeAgentManager.open();
|
|
321
|
-
|
|
322
302
|
this._handlerFactories.set(Invitation.Kind.SPACE, (invitation) => {
|
|
323
303
|
invariant(this.dataSpaceManager, 'dataSpaceManager not initialized yet');
|
|
324
304
|
return new SpaceInvitationProtocol(this.dataSpaceManager, signingContext, this.keyring, invitation.spaceKey);
|
|
@@ -358,51 +338,4 @@ export class ServiceContext extends Resource {
|
|
|
358
338
|
|
|
359
339
|
await identity.space.spaceState.addCredentialProcessor(this._deviceSpaceSync);
|
|
360
340
|
}
|
|
361
|
-
|
|
362
|
-
private async _setNetworkIdentity(params?: { deviceCredential: Credential }) {
|
|
363
|
-
using _ = await this._edgeIdentityUpdateMutex.acquire();
|
|
364
|
-
|
|
365
|
-
let edgeIdentity: EdgeIdentity;
|
|
366
|
-
const identity = this.identityManager.identity;
|
|
367
|
-
if (identity) {
|
|
368
|
-
log.info('Setting identity on edge connection', {
|
|
369
|
-
identity: identity.identityKey.toHex(),
|
|
370
|
-
swarms: this.networkManager.topics,
|
|
371
|
-
});
|
|
372
|
-
if (params?.deviceCredential) {
|
|
373
|
-
edgeIdentity = await createChainEdgeIdentity(
|
|
374
|
-
identity.signer,
|
|
375
|
-
identity.identityKey,
|
|
376
|
-
identity.deviceKey,
|
|
377
|
-
{ credential: params.deviceCredential },
|
|
378
|
-
[], // TODO(dmaretskyi): Service access credentials.
|
|
379
|
-
);
|
|
380
|
-
} else {
|
|
381
|
-
// TODO: throw here or from identity if device chain can't be loaded, to avoid indefinite hangup
|
|
382
|
-
await warnAfterTimeout(10_000, 'Waiting for identity to be ready for edge connection', async () => {
|
|
383
|
-
await identity.ready();
|
|
384
|
-
});
|
|
385
|
-
|
|
386
|
-
invariant(identity.deviceCredentialChain);
|
|
387
|
-
|
|
388
|
-
edgeIdentity = await createChainEdgeIdentity(
|
|
389
|
-
identity.signer,
|
|
390
|
-
identity.identityKey,
|
|
391
|
-
identity.deviceKey,
|
|
392
|
-
identity.deviceCredentialChain,
|
|
393
|
-
[], // TODO(dmaretskyi): Service access credentials.
|
|
394
|
-
);
|
|
395
|
-
}
|
|
396
|
-
} else {
|
|
397
|
-
edgeIdentity = await createEphemeralEdgeIdentity();
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
if (this._edgeConnection) {
|
|
401
|
-
this._edgeConnection.setIdentity(edgeIdentity);
|
|
402
|
-
}
|
|
403
|
-
this.networkManager.setPeerInfo({
|
|
404
|
-
identityKey: edgeIdentity.identityKey,
|
|
405
|
-
peerKey: edgeIdentity.peerKey,
|
|
406
|
-
});
|
|
407
|
-
}
|
|
408
341
|
}
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import chai, { expect } from 'chai';
|
|
6
|
+
import chaiAsPromised from 'chai-as-promised';
|
|
5
7
|
import { rmSync } from 'node:fs';
|
|
6
|
-
import { afterEach, onTestFinished, describe, expect, test } from 'vitest';
|
|
7
8
|
|
|
8
9
|
import { asyncTimeout, latch, Trigger } from '@dxos/async';
|
|
9
10
|
import { Config } from '@dxos/config';
|
|
@@ -13,10 +14,13 @@ import { type PublicKey } from '@dxos/keys';
|
|
|
13
14
|
import { MemorySignalManagerContext } from '@dxos/messaging';
|
|
14
15
|
import { type Identity } from '@dxos/protocols/proto/dxos/client/services';
|
|
15
16
|
import { type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
17
|
+
import { afterTest, describe, test } from '@dxos/test';
|
|
16
18
|
import { isNode } from '@dxos/util';
|
|
17
19
|
|
|
18
20
|
import { createMockCredential, createServiceHost } from '../testing';
|
|
19
21
|
|
|
22
|
+
chai.use(chaiAsPromised);
|
|
23
|
+
|
|
20
24
|
describe('ClientServicesHost', () => {
|
|
21
25
|
const dataRoot = '/tmp/dxos/client-services/service-host/storage';
|
|
22
26
|
|
|
@@ -34,7 +38,7 @@ describe('ClientServicesHost', () => {
|
|
|
34
38
|
test('queryCredentials', async () => {
|
|
35
39
|
const host = createServiceHost(new Config(), new MemorySignalManagerContext());
|
|
36
40
|
await host.open(new Context());
|
|
37
|
-
|
|
41
|
+
afterTest(() => host.close());
|
|
38
42
|
|
|
39
43
|
await host.services.IdentityService!.createIdentity({});
|
|
40
44
|
const { spaceKey } = await host.services.SpacesService!.createSpace();
|
|
@@ -45,7 +49,7 @@ describe('ClientServicesHost', () => {
|
|
|
45
49
|
tick();
|
|
46
50
|
// console.log(credential);
|
|
47
51
|
});
|
|
48
|
-
|
|
52
|
+
afterTest(() => stream.close());
|
|
49
53
|
|
|
50
54
|
await done();
|
|
51
55
|
});
|
|
@@ -53,7 +57,7 @@ describe('ClientServicesHost', () => {
|
|
|
53
57
|
test('write and query credentials', async () => {
|
|
54
58
|
const host = createServiceHost(new Config(), new MemorySignalManagerContext());
|
|
55
59
|
await host.open(new Context());
|
|
56
|
-
|
|
60
|
+
afterTest(() => host.close());
|
|
57
61
|
|
|
58
62
|
await host.services.IdentityService!.createIdentity({});
|
|
59
63
|
|
|
@@ -82,7 +86,7 @@ describe('ClientServicesHost', () => {
|
|
|
82
86
|
queriedCredential.wake(credential);
|
|
83
87
|
}
|
|
84
88
|
});
|
|
85
|
-
|
|
89
|
+
afterTest(() => credentials.close());
|
|
86
90
|
|
|
87
91
|
await queriedCredential.wait();
|
|
88
92
|
});
|
|
@@ -90,7 +94,7 @@ describe('ClientServicesHost', () => {
|
|
|
90
94
|
test('sign presentation', async () => {
|
|
91
95
|
const host = createServiceHost(new Config(), new MemorySignalManagerContext());
|
|
92
96
|
await host.open(new Context());
|
|
93
|
-
|
|
97
|
+
afterTest(() => host.close());
|
|
94
98
|
|
|
95
99
|
await host.services.IdentityService!.createIdentity({});
|
|
96
100
|
|
|
@@ -143,9 +147,9 @@ describe('ClientServicesHost', () => {
|
|
|
143
147
|
trigger.wake(identity.identity);
|
|
144
148
|
}
|
|
145
149
|
});
|
|
146
|
-
await expect(asyncTimeout(trigger.wait(), 200)).
|
|
150
|
+
await expect(asyncTimeout(trigger.wait(), 200)).to.be.rejectedWith();
|
|
147
151
|
await stream?.close();
|
|
148
152
|
await host.close();
|
|
149
153
|
}
|
|
150
|
-
});
|
|
154
|
+
}).onlyEnvironments('nodejs', 'chromium', 'firefox');
|
|
151
155
|
});
|
|
@@ -6,7 +6,7 @@ import { Event, synchronized } from '@dxos/async';
|
|
|
6
6
|
import { clientServiceBundle, type ClientServices } from '@dxos/client-protocol';
|
|
7
7
|
import { type Config } from '@dxos/config';
|
|
8
8
|
import { Context } from '@dxos/context';
|
|
9
|
-
import { EdgeClient,
|
|
9
|
+
import { EdgeClient, type EdgeConnection } from '@dxos/edge-client';
|
|
10
10
|
import { invariant } from '@dxos/invariant';
|
|
11
11
|
import { PublicKey } from '@dxos/keys';
|
|
12
12
|
import { type LevelDB } from '@dxos/kv-store';
|
|
@@ -15,7 +15,7 @@ import { EdgeSignalManager, WebsocketSignalManager, type SignalManager } from '@
|
|
|
15
15
|
import {
|
|
16
16
|
SwarmNetworkManager,
|
|
17
17
|
createIceProvider,
|
|
18
|
-
|
|
18
|
+
createSimplePeerTransportFactory,
|
|
19
19
|
type TransportFactory,
|
|
20
20
|
} from '@dxos/network-manager';
|
|
21
21
|
import { trace } from '@dxos/protocols';
|
|
@@ -26,13 +26,12 @@ import { WebsocketRpcClient } from '@dxos/websocket-rpc';
|
|
|
26
26
|
|
|
27
27
|
import { ServiceContext, type ServiceContextRuntimeParams } from './service-context';
|
|
28
28
|
import { ServiceRegistry } from './service-registry';
|
|
29
|
-
import { EdgeAgentServiceImpl } from '../agents';
|
|
30
29
|
import { DevicesServiceImpl } from '../devices';
|
|
31
30
|
import { DevtoolsHostEvents, DevtoolsServiceImpl } from '../devtools';
|
|
32
31
|
import {
|
|
32
|
+
type CollectDiagnosticsBroadcastHandler,
|
|
33
33
|
createCollectDiagnosticsBroadcastHandler,
|
|
34
34
|
createDiagnostics,
|
|
35
|
-
type CollectDiagnosticsBroadcastHandler,
|
|
36
35
|
} from '../diagnostics';
|
|
37
36
|
import { IdentityServiceImpl, type CreateIdentityOptions } from '../identity';
|
|
38
37
|
import { ContactsServiceImpl } from '../identity/contacts-service';
|
|
@@ -90,7 +89,6 @@ export class ClientServicesHost {
|
|
|
90
89
|
private _callbacks?: ClientServicesHostCallbacks;
|
|
91
90
|
private _devtoolsProxy?: WebsocketRpcClient<{}, ClientServices>;
|
|
92
91
|
private _edgeConnection?: EdgeConnection = undefined;
|
|
93
|
-
private _edgeHttpClient?: EdgeHttpClient = undefined;
|
|
94
92
|
|
|
95
93
|
private _serviceContext!: ServiceContext;
|
|
96
94
|
private readonly _runtimeParams: ServiceContextRuntimeParams;
|
|
@@ -214,13 +212,13 @@ export class ClientServicesHost {
|
|
|
214
212
|
|
|
215
213
|
const edgeEndpoint = config?.get('runtime.services.edge.url');
|
|
216
214
|
if (edgeEndpoint) {
|
|
217
|
-
|
|
218
|
-
this.
|
|
215
|
+
const randomKey = PublicKey.random().toHex();
|
|
216
|
+
this._edgeConnection = new EdgeClient(randomKey, randomKey, { socketEndpoint: edgeEndpoint });
|
|
219
217
|
}
|
|
220
218
|
|
|
221
219
|
const {
|
|
222
220
|
connectionLog = true,
|
|
223
|
-
transportFactory =
|
|
221
|
+
transportFactory = createSimplePeerTransportFactory(
|
|
224
222
|
{ iceServers: this._config?.get('runtime.services.ice') },
|
|
225
223
|
this._config?.get('runtime.services.iceProviders') &&
|
|
226
224
|
createIceProvider(this._config!.get('runtime.services.iceProviders')!),
|
|
@@ -280,7 +278,6 @@ export class ClientServicesHost {
|
|
|
280
278
|
this._networkManager,
|
|
281
279
|
this._signalManager,
|
|
282
280
|
this._edgeConnection,
|
|
283
|
-
this._edgeHttpClient,
|
|
284
281
|
this._runtimeParams,
|
|
285
282
|
this._config.get('runtime.client.edgeFeatures'),
|
|
286
283
|
);
|
|
@@ -290,11 +287,6 @@ export class ClientServicesHost {
|
|
|
290
287
|
return this._serviceContext.dataSpaceManager!;
|
|
291
288
|
};
|
|
292
289
|
|
|
293
|
-
const agentManagerProvider = async () => {
|
|
294
|
-
await this._serviceContext.initialized.wait();
|
|
295
|
-
return this._serviceContext.edgeAgentManager!;
|
|
296
|
-
};
|
|
297
|
-
|
|
298
290
|
const identityService = new IdentityServiceImpl(
|
|
299
291
|
this._serviceContext.identityManager,
|
|
300
292
|
this._serviceContext.keyring,
|
|
@@ -336,8 +328,6 @@ export class ClientServicesHost {
|
|
|
336
328
|
config: this._config,
|
|
337
329
|
context: this._serviceContext,
|
|
338
330
|
}),
|
|
339
|
-
|
|
340
|
-
EdgeAgentService: new EdgeAgentServiceImpl(agentManagerProvider),
|
|
341
331
|
});
|
|
342
332
|
|
|
343
333
|
await this._serviceContext.open(ctx);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { expect } from 'chai';
|
|
6
6
|
|
|
7
7
|
import { Event } from '@dxos/async';
|
|
8
8
|
import { type ClientServices } from '@dxos/client-protocol';
|
|
@@ -12,6 +12,7 @@ import { log } from '@dxos/log';
|
|
|
12
12
|
import { schema } from '@dxos/protocols/proto';
|
|
13
13
|
import { type SystemService, SystemStatus } from '@dxos/protocols/proto/dxos/client/services';
|
|
14
14
|
import { createLinkedPorts, createProtoRpcPeer, createServiceBundle } from '@dxos/rpc';
|
|
15
|
+
import { describe, test } from '@dxos/test';
|
|
15
16
|
|
|
16
17
|
import { ServiceRegistry } from './service-registry';
|
|
17
18
|
import { SystemServiceImpl } from '../system';
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { expect } from 'chai';
|
|
6
6
|
|
|
7
7
|
import { asyncTimeout, latch } from '@dxos/async';
|
|
8
8
|
import { createAdmissionCredentials } from '@dxos/credentials';
|
|
@@ -10,7 +10,7 @@ import { AuthStatus } from '@dxos/echo-pipeline';
|
|
|
10
10
|
import { writeMessages } from '@dxos/feed-store';
|
|
11
11
|
import { log } from '@dxos/log';
|
|
12
12
|
import { SpaceState } from '@dxos/protocols/proto/dxos/client/services';
|
|
13
|
-
import { openAndClose } from '@dxos/test
|
|
13
|
+
import { describe, openAndClose, test } from '@dxos/test';
|
|
14
14
|
|
|
15
15
|
import { TestBuilder, type TestPeer } from '../testing';
|
|
16
16
|
|
|
@@ -14,11 +14,8 @@ import {
|
|
|
14
14
|
type DelegateInvitationCredential,
|
|
15
15
|
type MemberInfo,
|
|
16
16
|
} from '@dxos/credentials';
|
|
17
|
+
import { convertLegacyReferences, findInlineObjectOfType, type EchoEdgeReplicator, type EchoHost } from '@dxos/echo-db';
|
|
17
18
|
import {
|
|
18
|
-
convertLegacyReferences,
|
|
19
|
-
findInlineObjectOfType,
|
|
20
|
-
type EchoEdgeReplicator,
|
|
21
|
-
type EchoHost,
|
|
22
19
|
AuthStatus,
|
|
23
20
|
CredentialServerExtension,
|
|
24
21
|
type MeshEchoReplicator,
|
|
@@ -35,8 +32,8 @@ import {
|
|
|
35
32
|
type ObjectStructure,
|
|
36
33
|
type SpaceDoc,
|
|
37
34
|
} from '@dxos/echo-protocol';
|
|
38
|
-
import { TYPE_PROPERTIES,
|
|
39
|
-
import type { EdgeConnection
|
|
35
|
+
import { TYPE_PROPERTIES, generateEchoId, getTypeReference } from '@dxos/echo-schema';
|
|
36
|
+
import type { EdgeConnection } from '@dxos/edge-client';
|
|
40
37
|
import { writeMessages, type FeedStore } from '@dxos/feed-store';
|
|
41
38
|
import { invariant } from '@dxos/invariant';
|
|
42
39
|
import { type Keyring } from '@dxos/keyring';
|
|
@@ -46,7 +43,7 @@ import { AlreadyJoinedError, trace as Trace } from '@dxos/protocols';
|
|
|
46
43
|
import { Invitation, SpaceState } from '@dxos/protocols/proto/dxos/client/services';
|
|
47
44
|
import { type Runtime } from '@dxos/protocols/proto/dxos/config';
|
|
48
45
|
import { type FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';
|
|
49
|
-
import { type SpaceMetadata
|
|
46
|
+
import { type SpaceMetadata } from '@dxos/protocols/proto/dxos/echo/metadata';
|
|
50
47
|
import { SpaceMember, type Credential, type ProfileDocument } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
51
48
|
import { type DelegateSpaceInvitation } from '@dxos/protocols/proto/dxos/halo/invitations';
|
|
52
49
|
import { type PeerState } from '@dxos/protocols/proto/dxos/mesh/presence';
|
|
@@ -110,7 +107,6 @@ export type DataSpaceManagerParams = {
|
|
|
110
107
|
echoHost: EchoHost;
|
|
111
108
|
invitationsManager: InvitationsManager;
|
|
112
109
|
edgeConnection?: EdgeConnection;
|
|
113
|
-
edgeHttpClient?: EdgeHttpClient;
|
|
114
110
|
meshReplicator?: MeshEchoReplicator;
|
|
115
111
|
echoEdgeReplicator?: EchoEdgeReplicator;
|
|
116
112
|
runtimeParams?: DataSpaceManagerRuntimeParams;
|
|
@@ -120,7 +116,6 @@ export type DataSpaceManagerParams = {
|
|
|
120
116
|
export type DataSpaceManagerRuntimeParams = {
|
|
121
117
|
spaceMemberPresenceAnnounceInterval?: number;
|
|
122
118
|
spaceMemberPresenceOfflineTimeout?: number;
|
|
123
|
-
activeEdgeNotarizationPollingInterval?: number;
|
|
124
119
|
disableP2pReplication?: boolean;
|
|
125
120
|
};
|
|
126
121
|
|
|
@@ -140,7 +135,6 @@ export class DataSpaceManager extends Resource {
|
|
|
140
135
|
private readonly _echoHost: EchoHost;
|
|
141
136
|
private readonly _invitationsManager: InvitationsManager;
|
|
142
137
|
private readonly _edgeConnection?: EdgeConnection = undefined;
|
|
143
|
-
private readonly _edgeHttpClient?: EdgeHttpClient = undefined;
|
|
144
138
|
private readonly _edgeFeatures?: Runtime.Client.EdgeFeatures = undefined;
|
|
145
139
|
private readonly _meshReplicator?: MeshEchoReplicator = undefined;
|
|
146
140
|
private readonly _echoEdgeReplicator?: EchoEdgeReplicator = undefined;
|
|
@@ -160,7 +154,6 @@ export class DataSpaceManager extends Resource {
|
|
|
160
154
|
this._edgeConnection = params.edgeConnection;
|
|
161
155
|
this._edgeFeatures = params.edgeFeatures;
|
|
162
156
|
this._echoEdgeReplicator = params.echoEdgeReplicator;
|
|
163
|
-
this._edgeHttpClient = params.edgeHttpClient;
|
|
164
157
|
this._runtimeParams = params.runtimeParams;
|
|
165
158
|
|
|
166
159
|
trace.diagnostic({
|
|
@@ -297,7 +290,7 @@ export class DataSpaceManager extends Resource {
|
|
|
297
290
|
},
|
|
298
291
|
};
|
|
299
292
|
|
|
300
|
-
const propertiesId =
|
|
293
|
+
const propertiesId = generateEchoId();
|
|
301
294
|
document.change((doc: SpaceDoc) => {
|
|
302
295
|
setDeep(doc, ['objects', propertiesId], properties);
|
|
303
296
|
});
|
|
@@ -395,26 +388,6 @@ export class DataSpaceManager extends Resource {
|
|
|
395
388
|
});
|
|
396
389
|
}
|
|
397
390
|
|
|
398
|
-
async setSpaceEdgeReplicationSetting(spaceKey: PublicKey, setting: EdgeReplicationSetting) {
|
|
399
|
-
const space = this._spaces.get(spaceKey);
|
|
400
|
-
invariant(space, 'Space not found.');
|
|
401
|
-
|
|
402
|
-
await this._metadataStore.setSpaceEdgeReplicationSetting(spaceKey, setting);
|
|
403
|
-
|
|
404
|
-
if (space.isOpen) {
|
|
405
|
-
switch (setting) {
|
|
406
|
-
case EdgeReplicationSetting.DISABLED:
|
|
407
|
-
await this._echoEdgeReplicator?.disconnectFromSpace(space.id);
|
|
408
|
-
break;
|
|
409
|
-
case EdgeReplicationSetting.ENABLED:
|
|
410
|
-
await this._echoEdgeReplicator?.connectToSpace(space.id);
|
|
411
|
-
break;
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
space.stateUpdate.emit();
|
|
416
|
-
}
|
|
417
|
-
|
|
418
391
|
private async _constructSpace(metadata: SpaceMetadata) {
|
|
419
392
|
log('construct space', { metadata });
|
|
420
393
|
const gossip = new Gossip({
|
|
@@ -506,23 +479,13 @@ export class DataSpaceManager extends Resource {
|
|
|
506
479
|
},
|
|
507
480
|
cache: metadata.cache,
|
|
508
481
|
edgeConnection: this._edgeConnection,
|
|
509
|
-
edgeHttpClient: this._edgeHttpClient,
|
|
510
482
|
edgeFeatures: this._edgeFeatures,
|
|
511
|
-
activeEdgeNotarizationPollingInterval: this._runtimeParams?.activeEdgeNotarizationPollingInterval,
|
|
512
483
|
});
|
|
513
484
|
dataSpace.postOpen.append(async () => {
|
|
514
|
-
|
|
515
|
-
if (setting === EdgeReplicationSetting.ENABLED) {
|
|
516
|
-
await this._echoEdgeReplicator?.connectToSpace(dataSpace.id);
|
|
517
|
-
} else if (this._echoEdgeReplicator) {
|
|
518
|
-
log('not connecting EchoEdgeReplicator because of EdgeReplicationSetting', { spaceId: dataSpace.id });
|
|
519
|
-
}
|
|
485
|
+
await this._echoEdgeReplicator?.connectToSpace(dataSpace.id);
|
|
520
486
|
});
|
|
521
487
|
dataSpace.preClose.append(async () => {
|
|
522
|
-
|
|
523
|
-
if (setting === EdgeReplicationSetting.ENABLED) {
|
|
524
|
-
await this._echoEdgeReplicator?.disconnectFromSpace(dataSpace.id);
|
|
525
|
-
}
|
|
488
|
+
await this._echoEdgeReplicator?.disconnectFromSpace(dataSpace.id);
|
|
526
489
|
});
|
|
527
490
|
|
|
528
491
|
presence.newPeer.on((peerState) => {
|