@dxos/client-services 0.1.23 → 0.1.24-next.6b1f434

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 (126) hide show
  1. package/dist/lib/browser/chunk-ZPZBLOQW.mjs +4086 -0
  2. package/dist/lib/browser/chunk-ZPZBLOQW.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +66 -3066
  4. package/dist/lib/browser/index.mjs.map +4 -4
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/packlets/testing/index.mjs +198 -0
  7. package/dist/lib/browser/packlets/testing/index.mjs.map +7 -0
  8. package/dist/lib/node/index.cjs +1655 -669
  9. package/dist/lib/node/index.cjs.map +4 -4
  10. package/dist/lib/node/meta.json +1 -1
  11. package/dist/lib/node/packlets/testing/index.cjs +3806 -0
  12. package/dist/lib/node/packlets/testing/index.cjs.map +7 -0
  13. package/dist/types/src/packlets/deprecated/profile.d.ts +3 -1
  14. package/dist/types/src/packlets/deprecated/profile.d.ts.map +1 -1
  15. package/dist/types/src/packlets/deprecated/space.d.ts.map +1 -1
  16. package/dist/types/src/packlets/deprecated/system.d.ts +15 -9
  17. package/dist/types/src/packlets/deprecated/system.d.ts.map +1 -1
  18. package/dist/types/src/packlets/devtools/devtools.d.ts +2 -2
  19. package/dist/types/src/packlets/devtools/devtools.d.ts.map +1 -1
  20. package/dist/types/src/packlets/devtools/feeds.d.ts.map +1 -1
  21. package/dist/types/src/packlets/devtools/network.d.ts +3 -3
  22. package/dist/types/src/packlets/devtools/network.d.ts.map +1 -1
  23. package/dist/types/src/packlets/devtools/spaces.d.ts.map +1 -1
  24. package/dist/types/src/packlets/identity/authenticator.d.ts +2 -2
  25. package/dist/types/src/packlets/identity/authenticator.d.ts.map +1 -1
  26. package/dist/types/src/packlets/identity/identity-manager.d.ts +8 -2
  27. package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
  28. package/dist/types/src/packlets/identity/identity.d.ts +3 -2
  29. package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
  30. package/dist/types/src/packlets/invitations/halo-invitations-handler.d.ts +11 -3
  31. package/dist/types/src/packlets/invitations/halo-invitations-handler.d.ts.map +1 -1
  32. package/dist/types/src/packlets/invitations/invitations.d.ts +1 -1
  33. package/dist/types/src/packlets/invitations/invitations.d.ts.map +1 -1
  34. package/dist/types/src/packlets/invitations/space-invitations-handler.d.ts +1 -1
  35. package/dist/types/src/packlets/invitations/space-invitations-handler.d.ts.map +1 -1
  36. package/dist/types/src/packlets/services/service-context.d.ts +3 -1
  37. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  38. package/dist/types/src/packlets/services/service-context.test.d.ts +2 -0
  39. package/dist/types/src/packlets/services/service-context.test.d.ts.map +1 -0
  40. package/dist/types/src/packlets/services/service-definitions.d.ts +1 -1
  41. package/dist/types/src/packlets/services/service-definitions.d.ts.map +1 -1
  42. package/dist/types/src/packlets/services/service-host.d.ts +9 -6
  43. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  44. package/dist/types/src/packlets/services/service-registry.d.ts +4 -3
  45. package/dist/types/src/packlets/services/service-registry.d.ts.map +1 -1
  46. package/dist/types/src/packlets/spaces/data-space-manager.d.ts +9 -2
  47. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  48. package/dist/types/src/packlets/spaces/data-space.d.ts +18 -4
  49. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  50. package/dist/types/src/packlets/spaces/notarization-plugin.d.ts +50 -0
  51. package/dist/types/src/packlets/spaces/notarization-plugin.d.ts.map +1 -0
  52. package/dist/types/src/packlets/spaces/notarization-plugin.test.d.ts +2 -0
  53. package/dist/types/src/packlets/spaces/notarization-plugin.test.d.ts.map +1 -0
  54. package/dist/types/src/packlets/spaces/spaces-service.d.ts +3 -2
  55. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  56. package/dist/types/src/packlets/testing/credential-utils.d.ts +8 -0
  57. package/dist/types/src/packlets/testing/credential-utils.d.ts.map +1 -0
  58. package/dist/types/src/packlets/testing/index.d.ts +2 -0
  59. package/dist/types/src/packlets/testing/index.d.ts.map +1 -1
  60. package/dist/types/src/packlets/testing/invitation-utils.d.ts +3 -0
  61. package/dist/types/src/packlets/testing/invitation-utils.d.ts.map +1 -0
  62. package/dist/types/src/packlets/testing/test-builder.d.ts +2 -2
  63. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  64. package/dist/types/src/packlets/vault/iframe-host-runtime.d.ts +35 -0
  65. package/dist/types/src/packlets/vault/iframe-host-runtime.d.ts.map +1 -0
  66. package/dist/types/src/packlets/vault/{iframe-runtime.d.ts → iframe-proxy-runtime.d.ts} +9 -4
  67. package/dist/types/src/packlets/vault/iframe-proxy-runtime.d.ts.map +1 -0
  68. package/dist/types/src/packlets/vault/index.d.ts +6 -1
  69. package/dist/types/src/packlets/vault/index.d.ts.map +1 -1
  70. package/dist/types/src/packlets/vault/services.d.ts +9 -1
  71. package/dist/types/src/packlets/vault/services.d.ts.map +1 -1
  72. package/dist/types/src/packlets/vault/shell-controller.d.ts +24 -0
  73. package/dist/types/src/packlets/vault/shell-controller.d.ts.map +1 -0
  74. package/dist/types/src/packlets/vault/shell-runtime.d.ts +45 -0
  75. package/dist/types/src/packlets/vault/shell-runtime.d.ts.map +1 -0
  76. package/dist/types/src/packlets/vault/vault-resource-lock.d.ts +19 -0
  77. package/dist/types/src/packlets/vault/vault-resource-lock.d.ts.map +1 -0
  78. package/dist/types/src/packlets/vault/worker-runtime.d.ts +2 -1
  79. package/dist/types/src/packlets/vault/worker-runtime.d.ts.map +1 -1
  80. package/dist/types/src/packlets/vault/worker-session.d.ts +7 -4
  81. package/dist/types/src/packlets/vault/worker-session.d.ts.map +1 -1
  82. package/package.json +30 -29
  83. package/src/packlets/deprecated/profile.ts +20 -2
  84. package/src/packlets/deprecated/space.ts +41 -37
  85. package/src/packlets/deprecated/system.ts +26 -13
  86. package/src/packlets/devtools/devtools.ts +4 -4
  87. package/src/packlets/devtools/feeds.ts +11 -6
  88. package/src/packlets/devtools/network.ts +20 -9
  89. package/src/packlets/devtools/spaces.ts +8 -7
  90. package/src/packlets/identity/authenticator.ts +12 -7
  91. package/src/packlets/identity/identity-manager.test.ts +25 -16
  92. package/src/packlets/identity/identity-manager.ts +23 -9
  93. package/src/packlets/identity/identity.test.ts +22 -23
  94. package/src/packlets/identity/identity.ts +11 -6
  95. package/src/packlets/invitations/halo-invitations-handler.test.ts +4 -45
  96. package/src/packlets/invitations/halo-invitations-handler.ts +33 -17
  97. package/src/packlets/invitations/invitations.ts +2 -1
  98. package/src/packlets/invitations/space-invitations-handler.test.ts +43 -26
  99. package/src/packlets/invitations/space-invitations-handler.ts +9 -12
  100. package/src/packlets/services/service-context.test.ts +56 -0
  101. package/src/packlets/services/service-context.ts +62 -6
  102. package/src/packlets/services/service-definitions.ts +1 -1
  103. package/src/packlets/services/service-host.test.ts +74 -5
  104. package/src/packlets/services/service-host.ts +86 -24
  105. package/src/packlets/services/service-registry.test.ts +2 -1
  106. package/src/packlets/services/service-registry.ts +5 -1
  107. package/src/packlets/spaces/data-space-manager.test.ts +72 -15
  108. package/src/packlets/spaces/data-space-manager.ts +53 -12
  109. package/src/packlets/spaces/data-space.ts +113 -14
  110. package/src/packlets/spaces/notarization-plugin.test.ts +81 -0
  111. package/src/packlets/spaces/notarization-plugin.ts +211 -0
  112. package/src/packlets/spaces/spaces-service.ts +10 -2
  113. package/src/packlets/testing/credential-utils.ts +28 -0
  114. package/src/packlets/testing/index.ts +2 -0
  115. package/src/packlets/testing/invitation-utils.ts +44 -0
  116. package/src/packlets/testing/test-builder.ts +14 -18
  117. package/src/packlets/vault/iframe-host-runtime.ts +131 -0
  118. package/src/packlets/vault/{iframe-runtime.ts → iframe-proxy-runtime.ts} +18 -3
  119. package/src/packlets/vault/index.ts +6 -1
  120. package/src/packlets/vault/services.ts +17 -1
  121. package/src/packlets/vault/shell-controller.ts +77 -0
  122. package/src/packlets/vault/shell-runtime.ts +133 -0
  123. package/src/packlets/vault/vault-resource-lock.ts +76 -0
  124. package/src/packlets/vault/worker-runtime.ts +16 -4
  125. package/src/packlets/vault/worker-session.ts +36 -26
  126. package/dist/types/src/packlets/vault/iframe-runtime.d.ts.map +0 -1
@@ -42,16 +42,20 @@ __export(src_exports, {
42
42
  HaloInvitationsHandler: () => HaloInvitationsHandler,
43
43
  HaloInvitationsProxy: () => HaloInvitationsProxy,
44
44
  HaloInvitationsServiceImpl: () => HaloInvitationsServiceImpl,
45
- IFrameRuntime: () => IFrameRuntime,
45
+ IFrameHostRuntime: () => IFrameHostRuntime,
46
+ IFrameProxyRuntime: () => IFrameProxyRuntime,
46
47
  INVITATION_TIMEOUT: () => INVITATION_TIMEOUT,
47
48
  Identity: () => Identity,
48
49
  IdentityManager: () => IdentityManager,
49
50
  InvitationEncoder: () => InvitationEncoder,
50
51
  InvitationObservableProvider: () => InvitationObservableProvider,
52
+ MemoryShellRuntime: () => MemoryShellRuntime,
51
53
  ON_CLOSE_DELAY: () => ON_CLOSE_DELAY,
52
54
  ProfileServiceImpl: () => ProfileServiceImpl,
53
55
  ServiceContext: () => ServiceContext,
54
56
  ServiceRegistry: () => ServiceRegistry,
57
+ ShellController: () => ShellController,
58
+ ShellRuntimeImpl: () => ShellRuntimeImpl,
55
59
  SpaceInvitationsHandler: () => SpaceInvitationsHandler,
56
60
  SpaceInvitationsProxy: () => SpaceInvitationsProxy,
57
61
  SpaceInvitationsServiceImpl: () => SpaceInvitationsServiceImpl,
@@ -59,27 +63,31 @@ __export(src_exports, {
59
63
  SystemServiceImpl: () => SystemServiceImpl,
60
64
  TracingServiceImpl: () => TracingServiceImpl,
61
65
  TrustedKeySetAuthVerifier: () => TrustedKeySetAuthVerifier,
66
+ VaultResourceLock: () => VaultResourceLock,
62
67
  WorkerRuntime: () => WorkerRuntime,
63
68
  WorkerSession: () => WorkerSession,
69
+ appServiceBundle: () => appServiceBundle,
64
70
  clientServiceBundle: () => clientServiceBundle,
65
71
  createAuthProvider: () => createAuthProvider,
66
72
  createDefaultModelFactory: () => createDefaultModelFactory,
67
73
  createStorageObjects: () => createStorageObjects,
68
74
  getNetworkPeers: () => getNetworkPeers,
75
+ iframeServiceBundle: () => iframeServiceBundle,
76
+ shellServiceBundle: () => shellServiceBundle,
69
77
  subscribeToFeedBlocks: () => subscribeToFeedBlocks,
70
78
  subscribeToFeeds: () => subscribeToFeeds,
71
79
  subscribeToNetworkStatus: () => subscribeToNetworkStatus,
72
80
  subscribeToNetworkTopics: () => subscribeToNetworkTopics,
73
- subscribeToSignalTrace: () => subscribeToSignalTrace,
81
+ subscribeToSignal: () => subscribeToSignal,
74
82
  subscribeToSpaces: () => subscribeToSpaces,
75
83
  subscribeToSwarmInfo: () => subscribeToSwarmInfo,
84
+ workerServiceBundle: () => workerServiceBundle,
76
85
  wrapObservable: () => wrapObservable
77
86
  });
78
87
  module.exports = __toCommonJS(src_exports);
79
88
 
80
89
  // packages/sdk/client-services/src/packlets/deprecated/space.ts
81
90
  var import_node_assert = __toESM(require("node:assert"));
82
- var import_async = require("@dxos/async");
83
91
  var import_codec_protobuf = require("@dxos/codec-protobuf");
84
92
  var import_debug = require("@dxos/debug");
85
93
  var import_log = require("@dxos/log");
@@ -103,10 +111,9 @@ var SpaceServiceImpl = class {
103
111
  });
104
112
  }
105
113
  subscribeSpaces() {
106
- return new import_codec_protobuf.Stream(({ next }) => {
107
- const subscriptions = new import_async.EventSubscriptions();
114
+ return new import_codec_protobuf.Stream(({ next, ctx }) => {
108
115
  const onUpdate = () => {
109
- const spaces = Array.from(this.serviceContext.dataSpaceManager.spaces.values()).map((space) => ({
116
+ const spaces = Array.from(this.serviceContext.dataSpaceManager.spaces.values()).filter((space) => this.serviceContext.dataServiceSubscriptions.getDataService(space.key)).map((space) => ({
110
117
  publicKey: space.key,
111
118
  isOpen: true,
112
119
  isActive: true,
@@ -126,7 +133,7 @@ var SpaceServiceImpl = class {
126
133
  spaces
127
134
  }, {
128
135
  file: "space.ts",
129
- line: 120,
136
+ line: 119,
130
137
  scope: this,
131
138
  callSite: (f, a) => f(...a)
132
139
  });
@@ -141,26 +148,31 @@ var SpaceServiceImpl = class {
141
148
  });
142
149
  }
143
150
  await this.serviceContext.initialized.wait();
144
- subscriptions.add(this.serviceContext.dataSpaceManager.updated.on(() => {
145
- this.serviceContext.dataSpaceManager.spaces.forEach((space) => {
146
- subscriptions.add(space.stateUpdate.on(onUpdate));
147
- subscriptions.add(space.presence.updated.on(onUpdate));
148
- });
151
+ const subscribeSpaces = () => {
152
+ for (const space of this.serviceContext.dataSpaceManager.spaces.values()) {
153
+ if (!this.serviceContext.dataServiceSubscriptions.getDataService(space.key)) {
154
+ continue;
155
+ }
156
+ space.stateUpdate.on(ctx, onUpdate);
157
+ space.presence.updated.on(ctx, onUpdate);
158
+ }
159
+ };
160
+ this.serviceContext.dataSpaceManager.updated.on(ctx, () => {
161
+ subscribeSpaces();
149
162
  onUpdate();
150
- }));
151
- this.serviceContext.dataSpaceManager.spaces.forEach((space) => {
152
- subscriptions.add(space.stateUpdate.on(onUpdate));
153
- subscriptions.add(space.presence.updated.on(onUpdate));
154
163
  });
164
+ subscribeSpaces();
155
165
  onUpdate();
156
166
  });
157
- return () => subscriptions.clear();
158
167
  });
159
168
  }
160
169
  async getSpaceDetails(request) {
161
170
  return (0, import_debug.todo)();
162
171
  }
163
172
  async createSpace() {
173
+ if (!this.serviceContext.identityManager.identity) {
174
+ throw new Error("This device has no HALO identity available. See https://docs.dxos.org/guide/halo");
175
+ }
164
176
  await this.serviceContext.initialized.wait();
165
177
  const space = await this.serviceContext.dataSpaceManager.createSpace();
166
178
  return {
@@ -193,7 +205,9 @@ var SpaceServiceImpl = class {
193
205
  };
194
206
 
195
207
  // packages/sdk/client-services/src/packlets/deprecated/profile.ts
208
+ var import_node_assert2 = __toESM(require("node:assert"));
196
209
  var import_codec_protobuf2 = require("@dxos/codec-protobuf");
210
+ var import_credentials = require("@dxos/credentials");
197
211
  var import_debug2 = require("@dxos/debug");
198
212
  var ProfileServiceImpl = class {
199
213
  constructor(context) {
@@ -208,7 +222,8 @@ var ProfileServiceImpl = class {
208
222
  profile: this.context.identityManager.identity ? {
209
223
  identityKey: this.context.identityManager.identity.identityKey,
210
224
  deviceKey: this.context.identityManager.identity.deviceKey,
211
- displayName: (_a = this.context.identityManager.identity.profileDocument) == null ? void 0 : _a.displayName
225
+ displayName: (_a = this.context.identityManager.identity.profileDocument) == null ? void 0 : _a.displayName,
226
+ haloSpace: this.context.identityManager.identity.space.key
212
227
  } : void 0
213
228
  });
214
229
  };
@@ -224,7 +239,8 @@ var ProfileServiceImpl = class {
224
239
  return {
225
240
  identityKey: this.context.identityManager.identity.identityKey,
226
241
  deviceKey: this.context.identityManager.identity.deviceKey,
227
- displayName: (_a = this.context.identityManager.identity.profileDocument) == null ? void 0 : _a.displayName
242
+ displayName: (_a = this.context.identityManager.identity.profileDocument) == null ? void 0 : _a.displayName,
243
+ haloSpace: this.context.identityManager.identity.space.key
228
244
  };
229
245
  }
230
246
  async recoverProfile(request) {
@@ -233,28 +249,38 @@ var ProfileServiceImpl = class {
233
249
  throw new Error("Recovery SeedPhrase not provided.");
234
250
  }
235
251
  }
252
+ async signPresentation({ presentation, nonce }) {
253
+ (0, import_node_assert2.default)(this.context.identityManager.identity, "Identity not initialized.");
254
+ return await (0, import_credentials.signPresentation)({
255
+ presentation,
256
+ signer: this.context.keyring,
257
+ signerKey: this.context.identityManager.identity.deviceKey,
258
+ chain: this.context.identityManager.identity.deviceCredentialChain,
259
+ nonce
260
+ });
261
+ }
236
262
  };
237
263
 
238
264
  // packages/sdk/client-services/src/packlets/deprecated/system.ts
239
265
  var SystemServiceImpl = class {
240
- constructor(_config, _serviceContext) {
241
- this._config = _config;
242
- this._serviceContext = _serviceContext;
243
- }
244
- // TODO(burdon): Remove.
245
- async initSession() {
266
+ constructor({ config, onInit, onStatus, onReset }) {
267
+ this._config = config;
268
+ this._onInit = onInit;
269
+ this._onStatus = onStatus;
270
+ this._onReset = onReset;
246
271
  }
247
- async getConfig(request) {
272
+ async getConfig() {
248
273
  return this._config.values;
249
274
  }
250
275
  // TODO(burdon): Connect to iframe RPC heartbeat for network status?
251
- async getStatus(request) {
252
- return {
253
- message: `ok: ${Date.now()}`
254
- };
276
+ async getStatus() {
277
+ return this._onStatus();
278
+ }
279
+ async initSession() {
280
+ await this._onInit();
255
281
  }
256
- async reset(request) {
257
- await this._serviceContext.reset();
282
+ async reset() {
283
+ await this._onReset();
258
284
  }
259
285
  };
260
286
 
@@ -272,79 +298,83 @@ var TracingServiceImpl = class {
272
298
  };
273
299
 
274
300
  // packages/sdk/client-services/src/packlets/devtools/devtools.ts
275
- var import_async3 = require("@dxos/async");
301
+ var import_async2 = require("@dxos/async");
276
302
  var import_codec_protobuf7 = require("@dxos/codec-protobuf");
277
303
 
278
304
  // packages/sdk/client-services/src/packlets/devtools/feeds.ts
279
- var import_async2 = require("@dxos/async");
305
+ var import_async = require("@dxos/async");
280
306
  var import_codec_protobuf3 = require("@dxos/codec-protobuf");
281
307
  var import_feed_store = require("@dxos/feed-store");
282
308
  var import_keys = require("@dxos/keys");
283
309
  var import_util2 = require("@dxos/util");
284
- var subscribeToFeeds = ({ feedStore }, { feedKeys }) => new import_codec_protobuf3.Stream(({ next }) => {
285
- if ((feedKeys == null ? void 0 : feedKeys.length) === 0) {
286
- return;
287
- }
288
- const feedMap = new import_util2.ComplexMap(import_keys.PublicKey.hash);
289
- const subscriptions = new import_async2.EventSubscriptions();
290
- const update = () => {
291
- const feeds = feedStore.feeds;
292
- feeds.filter((feed) => !(feedKeys == null ? void 0 : feedKeys.length) || feedKeys.some((feedKey) => feedKey.equals(feed.key))).forEach((feed) => {
293
- if (!feedMap.has(feed.key)) {
294
- feedMap.set(feed.key, feed);
295
- feed.on("close", update);
296
- subscriptions.add(feed.off("close", update));
297
- }
298
- });
299
- next({
300
- feeds: Array.from(feedMap.values()).map((feed) => ({
301
- feedKey: feed.key,
302
- length: feed.properties.length
303
- }))
304
- });
305
- };
306
- subscriptions.add(feedStore.feedOpened.on(update));
307
- update();
308
- return () => {
309
- subscriptions.clear();
310
- };
311
- });
312
- var subscribeToFeedBlocks = ({ feedStore }, { feedKey, maxBlocks = 10 }) => new import_codec_protobuf3.Stream(({ next }) => {
313
- if (!feedKey) {
314
- return;
315
- }
316
- const subscriptions = new import_async2.EventSubscriptions();
317
- const timeout = setTimeout(async () => {
318
- const feed = feedStore.getFeed(feedKey);
319
- if (!feed) {
310
+ var subscribeToFeeds = ({ feedStore }, { feedKeys }) => {
311
+ return new import_codec_protobuf3.Stream(({ next }) => {
312
+ if ((feedKeys == null ? void 0 : feedKeys.length) === 0) {
320
313
  return;
321
314
  }
322
- const update = async () => {
323
- const iterator = new import_feed_store.FeedIterator(feed);
324
- await iterator.open();
325
- const blocks = [];
326
- for await (const block of iterator) {
327
- blocks.push(block);
328
- if (blocks.length >= feed.properties.length) {
329
- break;
315
+ const subscriptions = new import_async.EventSubscriptions();
316
+ const feedMap = new import_util2.ComplexMap(import_keys.PublicKey.hash);
317
+ const update = () => {
318
+ const { feeds } = feedStore;
319
+ feeds.filter((feed) => !(feedKeys == null ? void 0 : feedKeys.length) || feedKeys.some((feedKey) => feedKey.equals(feed.key))).forEach((feed) => {
320
+ if (!feedMap.has(feed.key)) {
321
+ feedMap.set(feed.key, feed);
322
+ feed.on("close", update);
323
+ subscriptions.add(feed.off("close", update));
330
324
  }
331
- }
325
+ });
332
326
  next({
333
- blocks: blocks.slice(-maxBlocks)
327
+ feeds: Array.from(feedMap.values()).map((feed) => ({
328
+ feedKey: feed.key,
329
+ length: feed.properties.length
330
+ }))
334
331
  });
335
- await iterator.close();
336
332
  };
337
- feed.on("append", update);
338
- subscriptions.add(() => feed.off("append", update));
339
- feed.on("truncate", update);
340
- subscriptions.add(() => feed.off("truncate", update));
341
- await update();
333
+ subscriptions.add(feedStore.feedOpened.on(update));
334
+ update();
335
+ return () => {
336
+ subscriptions.clear();
337
+ };
342
338
  });
343
- return () => {
344
- subscriptions.clear();
345
- clearTimeout(timeout);
346
- };
347
- });
339
+ };
340
+ var subscribeToFeedBlocks = ({ feedStore }, { feedKey, maxBlocks = 10 }) => {
341
+ return new import_codec_protobuf3.Stream(({ next }) => {
342
+ if (!feedKey) {
343
+ return;
344
+ }
345
+ const subscriptions = new import_async.EventSubscriptions();
346
+ const timeout = setTimeout(async () => {
347
+ const feed = feedStore.getFeed(feedKey);
348
+ if (!feed) {
349
+ return;
350
+ }
351
+ const update = async () => {
352
+ const iterator = new import_feed_store.FeedIterator(feed);
353
+ await iterator.open();
354
+ const blocks = [];
355
+ for await (const block of iterator) {
356
+ blocks.push(block);
357
+ if (blocks.length >= feed.properties.length) {
358
+ break;
359
+ }
360
+ }
361
+ next({
362
+ blocks: blocks.slice(-maxBlocks)
363
+ });
364
+ await iterator.close();
365
+ };
366
+ feed.on("append", update);
367
+ subscriptions.add(() => feed.off("append", update));
368
+ feed.on("truncate", update);
369
+ subscriptions.add(() => feed.off("truncate", update));
370
+ await update();
371
+ });
372
+ return () => {
373
+ subscriptions.clear();
374
+ clearTimeout(timeout);
375
+ };
376
+ });
377
+ };
348
378
 
349
379
  // packages/sdk/client-services/src/packlets/devtools/keys.ts
350
380
  var import_codec_protobuf4 = require("@dxos/codec-protobuf");
@@ -361,6 +391,7 @@ var subscribeToKeyringKeys = ({ keyring }) => new import_codec_protobuf4.Stream(
361
391
 
362
392
  // packages/sdk/client-services/src/packlets/devtools/network.ts
363
393
  var import_codec_protobuf5 = require("@dxos/codec-protobuf");
394
+ var import_context = require("@dxos/context");
364
395
  var import_keys2 = require("@dxos/keys");
365
396
  var subscribeToNetworkStatus = ({ networkManager }) => new import_codec_protobuf5.Stream(({ next, close }) => {
366
397
  const update = () => {
@@ -376,17 +407,27 @@ var subscribeToNetworkStatus = ({ networkManager }) => new import_codec_protobuf
376
407
  networkManager.signalManager.statusChanged.on(update);
377
408
  update();
378
409
  });
379
- var subscribeToSignalTrace = ({ networkManager }) => new import_codec_protobuf5.Stream(({ next }) => {
380
- next({
381
- events: []
410
+ var subscribeToSignal = ({ networkManager }) => new import_codec_protobuf5.Stream(({ next }) => {
411
+ const ctx = new import_context.Context();
412
+ networkManager.signalManager.onMessage.on(ctx, (message) => {
413
+ next({
414
+ message: {
415
+ author: message.author.asUint8Array(),
416
+ recipient: message.recipient.asUint8Array(),
417
+ payload: message.payload
418
+ },
419
+ receivedAt: new Date()
420
+ });
382
421
  });
383
- const trace = [];
384
- networkManager.signalManager.commandTrace.on((msg) => {
385
- trace.push(msg);
422
+ networkManager.signalManager.swarmEvent.on(ctx, (swarmEvent) => {
386
423
  next({
387
- events: trace.map((msg2) => JSON.stringify(msg2))
424
+ swarmEvent: swarmEvent.swarmEvent,
425
+ receivedAt: new Date()
388
426
  });
389
427
  });
428
+ return () => {
429
+ return ctx.dispose();
430
+ };
390
431
  });
391
432
  var subscribeToNetworkTopics = ({ networkManager }) => new import_codec_protobuf5.Stream(({ next, close }) => {
392
433
  const update = () => {
@@ -438,42 +479,44 @@ var getNetworkPeers = ({ networkManager }, request) => {
438
479
 
439
480
  // packages/sdk/client-services/src/packlets/devtools/spaces.ts
440
481
  var import_codec_protobuf6 = require("@dxos/codec-protobuf");
441
- var subscribeToSpaces = (context, { spaceKeys = [] }) => new import_codec_protobuf6.Stream(({ next }) => {
442
- let unsubscribe;
443
- const update = async () => {
444
- const spaces = [
445
- ...context.spaceManager.spaces.values()
446
- ];
447
- const filteredSpaces = spaces.filter((space) => !(spaceKeys == null ? void 0 : spaceKeys.length) || spaceKeys.some((spaceKey) => spaceKey.equals(space.key)));
448
- next({
449
- spaces: filteredSpaces.map((space) => {
450
- const spaceMetadata = context.metadataStore.spaces.find((spaceMetadata2) => spaceMetadata2.key.equals(space.key));
451
- return {
452
- key: space.key,
453
- isOpen: space.isOpen,
454
- timeframe: spaceMetadata == null ? void 0 : spaceMetadata.latestTimeframe,
455
- genesisFeed: space.genesisFeedKey,
456
- controlFeed: space.controlFeedKey,
457
- dataFeed: space.dataFeedKey
458
- };
459
- })
482
+ var subscribeToSpaces = (context, { spaceKeys = [] }) => {
483
+ return new import_codec_protobuf6.Stream(({ next }) => {
484
+ let unsubscribe;
485
+ const update = async () => {
486
+ const spaces = [
487
+ ...context.spaceManager.spaces.values()
488
+ ];
489
+ const filteredSpaces = spaces.filter((space) => !(spaceKeys == null ? void 0 : spaceKeys.length) || spaceKeys.some((spaceKey) => spaceKey.equals(space.key)));
490
+ next({
491
+ spaces: filteredSpaces.map((space) => {
492
+ const spaceMetadata = context.metadataStore.spaces.find((spaceMetadata2) => spaceMetadata2.key.equals(space.key));
493
+ return {
494
+ key: space.key,
495
+ isOpen: space.isOpen,
496
+ timeframe: spaceMetadata == null ? void 0 : spaceMetadata.dataTimeframe,
497
+ genesisFeed: space.genesisFeedKey,
498
+ controlFeed: space.controlFeedKey,
499
+ dataFeed: space.dataFeedKey
500
+ };
501
+ })
502
+ });
503
+ };
504
+ const timeout = setTimeout(async () => {
505
+ await context.initialized.wait();
506
+ unsubscribe = context.dataSpaceManager.updated.on(() => update());
507
+ await update();
460
508
  });
461
- };
462
- const timeout = setTimeout(async () => {
463
- await context.initialized.wait();
464
- unsubscribe = context.dataSpaceManager.updated.on(() => update());
465
- await update();
509
+ return () => {
510
+ unsubscribe == null ? void 0 : unsubscribe();
511
+ clearTimeout(timeout);
512
+ };
466
513
  });
467
- return () => {
468
- unsubscribe == null ? void 0 : unsubscribe();
469
- clearTimeout(timeout);
470
- };
471
- });
514
+ };
472
515
 
473
516
  // packages/sdk/client-services/src/packlets/devtools/devtools.ts
474
517
  var DevtoolsHostEvents = class {
475
518
  constructor() {
476
- this.ready = new import_async3.Event();
519
+ this.ready = new import_async2.Event();
477
520
  }
478
521
  };
479
522
  var DevtoolsServiceImpl = class {
@@ -545,8 +588,8 @@ var DevtoolsServiceImpl = class {
545
588
  networkManager: this.params.context.networkManager
546
589
  });
547
590
  }
548
- subscribeToSignalTrace() {
549
- return subscribeToSignalTrace({
591
+ subscribeToSignal() {
592
+ return subscribeToSignal({
550
593
  networkManager: this.params.context.networkManager
551
594
  });
552
595
  }
@@ -558,9 +601,9 @@ var DevtoolsServiceImpl = class {
558
601
  };
559
602
 
560
603
  // packages/sdk/client-services/src/packlets/identity/authenticator.ts
561
- var import_async4 = require("@dxos/async");
562
- var import_context = require("@dxos/context");
563
- var import_credentials = require("@dxos/credentials");
604
+ var import_async3 = require("@dxos/async");
605
+ var import_context2 = require("@dxos/context");
606
+ var import_credentials2 = require("@dxos/credentials");
564
607
  var import_log2 = require("@dxos/log");
565
608
  var import_protocols = require("@dxos/protocols");
566
609
  var createAuthProvider = (signer) => async (nonce) => {
@@ -574,17 +617,14 @@ var createAuthProvider = (signer) => async (nonce) => {
574
617
  return import_protocols.schema.getCodecForType("dxos.halo.credentials.Credential").encode(credential);
575
618
  };
576
619
  var TrustedKeySetAuthVerifier = class {
620
+ // prettier-ignore
577
621
  constructor(_params) {
578
622
  this._params = _params;
579
- this._ctx = new import_context.Context();
623
+ this._ctx = new import_context2.Context();
580
624
  }
581
625
  async close() {
582
626
  await this._ctx.dispose();
583
627
  }
584
- _isTrustedKey(deviceKey) {
585
- const deviceSet = this._params.trustedKeysProvider();
586
- return deviceSet.has(deviceKey);
587
- }
588
628
  get verifier() {
589
629
  return async (nonce, auth) => {
590
630
  const credential = import_protocols.schema.getCodecForType("dxos.halo.credentials.Credential").decode(auth);
@@ -592,17 +632,17 @@ var TrustedKeySetAuthVerifier = class {
592
632
  credential
593
633
  }, {
594
634
  file: "authenticator.ts",
595
- line: 59,
635
+ line: 57,
596
636
  scope: this,
597
637
  callSite: (f, a) => f(...a)
598
638
  });
599
- const result = await (0, import_credentials.verifyCredential)(credential);
639
+ const result = await (0, import_credentials2.verifyCredential)(credential);
600
640
  if (result.kind === "fail") {
601
641
  (0, import_log2.log)("Invalid credential", {
602
642
  result
603
643
  }, {
604
644
  file: "authenticator.ts",
605
- line: 63,
645
+ line: 61,
606
646
  scope: this,
607
647
  callSite: (f, a) => f(...a)
608
648
  });
@@ -614,7 +654,7 @@ var TrustedKeySetAuthVerifier = class {
614
654
  credential
615
655
  }, {
616
656
  file: "authenticator.ts",
617
- line: 68,
657
+ line: 66,
618
658
  scope: this,
619
659
  callSite: (f, a) => f(...a)
620
660
  });
@@ -625,13 +665,13 @@ var TrustedKeySetAuthVerifier = class {
625
665
  key: credential.issuer
626
666
  }, {
627
667
  file: "authenticator.ts",
628
- line: 73,
668
+ line: 71,
629
669
  scope: this,
630
670
  callSite: (f, a) => f(...a)
631
671
  });
632
672
  return true;
633
673
  }
634
- const trigger = new import_async4.Trigger();
674
+ const trigger = new import_async3.Trigger();
635
675
  this._ctx.onDispose(() => {
636
676
  trigger.wake(false);
637
677
  });
@@ -641,7 +681,7 @@ var TrustedKeySetAuthVerifier = class {
641
681
  key: credential.issuer
642
682
  }, {
643
683
  file: "authenticator.ts",
644
- line: 83,
684
+ line: 82,
645
685
  scope: this,
646
686
  callSite: (f, a) => f(...a)
647
687
  });
@@ -651,7 +691,7 @@ var TrustedKeySetAuthVerifier = class {
651
691
  key: credential.issuer
652
692
  }, {
653
693
  file: "authenticator.ts",
654
- line: 86,
694
+ line: 85,
655
695
  scope: this,
656
696
  callSite: (f, a) => f(...a)
657
697
  });
@@ -668,29 +708,34 @@ var TrustedKeySetAuthVerifier = class {
668
708
  }
669
709
  };
670
710
  }
711
+ _isTrustedKey(deviceKey) {
712
+ const deviceSet = this._params.trustedKeysProvider();
713
+ return deviceSet.has(deviceKey);
714
+ }
671
715
  };
672
716
 
673
717
  // packages/sdk/client-services/src/packlets/identity/identity.ts
674
- var import_node_assert2 = __toESM(require("node:assert"));
675
- var import_async5 = require("@dxos/async");
676
- var import_credentials2 = require("@dxos/credentials");
718
+ var import_node_assert3 = __toESM(require("node:assert"));
719
+ var import_async4 = require("@dxos/async");
720
+ var import_credentials3 = require("@dxos/credentials");
721
+ var import_debug3 = require("@dxos/debug");
677
722
  var import_feed_store2 = require("@dxos/feed-store");
678
723
  var import_log3 = require("@dxos/log");
679
- var import_credentials3 = require("@dxos/protocols/proto/dxos/halo/credentials");
724
+ var import_credentials4 = require("@dxos/protocols/proto/dxos/halo/credentials");
680
725
  var AUTH_TIMEOUT = 3e4;
681
726
  var Identity = class {
682
727
  constructor({ space, signer, identityKey, deviceKey }) {
683
- this.stateUpdate = new import_async5.Event();
728
+ this.stateUpdate = new import_async4.Event();
684
729
  this.space = space;
685
730
  this._signer = signer;
686
731
  this.identityKey = identityKey;
687
732
  this.deviceKey = deviceKey;
688
- this._deviceStateMachine = this.space.spaceState.registerProcessor(new import_credentials2.DeviceStateMachine({
733
+ this._deviceStateMachine = this.space.spaceState.registerProcessor(new import_credentials3.DeviceStateMachine({
689
734
  identityKey: this.identityKey,
690
735
  deviceKey: this.deviceKey,
691
736
  onUpdate: () => this.stateUpdate.emit()
692
737
  }));
693
- this._profileStateMachine = this.space.spaceState.registerProcessor(new import_credentials2.ProfileStateMachine({
738
+ this._profileStateMachine = this.space.spaceState.registerProcessor(new import_credentials3.ProfileStateMachine({
694
739
  identityKey: this.identityKey,
695
740
  onUpdate: () => this.stateUpdate.emit()
696
741
  }));
@@ -717,6 +762,9 @@ var Identity = class {
717
762
  }
718
763
  async ready() {
719
764
  await this._deviceStateMachine.processor.deviceChainReady.wait();
765
+ await this.controlPipeline.state.waitUntilReachedTargetTimeframe({
766
+ timeout: 3e3
767
+ });
720
768
  }
721
769
  get profileDocument() {
722
770
  return this._profileStateMachine.processor.profile;
@@ -733,11 +781,15 @@ var Identity = class {
733
781
  get haloGenesisFeedKey() {
734
782
  return this.space.genesisFeedKey;
735
783
  }
784
+ get deviceCredentialChain() {
785
+ return this._deviceStateMachine.processor.deviceCredentialChain;
786
+ }
736
787
  getAdmissionCredentials() {
788
+ var _a, _b;
737
789
  return {
738
790
  deviceKey: this.deviceKey,
739
- controlFeedKey: this.space.controlFeedKey,
740
- dataFeedKey: this.space.dataFeedKey
791
+ controlFeedKey: (_a = this.space.controlFeedKey) != null ? _a : (0, import_debug3.failUndefined)(),
792
+ dataFeedKey: (_b = this.space.dataFeedKey) != null ? _b : (0, import_debug3.failUndefined)()
741
793
  };
742
794
  }
743
795
  /**
@@ -745,14 +797,14 @@ var Identity = class {
745
797
  * Requires identity to be ready.
746
798
  */
747
799
  getIdentityCredentialSigner() {
748
- (0, import_node_assert2.default)(this._deviceStateMachine.processor.deviceCredentialChain, "Device credential chain is not ready.");
749
- return (0, import_credentials2.createCredentialSignerWithChain)(this._signer, this._deviceStateMachine.processor.deviceCredentialChain, this.deviceKey);
800
+ (0, import_node_assert3.default)(this._deviceStateMachine.processor.deviceCredentialChain, "Device credential chain is not ready.");
801
+ return (0, import_credentials3.createCredentialSignerWithChain)(this._signer, this._deviceStateMachine.processor.deviceCredentialChain, this.deviceKey);
750
802
  }
751
803
  /**
752
804
  * Issues credentials as device.
753
805
  */
754
806
  getDeviceCredentialSigner() {
755
- return (0, import_credentials2.createCredentialSignerWithKey)(this._signer, this.deviceKey);
807
+ return (0, import_credentials3.createCredentialSignerWithKey)(this._signer, this.deviceKey);
756
808
  }
757
809
  async admitDevice({ deviceKey, controlFeedKey, dataFeedKey }) {
758
810
  (0, import_log3.log)("Admitting device:", {
@@ -763,7 +815,7 @@ var Identity = class {
763
815
  dataFeedKey
764
816
  }, {
765
817
  file: "identity.ts",
766
- line: 155,
818
+ line: 160,
767
819
  scope: this,
768
820
  callSite: (f, a) => f(...a)
769
821
  });
@@ -784,7 +836,7 @@ var Identity = class {
784
836
  spaceKey: this.haloSpaceKey,
785
837
  deviceKey,
786
838
  identityKey: this.identityKey,
787
- designation: import_credentials3.AdmittedFeed.Designation.CONTROL
839
+ designation: import_credentials4.AdmittedFeed.Designation.CONTROL
788
840
  }
789
841
  }),
790
842
  await signer.createCredential({
@@ -794,31 +846,33 @@ var Identity = class {
794
846
  spaceKey: this.haloSpaceKey,
795
847
  deviceKey,
796
848
  identityKey: this.identityKey,
797
- designation: import_credentials3.AdmittedFeed.Designation.DATA
849
+ designation: import_credentials4.AdmittedFeed.Designation.DATA
798
850
  }
799
851
  })
800
852
  ].map((credential) => ({
801
- "@type": "dxos.echo.feed.CredentialsMessage",
802
- credential
853
+ credential: {
854
+ credential
855
+ }
803
856
  })));
804
857
  }
805
858
  };
806
859
 
807
860
  // packages/sdk/client-services/src/packlets/identity/identity-manager.ts
808
- var import_node_assert3 = __toESM(require("node:assert"));
809
- var import_async6 = require("@dxos/async");
810
- var import_credentials4 = require("@dxos/credentials");
861
+ var import_node_assert4 = __toESM(require("node:assert"));
862
+ var import_async5 = require("@dxos/async");
863
+ var import_credentials5 = require("@dxos/credentials");
811
864
  var import_log4 = require("@dxos/log");
812
- var import_credentials5 = require("@dxos/protocols/proto/dxos/halo/credentials");
865
+ var import_credentials6 = require("@dxos/protocols/proto/dxos/halo/credentials");
813
866
  var import_util3 = require("@dxos/util");
814
867
  var IdentityManager = class {
815
868
  // TODO(burdon): IdentityManagerParams.
816
869
  // TODO(dmaretskyi): Perhaps this should take/generate the peerKey outside of an initialized identity.
817
- constructor(_metadataStore, _keyring, _spaceManager) {
870
+ constructor(_metadataStore, _keyring, _feedStore, _spaceManager) {
818
871
  this._metadataStore = _metadataStore;
819
872
  this._keyring = _keyring;
873
+ this._feedStore = _feedStore;
820
874
  this._spaceManager = _spaceManager;
821
- this.stateUpdate = new import_async6.Event();
875
+ this.stateUpdate = new import_async5.Event();
822
876
  }
823
877
  get identity() {
824
878
  return this._identity;
@@ -830,7 +884,7 @@ var IdentityManager = class {
830
884
  identityRecord
831
885
  }, {
832
886
  file: "identity-manager.ts",
833
- line: 57,
887
+ line: 63,
834
888
  scope: this,
835
889
  callSite: (f, a) => f(...a)
836
890
  });
@@ -846,10 +900,10 @@ var IdentityManager = class {
846
900
  await ((_a = this._identity) == null ? void 0 : _a.close());
847
901
  }
848
902
  async createIdentity({ displayName } = {}) {
849
- (0, import_node_assert3.default)(!this._identity, "Identity already exists.");
903
+ (0, import_node_assert4.default)(!this._identity, "Identity already exists.");
850
904
  (0, import_log4.log)("creating identity...", {}, {
851
905
  file: "identity-manager.ts",
852
- line: 72,
906
+ line: 78,
853
907
  scope: this,
854
908
  callSite: (f, a) => f(...a)
855
909
  });
@@ -867,12 +921,12 @@ var IdentityManager = class {
867
921
  const identity = await this._constructIdentity(identityRecord);
868
922
  await identity.open();
869
923
  {
870
- const generator = new import_credentials4.CredentialGenerator(this._keyring, identityRecord.identityKey, identityRecord.deviceKey);
924
+ const generator = new import_credentials5.CredentialGenerator(this._keyring, identityRecord.identityKey, identityRecord.deviceKey);
871
925
  const credentials = [
872
926
  // Space genesis.
873
927
  ...await generator.createSpaceGenesis(identityRecord.haloSpace.spaceKey, identityRecord.haloSpace.genesisFeedKey),
874
928
  // Feed admission.
875
- await generator.createFeedAdmission(identityRecord.haloSpace.spaceKey, identityRecord.haloSpace.writeDataFeedKey, import_credentials5.AdmittedFeed.Designation.DATA)
929
+ await generator.createFeedAdmission(identityRecord.haloSpace.spaceKey, identityRecord.haloSpace.writeDataFeedKey, import_credentials6.AdmittedFeed.Designation.DATA)
876
930
  ];
877
931
  if (displayName) {
878
932
  credentials.push(await generator.createProfileCredential({
@@ -882,8 +936,9 @@ var IdentityManager = class {
882
936
  credentials.push(await generator.createDeviceAuthorization(identityRecord.deviceKey));
883
937
  for (const credential of credentials) {
884
938
  await identity.controlPipeline.writer.write({
885
- "@type": "dxos.echo.feed.CredentialsMessage",
886
- credential
939
+ credential: {
940
+ credential
941
+ }
887
942
  });
888
943
  }
889
944
  }
@@ -896,7 +951,7 @@ var IdentityManager = class {
896
951
  deviceKey: identity.deviceKey
897
952
  }, {
898
953
  file: "identity-manager.ts",
899
- line: 131,
954
+ line: 136,
900
955
  scope: this,
901
956
  callSite: (f, a) => f(...a)
902
957
  });
@@ -910,47 +965,65 @@ var IdentityManager = class {
910
965
  params
911
966
  }, {
912
967
  file: "identity-manager.ts",
913
- line: 139,
968
+ line: 144,
914
969
  scope: this,
915
970
  callSite: (f, a) => f(...a)
916
971
  });
917
- (0, import_node_assert3.default)(!this._identity, "Identity already exists.");
972
+ (0, import_node_assert4.default)(!this._identity, "Identity already exists.");
918
973
  const identityRecord = {
919
974
  identityKey: params.identityKey,
920
- deviceKey: await this._keyring.createKey(),
975
+ deviceKey: params.deviceKey,
921
976
  haloSpace: {
922
977
  spaceKey: params.haloSpaceKey,
923
978
  genesisFeedKey: params.haloGenesisFeedKey,
924
- writeControlFeedKey: await this._keyring.createKey(),
925
- writeDataFeedKey: await this._keyring.createKey()
979
+ writeControlFeedKey: params.controlFeedKey,
980
+ writeDataFeedKey: params.dataFeedKey
926
981
  }
927
982
  };
928
983
  const identity = await this._constructIdentity(identityRecord);
929
984
  await identity.open();
930
985
  this._identity = identity;
931
986
  await this._metadataStore.setIdentityRecord(identityRecord);
987
+ await this._identity.ready();
932
988
  this.stateUpdate.emit();
989
+ (0, import_log4.log)("accepted identity", {
990
+ identityKey: identity.identityKey,
991
+ deviceKey: identity.deviceKey
992
+ }, {
993
+ file: "identity-manager.ts",
994
+ line: 164,
995
+ scope: this,
996
+ callSite: (f, a) => f(...a)
997
+ });
933
998
  return identity;
934
999
  }
935
1000
  async _constructIdentity(identityRecord) {
936
- (0, import_node_assert3.default)(!this._identity);
1001
+ (0, import_node_assert4.default)(!this._identity);
937
1002
  (0, import_log4.log)("constructing identity", {
938
1003
  identityRecord
939
1004
  }, {
940
1005
  file: "identity-manager.ts",
941
- line: 163,
1006
+ line: 170,
942
1007
  scope: this,
943
1008
  callSite: (f, a) => f(...a)
944
1009
  });
1010
+ const controlFeed = await this._feedStore.openFeed(identityRecord.haloSpace.writeControlFeedKey, {
1011
+ writable: true
1012
+ });
1013
+ const dataFeed = await this._feedStore.openFeed(identityRecord.haloSpace.writeDataFeedKey, {
1014
+ writable: true
1015
+ });
945
1016
  const space = await this._constructSpace({
946
1017
  spaceRecord: identityRecord.haloSpace,
947
1018
  swarmIdentity: {
948
1019
  peerKey: identityRecord.deviceKey,
949
- credentialProvider: createAuthProvider((0, import_credentials4.createCredentialSignerWithKey)(this._keyring, identityRecord.deviceKey)),
1020
+ credentialProvider: createAuthProvider((0, import_credentials5.createCredentialSignerWithKey)(this._keyring, identityRecord.deviceKey)),
950
1021
  credentialAuthenticator: (0, import_util3.deferFunction)(() => identity.authVerifier.verifier)
951
1022
  },
952
1023
  identityKey: identityRecord.identityKey
953
1024
  });
1025
+ space.setControlFeed(controlFeed);
1026
+ space.setDataFeed(dataFeed);
954
1027
  const identity = new Identity({
955
1028
  space,
956
1029
  signer: this._keyring,
@@ -961,7 +1034,7 @@ var IdentityManager = class {
961
1034
  identityKey: identityRecord.identityKey
962
1035
  }, {
963
1036
  file: "identity-manager.ts",
964
- line: 180,
1037
+ line: 196,
965
1038
  scope: this,
966
1039
  callSite: (f, a) => f(...a)
967
1040
  });
@@ -971,9 +1044,7 @@ var IdentityManager = class {
971
1044
  return this._spaceManager.constructSpace({
972
1045
  metadata: {
973
1046
  key: spaceRecord.spaceKey,
974
- genesisFeedKey: spaceRecord.genesisFeedKey,
975
- controlFeedKey: spaceRecord.writeControlFeedKey,
976
- dataFeedKey: spaceRecord.writeDataFeedKey
1047
+ genesisFeedKey: spaceRecord.genesisFeedKey
977
1048
  },
978
1049
  swarmIdentity,
979
1050
  onNetworkConnection: () => {
@@ -997,11 +1068,10 @@ var InvitationEncoder = class {
997
1068
  };
998
1069
 
999
1070
  // packages/sdk/client-services/src/packlets/invitations/halo-invitations-handler.ts
1000
- var import_node_assert5 = __toESM(require("node:assert"));
1001
- var import_async8 = require("@dxos/async");
1002
- var import_context2 = require("@dxos/context");
1003
- var import_credentials6 = require("@dxos/credentials");
1004
- var import_debug3 = require("@dxos/debug");
1071
+ var import_node_assert6 = __toESM(require("node:assert"));
1072
+ var import_async7 = require("@dxos/async");
1073
+ var import_context3 = require("@dxos/context");
1074
+ var import_credentials7 = require("@dxos/credentials");
1005
1075
  var import_keys4 = require("@dxos/keys");
1006
1076
  var import_log5 = require("@dxos/log");
1007
1077
  var import_network_manager = require("@dxos/network-manager");
@@ -1011,13 +1081,13 @@ var import_invitations = require("@dxos/protocols/proto/dxos/halo/invitations");
1011
1081
  var import_teleport = require("@dxos/teleport");
1012
1082
 
1013
1083
  // packages/sdk/client-services/src/packlets/invitations/invitations.ts
1014
- var import_node_assert4 = __toESM(require("node:assert"));
1015
- var import_async7 = require("@dxos/async");
1084
+ var import_node_assert5 = __toESM(require("node:assert"));
1085
+ var import_async6 = require("@dxos/async");
1016
1086
  var import_services = require("@dxos/protocols/proto/dxos/client/services");
1017
1087
  var AUTHENTICATION_CODE_LENGTH = 6;
1018
1088
  var INVITATION_TIMEOUT = 3 * 6e4;
1019
- var ON_CLOSE_DELAY = 500;
1020
- var InvitationObservableProvider = class extends import_async7.CancellableObservableProvider {
1089
+ var ON_CLOSE_DELAY = 1e3;
1090
+ var InvitationObservableProvider = class extends import_async6.CancellableObservableProvider {
1021
1091
  get invitation() {
1022
1092
  return this._invitation;
1023
1093
  }
@@ -1039,7 +1109,7 @@ var wrapObservable = async (observable) => {
1039
1109
  return new Promise((resolve, reject) => {
1040
1110
  const unsubscribe = observable.subscribe({
1041
1111
  onSuccess: (invitation) => {
1042
- (0, import_node_assert4.default)(invitation.state === import_services.Invitation.State.SUCCESS);
1112
+ (0, import_node_assert5.default)(invitation.state === import_services.Invitation.State.SUCCESS);
1043
1113
  unsubscribe();
1044
1114
  resolve(invitation);
1045
1115
  },
@@ -1062,25 +1132,24 @@ var AbstractInvitationsHandler = class {
1062
1132
  // packages/sdk/client-services/src/packlets/invitations/halo-invitations-handler.ts
1063
1133
  var HaloInvitationsHandler = class extends AbstractInvitationsHandler {
1064
1134
  // prettier-ignore
1065
- constructor(networkManager, _identityManager) {
1066
- super(networkManager);
1067
- this._identityManager = _identityManager;
1135
+ constructor(_params) {
1136
+ super(_params.networkManager);
1137
+ this._params = _params;
1068
1138
  }
1069
1139
  /**
1070
1140
  * Creates an invitation and listens for a join request from the invited (guest) peer.
1071
1141
  */
1072
1142
  createInvitation(context, options) {
1073
- var _a;
1074
1143
  const { type, timeout = INVITATION_TIMEOUT, swarmKey } = options != null ? options : {};
1075
- (0, import_node_assert5.default)(type !== import_services2.Invitation.Type.OFFLINE);
1076
- const identity = (_a = this._identityManager.identity) != null ? _a : (0, import_debug3.failUndefined)();
1144
+ (0, import_node_assert6.default)(type !== import_services2.Invitation.Type.OFFLINE);
1145
+ const identity = this._params.getIdentity();
1077
1146
  const invitation = {
1078
1147
  type,
1079
1148
  invitationId: import_keys4.PublicKey.random().toHex(),
1080
1149
  swarmKey: swarmKey != null ? swarmKey : import_keys4.PublicKey.random(),
1081
- authenticationCode: (0, import_credentials6.generatePasscode)(AUTHENTICATION_CODE_LENGTH)
1150
+ authenticationCode: (0, import_credentials7.generatePasscode)(AUTHENTICATION_CODE_LENGTH)
1082
1151
  };
1083
- const ctx = new import_context2.Context({
1152
+ const ctx = new import_context3.Context({
1084
1153
  onError: (err) => {
1085
1154
  void ctx.dispose();
1086
1155
  observable.callback.onError(err);
@@ -1090,111 +1159,108 @@ var HaloInvitationsHandler = class extends AbstractInvitationsHandler {
1090
1159
  await ctx.dispose();
1091
1160
  });
1092
1161
  let authenticationCode;
1093
- const complete = new import_async8.Trigger();
1094
- const createExtension = () => {
1095
- const hostInvitationExtension = new HostHaloInvitationExtension({
1096
- requestAdmission: async () => {
1097
- var _a2, _b;
1098
- (0, import_log5.log)("responding with admission offer", {
1099
- host: identity.deviceKey
1100
- }, {
1101
- file: "halo-invitations-handler.ts",
1102
- line: 84,
1103
- scope: this,
1104
- callSite: (f, a) => f(...a)
1105
- });
1106
- (_b = (_a2 = observable.callback).onAuthenticating) == null ? void 0 : _b.call(_a2, invitation);
1107
- return {
1108
- identityKey: identity.identityKey,
1109
- haloSpaceKey: identity.haloSpaceKey,
1110
- genesisFeedKey: identity.haloGenesisFeedKey
1111
- };
1112
- },
1113
- authenticate: async ({ authenticationCode: code }) => {
1114
- (0, import_log5.log)("received authentication request", {
1115
- authenticationCode: code
1162
+ const complete = new import_async7.Trigger();
1163
+ const createExtension = () => new HostHaloInvitationExtension({
1164
+ requestAdmission: async () => {
1165
+ var _a, _b;
1166
+ (0, import_log5.log)("responding with admission offer", {
1167
+ host: identity.deviceKey
1168
+ }, {
1169
+ file: "halo-invitations-handler.ts",
1170
+ line: 91,
1171
+ scope: this,
1172
+ callSite: (f, a) => f(...a)
1173
+ });
1174
+ (_b = (_a = observable.callback).onAuthenticating) == null ? void 0 : _b.call(_a, invitation);
1175
+ return {
1176
+ identityKey: identity.identityKey,
1177
+ haloSpaceKey: identity.haloSpaceKey,
1178
+ genesisFeedKey: identity.haloGenesisFeedKey
1179
+ };
1180
+ },
1181
+ authenticate: async ({ authenticationCode: code }) => {
1182
+ (0, import_log5.log)("received authentication request", {
1183
+ authenticationCode: code
1184
+ }, {
1185
+ file: "halo-invitations-handler.ts",
1186
+ line: 105,
1187
+ scope: this,
1188
+ callSite: (f, a) => f(...a)
1189
+ });
1190
+ authenticationCode = code;
1191
+ return {
1192
+ status: import_invitations.AuthenticationResponse.Status.OK
1193
+ };
1194
+ },
1195
+ // TODO(burdon): Not used: controlFeedKey, dataFeedKey.
1196
+ presentAdmissionCredentials: async (credentials) => {
1197
+ try {
1198
+ if (invitation.type !== import_services2.Invitation.Type.INTERACTIVE_TESTING) {
1199
+ if (invitation.authenticationCode === void 0 || invitation.authenticationCode !== authenticationCode) {
1200
+ throw new Error(`invalid authentication code: ${authenticationCode}`);
1201
+ }
1202
+ }
1203
+ (0, import_log5.log)("writing guest credentials", {
1204
+ host: identity.deviceKey,
1205
+ guest: credentials.deviceKey
1116
1206
  }, {
1117
1207
  file: "halo-invitations-handler.ts",
1118
- line: 98,
1208
+ line: 120,
1119
1209
  scope: this,
1120
1210
  callSite: (f, a) => f(...a)
1121
1211
  });
1122
- authenticationCode = code;
1123
- return {
1124
- status: import_invitations.AuthenticationResponse.Status.OK
1125
- };
1126
- },
1127
- // TODO(burdon): Not used: controlFeedKey, dataFeedKey.
1128
- presentAdmissionCredentials: async (credentials) => {
1212
+ await identity.admitDevice(credentials);
1213
+ complete.wake(credentials.deviceKey);
1214
+ } catch (err) {
1215
+ observable.callback.onError(err);
1216
+ throw err;
1217
+ }
1218
+ },
1219
+ onOpen: () => {
1220
+ (0, import_async7.scheduleTask)(ctx, async () => {
1221
+ var _a, _b;
1129
1222
  try {
1130
- if (invitation.type !== import_services2.Invitation.Type.INTERACTIVE_TESTING) {
1131
- if (invitation.authenticationCode === void 0 || invitation.authenticationCode !== authenticationCode) {
1132
- throw new Error(`invalid authentication code: ${authenticationCode}`);
1133
- }
1134
- }
1135
- (0, import_log5.log)("writing guest credentials", {
1223
+ (0, import_log5.log)("connected", {
1224
+ host: identity.deviceKey
1225
+ }, {
1226
+ file: "halo-invitations-handler.ts",
1227
+ line: 136,
1228
+ scope: this,
1229
+ callSite: (f, a) => f(...a)
1230
+ });
1231
+ (_b = (_a = observable.callback).onConnected) == null ? void 0 : _b.call(_a, invitation);
1232
+ const deviceKey = await complete.wait({
1233
+ timeout
1234
+ });
1235
+ (0, import_log5.log)("admitted guest", {
1136
1236
  host: identity.deviceKey,
1137
- guest: credentials.deviceKey
1237
+ guest: deviceKey
1138
1238
  }, {
1139
1239
  file: "halo-invitations-handler.ts",
1140
- line: 113,
1240
+ line: 139,
1141
1241
  scope: this,
1142
1242
  callSite: (f, a) => f(...a)
1143
1243
  });
1144
- await identity.admitDevice(credentials);
1145
- complete.wake(credentials.deviceKey);
1244
+ observable.callback.onSuccess(invitation);
1146
1245
  } catch (err) {
1147
- observable.callback.onError(err);
1148
- throw err;
1149
- }
1150
- },
1151
- onOpen: () => {
1152
- (0, import_async8.scheduleTask)(ctx, async () => {
1153
- var _a2, _b;
1154
- try {
1155
- (0, import_log5.log)("connected", {
1156
- host: identity.deviceKey
1157
- }, {
1158
- file: "halo-invitations-handler.ts",
1159
- line: 129,
1160
- scope: this,
1161
- callSite: (f, a) => f(...a)
1162
- });
1163
- (_b = (_a2 = observable.callback).onConnected) == null ? void 0 : _b.call(_a2, invitation);
1164
- const deviceKey = await complete.wait({
1165
- timeout
1166
- });
1167
- (0, import_log5.log)("admitted guest", {
1168
- host: identity.deviceKey,
1169
- guest: deviceKey
1170
- }, {
1246
+ if (!observable.cancelled) {
1247
+ import_log5.log.error("failed", err, {
1171
1248
  file: "halo-invitations-handler.ts",
1172
- line: 132,
1249
+ line: 143,
1173
1250
  scope: this,
1174
1251
  callSite: (f, a) => f(...a)
1175
1252
  });
1176
- observable.callback.onSuccess(invitation);
1177
- } catch (err) {
1178
- if (!observable.cancelled) {
1179
- import_log5.log.error("failed", err, {
1180
- file: "halo-invitations-handler.ts",
1181
- line: 136,
1182
- scope: this,
1183
- callSite: (f, a) => f(...a)
1184
- });
1185
- observable.callback.onError(err);
1186
- }
1187
- } finally {
1188
- await (0, import_async8.sleep)(ON_CLOSE_DELAY);
1189
- await ctx.dispose();
1253
+ observable.callback.onError(err);
1190
1254
  }
1191
- });
1192
- }
1193
- });
1194
- return hostInvitationExtension;
1195
- };
1196
- (0, import_async8.scheduleTask)(ctx, async () => {
1197
- var _a2, _b;
1255
+ } finally {
1256
+ await (0, import_async7.sleep)(ON_CLOSE_DELAY);
1257
+ await ctx.dispose();
1258
+ }
1259
+ });
1260
+ }
1261
+ });
1262
+ (0, import_async7.scheduleTask)(ctx, async () => {
1263
+ var _a, _b;
1198
1264
  const topic = invitation.swarmKey;
1199
1265
  const swarmConnection = await this._networkManager.joinSwarm({
1200
1266
  topic,
@@ -1205,7 +1271,7 @@ var HaloInvitationsHandler = class extends AbstractInvitationsHandler {
1205
1271
  topology: new import_network_manager.StarTopology(topic)
1206
1272
  });
1207
1273
  ctx.onDispose(() => swarmConnection.close());
1208
- (_b = (_a2 = observable.callback).onConnecting) == null ? void 0 : _b.call(_a2, invitation);
1274
+ (_b = (_a = observable.callback).onConnecting) == null ? void 0 : _b.call(_a, invitation);
1209
1275
  });
1210
1276
  return observable;
1211
1277
  }
@@ -1216,13 +1282,13 @@ var HaloInvitationsHandler = class extends AbstractInvitationsHandler {
1216
1282
  */
1217
1283
  acceptInvitation(invitation, options) {
1218
1284
  const { timeout = INVITATION_TIMEOUT } = options != null ? options : {};
1219
- const ctx = new import_context2.Context({
1285
+ const ctx = new import_context3.Context({
1220
1286
  onError: (err) => {
1221
1287
  void ctx.dispose();
1222
1288
  observable.callback.onError(err);
1223
1289
  }
1224
1290
  });
1225
- const authenticated = new import_async8.Trigger();
1291
+ const authenticated = new import_async7.Trigger();
1226
1292
  const observable = new AuthenticatingInvitationProvider({
1227
1293
  onCancel: async () => {
1228
1294
  await ctx.dispose();
@@ -1233,11 +1299,11 @@ var HaloInvitationsHandler = class extends AbstractInvitationsHandler {
1233
1299
  }
1234
1300
  });
1235
1301
  let connectionCount = 0;
1236
- const complete = new import_async8.Trigger();
1302
+ const complete = new import_async7.Trigger();
1237
1303
  const createExtension = () => {
1238
1304
  const extension = new GuestHaloInvitationExtension({
1239
1305
  onOpen: () => {
1240
- (0, import_async8.scheduleTask)(ctx, async () => {
1306
+ (0, import_async7.scheduleTask)(ctx, async () => {
1241
1307
  var _a, _b, _c, _d;
1242
1308
  try {
1243
1309
  if (++connectionCount > 1) {
@@ -1245,14 +1311,14 @@ var HaloInvitationsHandler = class extends AbstractInvitationsHandler {
1245
1311
  }
1246
1312
  (0, import_log5.log)("connected", {}, {
1247
1313
  file: "halo-invitations-handler.ts",
1248
- line: 209,
1314
+ line: 214,
1249
1315
  scope: this,
1250
1316
  callSite: (f, a) => f(...a)
1251
1317
  });
1252
1318
  (_b = (_a = observable.callback).onConnected) == null ? void 0 : _b.call(_a, invitation);
1253
1319
  (0, import_log5.log)("sending admission request", {}, {
1254
1320
  file: "halo-invitations-handler.ts",
1255
- line: 213,
1321
+ line: 218,
1256
1322
  scope: this,
1257
1323
  callSite: (f, a) => f(...a)
1258
1324
  });
@@ -1260,7 +1326,7 @@ var HaloInvitationsHandler = class extends AbstractInvitationsHandler {
1260
1326
  if (invitation.type === void 0 || invitation.type === import_services2.Invitation.Type.INTERACTIVE) {
1261
1327
  (0, import_log5.log)("guest waiting for authentication code...", {}, {
1262
1328
  file: "halo-invitations-handler.ts",
1263
- line: 220,
1329
+ line: 225,
1264
1330
  scope: this,
1265
1331
  callSite: (f, a) => f(...a)
1266
1332
  });
@@ -1270,7 +1336,7 @@ var HaloInvitationsHandler = class extends AbstractInvitationsHandler {
1270
1336
  });
1271
1337
  (0, import_log5.log)("sending authentication request", {}, {
1272
1338
  file: "halo-invitations-handler.ts",
1273
- line: 223,
1339
+ line: 228,
1274
1340
  scope: this,
1275
1341
  callSite: (f, a) => f(...a)
1276
1342
  });
@@ -1278,28 +1344,40 @@ var HaloInvitationsHandler = class extends AbstractInvitationsHandler {
1278
1344
  authenticationCode
1279
1345
  });
1280
1346
  }
1281
- const identity = await this._identityManager.acceptIdentity({
1282
- identityKey,
1283
- haloSpaceKey,
1284
- haloGenesisFeedKey: genesisFeedKey
1285
- });
1347
+ const deviceKey = await this._params.keyring.createKey();
1348
+ const controlFeedKey = await this._params.keyring.createKey();
1349
+ const dataFeedKey = await this._params.keyring.createKey();
1286
1350
  (0, import_log5.log)("presenting admission credentials", {
1287
- guest: identity.deviceKey,
1288
- identityKey
1351
+ identityKey,
1352
+ deviceKey,
1353
+ controlFeedKey,
1354
+ dataFeedKey
1289
1355
  }, {
1290
1356
  file: "halo-invitations-handler.ts",
1291
- line: 236,
1357
+ line: 237,
1292
1358
  scope: this,
1293
1359
  callSite: (f, a) => f(...a)
1294
1360
  });
1295
- await extension.rpc.HaloHostService.presentAdmissionCredentials(identity.getAdmissionCredentials());
1296
- (0, import_log5.log)("admitted by host", {
1297
- guest: identity.deviceKey,
1298
- identityKey
1299
- }, {
1300
- file: "halo-invitations-handler.ts",
1301
- line: 240,
1302
- scope: this,
1361
+ await extension.rpc.HaloHostService.presentAdmissionCredentials({
1362
+ deviceKey,
1363
+ controlFeedKey,
1364
+ dataFeedKey
1365
+ });
1366
+ const identity = await this._params.acceptIdentity({
1367
+ identityKey,
1368
+ deviceKey,
1369
+ haloSpaceKey,
1370
+ haloGenesisFeedKey: genesisFeedKey,
1371
+ controlFeedKey,
1372
+ dataFeedKey
1373
+ });
1374
+ (0, import_log5.log)("admitted by host", {
1375
+ guest: identity.deviceKey,
1376
+ identityKey
1377
+ }, {
1378
+ file: "halo-invitations-handler.ts",
1379
+ line: 256,
1380
+ scope: this,
1303
1381
  callSite: (f, a) => f(...a)
1304
1382
  });
1305
1383
  complete.wake(identityKey);
@@ -1307,7 +1385,7 @@ var HaloInvitationsHandler = class extends AbstractInvitationsHandler {
1307
1385
  if (!observable.cancelled) {
1308
1386
  import_log5.log.warn("auth failed", err, {
1309
1387
  file: "halo-invitations-handler.ts",
1310
- line: 244,
1388
+ line: 260,
1311
1389
  scope: this,
1312
1390
  callSite: (f, a) => f(...a)
1313
1391
  });
@@ -1321,9 +1399,9 @@ var HaloInvitationsHandler = class extends AbstractInvitationsHandler {
1321
1399
  });
1322
1400
  return extension;
1323
1401
  };
1324
- (0, import_async8.scheduleTask)(ctx, async () => {
1402
+ (0, import_async7.scheduleTask)(ctx, async () => {
1325
1403
  var _a, _b;
1326
- (0, import_node_assert5.default)(invitation.swarmKey);
1404
+ (0, import_node_assert6.default)(invitation.swarmKey);
1327
1405
  const topic = invitation.swarmKey;
1328
1406
  const swarmConnection = await this._networkManager.joinSwarm({
1329
1407
  topic,
@@ -1393,8 +1471,8 @@ var GuestHaloInvitationExtension = class extends import_teleport.RpcExtension {
1393
1471
  };
1394
1472
 
1395
1473
  // packages/sdk/client-services/src/packlets/invitations/invitations-proxy.ts
1396
- var import_node_assert6 = __toESM(require("node:assert"));
1397
- var import_async9 = require("@dxos/async");
1474
+ var import_node_assert7 = __toESM(require("node:assert"));
1475
+ var import_async8 = require("@dxos/async");
1398
1476
  var import_log6 = require("@dxos/log");
1399
1477
  var import_services3 = require("@dxos/protocols/proto/dxos/client/services");
1400
1478
  var AbstractInvitationsProxy = class {
@@ -1421,7 +1499,7 @@ var AbstractInvitationsProxy = class {
1421
1499
  observable.setInvitation(invitation2);
1422
1500
  switch (invitation2.state) {
1423
1501
  case import_services3.Invitation.State.CONNECTING: {
1424
- (0, import_node_assert6.default)(invitation2.invitationId);
1502
+ (0, import_node_assert7.default)(invitation2.invitationId);
1425
1503
  invitationId = invitation2.invitationId;
1426
1504
  (_b = (_a = observable.callback).onConnecting) == null ? void 0 : _b.call(_a, invitation2);
1427
1505
  break;
@@ -1453,18 +1531,18 @@ var AbstractInvitationsProxy = class {
1453
1531
  }
1454
1532
  }, (err) => {
1455
1533
  if (err) {
1456
- (0, import_async9.observableError)(observable, err);
1534
+ (0, import_async8.observableError)(observable, err);
1457
1535
  }
1458
1536
  });
1459
1537
  return observable;
1460
1538
  }
1461
1539
  acceptInvitation(invitation, options) {
1462
- (0, import_node_assert6.default)(invitation && invitation.swarmKey);
1540
+ (0, import_node_assert7.default)(invitation && invitation.swarmKey);
1463
1541
  const observable = new AuthenticatingInvitationProvider({
1464
1542
  onCancel: async () => {
1465
1543
  var _a;
1466
1544
  const invitationId = (_a = observable.invitation) == null ? void 0 : _a.invitationId;
1467
- (0, import_node_assert6.default)(invitationId);
1545
+ (0, import_node_assert7.default)(invitationId);
1468
1546
  await this._invitationsService.cancelInvitation({
1469
1547
  invitationId
1470
1548
  });
@@ -1472,7 +1550,7 @@ var AbstractInvitationsProxy = class {
1472
1550
  onAuthenticate: async (authenticationCode) => {
1473
1551
  var _a;
1474
1552
  const invitationId = (_a = observable.invitation) == null ? void 0 : _a.invitationId;
1475
- (0, import_node_assert6.default)(invitationId);
1553
+ (0, import_node_assert7.default)(invitationId);
1476
1554
  await this._invitationsService.authenticate({
1477
1555
  invitationId,
1478
1556
  authenticationCode
@@ -1485,7 +1563,7 @@ var AbstractInvitationsProxy = class {
1485
1563
  });
1486
1564
  stream.subscribe((invitation2) => {
1487
1565
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1488
- (0, import_node_assert6.default)(invitation2.invitationId);
1566
+ (0, import_node_assert7.default)(invitation2.invitationId);
1489
1567
  observable.setInvitation(invitation2);
1490
1568
  switch (invitation2.state) {
1491
1569
  case import_services3.Invitation.State.CONNECTING: {
@@ -1519,7 +1597,7 @@ var AbstractInvitationsProxy = class {
1519
1597
  }
1520
1598
  }, (err) => {
1521
1599
  if (err) {
1522
- (0, import_async9.observableError)(observable, err);
1600
+ (0, import_async8.observableError)(observable, err);
1523
1601
  }
1524
1602
  });
1525
1603
  return observable;
@@ -1534,7 +1612,7 @@ var HaloInvitationsProxy = class extends AbstractInvitationsProxy {
1534
1612
  };
1535
1613
 
1536
1614
  // packages/sdk/client-services/src/packlets/invitations/invitations-service.ts
1537
- var import_node_assert7 = __toESM(require("node:assert"));
1615
+ var import_node_assert8 = __toESM(require("node:assert"));
1538
1616
  var import_codec_protobuf8 = require("@dxos/codec-protobuf");
1539
1617
  var import_log7 = require("@dxos/log");
1540
1618
  var import_services4 = require("@dxos/protocols/proto/dxos/client/services");
@@ -1571,30 +1649,30 @@ var AbstractInvitationsService = class {
1571
1649
  });
1572
1650
  observable.subscribe({
1573
1651
  onConnecting: (invitation2) => {
1574
- (0, import_node_assert7.default)(invitation2.invitationId);
1652
+ (0, import_node_assert8.default)(invitation2.invitationId);
1575
1653
  invitationId = invitation2.invitationId;
1576
1654
  this._createInvitations.set(invitation2.invitationId, observable);
1577
1655
  invitation2.state = import_services4.Invitation.State.CONNECTING;
1578
1656
  next(invitation2);
1579
1657
  },
1580
1658
  onConnected: (invitation2) => {
1581
- (0, import_node_assert7.default)(invitation2.invitationId);
1659
+ (0, import_node_assert8.default)(invitation2.invitationId);
1582
1660
  invitation2.state = import_services4.Invitation.State.CONNECTED;
1583
1661
  next(invitation2);
1584
1662
  },
1585
1663
  onAuthenticating: (invitation2) => {
1586
- (0, import_node_assert7.default)(invitation2.invitationId);
1664
+ (0, import_node_assert8.default)(invitation2.invitationId);
1587
1665
  invitation2.state = import_services4.Invitation.State.AUTHENTICATING;
1588
1666
  next(invitation2);
1589
1667
  },
1590
1668
  onSuccess: (invitation2) => {
1591
- (0, import_node_assert7.default)(invitation2.invitationId);
1669
+ (0, import_node_assert8.default)(invitation2.invitationId);
1592
1670
  invitation2.state = import_services4.Invitation.State.SUCCESS;
1593
1671
  next(invitation2);
1594
1672
  close();
1595
1673
  },
1596
1674
  onCancelled: () => {
1597
- (0, import_node_assert7.default)(invitationId);
1675
+ (0, import_node_assert8.default)(invitationId);
1598
1676
  invitation.invitationId = invitationId;
1599
1677
  invitation.state = import_services4.Invitation.State.CANCELLED;
1600
1678
  next(invitation);
@@ -1646,19 +1724,19 @@ var AbstractInvitationsService = class {
1646
1724
  const observable = invitationsHandler.acceptInvitation(invitation, options);
1647
1725
  observable.subscribe({
1648
1726
  onConnecting: (invitation2) => {
1649
- (0, import_node_assert7.default)(invitation2.invitationId);
1727
+ (0, import_node_assert8.default)(invitation2.invitationId);
1650
1728
  invitationId = invitation2.invitationId;
1651
1729
  this._acceptInvitations.set(invitation2.invitationId, observable);
1652
1730
  invitation2.state = import_services4.Invitation.State.CONNECTING;
1653
1731
  next(invitation2);
1654
1732
  },
1655
1733
  onConnected: (invitation2) => {
1656
- (0, import_node_assert7.default)(invitation2.invitationId);
1734
+ (0, import_node_assert8.default)(invitation2.invitationId);
1657
1735
  invitation2.state = import_services4.Invitation.State.CONNECTED;
1658
1736
  next(invitation2);
1659
1737
  },
1660
1738
  onAuthenticating: (invitation2) => {
1661
- (0, import_node_assert7.default)(invitation2.invitationId);
1739
+ (0, import_node_assert8.default)(invitation2.invitationId);
1662
1740
  invitation2.state = import_services4.Invitation.State.AUTHENTICATING;
1663
1741
  next(invitation2);
1664
1742
  },
@@ -1668,7 +1746,7 @@ var AbstractInvitationsService = class {
1668
1746
  close();
1669
1747
  },
1670
1748
  onCancelled: () => {
1671
- (0, import_node_assert7.default)(invitationId);
1749
+ (0, import_node_assert8.default)(invitationId);
1672
1750
  invitation.invitationId = invitationId;
1673
1751
  invitation.state = import_services4.Invitation.State.CANCELLED;
1674
1752
  next(invitation);
@@ -1714,7 +1792,7 @@ var AbstractInvitationsService = class {
1714
1792
  scope: this,
1715
1793
  callSite: (f, a) => f(...a)
1716
1794
  });
1717
- (0, import_node_assert7.default)(invitationId);
1795
+ (0, import_node_assert8.default)(invitationId);
1718
1796
  const observable = this._acceptInvitations.get(invitationId);
1719
1797
  if (!observable) {
1720
1798
  import_log7.log.warn("invalid invitation", {
@@ -1737,7 +1815,7 @@ var AbstractInvitationsService = class {
1737
1815
  scope: this,
1738
1816
  callSite: (f, a) => f(...a)
1739
1817
  });
1740
- (0, import_node_assert7.default)(invitation.invitationId);
1818
+ (0, import_node_assert8.default)(invitation.invitationId);
1741
1819
  const observable = (_a = this._createInvitations.get(invitation.invitationId)) != null ? _a : this._acceptInvitations.get(invitation.invitationId);
1742
1820
  if (!observable) {
1743
1821
  import_log7.log.warn("invalid invitation", {
@@ -1766,10 +1844,10 @@ var HaloInvitationsServiceImpl = class extends AbstractInvitationsService {
1766
1844
  };
1767
1845
 
1768
1846
  // packages/sdk/client-services/src/packlets/invitations/space-invitations-handler.ts
1769
- var import_node_assert8 = __toESM(require("node:assert"));
1770
- var import_async10 = require("@dxos/async");
1771
- var import_context3 = require("@dxos/context");
1772
- var import_credentials7 = require("@dxos/credentials");
1847
+ var import_node_assert9 = __toESM(require("node:assert"));
1848
+ var import_async9 = require("@dxos/async");
1849
+ var import_context4 = require("@dxos/context");
1850
+ var import_credentials8 = require("@dxos/credentials");
1773
1851
  var import_feed_store3 = require("@dxos/feed-store");
1774
1852
  var import_keys5 = require("@dxos/keys");
1775
1853
  var import_log8 = require("@dxos/log");
@@ -1792,16 +1870,16 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
1792
1870
  createInvitation(space, options) {
1793
1871
  let swarmConnection;
1794
1872
  const { type, timeout = INVITATION_TIMEOUT, swarmKey } = options != null ? options : {};
1795
- (0, import_node_assert8.default)(type !== import_services5.Invitation.Type.OFFLINE);
1796
- (0, import_node_assert8.default)(space);
1873
+ (0, import_node_assert9.default)(type !== import_services5.Invitation.Type.OFFLINE);
1874
+ (0, import_node_assert9.default)(space);
1797
1875
  const invitation = {
1798
1876
  type,
1799
1877
  invitationId: import_keys5.PublicKey.random().toHex(),
1800
1878
  swarmKey: swarmKey != null ? swarmKey : import_keys5.PublicKey.random(),
1801
1879
  spaceKey: space.key,
1802
- authenticationCode: (0, import_credentials7.generatePasscode)(AUTHENTICATION_CODE_LENGTH)
1880
+ authenticationCode: (0, import_credentials8.generatePasscode)(AUTHENTICATION_CODE_LENGTH)
1803
1881
  };
1804
- const ctx = new import_context3.Context({
1882
+ const ctx = new import_context4.Context({
1805
1883
  onError: (err) => {
1806
1884
  void ctx.dispose();
1807
1885
  observable.callback.onError(err);
@@ -1813,7 +1891,7 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
1813
1891
  let authenticationCode;
1814
1892
  let authenticationRetry = 0;
1815
1893
  const createExtension = () => {
1816
- const complete = new import_async10.Trigger();
1894
+ const complete = new import_async9.Trigger();
1817
1895
  let guestProfile;
1818
1896
  const hostInvitationExtension = new HostSpaceInvitationExtension({
1819
1897
  introduce: async ({ profile }) => {
@@ -1824,7 +1902,7 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
1824
1902
  spaceKey: space.key
1825
1903
  }, {
1826
1904
  file: "space-invitations-handler.ts",
1827
- line: 97,
1905
+ line: 98,
1828
1906
  scope: this,
1829
1907
  callSite: (f, a) => f(...a)
1830
1908
  });
@@ -1836,7 +1914,7 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
1836
1914
  authenticationCode: code
1837
1915
  }, {
1838
1916
  file: "space-invitations-handler.ts",
1839
- line: 111,
1917
+ line: 112,
1840
1918
  scope: this,
1841
1919
  callSite: (f, a) => f(...a)
1842
1920
  });
@@ -1866,14 +1944,14 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
1866
1944
  guest: deviceKey
1867
1945
  }, {
1868
1946
  file: "space-invitations-handler.ts",
1869
- line: 138,
1947
+ line: 139,
1870
1948
  scope: this,
1871
1949
  callSite: (f, a) => f(...a)
1872
1950
  });
1873
- const credentials = await (0, import_credentials7.createAdmissionCredentials)(this._signingContext.credentialSigner, identityKey, deviceKey, space.key, controlFeedKey, dataFeedKey, space.inner.genesisFeedKey, guestProfile);
1874
- (0, import_node_assert8.default)(credentials[0]["@type"] === "dxos.echo.feed.CredentialsMessage");
1875
- const spaceMemberCredential = credentials[0].credential;
1876
- (0, import_node_assert8.default)((0, import_credentials7.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember");
1951
+ const credentials = await (0, import_credentials8.createAdmissionCredentials)(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, guestProfile);
1952
+ (0, import_node_assert9.default)(credentials[0].credential);
1953
+ const spaceMemberCredential = credentials[0].credential.credential;
1954
+ (0, import_node_assert9.default)((0, import_credentials8.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember");
1877
1955
  await (0, import_feed_store3.writeMessages)(space.inner.controlPipeline.writer, credentials);
1878
1956
  complete.wake(deviceKey);
1879
1957
  return {
@@ -1885,14 +1963,14 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
1885
1963
  }
1886
1964
  },
1887
1965
  onOpen: () => {
1888
- (0, import_async10.scheduleTask)(ctx, async () => {
1966
+ (0, import_async9.scheduleTask)(ctx, async () => {
1889
1967
  var _a, _b;
1890
1968
  try {
1891
1969
  (0, import_log8.log)("connected", {
1892
1970
  host: this._signingContext.deviceKey
1893
1971
  }, {
1894
1972
  file: "space-invitations-handler.ts",
1895
- line: 172,
1973
+ line: 170,
1896
1974
  scope: this,
1897
1975
  callSite: (f, a) => f(...a)
1898
1976
  });
@@ -1905,7 +1983,7 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
1905
1983
  guest: deviceKey
1906
1984
  }, {
1907
1985
  file: "space-invitations-handler.ts",
1908
- line: 175,
1986
+ line: 173,
1909
1987
  scope: this,
1910
1988
  callSite: (f, a) => f(...a)
1911
1989
  });
@@ -1914,7 +1992,7 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
1914
1992
  if (!observable.cancelled) {
1915
1993
  import_log8.log.error("failed", err, {
1916
1994
  file: "space-invitations-handler.ts",
1917
- line: 179,
1995
+ line: 177,
1918
1996
  scope: this,
1919
1997
  callSite: (f, a) => f(...a)
1920
1998
  });
@@ -1922,7 +2000,7 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
1922
2000
  }
1923
2001
  } finally {
1924
2002
  if (type !== import_services5.Invitation.Type.MULTIUSE_TESTING) {
1925
- await (0, import_async10.sleep)(ON_CLOSE_DELAY);
2003
+ await (0, import_async9.sleep)(ON_CLOSE_DELAY);
1926
2004
  await ctx.dispose();
1927
2005
  }
1928
2006
  }
@@ -1931,7 +2009,7 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
1931
2009
  });
1932
2010
  return hostInvitationExtension;
1933
2011
  };
1934
- (0, import_async10.scheduleTask)(ctx, async () => {
2012
+ (0, import_async9.scheduleTask)(ctx, async () => {
1935
2013
  var _a, _b;
1936
2014
  const topic = invitation.swarmKey;
1937
2015
  const swarmConnection2 = await this._networkManager.joinSwarm({
@@ -1954,13 +2032,13 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
1954
2032
  */
1955
2033
  acceptInvitation(invitation, options) {
1956
2034
  const { timeout = INVITATION_TIMEOUT } = options != null ? options : {};
1957
- const ctx = new import_context3.Context({
2035
+ const ctx = new import_context4.Context({
1958
2036
  onError: (err) => {
1959
2037
  void ctx.dispose();
1960
2038
  observable.callback.onError(err);
1961
2039
  }
1962
2040
  });
1963
- const authenticated = new import_async10.Trigger();
2041
+ const authenticated = new import_async9.Trigger();
1964
2042
  const observable = new AuthenticatingInvitationProvider({
1965
2043
  onCancel: async () => {
1966
2044
  await ctx.dispose();
@@ -1970,11 +2048,11 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
1970
2048
  }
1971
2049
  });
1972
2050
  let connectionCount = 0;
1973
- const complete = new import_async10.Trigger();
2051
+ const complete = new import_async9.Trigger();
1974
2052
  const createExtension = () => {
1975
2053
  const extension = new GuestSpaceInvitationExtension({
1976
2054
  onOpen: () => {
1977
- (0, import_async10.scheduleTask)(ctx, async () => {
2055
+ (0, import_async9.scheduleTask)(ctx, async () => {
1978
2056
  var _a, _b, _c, _d;
1979
2057
  try {
1980
2058
  if (++connectionCount > 1) {
@@ -1984,7 +2062,7 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
1984
2062
  guest: this._signingContext.deviceKey
1985
2063
  }, {
1986
2064
  file: "space-invitations-handler.ts",
1987
- line: 252,
2065
+ line: 250,
1988
2066
  scope: this,
1989
2067
  callSite: (f, a) => f(...a)
1990
2068
  });
@@ -1993,7 +2071,7 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
1993
2071
  guest: this._signingContext.deviceKey
1994
2072
  }, {
1995
2073
  file: "space-invitations-handler.ts",
1996
- line: 256,
2074
+ line: 254,
1997
2075
  scope: this,
1998
2076
  callSite: (f, a) => f(...a)
1999
2077
  });
@@ -2004,7 +2082,7 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
2004
2082
  for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
2005
2083
  (0, import_log8.log)("guest waiting for authentication code...", {}, {
2006
2084
  file: "space-invitations-handler.ts",
2007
- line: 265,
2085
+ line: 263,
2008
2086
  scope: this,
2009
2087
  callSite: (f, a) => f(...a)
2010
2088
  });
@@ -2014,7 +2092,7 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
2014
2092
  });
2015
2093
  (0, import_log8.log)("sending authentication request", {}, {
2016
2094
  file: "space-invitations-handler.ts",
2017
- line: 269,
2095
+ line: 267,
2018
2096
  scope: this,
2019
2097
  callSite: (f, a) => f(...a)
2020
2098
  });
@@ -2032,7 +2110,7 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
2032
2110
  attempt
2033
2111
  }, {
2034
2112
  file: "space-invitations-handler.ts",
2035
- line: 279,
2113
+ line: 277,
2036
2114
  scope: this,
2037
2115
  callSite: (f, a) => f(...a)
2038
2116
  });
@@ -2047,7 +2125,7 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
2047
2125
  guest: this._signingContext.deviceKey
2048
2126
  }, {
2049
2127
  file: "space-invitations-handler.ts",
2050
- line: 290,
2128
+ line: 288,
2051
2129
  scope: this,
2052
2130
  callSite: (f, a) => f(...a)
2053
2131
  });
@@ -2057,21 +2135,20 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
2057
2135
  controlFeedKey,
2058
2136
  dataFeedKey
2059
2137
  });
2060
- const assertion = (0, import_credentials7.getCredentialAssertion)(credential);
2061
- (0, import_node_assert8.default)(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential");
2062
- (0, import_node_assert8.default)(credential.subject.id.equals(this._signingContext.identityKey));
2138
+ const assertion = (0, import_credentials8.getCredentialAssertion)(credential);
2139
+ (0, import_node_assert9.default)(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential");
2140
+ (0, import_node_assert9.default)(credential.subject.id.equals(this._signingContext.identityKey));
2063
2141
  const space = await this._spaceManager.acceptSpace({
2064
2142
  spaceKey: assertion.spaceKey,
2065
- genesisFeedKey: assertion.genesisFeedKey,
2066
- controlFeedKey,
2067
- dataFeedKey
2143
+ genesisFeedKey: assertion.genesisFeedKey
2068
2144
  });
2145
+ await this._signingContext.recordCredential(credential);
2069
2146
  (0, import_log8.log)("admitted by host", {
2070
2147
  guest: this._signingContext.deviceKey,
2071
2148
  spaceKey: space.key
2072
2149
  }, {
2073
2150
  file: "space-invitations-handler.ts",
2074
- line: 313,
2151
+ line: 310,
2075
2152
  scope: this,
2076
2153
  callSite: (f, a) => f(...a)
2077
2154
  });
@@ -2080,7 +2157,7 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
2080
2157
  if (!observable.cancelled) {
2081
2158
  import_log8.log.warn("auth failed", err, {
2082
2159
  file: "space-invitations-handler.ts",
2083
- line: 317,
2160
+ line: 314,
2084
2161
  scope: this,
2085
2162
  callSite: (f, a) => f(...a)
2086
2163
  });
@@ -2094,9 +2171,9 @@ var SpaceInvitationsHandler = class extends AbstractInvitationsHandler {
2094
2171
  });
2095
2172
  return extension;
2096
2173
  };
2097
- (0, import_async10.scheduleTask)(ctx, async () => {
2174
+ (0, import_async9.scheduleTask)(ctx, async () => {
2098
2175
  var _a, _b;
2099
- (0, import_node_assert8.default)(invitation.swarmKey);
2176
+ (0, import_node_assert9.default)(invitation.swarmKey);
2100
2177
  const topic = invitation.swarmKey;
2101
2178
  const swarmConnection = await this._networkManager.joinSwarm({
2102
2179
  topic,
@@ -2174,7 +2251,7 @@ var SpaceInvitationsProxy = class extends AbstractInvitationsProxy {
2174
2251
  };
2175
2252
 
2176
2253
  // packages/sdk/client-services/src/packlets/invitations/space-invitations-service.ts
2177
- var import_node_assert9 = __toESM(require("node:assert"));
2254
+ var import_node_assert10 = __toESM(require("node:assert"));
2178
2255
  var SpaceInvitationsServiceImpl = class extends AbstractInvitationsService {
2179
2256
  // prettier-ignore
2180
2257
  constructor(identityManager, invitationsHandler, _getSpaceManager) {
@@ -2183,39 +2260,280 @@ var SpaceInvitationsServiceImpl = class extends AbstractInvitationsService {
2183
2260
  this._getSpaceManager = _getSpaceManager;
2184
2261
  }
2185
2262
  getContext(invitation) {
2186
- (0, import_node_assert9.default)(invitation.spaceKey);
2263
+ (0, import_node_assert10.default)(invitation.spaceKey);
2187
2264
  const spaceManager = this._getSpaceManager();
2188
2265
  const space = spaceManager.spaces.get(invitation.spaceKey);
2189
- (0, import_node_assert9.default)(space);
2266
+ (0, import_node_assert10.default)(space);
2190
2267
  return space;
2191
2268
  }
2192
2269
  };
2193
2270
 
2194
2271
  // packages/sdk/client-services/src/packlets/services/service-context.ts
2195
2272
  var import_async13 = require("@dxos/async");
2196
- var import_debug4 = require("@dxos/debug");
2197
- var import_echo_db3 = require("@dxos/echo-db");
2273
+ var import_credentials11 = require("@dxos/credentials");
2274
+ var import_debug5 = require("@dxos/debug");
2275
+ var import_echo_pipeline3 = require("@dxos/echo-pipeline");
2198
2276
  var import_feed_store4 = require("@dxos/feed-store");
2199
2277
  var import_keyring = require("@dxos/keyring");
2200
- var import_log10 = require("@dxos/log");
2278
+ var import_log11 = require("@dxos/log");
2201
2279
 
2202
2280
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
2203
- var import_node_assert11 = __toESM(require("node:assert"));
2281
+ var import_node_assert12 = __toESM(require("node:assert"));
2204
2282
  var import_async12 = require("@dxos/async");
2205
- var import_context5 = require("@dxos/context");
2206
- var import_echo_db2 = require("@dxos/echo-db");
2207
- var import_keys7 = require("@dxos/keys");
2208
- var import_log9 = require("@dxos/log");
2283
+ var import_context7 = require("@dxos/context");
2284
+ var import_credentials10 = require("@dxos/credentials");
2285
+ var import_echo_pipeline2 = require("@dxos/echo-pipeline");
2286
+ var import_keys8 = require("@dxos/keys");
2287
+ var import_log10 = require("@dxos/log");
2209
2288
  var import_teleport_extension_presence = require("@dxos/teleport-extension-presence");
2210
- var import_util5 = require("@dxos/util");
2289
+ var import_util6 = require("@dxos/util");
2211
2290
 
2212
2291
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
2213
- var import_node_assert10 = __toESM(require("node:assert"));
2214
2292
  var import_async11 = require("@dxos/async");
2215
- var import_context4 = require("@dxos/context");
2216
- var import_echo_db = require("@dxos/echo-db");
2293
+ var import_context6 = require("@dxos/context");
2294
+ var import_debug4 = require("@dxos/debug");
2295
+ var import_echo_pipeline = require("@dxos/echo-pipeline");
2296
+ var import_keys7 = require("@dxos/keys");
2297
+ var import_credentials9 = require("@dxos/protocols/proto/dxos/halo/credentials");
2298
+ var import_util5 = require("@dxos/util");
2299
+
2300
+ // packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
2301
+ var import_node_assert11 = __toESM(require("node:assert"));
2302
+ var import_async10 = require("@dxos/async");
2303
+ var import_context5 = require("@dxos/context");
2217
2304
  var import_keys6 = require("@dxos/keys");
2305
+ var import_log9 = require("@dxos/log");
2306
+ var import_protocols5 = require("@dxos/protocols");
2307
+ var import_teleport3 = require("@dxos/teleport");
2218
2308
  var import_util4 = require("@dxos/util");
2309
+ var RETRY_TIMEOUT = 1e3;
2310
+ var NOTARIZE_TIMEOUT = 1e4;
2311
+ var NotarizationPlugin = class {
2312
+ constructor() {
2313
+ this._ctx = new import_context5.Context();
2314
+ this._extensionOpened = new import_async10.Event();
2315
+ this._extensions = /* @__PURE__ */ new Set();
2316
+ this._processedCredentials = new import_util4.ComplexSet(import_keys6.PublicKey.hash);
2317
+ this._processCredentialsTriggers = new import_util4.ComplexMap(import_keys6.PublicKey.hash);
2318
+ }
2319
+ async open() {
2320
+ }
2321
+ async close() {
2322
+ await this._ctx.dispose();
2323
+ }
2324
+ /**
2325
+ * Request credentials to be notarized.
2326
+ */
2327
+ async notarize(credentials) {
2328
+ (0, import_log9.log)("notarize", {
2329
+ credentials
2330
+ }, {
2331
+ file: "notarization-plugin.ts",
2332
+ line: 44,
2333
+ scope: this,
2334
+ callSite: (f, a) => f(...a)
2335
+ });
2336
+ (0, import_node_assert11.default)(credentials.every((credential) => credential.id), "Credentials must have an id");
2337
+ const errors = new import_async10.Trigger();
2338
+ const ctx = this._ctx.derive({
2339
+ onError: (err) => {
2340
+ import_log9.log.warn("Notarization error", {
2341
+ err
2342
+ }, {
2343
+ file: "notarization-plugin.ts",
2344
+ line: 53,
2345
+ scope: this,
2346
+ callSite: (f, a) => f(...a)
2347
+ });
2348
+ void ctx.dispose();
2349
+ errors.throw(err);
2350
+ }
2351
+ });
2352
+ (0, import_async10.scheduleTask)(ctx, () => {
2353
+ import_log9.log.warn("Notarization timeout", {}, {
2354
+ file: "notarization-plugin.ts",
2355
+ line: 61,
2356
+ scope: this,
2357
+ callSite: (f, a) => f(...a)
2358
+ });
2359
+ void ctx.dispose();
2360
+ errors.throw(new import_async10.TimeoutError(NOTARIZE_TIMEOUT, "Notarization timed out"));
2361
+ }, NOTARIZE_TIMEOUT);
2362
+ const allNotarized = Promise.all(credentials.map((credential) => this._waitUntilProcessed(credential.id)));
2363
+ const peersTried = /* @__PURE__ */ new Set();
2364
+ const notarizeTask = new import_async10.DeferredTask(ctx, async () => {
2365
+ try {
2366
+ if (this._extensions.size === 0) {
2367
+ import_log9.log.warn("No peers to notarize with", {}, {
2368
+ file: "notarization-plugin.ts",
2369
+ line: 76,
2370
+ scope: this,
2371
+ callSite: (f, a) => f(...a)
2372
+ });
2373
+ return;
2374
+ }
2375
+ const peer = [
2376
+ ...this._extensions
2377
+ ].find((peer2) => !peersTried.has(peer2));
2378
+ if (!peer) {
2379
+ import_log9.log.warn("Exhausted all peers to notarize with", {
2380
+ retryIn: RETRY_TIMEOUT
2381
+ }, {
2382
+ file: "notarization-plugin.ts",
2383
+ line: 83,
2384
+ scope: this,
2385
+ callSite: (f, a) => f(...a)
2386
+ });
2387
+ peersTried.clear();
2388
+ (0, import_async10.scheduleTask)(ctx, () => notarizeTask.schedule(), RETRY_TIMEOUT);
2389
+ return;
2390
+ }
2391
+ peersTried.add(peer);
2392
+ (0, import_log9.log)("try notarizing", {
2393
+ peer: peer.localPeerId,
2394
+ credentialId: credentials.map((credential) => credential.id)
2395
+ }, {
2396
+ file: "notarization-plugin.ts",
2397
+ line: 90,
2398
+ scope: this,
2399
+ callSite: (f, a) => f(...a)
2400
+ });
2401
+ await peer.rpc.NotarizationService.notarize({
2402
+ credentials: credentials.filter((credential) => !this._processedCredentials.has(credential.id))
2403
+ });
2404
+ (0, import_log9.log)("success", {}, {
2405
+ file: "notarization-plugin.ts",
2406
+ line: 94,
2407
+ scope: this,
2408
+ callSite: (f, a) => f(...a)
2409
+ });
2410
+ } catch (err) {
2411
+ import_log9.log.warn("error notarizing (recoverable)", err, {
2412
+ file: "notarization-plugin.ts",
2413
+ line: 96,
2414
+ scope: this,
2415
+ callSite: (f, a) => f(...a)
2416
+ });
2417
+ notarizeTask.schedule();
2418
+ }
2419
+ });
2420
+ notarizeTask.schedule();
2421
+ this._extensionOpened.on(ctx, () => notarizeTask.schedule());
2422
+ try {
2423
+ await Promise.race([
2424
+ allNotarized,
2425
+ errors.wait()
2426
+ ]);
2427
+ (0, import_log9.log)("done", {}, {
2428
+ file: "notarization-plugin.ts",
2429
+ line: 107,
2430
+ scope: this,
2431
+ callSite: (f, a) => f(...a)
2432
+ });
2433
+ } finally {
2434
+ await ctx.dispose();
2435
+ }
2436
+ }
2437
+ /**
2438
+ * Called with credentials arriving from the control pipeline.
2439
+ */
2440
+ async process(credential) {
2441
+ var _a;
2442
+ if (!credential.id) {
2443
+ return;
2444
+ }
2445
+ (_a = this._processCredentialsTriggers.get(credential.id)) == null ? void 0 : _a.wake();
2446
+ this._processedCredentials.add(credential.id);
2447
+ this._processCredentialsTriggers.delete(credential.id);
2448
+ }
2449
+ setWriter(writer) {
2450
+ (0, import_node_assert11.default)(!this._writer, "Writer already set.");
2451
+ this._writer = writer;
2452
+ }
2453
+ async _waitUntilProcessed(id) {
2454
+ if (this._processedCredentials.has(id)) {
2455
+ return;
2456
+ }
2457
+ await (0, import_util4.entry)(this._processCredentialsTriggers, id).orInsert(new import_async10.Trigger()).value.wait();
2458
+ }
2459
+ /**
2460
+ * Requests from other peers to notarize credentials.
2461
+ */
2462
+ async _onNotarize(request) {
2463
+ var _a;
2464
+ if (!this._writer) {
2465
+ throw new Error("Writer not set");
2466
+ }
2467
+ for (const credential of (_a = request.credentials) != null ? _a : []) {
2468
+ (0, import_node_assert11.default)(credential.id, "Credential must have an id");
2469
+ if (this._processedCredentials.has(credential.id)) {
2470
+ continue;
2471
+ }
2472
+ await this._writer.write(credential);
2473
+ }
2474
+ }
2475
+ createExtension() {
2476
+ const extension = new NotarizationTeleportExtension({
2477
+ onOpen: async () => {
2478
+ (0, import_log9.log)("extension opened", {
2479
+ peer: extension.localPeerId
2480
+ }, {
2481
+ file: "notarization-plugin.ts",
2482
+ line: 156,
2483
+ scope: this,
2484
+ callSite: (f, a) => f(...a)
2485
+ });
2486
+ this._extensions.add(extension);
2487
+ this._extensionOpened.emit();
2488
+ },
2489
+ onClose: async () => {
2490
+ (0, import_log9.log)("extension closed", {
2491
+ peer: extension.localPeerId
2492
+ }, {
2493
+ file: "notarization-plugin.ts",
2494
+ line: 161,
2495
+ scope: this,
2496
+ callSite: (f, a) => f(...a)
2497
+ });
2498
+ this._extensions.delete(extension);
2499
+ },
2500
+ onNotarize: this._onNotarize.bind(this)
2501
+ });
2502
+ return extension;
2503
+ }
2504
+ };
2505
+ var NotarizationTeleportExtension = class extends import_teleport3.RpcExtension {
2506
+ constructor(_params) {
2507
+ super({
2508
+ requested: {
2509
+ NotarizationService: import_protocols5.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
2510
+ },
2511
+ exposed: {
2512
+ NotarizationService: import_protocols5.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
2513
+ }
2514
+ });
2515
+ this._params = _params;
2516
+ }
2517
+ async getHandlers() {
2518
+ return {
2519
+ NotarizationService: {
2520
+ notarize: async (request) => {
2521
+ await this._params.onNotarize(request);
2522
+ }
2523
+ }
2524
+ };
2525
+ }
2526
+ async onOpen(ctx) {
2527
+ await super.onOpen(ctx);
2528
+ await this._params.onOpen();
2529
+ }
2530
+ async onClose(err) {
2531
+ await this._params.onClose();
2532
+ await super.onClose(err);
2533
+ }
2534
+ };
2535
+
2536
+ // packages/sdk/client-services/src/packlets/spaces/data-space.ts
2219
2537
  var __decorate = function(decorators, target, key, desc) {
2220
2538
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2221
2539
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -2227,12 +2545,17 @@ var __decorate = function(decorators, target, key, desc) {
2227
2545
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2228
2546
  };
2229
2547
  var AUTH_TIMEOUT2 = 3e4;
2548
+ var CONTROL_PIPELINE_READY_TIMEFRAME = 3e3;
2230
2549
  var DataSpace = class DataSpace2 {
2231
2550
  constructor(params) {
2232
- this._ctx = new import_context4.Context();
2551
+ this._ctx = new import_context6.Context();
2233
2552
  this._inner = params.inner;
2234
2553
  this._presence = params.presence;
2235
- this._dataPipelineController = new import_echo_db.DataPipelineControllerImpl({
2554
+ this._keyring = params.keyring;
2555
+ this._feedStore = params.feedStore;
2556
+ this._metadataStore = params.metadataStore;
2557
+ this._signingContext = params.signingContext;
2558
+ this._dataPipelineController = new import_echo_pipeline.DataPipelineControllerImpl({
2236
2559
  modelFactory: params.modelFactory,
2237
2560
  metadataStore: params.metadataStore,
2238
2561
  snapshotManager: params.snapshotManager,
@@ -2242,44 +2565,102 @@ var DataSpace = class DataSpace2 {
2242
2565
  snapshotId: params.snapshotId
2243
2566
  });
2244
2567
  this.authVerifier = new TrustedKeySetAuthVerifier({
2245
- trustedKeysProvider: () => new import_util4.ComplexSet(import_keys6.PublicKey.hash, Array.from(this._inner.spaceState.members.keys())),
2568
+ trustedKeysProvider: () => new import_util5.ComplexSet(import_keys7.PublicKey.hash, Array.from(this._inner.spaceState.members.keys())),
2246
2569
  update: this._inner.stateUpdate,
2247
2570
  authTimeout: AUTH_TIMEOUT2
2248
2571
  });
2572
+ this._notarizationPluginConsumer = this._inner.spaceState.registerProcessor(new NotarizationPlugin());
2249
2573
  }
2250
2574
  get key() {
2251
2575
  return this._inner.key;
2252
2576
  }
2253
- get inner() {
2254
- return this._inner;
2255
- }
2256
2577
  get isOpen() {
2257
2578
  return this._inner.isOpen;
2258
2579
  }
2580
+ // TODO(burdon): Can we mark this for debugging only?
2581
+ get inner() {
2582
+ return this._inner;
2583
+ }
2259
2584
  get dataPipelineController() {
2260
2585
  return this._dataPipelineController;
2261
2586
  }
2262
- get database() {
2263
- (0, import_node_assert10.default)(this._dataPipelineController.database);
2264
- return this._dataPipelineController.database;
2265
- }
2266
2587
  get stateUpdate() {
2267
2588
  return this._inner.stateUpdate;
2268
2589
  }
2269
2590
  get presence() {
2270
2591
  return this._presence;
2271
2592
  }
2593
+ get notarizationPlugin() {
2594
+ return this._notarizationPluginConsumer.processor;
2595
+ }
2272
2596
  async open() {
2597
+ await this.notarizationPlugin.open();
2598
+ await this._notarizationPluginConsumer.open();
2273
2599
  await this._inner.open();
2274
- await this._inner.initDataPipeline(this._dataPipelineController);
2275
2600
  }
2276
2601
  async close() {
2277
2602
  await this._ctx.dispose();
2278
2603
  await this.authVerifier.close();
2279
2604
  await this._inner.close();
2605
+ await this._notarizationPluginConsumer.close();
2606
+ await this.notarizationPlugin.close();
2280
2607
  await this._presence.destroy();
2281
2608
  }
2609
+ async initializeDataPipeline() {
2610
+ await this._inner.controlPipeline.state.waitUntilReachedTargetTimeframe({
2611
+ timeout: CONTROL_PIPELINE_READY_TIMEFRAME
2612
+ });
2613
+ await this._createWritableFeeds();
2614
+ this.notarizationPlugin.setWriter((0, import_echo_pipeline.createMappedFeedWriter)((credential) => ({
2615
+ credential: {
2616
+ credential
2617
+ }
2618
+ }), this._inner.controlPipeline.writer));
2619
+ await this._inner.initDataPipeline(this._dataPipelineController);
2620
+ }
2621
+ async _createWritableFeeds() {
2622
+ const credentials = [];
2623
+ if (!this.inner.controlFeedKey) {
2624
+ const controlFeed = await this._feedStore.openFeed(await this._keyring.createKey(), {
2625
+ writable: true
2626
+ });
2627
+ this.inner.setControlFeed(controlFeed);
2628
+ credentials.push(await this._signingContext.credentialSigner.createCredential({
2629
+ subject: controlFeed.key,
2630
+ assertion: {
2631
+ "@type": "dxos.halo.credentials.AdmittedFeed",
2632
+ spaceKey: this.key,
2633
+ deviceKey: this._signingContext.deviceKey,
2634
+ identityKey: this._signingContext.identityKey,
2635
+ designation: import_credentials9.AdmittedFeed.Designation.CONTROL
2636
+ }
2637
+ }));
2638
+ }
2639
+ if (!this.inner.dataFeedKey) {
2640
+ const dataFeed = await this._feedStore.openFeed(await this._keyring.createKey(), {
2641
+ writable: true
2642
+ });
2643
+ this.inner.setDataFeed(dataFeed);
2644
+ credentials.push(await this._signingContext.credentialSigner.createCredential({
2645
+ subject: dataFeed.key,
2646
+ assertion: {
2647
+ "@type": "dxos.halo.credentials.AdmittedFeed",
2648
+ spaceKey: this.key,
2649
+ deviceKey: this._signingContext.deviceKey,
2650
+ identityKey: this._signingContext.identityKey,
2651
+ designation: import_credentials9.AdmittedFeed.Designation.DATA
2652
+ }
2653
+ }));
2654
+ }
2655
+ if (credentials.length > 0) {
2656
+ await this.notarizationPlugin.notarize(credentials);
2657
+ }
2658
+ await this._metadataStore.setWritableFeedKeys(this.key, this.inner.controlFeedKey, this.inner.dataFeedKey);
2659
+ }
2282
2660
  };
2661
+ __decorate([
2662
+ (0, import_debug4.timed)(1e4)
2663
+ ], DataSpace.prototype, "_createWritableFeeds", null);
2283
2664
  DataSpace = __decorate([
2284
2665
  (0, import_async11.trackLeaks)("open", "close")
2285
2666
  ], DataSpace);
@@ -2295,18 +2676,20 @@ var __decorate2 = function(decorators, target, key, desc) {
2295
2676
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2296
2677
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2297
2678
  };
2679
+ var DATA_PIPELINE_READY_TIMEOUT = 3e3;
2298
2680
  var DataSpaceManager = class DataSpaceManager2 {
2299
- constructor(_spaceManager, _metadataStore, _dataServiceSubscriptions, _keyring, _signingContext, _modelFactory, _snapshotStore) {
2681
+ constructor(_spaceManager, _metadataStore, _dataServiceSubscriptions, _keyring, _signingContext, _modelFactory, _feedStore, _snapshotStore) {
2300
2682
  this._spaceManager = _spaceManager;
2301
2683
  this._metadataStore = _metadataStore;
2302
2684
  this._dataServiceSubscriptions = _dataServiceSubscriptions;
2303
2685
  this._keyring = _keyring;
2304
2686
  this._signingContext = _signingContext;
2305
2687
  this._modelFactory = _modelFactory;
2688
+ this._feedStore = _feedStore;
2306
2689
  this._snapshotStore = _snapshotStore;
2307
- this._ctx = new import_context5.Context();
2690
+ this._ctx = new import_context7.Context();
2308
2691
  this.updated = new import_async12.Event();
2309
- this._spaces = new import_util5.ComplexMap(import_keys7.PublicKey.hash);
2692
+ this._spaces = new import_util6.ComplexMap(import_keys8.PublicKey.hash);
2310
2693
  }
2311
2694
  // TODO(burdon): Remove.
2312
2695
  get spaces() {
@@ -2314,35 +2697,40 @@ var DataSpaceManager = class DataSpaceManager2 {
2314
2697
  }
2315
2698
  async open() {
2316
2699
  await this._metadataStore.load();
2317
- (0, import_log9.log)("metadata loaded", {
2700
+ (0, import_log10.log)("metadata loaded", {
2318
2701
  spaces: this._metadataStore.spaces.length
2319
2702
  }, {
2320
2703
  file: "data-space-manager.ts",
2321
- line: 57,
2704
+ line: 67,
2322
2705
  scope: this,
2323
2706
  callSite: (f, a) => f(...a)
2324
2707
  });
2325
2708
  for (const spaceMetadata of this._metadataStore.spaces) {
2326
- (0, import_log9.log)("load space", {
2709
+ (0, import_log10.log)("load space", {
2327
2710
  spaceMetadata
2328
2711
  }, {
2329
2712
  file: "data-space-manager.ts",
2330
- line: 60,
2713
+ line: 70,
2331
2714
  scope: this,
2332
2715
  callSite: (f, a) => f(...a)
2333
2716
  });
2334
2717
  const space = await this._constructSpace(spaceMetadata);
2335
- if (spaceMetadata.latestTimeframe) {
2336
- (0, import_log9.log)("waiting for latest timeframe", {
2718
+ await space.initializeDataPipeline();
2719
+ if (spaceMetadata.dataTimeframe) {
2720
+ (0, import_log10.log)("waiting for latest timeframe", {
2337
2721
  spaceMetadata
2338
2722
  }, {
2339
2723
  file: "data-space-manager.ts",
2340
- line: 63,
2724
+ line: 74,
2341
2725
  scope: this,
2342
2726
  callSite: (f, a) => f(...a)
2343
2727
  });
2344
- await space.dataPipelineController.waitUntilTimeframe(spaceMetadata.latestTimeframe);
2728
+ await space.dataPipelineController.pipelineState.setTargetTimeframe(spaceMetadata.dataTimeframe);
2345
2729
  }
2730
+ await space.dataPipelineController.pipelineState.waitUntilReachedTargetTimeframe({
2731
+ timeout: DATA_PIPELINE_READY_TIMEOUT
2732
+ });
2733
+ this._dataServiceSubscriptions.registerSpace(space.key, space.dataPipelineController.databaseBackend.createDataServiceHost());
2346
2734
  }
2347
2735
  }
2348
2736
  async close() {
@@ -2364,31 +2752,36 @@ var DataSpaceManager = class DataSpaceManager2 {
2364
2752
  controlFeedKey,
2365
2753
  dataFeedKey
2366
2754
  };
2367
- (0, import_log9.log)("creating space...", {
2755
+ (0, import_log10.log)("creating space...", {
2368
2756
  spaceKey
2369
2757
  }, {
2370
2758
  file: "data-space-manager.ts",
2371
- line: 92,
2759
+ line: 110,
2372
2760
  scope: this,
2373
2761
  callSite: (f, a) => f(...a)
2374
2762
  });
2375
2763
  const space = await this._constructSpace(metadata);
2376
- await (0, import_echo_db2.spaceGenesis)(this._keyring, this._signingContext, space.inner);
2764
+ const credentials = await (0, import_echo_pipeline2.spaceGenesis)(this._keyring, this._signingContext, space.inner);
2377
2765
  await this._metadataStore.addSpace(metadata);
2766
+ const memberCredential = credentials[1];
2767
+ (0, import_node_assert12.default)((0, import_credentials10.getCredentialAssertion)(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember");
2768
+ await this._signingContext.recordCredential(memberCredential);
2769
+ await space.initializeDataPipeline();
2770
+ this._dataServiceSubscriptions.registerSpace(space.key, space.dataPipelineController.databaseBackend.createDataServiceHost());
2378
2771
  this.updated.emit();
2379
2772
  return space;
2380
2773
  }
2381
2774
  // TODO(burdon): Rename join space.
2382
2775
  async acceptSpace(opts) {
2383
- (0, import_node_assert11.default)(!this._spaces.has(opts.spaceKey), "Space already exists.");
2776
+ (0, import_node_assert12.default)(!this._spaces.has(opts.spaceKey), "Space already exists.");
2384
2777
  const metadata = {
2385
2778
  key: opts.spaceKey,
2386
- genesisFeedKey: opts.genesisFeedKey,
2387
- controlFeedKey: opts.controlFeedKey,
2388
- dataFeedKey: opts.dataFeedKey
2779
+ genesisFeedKey: opts.genesisFeedKey
2389
2780
  };
2390
2781
  const space = await this._constructSpace(metadata);
2391
2782
  await this._metadataStore.addSpace(metadata);
2783
+ await space.initializeDataPipeline();
2784
+ this._dataServiceSubscriptions.registerSpace(space.key, space.dataPipelineController.databaseBackend.createDataServiceHost());
2392
2785
  this.updated.emit();
2393
2786
  return space;
2394
2787
  }
@@ -2399,21 +2792,30 @@ var DataSpaceManager = class DataSpaceManager2 {
2399
2792
  offlineTimeout: 3e4,
2400
2793
  identityKey: this._signingContext.identityKey
2401
2794
  });
2402
- const snapshotManager = new import_echo_db2.SnapshotManager(this._snapshotStore);
2795
+ const snapshotManager = new import_echo_pipeline2.SnapshotManager(this._snapshotStore);
2796
+ const controlFeed = metadata.controlFeedKey && await this._feedStore.openFeed(metadata.controlFeedKey, {
2797
+ writable: true
2798
+ });
2799
+ const dataFeed = metadata.dataFeedKey && await this._feedStore.openFeed(metadata.dataFeedKey, {
2800
+ writable: true
2801
+ });
2403
2802
  const space = await this._spaceManager.constructSpace({
2404
2803
  metadata,
2405
2804
  swarmIdentity: {
2406
2805
  peerKey: this._signingContext.deviceKey,
2407
2806
  credentialProvider: createAuthProvider(this._signingContext.credentialSigner),
2408
- credentialAuthenticator: (0, import_util5.deferFunction)(() => dataSpace.authVerifier.verifier)
2807
+ credentialAuthenticator: (0, import_util6.deferFunction)(() => dataSpace.authVerifier.verifier)
2409
2808
  },
2410
2809
  onNetworkConnection: (session) => {
2411
2810
  session.addExtension("dxos.mesh.teleport.presence", presence.createExtension({
2412
2811
  remotePeerId: session.remotePeerId
2413
2812
  }));
2414
2813
  session.addExtension("dxos.mesh.teleport.objectsync", snapshotManager.objectSync.createExtension());
2814
+ session.addExtension("dxos.mesh.teleport.notarization", dataSpace.notarizationPlugin.createExtension());
2415
2815
  }
2416
2816
  });
2817
+ controlFeed && space.setControlFeed(controlFeed);
2818
+ dataFeed && space.setDataFeed(dataFeed);
2417
2819
  const dataSpace = new DataSpace({
2418
2820
  inner: space,
2419
2821
  modelFactory: this._modelFactory,
@@ -2421,10 +2823,12 @@ var DataSpaceManager = class DataSpaceManager2 {
2421
2823
  snapshotManager,
2422
2824
  presence,
2423
2825
  memberKey: this._signingContext.identityKey,
2826
+ keyring: this._keyring,
2827
+ feedStore: this._feedStore,
2828
+ signingContext: this._signingContext,
2424
2829
  snapshotId: metadata.snapshot
2425
2830
  });
2426
2831
  await dataSpace.open();
2427
- this._dataServiceSubscriptions.registerSpace(space.key, dataSpace.database.createDataServiceHost());
2428
2832
  this._spaces.set(metadata.key, dataSpace);
2429
2833
  return dataSpace;
2430
2834
  }
@@ -2453,30 +2857,38 @@ var ServiceContext = class {
2453
2857
  this.networkManager = networkManager;
2454
2858
  this.modelFactory = modelFactory;
2455
2859
  this.initialized = new import_async13.Trigger();
2456
- this.dataServiceSubscriptions = new import_echo_db3.DataServiceSubscriptions();
2457
- this.metadataStore = new import_echo_db3.MetadataStore(storage.createDirectory("metadata"));
2458
- this.snapshotStore = new import_echo_db3.SnapshotStore(storage.createDirectory("snapshots"));
2860
+ this.dataServiceSubscriptions = new import_echo_pipeline3.DataServiceSubscriptions();
2861
+ this.metadataStore = new import_echo_pipeline3.MetadataStore(storage.createDirectory("metadata"));
2862
+ this.snapshotStore = new import_echo_pipeline3.SnapshotStore(storage.createDirectory("snapshots"));
2459
2863
  this.keyring = new import_keyring.Keyring(storage.createDirectory("keyring"));
2460
2864
  this.feedStore = new import_feed_store4.FeedStore({
2461
2865
  factory: new import_feed_store4.FeedFactory({
2462
2866
  root: storage.createDirectory("feeds"),
2463
2867
  signer: this.keyring,
2464
2868
  hypercore: {
2465
- valueEncoding: import_echo_db3.valueEncoding
2869
+ valueEncoding: import_echo_pipeline3.valueEncoding
2466
2870
  }
2467
2871
  })
2468
2872
  });
2469
- this.spaceManager = new import_echo_db3.SpaceManager({
2873
+ this.spaceManager = new import_echo_pipeline3.SpaceManager({
2470
2874
  feedStore: this.feedStore,
2471
2875
  networkManager: this.networkManager
2472
2876
  });
2473
- this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.spaceManager);
2474
- this.haloInvitations = new HaloInvitationsHandler(this.networkManager, this.identityManager);
2877
+ this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager);
2878
+ this.haloInvitations = new HaloInvitationsHandler({
2879
+ networkManager: this.networkManager,
2880
+ getIdentity: () => {
2881
+ var _a;
2882
+ return (_a = this.identityManager.identity) != null ? _a : (0, import_debug5.failUndefined)();
2883
+ },
2884
+ acceptIdentity: this._acceptIdentity.bind(this),
2885
+ keyring: this.keyring
2886
+ });
2475
2887
  }
2476
2888
  async open() {
2477
- (0, import_log10.log)("opening...", {}, {
2889
+ (0, import_log11.log)("opening...", {}, {
2478
2890
  file: "service-context.ts",
2479
- line: 83,
2891
+ line: 94,
2480
2892
  scope: this,
2481
2893
  callSite: (f, a) => f(...a)
2482
2894
  });
@@ -2486,46 +2898,47 @@ var ServiceContext = class {
2486
2898
  if (this.identityManager.identity) {
2487
2899
  await this._initialize();
2488
2900
  }
2489
- (0, import_log10.log)("opened", {}, {
2901
+ (0, import_log11.log)("opened", {}, {
2490
2902
  file: "service-context.ts",
2491
- line: 90,
2903
+ line: 101,
2492
2904
  scope: this,
2493
2905
  callSite: (f, a) => f(...a)
2494
2906
  });
2495
2907
  }
2496
2908
  async close() {
2497
- var _a;
2498
- (0, import_log10.log)("closing...", {}, {
2909
+ var _a, _b;
2910
+ (0, import_log11.log)("closing...", {}, {
2499
2911
  file: "service-context.ts",
2500
- line: 94,
2912
+ line: 105,
2501
2913
  scope: this,
2502
2914
  callSite: (f, a) => f(...a)
2503
2915
  });
2504
- await ((_a = this.dataSpaceManager) == null ? void 0 : _a.close());
2916
+ await ((_a = this._deviceSpaceSync) == null ? void 0 : _a.close());
2917
+ await ((_b = this.dataSpaceManager) == null ? void 0 : _b.close());
2505
2918
  await this.identityManager.close();
2506
2919
  await this.spaceManager.close();
2507
2920
  await this.feedStore.close();
2508
2921
  await this.networkManager.close();
2509
2922
  this.dataServiceSubscriptions.clear();
2510
- (0, import_log10.log)("closed", {}, {
2923
+ (0, import_log11.log)("closed", {}, {
2511
2924
  file: "service-context.ts",
2512
- line: 101,
2925
+ line: 113,
2513
2926
  scope: this,
2514
2927
  callSite: (f, a) => f(...a)
2515
2928
  });
2516
2929
  }
2517
2930
  async reset() {
2518
- (0, import_log10.log)("resetting...", {}, {
2931
+ (0, import_log11.log)("resetting...", {}, {
2519
2932
  file: "service-context.ts",
2520
- line: 105,
2933
+ line: 117,
2521
2934
  scope: this,
2522
2935
  callSite: (f, a) => f(...a)
2523
2936
  });
2524
2937
  await this.close();
2525
2938
  await this.storage.reset();
2526
- (0, import_log10.log)("reset", {}, {
2939
+ (0, import_log11.log)("reset", {}, {
2527
2940
  file: "service-context.ts",
2528
- line: 108,
2941
+ line: 120,
2529
2942
  scope: this,
2530
2943
  callSite: (f, a) => f(...a)
2531
2944
  });
@@ -2535,53 +2948,121 @@ var ServiceContext = class {
2535
2948
  await this._initialize();
2536
2949
  return identity;
2537
2950
  }
2951
+ async _acceptIdentity(params) {
2952
+ const identity = await this.identityManager.acceptIdentity(params);
2953
+ await this._initialize();
2954
+ return identity;
2955
+ }
2538
2956
  // Called when identity is created.
2539
2957
  async _initialize() {
2540
2958
  var _a;
2541
- (0, import_log10.log)("initializing spaces...", {}, {
2959
+ (0, import_log11.log)("initializing spaces...", {}, {
2542
2960
  file: "service-context.ts",
2543
- line: 120,
2961
+ line: 139,
2544
2962
  scope: this,
2545
2963
  callSite: (f, a) => f(...a)
2546
2964
  });
2547
- const identity = (_a = this.identityManager.identity) != null ? _a : (0, import_debug4.failUndefined)();
2965
+ const identity = (_a = this.identityManager.identity) != null ? _a : (0, import_debug5.failUndefined)();
2548
2966
  const signingContext = {
2549
2967
  credentialSigner: identity.getIdentityCredentialSigner(),
2550
2968
  identityKey: identity.identityKey,
2551
2969
  deviceKey: identity.deviceKey,
2552
- profile: identity.profileDocument
2970
+ profile: identity.profileDocument,
2971
+ recordCredential: async (credential) => {
2972
+ await identity.controlPipeline.writer.write({
2973
+ credential: {
2974
+ credential
2975
+ }
2976
+ });
2977
+ }
2553
2978
  };
2554
- this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.dataServiceSubscriptions, this.keyring, signingContext, this.modelFactory, this.snapshotStore);
2979
+ this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.dataServiceSubscriptions, this.keyring, signingContext, this.modelFactory, this.feedStore, this.snapshotStore);
2555
2980
  await this.dataSpaceManager.open();
2556
2981
  this.spaceInvitations = new SpaceInvitationsHandler(this.networkManager, this.dataSpaceManager, signingContext, this.keyring);
2557
2982
  this.initialized.wake();
2983
+ this._deviceSpaceSync = identity.space.spaceState.registerProcessor({
2984
+ process: async (credential) => {
2985
+ const assertion = (0, import_credentials11.getCredentialAssertion)(credential);
2986
+ if (assertion["@type"] !== "dxos.halo.credentials.SpaceMember") {
2987
+ return;
2988
+ }
2989
+ if (assertion.spaceKey.equals(identity.space.key)) {
2990
+ return;
2991
+ }
2992
+ if (!this.dataSpaceManager) {
2993
+ (0, import_log11.log)("dataSpaceManager not initialized yet, ignoring space admission", {
2994
+ details: assertion
2995
+ }, {
2996
+ file: "service-context.ts",
2997
+ line: 182,
2998
+ scope: this,
2999
+ callSite: (f, a) => f(...a)
3000
+ });
3001
+ return;
3002
+ }
3003
+ if (this.dataSpaceManager.spaces.has(assertion.spaceKey)) {
3004
+ (0, import_log11.log)("space already exists, ignoring space admission", {
3005
+ details: assertion
3006
+ }, {
3007
+ file: "service-context.ts",
3008
+ line: 186,
3009
+ scope: this,
3010
+ callSite: (f, a) => f(...a)
3011
+ });
3012
+ return;
3013
+ }
3014
+ try {
3015
+ (0, import_log11.log)("accepting space recorded in halo", {
3016
+ details: assertion
3017
+ }, {
3018
+ file: "service-context.ts",
3019
+ line: 191,
3020
+ scope: this,
3021
+ callSite: (f, a) => f(...a)
3022
+ });
3023
+ await this.dataSpaceManager.acceptSpace({
3024
+ spaceKey: assertion.spaceKey,
3025
+ genesisFeedKey: assertion.genesisFeedKey
3026
+ });
3027
+ } catch (err) {
3028
+ import_log11.log.catch(err, {}, {
3029
+ file: "service-context.ts",
3030
+ line: 197,
3031
+ scope: this,
3032
+ callSite: (f, a) => f(...a)
3033
+ });
3034
+ }
3035
+ }
3036
+ });
3037
+ await this._deviceSpaceSync.open();
2558
3038
  }
2559
3039
  };
2560
3040
 
2561
3041
  // packages/sdk/client-services/src/packlets/services/service-definitions.ts
2562
- var import_protocols5 = require("@dxos/protocols");
3042
+ var import_protocols6 = require("@dxos/protocols");
2563
3043
  var import_rpc = require("@dxos/rpc");
2564
3044
  var clientServiceBundle = (0, import_rpc.createServiceBundle)({
2565
- HaloInvitationsService: import_protocols5.schema.getService("dxos.client.services.HaloInvitationsService"),
2566
- DevicesService: import_protocols5.schema.getService("dxos.client.services.DevicesService"),
2567
- SpaceInvitationsService: import_protocols5.schema.getService("dxos.client.services.SpaceInvitationsService"),
2568
- SpacesService: import_protocols5.schema.getService("dxos.client.services.SpacesService"),
2569
- NetworkService: import_protocols5.schema.getService("dxos.client.services.NetworkService"),
3045
+ HaloInvitationsService: import_protocols6.schema.getService("dxos.client.services.HaloInvitationsService"),
3046
+ DevicesService: import_protocols6.schema.getService("dxos.client.services.DevicesService"),
3047
+ SpaceInvitationsService: import_protocols6.schema.getService("dxos.client.services.SpaceInvitationsService"),
3048
+ SpacesService: import_protocols6.schema.getService("dxos.client.services.SpacesService"),
3049
+ NetworkService: import_protocols6.schema.getService("dxos.client.services.NetworkService"),
2570
3050
  // TODO(burdon): Deprecated.
2571
- SpaceService: import_protocols5.schema.getService("dxos.client.SpaceService"),
2572
- DataService: import_protocols5.schema.getService("dxos.echo.service.DataService"),
2573
- ProfileService: import_protocols5.schema.getService("dxos.client.ProfileService"),
2574
- SystemService: import_protocols5.schema.getService("dxos.client.SystemService"),
2575
- DevtoolsHost: import_protocols5.schema.getService("dxos.devtools.host.DevtoolsHost"),
2576
- TracingService: import_protocols5.schema.getService("dxos.devtools.host.TracingService")
3051
+ SpaceService: import_protocols6.schema.getService("dxos.client.SpaceService"),
3052
+ DataService: import_protocols6.schema.getService("dxos.echo.service.DataService"),
3053
+ ProfileService: import_protocols6.schema.getService("dxos.client.ProfileService"),
3054
+ SystemService: import_protocols6.schema.getService("dxos.client.SystemService"),
3055
+ DevtoolsHost: import_protocols6.schema.getService("dxos.devtools.host.DevtoolsHost"),
3056
+ TracingService: import_protocols6.schema.getService("dxos.devtools.host.TracingService")
2577
3057
  });
2578
3058
 
2579
3059
  // packages/sdk/client-services/src/packlets/services/service-host.ts
2580
- var import_debug6 = require("@dxos/debug");
2581
- var import_echo_db5 = require("@dxos/echo-db");
2582
- var import_log11 = require("@dxos/log");
3060
+ var import_debug7 = require("@dxos/debug");
3061
+ var import_document_model = require("@dxos/document-model");
3062
+ var import_echo_pipeline5 = require("@dxos/echo-pipeline");
3063
+ var import_log17 = require("@dxos/log");
2583
3064
  var import_model_factory = require("@dxos/model-factory");
2584
- var import_object_model = require("@dxos/object-model");
3065
+ var import_client2 = require("@dxos/protocols/proto/dxos/client");
2585
3066
  var import_text_model = require("@dxos/text-model");
2586
3067
 
2587
3068
  // packages/sdk/client-services/src/packlets/identity/devices-service-impl.ts
@@ -2651,8 +3132,8 @@ var NetworkServiceImpl = class {
2651
3132
  // packages/sdk/client-services/src/packlets/spaces/spaces-service.ts
2652
3133
  var import_async15 = require("@dxos/async");
2653
3134
  var import_codec_protobuf11 = require("@dxos/codec-protobuf");
2654
- var import_debug5 = require("@dxos/debug");
2655
- var import_echo_db4 = require("@dxos/echo-db");
3135
+ var import_debug6 = require("@dxos/debug");
3136
+ var import_echo_pipeline4 = require("@dxos/echo-pipeline");
2656
3137
  var SpacesServiceImpl = class {
2657
3138
  constructor(_spaceManager) {
2658
3139
  this._spaceManager = _spaceManager;
@@ -2669,7 +3150,7 @@ var SpacesServiceImpl = class {
2669
3150
  queryCredentials({ spaceKey }) {
2670
3151
  return new import_codec_protobuf11.Stream(({ ctx, next }) => {
2671
3152
  var _a;
2672
- const space = (_a = this._spaceManager.spaces.get(spaceKey)) != null ? _a : (0, import_debug5.raise)(new import_echo_db4.SpaceNotFoundError(spaceKey));
3153
+ const space = (_a = this._spaceManager.spaces.get(spaceKey)) != null ? _a : (0, import_debug6.raise)(new import_echo_pipeline4.SpaceNotFoundError(spaceKey));
2673
3154
  const processor = space.spaceState.registerProcessor({
2674
3155
  process: async (credential) => {
2675
3156
  next(credential);
@@ -2679,6 +3160,17 @@ var SpacesServiceImpl = class {
2679
3160
  (0, import_async15.scheduleTask)(ctx, () => processor.open());
2680
3161
  });
2681
3162
  }
3163
+ async writeCredentials({ spaceKey, credentials }) {
3164
+ var _a;
3165
+ const space = (_a = this._spaceManager.spaces.get(spaceKey)) != null ? _a : (0, import_debug6.raise)(new import_echo_pipeline4.SpaceNotFoundError(spaceKey));
3166
+ for (const credential of credentials != null ? credentials : []) {
3167
+ await space.controlPipeline.writer.write({
3168
+ credential: {
3169
+ credential
3170
+ }
3171
+ });
3172
+ }
3173
+ }
2682
3174
  };
2683
3175
 
2684
3176
  // packages/sdk/client-services/src/packlets/storage/storage.ts
@@ -2726,169 +3218,265 @@ var toStorageType = (type) => {
2726
3218
  }
2727
3219
  };
2728
3220
 
2729
- // packages/sdk/client-services/src/packlets/services/service-registry.ts
2730
- var ServiceRegistry = class {
2731
- // prettier-ignore
2732
- constructor(_serviceBundle, _handlers) {
2733
- this._serviceBundle = _serviceBundle;
2734
- this._handlers = _handlers;
3221
+ // packages/sdk/client-services/src/packlets/vault/iframe-host-runtime.ts
3222
+ var import_async17 = require("@dxos/async");
3223
+ var import_log12 = require("@dxos/log");
3224
+ var import_messaging = require("@dxos/messaging");
3225
+ var import_network_manager3 = require("@dxos/network-manager");
3226
+ var import_rpc3 = require("@dxos/rpc");
3227
+ var import_util7 = require("@dxos/util");
3228
+
3229
+ // packages/sdk/client-services/src/packlets/vault/shell-runtime.ts
3230
+ var import_node_assert13 = __toESM(require("node:assert"));
3231
+ var import_async16 = require("@dxos/async");
3232
+ var import_iframe = require("@dxos/protocols/proto/dxos/iframe");
3233
+ var import_rpc2 = require("@dxos/rpc");
3234
+
3235
+ // packages/sdk/client-services/src/packlets/vault/services.ts
3236
+ var import_protocols7 = require("@dxos/protocols");
3237
+ var iframeServiceBundle = {
3238
+ IframeService: import_protocols7.schema.getService("dxos.iframe.IframeService"),
3239
+ BridgeService: import_protocols7.schema.getService("dxos.mesh.bridge.BridgeService")
3240
+ };
3241
+ var workerServiceBundle = {
3242
+ WorkerService: import_protocols7.schema.getService("dxos.iframe.WorkerService")
3243
+ };
3244
+ var appServiceBundle = {
3245
+ AppService: import_protocols7.schema.getService("dxos.iframe.AppService")
3246
+ };
3247
+ var shellServiceBundle = {
3248
+ ShellService: import_protocols7.schema.getService("dxos.iframe.ShellService")
3249
+ };
3250
+
3251
+ // packages/sdk/client-services/src/packlets/vault/shell-runtime.ts
3252
+ var ShellRuntimeImpl = class {
3253
+ constructor(_port) {
3254
+ this._port = _port;
3255
+ this.layoutUpdate = new import_async16.Event();
3256
+ this._layout = import_iframe.ShellLayout.DEFAULT;
3257
+ }
3258
+ get layout() {
3259
+ return this._layout;
3260
+ }
3261
+ get invitationCode() {
3262
+ return this._invitationCode;
3263
+ }
3264
+ get spaceKey() {
3265
+ return this._spaceKey;
3266
+ }
3267
+ setLayout(layout, options = {}) {
3268
+ this._layout = layout;
3269
+ this._invitationCode = options.invitationCode;
3270
+ this._spaceKey = options.spaceKey;
3271
+ this.layoutUpdate.emit({
3272
+ layout,
3273
+ ...options
3274
+ });
2735
3275
  }
2736
- get descriptors() {
2737
- return this._serviceBundle;
3276
+ async setAppContext(context) {
3277
+ (0, import_node_assert13.default)(this._appRpc, "runtime not open");
3278
+ if (context.spaceKey) {
3279
+ this._spaceKey = context.spaceKey;
3280
+ }
3281
+ if (context.invitationCode) {
3282
+ this._invitationCode = context.invitationCode;
3283
+ }
3284
+ await this._appRpc.rpc.AppService.setContext({
3285
+ ...context,
3286
+ spaceKey: this._spaceKey,
3287
+ invitationCode: this._invitationCode
3288
+ });
2738
3289
  }
2739
- get services() {
2740
- return this._handlers;
3290
+ async open() {
3291
+ this._appRpc = (0, import_rpc2.createProtoRpcPeer)({
3292
+ requested: appServiceBundle,
3293
+ exposed: shellServiceBundle,
3294
+ handlers: {
3295
+ ShellService: {
3296
+ setLayout: async (request) => {
3297
+ this._layout = request.layout;
3298
+ this._invitationCode = request.invitationCode;
3299
+ this._spaceKey = request.spaceKey;
3300
+ this.layoutUpdate.emit(request);
3301
+ }
3302
+ }
3303
+ },
3304
+ port: this._port
3305
+ });
3306
+ await this._appRpc.open();
3307
+ }
3308
+ async close() {
3309
+ var _a;
3310
+ await ((_a = this._appRpc) == null ? void 0 : _a.close());
3311
+ this._appRpc = void 0;
3312
+ }
3313
+ };
3314
+ var MemoryShellRuntime = class {
3315
+ constructor({ layout, invitationCode, spaceKey } = {}) {
3316
+ this.layoutUpdate = new import_async16.Event();
3317
+ this.contextUpdate = new import_async16.Event();
3318
+ this._layout = layout != null ? layout : import_iframe.ShellLayout.DEFAULT;
3319
+ this._invitationCode = invitationCode;
3320
+ this._spaceKey = spaceKey;
3321
+ }
3322
+ get layout() {
3323
+ return this._layout;
3324
+ }
3325
+ get invitationCode() {
3326
+ return this._invitationCode;
3327
+ }
3328
+ get spaceKey() {
3329
+ return this._spaceKey;
3330
+ }
3331
+ setLayout(layout, options = {}) {
3332
+ this._layout = layout;
3333
+ this._invitationCode = options.invitationCode;
3334
+ this._spaceKey = options.spaceKey;
3335
+ this.layoutUpdate.emit({
3336
+ layout,
3337
+ ...options
3338
+ });
3339
+ }
3340
+ async setAppContext(context) {
3341
+ this.contextUpdate.emit(context);
2741
3342
  }
2742
3343
  };
2743
3344
 
2744
- // packages/sdk/client-services/src/packlets/services/service-host.ts
2745
- var createDefaultModelFactory = () => {
2746
- return new import_model_factory.ModelFactory().registerModel(import_object_model.ObjectModel).registerModel(import_text_model.TextModel);
3345
+ // packages/sdk/client-services/src/packlets/vault/iframe-host-runtime.ts
3346
+ var __decorate3 = function(decorators, target, key, desc) {
3347
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3348
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
3349
+ r = Reflect.decorate(decorators, target, key, desc);
3350
+ else
3351
+ for (var i = decorators.length - 1; i >= 0; i--)
3352
+ if (d = decorators[i])
3353
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
3354
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
2747
3355
  };
2748
- var ClientServicesHost = class {
2749
- constructor({
2750
- config,
2751
- modelFactory = createDefaultModelFactory(),
2752
- // TODO(burdon): Create ApolloLink abstraction (see Client).
2753
- networkManager,
2754
- storage = createStorageObjects(config.get("runtime.client.storage", {})).storage
2755
- }) {
2756
- this._config = config;
2757
- this._modelFactory = modelFactory;
2758
- this._networkManager = networkManager;
2759
- this._storage = storage;
2760
- }
2761
- get descriptors() {
2762
- return this._serviceRegistry.descriptors;
3356
+ var LOCK_KEY = "DXOS_RESOURCE_LOCK";
3357
+ var IFrameHostRuntime = class {
3358
+ constructor({ configProvider, appPort, shellPort }) {
3359
+ this._transportFactory = (0, import_network_manager3.createWebRTCTransportFactory)();
3360
+ this._ready = new import_async17.Trigger();
3361
+ this._configProvider = configProvider;
3362
+ this._appPort = appPort;
3363
+ this._shellPort = shellPort;
3364
+ this._getService = async (find) => {
3365
+ const error = await this._ready.wait();
3366
+ if (error) {
3367
+ throw error;
3368
+ }
3369
+ const service = await find(this._clientServices.services);
3370
+ if (!service) {
3371
+ throw new Error("Service not found");
3372
+ }
3373
+ return service;
3374
+ };
3375
+ if (this._shellPort) {
3376
+ this._shellRuntime = new ShellRuntimeImpl(this._shellPort);
3377
+ }
2763
3378
  }
2764
3379
  get services() {
2765
- return this._serviceRegistry.services;
3380
+ return this._clientServices;
2766
3381
  }
2767
- async open() {
3382
+ get shell() {
3383
+ return this._shellRuntime;
3384
+ }
3385
+ async start() {
2768
3386
  var _a;
2769
- (0, import_log11.log)("opening...", {}, {
2770
- file: "service-host.ts",
2771
- line: 73,
2772
- scope: this,
2773
- callSite: (f, a) => f(...a)
2774
- });
2775
- await this._initialize();
2776
- await this._serviceContext.open();
2777
- const deviceKey = (_a = this._serviceContext.identityManager.identity) == null ? void 0 : _a.deviceKey;
2778
- (0, import_log11.log)("opened", {
2779
- deviceKey
2780
- }, {
2781
- file: "service-host.ts",
2782
- line: 77,
3387
+ (0, import_log12.log)("starting...", {}, {
3388
+ file: "iframe-host-runtime.ts",
3389
+ line: 81,
2783
3390
  scope: this,
2784
3391
  callSite: (f, a) => f(...a)
2785
3392
  });
3393
+ try {
3394
+ this._config = await (0, import_util7.getAsyncValue)(this._configProvider);
3395
+ const signalServer = this._config.get("runtime.services.signal.server");
3396
+ this._clientServices = new ClientServicesHost({
3397
+ lockKey: LOCK_KEY,
3398
+ config: this._config,
3399
+ networkManager: new import_network_manager3.NetworkManager({
3400
+ log: true,
3401
+ signalManager: signalServer ? new import_messaging.WebsocketSignalManager([
3402
+ signalServer
3403
+ ]) : new import_messaging.MemorySignalManager(new import_messaging.MemorySignalManagerContext()),
3404
+ transportFactory: this._transportFactory
3405
+ })
3406
+ });
3407
+ this._clientRpc = (0, import_rpc3.createProtoRpcPeer)({
3408
+ exposed: clientServiceBundle,
3409
+ handlers: {
3410
+ DataService: async () => await this._getService((services) => services.DataService),
3411
+ DevicesService: async () => await this._getService((services) => services.DevicesService),
3412
+ DevtoolsHost: async () => await this._getService((services) => services.DevtoolsHost),
3413
+ HaloInvitationsService: async () => await this._getService((services) => services.HaloInvitationsService),
3414
+ NetworkService: async () => await this._getService((services) => services.NetworkService),
3415
+ ProfileService: async () => await this._getService((services) => services.ProfileService),
3416
+ SpaceInvitationsService: async () => await this._getService((services) => services.SpaceInvitationsService),
3417
+ SpaceService: async () => await this._getService((services) => services.SpaceService),
3418
+ SpacesService: async () => await this._getService((services) => services.SpacesService),
3419
+ SystemService: async () => await this._getService((services) => services.SystemService),
3420
+ TracingService: async () => await this._getService((services) => services.TracingService)
3421
+ },
3422
+ port: this._appPort
3423
+ });
3424
+ await Promise.all([
3425
+ this._clientServices.open(),
3426
+ this._clientRpc.open(),
3427
+ (_a = this._shellRuntime) == null ? void 0 : _a.open()
3428
+ ]);
3429
+ this._ready.wake(void 0);
3430
+ (0, import_log12.log)("started", {}, {
3431
+ file: "iframe-host-runtime.ts",
3432
+ line: 117,
3433
+ scope: this,
3434
+ callSite: (f, a) => f(...a)
3435
+ });
3436
+ } catch (err) {
3437
+ this._ready.wake(err);
3438
+ import_log12.log.catch(err, {}, {
3439
+ file: "iframe-host-runtime.ts",
3440
+ line: 120,
3441
+ scope: this,
3442
+ callSite: (f, a) => f(...a)
3443
+ });
3444
+ }
2786
3445
  }
2787
- async close() {
3446
+ async stop() {
2788
3447
  var _a;
2789
- const deviceKey = (_a = this._serviceContext.identityManager.identity) == null ? void 0 : _a.deviceKey;
2790
- (0, import_log11.log)("closing...", {
2791
- deviceKey
2792
- }, {
2793
- file: "service-host.ts",
2794
- line: 82,
3448
+ (0, import_log12.log)("stopping...", {}, {
3449
+ file: "iframe-host-runtime.ts",
3450
+ line: 125,
2795
3451
  scope: this,
2796
3452
  callSite: (f, a) => f(...a)
2797
3453
  });
2798
- await this._serviceContext.close();
2799
- (0, import_log11.log)("closed", {
2800
- deviceKey
2801
- }, {
2802
- file: "service-host.ts",
2803
- line: 84,
3454
+ await this._clientRpc.close();
3455
+ await this._clientServices.close();
3456
+ await ((_a = this._shellRuntime) == null ? void 0 : _a.close());
3457
+ (0, import_log12.log)("stopped", {}, {
3458
+ file: "iframe-host-runtime.ts",
3459
+ line: 129,
2804
3460
  scope: this,
2805
3461
  callSite: (f, a) => f(...a)
2806
3462
  });
2807
3463
  }
2808
- // TODO(burdon): Move into open.
2809
- async _initialize() {
2810
- this._serviceContext = new ServiceContext(this._storage, this._networkManager, this._modelFactory);
2811
- this._serviceRegistry = new ServiceRegistry(clientServiceBundle, {
2812
- HaloInvitationsService: new HaloInvitationsServiceImpl(this._serviceContext.identityManager, this._serviceContext.haloInvitations),
2813
- DevicesService: new DevicesServiceImpl(this._serviceContext.identityManager),
2814
- SpaceInvitationsService: new SpaceInvitationsServiceImpl(this._serviceContext.identityManager, () => {
2815
- var _a;
2816
- return (_a = this._serviceContext.spaceInvitations) != null ? _a : (0, import_debug6.raise)(new Error("SpaceInvitations not initialized"));
2817
- }, () => {
2818
- var _a;
2819
- return (_a = this._serviceContext.dataSpaceManager) != null ? _a : (0, import_debug6.raise)(new Error("SpaceManager not initialized"));
2820
- }),
2821
- SpacesService: new SpacesServiceImpl(this._serviceContext.spaceManager),
2822
- DataService: new import_echo_db5.DataServiceImpl(this._serviceContext.dataServiceSubscriptions),
2823
- NetworkService: new NetworkServiceImpl(this._serviceContext.networkManager),
2824
- // TODO(burdon): Move to new protobuf definitions.
2825
- ProfileService: new ProfileServiceImpl(this._serviceContext),
2826
- SpaceService: new SpaceServiceImpl(this._serviceContext),
2827
- SystemService: new SystemServiceImpl(this._config, this._serviceContext),
2828
- TracingService: new TracingServiceImpl(this._config),
2829
- DevtoolsHost: new DevtoolsServiceImpl({
2830
- events: new DevtoolsHostEvents(),
2831
- config: this._config,
2832
- context: this._serviceContext
2833
- })
2834
- });
2835
- }
2836
- };
2837
-
2838
- // packages/sdk/client-services/src/packlets/services/service-proxy.ts
2839
- var import_async16 = require("@dxos/async");
2840
- var import_errors2 = require("@dxos/errors");
2841
- var import_rpc2 = require("@dxos/rpc");
2842
- var ClientServicesProxy = class {
2843
- // prettier-ignore
2844
- constructor(port, _timeout = 3e4) {
2845
- this._timeout = _timeout;
2846
- this._proxy = (0, import_rpc2.createProtoRpcPeer)({
2847
- requested: clientServiceBundle,
2848
- exposed: {},
2849
- handlers: {},
2850
- port
2851
- });
2852
- }
2853
- get proxy() {
2854
- return this._proxy;
2855
- }
2856
- get descriptors() {
2857
- return clientServiceBundle;
2858
- }
2859
- get services() {
2860
- return this._proxy.rpc;
2861
- }
2862
- async open() {
2863
- await (0, import_async16.asyncTimeout)(this._proxy.open(), this._timeout, new import_errors2.RemoteServiceConnectionTimeout());
2864
- }
2865
- async close() {
2866
- await this._proxy.close();
2867
- }
2868
- };
2869
-
2870
- // packages/sdk/client-services/src/packlets/vault/iframe-runtime.ts
2871
- var import_network_manager3 = require("@dxos/network-manager");
2872
- var import_rpc3 = require("@dxos/rpc");
2873
-
2874
- // packages/sdk/client-services/src/packlets/vault/services.ts
2875
- var import_protocols6 = require("@dxos/protocols");
2876
- var iframeServiceBundle = {
2877
- IframeService: import_protocols6.schema.getService("dxos.iframe.IframeService"),
2878
- BridgeService: import_protocols6.schema.getService("dxos.mesh.bridge.BridgeService")
2879
- };
2880
- var workerServiceBundle = {
2881
- WorkerService: import_protocols6.schema.getService("dxos.iframe.WorkerService")
2882
3464
  };
3465
+ __decorate3([
3466
+ import_log12.logInfo
3467
+ ], IFrameHostRuntime.prototype, "origin", void 0);
2883
3468
 
2884
- // packages/sdk/client-services/src/packlets/vault/iframe-runtime.ts
2885
- var IFrameRuntime = class {
2886
- constructor({ systemPort, workerAppPort, windowAppPort }) {
2887
- this._transportService = new import_network_manager3.WebRTCTransportService();
3469
+ // packages/sdk/client-services/src/packlets/vault/iframe-proxy-runtime.ts
3470
+ var import_network_manager4 = require("@dxos/network-manager");
3471
+ var import_rpc4 = require("@dxos/rpc");
3472
+ var IFrameProxyRuntime = class {
3473
+ constructor({ systemPort, workerAppPort, windowAppPort, shellPort }) {
3474
+ this._transportService = new import_network_manager4.WebRTCTransportService();
2888
3475
  this._systemPort = systemPort;
2889
3476
  this._windowAppPort = windowAppPort;
2890
3477
  this._workerAppPort = workerAppPort;
2891
- this._systemRpc = (0, import_rpc3.createProtoRpcPeer)({
3478
+ this._shellPort = shellPort;
3479
+ this._systemRpc = (0, import_rpc4.createProtoRpcPeer)({
2892
3480
  requested: workerServiceBundle,
2893
3481
  exposed: iframeServiceBundle,
2894
3482
  handlers: {
@@ -2903,31 +3491,191 @@ var IFrameRuntime = class {
2903
3491
  });
2904
3492
  this._workerAppPort.subscribe((msg) => this._windowAppPort.send(msg));
2905
3493
  this._windowAppPort.subscribe((msg) => this._workerAppPort.send(msg));
3494
+ if (this._shellPort) {
3495
+ this._shellRuntime = new ShellRuntimeImpl(this._shellPort);
3496
+ }
3497
+ }
3498
+ get shell() {
3499
+ return this._shellRuntime;
2906
3500
  }
2907
3501
  async open(origin) {
3502
+ var _a;
2908
3503
  await this._systemRpc.open();
2909
3504
  await this._systemRpc.rpc.WorkerService.start({
2910
3505
  origin
2911
3506
  });
3507
+ await ((_a = this._shellRuntime) == null ? void 0 : _a.open());
2912
3508
  }
2913
3509
  async close() {
3510
+ var _a;
3511
+ await ((_a = this._shellRuntime) == null ? void 0 : _a.close());
2914
3512
  await this._systemRpc.rpc.WorkerService.stop();
2915
3513
  await this._systemRpc.close();
2916
3514
  }
2917
3515
  };
2918
3516
 
2919
- // packages/sdk/client-services/src/packlets/vault/worker-runtime.ts
3517
+ // packages/sdk/client-services/src/packlets/vault/shell-controller.ts
2920
3518
  var import_async18 = require("@dxos/async");
2921
- var import_messaging = require("@dxos/messaging");
2922
- var import_network_manager4 = require("@dxos/network-manager");
3519
+ var import_log13 = require("@dxos/log");
3520
+ var import_iframe2 = require("@dxos/protocols/proto/dxos/iframe");
3521
+ var import_rpc5 = require("@dxos/rpc");
3522
+ var ShellController = class {
3523
+ constructor(_port) {
3524
+ this._port = _port;
3525
+ this.contextUpdate = new import_async18.Event();
3526
+ this._display = import_iframe2.ShellDisplay.NONE;
3527
+ }
3528
+ get display() {
3529
+ return this._display;
3530
+ }
3531
+ get spaceKey() {
3532
+ return this._spaceKey;
3533
+ }
3534
+ setSpace(key) {
3535
+ this._spaceKey = key;
3536
+ this._emitUpdate();
3537
+ }
3538
+ async setLayout(layout, options = {}) {
3539
+ var _a;
3540
+ this._display = import_iframe2.ShellDisplay.FULLSCREEN;
3541
+ this._emitUpdate();
3542
+ await ((_a = this._shellRpc) == null ? void 0 : _a.rpc.ShellService.setLayout({
3543
+ layout,
3544
+ ...options
3545
+ }));
3546
+ }
3547
+ async open() {
3548
+ this._shellRpc = (0, import_rpc5.createProtoRpcPeer)({
3549
+ requested: shellServiceBundle,
3550
+ exposed: appServiceBundle,
3551
+ handlers: {
3552
+ AppService: {
3553
+ setContext: async (request) => {
3554
+ (0, import_log13.log)("set context", request, {
3555
+ file: "shell-controller.ts",
3556
+ line: 51,
3557
+ scope: this,
3558
+ callSite: (f, a) => f(...a)
3559
+ });
3560
+ this._display = request.display;
3561
+ this._spaceKey = request.spaceKey;
3562
+ this._invitationCode = request.invitationCode;
3563
+ this.contextUpdate.emit(request);
3564
+ }
3565
+ }
3566
+ },
3567
+ port: this._port
3568
+ });
3569
+ await this._shellRpc.open();
3570
+ }
3571
+ async close() {
3572
+ var _a;
3573
+ await ((_a = this._shellRpc) == null ? void 0 : _a.close());
3574
+ this._shellRpc = void 0;
3575
+ }
3576
+ _emitUpdate() {
3577
+ this.contextUpdate.emit({
3578
+ display: this._display,
3579
+ spaceKey: this._spaceKey,
3580
+ invitationCode: this._invitationCode
3581
+ });
3582
+ }
3583
+ };
3584
+
3585
+ // packages/sdk/client-services/src/packlets/vault/vault-resource-lock.ts
3586
+ var import_async19 = require("@dxos/async");
3587
+ var import_log14 = require("@dxos/log");
3588
+ var Message;
3589
+ (function(Message2) {
3590
+ Message2["ACQUIRING"] = "acquiring";
3591
+ })(Message || (Message = {}));
3592
+ var VaultResourceLock = class {
3593
+ constructor({ lockKey, onAcquire, onRelease }) {
3594
+ this._broadcastChannel = new BroadcastChannel("vault-resource-lock");
3595
+ this._releaseTrigger = new import_async19.Trigger();
3596
+ this._lockKey = lockKey;
3597
+ this._onAcquire = onAcquire;
3598
+ this._onRelease = onRelease;
3599
+ this._broadcastChannel.onmessage = this._onMessage.bind(this);
3600
+ }
3601
+ async acquire() {
3602
+ this._broadcastChannel.postMessage({
3603
+ message: Message.ACQUIRING
3604
+ });
3605
+ try {
3606
+ await (0, import_async19.asyncTimeout)(this._requestLock(), 3e3);
3607
+ } catch (e) {
3608
+ await this._requestLock(true);
3609
+ }
3610
+ }
3611
+ async release() {
3612
+ this._releaseTrigger.wake();
3613
+ }
3614
+ _onMessage(event) {
3615
+ if (event.data.message === Message.ACQUIRING) {
3616
+ this._releaseTrigger.wake();
3617
+ }
3618
+ }
3619
+ async _requestLock(steal = false) {
3620
+ (0, import_log14.log)("requesting lock...", {
3621
+ steal
3622
+ }, {
3623
+ file: "vault-resource-lock.ts",
3624
+ line: 56,
3625
+ scope: this,
3626
+ callSite: (f, a) => f(...a)
3627
+ });
3628
+ const acquired = new import_async19.Trigger();
3629
+ void navigator.locks.request(this._lockKey, {
3630
+ steal
3631
+ }, async () => {
3632
+ var _a, _b;
3633
+ await ((_a = this._onAcquire) == null ? void 0 : _a.call(this));
3634
+ acquired.wake();
3635
+ this._releaseTrigger = new import_async19.Trigger();
3636
+ await this._releaseTrigger.wait();
3637
+ (0, import_log14.log)("releasing lock...", {}, {
3638
+ file: "vault-resource-lock.ts",
3639
+ line: 65,
3640
+ scope: this,
3641
+ callSite: (f, a) => f(...a)
3642
+ });
3643
+ await ((_b = this._onRelease) == null ? void 0 : _b.call(this));
3644
+ (0, import_log14.log)("released lock", {}, {
3645
+ file: "vault-resource-lock.ts",
3646
+ line: 67,
3647
+ scope: this,
3648
+ callSite: (f, a) => f(...a)
3649
+ });
3650
+ }).catch(async () => {
3651
+ var _a;
3652
+ await ((_a = this._onRelease) == null ? void 0 : _a.call(this));
3653
+ });
3654
+ await acquired.wait();
3655
+ (0, import_log14.log)("recieved lock", {
3656
+ steal
3657
+ }, {
3658
+ file: "vault-resource-lock.ts",
3659
+ line: 74,
3660
+ scope: this,
3661
+ callSite: (f, a) => f(...a)
3662
+ });
3663
+ }
3664
+ };
3665
+
3666
+ // packages/sdk/client-services/src/packlets/vault/worker-runtime.ts
3667
+ var import_async21 = require("@dxos/async");
3668
+ var import_log16 = require("@dxos/log");
3669
+ var import_messaging2 = require("@dxos/messaging");
3670
+ var import_network_manager5 = require("@dxos/network-manager");
2923
3671
 
2924
3672
  // packages/sdk/client-services/src/packlets/vault/worker-session.ts
2925
- var import_node_assert12 = __toESM(require("node:assert"));
2926
- var import_async17 = require("@dxos/async");
2927
- var import_log12 = require("@dxos/log");
2928
- var import_rpc4 = require("@dxos/rpc");
2929
- var import_util6 = require("@dxos/util");
2930
- var __decorate3 = function(decorators, target, key, desc) {
3673
+ var import_node_assert14 = __toESM(require("node:assert"));
3674
+ var import_async20 = require("@dxos/async");
3675
+ var import_log15 = require("@dxos/log");
3676
+ var import_rpc6 = require("@dxos/rpc");
3677
+ var import_util8 = require("@dxos/util");
3678
+ var __decorate4 = function(decorators, target, key, desc) {
2931
3679
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2932
3680
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
2933
3681
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2938,33 +3686,39 @@ var __decorate3 = function(decorators, target, key, desc) {
2938
3686
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2939
3687
  };
2940
3688
  var WorkerSession = class {
2941
- constructor({ getServices, systemPort, appPort, options = {
3689
+ constructor({ getService, systemPort, appPort, shellPort, options = {
2942
3690
  heartbeatInterval: 1e3
2943
3691
  } }) {
2944
- this._startTrigger = new import_async17.Trigger();
2945
- this.onClose = new import_util6.Callback();
2946
- (0, import_node_assert12.default)(options);
2947
- (0, import_node_assert12.default)(getServices);
3692
+ this._startTrigger = new import_async20.Trigger();
3693
+ this.onClose = new import_util8.Callback();
3694
+ (0, import_node_assert14.default)(options);
3695
+ (0, import_node_assert14.default)(getService);
2948
3696
  this._options = options;
2949
- this._getServices = getServices;
2950
- this._clientRpc = (0, import_rpc4.createProtoRpcPeer)({
3697
+ this._getService = getService;
3698
+ const handlers = {
3699
+ DataService: async () => await this._getService((services) => services.DataService),
3700
+ DevicesService: async () => await this._getService((services) => services.DevicesService),
3701
+ DevtoolsHost: async () => await this._getService((services) => services.DevtoolsHost),
3702
+ HaloInvitationsService: async () => await this._getService((services) => services.HaloInvitationsService),
3703
+ NetworkService: async () => await this._getService((services) => services.NetworkService),
3704
+ ProfileService: async () => await this._getService((services) => services.ProfileService),
3705
+ SpaceInvitationsService: async () => await this._getService((services) => services.SpaceInvitationsService),
3706
+ SpaceService: async () => await this._getService((services) => services.SpaceService),
3707
+ SpacesService: async () => await this._getService((services) => services.SpacesService),
3708
+ SystemService: async () => await this._getService((services) => services.SystemService),
3709
+ TracingService: async () => await this._getService((services) => services.TracingService)
3710
+ };
3711
+ this._clientRpc = (0, import_rpc6.createProtoRpcPeer)({
2951
3712
  exposed: clientServiceBundle,
2952
- handlers: {
2953
- HaloInvitationsService: async () => (await this._getServices()).services.HaloInvitationsService,
2954
- DevicesService: async () => (await this._getServices()).services.DevicesService,
2955
- SpaceInvitationsService: async () => (await this._getServices()).services.SpaceInvitationsService,
2956
- SpacesService: async () => (await this._getServices()).services.SpacesService,
2957
- NetworkService: async () => (await this._getServices()).services.NetworkService,
2958
- SpaceService: async () => (await this._getServices()).services.SpaceService,
2959
- DataService: async () => (await this._getServices()).services.DataService,
2960
- ProfileService: async () => (await this._getServices()).services.ProfileService,
2961
- SystemService: async () => (await this._getServices()).services.SystemService,
2962
- DevtoolsHost: async () => (await this._getServices()).services.DevtoolsHost,
2963
- TracingService: async () => (await this._getServices()).services.TracingService
2964
- },
3713
+ handlers,
2965
3714
  port: appPort
2966
3715
  });
2967
- this._iframeRpc = (0, import_rpc4.createProtoRpcPeer)({
3716
+ this._shellClientRpc = (0, import_rpc6.createProtoRpcPeer)({
3717
+ exposed: clientServiceBundle,
3718
+ handlers,
3719
+ port: shellPort
3720
+ });
3721
+ this._iframeRpc = (0, import_rpc6.createProtoRpcPeer)({
2968
3722
  requested: iframeServiceBundle,
2969
3723
  exposed: workerServiceBundle,
2970
3724
  handlers: {
@@ -2978,9 +3732,9 @@ var WorkerSession = class {
2978
3732
  try {
2979
3733
  await this.close();
2980
3734
  } catch (err) {
2981
- import_log12.log.catch(err, {}, {
3735
+ import_log15.log.catch(err, {}, {
2982
3736
  file: "worker-session.ts",
2983
- line: 90,
3737
+ line: 92,
2984
3738
  scope: this,
2985
3739
  callSite: (f, a) => f(...a)
2986
3740
  });
@@ -2996,15 +3750,16 @@ var WorkerSession = class {
2996
3750
  this.bridgeService = this._iframeRpc.rpc.BridgeService;
2997
3751
  }
2998
3752
  async open() {
2999
- import_log12.log.info("opening..", {}, {
3753
+ import_log15.log.info("opening..", {}, {
3000
3754
  file: "worker-session.ts",
3001
- line: 104,
3755
+ line: 106,
3002
3756
  scope: this,
3003
3757
  callSite: (f, a) => f(...a)
3004
3758
  });
3005
3759
  await Promise.all([
3006
3760
  this._clientRpc.open(),
3007
- this._iframeRpc.open()
3761
+ this._iframeRpc.open(),
3762
+ this._maybeOpenShell()
3008
3763
  ]);
3009
3764
  await this._startTrigger.wait({
3010
3765
  timeout: 3e3
@@ -3013,20 +3768,20 @@ var WorkerSession = class {
3013
3768
  try {
3014
3769
  await this._iframeRpc.rpc.IframeService.heartbeat();
3015
3770
  } catch (err1) {
3016
- import_log12.log.warn("Heartbeat failed", {
3771
+ import_log15.log.warn("Heartbeat failed", {
3017
3772
  err: err1
3018
3773
  }, {
3019
3774
  file: "worker-session.ts",
3020
- line: 116,
3775
+ line: 118,
3021
3776
  scope: this,
3022
3777
  callSite: (f, a) => f(...a)
3023
3778
  });
3024
3779
  try {
3025
3780
  await this.close();
3026
3781
  } catch (err) {
3027
- import_log12.log.catch(err, {}, {
3782
+ import_log15.log.catch(err, {}, {
3028
3783
  file: "worker-session.ts",
3029
- line: 120,
3784
+ line: 122,
3030
3785
  scope: this,
3031
3786
  callSite: (f, a) => f(...a)
3032
3787
  });
@@ -3035,18 +3790,18 @@ var WorkerSession = class {
3035
3790
  }, this._options.heartbeatInterval);
3036
3791
  }
3037
3792
  async close() {
3038
- import_log12.log.info("closing..", {}, {
3793
+ import_log15.log.info("closing..", {}, {
3039
3794
  file: "worker-session.ts",
3040
- line: 127,
3795
+ line: 129,
3041
3796
  scope: this,
3042
3797
  callSite: (f, a) => f(...a)
3043
3798
  });
3044
3799
  try {
3045
3800
  await this.onClose.callIfSet();
3046
3801
  } catch (err) {
3047
- import_log12.log.catch(err, {}, {
3802
+ import_log15.log.catch(err, {}, {
3048
3803
  file: "worker-session.ts",
3049
- line: 131,
3804
+ line: 133,
3050
3805
  scope: this,
3051
3806
  callSite: (f, a) => f(...a)
3052
3807
  });
@@ -3059,9 +3814,21 @@ var WorkerSession = class {
3059
3814
  this._iframeRpc.close()
3060
3815
  ]);
3061
3816
  }
3817
+ async _maybeOpenShell() {
3818
+ try {
3819
+ await (0, import_async20.asyncTimeout)(this._shellClientRpc.open(), 1e3);
3820
+ } catch (e) {
3821
+ import_log15.log.info("No shell connected.", {}, {
3822
+ file: "worker-session.ts",
3823
+ line: 147,
3824
+ scope: this,
3825
+ callSite: (f, a) => f(...a)
3826
+ });
3827
+ }
3828
+ }
3062
3829
  };
3063
- __decorate3([
3064
- import_log12.logInfo
3830
+ __decorate4([
3831
+ import_log15.logInfo
3065
3832
  ], WorkerSession.prototype, "origin", void 0);
3066
3833
 
3067
3834
  // packages/sdk/client-services/src/packlets/vault/worker-runtime.ts
@@ -3069,28 +3836,46 @@ var WorkerRuntime = class {
3069
3836
  // prettier-ignore
3070
3837
  constructor(_configProvider) {
3071
3838
  this._configProvider = _configProvider;
3072
- this._transportFactory = new import_network_manager4.WebRTCTransportProxyFactory();
3073
- this._ready = new import_async18.Trigger();
3839
+ this._transportFactory = new import_network_manager5.WebRTCTransportProxyFactory();
3840
+ this._ready = new import_async21.Trigger();
3074
3841
  this.sessions = /* @__PURE__ */ new Set();
3075
3842
  }
3076
3843
  async start() {
3844
+ (0, import_log16.log)("starting...", {}, {
3845
+ file: "worker-runtime.ts",
3846
+ line: 42,
3847
+ scope: this,
3848
+ callSite: (f, a) => f(...a)
3849
+ });
3077
3850
  try {
3078
3851
  this._config = await this._configProvider();
3079
3852
  const signalServer = this._config.get("runtime.services.signal.server");
3080
3853
  this._clientServices = new ClientServicesHost({
3081
3854
  config: this._config,
3082
- networkManager: new import_network_manager4.NetworkManager({
3855
+ networkManager: new import_network_manager5.NetworkManager({
3083
3856
  log: true,
3084
- signalManager: signalServer ? new import_messaging.WebsocketSignalManager([
3857
+ signalManager: signalServer ? new import_messaging2.WebsocketSignalManager([
3085
3858
  signalServer
3086
- ]) : new import_messaging.MemorySignalManager(new import_messaging.MemorySignalManagerContext()),
3859
+ ]) : new import_messaging2.MemorySignalManager(new import_messaging2.MemorySignalManagerContext()),
3087
3860
  transportFactory: this._transportFactory
3088
3861
  })
3089
3862
  });
3090
3863
  await this._clientServices.open();
3091
3864
  this._ready.wake(void 0);
3865
+ (0, import_log16.log)("started", {}, {
3866
+ file: "worker-runtime.ts",
3867
+ line: 59,
3868
+ scope: this,
3869
+ callSite: (f, a) => f(...a)
3870
+ });
3092
3871
  } catch (err) {
3093
3872
  this._ready.wake(err);
3873
+ import_log16.log.catch(err, {}, {
3874
+ file: "worker-runtime.ts",
3875
+ line: 62,
3876
+ scope: this,
3877
+ callSite: (f, a) => f(...a)
3878
+ });
3094
3879
  }
3095
3880
  }
3096
3881
  async stop() {
@@ -3099,17 +3884,22 @@ var WorkerRuntime = class {
3099
3884
  /**
3100
3885
  * Create a new session.
3101
3886
  */
3102
- async createSession({ appPort, systemPort }) {
3887
+ async createSession({ appPort, systemPort, shellPort }) {
3103
3888
  const session = new WorkerSession({
3104
- getServices: async () => {
3889
+ getService: async (find) => {
3105
3890
  const error = await this._ready.wait();
3106
- if (error !== void 0) {
3891
+ if (error) {
3107
3892
  throw error;
3108
3893
  }
3109
- return this._clientServices;
3894
+ const service = find(this._clientServices.services);
3895
+ if (!service) {
3896
+ throw new Error("Service not found");
3897
+ }
3898
+ return service;
3110
3899
  },
3111
3900
  appPort,
3112
3901
  systemPort,
3902
+ shellPort,
3113
3903
  readySignal: this._ready
3114
3904
  });
3115
3905
  session.onClose.set(async () => {
@@ -3140,6 +3930,193 @@ var WorkerRuntime = class {
3140
3930
  }
3141
3931
  }
3142
3932
  };
3933
+
3934
+ // packages/sdk/client-services/src/packlets/services/service-registry.ts
3935
+ var ServiceRegistry = class {
3936
+ // prettier-ignore
3937
+ constructor(_serviceBundle, _handlers) {
3938
+ this._serviceBundle = _serviceBundle;
3939
+ this._handlers = _handlers;
3940
+ }
3941
+ get descriptors() {
3942
+ return this._serviceBundle;
3943
+ }
3944
+ get services() {
3945
+ return this._handlers;
3946
+ }
3947
+ setServices(services) {
3948
+ this._handlers = services;
3949
+ }
3950
+ };
3951
+
3952
+ // packages/sdk/client-services/src/packlets/services/service-host.ts
3953
+ var createDefaultModelFactory = () => {
3954
+ return new import_model_factory.ModelFactory().registerModel(import_document_model.DocumentModel).registerModel(import_text_model.TextModel);
3955
+ };
3956
+ var ClientServicesHost = class {
3957
+ constructor({
3958
+ config,
3959
+ modelFactory = createDefaultModelFactory(),
3960
+ // TODO(burdon): Create ApolloLink abstraction (see Client).
3961
+ networkManager,
3962
+ storage = createStorageObjects(config.get("runtime.client.storage", {})).storage,
3963
+ lockKey
3964
+ }) {
3965
+ this._open = false;
3966
+ this._config = config;
3967
+ this._modelFactory = modelFactory;
3968
+ this._networkManager = networkManager;
3969
+ this._storage = storage;
3970
+ this._resourceLock = lockKey ? new VaultResourceLock({
3971
+ lockKey,
3972
+ onAcquire: () => this.open(),
3973
+ onRelease: () => this.close()
3974
+ }) : void 0;
3975
+ this._systemService = new SystemServiceImpl({
3976
+ config: this._config,
3977
+ onInit: async () => {
3978
+ var _a;
3979
+ await ((_a = this._resourceLock) == null ? void 0 : _a.acquire());
3980
+ },
3981
+ onStatus: async () => {
3982
+ if (!this.isOpen) {
3983
+ return {
3984
+ status: import_client2.Status.INACTIVE
3985
+ };
3986
+ }
3987
+ return {
3988
+ status: import_client2.Status.ACTIVE
3989
+ };
3990
+ },
3991
+ onReset: async () => {
3992
+ var _a;
3993
+ await ((_a = this._serviceContext) == null ? void 0 : _a.reset());
3994
+ }
3995
+ });
3996
+ this._serviceRegistry = new ServiceRegistry(clientServiceBundle, {
3997
+ SystemService: this._systemService
3998
+ });
3999
+ }
4000
+ get isOpen() {
4001
+ return this._open;
4002
+ }
4003
+ get descriptors() {
4004
+ return this._serviceRegistry.descriptors;
4005
+ }
4006
+ get services() {
4007
+ return this._serviceRegistry.services;
4008
+ }
4009
+ async open() {
4010
+ var _a;
4011
+ if (this._open) {
4012
+ return;
4013
+ }
4014
+ (0, import_log17.log)("opening...", {}, {
4015
+ file: "service-host.ts",
4016
+ line: 125,
4017
+ scope: this,
4018
+ callSite: (f, a) => f(...a)
4019
+ });
4020
+ this._serviceContext = new ServiceContext(this._storage, this._networkManager, this._modelFactory);
4021
+ this._serviceRegistry.setServices({
4022
+ // TODO(burdon): Move to new protobuf definitions.
4023
+ SystemService: this._systemService,
4024
+ HaloInvitationsService: new HaloInvitationsServiceImpl(this._serviceContext.identityManager, this._serviceContext.haloInvitations),
4025
+ DevicesService: new DevicesServiceImpl(this._serviceContext.identityManager),
4026
+ SpaceInvitationsService: new SpaceInvitationsServiceImpl(this._serviceContext.identityManager, () => {
4027
+ var _a2;
4028
+ return (_a2 = this._serviceContext.spaceInvitations) != null ? _a2 : (0, import_debug7.raise)(new Error("SpaceInvitations not initialized"));
4029
+ }, () => {
4030
+ var _a2;
4031
+ return (_a2 = this._serviceContext.dataSpaceManager) != null ? _a2 : (0, import_debug7.raise)(new Error("SpaceManager not initialized"));
4032
+ }),
4033
+ SpacesService: new SpacesServiceImpl(this._serviceContext.spaceManager),
4034
+ DataService: new import_echo_pipeline5.DataServiceImpl(this._serviceContext.dataServiceSubscriptions),
4035
+ NetworkService: new NetworkServiceImpl(this._serviceContext.networkManager),
4036
+ // TODO(burdon): Move to new protobuf definitions.
4037
+ ProfileService: new ProfileServiceImpl(this._serviceContext),
4038
+ // TODO(burdon): Port old SubscribeSpaces to QueryServices>
4039
+ SpaceService: new SpaceServiceImpl(this._serviceContext),
4040
+ TracingService: new TracingServiceImpl(this._config),
4041
+ DevtoolsHost: new DevtoolsServiceImpl({
4042
+ events: new DevtoolsHostEvents(),
4043
+ config: this._config,
4044
+ context: this._serviceContext
4045
+ })
4046
+ });
4047
+ await this._serviceContext.open();
4048
+ this._open = true;
4049
+ const deviceKey = (_a = this._serviceContext.identityManager.identity) == null ? void 0 : _a.deviceKey;
4050
+ (0, import_log17.log)("opened", {
4051
+ deviceKey
4052
+ }, {
4053
+ file: "service-host.ts",
4054
+ line: 172,
4055
+ scope: this,
4056
+ callSite: (f, a) => f(...a)
4057
+ });
4058
+ }
4059
+ async close() {
4060
+ var _a;
4061
+ if (!this._open) {
4062
+ return;
4063
+ }
4064
+ const deviceKey = (_a = this._serviceContext.identityManager.identity) == null ? void 0 : _a.deviceKey;
4065
+ (0, import_log17.log)("closing...", {
4066
+ deviceKey
4067
+ }, {
4068
+ file: "service-host.ts",
4069
+ line: 181,
4070
+ scope: this,
4071
+ callSite: (f, a) => f(...a)
4072
+ });
4073
+ this._serviceRegistry.setServices({
4074
+ SystemService: this._systemService
4075
+ });
4076
+ await this._serviceContext.close();
4077
+ this._open = false;
4078
+ (0, import_log17.log)("closed", {
4079
+ deviceKey
4080
+ }, {
4081
+ file: "service-host.ts",
4082
+ line: 185,
4083
+ scope: this,
4084
+ callSite: (f, a) => f(...a)
4085
+ });
4086
+ }
4087
+ };
4088
+
4089
+ // packages/sdk/client-services/src/packlets/services/service-proxy.ts
4090
+ var import_async22 = require("@dxos/async");
4091
+ var import_errors2 = require("@dxos/errors");
4092
+ var import_rpc7 = require("@dxos/rpc");
4093
+ var ClientServicesProxy = class {
4094
+ // prettier-ignore
4095
+ constructor(port, _timeout = 3e4) {
4096
+ this._timeout = _timeout;
4097
+ this._proxy = (0, import_rpc7.createProtoRpcPeer)({
4098
+ requested: clientServiceBundle,
4099
+ exposed: {},
4100
+ handlers: {},
4101
+ port
4102
+ });
4103
+ }
4104
+ get proxy() {
4105
+ return this._proxy;
4106
+ }
4107
+ get descriptors() {
4108
+ return clientServiceBundle;
4109
+ }
4110
+ get services() {
4111
+ return this._proxy.rpc;
4112
+ }
4113
+ async open() {
4114
+ await (0, import_async22.asyncTimeout)(this._proxy.open(), this._timeout, new import_errors2.RemoteServiceConnectionTimeout());
4115
+ }
4116
+ async close() {
4117
+ await this._proxy.close();
4118
+ }
4119
+ };
3143
4120
  // Annotate the CommonJS export names for ESM import in node:
3144
4121
  0 && (module.exports = {
3145
4122
  AUTHENTICATION_CODE_LENGTH,
@@ -3154,16 +4131,20 @@ var WorkerRuntime = class {
3154
4131
  HaloInvitationsHandler,
3155
4132
  HaloInvitationsProxy,
3156
4133
  HaloInvitationsServiceImpl,
3157
- IFrameRuntime,
4134
+ IFrameHostRuntime,
4135
+ IFrameProxyRuntime,
3158
4136
  INVITATION_TIMEOUT,
3159
4137
  Identity,
3160
4138
  IdentityManager,
3161
4139
  InvitationEncoder,
3162
4140
  InvitationObservableProvider,
4141
+ MemoryShellRuntime,
3163
4142
  ON_CLOSE_DELAY,
3164
4143
  ProfileServiceImpl,
3165
4144
  ServiceContext,
3166
4145
  ServiceRegistry,
4146
+ ShellController,
4147
+ ShellRuntimeImpl,
3167
4148
  SpaceInvitationsHandler,
3168
4149
  SpaceInvitationsProxy,
3169
4150
  SpaceInvitationsServiceImpl,
@@ -3171,20 +4152,25 @@ var WorkerRuntime = class {
3171
4152
  SystemServiceImpl,
3172
4153
  TracingServiceImpl,
3173
4154
  TrustedKeySetAuthVerifier,
4155
+ VaultResourceLock,
3174
4156
  WorkerRuntime,
3175
4157
  WorkerSession,
4158
+ appServiceBundle,
3176
4159
  clientServiceBundle,
3177
4160
  createAuthProvider,
3178
4161
  createDefaultModelFactory,
3179
4162
  createStorageObjects,
3180
4163
  getNetworkPeers,
4164
+ iframeServiceBundle,
4165
+ shellServiceBundle,
3181
4166
  subscribeToFeedBlocks,
3182
4167
  subscribeToFeeds,
3183
4168
  subscribeToNetworkStatus,
3184
4169
  subscribeToNetworkTopics,
3185
- subscribeToSignalTrace,
4170
+ subscribeToSignal,
3186
4171
  subscribeToSpaces,
3187
4172
  subscribeToSwarmInfo,
4173
+ workerServiceBundle,
3188
4174
  wrapObservable
3189
4175
  });
3190
4176
  //# sourceMappingURL=index.cjs.map