@dxos/client-services 0.5.9-main.cb71230 → 0.5.9-main.d63ef8d

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.
Files changed (53) hide show
  1. package/dist/lib/browser/{chunk-HSM5JUN6.mjs → chunk-C2VXW65X.mjs} +1101 -805
  2. package/dist/lib/browser/chunk-C2VXW65X.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +1 -3
  4. package/dist/lib/browser/index.mjs.map +1 -1
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/packlets/testing/index.mjs +11 -11
  7. package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
  8. package/dist/lib/node/{chunk-4OGPGXOU.cjs → chunk-OD7BTUYY.cjs} +1399 -1110
  9. package/dist/lib/node/chunk-OD7BTUYY.cjs.map +7 -0
  10. package/dist/lib/node/index.cjs +41 -43
  11. package/dist/lib/node/index.cjs.map +1 -1
  12. package/dist/lib/node/meta.json +1 -1
  13. package/dist/lib/node/packlets/testing/index.cjs +17 -17
  14. package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
  15. package/dist/types/src/packlets/identity/default-space-state-machine.d.ts +19 -0
  16. package/dist/types/src/packlets/identity/default-space-state-machine.d.ts.map +1 -0
  17. package/dist/types/src/packlets/identity/identity-service.d.ts +14 -7
  18. package/dist/types/src/packlets/identity/identity-service.d.ts.map +1 -1
  19. package/dist/types/src/packlets/identity/identity.d.ts +4 -1
  20. package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
  21. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  22. package/dist/types/src/packlets/services/service-host.d.ts +1 -1
  23. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  24. package/dist/types/src/packlets/spaces/automerge-space-state.d.ts +4 -1
  25. package/dist/types/src/packlets/spaces/automerge-space-state.d.ts.map +1 -1
  26. package/dist/types/src/packlets/spaces/data-space-manager.d.ts +5 -3
  27. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  28. package/dist/types/src/packlets/spaces/data-space.d.ts +9 -9
  29. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  30. package/dist/types/src/packlets/spaces/epoch-migrations.d.ts +23 -0
  31. package/dist/types/src/packlets/spaces/epoch-migrations.d.ts.map +1 -0
  32. package/dist/types/src/packlets/spaces/spaces-service.d.ts +2 -2
  33. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  34. package/dist/types/src/packlets/testing/test-builder.d.ts +8 -6
  35. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  36. package/dist/types/src/version.d.ts +1 -1
  37. package/package.json +36 -36
  38. package/src/packlets/identity/default-space-state-machine.ts +44 -0
  39. package/src/packlets/identity/identity-service.test.ts +35 -5
  40. package/src/packlets/identity/identity-service.ts +76 -8
  41. package/src/packlets/identity/identity.ts +25 -2
  42. package/src/packlets/services/service-context.ts +1 -4
  43. package/src/packlets/services/service-host.ts +13 -40
  44. package/src/packlets/spaces/automerge-space-state.ts +11 -2
  45. package/src/packlets/spaces/data-space-manager.test.ts +46 -1
  46. package/src/packlets/spaces/data-space-manager.ts +81 -31
  47. package/src/packlets/spaces/data-space.ts +82 -149
  48. package/src/packlets/spaces/epoch-migrations.ts +135 -0
  49. package/src/packlets/spaces/spaces-service.ts +4 -2
  50. package/src/packlets/testing/test-builder.ts +12 -10
  51. package/src/version.ts +1 -1
  52. package/dist/lib/browser/chunk-HSM5JUN6.mjs.map +0 -7
  53. package/dist/lib/node/chunk-4OGPGXOU.cjs.map +0 -7
@@ -1 +1 @@
1
- {"version":3,"file":"spaces-service.d.ts","sourceRoot":"","sources":["../../../../../src/packlets/spaces/spaces-service.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAG9C,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAWxD,OAAO,EAGL,KAAK,kBAAkB,EACv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AgB,CAAC,CAAC;IAGtE,WAAW,IAAI,OAAO,CAAC,KAAK,CAAC;IAQ7B,WAAW,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,kBAAkB;IAmBnD,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC;IA0BvE,WAAW,IAAI,MAAM,CAAC,mBAAmB,CAAC;IAmDpC,WAAW,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,kBAAkB;IAMpE,iBAAiB,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,wBAAwB;IAajE,gBAAgB,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,uBAAuB,GAAG,MAAM,CAAC,UAAU,CAAC;IAmB7E,gBAAgB,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,EAAE,uBAAuB;IAmBnE,WAAW,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,gBAAgB,EAAE,EAAE,kBAAkB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAO9G,OAAO,CAAC,eAAe;IA6CvB,OAAO,CAAC,gBAAgB;YASV,cAAc;CAS7B"}
@@ -9,12 +9,13 @@ import { SwarmNetworkManager } from '@dxos/network-manager';
9
9
  import { StorageType, type Storage } from '@dxos/random-access-storage';
10
10
  import { BlobStore } from '@dxos/teleport-extension-object-sync';
11
11
  import { InvitationsManager } from '../invitations';
12
- import { ClientServicesHost, ServiceContext } from '../services';
13
- import { DataSpaceManager, type SigningContext } from '../spaces';
12
+ import { ClientServicesHost, ServiceContext, type ServiceContextRuntimeParams } from '../services';
13
+ import { DataSpaceManager, type DataSpaceManagerRuntimeParams, type SigningContext } from '../spaces';
14
14
  export declare const createServiceHost: (config: Config, signalManagerContext: MemorySignalManagerContext) => ClientServicesHost;
15
- export declare const createServiceContext: ({ signalContext, storage, }?: {
15
+ export declare const createServiceContext: ({ signalContext, storage, runtimeParams, }?: {
16
16
  signalContext?: MemorySignalManagerContext;
17
17
  storage?: Storage;
18
+ runtimeParams?: ServiceContextRuntimeParams;
18
19
  }) => Promise<ServiceContext>;
19
20
  export declare const createPeers: (numPeers: number) => Promise<ServiceContext[]>;
20
21
  export declare const createIdentity: (peer: ServiceContext) => Promise<ServiceContext>;
@@ -26,6 +27,7 @@ export declare class TestBuilder {
26
27
  }
27
28
  export type TestPeerOpts = {
28
29
  dataStore?: StorageType;
30
+ dataSpaceParams?: DataSpaceManagerRuntimeParams;
29
31
  };
30
32
  export type TestPeerProps = {
31
33
  storage?: Storage;
@@ -43,10 +45,10 @@ export type TestPeerProps = {
43
45
  invitationsManager?: InvitationsManager;
44
46
  };
45
47
  export declare class TestPeer {
46
- private readonly signalContext;
47
- private readonly opts;
48
+ private readonly _signalContext;
49
+ private readonly _opts;
48
50
  private _props;
49
- constructor(signalContext: MemorySignalManagerContext, opts?: TestPeerOpts);
51
+ constructor(_signalContext: MemorySignalManagerContext, _opts?: TestPeerOpts);
50
52
  get props(): TestPeerProps;
51
53
  get storage(): Storage;
52
54
  get keyring(): Keyring;
@@ -1 +1 @@
1
- {"version":3,"file":"test-builder.d.ts","sourceRoot":"","sources":["../../../../../src/packlets/testing/test-builder.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,cAAc,CAAC;AAI3C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,YAAY,EAAiB,MAAM,qBAAqB,CAAC;AAChG,OAAO,EAAe,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAE9C,OAAO,EAAuB,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAClF,OAAO,EAA0B,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAEpF,OAAO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AC,CAAC;IAC3B,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,cAAc,CAAC,EAAE,mBAAmB,CAAC;IACrC,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;CACzC,CAAC;AAEF,qBAAa,QAAQ;IAIjB,OAAO,CAAC,QAAQ,CAAC,cAAc;IAC/B,OAAO,CAAC,QAAQ,CAAC,KAAK;IAJxB,OAAO,CAAC,MAAM,CAAqB;gBAGhB,cAAc,EAAE,0BAA0B,EAC1C,KAAK,GAAE,YAA6C;IAGvE,IAAI,KAAK,kBAER;IAED,IAAI,OAAO,YAEV;IAED,IAAI,OAAO,YAEV;IAED,IAAI,KAAK,YAER;IAED,IAAI,SAAS,mBAUZ;IAED,IAAI,aAAa,kBAEhB;IAED,IAAI,SAAS,cAEZ;IAED,IAAI,aAAa,kBAEhB;IAED,IAAI,cAAc,wBAKjB;IAED,IAAI,YAAY,iBAQf;IAED,IAAI,QAAQ,mBAEX;IAED,IAAI,QAAQ,aAEX;IAED,IAAI,gBAAgB,IAAI,gBAAgB,CAWvC;IAED,IAAI,kBAAkB,uBAYrB;IAEK,cAAc;IAId,OAAO;CAId;AAED,eAAO,MAAM,oBAAoB,YAAmB,OAAO,KAAG,QAAQ,cAAc,CAiBnF,CAAC"}
@@ -1,2 +1,2 @@
1
- export declare const DXOS_VERSION = "0.5.9-main.cb71230";
1
+ export declare const DXOS_VERSION = "0.5.9-main.d63ef8d";
2
2
  //# sourceMappingURL=version.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/client-services",
3
- "version": "0.5.9-main.cb71230",
3
+ "version": "0.5.9-main.d63ef8d",
4
4
  "description": "DXOS client services implementation",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -23,45 +23,45 @@
23
23
  ],
24
24
  "dependencies": {
25
25
  "platform": "^1.3.6",
26
- "@dxos/async": "0.5.9-main.cb71230",
27
- "@dxos/automerge": "0.5.9-main.cb71230",
28
- "@dxos/client-protocol": "0.5.9-main.cb71230",
29
- "@dxos/codec-protobuf": "0.5.9-main.cb71230",
30
- "@dxos/config": "0.5.9-main.cb71230",
31
- "@dxos/credentials": "0.5.9-main.cb71230",
32
- "@dxos/context": "0.5.9-main.cb71230",
33
- "@dxos/debug": "0.5.9-main.cb71230",
34
- "@dxos/echo-db": "0.5.9-main.cb71230",
35
- "@dxos/crypto": "0.5.9-main.cb71230",
36
- "@dxos/echo-pipeline": "0.5.9-main.cb71230",
37
- "@dxos/echo-protocol": "0.5.9-main.cb71230",
38
- "@dxos/echo-schema": "0.5.9-main.cb71230",
39
- "@dxos/feed-store": "0.5.9-main.cb71230",
40
- "@dxos/indexing": "0.5.9-main.cb71230",
41
- "@dxos/keyring": "0.5.9-main.cb71230",
42
- "@dxos/invariant": "0.5.9-main.cb71230",
43
- "@dxos/keys": "0.5.9-main.cb71230",
44
- "@dxos/lock-file": "0.5.9-main.cb71230",
45
- "@dxos/kv-store": "0.5.9-main.cb71230",
46
- "@dxos/log": "0.5.9-main.cb71230",
47
- "@dxos/network-manager": "0.5.9-main.cb71230",
48
- "@dxos/messaging": "0.5.9-main.cb71230",
49
- "@dxos/node-std": "0.5.9-main.cb71230",
50
- "@dxos/rpc": "0.5.9-main.cb71230",
51
- "@dxos/random-access-storage": "0.5.9-main.cb71230",
52
- "@dxos/protocols": "0.5.9-main.cb71230",
53
- "@dxos/teleport-extension-gossip": "0.5.9-main.cb71230",
54
- "@dxos/teleport": "0.5.9-main.cb71230",
55
- "@dxos/teleport-extension-object-sync": "0.5.9-main.cb71230",
56
- "@dxos/timeframe": "0.5.9-main.cb71230",
57
- "@dxos/tracing": "0.5.9-main.cb71230",
58
- "@dxos/util": "0.5.9-main.cb71230",
59
- "@dxos/websocket-rpc": "0.5.9-main.cb71230"
26
+ "@dxos/async": "0.5.9-main.d63ef8d",
27
+ "@dxos/automerge": "0.5.9-main.d63ef8d",
28
+ "@dxos/client-protocol": "0.5.9-main.d63ef8d",
29
+ "@dxos/codec-protobuf": "0.5.9-main.d63ef8d",
30
+ "@dxos/config": "0.5.9-main.d63ef8d",
31
+ "@dxos/context": "0.5.9-main.d63ef8d",
32
+ "@dxos/credentials": "0.5.9-main.d63ef8d",
33
+ "@dxos/crypto": "0.5.9-main.d63ef8d",
34
+ "@dxos/debug": "0.5.9-main.d63ef8d",
35
+ "@dxos/echo-db": "0.5.9-main.d63ef8d",
36
+ "@dxos/echo-pipeline": "0.5.9-main.d63ef8d",
37
+ "@dxos/echo-protocol": "0.5.9-main.d63ef8d",
38
+ "@dxos/echo-schema": "0.5.9-main.d63ef8d",
39
+ "@dxos/invariant": "0.5.9-main.d63ef8d",
40
+ "@dxos/feed-store": "0.5.9-main.d63ef8d",
41
+ "@dxos/indexing": "0.5.9-main.d63ef8d",
42
+ "@dxos/keyring": "0.5.9-main.d63ef8d",
43
+ "@dxos/keys": "0.5.9-main.d63ef8d",
44
+ "@dxos/kv-store": "0.5.9-main.d63ef8d",
45
+ "@dxos/lock-file": "0.5.9-main.d63ef8d",
46
+ "@dxos/log": "0.5.9-main.d63ef8d",
47
+ "@dxos/network-manager": "0.5.9-main.d63ef8d",
48
+ "@dxos/messaging": "0.5.9-main.d63ef8d",
49
+ "@dxos/node-std": "0.5.9-main.d63ef8d",
50
+ "@dxos/protocols": "0.5.9-main.d63ef8d",
51
+ "@dxos/random-access-storage": "0.5.9-main.d63ef8d",
52
+ "@dxos/rpc": "0.5.9-main.d63ef8d",
53
+ "@dxos/teleport": "0.5.9-main.d63ef8d",
54
+ "@dxos/teleport-extension-object-sync": "0.5.9-main.d63ef8d",
55
+ "@dxos/teleport-extension-gossip": "0.5.9-main.d63ef8d",
56
+ "@dxos/tracing": "0.5.9-main.d63ef8d",
57
+ "@dxos/timeframe": "0.5.9-main.d63ef8d",
58
+ "@dxos/util": "0.5.9-main.d63ef8d",
59
+ "@dxos/websocket-rpc": "0.5.9-main.d63ef8d"
60
60
  },
61
61
  "devDependencies": {
62
62
  "@types/platform": "^1.3.4",
63
63
  "@types/readable-stream": "^2.3.9",
64
- "@dxos/signal": "0.5.9-main.cb71230"
64
+ "@dxos/signal": "0.5.9-main.d63ef8d"
65
65
  },
66
66
  "publishConfig": {
67
67
  "access": "public"
@@ -0,0 +1,44 @@
1
+ //
2
+ // Copyright 2022 DXOS.org
3
+ //
4
+
5
+ import { type CredentialProcessor, getCredentialAssertion } from '@dxos/credentials';
6
+ import { SpaceId, type PublicKey } from '@dxos/keys';
7
+ import { log } from '@dxos/log';
8
+ import { type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';
9
+
10
+ type DefaultSpaceStateMachineParams = {
11
+ identityKey: PublicKey;
12
+ onUpdate?: () => void;
13
+ };
14
+
15
+ /**
16
+ * Processes device invitation credentials.
17
+ */
18
+ export class DefaultSpaceStateMachine implements CredentialProcessor {
19
+ private _spaceId: SpaceId | undefined;
20
+
21
+ constructor(private readonly _params: DefaultSpaceStateMachineParams) {}
22
+
23
+ public get spaceId(): SpaceId | undefined {
24
+ return this._spaceId;
25
+ }
26
+
27
+ async processCredential(credential: Credential) {
28
+ const assertion = getCredentialAssertion(credential);
29
+ switch (assertion['@type']) {
30
+ case 'dxos.halo.credentials.DefaultSpace': {
31
+ if (!credential.subject.id.equals(this._params.identityKey)) {
32
+ log.warn('Invalid default space credential', { expectedIdentity: this._params.identityKey, credential });
33
+ return;
34
+ }
35
+ if (!SpaceId.isValid(assertion.spaceId)) {
36
+ log.warn('Invalid default space id', { id: assertion.spaceId });
37
+ return;
38
+ }
39
+ this._spaceId = assertion.spaceId;
40
+ break;
41
+ }
42
+ }
43
+ }
44
+ }
@@ -24,11 +24,7 @@ describe('IdentityService', () => {
24
24
  beforeEach(async () => {
25
25
  serviceContext = await createServiceContext();
26
26
  await serviceContext.open(new Context());
27
- identityService = new IdentityServiceImpl(
28
- (options) => serviceContext.createIdentity(options),
29
- serviceContext.identityManager,
30
- serviceContext.keyring,
31
- );
27
+ identityService = createIdentityService(serviceContext);
32
28
  });
33
29
 
34
30
  afterEach(async () => {
@@ -95,3 +91,37 @@ describe('IdentityService', () => {
95
91
  });
96
92
  });
97
93
  });
94
+
95
+ describe('open', () => {
96
+ test('identity without default space fixed', async () => {
97
+ const serviceContext = await createServiceContext();
98
+ await serviceContext.open(new Context());
99
+ const identity = await serviceContext.createIdentity();
100
+ const identityService = createIdentityService(serviceContext);
101
+ const getDataSpaces = () => [...(serviceContext.dataSpaceManager?.spaces?.values() ?? [])];
102
+ expect(getDataSpaces().length).to.eq(0);
103
+ expect(identity.defaultSpaceId).to.be.undefined;
104
+ await identityService.open();
105
+ expect(getDataSpaces()[0].id === identity.defaultSpaceId).to.be.true;
106
+ });
107
+
108
+ test('identity without default space credential fixed', async () => {
109
+ const serviceContext = await createServiceContext();
110
+ await serviceContext.open(new Context());
111
+ const identity = await serviceContext.createIdentity();
112
+ const space = await serviceContext.dataSpaceManager!.createDefaultSpace();
113
+ const identityService = createIdentityService(serviceContext);
114
+ expect(identity.defaultSpaceId).to.be.undefined;
115
+ await identityService.open();
116
+ expect(identity.defaultSpaceId === space.id).to.be.true;
117
+ });
118
+ });
119
+
120
+ const createIdentityService = (serviceContext: ServiceContext) => {
121
+ return new IdentityServiceImpl(
122
+ serviceContext.identityManager,
123
+ serviceContext.keyring,
124
+ () => serviceContext.dataSpaceManager!,
125
+ (options) => serviceContext.createIdentity(options),
126
+ );
127
+ };
@@ -2,37 +2,65 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
+ import { Trigger, sleep } from '@dxos/async';
5
6
  import { Stream } from '@dxos/codec-protobuf';
7
+ import { Resource } from '@dxos/context';
6
8
  import { signPresentation } from '@dxos/credentials';
7
9
  import { todo } from '@dxos/debug';
8
10
  import { invariant } from '@dxos/invariant';
9
11
  import { type Keyring } from '@dxos/keyring';
12
+ import { log } from '@dxos/log';
10
13
  import {
11
14
  type CreateIdentityRequest,
12
- type Identity,
15
+ type Identity as IdentityProto,
13
16
  type IdentityService,
14
17
  type QueryIdentityResponse,
15
18
  type RecoverIdentityRequest,
16
19
  type SignPresentationRequest,
20
+ SpaceState,
17
21
  } from '@dxos/protocols/proto/dxos/client/services';
18
22
  import { type Presentation, type ProfileDocument } from '@dxos/protocols/proto/dxos/halo/credentials';
23
+ import { safeAwaitAll } from '@dxos/util';
19
24
 
25
+ import { type Identity } from './identity';
20
26
  import { type CreateIdentityOptions, type IdentityManager } from './identity-manager';
27
+ import { type DataSpaceManager } from '../spaces';
21
28
 
22
- export class IdentityServiceImpl implements IdentityService {
29
+ const DEFAULT_SPACE_SEARCH_TIMEOUT = 10_000;
30
+
31
+ export class IdentityServiceImpl extends Resource implements IdentityService {
23
32
  constructor(
24
- private readonly _createIdentity: (params: CreateIdentityOptions) => Promise<Identity>,
25
33
  private readonly _identityManager: IdentityManager,
26
34
  private readonly _keyring: Keyring,
35
+ private readonly _dataSpaceManagerProvider: () => DataSpaceManager,
36
+ private readonly _createIdentity: (params: CreateIdentityOptions) => Promise<Identity>,
27
37
  private readonly _onProfileUpdate?: (profile: ProfileDocument | undefined) => Promise<void>,
28
- ) {}
38
+ ) {
39
+ super();
40
+ }
41
+
42
+ protected override async _open() {
43
+ const identity = this._identityManager.identity;
44
+ if (identity && !identity.defaultSpaceId) {
45
+ await this._fixIdentityWithoutDefaultSpace(identity);
46
+ }
47
+ }
29
48
 
30
- async createIdentity(request: CreateIdentityRequest): Promise<Identity> {
49
+ async createIdentity(request: CreateIdentityRequest): Promise<IdentityProto> {
31
50
  await this._createIdentity({ displayName: request.profile?.displayName, deviceProfile: request.deviceProfile });
51
+ const dataSpaceManager = this._dataSpaceManagerProvider();
52
+ await this._createDefaultSpace(dataSpaceManager);
32
53
  return this._getIdentity()!;
33
54
  }
34
55
 
35
- async recoverIdentity(request: RecoverIdentityRequest): Promise<Identity> {
56
+ private async _createDefaultSpace(dataSpaceManager: DataSpaceManager) {
57
+ const space = await dataSpaceManager!.createDefaultSpace();
58
+ const identity = this._identityManager.identity;
59
+ invariant(identity);
60
+ await identity.updateDefaultSpace(space.id);
61
+ }
62
+
63
+ async recoverIdentity(request: RecoverIdentityRequest): Promise<IdentityProto> {
36
64
  return todo();
37
65
  }
38
66
 
@@ -45,7 +73,7 @@ export class IdentityServiceImpl implements IdentityService {
45
73
  });
46
74
  }
47
75
 
48
- private _getIdentity(): Identity | undefined {
76
+ private _getIdentity(): IdentityProto | undefined {
49
77
  if (!this._identityManager.identity) {
50
78
  return undefined;
51
79
  }
@@ -57,7 +85,7 @@ export class IdentityServiceImpl implements IdentityService {
57
85
  };
58
86
  }
59
87
 
60
- async updateProfile(profile: ProfileDocument): Promise<Identity> {
88
+ async updateProfile(profile: ProfileDocument): Promise<IdentityProto> {
61
89
  invariant(this._identityManager.identity, 'Identity not initialized.');
62
90
  await this._identityManager.updateProfile(profile);
63
91
  await this._onProfileUpdate?.(this._identityManager.identity.profileDocument);
@@ -75,4 +103,44 @@ export class IdentityServiceImpl implements IdentityService {
75
103
  nonce,
76
104
  });
77
105
  }
106
+
107
+ private async _fixIdentityWithoutDefaultSpace(identity: Identity) {
108
+ let recodedDefaultSpace = false;
109
+ let foundDefaultSpace = false;
110
+ const dataSpaceManager = this._dataSpaceManagerProvider();
111
+
112
+ const recordedDefaultSpaceTrigger = new Trigger();
113
+
114
+ const allProcessed = safeAwaitAll(dataSpaceManager.spaces.values(), async (space) => {
115
+ if (space.state === SpaceState.CLOSED) {
116
+ await space.open();
117
+
118
+ // Wait until the space is either READY or REQUIRES_MIGRATION.
119
+ // NOTE: Space could potentially never initialize if the space data is corrupted.
120
+ const requiresMigration = space.stateUpdate.waitForCondition(
121
+ () => space.state === SpaceState.REQUIRES_MIGRATION,
122
+ );
123
+ await Promise.race([space.initializeDataPipeline(), requiresMigration]);
124
+ }
125
+ if (await dataSpaceManager.isDefaultSpace(space)) {
126
+ if (foundDefaultSpace) {
127
+ log.warn('Multiple default spaces found. Using the first one.', { duplicate: space.id });
128
+ return;
129
+ }
130
+
131
+ foundDefaultSpace = true;
132
+ await identity.updateDefaultSpace(space.id);
133
+ recodedDefaultSpace = true;
134
+ recordedDefaultSpaceTrigger.wake();
135
+ }
136
+ });
137
+
138
+ // Wait for all spaces to be processed or until the default space is recorded.
139
+ // If the timeout is reached, create a new default space.
140
+ await Promise.race([allProcessed, recordedDefaultSpaceTrigger.wait(), sleep(DEFAULT_SPACE_SEARCH_TIMEOUT)]);
141
+
142
+ if (!recodedDefaultSpace) {
143
+ await this._createDefaultSpace(dataSpaceManager);
144
+ }
145
+ }
78
146
  }
@@ -16,7 +16,7 @@ import { type Signer } from '@dxos/crypto';
16
16
  import { type Space } from '@dxos/echo-pipeline';
17
17
  import { writeMessages } from '@dxos/feed-store';
18
18
  import { invariant } from '@dxos/invariant';
19
- import { PublicKey } from '@dxos/keys';
19
+ import { PublicKey, type SpaceId } from '@dxos/keys';
20
20
  import { log } from '@dxos/log';
21
21
  import { type FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';
22
22
  import {
@@ -26,10 +26,12 @@ import {
26
26
  } from '@dxos/protocols/proto/dxos/halo/credentials';
27
27
  import { type DeviceAdmissionRequest } from '@dxos/protocols/proto/dxos/halo/invitations';
28
28
  import { type Presence } from '@dxos/teleport-extension-gossip';
29
+ import { Timeframe } from '@dxos/timeframe';
29
30
  import { trace } from '@dxos/tracing';
30
31
  import { type ComplexMap, ComplexSet } from '@dxos/util';
31
32
 
32
33
  import { TrustedKeySetAuthVerifier } from './authenticator';
34
+ import { DefaultSpaceStateMachine } from './default-space-state-machine';
33
35
 
34
36
  export type IdentityParams = {
35
37
  identityKey: PublicKey;
@@ -49,6 +51,7 @@ export class Identity {
49
51
  private readonly _presence?: Presence;
50
52
  private readonly _deviceStateMachine: DeviceStateMachine;
51
53
  private readonly _profileStateMachine: ProfileStateMachine;
54
+ private readonly _defaultSpaceStateMachine: DefaultSpaceStateMachine;
52
55
  public readonly authVerifier: TrustedKeySetAuthVerifier;
53
56
 
54
57
  public readonly identityKey: PublicKey;
@@ -75,6 +78,10 @@ export class Identity {
75
78
  identityKey: this.identityKey,
76
79
  onUpdate: () => this.stateUpdate.emit(),
77
80
  });
81
+ this._defaultSpaceStateMachine = new DefaultSpaceStateMachine({
82
+ identityKey: this.identityKey,
83
+ onUpdate: () => this.stateUpdate.emit(),
84
+ });
78
85
 
79
86
  this.authVerifier = new TrustedKeySetAuthVerifier({
80
87
  trustedKeysProvider: () => new ComplexSet(PublicKey.hash, this.authorizedDeviceKeys.keys()),
@@ -88,17 +95,24 @@ export class Identity {
88
95
  return this._deviceStateMachine.authorizedDeviceKeys;
89
96
  }
90
97
 
98
+ get defaultSpaceId(): SpaceId | undefined {
99
+ return this._defaultSpaceStateMachine.spaceId;
100
+ }
101
+
91
102
  @trace.span()
92
103
  async open(ctx: Context) {
104
+ await this._presence?.open();
93
105
  await this.space.spaceState.addCredentialProcessor(this._deviceStateMachine);
94
106
  await this.space.spaceState.addCredentialProcessor(this._profileStateMachine);
107
+ await this.space.spaceState.addCredentialProcessor(this._defaultSpaceStateMachine);
95
108
  await this.space.open(ctx);
96
109
  }
97
110
 
98
111
  @trace.span()
99
112
  async close(ctx: Context) {
100
- await this._presence?.destroy();
113
+ await this._presence?.close();
101
114
  await this.authVerifier.close();
115
+ await this.space.spaceState.removeCredentialProcessor(this._defaultSpaceStateMachine);
102
116
  await this.space.spaceState.removeCredentialProcessor(this._profileStateMachine);
103
117
  await this.space.spaceState.removeCredentialProcessor(this._deviceStateMachine);
104
118
  await this.space.close();
@@ -157,6 +171,15 @@ export class Identity {
157
171
  return createCredentialSignerWithKey(this._signer, this.deviceKey);
158
172
  }
159
173
 
174
+ async updateDefaultSpace(spaceId: SpaceId) {
175
+ const credential = await this.getDeviceCredentialSigner().createCredential({
176
+ subject: this.identityKey,
177
+ assertion: { '@type': 'dxos.halo.credentials.DefaultSpace', spaceId },
178
+ });
179
+ const receipt = await this.controlPipeline.writer.write({ credential: { credential } });
180
+ await this.controlPipeline.state.waitUntilTimeframe(new Timeframe([[receipt.feedKey, receipt.seq]]));
181
+ }
182
+
160
183
  async admitDevice({ deviceKey, controlFeedKey, dataFeedKey }: DeviceAdmissionRequest) {
161
184
  log('Admitting device:', {
162
185
  identityKey: this.identityKey,
@@ -120,10 +120,7 @@ export class ServiceContext extends Resource {
120
120
  this._runtimeParams as IdentityManagerRuntimeParams,
121
121
  );
122
122
 
123
- this.echoHost = new EchoHost({
124
- kv: this.level,
125
- storage: this.storage,
126
- });
123
+ this.echoHost = new EchoHost({ kv: this.level });
127
124
 
128
125
  this.invitations = new InvitationsHandler(this.networkManager, _runtimeParams?.invitationConnectionDefaultParams);
129
126
  this.invitationsManager = new InvitationsManager(
@@ -3,11 +3,9 @@
3
3
  //
4
4
 
5
5
  import { Event, synchronized } from '@dxos/async';
6
- import { clientServiceBundle, defaultKey, type ClientServices, PropertiesType } from '@dxos/client-protocol';
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 { type ObjectStructure, encodeReference, type SpaceDoc } from '@dxos/echo-protocol';
10
- import { getTypeReference } from '@dxos/echo-schema';
11
9
  import { invariant } from '@dxos/invariant';
12
10
  import { PublicKey } from '@dxos/keys';
13
11
  import { type LevelDB } from '@dxos/kv-store';
@@ -18,7 +16,6 @@ import { trace } from '@dxos/protocols';
18
16
  import { SystemStatus } from '@dxos/protocols/proto/dxos/client/services';
19
17
  import { type Storage } from '@dxos/random-access-storage';
20
18
  import { TRACE_PROCESSOR, trace as Trace } from '@dxos/tracing';
21
- import { assignDeep } from '@dxos/util';
22
19
  import { WebsocketRpcClient } from '@dxos/websocket-rpc';
23
20
 
24
21
  import { ServiceContext, type ServiceContextRuntimeParams } from './service-context';
@@ -86,7 +83,7 @@ export class ClientServicesHost {
86
83
  private _devtoolsProxy?: WebsocketRpcClient<{}, ClientServices>;
87
84
 
88
85
  private _serviceContext!: ServiceContext;
89
- private readonly _runtimeParams?: ServiceContextRuntimeParams;
86
+ private readonly _runtimeParams: ServiceContextRuntimeParams;
90
87
  private diagnosticsBroadcastHandler: CollectDiagnosticsBroadcastHandler;
91
88
 
92
89
  @Trace.info()
@@ -109,7 +106,7 @@ export class ClientServicesHost {
109
106
  this._storage = storage;
110
107
  this._level = level;
111
108
  this._callbacks = callbacks;
112
- this._runtimeParams = runtimeParams;
109
+ this._runtimeParams = runtimeParams ?? {};
113
110
 
114
111
  if (config) {
115
112
  this.initialize({ config, transportFactory, signalManager });
@@ -254,15 +251,17 @@ export class ClientServicesHost {
254
251
  this._runtimeParams,
255
252
  );
256
253
 
254
+ const identityService = new IdentityServiceImpl(
255
+ this._serviceContext.identityManager,
256
+ this._serviceContext.keyring,
257
+ () => this._serviceContext.dataSpaceManager!,
258
+ (params) => this._createIdentity(params),
259
+ (profile) => this._serviceContext.broadcastProfileUpdate(profile),
260
+ );
261
+
257
262
  this._serviceRegistry.setServices({
258
263
  SystemService: this._systemService,
259
-
260
- IdentityService: new IdentityServiceImpl(
261
- (params) => this._createIdentity(params),
262
- this._serviceContext.identityManager,
263
- this._serviceContext.keyring,
264
- (profile) => this._serviceContext.broadcastProfileUpdate(profile),
265
- ),
264
+ IdentityService: identityService,
266
265
 
267
266
  InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitationsManager),
268
267
 
@@ -294,6 +293,7 @@ export class ClientServicesHost {
294
293
  });
295
294
 
296
295
  await this._serviceContext.open(ctx);
296
+ await identityService.open();
297
297
 
298
298
  const devtoolsProxy = this._config?.get('runtime.client.devtoolsProxy');
299
299
  if (devtoolsProxy) {
@@ -349,34 +349,7 @@ export class ClientServicesHost {
349
349
 
350
350
  private async _createIdentity(params: CreateIdentityOptions) {
351
351
  const identity = await this._serviceContext.createIdentity(params);
352
-
353
- // Setup default space.
354
352
  await this._serviceContext.initialized.wait();
355
- const space = await this._serviceContext.dataSpaceManager!.createSpace();
356
-
357
- const automergeIndex = space.automergeSpaceState.rootUrl;
358
- invariant(automergeIndex);
359
- const document = this._serviceContext.echoHost.automergeRepo.find<SpaceDoc>(automergeIndex as any);
360
- await document.whenReady();
361
-
362
- // TODO(dmaretskyi): Better API for low-level data access.
363
- const properties: ObjectStructure = {
364
- system: {
365
- type: encodeReference(getTypeReference(PropertiesType)!),
366
- },
367
- data: {
368
- [defaultKey]: identity.identityKey.toHex(),
369
- },
370
- meta: {
371
- keys: [],
372
- },
373
- };
374
- const propertiesId = PublicKey.random().toHex();
375
- document.change((doc: SpaceDoc) => {
376
- assignDeep(doc, ['objects', propertiesId], properties);
377
- });
378
-
379
- await this._serviceContext.echoHost.flush();
380
353
  return identity;
381
354
  }
382
355
  }
@@ -3,10 +3,11 @@
3
3
  //
4
4
 
5
5
  import { Event } from '@dxos/async';
6
+ import { Resource, type Context } from '@dxos/context';
6
7
  import { type CredentialProcessor, type SpecificCredential, checkCredentialType } from '@dxos/credentials';
7
8
  import { type Credential, type Epoch } from '@dxos/protocols/proto/dxos/halo/credentials';
8
9
 
9
- export class AutomergeSpaceState implements CredentialProcessor {
10
+ export class AutomergeSpaceState extends Resource implements CredentialProcessor {
10
11
  public rootUrl: string | undefined = undefined;
11
12
  public lastEpoch: SpecificCredential<Epoch> | undefined = undefined;
12
13
 
@@ -14,7 +15,15 @@ export class AutomergeSpaceState implements CredentialProcessor {
14
15
 
15
16
  private _isProcessingRootDocs = false;
16
17
 
17
- constructor(private readonly _onNewRoot: (rootUrl: string) => void) {}
18
+ constructor(private readonly _onNewRoot: (rootUrl: string) => void) {
19
+ super();
20
+ }
21
+
22
+ protected override async _open(ctx: Context): Promise<void> {}
23
+
24
+ protected override async _close(ctx: Context): Promise<void> {
25
+ this._isProcessingRootDocs = false;
26
+ }
18
27
 
19
28
  async processCredential(credential: Credential) {
20
29
  if (!checkCredentialType(credential, 'dxos.halo.credentials.Epoch')) {