@dxos/client-services 0.4.10-main.c42bfdb → 0.4.10-main.c61b011

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 (77) hide show
  1. package/dist/lib/browser/{chunk-W7UANCHR.mjs → chunk-ZWMG6QKN.mjs} +831 -706
  2. package/dist/lib/browser/chunk-ZWMG6QKN.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +10 -6
  4. package/dist/lib/browser/index.mjs.map +3 -3
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/packlets/testing/index.mjs +138 -118
  7. package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
  8. package/dist/lib/node/{chunk-JSVLZGJM.cjs → chunk-PP42CXTU.cjs} +862 -734
  9. package/dist/lib/node/chunk-PP42CXTU.cjs.map +7 -0
  10. package/dist/lib/node/index.cjs +50 -46
  11. package/dist/lib/node/index.cjs.map +3 -3
  12. package/dist/lib/node/meta.json +1 -1
  13. package/dist/lib/node/packlets/testing/index.cjs +137 -120
  14. package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
  15. package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
  16. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts +3 -1
  17. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts.map +1 -1
  18. package/dist/types/src/packlets/invitations/index.d.ts +1 -0
  19. package/dist/types/src/packlets/invitations/index.d.ts.map +1 -1
  20. package/dist/types/src/packlets/invitations/invitation-extension.d.ts +1 -0
  21. package/dist/types/src/packlets/invitations/invitation-extension.d.ts.map +1 -1
  22. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts +6 -1
  23. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts.map +1 -1
  24. package/dist/types/src/packlets/invitations/invitations-handler.d.ts +8 -4
  25. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  26. package/dist/types/src/packlets/invitations/invitations-manager.d.ts +44 -0
  27. package/dist/types/src/packlets/invitations/invitations-manager.d.ts.map +1 -0
  28. package/dist/types/src/packlets/invitations/invitations-service.d.ts +7 -23
  29. package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
  30. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts +2 -1
  31. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
  32. package/dist/types/src/packlets/services/service-context.d.ts +6 -6
  33. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  34. package/dist/types/src/packlets/services/service-host.d.ts +3 -1
  35. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  36. package/dist/types/src/packlets/spaces/data-space-manager.d.ts +8 -3
  37. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  38. package/dist/types/src/packlets/spaces/data-space.d.ts +4 -3
  39. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  40. package/dist/types/src/packlets/storage/level.d.ts.map +1 -1
  41. package/dist/types/src/packlets/testing/invitation-utils.d.ts.map +1 -1
  42. package/dist/types/src/packlets/testing/test-builder.d.ts +9 -3
  43. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  44. package/dist/types/src/packlets/vault/worker-runtime.d.ts.map +1 -1
  45. package/dist/types/src/version.d.ts +1 -1
  46. package/package.json +34 -34
  47. package/src/packlets/identity/identity-manager.ts +1 -0
  48. package/src/packlets/identity/identity.test.ts +3 -0
  49. package/src/packlets/invitations/device-invitation-protocol.ts +6 -1
  50. package/src/packlets/invitations/index.ts +1 -0
  51. package/src/packlets/invitations/invitation-extension.ts +28 -1
  52. package/src/packlets/invitations/invitation-protocol.ts +7 -1
  53. package/src/packlets/invitations/invitations-handler.ts +75 -96
  54. package/src/packlets/invitations/invitations-manager.ts +271 -0
  55. package/src/packlets/invitations/invitations-service.ts +23 -168
  56. package/src/packlets/invitations/space-invitation-protocol.ts +45 -3
  57. package/src/packlets/services/automerge-host.test.ts +13 -7
  58. package/src/packlets/services/service-context.test.ts +4 -1
  59. package/src/packlets/services/service-context.ts +23 -23
  60. package/src/packlets/services/service-host.test.ts +6 -0
  61. package/src/packlets/services/service-host.ts +13 -22
  62. package/src/packlets/spaces/data-space-manager.test.ts +4 -4
  63. package/src/packlets/spaces/data-space-manager.ts +56 -13
  64. package/src/packlets/spaces/data-space.ts +14 -19
  65. package/src/packlets/storage/level.ts +2 -1
  66. package/src/packlets/testing/invitation-utils.ts +100 -97
  67. package/src/packlets/testing/test-builder.ts +37 -8
  68. package/src/packlets/vault/worker-runtime.ts +3 -1
  69. package/src/version.ts +1 -1
  70. package/dist/lib/browser/chunk-W7UANCHR.mjs.map +0 -7
  71. package/dist/lib/node/chunk-JSVLZGJM.cjs.map +0 -7
  72. package/dist/types/src/packlets/indexing/index.d.ts +0 -2
  73. package/dist/types/src/packlets/indexing/index.d.ts.map +0 -1
  74. package/dist/types/src/packlets/indexing/util.d.ts +0 -15
  75. package/dist/types/src/packlets/indexing/util.d.ts.map +0 -1
  76. package/src/packlets/indexing/index.ts +0 -5
  77. package/src/packlets/indexing/util.ts +0 -89
@@ -26,8 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var chunk_JSVLZGJM_exports = {};
30
- __export(chunk_JSVLZGJM_exports, {
29
+ var chunk_PP42CXTU_exports = {};
30
+ __export(chunk_PP42CXTU_exports, {
31
31
  ClientRpcServer: () => ClientRpcServer,
32
32
  ClientServicesHost: () => ClientServicesHost,
33
33
  ClientServicesProviderResource: () => ClientServicesProviderResource,
@@ -41,6 +41,7 @@ __export(chunk_JSVLZGJM_exports, {
41
41
  IdentityManager: () => IdentityManager,
42
42
  IdentityServiceImpl: () => IdentityServiceImpl,
43
43
  InvitationsHandler: () => InvitationsHandler,
44
+ InvitationsManager: () => InvitationsManager,
44
45
  InvitationsServiceImpl: () => InvitationsServiceImpl,
45
46
  Lock: () => Lock,
46
47
  ServiceContext: () => ServiceContext,
@@ -48,6 +49,7 @@ __export(chunk_JSVLZGJM_exports, {
48
49
  SpaceInvitationProtocol: () => SpaceInvitationProtocol,
49
50
  SpacesServiceImpl: () => SpacesServiceImpl,
50
51
  TrustedKeySetAuthVerifier: () => TrustedKeySetAuthVerifier,
52
+ createAdmissionKeypair: () => createAdmissionKeypair,
51
53
  createAuthProvider: () => createAuthProvider,
52
54
  createCollectDiagnosticsBroadcastHandler: () => createCollectDiagnosticsBroadcastHandler,
53
55
  createCollectDiagnosticsBroadcastSender: () => createCollectDiagnosticsBroadcastSender,
@@ -55,7 +57,6 @@ __export(chunk_JSVLZGJM_exports, {
55
57
  createLevel: () => createLevel,
56
58
  createStorageObjects: () => createStorageObjects,
57
59
  getNetworkPeers: () => getNetworkPeers,
58
- invitationExpired: () => invitationExpired,
59
60
  isLocked: () => isLocked,
60
61
  subscribeToFeedBlocks: () => subscribeToFeedBlocks,
61
62
  subscribeToFeeds: () => subscribeToFeeds,
@@ -65,7 +66,7 @@ __export(chunk_JSVLZGJM_exports, {
65
66
  subscribeToSpaces: () => subscribeToSpaces,
66
67
  subscribeToSwarmInfo: () => subscribeToSwarmInfo
67
68
  });
68
- module.exports = __toCommonJS(chunk_JSVLZGJM_exports);
69
+ module.exports = __toCommonJS(chunk_PP42CXTU_exports);
69
70
  var import_async = require("@dxos/async");
70
71
  var import_codec_protobuf = require("@dxos/codec-protobuf");
71
72
  var import_feed_store = require("@dxos/feed-store");
@@ -119,7 +120,7 @@ var import_services2 = require("@dxos/protocols/proto/dxos/client/services");
119
120
  var import_async7 = require("@dxos/async");
120
121
  var import_client_protocol2 = require("@dxos/client-protocol");
121
122
  var import_context4 = require("@dxos/context");
122
- var import_credentials7 = require("@dxos/credentials");
123
+ var import_crypto = require("@dxos/crypto");
123
124
  var import_invariant5 = require("@dxos/invariant");
124
125
  var import_keys5 = require("@dxos/keys");
125
126
  var import_log4 = require("@dxos/log");
@@ -129,6 +130,7 @@ var import_services3 = require("@dxos/protocols/proto/dxos/client/services");
129
130
  var import_invitations = require("@dxos/protocols/proto/dxos/halo/invitations");
130
131
  var import_async8 = require("@dxos/async");
131
132
  var import_context5 = require("@dxos/context");
133
+ var import_crypto2 = require("@dxos/crypto");
132
134
  var import_invariant6 = require("@dxos/invariant");
133
135
  var import_keys6 = require("@dxos/keys");
134
136
  var import_log5 = require("@dxos/log");
@@ -136,61 +138,67 @@ var import_protocols5 = require("@dxos/protocols");
136
138
  var import_services4 = require("@dxos/protocols/proto/dxos/client/services");
137
139
  var import_invitations2 = require("@dxos/protocols/proto/dxos/halo/invitations");
138
140
  var import_teleport = require("@dxos/teleport");
139
- var import_async9 = require("@dxos/async");
140
141
  var import_codec_protobuf8 = require("@dxos/codec-protobuf");
141
- var import_context6 = require("@dxos/context");
142
- var import_invariant7 = require("@dxos/invariant");
143
- var import_log6 = require("@dxos/log");
144
142
  var import_services5 = require("@dxos/protocols/proto/dxos/client/services");
145
- var import_credentials8 = require("@dxos/credentials");
143
+ var import_credentials7 = require("@dxos/credentials");
146
144
  var import_feed_store3 = require("@dxos/feed-store");
147
- var import_invariant8 = require("@dxos/invariant");
148
- var import_log7 = require("@dxos/log");
145
+ var import_invariant7 = require("@dxos/invariant");
146
+ var import_log6 = require("@dxos/log");
149
147
  var import_protocols6 = require("@dxos/protocols");
150
148
  var import_services6 = require("@dxos/protocols/proto/dxos/client/services");
149
+ var import_credentials8 = require("@dxos/protocols/proto/dxos/halo/credentials");
150
+ var import_async9 = require("@dxos/async");
151
+ var import_client_protocol3 = require("@dxos/client-protocol");
152
+ var import_context6 = require("@dxos/context");
153
+ var import_credentials9 = require("@dxos/credentials");
154
+ var import_echo_pipeline = require("@dxos/echo-pipeline");
155
+ var import_invariant8 = require("@dxos/invariant");
156
+ var import_keys7 = require("@dxos/keys");
157
+ var import_log7 = require("@dxos/log");
158
+ var import_services7 = require("@dxos/protocols/proto/dxos/client/services");
151
159
  var import_codec_protobuf9 = require("@dxos/codec-protobuf");
152
160
  var import_debug2 = require("@dxos/debug");
153
161
  var import_rpc = require("@dxos/rpc");
154
162
  var import_tracing3 = require("@dxos/tracing");
155
163
  var import_async10 = require("@dxos/async");
156
- var import_client_protocol3 = require("@dxos/client-protocol");
164
+ var import_client_protocol4 = require("@dxos/client-protocol");
157
165
  var import_context7 = require("@dxos/context");
158
166
  var import_debug3 = require("@dxos/debug");
159
- var import_echo_db = require("@dxos/echo-db");
160
- var import_echo_pipeline = require("@dxos/echo-pipeline");
161
167
  var import_echo_pipeline2 = require("@dxos/echo-pipeline");
168
+ var import_echo_pipeline3 = require("@dxos/echo-pipeline");
169
+ var import_echo_schema = require("@dxos/echo-schema");
162
170
  var import_invariant9 = require("@dxos/invariant");
163
- var import_keys7 = require("@dxos/keys");
171
+ var import_keys8 = require("@dxos/keys");
164
172
  var import_log8 = require("@dxos/log");
165
173
  var import_protocols7 = require("@dxos/protocols");
166
- var import_services7 = require("@dxos/protocols/proto/dxos/client/services");
167
- var import_credentials9 = require("@dxos/protocols/proto/dxos/halo/credentials");
174
+ var import_services8 = require("@dxos/protocols/proto/dxos/client/services");
175
+ var import_credentials10 = require("@dxos/protocols/proto/dxos/halo/credentials");
168
176
  var import_timeframe2 = require("@dxos/timeframe");
169
177
  var import_tracing4 = require("@dxos/tracing");
170
178
  var import_util4 = require("@dxos/util");
171
179
  var import_async11 = require("@dxos/async");
172
- var import_credentials10 = require("@dxos/credentials");
180
+ var import_credentials11 = require("@dxos/credentials");
173
181
  var import_async12 = require("@dxos/async");
174
182
  var import_context8 = require("@dxos/context");
175
183
  var import_invariant10 = require("@dxos/invariant");
176
- var import_keys8 = require("@dxos/keys");
184
+ var import_keys9 = require("@dxos/keys");
177
185
  var import_log9 = require("@dxos/log");
178
186
  var import_protocols8 = require("@dxos/protocols");
179
187
  var import_teleport2 = require("@dxos/teleport");
180
188
  var import_util5 = require("@dxos/util");
181
189
  var import_async13 = require("@dxos/async");
182
190
  var import_context9 = require("@dxos/context");
183
- var import_credentials11 = require("@dxos/credentials");
191
+ var import_credentials12 = require("@dxos/credentials");
184
192
  var import_invariant11 = require("@dxos/invariant");
185
- var import_keys9 = require("@dxos/keys");
193
+ var import_keys10 = require("@dxos/keys");
186
194
  var import_log10 = require("@dxos/log");
187
195
  var import_protocols9 = require("@dxos/protocols");
188
- var import_services8 = require("@dxos/protocols/proto/dxos/client/services");
196
+ var import_services9 = require("@dxos/protocols/proto/dxos/client/services");
189
197
  var import_teleport_extension_gossip2 = require("@dxos/teleport-extension-gossip");
190
198
  var import_util6 = require("@dxos/util");
191
- var import_credentials12 = require("@dxos/credentials");
199
+ var import_credentials13 = require("@dxos/credentials");
192
200
  var import_debug4 = require("@dxos/debug");
193
- var import_credentials13 = require("@dxos/protocols/proto/dxos/halo/credentials");
201
+ var import_credentials14 = require("@dxos/protocols/proto/dxos/halo/credentials");
194
202
  var import_timeframe3 = require("@dxos/timeframe");
195
203
  var import_async14 = require("@dxos/async");
196
204
  var import_codec_protobuf10 = require("@dxos/codec-protobuf");
@@ -198,80 +206,76 @@ var import_debug5 = require("@dxos/debug");
198
206
  var import_invariant12 = require("@dxos/invariant");
199
207
  var import_log11 = require("@dxos/log");
200
208
  var import_protocols10 = require("@dxos/protocols");
201
- var import_services9 = require("@dxos/protocols/proto/dxos/client/services");
209
+ var import_services10 = require("@dxos/protocols/proto/dxos/client/services");
202
210
  var import_async15 = require("@dxos/async");
203
211
  var import_context10 = require("@dxos/context");
204
- var import_credentials14 = require("@dxos/credentials");
212
+ var import_credentials15 = require("@dxos/credentials");
205
213
  var import_debug6 = require("@dxos/debug");
206
- var import_echo_pipeline3 = require("@dxos/echo-pipeline");
214
+ var import_echo_db = require("@dxos/echo-db");
215
+ var import_echo_pipeline4 = require("@dxos/echo-pipeline");
207
216
  var import_feed_store4 = require("@dxos/feed-store");
208
- var import_indexing = require("@dxos/indexing");
209
217
  var import_invariant13 = require("@dxos/invariant");
210
218
  var import_keyring = require("@dxos/keyring");
211
- var import_keys10 = require("@dxos/keys");
219
+ var import_keys11 = require("@dxos/keys");
212
220
  var import_log12 = require("@dxos/log");
213
221
  var import_protocols11 = require("@dxos/protocols");
214
- var import_services10 = require("@dxos/protocols/proto/dxos/client/services");
222
+ var import_services11 = require("@dxos/protocols/proto/dxos/client/services");
215
223
  var import_teleport_extension_object_sync = require("@dxos/teleport-extension-object-sync");
216
224
  var import_tracing5 = require("@dxos/tracing");
217
225
  var import_util7 = require("@dxos/util");
218
- var import_automerge = require("@dxos/automerge/automerge");
219
- var import_debug7 = require("@dxos/debug");
220
- var import_protocols12 = require("@dxos/protocols");
221
226
  var import_codec_protobuf11 = require("@dxos/codec-protobuf");
222
- var import_credentials15 = require("@dxos/credentials");
227
+ var import_credentials16 = require("@dxos/credentials");
223
228
  var import_invariant14 = require("@dxos/invariant");
224
- var import_protocols13 = require("@dxos/protocols");
225
- var import_services11 = require("@dxos/protocols/proto/dxos/client/services");
226
- var import_tracing6 = require("@dxos/tracing");
229
+ var import_protocols12 = require("@dxos/protocols");
227
230
  var import_services12 = require("@dxos/protocols/proto/dxos/client/services");
228
- var import_config = require("@dxos/config");
231
+ var import_tracing6 = require("@dxos/tracing");
229
232
  var import_services13 = require("@dxos/protocols/proto/dxos/client/services");
233
+ var import_config = require("@dxos/config");
234
+ var import_services14 = require("@dxos/protocols/proto/dxos/client/services");
230
235
  var import_tracing7 = require("@dxos/tracing");
231
236
  var import_util8 = require("@dxos/util");
232
237
  var import_async16 = require("@dxos/async");
233
- var import_client_protocol4 = require("@dxos/client-protocol");
238
+ var import_client_protocol5 = require("@dxos/client-protocol");
234
239
  var import_context11 = require("@dxos/context");
235
- var import_echo_pipeline4 = require("@dxos/echo-pipeline");
236
- var E = __toESM(require("@dxos/echo-schema"));
237
- var import_indexing2 = require("@dxos/indexing");
240
+ var import_echo_pipeline5 = require("@dxos/echo-pipeline");
241
+ var import_echo_schema2 = require("@dxos/echo-schema");
238
242
  var import_invariant15 = require("@dxos/invariant");
239
- var import_keys11 = require("@dxos/keys");
243
+ var import_keys12 = require("@dxos/keys");
240
244
  var import_log13 = require("@dxos/log");
241
245
  var import_messaging = require("@dxos/messaging");
242
246
  var import_network_manager2 = require("@dxos/network-manager");
243
- var import_protocols14 = require("@dxos/protocols");
244
- var import_services14 = require("@dxos/protocols/proto/dxos/client/services");
247
+ var import_protocols13 = require("@dxos/protocols");
248
+ var import_services15 = require("@dxos/protocols/proto/dxos/client/services");
245
249
  var import_tracing8 = require("@dxos/tracing");
246
250
  var import_util9 = require("@dxos/util");
247
251
  var import_websocket_rpc = require("@dxos/websocket-rpc");
248
252
  var import_async17 = require("@dxos/async");
249
253
  var import_codec_protobuf12 = require("@dxos/codec-protobuf");
250
254
  var import_invariant16 = require("@dxos/invariant");
251
- var import_services15 = require("@dxos/protocols/proto/dxos/client/services");
255
+ var import_services16 = require("@dxos/protocols/proto/dxos/client/services");
252
256
  var import_invariant17 = require("@dxos/invariant");
253
257
  var import_lock_file = require("@dxos/lock-file");
254
258
  var import_log14 = require("@dxos/log");
255
259
  var import_async18 = require("@dxos/async");
256
260
  var import_codec_protobuf13 = require("@dxos/codec-protobuf");
257
- var import_keys12 = require("@dxos/keys");
261
+ var import_keys13 = require("@dxos/keys");
258
262
  var import_log15 = require("@dxos/log");
259
- var import_services16 = require("@dxos/protocols/proto/dxos/client/services");
263
+ var import_services17 = require("@dxos/protocols/proto/dxos/client/services");
260
264
  var import_util10 = require("@dxos/util");
261
265
  var import_codec_protobuf14 = require("@dxos/codec-protobuf");
262
- var import_protocols15 = require("@dxos/protocols");
266
+ var import_protocols14 = require("@dxos/protocols");
263
267
  var import_config2 = require("@dxos/protocols/proto/dxos/config");
264
268
  var import_random_access_storage = require("@dxos/random-access-storage");
265
- var import_client_protocol5 = require("@dxos/client-protocol");
269
+ var import_client_protocol6 = require("@dxos/client-protocol");
266
270
  var import_config3 = require("@dxos/protocols/proto/dxos/config");
267
271
  var import_util11 = require("@dxos/util");
268
272
  var import_level = require("level");
269
273
  var import_node_path = __toESM(require("node:path"));
270
- var import_keys13 = require("@dxos/keys");
274
+ var import_keys14 = require("@dxos/keys");
271
275
  var import_codec_protobuf15 = require("@dxos/codec-protobuf");
272
- var import_services17 = require("@dxos/protocols/proto/dxos/client/services");
276
+ var import_services18 = require("@dxos/protocols/proto/dxos/client/services");
273
277
  var import_util12 = require("@dxos/util");
274
- var import_keys14 = require("@dxos/keys");
278
+ var import_keys15 = require("@dxos/keys");
275
279
  var import_util13 = require("@dxos/util");
276
280
  var subscribeToFeeds = ({ feedStore }, { feedKeys }) => {
277
281
  return new import_codec_protobuf.Stream(({ next }) => {
@@ -1290,7 +1294,9 @@ var IdentityManager = class {
1290
1294
  C: (f, a) => f(...a)
1291
1295
  });
1292
1296
  },
1293
- memberKey: identityKey
1297
+ memberKey: identityKey,
1298
+ onDelegatedInvitationStatusChange: async () => {
1299
+ }
1294
1300
  });
1295
1301
  }
1296
1302
  };
@@ -1387,10 +1393,13 @@ var DeviceInvitationProtocol = class {
1387
1393
  kind: import_services2.Invitation.Kind.DEVICE
1388
1394
  };
1389
1395
  }
1390
- async admit(request) {
1396
+ async delegate(invitation) {
1397
+ throw new Error("delegation not supported");
1398
+ }
1399
+ async admit(_, request) {
1391
1400
  (0, import_invariant4.invariant)(request.device, void 0, {
1392
1401
  F: __dxlog_file5,
1393
- L: 37,
1402
+ L: 42,
1394
1403
  S: this,
1395
1404
  A: [
1396
1405
  "request.device",
@@ -1436,7 +1445,7 @@ var DeviceInvitationProtocol = class {
1436
1445
  async accept(response, request) {
1437
1446
  (0, import_invariant4.invariant)(response.device, void 0, {
1438
1447
  F: __dxlog_file5,
1439
- L: 82,
1448
+ L: 87,
1440
1449
  S: this,
1441
1450
  A: [
1442
1451
  "response.device",
@@ -1446,7 +1455,7 @@ var DeviceInvitationProtocol = class {
1446
1455
  const { identityKey, haloSpaceKey, genesisFeedKey, controlTimeframe } = response.device;
1447
1456
  (0, import_invariant4.invariant)(request.device, void 0, {
1448
1457
  F: __dxlog_file5,
1449
- L: 85,
1458
+ L: 90,
1450
1459
  S: this,
1451
1460
  A: [
1452
1461
  "request.device",
@@ -1485,6 +1494,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1485
1494
  this._callbacks = _callbacks;
1486
1495
  this._ctx = new import_context5.Context();
1487
1496
  this._remoteOptionsTrigger = new import_async8.Trigger();
1497
+ this._challenge = void 0;
1488
1498
  this.invitation = void 0;
1489
1499
  this.guestProfile = void 0;
1490
1500
  this.authenticationPassed = false;
@@ -1499,7 +1509,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1499
1509
  options: async (options) => {
1500
1510
  (0, import_invariant6.invariant)(!this._remoteOptions, "Remote options already set.", {
1501
1511
  F: __dxlog_file6,
1502
- L: 87,
1512
+ L: 90,
1503
1513
  S: this,
1504
1514
  A: [
1505
1515
  "!this._remoteOptions",
@@ -1516,7 +1526,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1516
1526
  id: traceId
1517
1527
  }), {
1518
1528
  F: __dxlog_file6,
1519
- L: 96,
1529
+ L: 99,
1520
1530
  S: this,
1521
1531
  C: (f, a) => f(...a)
1522
1532
  });
@@ -1526,7 +1536,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1526
1536
  invitationId
1527
1537
  }, {
1528
1538
  F: __dxlog_file6,
1529
- L: 100,
1539
+ L: 103,
1530
1540
  S: this,
1531
1541
  C: (f, a) => f(...a)
1532
1542
  });
@@ -1540,7 +1550,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1540
1550
  guestProfile: profile
1541
1551
  }, {
1542
1552
  F: __dxlog_file6,
1543
- L: 109,
1553
+ L: 112,
1544
1554
  S: this,
1545
1555
  C: (f, a) => f(...a)
1546
1556
  });
@@ -1549,25 +1559,27 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1549
1559
  ...this.invitation,
1550
1560
  state: import_services4.Invitation.State.READY_FOR_AUTHENTICATION
1551
1561
  });
1562
+ this._challenge = this.invitation.authMethod === import_services4.Invitation.AuthMethod.KNOWN_PUBLIC_KEY ? (0, import_crypto2.randomBytes)(32) : void 0;
1552
1563
  import_log5.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols5.trace.end({
1553
1564
  id: traceId
1554
1565
  }), {
1555
1566
  F: __dxlog_file6,
1556
- L: 116,
1567
+ L: 122,
1557
1568
  S: this,
1558
1569
  C: (f, a) => f(...a)
1559
1570
  });
1560
1571
  return {
1561
- authMethod: this.invitation.authMethod
1572
+ authMethod: this.invitation.authMethod,
1573
+ challenge: this._challenge
1562
1574
  };
1563
1575
  },
1564
- authenticate: async ({ authCode: code }) => {
1576
+ authenticate: async ({ authCode: code, signedChallenge }) => {
1565
1577
  const traceId = import_keys6.PublicKey.random().toHex();
1566
1578
  import_log5.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols5.trace.begin({
1567
1579
  id: traceId
1568
1580
  }), {
1569
1581
  F: __dxlog_file6,
1570
- L: 124,
1582
+ L: 131,
1571
1583
  S: this,
1572
1584
  C: (f, a) => f(...a)
1573
1585
  });
@@ -1575,14 +1587,14 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1575
1587
  authCode: code
1576
1588
  }, {
1577
1589
  F: __dxlog_file6,
1578
- L: 125,
1590
+ L: 132,
1579
1591
  S: this,
1580
1592
  C: (f, a) => f(...a)
1581
1593
  });
1582
1594
  let status = import_invitations2.AuthenticationResponse.Status.OK;
1583
1595
  (0, import_invariant6.invariant)(this.invitation, "Invitation is not set.", {
1584
1596
  F: __dxlog_file6,
1585
- L: 128,
1597
+ L: 135,
1586
1598
  S: this,
1587
1599
  A: [
1588
1600
  "this.invitation",
@@ -1593,7 +1605,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1593
1605
  case import_services4.Invitation.AuthMethod.NONE: {
1594
1606
  (0, import_log5.log)("authentication not required", void 0, {
1595
1607
  F: __dxlog_file6,
1596
- L: 131,
1608
+ L: 138,
1597
1609
  S: this,
1598
1610
  C: (f, a) => f(...a)
1599
1611
  });
@@ -1613,12 +1625,25 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1613
1625
  }
1614
1626
  break;
1615
1627
  }
1628
+ case import_services4.Invitation.AuthMethod.KNOWN_PUBLIC_KEY: {
1629
+ if (!this.invitation.guestKeypair) {
1630
+ status = import_invitations2.AuthenticationResponse.Status.INTERNAL_ERROR;
1631
+ break;
1632
+ }
1633
+ const isSignatureValid = this._challenge && (0, import_crypto2.verify)(this._challenge, Buffer.from(signedChallenge ?? []), this.invitation.guestKeypair.publicKey.asBuffer());
1634
+ if (isSignatureValid) {
1635
+ this.authenticationPassed = true;
1636
+ } else {
1637
+ status = import_invitations2.AuthenticationResponse.Status.INVALID_SIGNATURE;
1638
+ }
1639
+ break;
1640
+ }
1616
1641
  default: {
1617
1642
  import_log5.log.error("invalid authentication method", {
1618
1643
  authMethod: this.invitation.authMethod
1619
1644
  }, {
1620
1645
  F: __dxlog_file6,
1621
- L: 149,
1646
+ L: 176,
1622
1647
  S: this,
1623
1648
  C: (f, a) => f(...a)
1624
1649
  });
@@ -1633,7 +1658,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1633
1658
  }
1634
1659
  }), {
1635
1660
  F: __dxlog_file6,
1636
- L: 155,
1661
+ L: 182,
1637
1662
  S: this,
1638
1663
  C: (f, a) => f(...a)
1639
1664
  });
@@ -1647,14 +1672,14 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1647
1672
  id: traceId
1648
1673
  }), {
1649
1674
  F: __dxlog_file6,
1650
- L: 161,
1675
+ L: 188,
1651
1676
  S: this,
1652
1677
  C: (f, a) => f(...a)
1653
1678
  });
1654
1679
  try {
1655
1680
  (0, import_invariant6.invariant)(this.invitation, "Invitation is not set.", {
1656
1681
  F: __dxlog_file6,
1657
- L: 164,
1682
+ L: 191,
1658
1683
  S: this,
1659
1684
  A: [
1660
1685
  "this.invitation",
@@ -1669,7 +1694,7 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
1669
1694
  id: traceId
1670
1695
  }), {
1671
1696
  F: __dxlog_file6,
1672
- L: 172,
1697
+ L: 199,
1673
1698
  S: this,
1674
1699
  C: (f, a) => f(...a)
1675
1700
  });
@@ -1726,7 +1751,7 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1726
1751
  options: async (options) => {
1727
1752
  (0, import_invariant6.invariant)(!this._remoteOptions, "Remote options already set.", {
1728
1753
  F: __dxlog_file6,
1729
- L: 239,
1754
+ L: 266,
1730
1755
  S: this,
1731
1756
  A: [
1732
1757
  "!this._remoteOptions",
@@ -1753,7 +1778,7 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1753
1778
  try {
1754
1779
  (0, import_log5.log)("begin options", void 0, {
1755
1780
  F: __dxlog_file6,
1756
- L: 260,
1781
+ L: 287,
1757
1782
  S: this,
1758
1783
  C: (f, a) => f(...a)
1759
1784
  });
@@ -1765,7 +1790,7 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1765
1790
  }));
1766
1791
  (0, import_log5.log)("end options", void 0, {
1767
1792
  F: __dxlog_file6,
1768
- L: 263,
1793
+ L: 290,
1769
1794
  S: this,
1770
1795
  C: (f, a) => f(...a)
1771
1796
  });
@@ -1779,7 +1804,7 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1779
1804
  } catch (err) {
1780
1805
  (0, import_log5.log)("openError", err, {
1781
1806
  F: __dxlog_file6,
1782
- L: 273,
1807
+ L: 300,
1783
1808
  S: this,
1784
1809
  C: (f, a) => f(...a)
1785
1810
  });
@@ -1789,7 +1814,7 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
1789
1814
  async onClose() {
1790
1815
  (0, import_log5.log)("onClose", void 0, {
1791
1816
  F: __dxlog_file6,
1792
- L: 279,
1817
+ L: 306,
1793
1818
  S: this,
1794
1819
  C: (f, a) => f(...a)
1795
1820
  });
@@ -1805,49 +1830,7 @@ var InvitationsHandler = class {
1805
1830
  constructor(_networkManager) {
1806
1831
  this._networkManager = _networkManager;
1807
1832
  }
1808
- createInvitation(protocol, options) {
1809
- const { invitationId = import_keys5.PublicKey.random().toHex(), type = import_services3.Invitation.Type.INTERACTIVE, authMethod = import_services3.Invitation.AuthMethod.SHARED_SECRET, state = import_services3.Invitation.State.INIT, timeout = import_client_protocol2.INVITATION_TIMEOUT, swarmKey = import_keys5.PublicKey.random(), persistent = true, created = /* @__PURE__ */ new Date(), lifetime = 86400 } = options ?? {};
1810
- const authCode = options?.authCode ?? (authMethod === import_services3.Invitation.AuthMethod.SHARED_SECRET ? (0, import_credentials7.generatePasscode)(import_client_protocol2.AUTHENTICATION_CODE_LENGTH) : void 0);
1811
- (0, import_invariant5.invariant)(protocol, void 0, {
1812
- F: __dxlog_file7,
1813
- L: 84,
1814
- S: this,
1815
- A: [
1816
- "protocol",
1817
- ""
1818
- ]
1819
- });
1820
- const invitation = {
1821
- invitationId,
1822
- type,
1823
- authMethod,
1824
- state,
1825
- swarmKey,
1826
- authCode,
1827
- timeout,
1828
- persistent,
1829
- created,
1830
- lifetime,
1831
- ...protocol.getInvitationContext()
1832
- };
1833
- const stream = new import_async7.PushStream();
1834
- const ctx = new import_context4.Context({
1835
- onError: (err) => {
1836
- stream.error(err);
1837
- void ctx.dispose();
1838
- }
1839
- });
1840
- ctx.onDispose(() => {
1841
- (0, import_log4.log)("complete", {
1842
- ...protocol.toJSON()
1843
- }, {
1844
- F: __dxlog_file7,
1845
- L: 109,
1846
- S: this,
1847
- C: (f, a) => f(...a)
1848
- });
1849
- stream.complete();
1850
- });
1833
+ handleInvitationFlow(ctx, stream, protocol, invitation) {
1851
1834
  const createExtension = () => {
1852
1835
  const extension = new InvitationHostExtension({
1853
1836
  onStateUpdate: (invitation2) => {
@@ -1856,8 +1839,8 @@ var InvitationsHandler = class {
1856
1839
  state: import_services3.Invitation.State.READY_FOR_AUTHENTICATION
1857
1840
  });
1858
1841
  },
1859
- resolveInvitation: async ({ invitationId: invitationId2 }) => {
1860
- if (invitationId2 && invitationId2 !== invitation.invitationId) {
1842
+ resolveInvitation: async ({ invitationId }) => {
1843
+ if (invitationId && invitationId !== invitation.invitationId) {
1861
1844
  return void 0;
1862
1845
  }
1863
1846
  return invitation;
@@ -1867,14 +1850,14 @@ var InvitationsHandler = class {
1867
1850
  const deviceKey = admissionRequest.device?.deviceKey ?? admissionRequest.space?.deviceKey;
1868
1851
  (0, import_invariant5.invariant)(deviceKey, void 0, {
1869
1852
  F: __dxlog_file7,
1870
- L: 130,
1853
+ L: 87,
1871
1854
  S: this,
1872
1855
  A: [
1873
1856
  "deviceKey",
1874
1857
  ""
1875
1858
  ]
1876
1859
  });
1877
- const admissionResponse = await protocol.admit(admissionRequest, extension.guestProfile);
1860
+ const admissionResponse = await protocol.admit(invitation, admissionRequest, extension.guestProfile);
1878
1861
  extension.completedTrigger.wake(deviceKey);
1879
1862
  return admissionResponse;
1880
1863
  } catch (err) {
@@ -1890,7 +1873,7 @@ var InvitationsHandler = class {
1890
1873
  id: traceId
1891
1874
  }), {
1892
1875
  F: __dxlog_file7,
1893
- L: 148,
1876
+ L: 105,
1894
1877
  S: this,
1895
1878
  C: (f, a) => f(...a)
1896
1879
  });
@@ -1898,7 +1881,7 @@ var InvitationsHandler = class {
1898
1881
  ...protocol.toJSON()
1899
1882
  }, {
1900
1883
  F: __dxlog_file7,
1901
- L: 149,
1884
+ L: 106,
1902
1885
  S: this,
1903
1886
  C: (f, a) => f(...a)
1904
1887
  });
@@ -1907,14 +1890,14 @@ var InvitationsHandler = class {
1907
1890
  state: import_services3.Invitation.State.CONNECTED
1908
1891
  });
1909
1892
  const deviceKey = await extension.completedTrigger.wait({
1910
- timeout
1893
+ timeout: invitation.timeout
1911
1894
  });
1912
1895
  (0, import_log4.log)("admitted guest", {
1913
1896
  guest: deviceKey,
1914
1897
  ...protocol.toJSON()
1915
1898
  }, {
1916
1899
  F: __dxlog_file7,
1917
- L: 152,
1900
+ L: 109,
1918
1901
  S: this,
1919
1902
  C: (f, a) => f(...a)
1920
1903
  });
@@ -1926,7 +1909,7 @@ var InvitationsHandler = class {
1926
1909
  id: traceId
1927
1910
  }), {
1928
1911
  F: __dxlog_file7,
1929
- L: 154,
1912
+ L: 111,
1930
1913
  S: this,
1931
1914
  C: (f, a) => f(...a)
1932
1915
  });
@@ -1936,7 +1919,7 @@ var InvitationsHandler = class {
1936
1919
  ...protocol.toJSON()
1937
1920
  }, {
1938
1921
  F: __dxlog_file7,
1939
- L: 157,
1922
+ L: 114,
1940
1923
  S: this,
1941
1924
  C: (f, a) => f(...a)
1942
1925
  });
@@ -1947,7 +1930,7 @@ var InvitationsHandler = class {
1947
1930
  } else {
1948
1931
  import_log4.log.error("failed", err, {
1949
1932
  F: __dxlog_file7,
1950
- L: 160,
1933
+ L: 117,
1951
1934
  S: this,
1952
1935
  C: (f, a) => f(...a)
1953
1936
  });
@@ -1958,12 +1941,12 @@ var InvitationsHandler = class {
1958
1941
  error: err
1959
1942
  }), {
1960
1943
  F: __dxlog_file7,
1961
- L: 163,
1944
+ L: 120,
1962
1945
  S: this,
1963
1946
  C: (f, a) => f(...a)
1964
1947
  });
1965
1948
  } finally {
1966
- if (type !== import_services3.Invitation.Type.MULTIUSE) {
1949
+ if (!invitation.multiUse) {
1967
1950
  await swarmConnection.close();
1968
1951
  await ctx.dispose();
1969
1952
  }
@@ -1979,7 +1962,7 @@ var InvitationsHandler = class {
1979
1962
  ...protocol.toJSON()
1980
1963
  }, {
1981
1964
  F: __dxlog_file7,
1982
- L: 178,
1965
+ L: 135,
1983
1966
  S: this,
1984
1967
  C: (f, a) => f(...a)
1985
1968
  });
@@ -1990,7 +1973,7 @@ var InvitationsHandler = class {
1990
1973
  } else {
1991
1974
  import_log4.log.error("failed", err, {
1992
1975
  F: __dxlog_file7,
1993
- L: 181,
1976
+ L: 138,
1994
1977
  S: this,
1995
1978
  C: (f, a) => f(...a)
1996
1979
  });
@@ -2000,11 +1983,11 @@ var InvitationsHandler = class {
2000
1983
  });
2001
1984
  return extension;
2002
1985
  };
2003
- if (invitation.lifetime && invitation.created && invitation.lifetime !== 0) {
1986
+ if (invitation.lifetime && invitation.created) {
2004
1987
  if (invitation.created.getTime() + invitation.lifetime * 1e3 < Date.now()) {
2005
1988
  import_log4.log.warn("invitation has already expired", void 0, {
2006
1989
  F: __dxlog_file7,
2007
- L: 192,
1990
+ L: 149,
2008
1991
  S: this,
2009
1992
  C: (f, a) => f(...a)
2010
1993
  });
@@ -2038,24 +2021,12 @@ var InvitationsHandler = class {
2038
2021
  state: import_services3.Invitation.State.CONNECTING
2039
2022
  });
2040
2023
  });
2041
- const observable = new import_client_protocol2.CancellableInvitation({
2042
- initialInvitation: invitation,
2043
- subscriber: stream.observable,
2044
- onCancel: async () => {
2045
- stream.next({
2046
- ...invitation,
2047
- state: import_services3.Invitation.State.CANCELLED
2048
- });
2049
- await ctx.dispose();
2050
- }
2051
- });
2052
- return observable;
2053
2024
  }
2054
2025
  acceptInvitation(protocol, invitation, deviceProfile) {
2055
2026
  const { timeout = import_client_protocol2.INVITATION_TIMEOUT } = invitation;
2056
2027
  (0, import_invariant5.invariant)(protocol, void 0, {
2057
2028
  F: __dxlog_file7,
2058
- L: 246,
2029
+ L: 191,
2059
2030
  S: this,
2060
2031
  A: [
2061
2032
  "protocol",
@@ -2065,7 +2036,7 @@ var InvitationsHandler = class {
2065
2036
  if (deviceProfile) {
2066
2037
  (0, import_invariant5.invariant)(invitation.kind === import_services3.Invitation.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
2067
2038
  F: __dxlog_file7,
2068
- L: 250,
2039
+ L: 194,
2069
2040
  S: this,
2070
2041
  A: [
2071
2042
  "invitation.kind === Invitation.Kind.DEVICE",
@@ -2080,7 +2051,7 @@ var InvitationsHandler = class {
2080
2051
  const setState = (newData) => {
2081
2052
  (0, import_invariant5.invariant)(newData.state !== void 0, void 0, {
2082
2053
  F: __dxlog_file7,
2083
- L: 261,
2054
+ L: 205,
2084
2055
  S: this,
2085
2056
  A: [
2086
2057
  "newData.state !== undefined",
@@ -2100,7 +2071,7 @@ var InvitationsHandler = class {
2100
2071
  ...protocol.toJSON()
2101
2072
  }, {
2102
2073
  F: __dxlog_file7,
2103
- L: 269,
2074
+ L: 213,
2104
2075
  S: this,
2105
2076
  C: (f, a) => f(...a)
2106
2077
  });
@@ -2110,7 +2081,7 @@ var InvitationsHandler = class {
2110
2081
  } else {
2111
2082
  import_log4.log.warn("auth failed", err, {
2112
2083
  F: __dxlog_file7,
2113
- L: 272,
2084
+ L: 216,
2114
2085
  S: this,
2115
2086
  C: (f, a) => f(...a)
2116
2087
  });
@@ -2124,7 +2095,7 @@ var InvitationsHandler = class {
2124
2095
  ...protocol.toJSON()
2125
2096
  }, {
2126
2097
  F: __dxlog_file7,
2127
- L: 280,
2098
+ L: 224,
2128
2099
  S: this,
2129
2100
  C: (f, a) => f(...a)
2130
2101
  });
@@ -2139,7 +2110,7 @@ var InvitationsHandler = class {
2139
2110
  currentState
2140
2111
  }, {
2141
2112
  F: __dxlog_file7,
2142
- L: 290,
2113
+ L: 234,
2143
2114
  S: this,
2144
2115
  C: (f, a) => f(...a)
2145
2116
  });
@@ -2154,7 +2125,7 @@ var InvitationsHandler = class {
2154
2125
  id: traceId
2155
2126
  }), {
2156
2127
  F: __dxlog_file7,
2157
- L: 299,
2128
+ L: 243,
2158
2129
  S: this,
2159
2130
  C: (f, a) => f(...a)
2160
2131
  });
@@ -2166,7 +2137,7 @@ var InvitationsHandler = class {
2166
2137
  ...protocol.toJSON()
2167
2138
  }, {
2168
2139
  F: __dxlog_file7,
2169
- L: 307,
2140
+ L: 251,
2170
2141
  S: this,
2171
2142
  C: (f, a) => f(...a)
2172
2143
  });
@@ -2177,7 +2148,7 @@ var InvitationsHandler = class {
2177
2148
  ...protocol.toJSON()
2178
2149
  }, {
2179
2150
  F: __dxlog_file7,
2180
- L: 311,
2151
+ L: 255,
2181
2152
  S: this,
2182
2153
  C: (f, a) => f(...a)
2183
2154
  });
@@ -2187,62 +2158,28 @@ var InvitationsHandler = class {
2187
2158
  response: introductionResponse
2188
2159
  }, {
2189
2160
  F: __dxlog_file7,
2190
- L: 315,
2161
+ L: 259,
2191
2162
  S: this,
2192
2163
  C: (f, a) => f(...a)
2193
2164
  });
2194
2165
  invitation.authMethod = introductionResponse.authMethod;
2195
2166
  if (isAuthenticationRequired(invitation)) {
2196
- for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
2197
- (0, import_log4.log)("guest waiting for authentication code...", void 0, {
2198
- F: __dxlog_file7,
2199
- L: 321,
2200
- S: this,
2201
- C: (f, a) => f(...a)
2202
- });
2203
- setState({
2204
- state: import_services3.Invitation.State.READY_FOR_AUTHENTICATION
2205
- });
2206
- const authCode = await authenticated.wait({
2207
- timeout
2208
- });
2209
- (0, import_log4.log)("sending authentication request", void 0, {
2210
- F: __dxlog_file7,
2211
- L: 325,
2212
- S: this,
2213
- C: (f, a) => f(...a)
2214
- });
2215
- setState({
2216
- state: import_services3.Invitation.State.AUTHENTICATING
2217
- });
2218
- const response = await extension.rpc.InvitationHostService.authenticate({
2219
- authCode
2220
- });
2221
- if (response.status === void 0 || response.status === import_invitations.AuthenticationResponse.Status.OK) {
2167
+ switch (invitation.authMethod) {
2168
+ case import_services3.Invitation.AuthMethod.SHARED_SECRET:
2169
+ await this._handleGuestOtpAuth(extension, setState, authenticated, {
2170
+ timeout
2171
+ });
2172
+ break;
2173
+ case import_services3.Invitation.AuthMethod.KNOWN_PUBLIC_KEY:
2174
+ await this._handleGuestKpkAuth(extension, setState, invitation, introductionResponse);
2222
2175
  break;
2223
- }
2224
- if (response.status === import_invitations.AuthenticationResponse.Status.INVALID_OTP) {
2225
- if (attempt === MAX_OTP_ATTEMPTS) {
2226
- throw new Error(`Maximum retry attempts: ${MAX_OTP_ATTEMPTS}`);
2227
- } else {
2228
- (0, import_log4.log)("retrying invalid code", {
2229
- attempt
2230
- }, {
2231
- F: __dxlog_file7,
2232
- L: 336,
2233
- S: this,
2234
- C: (f, a) => f(...a)
2235
- });
2236
- authenticated.reset();
2237
- }
2238
- }
2239
2176
  }
2240
2177
  }
2241
2178
  (0, import_log4.log)("request admission", {
2242
2179
  ...protocol.toJSON()
2243
2180
  }, {
2244
2181
  F: __dxlog_file7,
2245
- L: 344,
2182
+ L: 275,
2246
2183
  S: this,
2247
2184
  C: (f, a) => f(...a)
2248
2185
  });
@@ -2254,7 +2191,7 @@ var InvitationsHandler = class {
2254
2191
  ...protocol.toJSON()
2255
2192
  }, {
2256
2193
  F: __dxlog_file7,
2257
- L: 355,
2194
+ L: 286,
2258
2195
  S: this,
2259
2196
  C: (f, a) => f(...a)
2260
2197
  });
@@ -2267,7 +2204,7 @@ var InvitationsHandler = class {
2267
2204
  id: traceId
2268
2205
  }), {
2269
2206
  F: __dxlog_file7,
2270
- L: 357,
2207
+ L: 288,
2271
2208
  S: this,
2272
2209
  C: (f, a) => f(...a)
2273
2210
  });
@@ -2277,7 +2214,7 @@ var InvitationsHandler = class {
2277
2214
  ...protocol.toJSON()
2278
2215
  }, {
2279
2216
  F: __dxlog_file7,
2280
- L: 360,
2217
+ L: 291,
2281
2218
  S: this,
2282
2219
  C: (f, a) => f(...a)
2283
2220
  });
@@ -2287,7 +2224,7 @@ var InvitationsHandler = class {
2287
2224
  } else {
2288
2225
  (0, import_log4.log)("auth failed", err, {
2289
2226
  F: __dxlog_file7,
2290
- L: 363,
2227
+ L: 294,
2291
2228
  S: this,
2292
2229
  C: (f, a) => f(...a)
2293
2230
  });
@@ -2298,7 +2235,7 @@ var InvitationsHandler = class {
2298
2235
  error: err
2299
2236
  }), {
2300
2237
  F: __dxlog_file7,
2301
- L: 366,
2238
+ L: 297,
2302
2239
  S: this,
2303
2240
  C: (f, a) => f(...a)
2304
2241
  });
@@ -2316,7 +2253,7 @@ var InvitationsHandler = class {
2316
2253
  ...protocol.toJSON()
2317
2254
  }, {
2318
2255
  F: __dxlog_file7,
2319
- L: 377,
2256
+ L: 308,
2320
2257
  S: this,
2321
2258
  C: (f, a) => f(...a)
2322
2259
  });
@@ -2326,7 +2263,7 @@ var InvitationsHandler = class {
2326
2263
  } else {
2327
2264
  (0, import_log4.log)("auth failed", err, {
2328
2265
  F: __dxlog_file7,
2329
- L: 380,
2266
+ L: 311,
2330
2267
  S: this,
2331
2268
  C: (f, a) => f(...a)
2332
2269
  });
@@ -2343,7 +2280,7 @@ var InvitationsHandler = class {
2343
2280
  } else {
2344
2281
  (0, import_invariant5.invariant)(invitation.swarmKey, void 0, {
2345
2282
  F: __dxlog_file7,
2346
- L: 394,
2283
+ L: 325,
2347
2284
  S: this,
2348
2285
  A: [
2349
2286
  "invitation.swarmKey",
@@ -2381,198 +2318,110 @@ var InvitationsHandler = class {
2381
2318
  });
2382
2319
  return observable;
2383
2320
  }
2321
+ async _handleGuestOtpAuth(extension, setState, authenticated, options) {
2322
+ for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
2323
+ (0, import_log4.log)("guest waiting for authentication code...", void 0, {
2324
+ F: __dxlog_file7,
2325
+ L: 365,
2326
+ S: this,
2327
+ C: (f, a) => f(...a)
2328
+ });
2329
+ setState({
2330
+ state: import_services3.Invitation.State.READY_FOR_AUTHENTICATION
2331
+ });
2332
+ const authCode = await authenticated.wait(options);
2333
+ (0, import_log4.log)("sending authentication request", void 0, {
2334
+ F: __dxlog_file7,
2335
+ L: 369,
2336
+ S: this,
2337
+ C: (f, a) => f(...a)
2338
+ });
2339
+ setState({
2340
+ state: import_services3.Invitation.State.AUTHENTICATING
2341
+ });
2342
+ const response = await extension.rpc.InvitationHostService.authenticate({
2343
+ authCode
2344
+ });
2345
+ if (response.status === void 0 || response.status === import_invitations.AuthenticationResponse.Status.OK) {
2346
+ break;
2347
+ }
2348
+ if (response.status === import_invitations.AuthenticationResponse.Status.INVALID_OTP) {
2349
+ if (attempt === MAX_OTP_ATTEMPTS) {
2350
+ throw new Error(`Maximum retry attempts: ${MAX_OTP_ATTEMPTS}`);
2351
+ } else {
2352
+ (0, import_log4.log)("retrying invalid code", {
2353
+ attempt
2354
+ }, {
2355
+ F: __dxlog_file7,
2356
+ L: 380,
2357
+ S: this,
2358
+ C: (f, a) => f(...a)
2359
+ });
2360
+ authenticated.reset();
2361
+ }
2362
+ }
2363
+ }
2364
+ }
2365
+ async _handleGuestKpkAuth(extension, setState, invitation, introductionResponse) {
2366
+ if (invitation.guestKeypair?.privateKey == null) {
2367
+ throw new Error("keypair missing in the invitation");
2368
+ }
2369
+ if (introductionResponse.challenge == null) {
2370
+ throw new Error("challenge missing in the introduction");
2371
+ }
2372
+ (0, import_log4.log)("sending authentication request", void 0, {
2373
+ F: __dxlog_file7,
2374
+ L: 399,
2375
+ S: this,
2376
+ C: (f, a) => f(...a)
2377
+ });
2378
+ setState({
2379
+ state: import_services3.Invitation.State.AUTHENTICATING
2380
+ });
2381
+ const signature = (0, import_crypto.sign)(Buffer.from(introductionResponse.challenge), invitation.guestKeypair.privateKey);
2382
+ const response = await extension.rpc.InvitationHostService.authenticate({
2383
+ signedChallenge: signature
2384
+ });
2385
+ if (response.status !== import_invitations.AuthenticationResponse.Status.OK) {
2386
+ throw new Error(`Authentication failed with code: ${response.status}`);
2387
+ }
2388
+ }
2384
2389
  };
2385
- var invitationExpired = (invitation) => {
2386
- return invitation.created && invitation.lifetime && invitation.lifetime !== 0 && invitation.created.getTime() + invitation.lifetime * 1e3 < Date.now();
2390
+ var createAdmissionKeypair = () => {
2391
+ const keypair = (0, import_crypto.createKeyPair)();
2392
+ return {
2393
+ publicKey: import_keys5.PublicKey.from(keypair.publicKey),
2394
+ privateKey: keypair.secretKey
2395
+ };
2387
2396
  };
2388
- var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-service.ts";
2389
2397
  var InvitationsServiceImpl = class {
2390
- constructor(_invitationsHandler, _getHandler, _metadataStore) {
2391
- this._invitationsHandler = _invitationsHandler;
2392
- this._getHandler = _getHandler;
2393
- this._metadataStore = _metadataStore;
2394
- this._createInvitations = /* @__PURE__ */ new Map();
2395
- this._acceptInvitations = /* @__PURE__ */ new Map();
2396
- this._invitationCreated = new import_async9.Event();
2397
- this._invitationAccepted = new import_async9.Event();
2398
- this._removedCreated = new import_async9.Event();
2399
- this._removedAccepted = new import_async9.Event();
2400
- this._saved = new import_async9.Event();
2401
- this._persistentInvitationsLoadedEvent = new import_async9.Event();
2402
- this._persistentInvitationsLoaded = false;
2398
+ constructor(_invitationsManager) {
2399
+ this._invitationsManager = _invitationsManager;
2403
2400
  }
2404
2401
  // TODO(burdon): Guest/host label.
2405
2402
  getLoggingContext() {
2406
2403
  return {};
2407
2404
  }
2408
2405
  createInvitation(options) {
2409
- let invitation;
2410
- const savePersistentInvitationCtx = new import_context6.Context();
2411
- const existingInvitation = this._createInvitations.get(options.invitationId);
2412
- if (existingInvitation) {
2413
- invitation = existingInvitation;
2414
- } else {
2415
- const handler = this._getHandler(options);
2416
- invitation = this._invitationsHandler.createInvitation(handler, options);
2417
- this._createInvitations.set(invitation.get().invitationId, invitation);
2418
- this._invitationCreated.emit(invitation.get());
2419
- }
2420
2406
  return new import_codec_protobuf8.Stream(({ next, close }) => {
2421
- if (invitation.get().persistent) {
2422
- (0, import_async9.scheduleTask)(savePersistentInvitationCtx, async () => {
2423
- try {
2424
- await this._metadataStore.addInvitation(invitation.get());
2425
- this._saved.emit(invitation.get());
2426
- } catch (err) {
2427
- close(err);
2428
- }
2429
- });
2430
- }
2431
- invitation.subscribe((invitation2) => {
2432
- next(invitation2);
2433
- }, async (err) => {
2434
- await savePersistentInvitationCtx.dispose();
2435
- close(err);
2436
- }, async () => {
2437
- close();
2438
- if (invitation.get().persistent) {
2439
- await savePersistentInvitationCtx.dispose();
2440
- await this._metadataStore.removeInvitation(invitation.get().invitationId);
2441
- }
2442
- this._createInvitations.delete(invitation.get().invitationId);
2443
- if (invitation.get().type !== import_services5.Invitation.Type.MULTIUSE) {
2444
- this._removedCreated.emit(invitation.get());
2445
- }
2446
- });
2407
+ void this._invitationsManager.createInvitation(options).then((invitation) => invitation.subscribe(next, close, close)).catch(close);
2447
2408
  });
2448
2409
  }
2449
- async loadPersistentInvitations() {
2450
- const persistentInvitations = this._metadataStore.getInvitations();
2451
- const freshInvitations = persistentInvitations.filter(async (invitation) => !invitationExpired(invitation));
2452
- const cInvitations = freshInvitations.map((persistentInvitation) => {
2453
- (0, import_invariant7.invariant)(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
2454
- F: __dxlog_file8,
2455
- L: 109,
2456
- S: this,
2457
- A: [
2458
- "!this._createInvitations.get(persistentInvitation.invitationId)",
2459
- "'invitation already exists'"
2460
- ]
2461
- });
2462
- const handler = this._getHandler(persistentInvitation);
2463
- const invitation = this._invitationsHandler.createInvitation(handler, persistentInvitation);
2464
- this._createInvitations.set(invitation.get().invitationId, invitation);
2465
- this._invitationCreated.emit(invitation.get());
2466
- return persistentInvitation;
2467
- });
2468
- this._persistentInvitationsLoadedEvent.emit();
2469
- this._persistentInvitationsLoaded = true;
2470
- return {
2471
- invitations: cInvitations
2472
- };
2473
- }
2474
- acceptInvitation({ invitation: options, deviceProfile }) {
2475
- let invitation;
2476
- if (deviceProfile) {
2477
- (0, import_invariant7.invariant)(options.kind === import_services5.Invitation.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
2478
- F: __dxlog_file8,
2479
- L: 127,
2480
- S: this,
2481
- A: [
2482
- "options.kind === Invitation.Kind.DEVICE",
2483
- "'deviceProfile provided for non-device invitation'"
2484
- ]
2485
- });
2486
- }
2487
- const existingInvitation = this._acceptInvitations.get(options.invitationId);
2488
- if (existingInvitation) {
2489
- invitation = existingInvitation;
2490
- } else {
2491
- const handler = this._getHandler(options);
2492
- invitation = this._invitationsHandler.acceptInvitation(handler, options, deviceProfile);
2493
- this._acceptInvitations.set(invitation.get().invitationId, invitation);
2494
- this._invitationAccepted.emit(invitation.get());
2495
- }
2410
+ acceptInvitation(request) {
2411
+ const invitation = this._invitationsManager.acceptInvitation(request);
2496
2412
  return new import_codec_protobuf8.Stream(({ next, close }) => {
2497
- invitation.subscribe((invitation2) => {
2498
- next(invitation2);
2499
- }, (err) => {
2500
- close(err);
2501
- }, () => {
2502
- close();
2503
- this._acceptInvitations.delete(invitation.get().invitationId);
2504
- if (invitation.get().type !== import_services5.Invitation.Type.MULTIUSE) {
2505
- this._removedAccepted.emit(invitation.get());
2506
- }
2507
- });
2413
+ invitation.subscribe(next, close, close);
2508
2414
  });
2509
2415
  }
2510
- async authenticate({ invitationId, authCode }) {
2511
- (0, import_log6.log)("authenticating...", void 0, {
2512
- F: __dxlog_file8,
2513
- L: 160,
2514
- S: this,
2515
- C: (f, a) => f(...a)
2516
- });
2517
- (0, import_invariant7.invariant)(invitationId, void 0, {
2518
- F: __dxlog_file8,
2519
- L: 161,
2520
- S: this,
2521
- A: [
2522
- "invitationId",
2523
- ""
2524
- ]
2525
- });
2526
- const observable = this._acceptInvitations.get(invitationId);
2527
- if (!observable) {
2528
- import_log6.log.warn("invalid invitation", {
2529
- invitationId
2530
- }, {
2531
- F: __dxlog_file8,
2532
- L: 164,
2533
- S: this,
2534
- C: (f, a) => f(...a)
2535
- });
2536
- } else {
2537
- await observable.authenticate(authCode);
2538
- }
2416
+ async authenticate(request) {
2417
+ return this._invitationsManager.authenticate(request);
2539
2418
  }
2540
- async cancelInvitation({ invitationId }) {
2541
- (0, import_log6.log)("cancelInvitation...", {
2542
- invitationId
2543
- }, {
2544
- F: __dxlog_file8,
2545
- L: 171,
2546
- S: this,
2547
- C: (f, a) => f(...a)
2548
- });
2549
- (0, import_invariant7.invariant)(invitationId, void 0, {
2550
- F: __dxlog_file8,
2551
- L: 172,
2552
- S: this,
2553
- A: [
2554
- "invitationId",
2555
- ""
2556
- ]
2557
- });
2558
- const created = this._createInvitations.get(invitationId);
2559
- const accepted = this._acceptInvitations.get(invitationId);
2560
- if (created) {
2561
- await created.cancel();
2562
- this._createInvitations.delete(invitationId);
2563
- this._removedCreated.emit(created.get());
2564
- if (created.get().persistent) {
2565
- await this._metadataStore.removeInvitation(created.get().invitationId);
2566
- }
2567
- } else if (accepted) {
2568
- await accepted.cancel();
2569
- this._acceptInvitations.delete(invitationId);
2570
- this._removedAccepted.emit(accepted.get());
2571
- }
2419
+ async cancelInvitation(request) {
2420
+ return this._invitationsManager.cancelInvitation(request);
2572
2421
  }
2573
2422
  queryInvitations() {
2574
2423
  return new import_codec_protobuf8.Stream(({ next, ctx }) => {
2575
- this._invitationCreated.on(ctx, (invitation) => {
2424
+ this._invitationsManager.invitationCreated.on(ctx, (invitation) => {
2576
2425
  next({
2577
2426
  action: import_services5.QueryInvitationsResponse.Action.ADDED,
2578
2427
  type: import_services5.QueryInvitationsResponse.Type.CREATED,
@@ -2581,7 +2430,7 @@ var InvitationsServiceImpl = class {
2581
2430
  ]
2582
2431
  });
2583
2432
  });
2584
- this._invitationAccepted.on(ctx, (invitation) => {
2433
+ this._invitationsManager.invitationAccepted.on(ctx, (invitation) => {
2585
2434
  next({
2586
2435
  action: import_services5.QueryInvitationsResponse.Action.ADDED,
2587
2436
  type: import_services5.QueryInvitationsResponse.Type.ACCEPTED,
@@ -2590,7 +2439,7 @@ var InvitationsServiceImpl = class {
2590
2439
  ]
2591
2440
  });
2592
2441
  });
2593
- this._removedCreated.on(ctx, (invitation) => {
2442
+ this._invitationsManager.removedCreated.on(ctx, (invitation) => {
2594
2443
  next({
2595
2444
  action: import_services5.QueryInvitationsResponse.Action.REMOVED,
2596
2445
  type: import_services5.QueryInvitationsResponse.Type.CREATED,
@@ -2599,7 +2448,7 @@ var InvitationsServiceImpl = class {
2599
2448
  ]
2600
2449
  });
2601
2450
  });
2602
- this._removedAccepted.on(ctx, (invitation) => {
2451
+ this._invitationsManager.removedAccepted.on(ctx, (invitation) => {
2603
2452
  next({
2604
2453
  action: import_services5.QueryInvitationsResponse.Action.REMOVED,
2605
2454
  type: import_services5.QueryInvitationsResponse.Type.ACCEPTED,
@@ -2608,7 +2457,7 @@ var InvitationsServiceImpl = class {
2608
2457
  ]
2609
2458
  });
2610
2459
  });
2611
- this._saved.on(ctx, (invitation) => {
2460
+ this._invitationsManager.saved.on(ctx, (invitation) => {
2612
2461
  next({
2613
2462
  action: import_services5.QueryInvitationsResponse.Action.SAVED,
2614
2463
  type: import_services5.QueryInvitationsResponse.Type.CREATED,
@@ -2620,32 +2469,25 @@ var InvitationsServiceImpl = class {
2620
2469
  next({
2621
2470
  action: import_services5.QueryInvitationsResponse.Action.ADDED,
2622
2471
  type: import_services5.QueryInvitationsResponse.Type.CREATED,
2623
- invitations: Array.from(this._createInvitations.values()).map((invitation) => invitation.get()),
2472
+ invitations: this._invitationsManager.getCreatedInvitations(),
2624
2473
  existing: true
2625
2474
  });
2626
2475
  next({
2627
2476
  action: import_services5.QueryInvitationsResponse.Action.ADDED,
2628
2477
  type: import_services5.QueryInvitationsResponse.Type.ACCEPTED,
2629
- invitations: Array.from(this._acceptInvitations.values()).map((invitation) => invitation.get()),
2478
+ invitations: this._invitationsManager.getAcceptedInvitations(),
2630
2479
  existing: true
2631
2480
  });
2632
- if (this._persistentInvitationsLoaded) {
2481
+ this._invitationsManager.onPersistentInvitationsLoaded(ctx, () => {
2633
2482
  next({
2634
2483
  action: import_services5.QueryInvitationsResponse.Action.LOAD_COMPLETE,
2635
2484
  type: import_services5.QueryInvitationsResponse.Type.CREATED
2636
2485
  });
2637
- } else {
2638
- this._persistentInvitationsLoadedEvent.on(ctx, () => {
2639
- next({
2640
- action: import_services5.QueryInvitationsResponse.Action.LOAD_COMPLETE,
2641
- type: import_services5.QueryInvitationsResponse.Type.CREATED
2642
- });
2643
- });
2644
- }
2486
+ });
2645
2487
  });
2646
2488
  }
2647
2489
  };
2648
- var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
2490
+ var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
2649
2491
  var SpaceInvitationProtocol = class {
2650
2492
  constructor(_spaceManager, _signingContext, _keyring, _spaceKey) {
2651
2493
  this._spaceManager = _spaceManager;
@@ -2665,10 +2507,10 @@ var SpaceInvitationProtocol = class {
2665
2507
  spaceKey: this._spaceKey
2666
2508
  };
2667
2509
  }
2668
- async admit(request, guestProfile) {
2669
- (0, import_invariant8.invariant)(this._spaceKey, void 0, {
2670
- F: __dxlog_file9,
2671
- L: 47,
2510
+ async admit(invitation, request, guestProfile) {
2511
+ (0, import_invariant7.invariant)(this._spaceKey, void 0, {
2512
+ F: __dxlog_file8,
2513
+ L: 55,
2672
2514
  S: this,
2673
2515
  A: [
2674
2516
  "this._spaceKey",
@@ -2676,18 +2518,18 @@ var SpaceInvitationProtocol = class {
2676
2518
  ]
2677
2519
  });
2678
2520
  const space = await this._spaceManager.spaces.get(this._spaceKey);
2679
- (0, import_invariant8.invariant)(space, void 0, {
2680
- F: __dxlog_file9,
2681
- L: 49,
2521
+ (0, import_invariant7.invariant)(space, void 0, {
2522
+ F: __dxlog_file8,
2523
+ L: 57,
2682
2524
  S: this,
2683
2525
  A: [
2684
2526
  "space",
2685
2527
  ""
2686
2528
  ]
2687
2529
  });
2688
- (0, import_invariant8.invariant)(request.space, void 0, {
2689
- F: __dxlog_file9,
2690
- L: 51,
2530
+ (0, import_invariant7.invariant)(request.space, void 0, {
2531
+ F: __dxlog_file8,
2532
+ L: 59,
2691
2533
  S: this,
2692
2534
  A: [
2693
2535
  "request.space",
@@ -2695,19 +2537,19 @@ var SpaceInvitationProtocol = class {
2695
2537
  ]
2696
2538
  });
2697
2539
  const { identityKey, deviceKey } = request.space;
2698
- (0, import_log7.log)("writing guest credentials", {
2540
+ (0, import_log6.log)("writing guest credentials", {
2699
2541
  host: this._signingContext.deviceKey,
2700
2542
  guest: deviceKey
2701
2543
  }, {
2702
- F: __dxlog_file9,
2703
- L: 54,
2544
+ F: __dxlog_file8,
2545
+ L: 62,
2704
2546
  S: this,
2705
2547
  C: (f, a) => f(...a)
2706
2548
  });
2707
- const credentials = await (0, import_credentials8.createAdmissionCredentials)(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, guestProfile);
2708
- (0, import_invariant8.invariant)(credentials[0].credential, void 0, {
2709
- F: __dxlog_file9,
2710
- L: 65,
2549
+ const credentials = await (0, import_credentials7.createAdmissionCredentials)(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, guestProfile, invitation.delegationCredentialId);
2550
+ (0, import_invariant7.invariant)(credentials[0].credential, void 0, {
2551
+ F: __dxlog_file8,
2552
+ L: 74,
2711
2553
  S: this,
2712
2554
  A: [
2713
2555
  "credentials[0].credential",
@@ -2715,22 +2557,85 @@ var SpaceInvitationProtocol = class {
2715
2557
  ]
2716
2558
  });
2717
2559
  const spaceMemberCredential = credentials[0].credential.credential;
2718
- (0, import_invariant8.invariant)((0, import_credentials8.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2719
- F: __dxlog_file9,
2720
- L: 67,
2560
+ (0, import_invariant7.invariant)((0, import_credentials7.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2561
+ F: __dxlog_file8,
2562
+ L: 76,
2563
+ S: this,
2564
+ A: [
2565
+ "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
2566
+ ""
2567
+ ]
2568
+ });
2569
+ await (0, import_feed_store3.writeMessages)(space.inner.controlPipeline.writer, credentials);
2570
+ return {
2571
+ space: {
2572
+ credential: spaceMemberCredential,
2573
+ controlTimeframe: space.inner.controlPipeline.state.timeframe
2574
+ }
2575
+ };
2576
+ }
2577
+ async delegate(invitation) {
2578
+ (0, import_invariant7.invariant)(this._spaceKey, void 0, {
2579
+ F: __dxlog_file8,
2580
+ L: 89,
2581
+ S: this,
2582
+ A: [
2583
+ "this._spaceKey",
2584
+ ""
2585
+ ]
2586
+ });
2587
+ const space = await this._spaceManager.spaces.get(this._spaceKey);
2588
+ (0, import_invariant7.invariant)(space, void 0, {
2589
+ F: __dxlog_file8,
2590
+ L: 91,
2591
+ S: this,
2592
+ A: [
2593
+ "space",
2594
+ ""
2595
+ ]
2596
+ });
2597
+ if (invitation.authMethod === import_services6.Invitation.AuthMethod.KNOWN_PUBLIC_KEY) {
2598
+ (0, import_invariant7.invariant)(invitation.guestKeypair?.publicKey, void 0, {
2599
+ F: __dxlog_file8,
2600
+ L: 93,
2601
+ S: this,
2602
+ A: [
2603
+ "invitation.guestKeypair?.publicKey",
2604
+ ""
2605
+ ]
2606
+ });
2607
+ }
2608
+ (0, import_log6.log)("writing delegate space invitation", {
2609
+ host: this._signingContext.deviceKey,
2610
+ id: invitation.invitationId
2611
+ }, {
2612
+ F: __dxlog_file8,
2613
+ L: 96,
2614
+ S: this,
2615
+ C: (f, a) => f(...a)
2616
+ });
2617
+ const credential = await (0, import_credentials7.createDelegatedSpaceInvitationCredential)(this._signingContext.credentialSigner, space.key, {
2618
+ invitationId: invitation.invitationId,
2619
+ authMethod: invitation.authMethod,
2620
+ swarmKey: invitation.swarmKey,
2621
+ role: import_credentials8.SpaceMember.Role.ADMIN,
2622
+ expiresOn: invitation.lifetime ? new Date((invitation.created?.getTime() ?? Date.now()) + invitation.lifetime) : void 0,
2623
+ multiUse: invitation.multiUse ?? false,
2624
+ guestKey: invitation.authMethod === import_services6.Invitation.AuthMethod.KNOWN_PUBLIC_KEY ? invitation.guestKeypair.publicKey : void 0
2625
+ });
2626
+ (0, import_invariant7.invariant)(credential.credential, void 0, {
2627
+ F: __dxlog_file8,
2628
+ L: 116,
2721
2629
  S: this,
2722
2630
  A: [
2723
- "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
2631
+ "credential.credential",
2724
2632
  ""
2725
2633
  ]
2726
2634
  });
2727
- await (0, import_feed_store3.writeMessages)(space.inner.controlPipeline.writer, credentials);
2728
- return {
2729
- space: {
2730
- credential: spaceMemberCredential,
2731
- controlTimeframe: space.inner.controlPipeline.state.timeframe
2732
- }
2733
- };
2635
+ await (0, import_feed_store3.writeMessages)(space.inner.controlPipeline.writer, [
2636
+ credential
2637
+ ]);
2638
+ return credential.credential.credential.id;
2734
2639
  }
2735
2640
  checkInvitation(invitation) {
2736
2641
  if (invitation.spaceKey && this._spaceManager.spaces.has(invitation.spaceKey)) {
@@ -2755,9 +2660,9 @@ var SpaceInvitationProtocol = class {
2755
2660
  };
2756
2661
  }
2757
2662
  async accept(response) {
2758
- (0, import_invariant8.invariant)(response.space, void 0, {
2759
- F: __dxlog_file9,
2760
- L: 107,
2663
+ (0, import_invariant7.invariant)(response.space, void 0, {
2664
+ F: __dxlog_file8,
2665
+ L: 149,
2761
2666
  S: this,
2762
2667
  A: [
2763
2668
  "response.space",
@@ -2765,19 +2670,19 @@ var SpaceInvitationProtocol = class {
2765
2670
  ]
2766
2671
  });
2767
2672
  const { credential, controlTimeframe, dataTimeframe } = response.space;
2768
- const assertion = (0, import_credentials8.getCredentialAssertion)(credential);
2769
- (0, import_invariant8.invariant)(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
2770
- F: __dxlog_file9,
2771
- L: 110,
2673
+ const assertion = (0, import_credentials7.getCredentialAssertion)(credential);
2674
+ (0, import_invariant7.invariant)(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
2675
+ F: __dxlog_file8,
2676
+ L: 152,
2772
2677
  S: this,
2773
2678
  A: [
2774
2679
  "assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
2775
2680
  "'Invalid credential'"
2776
2681
  ]
2777
2682
  });
2778
- (0, import_invariant8.invariant)(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
2779
- F: __dxlog_file9,
2780
- L: 111,
2683
+ (0, import_invariant7.invariant)(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
2684
+ F: __dxlog_file8,
2685
+ L: 153,
2781
2686
  S: this,
2782
2687
  A: [
2783
2688
  "credential.subject.id.equals(this._signingContext.identityKey)",
@@ -2799,6 +2704,284 @@ var SpaceInvitationProtocol = class {
2799
2704
  };
2800
2705
  }
2801
2706
  };
2707
+ var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts";
2708
+ var InvitationsManager = class {
2709
+ constructor(_invitationsHandler, _getHandler, _metadataStore) {
2710
+ this._invitationsHandler = _invitationsHandler;
2711
+ this._getHandler = _getHandler;
2712
+ this._metadataStore = _metadataStore;
2713
+ this._createInvitations = /* @__PURE__ */ new Map();
2714
+ this._acceptInvitations = /* @__PURE__ */ new Map();
2715
+ this.invitationCreated = new import_async9.Event();
2716
+ this.invitationAccepted = new import_async9.Event();
2717
+ this.removedCreated = new import_async9.Event();
2718
+ this.removedAccepted = new import_async9.Event();
2719
+ this.saved = new import_async9.Event();
2720
+ this._persistentInvitationsLoadedEvent = new import_async9.Event();
2721
+ this._persistentInvitationsLoaded = false;
2722
+ }
2723
+ async createInvitation(options) {
2724
+ if (options.invitationId) {
2725
+ const existingInvitation = this._createInvitations.get(options.invitationId);
2726
+ if (existingInvitation) {
2727
+ return existingInvitation;
2728
+ }
2729
+ }
2730
+ const handler = this._getHandler(options);
2731
+ const invitation = this._createInvitation(handler, options);
2732
+ const { ctx, stream, observableInvitation } = this._createObservableInvitation(handler, invitation);
2733
+ this._createInvitations.set(invitation.invitationId, observableInvitation);
2734
+ this.invitationCreated.emit(invitation);
2735
+ this._onInvitationComplete(observableInvitation, async () => {
2736
+ this._createInvitations.delete(observableInvitation.get().invitationId);
2737
+ this.removedCreated.emit(observableInvitation.get());
2738
+ if (observableInvitation.get().persistent) {
2739
+ await this._safeDeleteInvitation(observableInvitation.get());
2740
+ }
2741
+ });
2742
+ try {
2743
+ await this._persistIfRequired(handler, stream, invitation);
2744
+ } catch (err) {
2745
+ import_log7.log.catch(err, void 0, {
2746
+ F: __dxlog_file9,
2747
+ L: 76,
2748
+ S: this,
2749
+ C: (f, a) => f(...a)
2750
+ });
2751
+ await observableInvitation.cancel();
2752
+ return observableInvitation;
2753
+ }
2754
+ this._invitationsHandler.handleInvitationFlow(ctx, stream, handler, observableInvitation.get());
2755
+ return observableInvitation;
2756
+ }
2757
+ async loadPersistentInvitations() {
2758
+ if (this._persistentInvitationsLoaded) {
2759
+ const invitations = this.getCreatedInvitations().filter((i) => i.persistent);
2760
+ return {
2761
+ invitations
2762
+ };
2763
+ }
2764
+ try {
2765
+ const persistentInvitations = this._metadataStore.getInvitations();
2766
+ const freshInvitations = persistentInvitations.filter((invitation) => !(0, import_echo_pipeline.hasInvitationExpired)(invitation));
2767
+ const loadTasks = freshInvitations.map((persistentInvitation) => {
2768
+ (0, import_invariant8.invariant)(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
2769
+ F: __dxlog_file9,
2770
+ L: 97,
2771
+ S: this,
2772
+ A: [
2773
+ "!this._createInvitations.get(persistentInvitation.invitationId)",
2774
+ "'invitation already exists'"
2775
+ ]
2776
+ });
2777
+ return this.createInvitation({
2778
+ ...persistentInvitation,
2779
+ persistent: false
2780
+ });
2781
+ });
2782
+ const cInvitations = await Promise.all(loadTasks);
2783
+ return {
2784
+ invitations: cInvitations.map((invitation) => invitation.get())
2785
+ };
2786
+ } catch (err) {
2787
+ import_log7.log.catch(err, void 0, {
2788
+ F: __dxlog_file9,
2789
+ L: 104,
2790
+ S: this,
2791
+ C: (f, a) => f(...a)
2792
+ });
2793
+ return {
2794
+ invitations: []
2795
+ };
2796
+ } finally {
2797
+ this._persistentInvitationsLoadedEvent.emit();
2798
+ this._persistentInvitationsLoaded = true;
2799
+ }
2800
+ }
2801
+ acceptInvitation(request) {
2802
+ const options = request.invitation;
2803
+ const existingInvitation = this._acceptInvitations.get(options.invitationId);
2804
+ if (existingInvitation) {
2805
+ return existingInvitation;
2806
+ }
2807
+ const handler = this._getHandler(options);
2808
+ const invitation = this._invitationsHandler.acceptInvitation(handler, options, request.deviceProfile);
2809
+ this._acceptInvitations.set(invitation.get().invitationId, invitation);
2810
+ this.invitationAccepted.emit(invitation.get());
2811
+ this._onInvitationComplete(invitation, () => {
2812
+ this._acceptInvitations.delete(invitation.get().invitationId);
2813
+ this.removedAccepted.emit(invitation.get());
2814
+ });
2815
+ return invitation;
2816
+ }
2817
+ async authenticate({ invitationId, authCode }) {
2818
+ (0, import_log7.log)("authenticating...", void 0, {
2819
+ F: __dxlog_file9,
2820
+ L: 133,
2821
+ S: this,
2822
+ C: (f, a) => f(...a)
2823
+ });
2824
+ (0, import_invariant8.invariant)(invitationId, void 0, {
2825
+ F: __dxlog_file9,
2826
+ L: 134,
2827
+ S: this,
2828
+ A: [
2829
+ "invitationId",
2830
+ ""
2831
+ ]
2832
+ });
2833
+ const observable = this._acceptInvitations.get(invitationId);
2834
+ if (!observable) {
2835
+ import_log7.log.warn("invalid invitation", {
2836
+ invitationId
2837
+ }, {
2838
+ F: __dxlog_file9,
2839
+ L: 137,
2840
+ S: this,
2841
+ C: (f, a) => f(...a)
2842
+ });
2843
+ } else {
2844
+ await observable.authenticate(authCode);
2845
+ }
2846
+ }
2847
+ async cancelInvitation({ invitationId }) {
2848
+ (0, import_log7.log)("cancelInvitation...", {
2849
+ invitationId
2850
+ }, {
2851
+ F: __dxlog_file9,
2852
+ L: 144,
2853
+ S: this,
2854
+ C: (f, a) => f(...a)
2855
+ });
2856
+ (0, import_invariant8.invariant)(invitationId, void 0, {
2857
+ F: __dxlog_file9,
2858
+ L: 145,
2859
+ S: this,
2860
+ A: [
2861
+ "invitationId",
2862
+ ""
2863
+ ]
2864
+ });
2865
+ const created = this._createInvitations.get(invitationId);
2866
+ if (created) {
2867
+ if (created.get().persistent) {
2868
+ await this._metadataStore.removeInvitation(invitationId);
2869
+ }
2870
+ await created.cancel();
2871
+ this._createInvitations.delete(invitationId);
2872
+ this.removedCreated.emit(created.get());
2873
+ return;
2874
+ }
2875
+ const accepted = this._acceptInvitations.get(invitationId);
2876
+ if (accepted) {
2877
+ await accepted.cancel();
2878
+ this._acceptInvitations.delete(invitationId);
2879
+ this.removedAccepted.emit(accepted.get());
2880
+ }
2881
+ }
2882
+ getCreatedInvitations() {
2883
+ return [
2884
+ ...this._createInvitations.values()
2885
+ ].map((i) => i.get());
2886
+ }
2887
+ getAcceptedInvitations() {
2888
+ return [
2889
+ ...this._acceptInvitations.values()
2890
+ ].map((i) => i.get());
2891
+ }
2892
+ onPersistentInvitationsLoaded(ctx, callback) {
2893
+ if (this._persistentInvitationsLoaded) {
2894
+ callback();
2895
+ } else {
2896
+ this._persistentInvitationsLoadedEvent.once(ctx, () => callback());
2897
+ }
2898
+ }
2899
+ _createInvitation(protocol, options) {
2900
+ const { invitationId = import_keys7.PublicKey.random().toHex(), type = import_services7.Invitation.Type.INTERACTIVE, authMethod = import_services7.Invitation.AuthMethod.SHARED_SECRET, state = import_services7.Invitation.State.INIT, timeout = import_client_protocol3.INVITATION_TIMEOUT, swarmKey = import_keys7.PublicKey.random(), persistent = options?.authMethod !== import_services7.Invitation.AuthMethod.KNOWN_PUBLIC_KEY, created = /* @__PURE__ */ new Date(), guestKeypair = void 0, lifetime = 86400, multiUse = false } = options ?? {};
2901
+ const authCode = options?.authCode ?? (authMethod === import_services7.Invitation.AuthMethod.SHARED_SECRET ? (0, import_credentials9.generatePasscode)(import_client_protocol3.AUTHENTICATION_CODE_LENGTH) : void 0);
2902
+ return {
2903
+ invitationId,
2904
+ type,
2905
+ authMethod,
2906
+ state,
2907
+ swarmKey,
2908
+ authCode,
2909
+ timeout,
2910
+ persistent: persistent && type !== import_services7.Invitation.Type.DELEGATED,
2911
+ guestKeypair: guestKeypair ?? (authMethod === import_services7.Invitation.AuthMethod.KNOWN_PUBLIC_KEY ? createAdmissionKeypair() : void 0),
2912
+ created,
2913
+ lifetime,
2914
+ multiUse,
2915
+ delegationCredentialId: options?.delegationCredentialId,
2916
+ ...protocol.getInvitationContext()
2917
+ };
2918
+ }
2919
+ _createObservableInvitation(handler, invitation) {
2920
+ const stream = new import_async9.PushStream();
2921
+ const ctx = new import_context6.Context({
2922
+ onError: (err) => {
2923
+ stream.error(err);
2924
+ void ctx.dispose();
2925
+ }
2926
+ });
2927
+ ctx.onDispose(() => {
2928
+ (0, import_log7.log)("complete", {
2929
+ ...handler.toJSON()
2930
+ }, {
2931
+ F: __dxlog_file9,
2932
+ L: 228,
2933
+ S: this,
2934
+ C: (f, a) => f(...a)
2935
+ });
2936
+ stream.complete();
2937
+ });
2938
+ const observableInvitation = new import_client_protocol3.CancellableInvitation({
2939
+ initialInvitation: invitation,
2940
+ subscriber: stream.observable,
2941
+ onCancel: async () => {
2942
+ stream.next({
2943
+ ...invitation,
2944
+ state: import_services7.Invitation.State.CANCELLED
2945
+ });
2946
+ await ctx.dispose();
2947
+ }
2948
+ });
2949
+ return {
2950
+ ctx,
2951
+ stream,
2952
+ observableInvitation
2953
+ };
2954
+ }
2955
+ async _persistIfRequired(handler, changeStream, invitation) {
2956
+ if (invitation.type === import_services7.Invitation.Type.DELEGATED && invitation.delegationCredentialId == null) {
2957
+ const delegationCredentialId = await handler.delegate(invitation);
2958
+ changeStream.next({
2959
+ ...invitation,
2960
+ delegationCredentialId
2961
+ });
2962
+ } else if (invitation.persistent) {
2963
+ await this._metadataStore.addInvitation(invitation);
2964
+ this.saved.emit(invitation);
2965
+ }
2966
+ }
2967
+ async _safeDeleteInvitation(invitation) {
2968
+ try {
2969
+ await this._metadataStore.removeInvitation(invitation.invitationId);
2970
+ } catch (err) {
2971
+ import_log7.log.catch(err, void 0, {
2972
+ F: __dxlog_file9,
2973
+ L: 260,
2974
+ S: this,
2975
+ C: (f, a) => f(...a)
2976
+ });
2977
+ }
2978
+ }
2979
+ _onInvitationComplete(invitation, callback) {
2980
+ invitation.subscribe(() => {
2981
+ }, () => {
2982
+ }, callback);
2983
+ }
2984
+ };
2802
2985
  function _ts_decorate3(decorators, target, key, desc) {
2803
2986
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2804
2987
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -2883,7 +3066,7 @@ var AutomergeSpaceState = class {
2883
3066
  this._isProcessingRootDocs = false;
2884
3067
  }
2885
3068
  async processCredential(credential) {
2886
- if (!(0, import_credentials10.checkCredentialType)(credential, "dxos.halo.credentials.Epoch")) {
3069
+ if (!(0, import_credentials11.checkCredentialType)(credential, "dxos.halo.credentials.Epoch")) {
2887
3070
  return;
2888
3071
  }
2889
3072
  this.lastEpoch = credential;
@@ -2918,8 +3101,8 @@ var NotarizationPlugin = class {
2918
3101
  this._ctx = new import_context8.Context();
2919
3102
  this._extensionOpened = new import_async12.Event();
2920
3103
  this._extensions = /* @__PURE__ */ new Set();
2921
- this._processedCredentials = new import_util5.ComplexSet(import_keys8.PublicKey.hash);
2922
- this._processCredentialsTriggers = new import_util5.ComplexMap(import_keys8.PublicKey.hash);
3104
+ this._processedCredentials = new import_util5.ComplexSet(import_keys9.PublicKey.hash);
3105
+ this._processCredentialsTriggers = new import_util5.ComplexMap(import_keys9.PublicKey.hash);
2923
3106
  }
2924
3107
  get hasWriter() {
2925
3108
  return !!this._writer;
@@ -3183,7 +3366,7 @@ var DataSpace = class {
3183
3366
  this._notarizationPlugin = new NotarizationPlugin();
3184
3367
  this._cache = void 0;
3185
3368
  this._automergeSpaceState = new AutomergeSpaceState((rootUrl) => this._onNewAutomergeRoot(rootUrl));
3186
- this._state = import_services7.SpaceState.CLOSED;
3369
+ this._state = import_services8.SpaceState.CLOSED;
3187
3370
  this.error = void 0;
3188
3371
  this.stateUpdate = new import_async10.Event();
3189
3372
  this.metrics = {};
@@ -3196,19 +3379,19 @@ var DataSpace = class {
3196
3379
  this._metadataStore = params.metadataStore;
3197
3380
  this._signingContext = params.signingContext;
3198
3381
  this._callbacks = params.callbacks ?? {};
3199
- this._automergeHost = params.automergeHost;
3382
+ this._echoHost = params.echoHost;
3200
3383
  this.authVerifier = new TrustedKeySetAuthVerifier({
3201
- trustedKeysProvider: () => new import_util4.ComplexSet(import_keys7.PublicKey.hash, Array.from(this._inner.spaceState.members.values()).filter((member) => !member.removed).map((member) => member.key)),
3384
+ trustedKeysProvider: () => new import_util4.ComplexSet(import_keys8.PublicKey.hash, Array.from(this._inner.spaceState.members.values()).filter((member) => !member.removed).map((member) => member.key)),
3202
3385
  update: this._inner.stateUpdate,
3203
- authTimeout: import_client_protocol3.AUTH_TIMEOUT
3386
+ authTimeout: import_client_protocol4.AUTH_TIMEOUT
3204
3387
  });
3205
3388
  this._cache = params.cache;
3206
3389
  this._state = params.initialState;
3207
3390
  (0, import_log8.log)("new state", {
3208
- state: import_services7.SpaceState[this._state]
3391
+ state: import_services8.SpaceState[this._state]
3209
3392
  }, {
3210
3393
  F: __dxlog_file11,
3211
- L: 140,
3394
+ L: 135,
3212
3395
  S: this,
3213
3396
  C: (f, a) => f(...a)
3214
3397
  });
@@ -3253,12 +3436,12 @@ var DataSpace = class {
3253
3436
  await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
3254
3437
  await this._inner.spaceState.addCredentialProcessor(this._automergeSpaceState);
3255
3438
  await this._inner.open(new import_context7.Context());
3256
- this._state = import_services7.SpaceState.CONTROL_ONLY;
3439
+ this._state = import_services8.SpaceState.CONTROL_ONLY;
3257
3440
  (0, import_log8.log)("new state", {
3258
- state: import_services7.SpaceState[this._state]
3441
+ state: import_services8.SpaceState[this._state]
3259
3442
  }, {
3260
3443
  F: __dxlog_file11,
3261
- L: 198,
3444
+ L: 193,
3262
3445
  S: this,
3263
3446
  C: (f, a) => f(...a)
3264
3447
  });
@@ -3271,12 +3454,12 @@ var DataSpace = class {
3271
3454
  }
3272
3455
  async _close() {
3273
3456
  await this._callbacks.beforeClose?.();
3274
- this._state = import_services7.SpaceState.CLOSED;
3457
+ this._state = import_services8.SpaceState.CLOSED;
3275
3458
  (0, import_log8.log)("new state", {
3276
- state: import_services7.SpaceState[this._state]
3459
+ state: import_services8.SpaceState[this._state]
3277
3460
  }, {
3278
3461
  F: __dxlog_file11,
3279
- L: 212,
3462
+ L: 207,
3280
3463
  S: this,
3281
3464
  C: (f, a) => f(...a)
3282
3465
  });
@@ -3308,7 +3491,7 @@ var DataSpace = class {
3308
3491
  if (err instanceof import_protocols7.CancelledError || err instanceof import_context7.ContextDisposedError) {
3309
3492
  (0, import_log8.log)("data pipeline initialization cancelled", err, {
3310
3493
  F: __dxlog_file11,
3311
- L: 245,
3494
+ L: 240,
3312
3495
  S: this,
3313
3496
  C: (f, a) => f(...a)
3314
3497
  });
@@ -3316,16 +3499,16 @@ var DataSpace = class {
3316
3499
  }
3317
3500
  import_log8.log.error("Error initializing data pipeline", err, {
3318
3501
  F: __dxlog_file11,
3319
- L: 249,
3502
+ L: 244,
3320
3503
  S: this,
3321
3504
  C: (f, a) => f(...a)
3322
3505
  });
3323
- this._state = import_services7.SpaceState.ERROR;
3506
+ this._state = import_services8.SpaceState.ERROR;
3324
3507
  (0, import_log8.log)("new state", {
3325
- state: import_services7.SpaceState[this._state]
3508
+ state: import_services8.SpaceState[this._state]
3326
3509
  }, {
3327
3510
  F: __dxlog_file11,
3328
- L: 251,
3511
+ L: 246,
3329
3512
  S: this,
3330
3513
  C: (f, a) => f(...a)
3331
3514
  });
@@ -3337,15 +3520,15 @@ var DataSpace = class {
3337
3520
  });
3338
3521
  }
3339
3522
  async initializeDataPipeline() {
3340
- if (this._state !== import_services7.SpaceState.CONTROL_ONLY) {
3523
+ if (this._state !== import_services8.SpaceState.CONTROL_ONLY) {
3341
3524
  throw new import_protocols7.SystemError("Invalid operation");
3342
3525
  }
3343
- this._state = import_services7.SpaceState.INITIALIZING;
3526
+ this._state = import_services8.SpaceState.INITIALIZING;
3344
3527
  (0, import_log8.log)("new state", {
3345
- state: import_services7.SpaceState[this._state]
3528
+ state: import_services8.SpaceState[this._state]
3346
3529
  }, {
3347
3530
  F: __dxlog_file11,
3348
- L: 267,
3531
+ L: 262,
3349
3532
  S: this,
3350
3533
  C: (f, a) => f(...a)
3351
3534
  });
@@ -3355,17 +3538,17 @@ var DataSpace = class {
3355
3538
  await (0, import_context7.cancelWithContext)(this._ctx, this.automergeSpaceState.ensureEpochInitialized());
3356
3539
  (0, import_log8.log)("data pipeline ready", void 0, {
3357
3540
  F: __dxlog_file11,
3358
- L: 279,
3541
+ L: 274,
3359
3542
  S: this,
3360
3543
  C: (f, a) => f(...a)
3361
3544
  });
3362
3545
  await this._callbacks.beforeReady?.();
3363
- this._state = import_services7.SpaceState.READY;
3546
+ this._state = import_services8.SpaceState.READY;
3364
3547
  (0, import_log8.log)("new state", {
3365
- state: import_services7.SpaceState[this._state]
3548
+ state: import_services8.SpaceState[this._state]
3366
3549
  }, {
3367
3550
  F: __dxlog_file11,
3368
- L: 283,
3551
+ L: 278,
3369
3552
  S: this,
3370
3553
  C: (f, a) => f(...a)
3371
3554
  });
@@ -3381,13 +3564,13 @@ var DataSpace = class {
3381
3564
  await this._createWritableFeeds();
3382
3565
  (0, import_log8.log)("writable feeds created", void 0, {
3383
3566
  F: __dxlog_file11,
3384
- L: 299,
3567
+ L: 294,
3385
3568
  S: this,
3386
3569
  C: (f, a) => f(...a)
3387
3570
  });
3388
3571
  this.stateUpdate.emit();
3389
3572
  if (!this.notarizationPlugin.hasWriter) {
3390
- this.notarizationPlugin.setWriter((0, import_echo_pipeline.createMappedFeedWriter)((credential) => ({
3573
+ this.notarizationPlugin.setWriter((0, import_echo_pipeline2.createMappedFeedWriter)((credential) => ({
3391
3574
  credential: {
3392
3575
  credential
3393
3576
  }
@@ -3408,7 +3591,7 @@ var DataSpace = class {
3408
3591
  spaceKey: this.key,
3409
3592
  deviceKey: this._signingContext.deviceKey,
3410
3593
  identityKey: this._signingContext.identityKey,
3411
- designation: import_credentials9.AdmittedFeed.Designation.CONTROL
3594
+ designation: import_credentials10.AdmittedFeed.Designation.CONTROL
3412
3595
  }
3413
3596
  }));
3414
3597
  }
@@ -3425,7 +3608,7 @@ var DataSpace = class {
3425
3608
  spaceKey: this.key,
3426
3609
  deviceKey: this._signingContext.deviceKey,
3427
3610
  identityKey: this._signingContext.identityKey,
3428
- designation: import_credentials9.AdmittedFeed.Designation.DATA
3611
+ designation: import_credentials10.AdmittedFeed.Designation.DATA
3429
3612
  }
3430
3613
  }));
3431
3614
  }
@@ -3444,12 +3627,12 @@ var DataSpace = class {
3444
3627
  rootUrl
3445
3628
  }, {
3446
3629
  F: __dxlog_file11,
3447
- L: 365,
3630
+ L: 360,
3448
3631
  S: this,
3449
3632
  C: (f, a) => f(...a)
3450
3633
  });
3451
- this._automergeHost._requestedDocs.add(rootUrl);
3452
- const handle = this._automergeHost.repo.find(rootUrl);
3634
+ this._echoHost.replicateDocument(rootUrl);
3635
+ const handle = this._echoHost.automergeRepo.find(rootUrl);
3453
3636
  queueMicrotask(async () => {
3454
3637
  try {
3455
3638
  await (0, import_debug3.warnAfterTimeout)(5e3, "Automerge root doc load timeout (DataSpace)", async () => {
@@ -3476,7 +3659,7 @@ var DataSpace = class {
3476
3659
  err
3477
3660
  }, {
3478
3661
  F: __dxlog_file11,
3479
- L: 388,
3662
+ L: 383,
3480
3663
  S: this,
3481
3664
  C: (f, a) => f(...a)
3482
3665
  });
@@ -3502,7 +3685,7 @@ var DataSpace = class {
3502
3685
  let epoch;
3503
3686
  switch (options?.migration) {
3504
3687
  case void 0:
3505
- case import_services7.CreateEpochRequest.Migration.NONE:
3688
+ case import_services8.CreateEpochRequest.Migration.NONE:
3506
3689
  {
3507
3690
  epoch = {
3508
3691
  previousId: this._automergeSpaceState.lastEpoch?.id,
@@ -3512,9 +3695,9 @@ var DataSpace = class {
3512
3695
  };
3513
3696
  }
3514
3697
  break;
3515
- case import_services7.CreateEpochRequest.Migration.INIT_AUTOMERGE:
3698
+ case import_services8.CreateEpochRequest.Migration.INIT_AUTOMERGE:
3516
3699
  {
3517
- const document = this._automergeHost.repo.create();
3700
+ const document = this._echoHost.automergeRepo.create();
3518
3701
  epoch = {
3519
3702
  previousId: this._automergeSpaceState.lastEpoch?.id,
3520
3703
  number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
@@ -3523,15 +3706,15 @@ var DataSpace = class {
3523
3706
  };
3524
3707
  }
3525
3708
  break;
3526
- case import_services7.CreateEpochRequest.Migration.PRUNE_AUTOMERGE_ROOT_HISTORY:
3709
+ case import_services8.CreateEpochRequest.Migration.PRUNE_AUTOMERGE_ROOT_HISTORY:
3527
3710
  {
3528
3711
  const currentRootUrl = this._automergeSpaceState.rootUrl;
3529
- const rootHandle = this._automergeHost.repo.find(currentRootUrl);
3712
+ const rootHandle = this._echoHost.automergeRepo.find(currentRootUrl);
3530
3713
  await (0, import_context7.cancelWithContext)(this._ctx, (0, import_async10.asyncTimeout)(rootHandle.whenReady(), 1e4));
3531
- const newRoot = this._automergeHost.repo.create(rootHandle.docSync());
3714
+ const newRoot = this._echoHost.automergeRepo.create(rootHandle.docSync());
3532
3715
  (0, import_invariant9.invariant)(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3533
3716
  F: __dxlog_file11,
3534
- L: 438,
3717
+ L: 433,
3535
3718
  S: this,
3536
3719
  A: [
3537
3720
  "typeof newRoot.url === 'string' && newRoot.url.length > 0",
@@ -3546,23 +3729,23 @@ var DataSpace = class {
3546
3729
  };
3547
3730
  }
3548
3731
  break;
3549
- case import_services7.CreateEpochRequest.Migration.FRAGMENT_AUTOMERGE_ROOT:
3732
+ case import_services8.CreateEpochRequest.Migration.FRAGMENT_AUTOMERGE_ROOT:
3550
3733
  {
3551
3734
  import_log8.log.info("Fragmenting", void 0, {
3552
3735
  F: __dxlog_file11,
3553
- L: 450,
3736
+ L: 445,
3554
3737
  S: this,
3555
3738
  C: (f, a) => f(...a)
3556
3739
  });
3557
3740
  const currentRootUrl = this._automergeSpaceState.rootUrl;
3558
- const rootHandle = this._automergeHost.repo.find(currentRootUrl);
3741
+ const rootHandle = this._echoHost.automergeRepo.find(currentRootUrl);
3559
3742
  await (0, import_context7.cancelWithContext)(this._ctx, (0, import_async10.asyncTimeout)(rootHandle.whenReady(), 1e4));
3560
3743
  const objects = Object.entries(rootHandle.docSync().objects);
3561
- const properties = objects.find(([_, value]) => value.system.type?.itemId === import_echo_db.TYPE_PROPERTIES);
3744
+ const properties = objects.find(([_, value]) => value.system.type?.itemId === import_echo_schema.TYPE_PROPERTIES);
3562
3745
  const otherObjects = objects.filter(([key]) => key !== properties?.[0]);
3563
3746
  (0, import_invariant9.invariant)(properties, "Properties not found", {
3564
3747
  F: __dxlog_file11,
3565
- L: 460,
3748
+ L: 455,
3566
3749
  S: this,
3567
3750
  A: [
3568
3751
  "properties",
@@ -3575,17 +3758,17 @@ var DataSpace = class {
3575
3758
  properties
3576
3759
  ])
3577
3760
  };
3578
- const newRoot = this._automergeHost.repo.create(newSpaceDoc);
3761
+ const newRoot = this._echoHost.automergeRepo.create(newSpaceDoc);
3579
3762
  (0, import_invariant9.invariant)(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3580
3763
  F: __dxlog_file11,
3581
- L: 465,
3764
+ L: 460,
3582
3765
  S: this,
3583
3766
  A: [
3584
3767
  "typeof newRoot.url === 'string' && newRoot.url.length > 0",
3585
3768
  ""
3586
3769
  ]
3587
3770
  });
3588
- const docLoader = new import_echo_pipeline2.AutomergeDocumentLoaderImpl(this.key, this._automergeHost.repo);
3771
+ const docLoader = new import_echo_pipeline3.AutomergeDocumentLoaderImpl(this.key, this._echoHost.automergeRepo);
3589
3772
  await docLoader.loadSpaceRootDocHandle(this._ctx, {
3590
3773
  rootUrl: newRoot.url
3591
3774
  });
@@ -3629,25 +3812,25 @@ var DataSpace = class {
3629
3812
  ]));
3630
3813
  }
3631
3814
  async activate() {
3632
- if (this._state !== import_services7.SpaceState.INACTIVE) {
3815
+ if (this._state !== import_services8.SpaceState.INACTIVE) {
3633
3816
  return;
3634
3817
  }
3635
- await this._metadataStore.setSpaceState(this.key, import_services7.SpaceState.ACTIVE);
3818
+ await this._metadataStore.setSpaceState(this.key, import_services8.SpaceState.ACTIVE);
3636
3819
  await this._open();
3637
3820
  this.initializeDataPipelineAsync();
3638
3821
  }
3639
3822
  async deactivate() {
3640
- if (this._state === import_services7.SpaceState.INACTIVE) {
3823
+ if (this._state === import_services8.SpaceState.INACTIVE) {
3641
3824
  return;
3642
3825
  }
3643
- await this._metadataStore.setSpaceState(this.key, import_services7.SpaceState.INACTIVE);
3826
+ await this._metadataStore.setSpaceState(this.key, import_services8.SpaceState.INACTIVE);
3644
3827
  await this._close();
3645
- this._state = import_services7.SpaceState.INACTIVE;
3828
+ this._state = import_services8.SpaceState.INACTIVE;
3646
3829
  (0, import_log8.log)("new state", {
3647
- state: import_services7.SpaceState[this._state]
3830
+ state: import_services8.SpaceState[this._state]
3648
3831
  }, {
3649
3832
  F: __dxlog_file11,
3650
- L: 531,
3833
+ L: 526,
3651
3834
  S: this,
3652
3835
  C: (f, a) => f(...a)
3653
3836
  });
@@ -3662,7 +3845,7 @@ _ts_decorate4([
3662
3845
  ], DataSpace.prototype, "key", null);
3663
3846
  _ts_decorate4([
3664
3847
  import_tracing4.trace.info({
3665
- enum: import_services7.SpaceState
3848
+ enum: import_services8.SpaceState
3666
3849
  })
3667
3850
  ], DataSpace.prototype, "state", null);
3668
3851
  _ts_decorate4([
@@ -3701,7 +3884,7 @@ DataSpace = _ts_decorate4([
3701
3884
  ], DataSpace);
3702
3885
  var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
3703
3886
  const credentials = [
3704
- await (0, import_credentials12.createCredential)({
3887
+ await (0, import_credentials13.createCredential)({
3705
3888
  signer: keyring,
3706
3889
  issuer: space.key,
3707
3890
  subject: space.key,
@@ -3710,14 +3893,14 @@ var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
3710
3893
  spaceKey: space.key
3711
3894
  }
3712
3895
  }),
3713
- await (0, import_credentials12.createCredential)({
3896
+ await (0, import_credentials13.createCredential)({
3714
3897
  signer: keyring,
3715
3898
  issuer: space.key,
3716
3899
  subject: signingContext.identityKey,
3717
3900
  assertion: {
3718
3901
  "@type": "dxos.halo.credentials.SpaceMember",
3719
3902
  spaceKey: space.key,
3720
- role: import_credentials13.SpaceMember.Role.ADMIN,
3903
+ role: import_credentials14.SpaceMember.Role.ADMIN,
3721
3904
  profile: signingContext.getProfile(),
3722
3905
  genesisFeedKey: space.controlFeedKey ?? (0, import_debug4.failUndefined)()
3723
3906
  }
@@ -3729,7 +3912,7 @@ var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
3729
3912
  spaceKey: space.key,
3730
3913
  identityKey: signingContext.identityKey,
3731
3914
  deviceKey: signingContext.deviceKey,
3732
- designation: import_credentials13.AdmittedFeed.Designation.CONTROL
3915
+ designation: import_credentials14.AdmittedFeed.Designation.CONTROL
3733
3916
  }
3734
3917
  }),
3735
3918
  await signingContext.credentialSigner.createCredential({
@@ -3739,7 +3922,7 @@ var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
3739
3922
  spaceKey: space.key,
3740
3923
  identityKey: signingContext.identityKey,
3741
3924
  deviceKey: signingContext.deviceKey,
3742
- designation: import_credentials13.AdmittedFeed.Designation.DATA
3925
+ designation: import_credentials14.AdmittedFeed.Designation.DATA
3743
3926
  }
3744
3927
  }),
3745
3928
  await signingContext.credentialSigner.createCredential({
@@ -3777,18 +3960,19 @@ var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/s
3777
3960
  var PRESENCE_ANNOUNCE_INTERVAL = 1e4;
3778
3961
  var PRESENCE_OFFLINE_TIMEOUT = 2e4;
3779
3962
  var DataSpaceManager = class {
3780
- constructor(_spaceManager, _metadataStore, _keyring, _signingContext, _feedStore, _automergeHost, params) {
3963
+ constructor(_spaceManager, _metadataStore, _keyring, _signingContext, _feedStore, _echoHost, _invitationsManager, params) {
3781
3964
  this._spaceManager = _spaceManager;
3782
3965
  this._metadataStore = _metadataStore;
3783
3966
  this._keyring = _keyring;
3784
3967
  this._signingContext = _signingContext;
3785
3968
  this._feedStore = _feedStore;
3786
- this._automergeHost = _automergeHost;
3969
+ this._echoHost = _echoHost;
3970
+ this._invitationsManager = _invitationsManager;
3787
3971
  this._ctx = new import_context9.Context();
3788
3972
  this.updated = new import_async13.Event();
3789
- this._spaces = new import_util6.ComplexMap(import_keys9.PublicKey.hash);
3973
+ this._spaces = new import_util6.ComplexMap(import_keys10.PublicKey.hash);
3790
3974
  this._isOpen = false;
3791
- this._instanceId = import_keys9.PublicKey.random().toHex();
3975
+ this._instanceId = import_keys10.PublicKey.random().toHex();
3792
3976
  const { spaceMemberPresenceAnnounceInterval = PRESENCE_ANNOUNCE_INTERVAL, spaceMemberPresenceOfflineTimeout = PRESENCE_OFFLINE_TIMEOUT } = params ?? {};
3793
3977
  this._spaceMemberPresenceAnnounceInterval = spaceMemberPresenceAnnounceInterval;
3794
3978
  this._spaceMemberPresenceOfflineTimeout = spaceMemberPresenceOfflineTimeout;
@@ -3800,7 +3984,7 @@ var DataSpaceManager = class {
3800
3984
  async open() {
3801
3985
  (0, import_log10.log)("open", void 0, {
3802
3986
  F: __dxlog_file12,
3803
- L: 98,
3987
+ L: 102,
3804
3988
  S: this,
3805
3989
  C: (f, a) => f(...a)
3806
3990
  });
@@ -3808,7 +3992,7 @@ var DataSpaceManager = class {
3808
3992
  id: this._instanceId
3809
3993
  }), {
3810
3994
  F: __dxlog_file12,
3811
- L: 99,
3995
+ L: 103,
3812
3996
  S: this,
3813
3997
  C: (f, a) => f(...a)
3814
3998
  });
@@ -3816,7 +4000,7 @@ var DataSpaceManager = class {
3816
4000
  spaces: this._metadataStore.spaces.length
3817
4001
  }, {
3818
4002
  F: __dxlog_file12,
3819
- L: 100,
4003
+ L: 104,
3820
4004
  S: this,
3821
4005
  C: (f, a) => f(...a)
3822
4006
  });
@@ -3826,7 +4010,7 @@ var DataSpaceManager = class {
3826
4010
  spaceMetadata
3827
4011
  }, {
3828
4012
  F: __dxlog_file12,
3829
- L: 104,
4013
+ L: 108,
3830
4014
  S: this,
3831
4015
  C: (f, a) => f(...a)
3832
4016
  });
@@ -3837,7 +4021,7 @@ var DataSpaceManager = class {
3837
4021
  err
3838
4022
  }, {
3839
4023
  F: __dxlog_file12,
3840
- L: 107,
4024
+ L: 111,
3841
4025
  S: this,
3842
4026
  C: (f, a) => f(...a)
3843
4027
  });
@@ -3846,7 +4030,7 @@ var DataSpaceManager = class {
3846
4030
  this._isOpen = true;
3847
4031
  this.updated.emit();
3848
4032
  for (const space of this._spaces.values()) {
3849
- if (space.state !== import_services8.SpaceState.INACTIVE) {
4033
+ if (space.state !== import_services9.SpaceState.INACTIVE) {
3850
4034
  space.initializeDataPipelineAsync();
3851
4035
  }
3852
4036
  }
@@ -3854,7 +4038,7 @@ var DataSpaceManager = class {
3854
4038
  id: this._instanceId
3855
4039
  }), {
3856
4040
  F: __dxlog_file12,
3857
- L: 120,
4041
+ L: 124,
3858
4042
  S: this,
3859
4043
  C: (f, a) => f(...a)
3860
4044
  });
@@ -3862,7 +4046,7 @@ var DataSpaceManager = class {
3862
4046
  async close() {
3863
4047
  (0, import_log10.log)("close", void 0, {
3864
4048
  F: __dxlog_file12,
3865
- L: 125,
4049
+ L: 129,
3866
4050
  S: this,
3867
4051
  C: (f, a) => f(...a)
3868
4052
  });
@@ -3878,7 +4062,7 @@ var DataSpaceManager = class {
3878
4062
  async createSpace() {
3879
4063
  (0, import_invariant11.invariant)(this._isOpen, "Not open.", {
3880
4064
  F: __dxlog_file12,
3881
- L: 138,
4065
+ L: 142,
3882
4066
  S: this,
3883
4067
  A: [
3884
4068
  "this._isOpen",
@@ -3893,27 +4077,22 @@ var DataSpaceManager = class {
3893
4077
  genesisFeedKey: controlFeedKey,
3894
4078
  controlFeedKey,
3895
4079
  dataFeedKey,
3896
- state: import_services8.SpaceState.ACTIVE
4080
+ state: import_services9.SpaceState.ACTIVE
3897
4081
  };
3898
4082
  (0, import_log10.log)("creating space...", {
3899
4083
  spaceKey
3900
4084
  }, {
3901
4085
  F: __dxlog_file12,
3902
- L: 150,
4086
+ L: 154,
3903
4087
  S: this,
3904
4088
  C: (f, a) => f(...a)
3905
4089
  });
3906
- const automergeRoot = this._automergeHost.repo.create();
3907
- automergeRoot.change((doc) => {
3908
- doc.access = {
3909
- spaceKey: spaceKey.toHex()
3910
- };
3911
- });
4090
+ const automergeRootUrl = await this._echoHost.createSpaceRoot(spaceKey);
3912
4091
  const space = await this._constructSpace(metadata);
3913
- const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner, automergeRoot.url);
4092
+ const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner, automergeRootUrl);
3914
4093
  await this._metadataStore.addSpace(metadata);
3915
4094
  const memberCredential = credentials[1];
3916
- (0, import_invariant11.invariant)((0, import_credentials11.getCredentialAssertion)(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
4095
+ (0, import_invariant11.invariant)((0, import_credentials12.getCredentialAssertion)(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
3917
4096
  F: __dxlog_file12,
3918
4097
  L: 163,
3919
4098
  S: this,
@@ -3975,7 +4154,7 @@ var DataSpaceManager = class {
3975
4154
  async waitUntilSpaceReady(spaceKey) {
3976
4155
  await (0, import_context9.cancelWithContext)(this._ctx, this.updated.waitForCondition(() => {
3977
4156
  const space = this._spaces.get(spaceKey);
3978
- return !!space && space.state === import_services8.SpaceState.READY;
4157
+ return !!space && space.state === import_services9.SpaceState.READY;
3979
4158
  }));
3980
4159
  }
3981
4160
  async _constructSpace(metadata) {
@@ -4015,8 +4194,8 @@ var DataSpaceManager = class {
4015
4194
  remotePeerId: session.remotePeerId
4016
4195
  }));
4017
4196
  session.addExtension("dxos.mesh.teleport.notarization", dataSpace.notarizationPlugin.createExtension());
4018
- this._automergeHost.authorizeDevice(space.key, session.remotePeerId);
4019
- session.addExtension("dxos.mesh.teleport.automerge", this._automergeHost.createExtension());
4197
+ this._echoHost.authorizeDevice(space.key, session.remotePeerId);
4198
+ session.addExtension("dxos.mesh.teleport.automerge", this._echoHost.createReplicationExtension());
4020
4199
  },
4021
4200
  onAuthFailure: () => {
4022
4201
  import_log10.log.warn("auth failure", void 0, {
@@ -4026,18 +4205,22 @@ var DataSpaceManager = class {
4026
4205
  C: (f, a) => f(...a)
4027
4206
  });
4028
4207
  },
4029
- memberKey: this._signingContext.identityKey
4208
+ memberKey: this._signingContext.identityKey,
4209
+ onDelegatedInvitationStatusChange: (invitation, isActive) => {
4210
+ return this._handleInvitationStatusChange(dataSpace, invitation, isActive);
4211
+ }
4030
4212
  });
4031
4213
  controlFeed && await space.setControlFeed(controlFeed);
4032
4214
  dataFeed && await space.setDataFeed(dataFeed);
4033
4215
  const dataSpace = new DataSpace({
4034
4216
  inner: space,
4035
- initialState: metadata.state === import_services8.SpaceState.INACTIVE ? import_services8.SpaceState.INACTIVE : import_services8.SpaceState.CLOSED,
4217
+ initialState: metadata.state === import_services9.SpaceState.INACTIVE ? import_services9.SpaceState.INACTIVE : import_services9.SpaceState.CLOSED,
4036
4218
  metadataStore: this._metadataStore,
4037
4219
  gossip,
4038
4220
  presence,
4039
4221
  keyring: this._keyring,
4040
4222
  feedStore: this._feedStore,
4223
+ echoHost: this._echoHost,
4041
4224
  signingContext: this._signingContext,
4042
4225
  callbacks: {
4043
4226
  beforeReady: async () => {
@@ -4045,7 +4228,7 @@ var DataSpaceManager = class {
4045
4228
  space: space.key
4046
4229
  }, {
4047
4230
  F: __dxlog_file12,
4048
- L: 265,
4231
+ L: 269,
4049
4232
  S: this,
4050
4233
  C: (f, a) => f(...a)
4051
4234
  });
@@ -4056,11 +4239,14 @@ var DataSpaceManager = class {
4056
4239
  open: this._isOpen
4057
4240
  }, {
4058
4241
  F: __dxlog_file12,
4059
- L: 268,
4242
+ L: 272,
4060
4243
  S: this,
4061
4244
  C: (f, a) => f(...a)
4062
4245
  });
4063
4246
  if (this._isOpen) {
4247
+ await this._createDelegatedInvitations(dataSpace, [
4248
+ ...space.spaceState.invitations.entries()
4249
+ ]);
4064
4250
  this.updated.emit();
4065
4251
  }
4066
4252
  },
@@ -4069,16 +4255,15 @@ var DataSpaceManager = class {
4069
4255
  space: space.key
4070
4256
  }, {
4071
4257
  F: __dxlog_file12,
4072
- L: 274,
4258
+ L: 279,
4073
4259
  S: this,
4074
4260
  C: (f, a) => f(...a)
4075
4261
  });
4076
4262
  }
4077
4263
  },
4078
- cache: metadata.cache,
4079
- automergeHost: this._automergeHost
4264
+ cache: metadata.cache
4080
4265
  });
4081
- if (metadata.state !== import_services8.SpaceState.INACTIVE) {
4266
+ if (metadata.state !== import_services9.SpaceState.INACTIVE) {
4082
4267
  await dataSpace.open();
4083
4268
  }
4084
4269
  if (metadata.controlTimeframe) {
@@ -4087,6 +4272,41 @@ var DataSpaceManager = class {
4087
4272
  this._spaces.set(metadata.key, dataSpace);
4088
4273
  return dataSpace;
4089
4274
  }
4275
+ async _handleInvitationStatusChange(dataSpace, delegatedInvitation, isActive) {
4276
+ if (dataSpace?.state !== import_services9.SpaceState.READY) {
4277
+ return;
4278
+ }
4279
+ if (isActive) {
4280
+ await this._createDelegatedInvitations(dataSpace, [
4281
+ [
4282
+ delegatedInvitation.credentialId,
4283
+ delegatedInvitation.invitation
4284
+ ]
4285
+ ]);
4286
+ } else {
4287
+ await this._invitationsManager.cancelInvitation(delegatedInvitation.invitation);
4288
+ }
4289
+ }
4290
+ async _createDelegatedInvitations(space, invitations) {
4291
+ const tasks = invitations.map(([credentialId, invitation]) => {
4292
+ return this._invitationsManager.createInvitation({
4293
+ type: import_services9.Invitation.Type.DELEGATED,
4294
+ kind: import_services9.Invitation.Kind.SPACE,
4295
+ spaceKey: space.key,
4296
+ authMethod: invitation.authMethod,
4297
+ invitationId: invitation.invitationId,
4298
+ swarmKey: invitation.swarmKey,
4299
+ guestKeypair: invitation.guestKey ? {
4300
+ publicKey: invitation.guestKey
4301
+ } : void 0,
4302
+ lifetime: invitation.expiresOn ? invitation.expiresOn.getTime() - Date.now() : void 0,
4303
+ multiUse: invitation.multiUse,
4304
+ delegationCredentialId: credentialId,
4305
+ persistent: false
4306
+ });
4307
+ });
4308
+ await Promise.all(tasks);
4309
+ }
4090
4310
  };
4091
4311
  _ts_decorate5([
4092
4312
  import_async13.synchronized
@@ -4123,10 +4343,10 @@ var SpacesServiceImpl = class {
4123
4343
  const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols10.SpaceNotFoundError(spaceKey));
4124
4344
  if (state) {
4125
4345
  switch (state) {
4126
- case import_services9.SpaceState.ACTIVE:
4346
+ case import_services10.SpaceState.ACTIVE:
4127
4347
  await space.activate();
4128
4348
  break;
4129
- case import_services9.SpaceState.INACTIVE:
4349
+ case import_services10.SpaceState.INACTIVE:
4130
4350
  await space.deactivate();
4131
4351
  break;
4132
4352
  default:
@@ -4300,7 +4520,7 @@ var SpacesServiceImpl = class {
4300
4520
  identityKey: member.key,
4301
4521
  profile: member.profile ?? {}
4302
4522
  },
4303
- presence: member.removed ? import_services9.SpaceMember.PresenceState.REMOVED : isMe || peers.length > 0 ? import_services9.SpaceMember.PresenceState.ONLINE : import_services9.SpaceMember.PresenceState.OFFLINE,
4523
+ presence: member.removed ? import_services10.SpaceMember.PresenceState.REMOVED : isMe || peers.length > 0 ? import_services10.SpaceMember.PresenceState.ONLINE : import_services10.SpaceMember.PresenceState.OFFLINE,
4304
4524
  peerStates: peers
4305
4525
  };
4306
4526
  }),
@@ -4311,80 +4531,6 @@ var SpacesServiceImpl = class {
4311
4531
  }
4312
4532
  };
4313
4533
  var getChannelId = (channel) => `user-channel/${channel}`;
4314
- var createSelectedDocumentsIterator = (automergeHost) => (
4315
- /**
4316
- * Get object data blobs from Automerge Repo by ids.
4317
- * @param ids
4318
- */
4319
- // TODO(mykola): Unload automerge handles after usage.
4320
- async function* loadDocuments(ids) {
4321
- for (const id of ids) {
4322
- const { documentId, objectId } = import_protocols12.idCodec.decode(id);
4323
- const handle = automergeHost.repo.find(documentId);
4324
- await (0, import_debug7.warnAfterTimeout)(5e3, "to long to load doc", () => handle.whenReady());
4325
- const doc = handle.docSync();
4326
- const hash = (0, import_automerge.getHeads)(doc).join("");
4327
- yield doc.objects?.[objectId] ? [
4328
- {
4329
- id,
4330
- object: doc.objects[objectId],
4331
- currentHash: hash
4332
- }
4333
- ] : [];
4334
- }
4335
- }
4336
- );
4337
- var createDocumentsIterator = (automergeHost) => (
4338
- /**
4339
- * Recursively get all object data blobs from Automerge Repo.
4340
- * @param ids
4341
- */
4342
- // TODO(mykola): Unload automerge handles after usage.
4343
- async function* getAllDocuments() {
4344
- const visited = /* @__PURE__ */ new Set();
4345
- async function* getObjectsFromHandle(handle) {
4346
- if (visited.has(handle.documentId)) {
4347
- return;
4348
- }
4349
- await (0, import_debug7.warnAfterTimeout)(5e3, "to long to load doc", () => handle.whenReady());
4350
- const doc = handle.docSync();
4351
- const heads = (0, import_automerge.getHeads)(doc);
4352
- if (doc.objects) {
4353
- yield Object.entries(doc.objects).map(([objectId, object]) => {
4354
- return {
4355
- id: import_protocols12.idCodec.encode({
4356
- documentId: handle.documentId,
4357
- objectId
4358
- }),
4359
- object,
4360
- currentHash: heads.join("")
4361
- };
4362
- });
4363
- }
4364
- if (doc.links) {
4365
- for (const id of Object.values(doc.links)) {
4366
- if (visited.has(id)) {
4367
- continue;
4368
- }
4369
- const linkHandle = automergeHost.repo.find(id);
4370
- for await (const result of getObjectsFromHandle(linkHandle)) {
4371
- yield result;
4372
- }
4373
- }
4374
- }
4375
- visited.add(handle.documentId);
4376
- }
4377
- for (const handle of Object.values(automergeHost.repo.handles)) {
4378
- if (visited.has(handle.documentId)) {
4379
- continue;
4380
- }
4381
- for await (const result of getObjectsFromHandle(handle)) {
4382
- yield result;
4383
- }
4384
- visited.add(handle.documentId);
4385
- }
4386
- }
4387
- );
4388
4534
  function _ts_decorate6(decorators, target, key, desc) {
4389
4535
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4390
4536
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -4406,9 +4552,9 @@ var ServiceContext = class extends import_context10.Resource {
4406
4552
  this._runtimeParams = _runtimeParams;
4407
4553
  this.initialized = new import_async15.Trigger();
4408
4554
  this._handlerFactories = /* @__PURE__ */ new Map();
4409
- this._instanceId = import_keys10.PublicKey.random().toHex();
4410
- this.metadataStore = new import_echo_pipeline3.MetadataStore(storage.createDirectory("metadata"));
4411
- this.snapshotStore = new import_echo_pipeline3.SnapshotStore(storage.createDirectory("snapshots"));
4555
+ this._instanceId = import_keys11.PublicKey.random().toHex();
4556
+ this.metadataStore = new import_echo_pipeline4.MetadataStore(storage.createDirectory("metadata"));
4557
+ this.snapshotStore = new import_echo_pipeline4.SnapshotStore(storage.createDirectory("snapshots"));
4412
4558
  this.blobStore = new import_teleport_extension_object_sync.BlobStore(storage.createDirectory("blobs"));
4413
4559
  this.keyring = new import_keyring.Keyring(storage.createDirectory("keyring"));
4414
4560
  this.feedStore = new import_feed_store4.FeedStore({
@@ -4416,12 +4562,12 @@ var ServiceContext = class extends import_context10.Resource {
4416
4562
  root: storage.createDirectory("feeds"),
4417
4563
  signer: this.keyring,
4418
4564
  hypercore: {
4419
- valueEncoding: import_echo_pipeline3.valueEncoding,
4565
+ valueEncoding: import_echo_pipeline4.valueEncoding,
4420
4566
  stats: true
4421
4567
  }
4422
4568
  })
4423
4569
  });
4424
- this.spaceManager = new import_echo_pipeline3.SpaceManager({
4570
+ this.spaceManager = new import_echo_pipeline4.SpaceManager({
4425
4571
  feedStore: this.feedStore,
4426
4572
  networkManager: this.networkManager,
4427
4573
  blobStore: this.blobStore,
@@ -4429,29 +4575,19 @@ var ServiceContext = class extends import_context10.Resource {
4429
4575
  snapshotStore: this.snapshotStore
4430
4576
  });
4431
4577
  this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager, this._runtimeParams);
4432
- this.indexMetadata = new import_indexing.IndexMetadataStore({
4433
- db: level.sublevel("index-metadata")
4434
- });
4435
- this.automergeHost = new import_echo_pipeline3.AutomergeHost({
4436
- directory: storage.createDirectory("automerge"),
4437
- metadata: this.indexMetadata
4438
- });
4439
- this.indexer = new import_indexing.Indexer({
4440
- indexStore: new import_indexing.IndexStore({
4441
- directory: storage.createDirectory("index-store")
4442
- }),
4443
- metadataStore: this.indexMetadata,
4444
- loadDocuments: createSelectedDocumentsIterator(this.automergeHost),
4445
- getAllDocuments: createDocumentsIterator(this.automergeHost)
4578
+ this.echoHost = new import_echo_db.EchoHost({
4579
+ kv: this.level,
4580
+ storage: this.storage
4446
4581
  });
4447
4582
  this.invitations = new InvitationsHandler(this.networkManager);
4448
- this._handlerFactories.set(import_services10.Invitation.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? (0, import_debug6.failUndefined)(), this._acceptIdentity.bind(this)));
4583
+ this.invitationsManager = new InvitationsManager(this.invitations, (invitation) => this.getInvitationHandler(invitation), this.metadataStore);
4584
+ this._handlerFactories.set(import_services11.Invitation.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? (0, import_debug6.failUndefined)(), this._acceptIdentity.bind(this)));
4449
4585
  }
4450
4586
  async _open(ctx) {
4451
4587
  await this._checkStorageVersion();
4452
4588
  (0, import_log12.log)("opening...", void 0, {
4453
4589
  F: __dxlog_file14,
4454
- L: 156,
4590
+ L: 151,
4455
4591
  S: this,
4456
4592
  C: (f, a) => f(...a)
4457
4593
  });
@@ -4459,18 +4595,28 @@ var ServiceContext = class extends import_context10.Resource {
4459
4595
  id: this._instanceId
4460
4596
  }), {
4461
4597
  F: __dxlog_file14,
4462
- L: 157,
4598
+ L: 152,
4463
4599
  S: this,
4464
4600
  C: (f, a) => f(...a)
4465
4601
  });
4466
4602
  await this.signalManager.open();
4467
4603
  await this.networkManager.open();
4604
+ await this.echoHost.open(ctx);
4468
4605
  await this.metadataStore.load();
4469
4606
  await this.spaceManager.open();
4470
4607
  await this.identityManager.open(ctx);
4471
4608
  if (this.identityManager.identity) {
4472
4609
  await this._initialize(ctx);
4473
4610
  }
4611
+ const loadedInvitations = await this.invitationsManager.loadPersistentInvitations();
4612
+ (0, import_log12.log)("loaded persistent invitations", {
4613
+ count: loadedInvitations.invitations?.length
4614
+ }, {
4615
+ F: __dxlog_file14,
4616
+ L: 165,
4617
+ S: this,
4618
+ C: (f, a) => f(...a)
4619
+ });
4474
4620
  import_log12.log.trace("dxos.sdk.service-context.open", import_protocols11.trace.end({
4475
4621
  id: this._instanceId
4476
4622
  }), {
@@ -4486,7 +4632,7 @@ var ServiceContext = class extends import_context10.Resource {
4486
4632
  C: (f, a) => f(...a)
4487
4633
  });
4488
4634
  }
4489
- async _close() {
4635
+ async _close(ctx) {
4490
4636
  (0, import_log12.log)("closing...", void 0, {
4491
4637
  F: __dxlog_file14,
4492
4638
  L: 172,
@@ -4496,18 +4642,17 @@ var ServiceContext = class extends import_context10.Resource {
4496
4642
  if (this._deviceSpaceSync && this.identityManager.identity) {
4497
4643
  await this.identityManager.identity.space.spaceState.removeCredentialProcessor(this._deviceSpaceSync);
4498
4644
  }
4499
- await this.automergeHost.close();
4500
4645
  await this.dataSpaceManager?.close();
4501
4646
  await this.identityManager.close();
4502
4647
  await this.spaceManager.close();
4503
4648
  await this.feedStore.close();
4649
+ await this.metadataStore.close();
4650
+ await this.echoHost.close(ctx);
4504
4651
  await this.networkManager.close();
4505
4652
  await this.signalManager.close();
4506
- await this.metadataStore.close();
4507
- await this.indexer.destroy();
4508
4653
  (0, import_log12.log)("closed", void 0, {
4509
4654
  F: __dxlog_file14,
4510
- L: 185,
4655
+ L: 184,
4511
4656
  S: this,
4512
4657
  C: (f, a) => f(...a)
4513
4658
  });
@@ -4521,7 +4666,7 @@ var ServiceContext = class extends import_context10.Resource {
4521
4666
  const factory = this._handlerFactories.get(invitation.kind);
4522
4667
  (0, import_invariant13.invariant)(factory, `Unknown invitation kind: ${invitation.kind}`, {
4523
4668
  F: __dxlog_file14,
4524
- L: 196,
4669
+ L: 195,
4525
4670
  S: this,
4526
4671
  A: [
4527
4672
  "factory",
@@ -4553,7 +4698,7 @@ var ServiceContext = class extends import_context10.Resource {
4553
4698
  async _initialize(ctx) {
4554
4699
  (0, import_log12.log)("initializing spaces...", void 0, {
4555
4700
  F: __dxlog_file14,
4556
- L: 227,
4701
+ L: 226,
4557
4702
  S: this,
4558
4703
  C: (f, a) => f(...a)
4559
4704
  });
@@ -4571,9 +4716,9 @@ var ServiceContext = class extends import_context10.Resource {
4571
4716
  });
4572
4717
  }
4573
4718
  };
4574
- this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.keyring, signingContext, this.feedStore, this.automergeHost, this._runtimeParams);
4719
+ this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.keyring, signingContext, this.feedStore, this.echoHost, this.invitationsManager, this._runtimeParams);
4575
4720
  await this.dataSpaceManager.open();
4576
- this._handlerFactories.set(import_services10.Invitation.Kind.SPACE, (invitation) => {
4721
+ this._handlerFactories.set(import_services11.Invitation.Kind.SPACE, (invitation) => {
4577
4722
  (0, import_invariant13.invariant)(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
4578
4723
  F: __dxlog_file14,
4579
4724
  L: 251,
@@ -4588,7 +4733,7 @@ var ServiceContext = class extends import_context10.Resource {
4588
4733
  this.initialized.wake();
4589
4734
  this._deviceSpaceSync = {
4590
4735
  processCredential: async (credential) => {
4591
- const assertion = (0, import_credentials14.getCredentialAssertion)(credential);
4736
+ const assertion = (0, import_credentials15.getCredentialAssertion)(credential);
4592
4737
  if (assertion["@type"] !== "dxos.halo.credentials.SpaceMember") {
4593
4738
  return;
4594
4739
  }
@@ -4675,26 +4820,26 @@ var ServiceRegistry = class {
4675
4820
  delete this._handlers[name];
4676
4821
  }
4677
4822
  };
4678
- var DXOS_VERSION = "0.4.10-main.c42bfdb";
4823
+ var DXOS_VERSION = "0.4.10-main.c61b011";
4679
4824
  var getPlatform = () => {
4680
4825
  if (process.browser) {
4681
4826
  if (typeof window !== "undefined") {
4682
4827
  const { userAgent } = window.navigator;
4683
4828
  return {
4684
- type: import_services12.Platform.PLATFORM_TYPE.BROWSER,
4829
+ type: import_services13.Platform.PLATFORM_TYPE.BROWSER,
4685
4830
  userAgent,
4686
4831
  uptime: Math.floor((Date.now() - window.performance.timeOrigin) / 1e3)
4687
4832
  };
4688
4833
  } else {
4689
4834
  return {
4690
- type: import_services12.Platform.PLATFORM_TYPE.SHARED_WORKER,
4835
+ type: import_services13.Platform.PLATFORM_TYPE.SHARED_WORKER,
4691
4836
  uptime: Math.floor((Date.now() - performance.timeOrigin) / 1e3)
4692
4837
  };
4693
4838
  }
4694
4839
  } else {
4695
4840
  const { platform: platform2, version, arch } = process;
4696
4841
  return {
4697
- type: import_services12.Platform.PLATFORM_TYPE.NODE,
4842
+ type: import_services13.Platform.PLATFORM_TYPE.NODE,
4698
4843
  platform: platform2,
4699
4844
  arch,
4700
4845
  runtime: version,
@@ -4712,7 +4857,7 @@ var createDiagnostics = async (clientServices, serviceContext, config) => {
4712
4857
  client: {
4713
4858
  version: DXOS_VERSION,
4714
4859
  storage: {
4715
- version: import_protocols13.STORAGE_VERSION
4860
+ version: import_protocols12.STORAGE_VERSION
4716
4861
  }
4717
4862
  },
4718
4863
  trace: import_tracing6.TRACE_PROCESSOR.getDiagnostics()
@@ -4781,7 +4926,7 @@ var getSpaceStats = async (space) => {
4781
4926
  const stats = {
4782
4927
  key: space.key,
4783
4928
  metrics: space.metrics,
4784
- epochs: space.inner.spaceState.credentials.filter((0, import_credentials15.credentialTypeFilter)("dxos.halo.credentials.Epoch")).map((credential) => ({
4929
+ epochs: space.inner.spaceState.credentials.filter((0, import_credentials16.credentialTypeFilter)("dxos.halo.credentials.Epoch")).map((credential) => ({
4785
4930
  ...credential.subject.assertion,
4786
4931
  id: credential.id
4787
4932
  })),
@@ -4792,7 +4937,7 @@ var getSpaceStats = async (space) => {
4792
4937
  displayName: member.assertion.profile?.displayName
4793
4938
  }
4794
4939
  },
4795
- presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? import_services11.SpaceMember.PresenceState.ONLINE : import_services11.SpaceMember.PresenceState.OFFLINE
4940
+ presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? import_services12.SpaceMember.PresenceState.ONLINE : import_services12.SpaceMember.PresenceState.OFFLINE
4796
4941
  })),
4797
4942
  pipeline: {
4798
4943
  // TODO(burdon): Pick properties from credentials if needed.
@@ -4856,9 +5001,9 @@ var DevicesServiceImpl = class {
4856
5001
  const peerState = peers.find((peer) => peer.identityKey.equals(key));
4857
5002
  return {
4858
5003
  deviceKey: key,
4859
- kind: this._identityManager.identity?.deviceKey.equals(key) ? import_services15.DeviceKind.CURRENT : import_services15.DeviceKind.TRUSTED,
5004
+ kind: this._identityManager.identity?.deviceKey.equals(key) ? import_services16.DeviceKind.CURRENT : import_services16.DeviceKind.TRUSTED,
4860
5005
  profile,
4861
- presence: isMe ? import_services15.Device.PresenceState.ONLINE : peerState ? import_services15.Device.PresenceState.ONLINE : import_services15.Device.PresenceState.OFFLINE
5006
+ presence: isMe ? import_services16.Device.PresenceState.ONLINE : peerState ? import_services16.Device.PresenceState.ONLINE : import_services16.Device.PresenceState.OFFLINE
4862
5007
  };
4863
5008
  })
4864
5009
  });
@@ -4957,7 +5102,7 @@ var LoggingServiceImpl = class {
4957
5102
  constructor() {
4958
5103
  this._logs = new import_async18.Event();
4959
5104
  this._started = Date.now();
4960
- this._sessionId = import_keys12.PublicKey.random().toHex();
5105
+ this._sessionId = import_keys13.PublicKey.random().toHex();
4961
5106
  this._logProcessor = (_config, entry2) => {
4962
5107
  this._logs.emit(entry2);
4963
5108
  };
@@ -5054,16 +5199,16 @@ var LoggingServiceImpl = class {
5054
5199
  };
5055
5200
  var matchFilter = (filter, level, path2, options) => {
5056
5201
  switch (options) {
5057
- case import_services16.QueryLogsRequest.MatchingOptions.INCLUSIVE:
5202
+ case import_services17.QueryLogsRequest.MatchingOptions.INCLUSIVE:
5058
5203
  return level >= filter.level && (!filter.pattern || path2.includes(filter.pattern));
5059
- case import_services16.QueryLogsRequest.MatchingOptions.EXPLICIT:
5204
+ case import_services17.QueryLogsRequest.MatchingOptions.EXPLICIT:
5060
5205
  return level === filter.level && (!filter.pattern || path2.includes(filter.pattern));
5061
5206
  }
5062
5207
  };
5063
5208
  var shouldLog = (entry2, request) => {
5064
- const options = request.options ?? import_services16.QueryLogsRequest.MatchingOptions.INCLUSIVE;
5209
+ const options = request.options ?? import_services17.QueryLogsRequest.MatchingOptions.INCLUSIVE;
5065
5210
  if (request.filters === void 0) {
5066
- return options === import_services16.QueryLogsRequest.MatchingOptions.INCLUSIVE;
5211
+ return options === import_services17.QueryLogsRequest.MatchingOptions.INCLUSIVE;
5067
5212
  } else {
5068
5213
  return request.filters.some((filter) => matchFilter(filter, entry2.level, entry2.meta?.F ?? "", options));
5069
5214
  }
@@ -5100,7 +5245,7 @@ var NetworkServiceImpl = class {
5100
5245
  }
5101
5246
  };
5102
5247
  var getRootPath = (config) => {
5103
- const { dataRoot = (0, import_util11.isNode)() ? import_client_protocol5.DX_DATA : "dxos/storage" } = config ?? {};
5248
+ const { dataRoot = (0, import_util11.isNode)() ? import_client_protocol6.DX_DATA : "dxos/storage" } = config ?? {};
5104
5249
  return `${dataRoot}/`;
5105
5250
  };
5106
5251
  var isPersistent = (config) => {
@@ -5111,16 +5256,16 @@ var StorageDriver = import_config2.Runtime.Client.Storage.StorageDriver;
5111
5256
  var createStorageObjects = (config) => {
5112
5257
  const { persistent = false, keyStore, dataStore } = config ?? {};
5113
5258
  if (persistent && dataStore === StorageDriver.RAM) {
5114
- throw new import_protocols15.InvalidConfigError("RAM storage cannot be used in persistent mode.");
5259
+ throw new import_protocols14.InvalidConfigError("RAM storage cannot be used in persistent mode.");
5115
5260
  }
5116
5261
  if (!persistent && dataStore !== void 0 && dataStore !== StorageDriver.RAM) {
5117
- throw new import_protocols15.InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
5262
+ throw new import_protocols14.InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
5118
5263
  }
5119
5264
  if (persistent && keyStore === StorageDriver.RAM) {
5120
- throw new import_protocols15.InvalidConfigError("RAM key storage cannot be used in persistent mode.");
5265
+ throw new import_protocols14.InvalidConfigError("RAM key storage cannot be used in persistent mode.");
5121
5266
  }
5122
5267
  if (!persistent && keyStore !== StorageDriver.RAM && keyStore !== void 0) {
5123
- throw new import_protocols15.InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
5268
+ throw new import_protocols14.InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
5124
5269
  }
5125
5270
  return {
5126
5271
  storage: (0, import_random_access_storage.createStorage)({
@@ -5151,7 +5296,7 @@ var toStorageType = (type) => {
5151
5296
  };
5152
5297
  var createLevel = async (config) => {
5153
5298
  const persistent = isPersistent(config);
5154
- const storagePath = persistent ? getRootPath(config) : import_node_path.default.join("tmp", "level", import_keys13.PublicKey.random().toHex());
5299
+ const storagePath = persistent ? import_node_path.default.join(getRootPath(config), "level") : `/tmp/dxos-${import_keys14.PublicKey.random().toHex()}`;
5155
5300
  const level = new import_level.Level(storagePath);
5156
5301
  await level.open();
5157
5302
  return level;
@@ -5176,8 +5321,8 @@ var SystemServiceImpl = class {
5176
5321
  return {
5177
5322
  timestamp: /* @__PURE__ */ new Date(),
5178
5323
  diagnostics: JSON.parse(JSON.stringify(diagnostics, (0, import_util12.jsonKeyReplacer)({
5179
- truncate: keys === import_services17.GetDiagnosticsRequest.KEY_OPTION.TRUNCATE,
5180
- humanize: keys === import_services17.GetDiagnosticsRequest.KEY_OPTION.HUMANIZE
5324
+ truncate: keys === import_services18.GetDiagnosticsRequest.KEY_OPTION.TRUNCATE,
5325
+ humanize: keys === import_services18.GetDiagnosticsRequest.KEY_OPTION.HUMANIZE
5181
5326
  })))
5182
5327
  };
5183
5328
  }
@@ -5225,6 +5370,7 @@ var ClientServicesHost = class {
5225
5370
  transportFactory,
5226
5371
  signalManager,
5227
5372
  storage,
5373
+ level,
5228
5374
  // TODO(wittjosiah): Turn this on by default.
5229
5375
  lockKey,
5230
5376
  callbacks,
@@ -5235,6 +5381,7 @@ var ClientServicesHost = class {
5235
5381
  this._opening = false;
5236
5382
  this._open = false;
5237
5383
  this._storage = storage;
5384
+ this._level = level;
5238
5385
  this._callbacks = callbacks;
5239
5386
  this._runtimeParams = runtimeParams;
5240
5387
  if (config) {
@@ -5258,14 +5405,14 @@ var ClientServicesHost = class {
5258
5405
  this._systemService = new SystemServiceImpl({
5259
5406
  config: () => this._config,
5260
5407
  statusUpdate: this._statusUpdate,
5261
- getCurrentStatus: () => this.isOpen ? import_services14.SystemStatus.ACTIVE : import_services14.SystemStatus.INACTIVE,
5408
+ getCurrentStatus: () => this.isOpen ? import_services15.SystemStatus.ACTIVE : import_services15.SystemStatus.INACTIVE,
5262
5409
  getDiagnostics: () => {
5263
5410
  return createDiagnostics(this._serviceRegistry.services, this._serviceContext, this._config);
5264
5411
  },
5265
5412
  onUpdateStatus: async (status) => {
5266
- if (!this.isOpen && status === import_services14.SystemStatus.ACTIVE) {
5413
+ if (!this.isOpen && status === import_services15.SystemStatus.ACTIVE) {
5267
5414
  await this._resourceLock?.acquire();
5268
- } else if (this.isOpen && status === import_services14.SystemStatus.INACTIVE) {
5415
+ } else if (this.isOpen && status === import_services15.SystemStatus.INACTIVE) {
5269
5416
  await this._resourceLock?.release();
5270
5417
  }
5271
5418
  },
@@ -5275,7 +5422,7 @@ var ClientServicesHost = class {
5275
5422
  });
5276
5423
  this.diagnosticsBroadcastHandler = createCollectDiagnosticsBroadcastHandler(this._systemService);
5277
5424
  this._loggingService = new LoggingServiceImpl();
5278
- this._serviceRegistry = new ServiceRegistry(import_client_protocol4.clientServiceBundle, {
5425
+ this._serviceRegistry = new ServiceRegistry(import_client_protocol5.clientServiceBundle, {
5279
5426
  SystemService: this._systemService,
5280
5427
  TracingService: this._tracingService
5281
5428
  });
@@ -5306,7 +5453,7 @@ var ClientServicesHost = class {
5306
5453
  initialize({ config, ...options }) {
5307
5454
  (0, import_invariant15.invariant)(!this._open, "service host is open", {
5308
5455
  F: __dxlog_file18,
5309
- L: 188,
5456
+ L: 190,
5310
5457
  S: this,
5311
5458
  A: [
5312
5459
  "!this._open",
@@ -5315,14 +5462,14 @@ var ClientServicesHost = class {
5315
5462
  });
5316
5463
  (0, import_log13.log)("initializing...", void 0, {
5317
5464
  F: __dxlog_file18,
5318
- L: 189,
5465
+ L: 191,
5319
5466
  S: this,
5320
5467
  C: (f, a) => f(...a)
5321
5468
  });
5322
5469
  if (config) {
5323
5470
  (0, import_invariant15.invariant)(!this._config, "config already set", {
5324
5471
  F: __dxlog_file18,
5325
- L: 192,
5472
+ L: 194,
5326
5473
  S: this,
5327
5474
  A: [
5328
5475
  "!this._config",
@@ -5337,7 +5484,7 @@ var ClientServicesHost = class {
5337
5484
  if (!options.signalManager) {
5338
5485
  import_log13.log.warn("running signaling without telemetry metadata.", void 0, {
5339
5486
  F: __dxlog_file18,
5340
- L: 200,
5487
+ L: 202,
5341
5488
  S: this,
5342
5489
  C: (f, a) => f(...a)
5343
5490
  });
@@ -5348,7 +5495,7 @@ var ClientServicesHost = class {
5348
5495
  this._signalManager = signalManager;
5349
5496
  (0, import_invariant15.invariant)(!this._networkManager, "network manager already set", {
5350
5497
  F: __dxlog_file18,
5351
- L: 211,
5498
+ L: 213,
5352
5499
  S: this,
5353
5500
  A: [
5354
5501
  "!this._networkManager",
@@ -5362,7 +5509,7 @@ var ClientServicesHost = class {
5362
5509
  });
5363
5510
  (0, import_log13.log)("initialized", void 0, {
5364
5511
  F: __dxlog_file18,
5365
- L: 218,
5512
+ L: 220,
5366
5513
  S: this,
5367
5514
  C: (f, a) => f(...a)
5368
5515
  });
@@ -5371,18 +5518,18 @@ var ClientServicesHost = class {
5371
5518
  if (this._open) {
5372
5519
  return;
5373
5520
  }
5374
- const traceId = import_keys11.PublicKey.random().toHex();
5375
- import_log13.log.trace("dxos.client-services.host.open", import_protocols14.trace.begin({
5521
+ const traceId = import_keys12.PublicKey.random().toHex();
5522
+ import_log13.log.trace("dxos.client-services.host.open", import_protocols13.trace.begin({
5376
5523
  id: traceId
5377
5524
  }), {
5378
5525
  F: __dxlog_file18,
5379
- L: 229,
5526
+ L: 231,
5380
5527
  S: this,
5381
5528
  C: (f, a) => f(...a)
5382
5529
  });
5383
5530
  (0, import_invariant15.invariant)(this._config, "config not set", {
5384
5531
  F: __dxlog_file18,
5385
- L: 231,
5532
+ L: 233,
5386
5533
  S: this,
5387
5534
  A: [
5388
5535
  "this._config",
@@ -5391,7 +5538,7 @@ var ClientServicesHost = class {
5391
5538
  });
5392
5539
  (0, import_invariant15.invariant)(this._storage, "storage not set", {
5393
5540
  F: __dxlog_file18,
5394
- L: 232,
5541
+ L: 234,
5395
5542
  S: this,
5396
5543
  A: [
5397
5544
  "this._storage",
@@ -5400,7 +5547,7 @@ var ClientServicesHost = class {
5400
5547
  });
5401
5548
  (0, import_invariant15.invariant)(this._signalManager, "signal manager not set", {
5402
5549
  F: __dxlog_file18,
5403
- L: 233,
5550
+ L: 235,
5404
5551
  S: this,
5405
5552
  A: [
5406
5553
  "this._signalManager",
@@ -5409,7 +5556,7 @@ var ClientServicesHost = class {
5409
5556
  });
5410
5557
  (0, import_invariant15.invariant)(this._networkManager, "network manager not set", {
5411
5558
  F: __dxlog_file18,
5412
- L: 234,
5559
+ L: 236,
5413
5560
  S: this,
5414
5561
  A: [
5415
5562
  "this._networkManager",
@@ -5421,30 +5568,28 @@ var ClientServicesHost = class {
5421
5568
  lockKey: this._resourceLock?.lockKey
5422
5569
  }, {
5423
5570
  F: __dxlog_file18,
5424
- L: 237,
5571
+ L: 239,
5425
5572
  S: this,
5426
5573
  C: (f, a) => f(...a)
5427
5574
  });
5428
5575
  if (!this._level) {
5429
5576
  this._level = await createLevel(this._config.get("runtime.client.storage", {}));
5430
5577
  }
5578
+ await this._level.open();
5431
5579
  await this._resourceLock?.acquire();
5432
5580
  await this._loggingService.open();
5433
5581
  this._serviceContext = new ServiceContext(this._storage, this._level, this._networkManager, this._signalManager, this._runtimeParams);
5434
5582
  this._serviceRegistry.setServices({
5435
5583
  SystemService: this._systemService,
5436
5584
  IdentityService: new IdentityServiceImpl((params) => this._createIdentity(params), this._serviceContext.identityManager, this._serviceContext.keyring, (profile) => this._serviceContext.broadcastProfileUpdate(profile)),
5437
- InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitations, (invitation) => this._serviceContext.getInvitationHandler(invitation), this._serviceContext.metadataStore),
5585
+ InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitationsManager),
5438
5586
  DevicesService: new DevicesServiceImpl(this._serviceContext.identityManager),
5439
5587
  SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, async () => {
5440
5588
  await this._serviceContext.initialized.wait();
5441
5589
  return this._serviceContext.dataSpaceManager;
5442
5590
  }),
5443
- DataService: new import_echo_pipeline4.DataServiceImpl(this._serviceContext.automergeHost),
5444
- IndexService: new import_indexing2.IndexServiceImpl({
5445
- indexer: this._serviceContext.indexer,
5446
- automergeHost: this._serviceContext.automergeHost
5447
- }),
5591
+ DataService: this._serviceContext.echoHost.dataService,
5592
+ QueryService: this._serviceContext.echoHost.queryService,
5448
5593
  NetworkService: new NetworkServiceImpl(this._serviceContext.networkManager, this._serviceContext.signalManager),
5449
5594
  LoggingService: this._loggingService,
5450
5595
  TracingService: this._tracingService,
@@ -5456,30 +5601,12 @@ var ClientServicesHost = class {
5456
5601
  })
5457
5602
  });
5458
5603
  await this._serviceContext.open(ctx);
5459
- (0, import_invariant15.invariant)(this.serviceRegistry.services.InvitationsService, void 0, {
5460
- F: __dxlog_file18,
5461
- L: 303,
5462
- S: this,
5463
- A: [
5464
- "this.serviceRegistry.services.InvitationsService",
5465
- ""
5466
- ]
5467
- });
5468
- const loadedInvitations = await this.serviceRegistry.services.InvitationsService.loadPersistentInvitations();
5469
- (0, import_log13.log)("loaded persistent invitations", {
5470
- count: loadedInvitations.invitations?.length
5471
- }, {
5472
- F: __dxlog_file18,
5473
- L: 306,
5474
- S: this,
5475
- C: (f, a) => f(...a)
5476
- });
5477
5604
  const devtoolsProxy = this._config?.get("runtime.client.devtoolsProxy");
5478
5605
  if (devtoolsProxy) {
5479
5606
  this._devtoolsProxy = new import_websocket_rpc.WebsocketRpcClient({
5480
5607
  url: devtoolsProxy,
5481
5608
  requested: {},
5482
- exposed: import_client_protocol4.clientServiceBundle,
5609
+ exposed: import_client_protocol5.clientServiceBundle,
5483
5610
  handlers: this.services
5484
5611
  });
5485
5612
  void this._devtoolsProxy.open();
@@ -5493,15 +5620,15 @@ var ClientServicesHost = class {
5493
5620
  deviceKey
5494
5621
  }, {
5495
5622
  F: __dxlog_file18,
5496
- L: 324,
5623
+ L: 315,
5497
5624
  S: this,
5498
5625
  C: (f, a) => f(...a)
5499
5626
  });
5500
- import_log13.log.trace("dxos.client-services.host.open", import_protocols14.trace.end({
5627
+ import_log13.log.trace("dxos.client-services.host.open", import_protocols13.trace.end({
5501
5628
  id: traceId
5502
5629
  }), {
5503
5630
  F: __dxlog_file18,
5504
- L: 325,
5631
+ L: 316,
5505
5632
  S: this,
5506
5633
  C: (f, a) => f(...a)
5507
5634
  });
@@ -5515,7 +5642,7 @@ var ClientServicesHost = class {
5515
5642
  deviceKey
5516
5643
  }, {
5517
5644
  F: __dxlog_file18,
5518
- L: 336,
5645
+ L: 327,
5519
5646
  S: this,
5520
5647
  C: (f, a) => f(...a)
5521
5648
  });
@@ -5533,24 +5660,24 @@ var ClientServicesHost = class {
5533
5660
  deviceKey
5534
5661
  }, {
5535
5662
  F: __dxlog_file18,
5536
- L: 345,
5663
+ L: 336,
5537
5664
  S: this,
5538
5665
  C: (f, a) => f(...a)
5539
5666
  });
5540
5667
  }
5541
5668
  async reset() {
5542
- const traceId = import_keys11.PublicKey.random().toHex();
5543
- import_log13.log.trace("dxos.sdk.client-services-host.reset", import_protocols14.trace.begin({
5669
+ const traceId = import_keys12.PublicKey.random().toHex();
5670
+ import_log13.log.trace("dxos.sdk.client-services-host.reset", import_protocols13.trace.begin({
5544
5671
  id: traceId
5545
5672
  }), {
5546
5673
  F: __dxlog_file18,
5547
- L: 350,
5674
+ L: 341,
5548
5675
  S: this,
5549
5676
  C: (f, a) => f(...a)
5550
5677
  });
5551
5678
  (0, import_log13.log)("resetting...", void 0, {
5552
5679
  F: __dxlog_file18,
5553
- L: 352,
5680
+ L: 343,
5554
5681
  S: this,
5555
5682
  C: (f, a) => f(...a)
5556
5683
  });
@@ -5558,15 +5685,15 @@ var ClientServicesHost = class {
5558
5685
  await this._storage.reset();
5559
5686
  (0, import_log13.log)("reset", void 0, {
5560
5687
  F: __dxlog_file18,
5561
- L: 355,
5688
+ L: 346,
5562
5689
  S: this,
5563
5690
  C: (f, a) => f(...a)
5564
5691
  });
5565
- import_log13.log.trace("dxos.sdk.client-services-host.reset", import_protocols14.trace.end({
5692
+ import_log13.log.trace("dxos.sdk.client-services-host.reset", import_protocols13.trace.end({
5566
5693
  id: traceId
5567
5694
  }), {
5568
5695
  F: __dxlog_file18,
5569
- L: 356,
5696
+ L: 347,
5570
5697
  S: this,
5571
5698
  C: (f, a) => f(...a)
5572
5699
  });
@@ -5579,34 +5706,34 @@ var ClientServicesHost = class {
5579
5706
  const automergeIndex = space.automergeSpaceState.rootUrl;
5580
5707
  (0, import_invariant15.invariant)(automergeIndex, void 0, {
5581
5708
  F: __dxlog_file18,
5582
- L: 368,
5709
+ L: 359,
5583
5710
  S: this,
5584
5711
  A: [
5585
5712
  "automergeIndex",
5586
5713
  ""
5587
5714
  ]
5588
5715
  });
5589
- const document = await this._serviceContext.automergeHost.repo.find(automergeIndex);
5716
+ const document = await this._serviceContext.echoHost.automergeRepo.find(automergeIndex);
5590
5717
  await document.whenReady();
5591
5718
  const properties = {
5592
5719
  system: {
5593
- type: (0, import_echo_pipeline4.encodeReference)(E.getTypeReference(import_client_protocol4.Properties))
5720
+ type: (0, import_echo_pipeline5.encodeReference)((0, import_echo_schema2.getTypeReference)(import_client_protocol5.Properties))
5594
5721
  },
5595
5722
  data: {
5596
- [import_client_protocol4.defaultKey]: identity.identityKey.toHex()
5723
+ [import_client_protocol5.defaultKey]: identity.identityKey.toHex()
5597
5724
  },
5598
5725
  meta: {
5599
5726
  keys: []
5600
5727
  }
5601
5728
  };
5602
- const propertiesId = import_keys11.PublicKey.random().toHex();
5729
+ const propertiesId = import_keys12.PublicKey.random().toHex();
5603
5730
  document.change((doc) => {
5604
5731
  (0, import_util9.assignDeep)(doc, [
5605
5732
  "objects",
5606
5733
  propertiesId
5607
5734
  ], properties);
5608
5735
  });
5609
- await this._serviceContext.automergeHost.repo.flush();
5736
+ await this._serviceContext.echoHost.flush();
5610
5737
  return identity;
5611
5738
  }
5612
5739
  };
@@ -5634,7 +5761,7 @@ var DiagnosticsCollector = class {
5634
5761
  }
5635
5762
  static async collect(config = findConfigs(), services = findSystemServiceProvider(), options = {}) {
5636
5763
  const serviceDiagnostics = await services?.services?.SystemService?.getDiagnostics({
5637
- keys: options.humanize ? import_services13.GetDiagnosticsRequest.KEY_OPTION.HUMANIZE : options.truncate ? import_services13.GetDiagnosticsRequest.KEY_OPTION.TRUNCATE : void 0
5764
+ keys: options.humanize ? import_services14.GetDiagnosticsRequest.KEY_OPTION.HUMANIZE : options.truncate ? import_services14.GetDiagnosticsRequest.KEY_OPTION.TRUNCATE : void 0
5638
5765
  });
5639
5766
  const clientDiagnostics = {
5640
5767
  config,
@@ -5674,6 +5801,7 @@ var findConfigs = () => {
5674
5801
  IdentityManager,
5675
5802
  IdentityServiceImpl,
5676
5803
  InvitationsHandler,
5804
+ InvitationsManager,
5677
5805
  InvitationsServiceImpl,
5678
5806
  Lock,
5679
5807
  ServiceContext,
@@ -5681,6 +5809,7 @@ var findConfigs = () => {
5681
5809
  SpaceInvitationProtocol,
5682
5810
  SpacesServiceImpl,
5683
5811
  TrustedKeySetAuthVerifier,
5812
+ createAdmissionKeypair,
5684
5813
  createAuthProvider,
5685
5814
  createCollectDiagnosticsBroadcastHandler,
5686
5815
  createCollectDiagnosticsBroadcastSender,
@@ -5688,7 +5817,6 @@ var findConfigs = () => {
5688
5817
  createLevel,
5689
5818
  createStorageObjects,
5690
5819
  getNetworkPeers,
5691
- invitationExpired,
5692
5820
  isLocked,
5693
5821
  subscribeToFeedBlocks,
5694
5822
  subscribeToFeeds,
@@ -5698,4 +5826,4 @@ var findConfigs = () => {
5698
5826
  subscribeToSpaces,
5699
5827
  subscribeToSwarmInfo
5700
5828
  });
5701
- //# sourceMappingURL=chunk-JSVLZGJM.cjs.map
5829
+ //# sourceMappingURL=chunk-PP42CXTU.cjs.map