@dxos/client-services 0.5.1-main.ff7d242 → 0.5.1-next.0ef769d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/{chunk-7AHPYPLI.mjs → chunk-EZDHZKXT.mjs} +1296 -940
- package/dist/lib/browser/chunk-EZDHZKXT.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +31 -2
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/packlets/testing/index.mjs +29 -9
- package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
- package/dist/lib/node/{chunk-HBT5F5OI.cjs → chunk-4E7K7B6U.cjs} +1459 -1111
- package/dist/lib/node/chunk-4E7K7B6U.cjs.map +7 -0
- package/dist/lib/node/index.cjs +73 -44
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/packlets/testing/index.cjs +35 -15
- package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
- package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts +2 -1
- package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitation-guest-extenstion.d.ts +39 -0
- package/dist/types/src/packlets/invitations/invitation-guest-extenstion.d.ts.map +1 -0
- package/dist/types/src/packlets/invitations/{invitation-extension.d.ts → invitation-host-extension.d.ts} +17 -31
- package/dist/types/src/packlets/invitations/invitation-host-extension.d.ts.map +1 -0
- package/dist/types/src/packlets/invitations/invitation-protocol.d.ts +6 -1
- package/dist/types/src/packlets/invitations/invitation-protocol.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitation-topology.d.ts +37 -0
- package/dist/types/src/packlets/invitations/invitation-topology.d.ts.map +1 -0
- package/dist/types/src/packlets/invitations/invitations-handler.d.ts +19 -10
- package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitations-handler.test.d.ts +2 -0
- package/dist/types/src/packlets/invitations/invitations-handler.test.d.ts.map +1 -0
- package/dist/types/src/packlets/invitations/invitations-manager.d.ts +2 -1
- package/dist/types/src/packlets/invitations/invitations-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts +1 -0
- package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/utils.d.ts +6 -0
- package/dist/types/src/packlets/invitations/utils.d.ts.map +1 -0
- package/dist/types/src/packlets/services/service-context.d.ts +8 -5
- package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-host.d.ts +1 -1
- package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
- package/dist/types/src/packlets/storage/level.d.ts +1 -2
- package/dist/types/src/packlets/storage/level.d.ts.map +1 -1
- package/dist/types/src/packlets/testing/invitation-utils.d.ts +2 -1
- package/dist/types/src/packlets/testing/invitation-utils.d.ts.map +1 -1
- package/dist/types/src/packlets/testing/test-builder.d.ts +2 -1
- package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
- package/dist/types/src/packlets/vault/shell-runtime.d.ts +10 -2
- package/dist/types/src/packlets/vault/shell-runtime.d.ts.map +1 -1
- package/dist/types/src/version.d.ts +1 -1
- package/package.json +36 -35
- package/src/packlets/invitations/device-invitation-protocol.ts +5 -1
- package/src/packlets/invitations/invitation-guest-extenstion.ts +126 -0
- package/src/packlets/invitations/{invitation-extension.ts → invitation-host-extension.ts} +99 -105
- package/src/packlets/invitations/invitation-protocol.ts +7 -1
- package/src/packlets/invitations/invitation-topology.ts +87 -0
- package/src/packlets/invitations/invitations-handler.test.ts +361 -0
- package/src/packlets/invitations/invitations-handler.ts +246 -149
- package/src/packlets/invitations/invitations-manager.ts +42 -3
- package/src/packlets/invitations/space-invitation-protocol.ts +19 -1
- package/src/packlets/invitations/utils.ts +27 -0
- package/src/packlets/services/automerge-host.test.ts +3 -1
- package/src/packlets/services/service-context.ts +7 -6
- package/src/packlets/services/service-host.ts +3 -4
- package/src/packlets/spaces/data-space.ts +2 -1
- package/src/packlets/storage/level.ts +2 -2
- package/src/packlets/testing/invitation-utils.ts +23 -3
- package/src/packlets/testing/test-builder.ts +6 -3
- package/src/packlets/vault/shell-runtime.ts +40 -2
- package/src/version.ts +1 -1
- package/dist/lib/browser/chunk-7AHPYPLI.mjs.map +0 -7
- package/dist/lib/node/chunk-HBT5F5OI.cjs.map +0 -7
- package/dist/types/src/packlets/invitations/invitation-extension.d.ts.map +0 -1
|
@@ -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
|
|
30
|
-
__export(
|
|
29
|
+
var chunk_4E7K7B6U_exports = {};
|
|
30
|
+
__export(chunk_4E7K7B6U_exports, {
|
|
31
31
|
ClientRpcServer: () => ClientRpcServer,
|
|
32
32
|
ClientServicesHost: () => ClientServicesHost,
|
|
33
33
|
ClientServicesProviderResource: () => ClientServicesProviderResource,
|
|
@@ -66,7 +66,7 @@ __export(chunk_HBT5F5OI_exports, {
|
|
|
66
66
|
subscribeToSpaces: () => subscribeToSpaces,
|
|
67
67
|
subscribeToSwarmInfo: () => subscribeToSwarmInfo
|
|
68
68
|
});
|
|
69
|
-
module.exports = __toCommonJS(
|
|
69
|
+
module.exports = __toCommonJS(chunk_4E7K7B6U_exports);
|
|
70
70
|
var import_async = require("@dxos/async");
|
|
71
71
|
var import_codec_protobuf = require("@dxos/codec-protobuf");
|
|
72
72
|
var import_feed_store = require("@dxos/feed-store");
|
|
@@ -128,155 +128,171 @@ var import_network_manager = require("@dxos/network-manager");
|
|
|
128
128
|
var import_protocols4 = require("@dxos/protocols");
|
|
129
129
|
var import_services3 = require("@dxos/protocols/proto/dxos/client/services");
|
|
130
130
|
var import_invitations = require("@dxos/protocols/proto/dxos/halo/invitations");
|
|
131
|
+
var import_invitations2 = require("@dxos/protocols/proto/dxos/halo/invitations");
|
|
132
|
+
var import_util4 = require("@dxos/util");
|
|
131
133
|
var import_async8 = require("@dxos/async");
|
|
132
134
|
var import_context5 = require("@dxos/context");
|
|
133
|
-
var import_crypto2 = require("@dxos/crypto");
|
|
134
135
|
var import_invariant6 = require("@dxos/invariant");
|
|
135
|
-
var import_keys6 = require("@dxos/keys");
|
|
136
136
|
var import_log5 = require("@dxos/log");
|
|
137
137
|
var import_protocols5 = require("@dxos/protocols");
|
|
138
|
-
var
|
|
139
|
-
var import_invitations2 = require("@dxos/protocols/proto/dxos/halo/invitations");
|
|
138
|
+
var import_invitations3 = require("@dxos/protocols/proto/dxos/halo/invitations");
|
|
140
139
|
var import_teleport = require("@dxos/teleport");
|
|
141
|
-
var
|
|
142
|
-
var
|
|
143
|
-
var
|
|
144
|
-
var
|
|
140
|
+
var import_context6 = require("@dxos/context");
|
|
141
|
+
var import_services4 = require("@dxos/protocols/proto/dxos/client/services");
|
|
142
|
+
var import_async9 = require("@dxos/async");
|
|
143
|
+
var import_context7 = require("@dxos/context");
|
|
144
|
+
var import_crypto2 = require("@dxos/crypto");
|
|
145
145
|
var import_invariant7 = require("@dxos/invariant");
|
|
146
|
+
var import_keys6 = require("@dxos/keys");
|
|
146
147
|
var import_log6 = require("@dxos/log");
|
|
147
148
|
var import_protocols6 = require("@dxos/protocols");
|
|
149
|
+
var import_services5 = require("@dxos/protocols/proto/dxos/client/services");
|
|
150
|
+
var import_invitations4 = require("@dxos/protocols/proto/dxos/halo/invitations");
|
|
151
|
+
var import_teleport2 = require("@dxos/teleport");
|
|
152
|
+
var import_invariant8 = require("@dxos/invariant");
|
|
153
|
+
var import_keys7 = require("@dxos/keys");
|
|
154
|
+
var import_log7 = require("@dxos/log");
|
|
155
|
+
var import_invitations5 = require("@dxos/protocols/proto/dxos/halo/invitations");
|
|
156
|
+
var import_util5 = require("@dxos/util");
|
|
157
|
+
var import_codec_protobuf8 = require("@dxos/codec-protobuf");
|
|
148
158
|
var import_services6 = require("@dxos/protocols/proto/dxos/client/services");
|
|
159
|
+
var import_credentials7 = require("@dxos/credentials");
|
|
160
|
+
var import_feed_store3 = require("@dxos/feed-store");
|
|
161
|
+
var import_invariant9 = require("@dxos/invariant");
|
|
162
|
+
var import_log8 = require("@dxos/log");
|
|
163
|
+
var import_protocols7 = require("@dxos/protocols");
|
|
164
|
+
var import_services7 = require("@dxos/protocols/proto/dxos/client/services");
|
|
149
165
|
var import_credentials8 = require("@dxos/protocols/proto/dxos/halo/credentials");
|
|
150
|
-
var
|
|
166
|
+
var import_async10 = require("@dxos/async");
|
|
151
167
|
var import_client_protocol3 = require("@dxos/client-protocol");
|
|
152
|
-
var
|
|
168
|
+
var import_context8 = require("@dxos/context");
|
|
153
169
|
var import_credentials9 = require("@dxos/credentials");
|
|
154
170
|
var import_echo_pipeline = require("@dxos/echo-pipeline");
|
|
155
|
-
var
|
|
156
|
-
var
|
|
157
|
-
var
|
|
158
|
-
var
|
|
171
|
+
var import_invariant10 = require("@dxos/invariant");
|
|
172
|
+
var import_keys8 = require("@dxos/keys");
|
|
173
|
+
var import_log9 = require("@dxos/log");
|
|
174
|
+
var import_services8 = require("@dxos/protocols/proto/dxos/client/services");
|
|
159
175
|
var import_codec_protobuf9 = require("@dxos/codec-protobuf");
|
|
160
176
|
var import_debug2 = require("@dxos/debug");
|
|
161
177
|
var import_rpc = require("@dxos/rpc");
|
|
162
178
|
var import_tracing3 = require("@dxos/tracing");
|
|
163
|
-
var
|
|
179
|
+
var import_async11 = require("@dxos/async");
|
|
164
180
|
var import_client_protocol4 = require("@dxos/client-protocol");
|
|
165
|
-
var
|
|
181
|
+
var import_context9 = require("@dxos/context");
|
|
166
182
|
var import_debug3 = require("@dxos/debug");
|
|
167
183
|
var import_echo_pipeline2 = require("@dxos/echo-pipeline");
|
|
168
184
|
var import_echo_pipeline3 = require("@dxos/echo-pipeline");
|
|
169
185
|
var import_echo_schema = require("@dxos/echo-schema");
|
|
170
|
-
var
|
|
171
|
-
var
|
|
172
|
-
var
|
|
173
|
-
var
|
|
174
|
-
var
|
|
186
|
+
var import_invariant11 = require("@dxos/invariant");
|
|
187
|
+
var import_keys9 = require("@dxos/keys");
|
|
188
|
+
var import_log10 = require("@dxos/log");
|
|
189
|
+
var import_protocols8 = require("@dxos/protocols");
|
|
190
|
+
var import_services9 = require("@dxos/protocols/proto/dxos/client/services");
|
|
175
191
|
var import_credentials10 = require("@dxos/protocols/proto/dxos/halo/credentials");
|
|
176
192
|
var import_timeframe2 = require("@dxos/timeframe");
|
|
177
193
|
var import_tracing4 = require("@dxos/tracing");
|
|
178
|
-
var
|
|
179
|
-
var import_async11 = require("@dxos/async");
|
|
180
|
-
var import_credentials11 = require("@dxos/credentials");
|
|
194
|
+
var import_util6 = require("@dxos/util");
|
|
181
195
|
var import_async12 = require("@dxos/async");
|
|
182
|
-
var
|
|
183
|
-
var import_invariant10 = require("@dxos/invariant");
|
|
184
|
-
var import_keys9 = require("@dxos/keys");
|
|
185
|
-
var import_log9 = require("@dxos/log");
|
|
186
|
-
var import_protocols8 = require("@dxos/protocols");
|
|
187
|
-
var import_teleport2 = require("@dxos/teleport");
|
|
188
|
-
var import_util5 = require("@dxos/util");
|
|
196
|
+
var import_credentials11 = require("@dxos/credentials");
|
|
189
197
|
var import_async13 = require("@dxos/async");
|
|
190
|
-
var
|
|
191
|
-
var
|
|
192
|
-
var import_invariant11 = require("@dxos/invariant");
|
|
198
|
+
var import_context10 = require("@dxos/context");
|
|
199
|
+
var import_invariant12 = require("@dxos/invariant");
|
|
193
200
|
var import_keys10 = require("@dxos/keys");
|
|
194
|
-
var
|
|
201
|
+
var import_log11 = require("@dxos/log");
|
|
195
202
|
var import_protocols9 = require("@dxos/protocols");
|
|
196
|
-
var
|
|
203
|
+
var import_teleport3 = require("@dxos/teleport");
|
|
204
|
+
var import_util7 = require("@dxos/util");
|
|
205
|
+
var import_async14 = require("@dxos/async");
|
|
206
|
+
var import_context11 = require("@dxos/context");
|
|
207
|
+
var import_credentials12 = require("@dxos/credentials");
|
|
208
|
+
var import_invariant13 = require("@dxos/invariant");
|
|
209
|
+
var import_keys11 = require("@dxos/keys");
|
|
210
|
+
var import_log12 = require("@dxos/log");
|
|
211
|
+
var import_protocols10 = require("@dxos/protocols");
|
|
212
|
+
var import_services10 = require("@dxos/protocols/proto/dxos/client/services");
|
|
197
213
|
var import_teleport_extension_gossip2 = require("@dxos/teleport-extension-gossip");
|
|
198
|
-
var
|
|
214
|
+
var import_util8 = require("@dxos/util");
|
|
199
215
|
var import_credentials13 = require("@dxos/credentials");
|
|
200
216
|
var import_debug4 = require("@dxos/debug");
|
|
201
217
|
var import_credentials14 = require("@dxos/protocols/proto/dxos/halo/credentials");
|
|
202
218
|
var import_timeframe3 = require("@dxos/timeframe");
|
|
203
|
-
var
|
|
219
|
+
var import_async15 = require("@dxos/async");
|
|
204
220
|
var import_codec_protobuf10 = require("@dxos/codec-protobuf");
|
|
205
221
|
var import_debug5 = require("@dxos/debug");
|
|
206
|
-
var
|
|
207
|
-
var
|
|
208
|
-
var
|
|
209
|
-
var
|
|
210
|
-
var
|
|
211
|
-
var
|
|
222
|
+
var import_invariant14 = require("@dxos/invariant");
|
|
223
|
+
var import_log13 = require("@dxos/log");
|
|
224
|
+
var import_protocols11 = require("@dxos/protocols");
|
|
225
|
+
var import_services11 = require("@dxos/protocols/proto/dxos/client/services");
|
|
226
|
+
var import_async16 = require("@dxos/async");
|
|
227
|
+
var import_context12 = require("@dxos/context");
|
|
212
228
|
var import_credentials15 = require("@dxos/credentials");
|
|
213
229
|
var import_debug6 = require("@dxos/debug");
|
|
214
230
|
var import_echo_db = require("@dxos/echo-db");
|
|
215
231
|
var import_echo_pipeline4 = require("@dxos/echo-pipeline");
|
|
216
232
|
var import_feed_store4 = require("@dxos/feed-store");
|
|
217
|
-
var
|
|
233
|
+
var import_invariant15 = require("@dxos/invariant");
|
|
218
234
|
var import_keyring = require("@dxos/keyring");
|
|
219
|
-
var
|
|
220
|
-
var
|
|
221
|
-
var
|
|
222
|
-
var
|
|
235
|
+
var import_keys12 = require("@dxos/keys");
|
|
236
|
+
var import_log14 = require("@dxos/log");
|
|
237
|
+
var import_protocols12 = require("@dxos/protocols");
|
|
238
|
+
var import_services12 = require("@dxos/protocols/proto/dxos/client/services");
|
|
223
239
|
var import_teleport_extension_object_sync = require("@dxos/teleport-extension-object-sync");
|
|
224
240
|
var import_tracing5 = require("@dxos/tracing");
|
|
225
|
-
var
|
|
241
|
+
var import_util9 = require("@dxos/util");
|
|
226
242
|
var import_codec_protobuf11 = require("@dxos/codec-protobuf");
|
|
227
243
|
var import_credentials16 = require("@dxos/credentials");
|
|
228
|
-
var
|
|
229
|
-
var
|
|
230
|
-
var import_services12 = require("@dxos/protocols/proto/dxos/client/services");
|
|
231
|
-
var import_tracing6 = require("@dxos/tracing");
|
|
244
|
+
var import_invariant16 = require("@dxos/invariant");
|
|
245
|
+
var import_protocols13 = require("@dxos/protocols");
|
|
232
246
|
var import_services13 = require("@dxos/protocols/proto/dxos/client/services");
|
|
233
|
-
var
|
|
247
|
+
var import_tracing6 = require("@dxos/tracing");
|
|
234
248
|
var import_services14 = require("@dxos/protocols/proto/dxos/client/services");
|
|
249
|
+
var import_config = require("@dxos/config");
|
|
250
|
+
var import_services15 = require("@dxos/protocols/proto/dxos/client/services");
|
|
235
251
|
var import_tracing7 = require("@dxos/tracing");
|
|
236
|
-
var
|
|
237
|
-
var
|
|
252
|
+
var import_util10 = require("@dxos/util");
|
|
253
|
+
var import_async17 = require("@dxos/async");
|
|
238
254
|
var import_client_protocol5 = require("@dxos/client-protocol");
|
|
239
|
-
var
|
|
240
|
-
var
|
|
255
|
+
var import_context13 = require("@dxos/context");
|
|
256
|
+
var import_echo_protocol = require("@dxos/echo-protocol");
|
|
241
257
|
var import_echo_schema2 = require("@dxos/echo-schema");
|
|
242
|
-
var
|
|
243
|
-
var
|
|
244
|
-
var
|
|
258
|
+
var import_invariant17 = require("@dxos/invariant");
|
|
259
|
+
var import_keys13 = require("@dxos/keys");
|
|
260
|
+
var import_log15 = require("@dxos/log");
|
|
245
261
|
var import_messaging = require("@dxos/messaging");
|
|
246
262
|
var import_network_manager2 = require("@dxos/network-manager");
|
|
247
|
-
var
|
|
248
|
-
var
|
|
263
|
+
var import_protocols14 = require("@dxos/protocols");
|
|
264
|
+
var import_services16 = require("@dxos/protocols/proto/dxos/client/services");
|
|
249
265
|
var import_tracing8 = require("@dxos/tracing");
|
|
250
|
-
var
|
|
266
|
+
var import_util11 = require("@dxos/util");
|
|
251
267
|
var import_websocket_rpc = require("@dxos/websocket-rpc");
|
|
252
|
-
var
|
|
268
|
+
var import_async18 = require("@dxos/async");
|
|
253
269
|
var import_codec_protobuf12 = require("@dxos/codec-protobuf");
|
|
254
|
-
var
|
|
255
|
-
var
|
|
256
|
-
var
|
|
270
|
+
var import_invariant18 = require("@dxos/invariant");
|
|
271
|
+
var import_services17 = require("@dxos/protocols/proto/dxos/client/services");
|
|
272
|
+
var import_invariant19 = require("@dxos/invariant");
|
|
257
273
|
var import_lock_file = require("@dxos/lock-file");
|
|
258
|
-
var
|
|
259
|
-
var
|
|
274
|
+
var import_log16 = require("@dxos/log");
|
|
275
|
+
var import_async19 = require("@dxos/async");
|
|
260
276
|
var import_codec_protobuf13 = require("@dxos/codec-protobuf");
|
|
261
|
-
var
|
|
262
|
-
var
|
|
263
|
-
var
|
|
264
|
-
var
|
|
277
|
+
var import_keys14 = require("@dxos/keys");
|
|
278
|
+
var import_log17 = require("@dxos/log");
|
|
279
|
+
var import_services18 = require("@dxos/protocols/proto/dxos/client/services");
|
|
280
|
+
var import_util12 = require("@dxos/util");
|
|
265
281
|
var import_codec_protobuf14 = require("@dxos/codec-protobuf");
|
|
266
|
-
var
|
|
282
|
+
var import_protocols15 = require("@dxos/protocols");
|
|
267
283
|
var import_config2 = require("@dxos/protocols/proto/dxos/config");
|
|
268
284
|
var import_random_access_storage = require("@dxos/random-access-storage");
|
|
269
285
|
var import_client_protocol6 = require("@dxos/client-protocol");
|
|
270
286
|
var import_config3 = require("@dxos/protocols/proto/dxos/config");
|
|
271
|
-
var
|
|
272
|
-
var import_level = require("level");
|
|
287
|
+
var import_util13 = require("@dxos/util");
|
|
273
288
|
var import_node_path = __toESM(require("node:path"));
|
|
274
|
-
var import_keys14 = require("@dxos/keys");
|
|
275
|
-
var import_codec_protobuf15 = require("@dxos/codec-protobuf");
|
|
276
|
-
var import_services18 = require("@dxos/protocols/proto/dxos/client/services");
|
|
277
|
-
var import_util12 = require("@dxos/util");
|
|
278
289
|
var import_keys15 = require("@dxos/keys");
|
|
279
|
-
var
|
|
290
|
+
var import_kv_store = require("@dxos/kv-store");
|
|
291
|
+
var import_codec_protobuf15 = require("@dxos/codec-protobuf");
|
|
292
|
+
var import_services19 = require("@dxos/protocols/proto/dxos/client/services");
|
|
293
|
+
var import_util14 = require("@dxos/util");
|
|
294
|
+
var import_keys16 = require("@dxos/keys");
|
|
295
|
+
var import_util15 = require("@dxos/util");
|
|
280
296
|
var subscribeToFeeds = ({ feedStore }, { feedKeys }) => {
|
|
281
297
|
return new import_codec_protobuf.Stream(({ next }) => {
|
|
282
298
|
const subscriptions = new import_async.EventSubscriptions();
|
|
@@ -1393,13 +1409,16 @@ var DeviceInvitationProtocol = class {
|
|
|
1393
1409
|
kind: import_services2.Invitation.Kind.DEVICE
|
|
1394
1410
|
};
|
|
1395
1411
|
}
|
|
1396
|
-
async delegate(
|
|
1412
|
+
async delegate() {
|
|
1413
|
+
throw new Error("delegation not supported");
|
|
1414
|
+
}
|
|
1415
|
+
async cancelDelegation() {
|
|
1397
1416
|
throw new Error("delegation not supported");
|
|
1398
1417
|
}
|
|
1399
1418
|
async admit(_, request) {
|
|
1400
1419
|
(0, import_invariant4.invariant)(request.device, void 0, {
|
|
1401
1420
|
F: __dxlog_file5,
|
|
1402
|
-
L:
|
|
1421
|
+
L: 46,
|
|
1403
1422
|
S: this,
|
|
1404
1423
|
A: [
|
|
1405
1424
|
"request.device",
|
|
@@ -1445,7 +1464,7 @@ var DeviceInvitationProtocol = class {
|
|
|
1445
1464
|
async accept(response, request) {
|
|
1446
1465
|
(0, import_invariant4.invariant)(response.device, void 0, {
|
|
1447
1466
|
F: __dxlog_file5,
|
|
1448
|
-
L:
|
|
1467
|
+
L: 91,
|
|
1449
1468
|
S: this,
|
|
1450
1469
|
A: [
|
|
1451
1470
|
"response.device",
|
|
@@ -1455,7 +1474,7 @@ var DeviceInvitationProtocol = class {
|
|
|
1455
1474
|
const { identityKey, haloSpaceKey, genesisFeedKey, controlTimeframe } = response.device;
|
|
1456
1475
|
(0, import_invariant4.invariant)(request.device, void 0, {
|
|
1457
1476
|
F: __dxlog_file5,
|
|
1458
|
-
L:
|
|
1477
|
+
L: 94,
|
|
1459
1478
|
S: this,
|
|
1460
1479
|
A: [
|
|
1461
1480
|
"request.device",
|
|
@@ -1478,11 +1497,25 @@ var DeviceInvitationProtocol = class {
|
|
|
1478
1497
|
};
|
|
1479
1498
|
}
|
|
1480
1499
|
};
|
|
1481
|
-
var
|
|
1500
|
+
var stateToString = (state) => {
|
|
1501
|
+
return Object.entries(import_services4.Invitation.State).find(([key, val]) => val === state)?.[0] ?? "unknown";
|
|
1502
|
+
};
|
|
1503
|
+
var tryAcquireBeforeContextDisposed = async (ctx, mutex) => {
|
|
1504
|
+
let guard;
|
|
1505
|
+
return (0, import_context6.cancelWithContext)(ctx, (async () => {
|
|
1506
|
+
guard = await mutex.acquire();
|
|
1507
|
+
if (ctx.disposed) {
|
|
1508
|
+
guard.release();
|
|
1509
|
+
guard = void 0;
|
|
1510
|
+
throw new import_context6.ContextDisposedError();
|
|
1511
|
+
}
|
|
1512
|
+
return guard;
|
|
1513
|
+
})());
|
|
1514
|
+
};
|
|
1515
|
+
var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-guest-extenstion.ts";
|
|
1482
1516
|
var OPTIONS_TIMEOUT = 1e4;
|
|
1483
|
-
var
|
|
1484
|
-
|
|
1485
|
-
constructor(_callbacks) {
|
|
1517
|
+
var InvitationGuestExtension = class extends import_teleport.RpcExtension {
|
|
1518
|
+
constructor(_invitationFlowMutex, _callbacks) {
|
|
1486
1519
|
super({
|
|
1487
1520
|
requested: {
|
|
1488
1521
|
InvitationHostService: import_protocols5.schema.getService("dxos.halo.invitations.InvitationHostService")
|
|
@@ -1491,25 +1524,22 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
|
|
|
1491
1524
|
InvitationHostService: import_protocols5.schema.getService("dxos.halo.invitations.InvitationHostService")
|
|
1492
1525
|
}
|
|
1493
1526
|
});
|
|
1527
|
+
this._invitationFlowMutex = _invitationFlowMutex;
|
|
1494
1528
|
this._callbacks = _callbacks;
|
|
1495
1529
|
this._ctx = new import_context5.Context();
|
|
1496
1530
|
this._remoteOptionsTrigger = new import_async8.Trigger();
|
|
1497
|
-
this.
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
this.
|
|
1501
|
-
this.authenticationRetry = 0;
|
|
1502
|
-
this.completedTrigger = new import_async8.Trigger();
|
|
1531
|
+
this._invitationFlowLock = null;
|
|
1532
|
+
}
|
|
1533
|
+
hasFlowLock() {
|
|
1534
|
+
return this._invitationFlowLock != null;
|
|
1503
1535
|
}
|
|
1504
1536
|
async getHandlers() {
|
|
1505
1537
|
return {
|
|
1506
|
-
// TODO(dmaretskyi): For now this is just forwarding the data to callbacks since we don't have session-specific logic.
|
|
1507
|
-
// Perhaps in the future we will have more complex logic here.
|
|
1508
1538
|
InvitationHostService: {
|
|
1509
1539
|
options: async (options) => {
|
|
1510
1540
|
(0, import_invariant6.invariant)(!this._remoteOptions, "Remote options already set.", {
|
|
1511
1541
|
F: __dxlog_file6,
|
|
1512
|
-
L:
|
|
1542
|
+
L: 63,
|
|
1513
1543
|
S: this,
|
|
1514
1544
|
A: [
|
|
1515
1545
|
"!this._remoteOptions",
|
|
@@ -1519,190 +1549,14 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
|
|
|
1519
1549
|
this._remoteOptions = options;
|
|
1520
1550
|
this._remoteOptionsTrigger.wake();
|
|
1521
1551
|
},
|
|
1522
|
-
introduce:
|
|
1523
|
-
|
|
1524
|
-
const traceId = import_keys6.PublicKey.random().toHex();
|
|
1525
|
-
import_log5.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols5.trace.begin({
|
|
1526
|
-
id: traceId
|
|
1527
|
-
}), {
|
|
1528
|
-
F: __dxlog_file6,
|
|
1529
|
-
L: 99,
|
|
1530
|
-
S: this,
|
|
1531
|
-
C: (f, a) => f(...a)
|
|
1532
|
-
});
|
|
1533
|
-
const invitation = await this._callbacks.resolveInvitation(request);
|
|
1534
|
-
if (!invitation) {
|
|
1535
|
-
import_log5.log.warn("invitation not found", {
|
|
1536
|
-
invitationId
|
|
1537
|
-
}, {
|
|
1538
|
-
F: __dxlog_file6,
|
|
1539
|
-
L: 103,
|
|
1540
|
-
S: this,
|
|
1541
|
-
C: (f, a) => f(...a)
|
|
1542
|
-
});
|
|
1543
|
-
this._callbacks.onError(new Error("Invitation not found."));
|
|
1544
|
-
return {
|
|
1545
|
-
authMethod: import_services4.Invitation.AuthMethod.NONE
|
|
1546
|
-
};
|
|
1547
|
-
}
|
|
1548
|
-
this.invitation = invitation;
|
|
1549
|
-
(0, import_log5.log)("guest introduced itself", {
|
|
1550
|
-
guestProfile: profile
|
|
1551
|
-
}, {
|
|
1552
|
-
F: __dxlog_file6,
|
|
1553
|
-
L: 112,
|
|
1554
|
-
S: this,
|
|
1555
|
-
C: (f, a) => f(...a)
|
|
1556
|
-
});
|
|
1557
|
-
this.guestProfile = profile;
|
|
1558
|
-
this._callbacks.onStateUpdate({
|
|
1559
|
-
...this.invitation,
|
|
1560
|
-
state: import_services4.Invitation.State.READY_FOR_AUTHENTICATION
|
|
1561
|
-
});
|
|
1562
|
-
this._challenge = this.invitation.authMethod === import_services4.Invitation.AuthMethod.KNOWN_PUBLIC_KEY ? (0, import_crypto2.randomBytes)(32) : void 0;
|
|
1563
|
-
import_log5.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols5.trace.end({
|
|
1564
|
-
id: traceId
|
|
1565
|
-
}), {
|
|
1566
|
-
F: __dxlog_file6,
|
|
1567
|
-
L: 122,
|
|
1568
|
-
S: this,
|
|
1569
|
-
C: (f, a) => f(...a)
|
|
1570
|
-
});
|
|
1571
|
-
return {
|
|
1572
|
-
authMethod: this.invitation.authMethod,
|
|
1573
|
-
challenge: this._challenge
|
|
1574
|
-
};
|
|
1552
|
+
introduce: () => {
|
|
1553
|
+
throw new Error("Method not allowed.");
|
|
1575
1554
|
},
|
|
1576
|
-
authenticate:
|
|
1577
|
-
|
|
1578
|
-
import_log5.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols5.trace.begin({
|
|
1579
|
-
id: traceId
|
|
1580
|
-
}), {
|
|
1581
|
-
F: __dxlog_file6,
|
|
1582
|
-
L: 131,
|
|
1583
|
-
S: this,
|
|
1584
|
-
C: (f, a) => f(...a)
|
|
1585
|
-
});
|
|
1586
|
-
(0, import_log5.log)("received authentication request", {
|
|
1587
|
-
authCode: code
|
|
1588
|
-
}, {
|
|
1589
|
-
F: __dxlog_file6,
|
|
1590
|
-
L: 132,
|
|
1591
|
-
S: this,
|
|
1592
|
-
C: (f, a) => f(...a)
|
|
1593
|
-
});
|
|
1594
|
-
let status = import_invitations2.AuthenticationResponse.Status.OK;
|
|
1595
|
-
(0, import_invariant6.invariant)(this.invitation, "Invitation is not set.", {
|
|
1596
|
-
F: __dxlog_file6,
|
|
1597
|
-
L: 135,
|
|
1598
|
-
S: this,
|
|
1599
|
-
A: [
|
|
1600
|
-
"this.invitation",
|
|
1601
|
-
"'Invitation is not set.'"
|
|
1602
|
-
]
|
|
1603
|
-
});
|
|
1604
|
-
switch (this.invitation.authMethod) {
|
|
1605
|
-
case import_services4.Invitation.AuthMethod.NONE: {
|
|
1606
|
-
(0, import_log5.log)("authentication not required", void 0, {
|
|
1607
|
-
F: __dxlog_file6,
|
|
1608
|
-
L: 138,
|
|
1609
|
-
S: this,
|
|
1610
|
-
C: (f, a) => f(...a)
|
|
1611
|
-
});
|
|
1612
|
-
return {
|
|
1613
|
-
status: import_invitations2.AuthenticationResponse.Status.OK
|
|
1614
|
-
};
|
|
1615
|
-
}
|
|
1616
|
-
case import_services4.Invitation.AuthMethod.SHARED_SECRET: {
|
|
1617
|
-
if (this.invitation.authCode) {
|
|
1618
|
-
if (this.authenticationRetry++ > MAX_OTP_ATTEMPTS) {
|
|
1619
|
-
status = import_invitations2.AuthenticationResponse.Status.INVALID_OPT_ATTEMPTS;
|
|
1620
|
-
} else if (code !== this.invitation.authCode) {
|
|
1621
|
-
status = import_invitations2.AuthenticationResponse.Status.INVALID_OTP;
|
|
1622
|
-
} else {
|
|
1623
|
-
this.authenticationPassed = true;
|
|
1624
|
-
}
|
|
1625
|
-
}
|
|
1626
|
-
break;
|
|
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
|
-
}
|
|
1641
|
-
default: {
|
|
1642
|
-
import_log5.log.error("invalid authentication method", {
|
|
1643
|
-
authMethod: this.invitation.authMethod
|
|
1644
|
-
}, {
|
|
1645
|
-
F: __dxlog_file6,
|
|
1646
|
-
L: 176,
|
|
1647
|
-
S: this,
|
|
1648
|
-
C: (f, a) => f(...a)
|
|
1649
|
-
});
|
|
1650
|
-
status = import_invitations2.AuthenticationResponse.Status.INTERNAL_ERROR;
|
|
1651
|
-
break;
|
|
1652
|
-
}
|
|
1653
|
-
}
|
|
1654
|
-
import_log5.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols5.trace.end({
|
|
1655
|
-
id: traceId,
|
|
1656
|
-
data: {
|
|
1657
|
-
status
|
|
1658
|
-
}
|
|
1659
|
-
}), {
|
|
1660
|
-
F: __dxlog_file6,
|
|
1661
|
-
L: 182,
|
|
1662
|
-
S: this,
|
|
1663
|
-
C: (f, a) => f(...a)
|
|
1664
|
-
});
|
|
1665
|
-
return {
|
|
1666
|
-
status
|
|
1667
|
-
};
|
|
1555
|
+
authenticate: () => {
|
|
1556
|
+
throw new Error("Method not allowed.");
|
|
1668
1557
|
},
|
|
1669
|
-
admit:
|
|
1670
|
-
|
|
1671
|
-
import_log5.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols5.trace.begin({
|
|
1672
|
-
id: traceId
|
|
1673
|
-
}), {
|
|
1674
|
-
F: __dxlog_file6,
|
|
1675
|
-
L: 188,
|
|
1676
|
-
S: this,
|
|
1677
|
-
C: (f, a) => f(...a)
|
|
1678
|
-
});
|
|
1679
|
-
try {
|
|
1680
|
-
(0, import_invariant6.invariant)(this.invitation, "Invitation is not set.", {
|
|
1681
|
-
F: __dxlog_file6,
|
|
1682
|
-
L: 191,
|
|
1683
|
-
S: this,
|
|
1684
|
-
A: [
|
|
1685
|
-
"this.invitation",
|
|
1686
|
-
"'Invitation is not set.'"
|
|
1687
|
-
]
|
|
1688
|
-
});
|
|
1689
|
-
if (isAuthenticationRequired(this.invitation) && !this.authenticationPassed) {
|
|
1690
|
-
throw new Error("Not authenticated");
|
|
1691
|
-
}
|
|
1692
|
-
const response = await this._callbacks.admit(request);
|
|
1693
|
-
import_log5.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols5.trace.end({
|
|
1694
|
-
id: traceId
|
|
1695
|
-
}), {
|
|
1696
|
-
F: __dxlog_file6,
|
|
1697
|
-
L: 199,
|
|
1698
|
-
S: this,
|
|
1699
|
-
C: (f, a) => f(...a)
|
|
1700
|
-
});
|
|
1701
|
-
return response;
|
|
1702
|
-
} catch (err) {
|
|
1703
|
-
this._callbacks.onError(err);
|
|
1704
|
-
throw err;
|
|
1705
|
-
}
|
|
1558
|
+
admit: () => {
|
|
1559
|
+
throw new Error("Method not allowed.");
|
|
1706
1560
|
}
|
|
1707
1561
|
}
|
|
1708
1562
|
};
|
|
@@ -1710,48 +1564,110 @@ var InvitationHostExtension = class extends import_teleport.RpcExtension {
|
|
|
1710
1564
|
async onOpen(context) {
|
|
1711
1565
|
await super.onOpen(context);
|
|
1712
1566
|
try {
|
|
1713
|
-
|
|
1714
|
-
|
|
1567
|
+
(0, import_log5.log)("guest acquire lock", void 0, {
|
|
1568
|
+
F: __dxlog_file6,
|
|
1569
|
+
L: 84,
|
|
1570
|
+
S: this,
|
|
1571
|
+
C: (f, a) => f(...a)
|
|
1572
|
+
});
|
|
1573
|
+
this._invitationFlowLock = await tryAcquireBeforeContextDisposed(this._ctx, this._invitationFlowMutex);
|
|
1574
|
+
(0, import_log5.log)("guest lock acquired", void 0, {
|
|
1575
|
+
F: __dxlog_file6,
|
|
1576
|
+
L: 86,
|
|
1577
|
+
S: this,
|
|
1578
|
+
C: (f, a) => f(...a)
|
|
1579
|
+
});
|
|
1580
|
+
await (0, import_context5.cancelWithContext)(this._ctx, this.rpc.InvitationHostService.options({
|
|
1581
|
+
role: import_invitations3.Options.Role.GUEST
|
|
1582
|
+
}));
|
|
1583
|
+
(0, import_log5.log)("options sent", void 0, {
|
|
1584
|
+
F: __dxlog_file6,
|
|
1585
|
+
L: 88,
|
|
1586
|
+
S: this,
|
|
1587
|
+
C: (f, a) => f(...a)
|
|
1715
1588
|
});
|
|
1716
1589
|
await (0, import_context5.cancelWithContext)(this._ctx, this._remoteOptionsTrigger.wait({
|
|
1717
1590
|
timeout: OPTIONS_TIMEOUT
|
|
1718
1591
|
}));
|
|
1719
|
-
|
|
1592
|
+
(0, import_log5.log)("options received", void 0, {
|
|
1593
|
+
F: __dxlog_file6,
|
|
1594
|
+
L: 90,
|
|
1595
|
+
S: this,
|
|
1596
|
+
C: (f, a) => f(...a)
|
|
1597
|
+
});
|
|
1598
|
+
if (this._remoteOptions?.role !== import_invitations3.Options.Role.HOST) {
|
|
1720
1599
|
throw new import_protocols5.InvalidInvitationExtensionRoleError(void 0, {
|
|
1721
|
-
expected:
|
|
1722
|
-
remoteOptions: this._remoteOptions
|
|
1600
|
+
expected: import_invitations3.Options.Role.HOST,
|
|
1601
|
+
remoteOptions: this._remoteOptions,
|
|
1602
|
+
remotePeerId: context.remotePeerId
|
|
1723
1603
|
});
|
|
1724
1604
|
}
|
|
1725
|
-
this._callbacks.onOpen();
|
|
1605
|
+
this._callbacks.onOpen(this._ctx, context);
|
|
1726
1606
|
} catch (err) {
|
|
1727
|
-
this.
|
|
1607
|
+
if (this._invitationFlowLock != null) {
|
|
1608
|
+
this._callbacks.onError(err);
|
|
1609
|
+
}
|
|
1610
|
+
if (!this._ctx.disposed) {
|
|
1611
|
+
context.close(err);
|
|
1612
|
+
}
|
|
1728
1613
|
}
|
|
1729
1614
|
}
|
|
1730
1615
|
async onClose() {
|
|
1616
|
+
await this._destroy();
|
|
1617
|
+
}
|
|
1618
|
+
async onAbort() {
|
|
1619
|
+
await this._destroy();
|
|
1620
|
+
}
|
|
1621
|
+
async _destroy() {
|
|
1731
1622
|
await this._ctx.dispose();
|
|
1623
|
+
if (this._invitationFlowLock != null) {
|
|
1624
|
+
this._invitationFlowLock.release();
|
|
1625
|
+
this._invitationFlowLock = null;
|
|
1626
|
+
(0, import_log5.log)("invitation flow lock released", void 0, {
|
|
1627
|
+
F: __dxlog_file6,
|
|
1628
|
+
L: 123,
|
|
1629
|
+
S: this,
|
|
1630
|
+
C: (f, a) => f(...a)
|
|
1631
|
+
});
|
|
1632
|
+
}
|
|
1732
1633
|
}
|
|
1733
1634
|
};
|
|
1734
|
-
var
|
|
1735
|
-
|
|
1635
|
+
var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-host-extension.ts";
|
|
1636
|
+
var OPTIONS_TIMEOUT2 = 1e4;
|
|
1637
|
+
var MAX_OTP_ATTEMPTS = 3;
|
|
1638
|
+
var InvitationHostExtension = class extends import_teleport2.RpcExtension {
|
|
1639
|
+
constructor(_invitationFlowMutex, _callbacks) {
|
|
1736
1640
|
super({
|
|
1737
1641
|
requested: {
|
|
1738
|
-
InvitationHostService:
|
|
1642
|
+
InvitationHostService: import_protocols6.schema.getService("dxos.halo.invitations.InvitationHostService")
|
|
1739
1643
|
},
|
|
1740
1644
|
exposed: {
|
|
1741
|
-
InvitationHostService:
|
|
1645
|
+
InvitationHostService: import_protocols6.schema.getService("dxos.halo.invitations.InvitationHostService")
|
|
1742
1646
|
}
|
|
1743
1647
|
});
|
|
1648
|
+
this._invitationFlowMutex = _invitationFlowMutex;
|
|
1744
1649
|
this._callbacks = _callbacks;
|
|
1745
|
-
this._ctx = new
|
|
1746
|
-
this._remoteOptionsTrigger = new
|
|
1650
|
+
this._ctx = new import_context7.Context();
|
|
1651
|
+
this._remoteOptionsTrigger = new import_async9.Trigger();
|
|
1652
|
+
this._challenge = void 0;
|
|
1653
|
+
this.guestProfile = void 0;
|
|
1654
|
+
this.authenticationPassed = false;
|
|
1655
|
+
this.authenticationRetry = 0;
|
|
1656
|
+
this.completedTrigger = new import_async9.Trigger();
|
|
1657
|
+
this._invitationFlowLock = null;
|
|
1658
|
+
}
|
|
1659
|
+
hasFlowLock() {
|
|
1660
|
+
return this._invitationFlowLock != null;
|
|
1747
1661
|
}
|
|
1748
1662
|
async getHandlers() {
|
|
1749
1663
|
return {
|
|
1664
|
+
// TODO(dmaretskyi): For now this is just forwarding the data to callbacks since we don't have session-specific logic.
|
|
1665
|
+
// Perhaps in the future we will have more complex logic here.
|
|
1750
1666
|
InvitationHostService: {
|
|
1751
1667
|
options: async (options) => {
|
|
1752
|
-
(0,
|
|
1753
|
-
F:
|
|
1754
|
-
L:
|
|
1668
|
+
(0, import_invariant7.invariant)(!this._remoteOptions, "Remote options already set.", {
|
|
1669
|
+
F: __dxlog_file7,
|
|
1670
|
+
L: 101,
|
|
1755
1671
|
S: this,
|
|
1756
1672
|
A: [
|
|
1757
1673
|
"!this._remoteOptions",
|
|
@@ -1761,14 +1677,191 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
|
|
|
1761
1677
|
this._remoteOptions = options;
|
|
1762
1678
|
this._remoteOptionsTrigger.wake();
|
|
1763
1679
|
},
|
|
1764
|
-
introduce: () => {
|
|
1765
|
-
|
|
1680
|
+
introduce: async (request) => {
|
|
1681
|
+
const { profile, invitationId } = request;
|
|
1682
|
+
const traceId = import_keys6.PublicKey.random().toHex();
|
|
1683
|
+
import_log6.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols6.trace.begin({
|
|
1684
|
+
id: traceId
|
|
1685
|
+
}), {
|
|
1686
|
+
F: __dxlog_file7,
|
|
1687
|
+
L: 110,
|
|
1688
|
+
S: this,
|
|
1689
|
+
C: (f, a) => f(...a)
|
|
1690
|
+
});
|
|
1691
|
+
const invitation = this._requireActiveInvitation();
|
|
1692
|
+
this._assertInvitationState(import_services5.Invitation.State.CONNECTED);
|
|
1693
|
+
if (invitationId !== invitation?.invitationId) {
|
|
1694
|
+
import_log6.log.warn("incorrect invitationId", {
|
|
1695
|
+
expected: invitation.invitationId,
|
|
1696
|
+
actual: invitationId
|
|
1697
|
+
}, {
|
|
1698
|
+
F: __dxlog_file7,
|
|
1699
|
+
L: 116,
|
|
1700
|
+
S: this,
|
|
1701
|
+
C: (f, a) => f(...a)
|
|
1702
|
+
});
|
|
1703
|
+
this._callbacks.onError(new Error("Incorrect invitationId."));
|
|
1704
|
+
(0, import_async9.scheduleTask)(this._ctx, () => this.close());
|
|
1705
|
+
return {
|
|
1706
|
+
authMethod: import_services5.Invitation.AuthMethod.NONE
|
|
1707
|
+
};
|
|
1708
|
+
}
|
|
1709
|
+
(0, import_log6.log)("guest introduced themselves", {
|
|
1710
|
+
guestProfile: profile
|
|
1711
|
+
}, {
|
|
1712
|
+
F: __dxlog_file7,
|
|
1713
|
+
L: 125,
|
|
1714
|
+
S: this,
|
|
1715
|
+
C: (f, a) => f(...a)
|
|
1716
|
+
});
|
|
1717
|
+
this.guestProfile = profile;
|
|
1718
|
+
this._callbacks.onStateUpdate(import_services5.Invitation.State.READY_FOR_AUTHENTICATION);
|
|
1719
|
+
this._challenge = invitation.authMethod === import_services5.Invitation.AuthMethod.KNOWN_PUBLIC_KEY ? (0, import_crypto2.randomBytes)(32) : void 0;
|
|
1720
|
+
import_log6.log.trace("dxos.sdk.invitation-handler.host.introduce", import_protocols6.trace.end({
|
|
1721
|
+
id: traceId
|
|
1722
|
+
}), {
|
|
1723
|
+
F: __dxlog_file7,
|
|
1724
|
+
L: 132,
|
|
1725
|
+
S: this,
|
|
1726
|
+
C: (f, a) => f(...a)
|
|
1727
|
+
});
|
|
1728
|
+
return {
|
|
1729
|
+
authMethod: invitation.authMethod,
|
|
1730
|
+
challenge: this._challenge
|
|
1731
|
+
};
|
|
1766
1732
|
},
|
|
1767
|
-
authenticate: () => {
|
|
1768
|
-
|
|
1733
|
+
authenticate: async ({ authCode: code, signedChallenge }) => {
|
|
1734
|
+
const traceId = import_keys6.PublicKey.random().toHex();
|
|
1735
|
+
import_log6.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols6.trace.begin({
|
|
1736
|
+
id: traceId
|
|
1737
|
+
}), {
|
|
1738
|
+
F: __dxlog_file7,
|
|
1739
|
+
L: 141,
|
|
1740
|
+
S: this,
|
|
1741
|
+
C: (f, a) => f(...a)
|
|
1742
|
+
});
|
|
1743
|
+
const invitation = this._requireActiveInvitation();
|
|
1744
|
+
(0, import_log6.log)("received authentication request", {
|
|
1745
|
+
authCode: code
|
|
1746
|
+
}, {
|
|
1747
|
+
F: __dxlog_file7,
|
|
1748
|
+
L: 144,
|
|
1749
|
+
S: this,
|
|
1750
|
+
C: (f, a) => f(...a)
|
|
1751
|
+
});
|
|
1752
|
+
let status = import_invitations4.AuthenticationResponse.Status.OK;
|
|
1753
|
+
this._assertInvitationState([
|
|
1754
|
+
import_services5.Invitation.State.AUTHENTICATING,
|
|
1755
|
+
import_services5.Invitation.State.READY_FOR_AUTHENTICATION
|
|
1756
|
+
]);
|
|
1757
|
+
this._callbacks.onStateUpdate(import_services5.Invitation.State.AUTHENTICATING);
|
|
1758
|
+
switch (invitation.authMethod) {
|
|
1759
|
+
case import_services5.Invitation.AuthMethod.NONE: {
|
|
1760
|
+
(0, import_log6.log)("authentication not required", void 0, {
|
|
1761
|
+
F: __dxlog_file7,
|
|
1762
|
+
L: 152,
|
|
1763
|
+
S: this,
|
|
1764
|
+
C: (f, a) => f(...a)
|
|
1765
|
+
});
|
|
1766
|
+
return {
|
|
1767
|
+
status: import_invitations4.AuthenticationResponse.Status.OK
|
|
1768
|
+
};
|
|
1769
|
+
}
|
|
1770
|
+
case import_services5.Invitation.AuthMethod.SHARED_SECRET: {
|
|
1771
|
+
if (invitation.authCode) {
|
|
1772
|
+
if (this.authenticationRetry++ > MAX_OTP_ATTEMPTS) {
|
|
1773
|
+
status = import_invitations4.AuthenticationResponse.Status.INVALID_OPT_ATTEMPTS;
|
|
1774
|
+
} else if (code !== invitation.authCode) {
|
|
1775
|
+
status = import_invitations4.AuthenticationResponse.Status.INVALID_OTP;
|
|
1776
|
+
} else {
|
|
1777
|
+
this.authenticationPassed = true;
|
|
1778
|
+
}
|
|
1779
|
+
}
|
|
1780
|
+
break;
|
|
1781
|
+
}
|
|
1782
|
+
case import_services5.Invitation.AuthMethod.KNOWN_PUBLIC_KEY: {
|
|
1783
|
+
if (!invitation.guestKeypair) {
|
|
1784
|
+
status = import_invitations4.AuthenticationResponse.Status.INTERNAL_ERROR;
|
|
1785
|
+
break;
|
|
1786
|
+
}
|
|
1787
|
+
const isSignatureValid = this._challenge && (0, import_crypto2.verify)(this._challenge, Buffer.from(signedChallenge ?? []), invitation.guestKeypair.publicKey.asBuffer());
|
|
1788
|
+
if (isSignatureValid) {
|
|
1789
|
+
this.authenticationPassed = true;
|
|
1790
|
+
} else {
|
|
1791
|
+
status = import_invitations4.AuthenticationResponse.Status.INVALID_SIGNATURE;
|
|
1792
|
+
}
|
|
1793
|
+
break;
|
|
1794
|
+
}
|
|
1795
|
+
default: {
|
|
1796
|
+
import_log6.log.error("invalid authentication method", {
|
|
1797
|
+
authMethod: invitation.authMethod
|
|
1798
|
+
}, {
|
|
1799
|
+
F: __dxlog_file7,
|
|
1800
|
+
L: 190,
|
|
1801
|
+
S: this,
|
|
1802
|
+
C: (f, a) => f(...a)
|
|
1803
|
+
});
|
|
1804
|
+
status = import_invitations4.AuthenticationResponse.Status.INTERNAL_ERROR;
|
|
1805
|
+
break;
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1808
|
+
if (![
|
|
1809
|
+
import_invitations4.AuthenticationResponse.Status.OK,
|
|
1810
|
+
import_invitations4.AuthenticationResponse.Status.INVALID_OTP
|
|
1811
|
+
].includes(status)) {
|
|
1812
|
+
this._callbacks.onError(new Error(`Authentication failed, with status=${status}`));
|
|
1813
|
+
(0, import_async9.scheduleTask)(this._ctx, () => this.close());
|
|
1814
|
+
return {
|
|
1815
|
+
status
|
|
1816
|
+
};
|
|
1817
|
+
}
|
|
1818
|
+
import_log6.log.trace("dxos.sdk.invitation-handler.host.authenticate", import_protocols6.trace.end({
|
|
1819
|
+
id: traceId,
|
|
1820
|
+
data: {
|
|
1821
|
+
status
|
|
1822
|
+
}
|
|
1823
|
+
}), {
|
|
1824
|
+
F: __dxlog_file7,
|
|
1825
|
+
L: 202,
|
|
1826
|
+
S: this,
|
|
1827
|
+
C: (f, a) => f(...a)
|
|
1828
|
+
});
|
|
1829
|
+
return {
|
|
1830
|
+
status
|
|
1831
|
+
};
|
|
1769
1832
|
},
|
|
1770
|
-
admit: () => {
|
|
1771
|
-
|
|
1833
|
+
admit: async (request) => {
|
|
1834
|
+
const traceId = import_keys6.PublicKey.random().toHex();
|
|
1835
|
+
import_log6.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols6.trace.begin({
|
|
1836
|
+
id: traceId
|
|
1837
|
+
}), {
|
|
1838
|
+
F: __dxlog_file7,
|
|
1839
|
+
L: 208,
|
|
1840
|
+
S: this,
|
|
1841
|
+
C: (f, a) => f(...a)
|
|
1842
|
+
});
|
|
1843
|
+
const invitation = this._requireActiveInvitation();
|
|
1844
|
+
try {
|
|
1845
|
+
if (isAuthenticationRequired(invitation)) {
|
|
1846
|
+
this._assertInvitationState(import_services5.Invitation.State.AUTHENTICATING);
|
|
1847
|
+
if (!this.authenticationPassed) {
|
|
1848
|
+
throw new Error("Not authenticated");
|
|
1849
|
+
}
|
|
1850
|
+
}
|
|
1851
|
+
const response = await this._callbacks.admit(request);
|
|
1852
|
+
import_log6.log.trace("dxos.sdk.invitation-handler.host.admit", import_protocols6.trace.end({
|
|
1853
|
+
id: traceId
|
|
1854
|
+
}), {
|
|
1855
|
+
F: __dxlog_file7,
|
|
1856
|
+
L: 222,
|
|
1857
|
+
S: this,
|
|
1858
|
+
C: (f, a) => f(...a)
|
|
1859
|
+
});
|
|
1860
|
+
return response;
|
|
1861
|
+
} catch (err) {
|
|
1862
|
+
this._callbacks.onError(err);
|
|
1863
|
+
throw err;
|
|
1864
|
+
}
|
|
1772
1865
|
}
|
|
1773
1866
|
}
|
|
1774
1867
|
};
|
|
@@ -1776,81 +1869,195 @@ var InvitationGuestExtension = class extends import_teleport.RpcExtension {
|
|
|
1776
1869
|
async onOpen(context) {
|
|
1777
1870
|
await super.onOpen(context);
|
|
1778
1871
|
try {
|
|
1779
|
-
(0,
|
|
1780
|
-
F:
|
|
1781
|
-
L:
|
|
1872
|
+
(0, import_log6.log)("host acquire lock", void 0, {
|
|
1873
|
+
F: __dxlog_file7,
|
|
1874
|
+
L: 237,
|
|
1782
1875
|
S: this,
|
|
1783
1876
|
C: (f, a) => f(...a)
|
|
1784
1877
|
});
|
|
1785
|
-
await (
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1878
|
+
this._invitationFlowLock = await tryAcquireBeforeContextDisposed(this._ctx, this._invitationFlowMutex);
|
|
1879
|
+
(0, import_log6.log)("host lock acquired", void 0, {
|
|
1880
|
+
F: __dxlog_file7,
|
|
1881
|
+
L: 239,
|
|
1882
|
+
S: this,
|
|
1883
|
+
C: (f, a) => f(...a)
|
|
1884
|
+
});
|
|
1885
|
+
const lastState = this._requireActiveInvitation().state;
|
|
1886
|
+
this._callbacks.onStateUpdate(import_services5.Invitation.State.CONNECTING);
|
|
1887
|
+
await this.rpc.InvitationHostService.options({
|
|
1888
|
+
role: import_invitations4.Options.Role.HOST
|
|
1889
|
+
});
|
|
1890
|
+
(0, import_log6.log)("options sent", void 0, {
|
|
1891
|
+
F: __dxlog_file7,
|
|
1892
|
+
L: 243,
|
|
1893
|
+
S: this,
|
|
1894
|
+
C: (f, a) => f(...a)
|
|
1895
|
+
});
|
|
1896
|
+
await (0, import_context7.cancelWithContext)(this._ctx, this._remoteOptionsTrigger.wait({
|
|
1897
|
+
timeout: OPTIONS_TIMEOUT2
|
|
1790
1898
|
}));
|
|
1791
|
-
(0,
|
|
1792
|
-
F:
|
|
1793
|
-
L:
|
|
1899
|
+
(0, import_log6.log)("options received", void 0, {
|
|
1900
|
+
F: __dxlog_file7,
|
|
1901
|
+
L: 245,
|
|
1794
1902
|
S: this,
|
|
1795
1903
|
C: (f, a) => f(...a)
|
|
1796
1904
|
});
|
|
1797
|
-
if (this._remoteOptions?.role !==
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1905
|
+
if (this._remoteOptions?.role !== import_invitations4.Options.Role.GUEST) {
|
|
1906
|
+
this._callbacks.onStateUpdate(lastState);
|
|
1907
|
+
throw new import_protocols6.InvalidInvitationExtensionRoleError(void 0, {
|
|
1908
|
+
expected: import_invitations4.Options.Role.GUEST,
|
|
1909
|
+
remoteOptions: this._remoteOptions,
|
|
1910
|
+
remotePeerId: context.remotePeerId
|
|
1801
1911
|
});
|
|
1802
1912
|
}
|
|
1803
|
-
this._callbacks.
|
|
1913
|
+
this._callbacks.onStateUpdate(import_services5.Invitation.State.CONNECTED);
|
|
1914
|
+
this._callbacks.onOpen(this._ctx, context);
|
|
1804
1915
|
} catch (err) {
|
|
1805
|
-
(
|
|
1806
|
-
|
|
1916
|
+
if (this._invitationFlowLock != null) {
|
|
1917
|
+
this._callbacks.onError(err);
|
|
1918
|
+
}
|
|
1919
|
+
if (!this._ctx.disposed) {
|
|
1920
|
+
context.close(err);
|
|
1921
|
+
}
|
|
1922
|
+
}
|
|
1923
|
+
}
|
|
1924
|
+
_requireActiveInvitation() {
|
|
1925
|
+
const invitation = this._callbacks.activeInvitation;
|
|
1926
|
+
if (invitation == null) {
|
|
1927
|
+
(0, import_async9.scheduleTask)(this._ctx, () => this.close());
|
|
1928
|
+
throw new Error("Active invitation not found");
|
|
1929
|
+
}
|
|
1930
|
+
return invitation;
|
|
1931
|
+
}
|
|
1932
|
+
_assertInvitationState(stateOrMany) {
|
|
1933
|
+
const invitation = this._requireActiveInvitation();
|
|
1934
|
+
const validStates = Array.isArray(stateOrMany) ? stateOrMany : [
|
|
1935
|
+
stateOrMany
|
|
1936
|
+
];
|
|
1937
|
+
if (!validStates.includes(invitation.state)) {
|
|
1938
|
+
(0, import_async9.scheduleTask)(this._ctx, () => this.close());
|
|
1939
|
+
throw new import_invariant7.InvariantViolation(`Expected ${stateToString(invitation.state)} to be one of [${validStates.map(stateToString).join(", ")}]`);
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1942
|
+
async onClose() {
|
|
1943
|
+
await this._destroy();
|
|
1944
|
+
}
|
|
1945
|
+
async onAbort() {
|
|
1946
|
+
await this._destroy();
|
|
1947
|
+
}
|
|
1948
|
+
async _destroy() {
|
|
1949
|
+
await this._ctx.dispose();
|
|
1950
|
+
if (this._invitationFlowLock != null) {
|
|
1951
|
+
this._invitationFlowLock?.release();
|
|
1952
|
+
this._invitationFlowLock = null;
|
|
1953
|
+
(0, import_log6.log)("invitation flow lock released", void 0, {
|
|
1954
|
+
F: __dxlog_file7,
|
|
1807
1955
|
L: 300,
|
|
1808
1956
|
S: this,
|
|
1809
1957
|
C: (f, a) => f(...a)
|
|
1810
1958
|
});
|
|
1811
|
-
this._callbacks.onError(err);
|
|
1812
1959
|
}
|
|
1813
1960
|
}
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1961
|
+
};
|
|
1962
|
+
var isAuthenticationRequired = (invitation) => invitation.authMethod !== import_services5.Invitation.AuthMethod.NONE;
|
|
1963
|
+
var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-topology.ts";
|
|
1964
|
+
var InvitationTopology = class {
|
|
1965
|
+
constructor(_role) {
|
|
1966
|
+
this._role = _role;
|
|
1967
|
+
this._seenPeers = new import_util5.ComplexSet(import_keys7.PublicKey.hash);
|
|
1968
|
+
}
|
|
1969
|
+
init(controller) {
|
|
1970
|
+
(0, import_invariant8.invariant)(!this._controller, "Already initialized.", {
|
|
1971
|
+
F: __dxlog_file8,
|
|
1972
|
+
L: 42,
|
|
1818
1973
|
S: this,
|
|
1819
|
-
|
|
1974
|
+
A: [
|
|
1975
|
+
"!this._controller",
|
|
1976
|
+
"'Already initialized.'"
|
|
1977
|
+
]
|
|
1820
1978
|
});
|
|
1821
|
-
|
|
1979
|
+
this._controller = controller;
|
|
1980
|
+
}
|
|
1981
|
+
update() {
|
|
1982
|
+
(0, import_invariant8.invariant)(this._controller, "Not initialized.", {
|
|
1983
|
+
F: __dxlog_file8,
|
|
1984
|
+
L: 47,
|
|
1985
|
+
S: this,
|
|
1986
|
+
A: [
|
|
1987
|
+
"this._controller",
|
|
1988
|
+
"'Not initialized.'"
|
|
1989
|
+
]
|
|
1990
|
+
});
|
|
1991
|
+
const { ownPeerId, candidates, connected, allPeers } = this._controller.getState();
|
|
1992
|
+
if (this._role === import_invitations5.Options.Role.GUEST) {
|
|
1993
|
+
return;
|
|
1994
|
+
}
|
|
1995
|
+
if (connected.length > 0) {
|
|
1996
|
+
connected.forEach((c) => this._seenPeers.add(c));
|
|
1997
|
+
return;
|
|
1998
|
+
}
|
|
1999
|
+
const firstUnknownPeer = candidates.find((peerId) => !this._seenPeers.has(peerId));
|
|
2000
|
+
this._seenPeers = new import_util5.ComplexSet(import_keys7.PublicKey.hash, allPeers.filter((peerId) => this._seenPeers.has(peerId)));
|
|
2001
|
+
if (firstUnknownPeer != null) {
|
|
2002
|
+
(0, import_log7.log)("invitation connect", {
|
|
2003
|
+
ownPeerId,
|
|
2004
|
+
remotePeerId: firstUnknownPeer
|
|
2005
|
+
}, {
|
|
2006
|
+
F: __dxlog_file8,
|
|
2007
|
+
L: 69,
|
|
2008
|
+
S: this,
|
|
2009
|
+
C: (f, a) => f(...a)
|
|
2010
|
+
});
|
|
2011
|
+
this._controller.connect(firstUnknownPeer);
|
|
2012
|
+
this._seenPeers.add(firstUnknownPeer);
|
|
2013
|
+
}
|
|
2014
|
+
}
|
|
2015
|
+
async onOffer(peer) {
|
|
2016
|
+
(0, import_invariant8.invariant)(this._controller, "Not initialized.", {
|
|
2017
|
+
F: __dxlog_file8,
|
|
2018
|
+
L: 76,
|
|
2019
|
+
S: this,
|
|
2020
|
+
A: [
|
|
2021
|
+
"this._controller",
|
|
2022
|
+
"'Not initialized.'"
|
|
2023
|
+
]
|
|
2024
|
+
});
|
|
2025
|
+
return !this._seenPeers.has(peer);
|
|
2026
|
+
}
|
|
2027
|
+
async destroy() {
|
|
2028
|
+
this._seenPeers.clear();
|
|
2029
|
+
}
|
|
2030
|
+
toString() {
|
|
2031
|
+
return `InvitationTopology(${this._role === import_invitations5.Options.Role.GUEST ? "guest" : "host"})`;
|
|
1822
2032
|
}
|
|
1823
2033
|
};
|
|
1824
|
-
var
|
|
1825
|
-
var
|
|
2034
|
+
var __dxlog_file9 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts";
|
|
2035
|
+
var MAX_DELEGATED_INVITATION_HOST_TRIES = 3;
|
|
1826
2036
|
var InvitationsHandler = class {
|
|
1827
2037
|
/**
|
|
1828
2038
|
* @internal
|
|
1829
2039
|
*/
|
|
1830
|
-
constructor(_networkManager) {
|
|
2040
|
+
constructor(_networkManager, _defaultTeleportParams) {
|
|
1831
2041
|
this._networkManager = _networkManager;
|
|
2042
|
+
this._defaultTeleportParams = _defaultTeleportParams;
|
|
1832
2043
|
}
|
|
1833
2044
|
handleInvitationFlow(ctx, stream, protocol, invitation) {
|
|
2045
|
+
const guardedState = this._createGuardedState(ctx, invitation, stream);
|
|
1834
2046
|
const createExtension = () => {
|
|
1835
|
-
const extension = new InvitationHostExtension({
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
...invitation2,
|
|
1839
|
-
state: import_services3.Invitation.State.READY_FOR_AUTHENTICATION
|
|
1840
|
-
});
|
|
2047
|
+
const extension = new InvitationHostExtension(guardedState.mutex, {
|
|
2048
|
+
get activeInvitation() {
|
|
2049
|
+
return ctx.disposed ? null : guardedState.current;
|
|
1841
2050
|
},
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
}
|
|
1846
|
-
return invitation;
|
|
2051
|
+
onStateUpdate: (newState) => {
|
|
2052
|
+
guardedState.set(extension, newState);
|
|
2053
|
+
return guardedState.current;
|
|
1847
2054
|
},
|
|
1848
2055
|
admit: async (admissionRequest) => {
|
|
1849
2056
|
try {
|
|
1850
2057
|
const deviceKey = admissionRequest.device?.deviceKey ?? admissionRequest.space?.deviceKey;
|
|
1851
2058
|
(0, import_invariant5.invariant)(deviceKey, void 0, {
|
|
1852
|
-
F:
|
|
1853
|
-
L:
|
|
2059
|
+
F: __dxlog_file9,
|
|
2060
|
+
L: 90,
|
|
1854
2061
|
S: this,
|
|
1855
2062
|
A: [
|
|
1856
2063
|
"deviceKey",
|
|
@@ -1861,34 +2068,36 @@ var InvitationsHandler = class {
|
|
|
1861
2068
|
extension.completedTrigger.wake(deviceKey);
|
|
1862
2069
|
return admissionResponse;
|
|
1863
2070
|
} catch (err) {
|
|
1864
|
-
|
|
2071
|
+
guardedState.error(extension, err);
|
|
1865
2072
|
throw err;
|
|
1866
2073
|
}
|
|
1867
2074
|
},
|
|
1868
|
-
onOpen: () => {
|
|
1869
|
-
|
|
2075
|
+
onOpen: (connectionCtx, extensionsCtx) => {
|
|
2076
|
+
let admitted = false;
|
|
2077
|
+
connectionCtx.onDispose(() => {
|
|
2078
|
+
if (!admitted) {
|
|
2079
|
+
guardedState.error(extension, new import_context4.ContextDisposedError());
|
|
2080
|
+
}
|
|
2081
|
+
});
|
|
2082
|
+
(0, import_async7.scheduleTask)(connectionCtx, async () => {
|
|
1870
2083
|
const traceId = import_keys5.PublicKey.random().toHex();
|
|
1871
2084
|
try {
|
|
1872
2085
|
import_log4.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols4.trace.begin({
|
|
1873
2086
|
id: traceId
|
|
1874
2087
|
}), {
|
|
1875
|
-
F:
|
|
1876
|
-
L:
|
|
2088
|
+
F: __dxlog_file9,
|
|
2089
|
+
L: 115,
|
|
1877
2090
|
S: this,
|
|
1878
2091
|
C: (f, a) => f(...a)
|
|
1879
2092
|
});
|
|
1880
2093
|
(0, import_log4.log)("connected", {
|
|
1881
2094
|
...protocol.toJSON()
|
|
1882
2095
|
}, {
|
|
1883
|
-
F:
|
|
1884
|
-
L:
|
|
2096
|
+
F: __dxlog_file9,
|
|
2097
|
+
L: 116,
|
|
1885
2098
|
S: this,
|
|
1886
2099
|
C: (f, a) => f(...a)
|
|
1887
2100
|
});
|
|
1888
|
-
stream.next({
|
|
1889
|
-
...invitation,
|
|
1890
|
-
state: import_services3.Invitation.State.CONNECTED
|
|
1891
|
-
});
|
|
1892
2101
|
const deviceKey = await extension.completedTrigger.wait({
|
|
1893
2102
|
timeout: invitation.timeout
|
|
1894
2103
|
});
|
|
@@ -1896,88 +2105,91 @@ var InvitationsHandler = class {
|
|
|
1896
2105
|
guest: deviceKey,
|
|
1897
2106
|
...protocol.toJSON()
|
|
1898
2107
|
}, {
|
|
1899
|
-
F:
|
|
1900
|
-
L:
|
|
2108
|
+
F: __dxlog_file9,
|
|
2109
|
+
L: 118,
|
|
1901
2110
|
S: this,
|
|
1902
2111
|
C: (f, a) => f(...a)
|
|
1903
2112
|
});
|
|
1904
|
-
|
|
1905
|
-
...invitation,
|
|
1906
|
-
state: import_services3.Invitation.State.SUCCESS
|
|
1907
|
-
});
|
|
2113
|
+
guardedState.set(extension, import_services3.Invitation.State.SUCCESS);
|
|
1908
2114
|
import_log4.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols4.trace.end({
|
|
1909
2115
|
id: traceId
|
|
1910
2116
|
}), {
|
|
1911
|
-
F:
|
|
1912
|
-
L:
|
|
2117
|
+
F: __dxlog_file9,
|
|
2118
|
+
L: 120,
|
|
1913
2119
|
S: this,
|
|
1914
2120
|
C: (f, a) => f(...a)
|
|
1915
2121
|
});
|
|
2122
|
+
admitted = true;
|
|
2123
|
+
if (!invitation.multiUse) {
|
|
2124
|
+
await ctx.dispose();
|
|
2125
|
+
}
|
|
1916
2126
|
} catch (err) {
|
|
1917
2127
|
if (err instanceof import_async7.TimeoutError) {
|
|
1918
|
-
(
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
state: import_services3.Invitation.State.TIMEOUT
|
|
1929
|
-
});
|
|
2128
|
+
if (guardedState.set(extension, import_services3.Invitation.State.TIMEOUT)) {
|
|
2129
|
+
(0, import_log4.log)("timeout", {
|
|
2130
|
+
...protocol.toJSON()
|
|
2131
|
+
}, {
|
|
2132
|
+
F: __dxlog_file9,
|
|
2133
|
+
L: 129,
|
|
2134
|
+
S: this,
|
|
2135
|
+
C: (f, a) => f(...a)
|
|
2136
|
+
});
|
|
2137
|
+
}
|
|
1930
2138
|
} else {
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
2139
|
+
if (guardedState.error(extension, err)) {
|
|
2140
|
+
import_log4.log.error("failed", err, {
|
|
2141
|
+
F: __dxlog_file9,
|
|
2142
|
+
L: 133,
|
|
2143
|
+
S: this,
|
|
2144
|
+
C: (f, a) => f(...a)
|
|
2145
|
+
});
|
|
2146
|
+
}
|
|
1938
2147
|
}
|
|
1939
2148
|
import_log4.log.trace("dxos.sdk.invitations-handler.host.onOpen", import_protocols4.trace.error({
|
|
1940
2149
|
id: traceId,
|
|
1941
2150
|
error: err
|
|
1942
2151
|
}), {
|
|
1943
|
-
F:
|
|
1944
|
-
L:
|
|
2152
|
+
F: __dxlog_file9,
|
|
2153
|
+
L: 136,
|
|
1945
2154
|
S: this,
|
|
1946
2155
|
C: (f, a) => f(...a)
|
|
1947
2156
|
});
|
|
1948
|
-
|
|
1949
|
-
if (!invitation.multiUse) {
|
|
1950
|
-
await swarmConnection.close();
|
|
1951
|
-
await ctx.dispose();
|
|
1952
|
-
}
|
|
2157
|
+
extensionsCtx.close(err);
|
|
1953
2158
|
}
|
|
1954
2159
|
});
|
|
1955
2160
|
},
|
|
1956
2161
|
onError: (err) => {
|
|
1957
2162
|
if (err instanceof import_protocols4.InvalidInvitationExtensionRoleError) {
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
if (err instanceof import_async7.TimeoutError) {
|
|
1961
|
-
(0, import_log4.log)("timeout", {
|
|
1962
|
-
...protocol.toJSON()
|
|
2163
|
+
(0, import_log4.log)("invalid role", {
|
|
2164
|
+
...err.context
|
|
1963
2165
|
}, {
|
|
1964
|
-
F:
|
|
1965
|
-
L:
|
|
2166
|
+
F: __dxlog_file9,
|
|
2167
|
+
L: 144,
|
|
1966
2168
|
S: this,
|
|
1967
2169
|
C: (f, a) => f(...a)
|
|
1968
2170
|
});
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
2171
|
+
return;
|
|
2172
|
+
}
|
|
2173
|
+
if (err instanceof import_async7.TimeoutError) {
|
|
2174
|
+
if (guardedState.set(extension, import_services3.Invitation.State.TIMEOUT)) {
|
|
2175
|
+
(0, import_log4.log)("timeout", {
|
|
2176
|
+
err
|
|
2177
|
+
}, {
|
|
2178
|
+
F: __dxlog_file9,
|
|
2179
|
+
L: 149,
|
|
2180
|
+
S: this,
|
|
2181
|
+
C: (f, a) => f(...a)
|
|
2182
|
+
});
|
|
2183
|
+
}
|
|
1973
2184
|
} else {
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
2185
|
+
if (guardedState.error(extension, err)) {
|
|
2186
|
+
import_log4.log.error("failed", err, {
|
|
2187
|
+
F: __dxlog_file9,
|
|
2188
|
+
L: 153,
|
|
2189
|
+
S: this,
|
|
2190
|
+
C: (f, a) => f(...a)
|
|
2191
|
+
});
|
|
2192
|
+
}
|
|
1981
2193
|
}
|
|
1982
2194
|
}
|
|
1983
2195
|
});
|
|
@@ -1986,57 +2198,31 @@ var InvitationsHandler = class {
|
|
|
1986
2198
|
if (invitation.lifetime && invitation.created) {
|
|
1987
2199
|
if (invitation.created.getTime() + invitation.lifetime * 1e3 < Date.now()) {
|
|
1988
2200
|
import_log4.log.warn("invitation has already expired", void 0, {
|
|
1989
|
-
F:
|
|
1990
|
-
L:
|
|
2201
|
+
F: __dxlog_file9,
|
|
2202
|
+
L: 164,
|
|
1991
2203
|
S: this,
|
|
1992
2204
|
C: (f, a) => f(...a)
|
|
1993
2205
|
});
|
|
1994
2206
|
} else {
|
|
1995
2207
|
(0, import_async7.scheduleTask)(ctx, async () => {
|
|
1996
2208
|
await swarmConnection.close();
|
|
1997
|
-
|
|
1998
|
-
...invitation,
|
|
1999
|
-
state: import_services3.Invitation.State.EXPIRED
|
|
2000
|
-
});
|
|
2209
|
+
guardedState.set(null, import_services3.Invitation.State.EXPIRED);
|
|
2001
2210
|
await ctx.dispose();
|
|
2002
2211
|
}, invitation.created.getTime() + invitation.lifetime * 1e3 - Date.now());
|
|
2003
2212
|
}
|
|
2004
2213
|
}
|
|
2005
2214
|
let swarmConnection;
|
|
2006
|
-
const invitationLabel = "invitation host for " + (invitation.kind === import_services3.Invitation.Kind.DEVICE ? "device" : `space ${invitation.spaceKey?.truncate()}`);
|
|
2007
2215
|
(0, import_async7.scheduleTask)(ctx, async () => {
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
topic,
|
|
2011
|
-
peerId: topic,
|
|
2012
|
-
protocolProvider: (0, import_network_manager.createTeleportProtocolFactory)(async (teleport) => {
|
|
2013
|
-
teleport.addExtension("dxos.halo.invitations", createExtension());
|
|
2014
|
-
}),
|
|
2015
|
-
topology: new import_network_manager.StarTopology(topic),
|
|
2016
|
-
label: invitationLabel
|
|
2017
|
-
});
|
|
2018
|
-
ctx.onDispose(() => swarmConnection.close());
|
|
2019
|
-
stream.next({
|
|
2020
|
-
...invitation,
|
|
2021
|
-
state: import_services3.Invitation.State.CONNECTING
|
|
2022
|
-
});
|
|
2216
|
+
swarmConnection = await this._joinSwarm(ctx, invitation, import_invitations2.Options.Role.HOST, createExtension);
|
|
2217
|
+
guardedState.set(null, import_services3.Invitation.State.CONNECTING);
|
|
2023
2218
|
});
|
|
2024
2219
|
}
|
|
2025
|
-
acceptInvitation(protocol, invitation, deviceProfile) {
|
|
2220
|
+
acceptInvitation(ctx, stream, protocol, invitation, otpEnteredTrigger, deviceProfile) {
|
|
2026
2221
|
const { timeout = import_client_protocol2.INVITATION_TIMEOUT } = invitation;
|
|
2027
|
-
(0, import_invariant5.invariant)(protocol, void 0, {
|
|
2028
|
-
F: __dxlog_file7,
|
|
2029
|
-
L: 191,
|
|
2030
|
-
S: this,
|
|
2031
|
-
A: [
|
|
2032
|
-
"protocol",
|
|
2033
|
-
""
|
|
2034
|
-
]
|
|
2035
|
-
});
|
|
2036
2222
|
if (deviceProfile) {
|
|
2037
2223
|
(0, import_invariant5.invariant)(invitation.kind === import_services3.Invitation.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
|
|
2038
|
-
F:
|
|
2039
|
-
L:
|
|
2224
|
+
F: __dxlog_file9,
|
|
2225
|
+
L: 197,
|
|
2040
2226
|
S: this,
|
|
2041
2227
|
A: [
|
|
2042
2228
|
"invitation.kind === Invitation.Kind.DEVICE",
|
|
@@ -2044,121 +2230,96 @@ var InvitationsHandler = class {
|
|
|
2044
2230
|
]
|
|
2045
2231
|
});
|
|
2046
2232
|
}
|
|
2047
|
-
const
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
S: this,
|
|
2056
|
-
A: [
|
|
2057
|
-
"newData.state !== undefined",
|
|
2058
|
-
""
|
|
2059
|
-
]
|
|
2060
|
-
});
|
|
2061
|
-
currentState = newData.state;
|
|
2062
|
-
stream.next({
|
|
2063
|
-
...invitation,
|
|
2064
|
-
...newData
|
|
2065
|
-
});
|
|
2066
|
-
};
|
|
2067
|
-
const ctx = new import_context4.Context({
|
|
2068
|
-
onError: (err) => {
|
|
2069
|
-
if (err instanceof import_async7.TimeoutError) {
|
|
2070
|
-
(0, import_log4.log)("timeout", {
|
|
2071
|
-
...protocol.toJSON()
|
|
2072
|
-
}, {
|
|
2073
|
-
F: __dxlog_file7,
|
|
2074
|
-
L: 213,
|
|
2075
|
-
S: this,
|
|
2076
|
-
C: (f, a) => f(...a)
|
|
2077
|
-
});
|
|
2078
|
-
setState({
|
|
2079
|
-
state: import_services3.Invitation.State.TIMEOUT
|
|
2080
|
-
});
|
|
2081
|
-
} else {
|
|
2082
|
-
import_log4.log.warn("auth failed", err, {
|
|
2083
|
-
F: __dxlog_file7,
|
|
2084
|
-
L: 216,
|
|
2085
|
-
S: this,
|
|
2086
|
-
C: (f, a) => f(...a)
|
|
2087
|
-
});
|
|
2088
|
-
stream.error(err);
|
|
2089
|
-
}
|
|
2090
|
-
void ctx.dispose();
|
|
2091
|
-
}
|
|
2092
|
-
});
|
|
2093
|
-
ctx.onDispose(() => {
|
|
2094
|
-
(0, import_log4.log)("complete", {
|
|
2095
|
-
...protocol.toJSON()
|
|
2233
|
+
const triedPeersIds = new import_util4.ComplexSet(import_keys5.PublicKey.hash);
|
|
2234
|
+
const guardedState = this._createGuardedState(ctx, invitation, stream);
|
|
2235
|
+
const shouldCancelInvitationFlow = (extension) => {
|
|
2236
|
+
const isLockedByAnotherConnection = guardedState.mutex.isLocked() && !extension.hasFlowLock();
|
|
2237
|
+
(0, import_log4.log)("should cancel invitation flow", {
|
|
2238
|
+
isLockedByAnotherConnection,
|
|
2239
|
+
invitationType: import_services3.Invitation.Type.DELEGATED,
|
|
2240
|
+
triedPeers: triedPeersIds.size
|
|
2096
2241
|
}, {
|
|
2097
|
-
F:
|
|
2098
|
-
L:
|
|
2242
|
+
F: __dxlog_file9,
|
|
2243
|
+
L: 205,
|
|
2099
2244
|
S: this,
|
|
2100
2245
|
C: (f, a) => f(...a)
|
|
2101
2246
|
});
|
|
2102
|
-
|
|
2103
|
-
|
|
2247
|
+
if (isLockedByAnotherConnection) {
|
|
2248
|
+
return false;
|
|
2249
|
+
}
|
|
2250
|
+
return invitation.type !== import_services3.Invitation.Type.DELEGATED || triedPeersIds.size >= MAX_DELEGATED_INVITATION_HOST_TRIES;
|
|
2251
|
+
};
|
|
2252
|
+
let admitted = false;
|
|
2104
2253
|
const createExtension = () => {
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2254
|
+
const extension = new InvitationGuestExtension(guardedState.mutex, {
|
|
2255
|
+
onStateUpdate: (newState) => {
|
|
2256
|
+
guardedState.set(extension, newState);
|
|
2257
|
+
},
|
|
2258
|
+
onOpen: (connectionCtx, extensionCtx) => {
|
|
2259
|
+
triedPeersIds.add(extensionCtx.remotePeerId);
|
|
2260
|
+
if (admitted) {
|
|
2261
|
+
extensionCtx.close();
|
|
2262
|
+
return;
|
|
2263
|
+
}
|
|
2264
|
+
connectionCtx.onDispose(async () => {
|
|
2109
2265
|
(0, import_log4.log)("extension disposed", {
|
|
2110
|
-
|
|
2266
|
+
admitted,
|
|
2267
|
+
currentState: guardedState.current.state
|
|
2111
2268
|
}, {
|
|
2112
|
-
F:
|
|
2113
|
-
L:
|
|
2269
|
+
F: __dxlog_file9,
|
|
2270
|
+
L: 233,
|
|
2114
2271
|
S: this,
|
|
2115
2272
|
C: (f, a) => f(...a)
|
|
2116
2273
|
});
|
|
2117
2274
|
if (!admitted) {
|
|
2118
|
-
|
|
2275
|
+
guardedState.error(extension, new import_context4.ContextDisposedError());
|
|
2276
|
+
if (shouldCancelInvitationFlow(extension)) {
|
|
2277
|
+
await ctx.dispose();
|
|
2278
|
+
}
|
|
2119
2279
|
}
|
|
2120
2280
|
});
|
|
2121
|
-
(0, import_async7.scheduleTask)(
|
|
2281
|
+
(0, import_async7.scheduleTask)(connectionCtx, async () => {
|
|
2122
2282
|
const traceId = import_keys5.PublicKey.random().toHex();
|
|
2123
2283
|
try {
|
|
2124
2284
|
import_log4.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols4.trace.begin({
|
|
2125
2285
|
id: traceId
|
|
2126
2286
|
}), {
|
|
2127
|
-
F:
|
|
2128
|
-
L:
|
|
2287
|
+
F: __dxlog_file9,
|
|
2288
|
+
L: 245,
|
|
2129
2289
|
S: this,
|
|
2130
2290
|
C: (f, a) => f(...a)
|
|
2131
2291
|
});
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2292
|
+
(0, import_async7.scheduleTask)(connectionCtx, () => {
|
|
2293
|
+
guardedState.set(extension, import_services3.Invitation.State.TIMEOUT);
|
|
2294
|
+
extensionCtx.close();
|
|
2295
|
+
}, timeout);
|
|
2136
2296
|
(0, import_log4.log)("connected", {
|
|
2137
2297
|
...protocol.toJSON()
|
|
2138
2298
|
}, {
|
|
2139
|
-
F:
|
|
2140
|
-
L:
|
|
2299
|
+
F: __dxlog_file9,
|
|
2300
|
+
L: 256,
|
|
2141
2301
|
S: this,
|
|
2142
2302
|
C: (f, a) => f(...a)
|
|
2143
2303
|
});
|
|
2144
|
-
|
|
2145
|
-
state: import_services3.Invitation.State.CONNECTED
|
|
2146
|
-
});
|
|
2304
|
+
guardedState.set(extension, import_services3.Invitation.State.CONNECTED);
|
|
2147
2305
|
(0, import_log4.log)("introduce", {
|
|
2148
2306
|
...protocol.toJSON()
|
|
2149
2307
|
}, {
|
|
2150
|
-
F:
|
|
2151
|
-
L:
|
|
2308
|
+
F: __dxlog_file9,
|
|
2309
|
+
L: 260,
|
|
2152
2310
|
S: this,
|
|
2153
2311
|
C: (f, a) => f(...a)
|
|
2154
2312
|
});
|
|
2155
|
-
const introductionResponse = await extension.rpc.InvitationHostService.introduce(
|
|
2313
|
+
const introductionResponse = await extension.rpc.InvitationHostService.introduce({
|
|
2314
|
+
invitationId: invitation.invitationId,
|
|
2315
|
+
...protocol.createIntroduction()
|
|
2316
|
+
});
|
|
2156
2317
|
(0, import_log4.log)("introduce response", {
|
|
2157
2318
|
...protocol.toJSON(),
|
|
2158
2319
|
response: introductionResponse
|
|
2159
2320
|
}, {
|
|
2160
|
-
F:
|
|
2161
|
-
L:
|
|
2321
|
+
F: __dxlog_file9,
|
|
2322
|
+
L: 265,
|
|
2162
2323
|
S: this,
|
|
2163
2324
|
C: (f, a) => f(...a)
|
|
2164
2325
|
});
|
|
@@ -2166,20 +2327,20 @@ var InvitationsHandler = class {
|
|
|
2166
2327
|
if (isAuthenticationRequired(invitation)) {
|
|
2167
2328
|
switch (invitation.authMethod) {
|
|
2168
2329
|
case import_services3.Invitation.AuthMethod.SHARED_SECRET:
|
|
2169
|
-
await this._handleGuestOtpAuth(extension,
|
|
2330
|
+
await this._handleGuestOtpAuth(extension, (state) => guardedState.set(extension, state), otpEnteredTrigger, {
|
|
2170
2331
|
timeout
|
|
2171
2332
|
});
|
|
2172
2333
|
break;
|
|
2173
2334
|
case import_services3.Invitation.AuthMethod.KNOWN_PUBLIC_KEY:
|
|
2174
|
-
await this._handleGuestKpkAuth(extension,
|
|
2335
|
+
await this._handleGuestKpkAuth(extension, (state) => guardedState.set(extension, state), invitation, introductionResponse);
|
|
2175
2336
|
break;
|
|
2176
2337
|
}
|
|
2177
2338
|
}
|
|
2178
2339
|
(0, import_log4.log)("request admission", {
|
|
2179
2340
|
...protocol.toJSON()
|
|
2180
2341
|
}, {
|
|
2181
|
-
F:
|
|
2182
|
-
L:
|
|
2342
|
+
F: __dxlog_file9,
|
|
2343
|
+
L: 291,
|
|
2183
2344
|
S: this,
|
|
2184
2345
|
C: (f, a) => f(...a)
|
|
2185
2346
|
});
|
|
@@ -2190,21 +2351,21 @@ var InvitationsHandler = class {
|
|
|
2190
2351
|
(0, import_log4.log)("admitted by host", {
|
|
2191
2352
|
...protocol.toJSON()
|
|
2192
2353
|
}, {
|
|
2193
|
-
F:
|
|
2194
|
-
L:
|
|
2354
|
+
F: __dxlog_file9,
|
|
2355
|
+
L: 302,
|
|
2195
2356
|
S: this,
|
|
2196
2357
|
C: (f, a) => f(...a)
|
|
2197
2358
|
});
|
|
2198
|
-
|
|
2359
|
+
await guardedState.complete({
|
|
2360
|
+
...guardedState.current,
|
|
2199
2361
|
...result,
|
|
2200
|
-
target: invitation.target,
|
|
2201
2362
|
state: import_services3.Invitation.State.SUCCESS
|
|
2202
2363
|
});
|
|
2203
2364
|
import_log4.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols4.trace.end({
|
|
2204
2365
|
id: traceId
|
|
2205
2366
|
}), {
|
|
2206
|
-
F:
|
|
2207
|
-
L:
|
|
2367
|
+
F: __dxlog_file9,
|
|
2368
|
+
L: 308,
|
|
2208
2369
|
S: this,
|
|
2209
2370
|
C: (f, a) => f(...a)
|
|
2210
2371
|
});
|
|
@@ -2213,34 +2374,31 @@ var InvitationsHandler = class {
|
|
|
2213
2374
|
(0, import_log4.log)("timeout", {
|
|
2214
2375
|
...protocol.toJSON()
|
|
2215
2376
|
}, {
|
|
2216
|
-
F:
|
|
2217
|
-
L:
|
|
2377
|
+
F: __dxlog_file9,
|
|
2378
|
+
L: 311,
|
|
2218
2379
|
S: this,
|
|
2219
2380
|
C: (f, a) => f(...a)
|
|
2220
2381
|
});
|
|
2221
|
-
|
|
2222
|
-
state: import_services3.Invitation.State.TIMEOUT
|
|
2223
|
-
});
|
|
2382
|
+
guardedState.set(extension, import_services3.Invitation.State.TIMEOUT);
|
|
2224
2383
|
} else {
|
|
2225
2384
|
(0, import_log4.log)("auth failed", err, {
|
|
2226
|
-
F:
|
|
2227
|
-
L:
|
|
2385
|
+
F: __dxlog_file9,
|
|
2386
|
+
L: 314,
|
|
2228
2387
|
S: this,
|
|
2229
2388
|
C: (f, a) => f(...a)
|
|
2230
2389
|
});
|
|
2231
|
-
|
|
2390
|
+
guardedState.error(extension, err);
|
|
2232
2391
|
}
|
|
2392
|
+
extensionCtx.close(err);
|
|
2233
2393
|
import_log4.log.trace("dxos.sdk.invitations-handler.guest.onOpen", import_protocols4.trace.error({
|
|
2234
2394
|
id: traceId,
|
|
2235
2395
|
error: err
|
|
2236
2396
|
}), {
|
|
2237
|
-
F:
|
|
2238
|
-
L:
|
|
2397
|
+
F: __dxlog_file9,
|
|
2398
|
+
L: 318,
|
|
2239
2399
|
S: this,
|
|
2240
2400
|
C: (f, a) => f(...a)
|
|
2241
2401
|
});
|
|
2242
|
-
} finally {
|
|
2243
|
-
await ctx.dispose();
|
|
2244
2402
|
}
|
|
2245
2403
|
});
|
|
2246
2404
|
},
|
|
@@ -2252,22 +2410,20 @@ var InvitationsHandler = class {
|
|
|
2252
2410
|
(0, import_log4.log)("timeout", {
|
|
2253
2411
|
...protocol.toJSON()
|
|
2254
2412
|
}, {
|
|
2255
|
-
F:
|
|
2256
|
-
L:
|
|
2413
|
+
F: __dxlog_file9,
|
|
2414
|
+
L: 327,
|
|
2257
2415
|
S: this,
|
|
2258
2416
|
C: (f, a) => f(...a)
|
|
2259
2417
|
});
|
|
2260
|
-
|
|
2261
|
-
state: import_services3.Invitation.State.TIMEOUT
|
|
2262
|
-
});
|
|
2418
|
+
guardedState.set(extension, import_services3.Invitation.State.TIMEOUT);
|
|
2263
2419
|
} else {
|
|
2264
2420
|
(0, import_log4.log)("auth failed", err, {
|
|
2265
|
-
F:
|
|
2266
|
-
L:
|
|
2421
|
+
F: __dxlog_file9,
|
|
2422
|
+
L: 330,
|
|
2267
2423
|
S: this,
|
|
2268
2424
|
C: (f, a) => f(...a)
|
|
2269
2425
|
});
|
|
2270
|
-
|
|
2426
|
+
guardedState.error(extension, err);
|
|
2271
2427
|
}
|
|
2272
2428
|
}
|
|
2273
2429
|
});
|
|
@@ -2277,68 +2433,140 @@ var InvitationsHandler = class {
|
|
|
2277
2433
|
const error = protocol.checkInvitation(invitation);
|
|
2278
2434
|
if (error) {
|
|
2279
2435
|
stream.error(error);
|
|
2436
|
+
await ctx.dispose();
|
|
2280
2437
|
} else {
|
|
2281
2438
|
(0, import_invariant5.invariant)(invitation.swarmKey, void 0, {
|
|
2282
|
-
F:
|
|
2283
|
-
L:
|
|
2439
|
+
F: __dxlog_file9,
|
|
2440
|
+
L: 345,
|
|
2284
2441
|
S: this,
|
|
2285
2442
|
A: [
|
|
2286
2443
|
"invitation.swarmKey",
|
|
2287
2444
|
""
|
|
2288
2445
|
]
|
|
2289
2446
|
});
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
topic,
|
|
2293
|
-
peerId: import_keys5.PublicKey.random(),
|
|
2294
|
-
protocolProvider: (0, import_network_manager.createTeleportProtocolFactory)(async (teleport) => {
|
|
2295
|
-
teleport.addExtension("dxos.halo.invitations", createExtension());
|
|
2296
|
-
}),
|
|
2297
|
-
topology: new import_network_manager.StarTopology(topic),
|
|
2298
|
-
label: "invitation guest"
|
|
2299
|
-
});
|
|
2300
|
-
ctx.onDispose(() => swarmConnection.close());
|
|
2301
|
-
setState({
|
|
2302
|
-
state: import_services3.Invitation.State.CONNECTING
|
|
2303
|
-
});
|
|
2447
|
+
await this._joinSwarm(ctx, invitation, import_invitations2.Options.Role.GUEST, createExtension);
|
|
2448
|
+
guardedState.set(null, import_services3.Invitation.State.CONNECTING);
|
|
2304
2449
|
}
|
|
2305
2450
|
});
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2451
|
+
}
|
|
2452
|
+
async _joinSwarm(ctx, invitation, role, extensionFactory) {
|
|
2453
|
+
let label;
|
|
2454
|
+
if (role === import_invitations2.Options.Role.GUEST) {
|
|
2455
|
+
label = "invitation guest";
|
|
2456
|
+
} else if (invitation.kind === import_services3.Invitation.Kind.DEVICE) {
|
|
2457
|
+
label = "invitation host for device";
|
|
2458
|
+
} else {
|
|
2459
|
+
label = `invitation host for space ${invitation.spaceKey?.truncate()}`;
|
|
2460
|
+
}
|
|
2461
|
+
const swarmConnection = await this._networkManager.joinSwarm({
|
|
2462
|
+
topic: invitation.swarmKey,
|
|
2463
|
+
peerId: import_keys5.PublicKey.random(),
|
|
2464
|
+
protocolProvider: (0, import_network_manager.createTeleportProtocolFactory)(async (teleport) => {
|
|
2465
|
+
teleport.addExtension("dxos.halo.invitations", extensionFactory());
|
|
2466
|
+
}, this._defaultTeleportParams),
|
|
2467
|
+
topology: new InvitationTopology(role),
|
|
2468
|
+
label
|
|
2469
|
+
});
|
|
2470
|
+
ctx.onDispose(() => swarmConnection.close());
|
|
2471
|
+
return swarmConnection;
|
|
2472
|
+
}
|
|
2473
|
+
/**
|
|
2474
|
+
* A utility object for serializing invitation state changes by multiple concurrent
|
|
2475
|
+
* invitation flow connections.
|
|
2476
|
+
*/
|
|
2477
|
+
_createGuardedState(ctx, invitation, stream) {
|
|
2478
|
+
const mutex = new import_async7.Mutex();
|
|
2479
|
+
let lastActiveExtension = null;
|
|
2480
|
+
let currentInvitation = {
|
|
2481
|
+
...invitation
|
|
2482
|
+
};
|
|
2483
|
+
const isStateChangeAllowed = (extension) => {
|
|
2484
|
+
if (ctx.disposed || extension !== null && mutex.isLocked() && !extension.hasFlowLock()) {
|
|
2485
|
+
return false;
|
|
2486
|
+
}
|
|
2487
|
+
return extension == null || lastActiveExtension !== extension || this._isNotTerminal(currentInvitation.state);
|
|
2488
|
+
};
|
|
2489
|
+
return {
|
|
2490
|
+
mutex,
|
|
2491
|
+
get current() {
|
|
2492
|
+
return currentInvitation;
|
|
2314
2493
|
},
|
|
2315
|
-
|
|
2316
|
-
|
|
2494
|
+
// disposing context prevents any further state updates
|
|
2495
|
+
complete: (newState) => {
|
|
2496
|
+
currentInvitation = {
|
|
2497
|
+
...currentInvitation,
|
|
2498
|
+
...newState
|
|
2499
|
+
};
|
|
2500
|
+
stream.next(currentInvitation);
|
|
2501
|
+
return ctx.dispose();
|
|
2502
|
+
},
|
|
2503
|
+
set: (extension, newState) => {
|
|
2504
|
+
if (isStateChangeAllowed(extension)) {
|
|
2505
|
+
this._logStateUpdate(currentInvitation, extension, newState);
|
|
2506
|
+
currentInvitation = {
|
|
2507
|
+
...currentInvitation,
|
|
2508
|
+
state: newState
|
|
2509
|
+
};
|
|
2510
|
+
stream.next(currentInvitation);
|
|
2511
|
+
lastActiveExtension = extension;
|
|
2512
|
+
return true;
|
|
2513
|
+
}
|
|
2514
|
+
return false;
|
|
2515
|
+
},
|
|
2516
|
+
error: (extension, error) => {
|
|
2517
|
+
if (isStateChangeAllowed(extension)) {
|
|
2518
|
+
this._logStateUpdate(currentInvitation, extension, import_services3.Invitation.State.ERROR);
|
|
2519
|
+
currentInvitation = {
|
|
2520
|
+
...currentInvitation,
|
|
2521
|
+
state: import_services3.Invitation.State.ERROR
|
|
2522
|
+
};
|
|
2523
|
+
stream.next(currentInvitation);
|
|
2524
|
+
stream.error(error);
|
|
2525
|
+
lastActiveExtension = extension;
|
|
2526
|
+
return true;
|
|
2527
|
+
}
|
|
2528
|
+
return false;
|
|
2317
2529
|
}
|
|
2530
|
+
};
|
|
2531
|
+
}
|
|
2532
|
+
_logStateUpdate(invitation, actor, newState) {
|
|
2533
|
+
(0, import_log4.log)("invitation state update", {
|
|
2534
|
+
actor: actor?.constructor.name,
|
|
2535
|
+
newState: stateToString(newState),
|
|
2536
|
+
oldState: stateToString(invitation.state)
|
|
2537
|
+
}, {
|
|
2538
|
+
F: __dxlog_file9,
|
|
2539
|
+
L: 438,
|
|
2540
|
+
S: this,
|
|
2541
|
+
C: (f, a) => f(...a)
|
|
2318
2542
|
});
|
|
2319
|
-
|
|
2543
|
+
}
|
|
2544
|
+
_isNotTerminal(currentState) {
|
|
2545
|
+
return ![
|
|
2546
|
+
import_services3.Invitation.State.SUCCESS,
|
|
2547
|
+
import_services3.Invitation.State.ERROR,
|
|
2548
|
+
import_services3.Invitation.State.CANCELLED,
|
|
2549
|
+
import_services3.Invitation.State.TIMEOUT,
|
|
2550
|
+
import_services3.Invitation.State.EXPIRED
|
|
2551
|
+
].includes(currentState);
|
|
2320
2552
|
}
|
|
2321
2553
|
async _handleGuestOtpAuth(extension, setState, authenticated, options) {
|
|
2322
2554
|
for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
|
|
2323
2555
|
(0, import_log4.log)("guest waiting for authentication code...", void 0, {
|
|
2324
|
-
F:
|
|
2325
|
-
L:
|
|
2556
|
+
F: __dxlog_file9,
|
|
2557
|
+
L: 462,
|
|
2326
2558
|
S: this,
|
|
2327
2559
|
C: (f, a) => f(...a)
|
|
2328
2560
|
});
|
|
2329
|
-
setState(
|
|
2330
|
-
state: import_services3.Invitation.State.READY_FOR_AUTHENTICATION
|
|
2331
|
-
});
|
|
2561
|
+
setState(import_services3.Invitation.State.READY_FOR_AUTHENTICATION);
|
|
2332
2562
|
const authCode = await authenticated.wait(options);
|
|
2333
2563
|
(0, import_log4.log)("sending authentication request", void 0, {
|
|
2334
|
-
F:
|
|
2335
|
-
L:
|
|
2564
|
+
F: __dxlog_file9,
|
|
2565
|
+
L: 466,
|
|
2336
2566
|
S: this,
|
|
2337
2567
|
C: (f, a) => f(...a)
|
|
2338
2568
|
});
|
|
2339
|
-
setState(
|
|
2340
|
-
state: import_services3.Invitation.State.AUTHENTICATING
|
|
2341
|
-
});
|
|
2569
|
+
setState(import_services3.Invitation.State.AUTHENTICATING);
|
|
2342
2570
|
const response = await extension.rpc.InvitationHostService.authenticate({
|
|
2343
2571
|
authCode
|
|
2344
2572
|
});
|
|
@@ -2352,8 +2580,8 @@ var InvitationsHandler = class {
|
|
|
2352
2580
|
(0, import_log4.log)("retrying invalid code", {
|
|
2353
2581
|
attempt
|
|
2354
2582
|
}, {
|
|
2355
|
-
F:
|
|
2356
|
-
L:
|
|
2583
|
+
F: __dxlog_file9,
|
|
2584
|
+
L: 477,
|
|
2357
2585
|
S: this,
|
|
2358
2586
|
C: (f, a) => f(...a)
|
|
2359
2587
|
});
|
|
@@ -2370,14 +2598,12 @@ var InvitationsHandler = class {
|
|
|
2370
2598
|
throw new Error("challenge missing in the introduction");
|
|
2371
2599
|
}
|
|
2372
2600
|
(0, import_log4.log)("sending authentication request", void 0, {
|
|
2373
|
-
F:
|
|
2374
|
-
L:
|
|
2601
|
+
F: __dxlog_file9,
|
|
2602
|
+
L: 496,
|
|
2375
2603
|
S: this,
|
|
2376
2604
|
C: (f, a) => f(...a)
|
|
2377
2605
|
});
|
|
2378
|
-
setState(
|
|
2379
|
-
state: import_services3.Invitation.State.AUTHENTICATING
|
|
2380
|
-
});
|
|
2606
|
+
setState(import_services3.Invitation.State.AUTHENTICATING);
|
|
2381
2607
|
const signature = (0, import_crypto.sign)(Buffer.from(introductionResponse.challenge), invitation.guestKeypair.privateKey);
|
|
2382
2608
|
const response = await extension.rpc.InvitationHostService.authenticate({
|
|
2383
2609
|
signedChallenge: signature
|
|
@@ -2423,8 +2649,8 @@ var InvitationsServiceImpl = class {
|
|
|
2423
2649
|
return new import_codec_protobuf8.Stream(({ next, ctx }) => {
|
|
2424
2650
|
this._invitationsManager.invitationCreated.on(ctx, (invitation) => {
|
|
2425
2651
|
next({
|
|
2426
|
-
action:
|
|
2427
|
-
type:
|
|
2652
|
+
action: import_services6.QueryInvitationsResponse.Action.ADDED,
|
|
2653
|
+
type: import_services6.QueryInvitationsResponse.Type.CREATED,
|
|
2428
2654
|
invitations: [
|
|
2429
2655
|
invitation
|
|
2430
2656
|
]
|
|
@@ -2432,8 +2658,8 @@ var InvitationsServiceImpl = class {
|
|
|
2432
2658
|
});
|
|
2433
2659
|
this._invitationsManager.invitationAccepted.on(ctx, (invitation) => {
|
|
2434
2660
|
next({
|
|
2435
|
-
action:
|
|
2436
|
-
type:
|
|
2661
|
+
action: import_services6.QueryInvitationsResponse.Action.ADDED,
|
|
2662
|
+
type: import_services6.QueryInvitationsResponse.Type.ACCEPTED,
|
|
2437
2663
|
invitations: [
|
|
2438
2664
|
invitation
|
|
2439
2665
|
]
|
|
@@ -2441,8 +2667,8 @@ var InvitationsServiceImpl = class {
|
|
|
2441
2667
|
});
|
|
2442
2668
|
this._invitationsManager.removedCreated.on(ctx, (invitation) => {
|
|
2443
2669
|
next({
|
|
2444
|
-
action:
|
|
2445
|
-
type:
|
|
2670
|
+
action: import_services6.QueryInvitationsResponse.Action.REMOVED,
|
|
2671
|
+
type: import_services6.QueryInvitationsResponse.Type.CREATED,
|
|
2446
2672
|
invitations: [
|
|
2447
2673
|
invitation
|
|
2448
2674
|
]
|
|
@@ -2450,8 +2676,8 @@ var InvitationsServiceImpl = class {
|
|
|
2450
2676
|
});
|
|
2451
2677
|
this._invitationsManager.removedAccepted.on(ctx, (invitation) => {
|
|
2452
2678
|
next({
|
|
2453
|
-
action:
|
|
2454
|
-
type:
|
|
2679
|
+
action: import_services6.QueryInvitationsResponse.Action.REMOVED,
|
|
2680
|
+
type: import_services6.QueryInvitationsResponse.Type.ACCEPTED,
|
|
2455
2681
|
invitations: [
|
|
2456
2682
|
invitation
|
|
2457
2683
|
]
|
|
@@ -2459,35 +2685,35 @@ var InvitationsServiceImpl = class {
|
|
|
2459
2685
|
});
|
|
2460
2686
|
this._invitationsManager.saved.on(ctx, (invitation) => {
|
|
2461
2687
|
next({
|
|
2462
|
-
action:
|
|
2463
|
-
type:
|
|
2688
|
+
action: import_services6.QueryInvitationsResponse.Action.SAVED,
|
|
2689
|
+
type: import_services6.QueryInvitationsResponse.Type.CREATED,
|
|
2464
2690
|
invitations: [
|
|
2465
2691
|
invitation
|
|
2466
2692
|
]
|
|
2467
2693
|
});
|
|
2468
2694
|
});
|
|
2469
2695
|
next({
|
|
2470
|
-
action:
|
|
2471
|
-
type:
|
|
2696
|
+
action: import_services6.QueryInvitationsResponse.Action.ADDED,
|
|
2697
|
+
type: import_services6.QueryInvitationsResponse.Type.CREATED,
|
|
2472
2698
|
invitations: this._invitationsManager.getCreatedInvitations(),
|
|
2473
2699
|
existing: true
|
|
2474
2700
|
});
|
|
2475
2701
|
next({
|
|
2476
|
-
action:
|
|
2477
|
-
type:
|
|
2702
|
+
action: import_services6.QueryInvitationsResponse.Action.ADDED,
|
|
2703
|
+
type: import_services6.QueryInvitationsResponse.Type.ACCEPTED,
|
|
2478
2704
|
invitations: this._invitationsManager.getAcceptedInvitations(),
|
|
2479
2705
|
existing: true
|
|
2480
2706
|
});
|
|
2481
2707
|
this._invitationsManager.onPersistentInvitationsLoaded(ctx, () => {
|
|
2482
2708
|
next({
|
|
2483
|
-
action:
|
|
2484
|
-
type:
|
|
2709
|
+
action: import_services6.QueryInvitationsResponse.Action.LOAD_COMPLETE,
|
|
2710
|
+
type: import_services6.QueryInvitationsResponse.Type.CREATED
|
|
2485
2711
|
});
|
|
2486
2712
|
});
|
|
2487
2713
|
});
|
|
2488
2714
|
}
|
|
2489
2715
|
};
|
|
2490
|
-
var
|
|
2716
|
+
var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
|
|
2491
2717
|
var SpaceInvitationProtocol = class {
|
|
2492
2718
|
constructor(_spaceManager, _signingContext, _keyring, _spaceKey) {
|
|
2493
2719
|
this._spaceManager = _spaceManager;
|
|
@@ -2503,14 +2729,14 @@ var SpaceInvitationProtocol = class {
|
|
|
2503
2729
|
}
|
|
2504
2730
|
getInvitationContext() {
|
|
2505
2731
|
return {
|
|
2506
|
-
kind:
|
|
2732
|
+
kind: import_services7.Invitation.Kind.SPACE,
|
|
2507
2733
|
spaceKey: this._spaceKey
|
|
2508
2734
|
};
|
|
2509
2735
|
}
|
|
2510
2736
|
async admit(invitation, request, guestProfile) {
|
|
2511
|
-
(0,
|
|
2512
|
-
F:
|
|
2513
|
-
L:
|
|
2737
|
+
(0, import_invariant9.invariant)(this._spaceKey, void 0, {
|
|
2738
|
+
F: __dxlog_file10,
|
|
2739
|
+
L: 56,
|
|
2514
2740
|
S: this,
|
|
2515
2741
|
A: [
|
|
2516
2742
|
"this._spaceKey",
|
|
@@ -2518,18 +2744,18 @@ var SpaceInvitationProtocol = class {
|
|
|
2518
2744
|
]
|
|
2519
2745
|
});
|
|
2520
2746
|
const space = await this._spaceManager.spaces.get(this._spaceKey);
|
|
2521
|
-
(0,
|
|
2522
|
-
F:
|
|
2523
|
-
L:
|
|
2747
|
+
(0, import_invariant9.invariant)(space, void 0, {
|
|
2748
|
+
F: __dxlog_file10,
|
|
2749
|
+
L: 58,
|
|
2524
2750
|
S: this,
|
|
2525
2751
|
A: [
|
|
2526
2752
|
"space",
|
|
2527
2753
|
""
|
|
2528
2754
|
]
|
|
2529
2755
|
});
|
|
2530
|
-
(0,
|
|
2531
|
-
F:
|
|
2532
|
-
L:
|
|
2756
|
+
(0, import_invariant9.invariant)(request.space, void 0, {
|
|
2757
|
+
F: __dxlog_file10,
|
|
2758
|
+
L: 60,
|
|
2533
2759
|
S: this,
|
|
2534
2760
|
A: [
|
|
2535
2761
|
"request.space",
|
|
@@ -2537,19 +2763,19 @@ var SpaceInvitationProtocol = class {
|
|
|
2537
2763
|
]
|
|
2538
2764
|
});
|
|
2539
2765
|
const { identityKey, deviceKey } = request.space;
|
|
2540
|
-
(0,
|
|
2766
|
+
(0, import_log8.log)("writing guest credentials", {
|
|
2541
2767
|
host: this._signingContext.deviceKey,
|
|
2542
2768
|
guest: deviceKey
|
|
2543
2769
|
}, {
|
|
2544
|
-
F:
|
|
2545
|
-
L:
|
|
2770
|
+
F: __dxlog_file10,
|
|
2771
|
+
L: 63,
|
|
2546
2772
|
S: this,
|
|
2547
2773
|
C: (f, a) => f(...a)
|
|
2548
2774
|
});
|
|
2549
2775
|
const credentials = await (0, import_credentials7.createAdmissionCredentials)(this._signingContext.credentialSigner, identityKey, space.key, space.inner.genesisFeedKey, guestProfile, invitation.delegationCredentialId);
|
|
2550
|
-
(0,
|
|
2551
|
-
F:
|
|
2552
|
-
L:
|
|
2776
|
+
(0, import_invariant9.invariant)(credentials[0].credential, void 0, {
|
|
2777
|
+
F: __dxlog_file10,
|
|
2778
|
+
L: 75,
|
|
2553
2779
|
S: this,
|
|
2554
2780
|
A: [
|
|
2555
2781
|
"credentials[0].credential",
|
|
@@ -2557,9 +2783,9 @@ var SpaceInvitationProtocol = class {
|
|
|
2557
2783
|
]
|
|
2558
2784
|
});
|
|
2559
2785
|
const spaceMemberCredential = credentials[0].credential.credential;
|
|
2560
|
-
(0,
|
|
2561
|
-
F:
|
|
2562
|
-
L:
|
|
2786
|
+
(0, import_invariant9.invariant)((0, import_credentials7.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
|
|
2787
|
+
F: __dxlog_file10,
|
|
2788
|
+
L: 77,
|
|
2563
2789
|
S: this,
|
|
2564
2790
|
A: [
|
|
2565
2791
|
"getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
|
|
@@ -2575,29 +2801,29 @@ var SpaceInvitationProtocol = class {
|
|
|
2575
2801
|
};
|
|
2576
2802
|
}
|
|
2577
2803
|
async delegate(invitation) {
|
|
2578
|
-
(0,
|
|
2579
|
-
F:
|
|
2580
|
-
L:
|
|
2804
|
+
(0, import_invariant9.invariant)(this._spaceKey, void 0, {
|
|
2805
|
+
F: __dxlog_file10,
|
|
2806
|
+
L: 90,
|
|
2581
2807
|
S: this,
|
|
2582
2808
|
A: [
|
|
2583
2809
|
"this._spaceKey",
|
|
2584
2810
|
""
|
|
2585
2811
|
]
|
|
2586
2812
|
});
|
|
2587
|
-
const space =
|
|
2588
|
-
(0,
|
|
2589
|
-
F:
|
|
2590
|
-
L:
|
|
2813
|
+
const space = this._spaceManager.spaces.get(this._spaceKey);
|
|
2814
|
+
(0, import_invariant9.invariant)(space, void 0, {
|
|
2815
|
+
F: __dxlog_file10,
|
|
2816
|
+
L: 92,
|
|
2591
2817
|
S: this,
|
|
2592
2818
|
A: [
|
|
2593
2819
|
"space",
|
|
2594
2820
|
""
|
|
2595
2821
|
]
|
|
2596
2822
|
});
|
|
2597
|
-
if (invitation.authMethod ===
|
|
2598
|
-
(0,
|
|
2599
|
-
F:
|
|
2600
|
-
L:
|
|
2823
|
+
if (invitation.authMethod === import_services7.Invitation.AuthMethod.KNOWN_PUBLIC_KEY) {
|
|
2824
|
+
(0, import_invariant9.invariant)(invitation.guestKeypair?.publicKey, void 0, {
|
|
2825
|
+
F: __dxlog_file10,
|
|
2826
|
+
L: 94,
|
|
2601
2827
|
S: this,
|
|
2602
2828
|
A: [
|
|
2603
2829
|
"invitation.guestKeypair?.publicKey",
|
|
@@ -2605,12 +2831,12 @@ var SpaceInvitationProtocol = class {
|
|
|
2605
2831
|
]
|
|
2606
2832
|
});
|
|
2607
2833
|
}
|
|
2608
|
-
(0,
|
|
2834
|
+
(0, import_log8.log)("writing delegate space invitation", {
|
|
2609
2835
|
host: this._signingContext.deviceKey,
|
|
2610
2836
|
id: invitation.invitationId
|
|
2611
2837
|
}, {
|
|
2612
|
-
F:
|
|
2613
|
-
L:
|
|
2838
|
+
F: __dxlog_file10,
|
|
2839
|
+
L: 97,
|
|
2614
2840
|
S: this,
|
|
2615
2841
|
C: (f, a) => f(...a)
|
|
2616
2842
|
});
|
|
@@ -2621,11 +2847,11 @@ var SpaceInvitationProtocol = class {
|
|
|
2621
2847
|
role: import_credentials8.SpaceMember.Role.ADMIN,
|
|
2622
2848
|
expiresOn: invitation.lifetime ? new Date((invitation.created?.getTime() ?? Date.now()) + invitation.lifetime) : void 0,
|
|
2623
2849
|
multiUse: invitation.multiUse ?? false,
|
|
2624
|
-
guestKey: invitation.authMethod ===
|
|
2850
|
+
guestKey: invitation.authMethod === import_services7.Invitation.AuthMethod.KNOWN_PUBLIC_KEY ? invitation.guestKeypair.publicKey : void 0
|
|
2625
2851
|
});
|
|
2626
|
-
(0,
|
|
2627
|
-
F:
|
|
2628
|
-
L:
|
|
2852
|
+
(0, import_invariant9.invariant)(credential.credential, void 0, {
|
|
2853
|
+
F: __dxlog_file10,
|
|
2854
|
+
L: 117,
|
|
2629
2855
|
S: this,
|
|
2630
2856
|
A: [
|
|
2631
2857
|
"credential.credential",
|
|
@@ -2637,9 +2863,61 @@ var SpaceInvitationProtocol = class {
|
|
|
2637
2863
|
]);
|
|
2638
2864
|
return credential.credential.credential.id;
|
|
2639
2865
|
}
|
|
2866
|
+
async cancelDelegation(invitation) {
|
|
2867
|
+
(0, import_invariant9.invariant)(this._spaceKey, void 0, {
|
|
2868
|
+
F: __dxlog_file10,
|
|
2869
|
+
L: 123,
|
|
2870
|
+
S: this,
|
|
2871
|
+
A: [
|
|
2872
|
+
"this._spaceKey",
|
|
2873
|
+
""
|
|
2874
|
+
]
|
|
2875
|
+
});
|
|
2876
|
+
(0, import_invariant9.invariant)(invitation.type === import_services7.Invitation.Type.DELEGATED && invitation.delegationCredentialId, void 0, {
|
|
2877
|
+
F: __dxlog_file10,
|
|
2878
|
+
L: 124,
|
|
2879
|
+
S: this,
|
|
2880
|
+
A: [
|
|
2881
|
+
"invitation.type === Invitation.Type.DELEGATED && invitation.delegationCredentialId",
|
|
2882
|
+
""
|
|
2883
|
+
]
|
|
2884
|
+
});
|
|
2885
|
+
const space = this._spaceManager.spaces.get(this._spaceKey);
|
|
2886
|
+
(0, import_invariant9.invariant)(space, void 0, {
|
|
2887
|
+
F: __dxlog_file10,
|
|
2888
|
+
L: 126,
|
|
2889
|
+
S: this,
|
|
2890
|
+
A: [
|
|
2891
|
+
"space",
|
|
2892
|
+
""
|
|
2893
|
+
]
|
|
2894
|
+
});
|
|
2895
|
+
(0, import_log8.log)("cancelling delegated space invitation", {
|
|
2896
|
+
host: this._signingContext.deviceKey,
|
|
2897
|
+
id: invitation.invitationId
|
|
2898
|
+
}, {
|
|
2899
|
+
F: __dxlog_file10,
|
|
2900
|
+
L: 128,
|
|
2901
|
+
S: this,
|
|
2902
|
+
C: (f, a) => f(...a)
|
|
2903
|
+
});
|
|
2904
|
+
const credential = await (0, import_credentials7.createCancelDelegatedSpaceInvitationCredential)(this._signingContext.credentialSigner, space.key, invitation.delegationCredentialId);
|
|
2905
|
+
(0, import_invariant9.invariant)(credential.credential, void 0, {
|
|
2906
|
+
F: __dxlog_file10,
|
|
2907
|
+
L: 135,
|
|
2908
|
+
S: this,
|
|
2909
|
+
A: [
|
|
2910
|
+
"credential.credential",
|
|
2911
|
+
""
|
|
2912
|
+
]
|
|
2913
|
+
});
|
|
2914
|
+
await (0, import_feed_store3.writeMessages)(space.inner.controlPipeline.writer, [
|
|
2915
|
+
credential
|
|
2916
|
+
]);
|
|
2917
|
+
}
|
|
2640
2918
|
checkInvitation(invitation) {
|
|
2641
2919
|
if (invitation.spaceKey && this._spaceManager.spaces.has(invitation.spaceKey)) {
|
|
2642
|
-
return new
|
|
2920
|
+
return new import_protocols7.AlreadyJoinedError("Already joined space.");
|
|
2643
2921
|
}
|
|
2644
2922
|
}
|
|
2645
2923
|
createIntroduction() {
|
|
@@ -2660,9 +2938,9 @@ var SpaceInvitationProtocol = class {
|
|
|
2660
2938
|
};
|
|
2661
2939
|
}
|
|
2662
2940
|
async accept(response) {
|
|
2663
|
-
(0,
|
|
2664
|
-
F:
|
|
2665
|
-
L:
|
|
2941
|
+
(0, import_invariant9.invariant)(response.space, void 0, {
|
|
2942
|
+
F: __dxlog_file10,
|
|
2943
|
+
L: 167,
|
|
2666
2944
|
S: this,
|
|
2667
2945
|
A: [
|
|
2668
2946
|
"response.space",
|
|
@@ -2671,18 +2949,18 @@ var SpaceInvitationProtocol = class {
|
|
|
2671
2949
|
});
|
|
2672
2950
|
const { credential, controlTimeframe, dataTimeframe } = response.space;
|
|
2673
2951
|
const assertion = (0, import_credentials7.getCredentialAssertion)(credential);
|
|
2674
|
-
(0,
|
|
2675
|
-
F:
|
|
2676
|
-
L:
|
|
2952
|
+
(0, import_invariant9.invariant)(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
|
|
2953
|
+
F: __dxlog_file10,
|
|
2954
|
+
L: 170,
|
|
2677
2955
|
S: this,
|
|
2678
2956
|
A: [
|
|
2679
2957
|
"assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
|
|
2680
2958
|
"'Invalid credential'"
|
|
2681
2959
|
]
|
|
2682
2960
|
});
|
|
2683
|
-
(0,
|
|
2684
|
-
F:
|
|
2685
|
-
L:
|
|
2961
|
+
(0, import_invariant9.invariant)(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
|
|
2962
|
+
F: __dxlog_file10,
|
|
2963
|
+
L: 171,
|
|
2686
2964
|
S: this,
|
|
2687
2965
|
A: [
|
|
2688
2966
|
"credential.subject.id.equals(this._signingContext.identityKey)",
|
|
@@ -2690,7 +2968,7 @@ var SpaceInvitationProtocol = class {
|
|
|
2690
2968
|
]
|
|
2691
2969
|
});
|
|
2692
2970
|
if (this._spaceManager.spaces.has(assertion.spaceKey)) {
|
|
2693
|
-
throw new
|
|
2971
|
+
throw new import_protocols7.AlreadyJoinedError("Already joined space.");
|
|
2694
2972
|
}
|
|
2695
2973
|
await this._spaceManager.acceptSpace({
|
|
2696
2974
|
spaceKey: assertion.spaceKey,
|
|
@@ -2704,7 +2982,7 @@ var SpaceInvitationProtocol = class {
|
|
|
2704
2982
|
};
|
|
2705
2983
|
}
|
|
2706
2984
|
};
|
|
2707
|
-
var
|
|
2985
|
+
var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts";
|
|
2708
2986
|
var InvitationsManager = class {
|
|
2709
2987
|
constructor(_invitationsHandler, _getHandler, _metadataStore) {
|
|
2710
2988
|
this._invitationsHandler = _invitationsHandler;
|
|
@@ -2712,12 +2990,12 @@ var InvitationsManager = class {
|
|
|
2712
2990
|
this._metadataStore = _metadataStore;
|
|
2713
2991
|
this._createInvitations = /* @__PURE__ */ new Map();
|
|
2714
2992
|
this._acceptInvitations = /* @__PURE__ */ new Map();
|
|
2715
|
-
this.invitationCreated = new
|
|
2716
|
-
this.invitationAccepted = new
|
|
2717
|
-
this.removedCreated = new
|
|
2718
|
-
this.removedAccepted = new
|
|
2719
|
-
this.saved = new
|
|
2720
|
-
this._persistentInvitationsLoadedEvent = new
|
|
2993
|
+
this.invitationCreated = new import_async10.Event();
|
|
2994
|
+
this.invitationAccepted = new import_async10.Event();
|
|
2995
|
+
this.removedCreated = new import_async10.Event();
|
|
2996
|
+
this.removedAccepted = new import_async10.Event();
|
|
2997
|
+
this.saved = new import_async10.Event();
|
|
2998
|
+
this._persistentInvitationsLoadedEvent = new import_async10.Event();
|
|
2721
2999
|
this._persistentInvitationsLoaded = false;
|
|
2722
3000
|
}
|
|
2723
3001
|
async createInvitation(options) {
|
|
@@ -2742,8 +3020,8 @@ var InvitationsManager = class {
|
|
|
2742
3020
|
try {
|
|
2743
3021
|
await this._persistIfRequired(handler, stream, invitation);
|
|
2744
3022
|
} catch (err) {
|
|
2745
|
-
|
|
2746
|
-
F:
|
|
3023
|
+
import_log9.log.catch(err, void 0, {
|
|
3024
|
+
F: __dxlog_file11,
|
|
2747
3025
|
L: 76,
|
|
2748
3026
|
S: this,
|
|
2749
3027
|
C: (f, a) => f(...a)
|
|
@@ -2765,8 +3043,8 @@ var InvitationsManager = class {
|
|
|
2765
3043
|
const persistentInvitations = this._metadataStore.getInvitations();
|
|
2766
3044
|
const freshInvitations = persistentInvitations.filter((invitation) => !(0, import_echo_pipeline.hasInvitationExpired)(invitation));
|
|
2767
3045
|
const loadTasks = freshInvitations.map((persistentInvitation) => {
|
|
2768
|
-
(0,
|
|
2769
|
-
F:
|
|
3046
|
+
(0, import_invariant10.invariant)(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
|
|
3047
|
+
F: __dxlog_file11,
|
|
2770
3048
|
L: 97,
|
|
2771
3049
|
S: this,
|
|
2772
3050
|
A: [
|
|
@@ -2784,8 +3062,8 @@ var InvitationsManager = class {
|
|
|
2784
3062
|
invitations: cInvitations.map((invitation) => invitation.get())
|
|
2785
3063
|
};
|
|
2786
3064
|
} catch (err) {
|
|
2787
|
-
|
|
2788
|
-
F:
|
|
3065
|
+
import_log9.log.catch(err, void 0, {
|
|
3066
|
+
F: __dxlog_file11,
|
|
2789
3067
|
L: 104,
|
|
2790
3068
|
S: this,
|
|
2791
3069
|
C: (f, a) => f(...a)
|
|
@@ -2805,7 +3083,8 @@ var InvitationsManager = class {
|
|
|
2805
3083
|
return existingInvitation;
|
|
2806
3084
|
}
|
|
2807
3085
|
const handler = this._getHandler(options);
|
|
2808
|
-
const invitation = this.
|
|
3086
|
+
const { ctx, invitation, stream, otpEnteredTrigger } = this._createObservableAcceptingInvitation(handler, options);
|
|
3087
|
+
this._invitationsHandler.acceptInvitation(ctx, stream, handler, options, otpEnteredTrigger, request.deviceProfile);
|
|
2809
3088
|
this._acceptInvitations.set(invitation.get().invitationId, invitation);
|
|
2810
3089
|
this.invitationAccepted.emit(invitation.get());
|
|
2811
3090
|
this._onInvitationComplete(invitation, () => {
|
|
@@ -2815,15 +3094,15 @@ var InvitationsManager = class {
|
|
|
2815
3094
|
return invitation;
|
|
2816
3095
|
}
|
|
2817
3096
|
async authenticate({ invitationId, authCode }) {
|
|
2818
|
-
(0,
|
|
2819
|
-
F:
|
|
2820
|
-
L:
|
|
3097
|
+
(0, import_log9.log)("authenticating...", void 0, {
|
|
3098
|
+
F: __dxlog_file11,
|
|
3099
|
+
L: 134,
|
|
2821
3100
|
S: this,
|
|
2822
3101
|
C: (f, a) => f(...a)
|
|
2823
3102
|
});
|
|
2824
|
-
(0,
|
|
2825
|
-
F:
|
|
2826
|
-
L:
|
|
3103
|
+
(0, import_invariant10.invariant)(invitationId, void 0, {
|
|
3104
|
+
F: __dxlog_file11,
|
|
3105
|
+
L: 135,
|
|
2827
3106
|
S: this,
|
|
2828
3107
|
A: [
|
|
2829
3108
|
"invitationId",
|
|
@@ -2832,11 +3111,11 @@ var InvitationsManager = class {
|
|
|
2832
3111
|
});
|
|
2833
3112
|
const observable = this._acceptInvitations.get(invitationId);
|
|
2834
3113
|
if (!observable) {
|
|
2835
|
-
|
|
3114
|
+
import_log9.log.warn("invalid invitation", {
|
|
2836
3115
|
invitationId
|
|
2837
3116
|
}, {
|
|
2838
|
-
F:
|
|
2839
|
-
L:
|
|
3117
|
+
F: __dxlog_file11,
|
|
3118
|
+
L: 138,
|
|
2840
3119
|
S: this,
|
|
2841
3120
|
C: (f, a) => f(...a)
|
|
2842
3121
|
});
|
|
@@ -2845,17 +3124,17 @@ var InvitationsManager = class {
|
|
|
2845
3124
|
}
|
|
2846
3125
|
}
|
|
2847
3126
|
async cancelInvitation({ invitationId }) {
|
|
2848
|
-
(0,
|
|
3127
|
+
(0, import_log9.log)("cancelInvitation...", {
|
|
2849
3128
|
invitationId
|
|
2850
3129
|
}, {
|
|
2851
|
-
F:
|
|
2852
|
-
L:
|
|
3130
|
+
F: __dxlog_file11,
|
|
3131
|
+
L: 145,
|
|
2853
3132
|
S: this,
|
|
2854
3133
|
C: (f, a) => f(...a)
|
|
2855
3134
|
});
|
|
2856
|
-
(0,
|
|
2857
|
-
F:
|
|
2858
|
-
L:
|
|
3135
|
+
(0, import_invariant10.invariant)(invitationId, void 0, {
|
|
3136
|
+
F: __dxlog_file11,
|
|
3137
|
+
L: 146,
|
|
2859
3138
|
S: this,
|
|
2860
3139
|
A: [
|
|
2861
3140
|
"invitationId",
|
|
@@ -2867,6 +3146,10 @@ var InvitationsManager = class {
|
|
|
2867
3146
|
if (created.get().persistent) {
|
|
2868
3147
|
await this._metadataStore.removeInvitation(invitationId);
|
|
2869
3148
|
}
|
|
3149
|
+
if (created.get().type === import_services8.Invitation.Type.DELEGATED) {
|
|
3150
|
+
const handler = this._getHandler(created.get());
|
|
3151
|
+
await handler.cancelDelegation(created.get());
|
|
3152
|
+
}
|
|
2870
3153
|
await created.cancel();
|
|
2871
3154
|
this._createInvitations.delete(invitationId);
|
|
2872
3155
|
this.removedCreated.emit(created.get());
|
|
@@ -2897,8 +3180,8 @@ var InvitationsManager = class {
|
|
|
2897
3180
|
}
|
|
2898
3181
|
}
|
|
2899
3182
|
_createInvitation(protocol, options) {
|
|
2900
|
-
const { invitationId =
|
|
2901
|
-
const authCode = options?.authCode ?? (authMethod ===
|
|
3183
|
+
const { invitationId = import_keys8.PublicKey.random().toHex(), type = import_services8.Invitation.Type.INTERACTIVE, authMethod = import_services8.Invitation.AuthMethod.SHARED_SECRET, state = import_services8.Invitation.State.INIT, timeout = import_client_protocol3.INVITATION_TIMEOUT, swarmKey = import_keys8.PublicKey.random(), persistent = options?.authMethod !== import_services8.Invitation.AuthMethod.KNOWN_PUBLIC_KEY, created = /* @__PURE__ */ new Date(), guestKeypair = void 0, lifetime = 86400, multiUse = false } = options ?? {};
|
|
3184
|
+
const authCode = options?.authCode ?? (authMethod === import_services8.Invitation.AuthMethod.SHARED_SECRET ? (0, import_credentials9.generatePasscode)(import_client_protocol3.AUTHENTICATION_CODE_LENGTH) : void 0);
|
|
2902
3185
|
return {
|
|
2903
3186
|
invitationId,
|
|
2904
3187
|
type,
|
|
@@ -2907,8 +3190,8 @@ var InvitationsManager = class {
|
|
|
2907
3190
|
swarmKey,
|
|
2908
3191
|
authCode,
|
|
2909
3192
|
timeout,
|
|
2910
|
-
persistent: persistent && type !==
|
|
2911
|
-
guestKeypair: guestKeypair ?? (authMethod ===
|
|
3193
|
+
persistent: persistent && type !== import_services8.Invitation.Type.DELEGATED,
|
|
3194
|
+
guestKeypair: guestKeypair ?? (authMethod === import_services8.Invitation.AuthMethod.KNOWN_PUBLIC_KEY ? createAdmissionKeypair() : void 0),
|
|
2912
3195
|
created,
|
|
2913
3196
|
lifetime,
|
|
2914
3197
|
multiUse,
|
|
@@ -2917,19 +3200,19 @@ var InvitationsManager = class {
|
|
|
2917
3200
|
};
|
|
2918
3201
|
}
|
|
2919
3202
|
_createObservableInvitation(handler, invitation) {
|
|
2920
|
-
const stream = new
|
|
2921
|
-
const ctx = new
|
|
3203
|
+
const stream = new import_async10.PushStream();
|
|
3204
|
+
const ctx = new import_context8.Context({
|
|
2922
3205
|
onError: (err) => {
|
|
2923
3206
|
stream.error(err);
|
|
2924
3207
|
void ctx.dispose();
|
|
2925
3208
|
}
|
|
2926
3209
|
});
|
|
2927
3210
|
ctx.onDispose(() => {
|
|
2928
|
-
(0,
|
|
3211
|
+
(0, import_log9.log)("complete", {
|
|
2929
3212
|
...handler.toJSON()
|
|
2930
3213
|
}, {
|
|
2931
|
-
F:
|
|
2932
|
-
L:
|
|
3214
|
+
F: __dxlog_file11,
|
|
3215
|
+
L: 233,
|
|
2933
3216
|
S: this,
|
|
2934
3217
|
C: (f, a) => f(...a)
|
|
2935
3218
|
});
|
|
@@ -2941,7 +3224,7 @@ var InvitationsManager = class {
|
|
|
2941
3224
|
onCancel: async () => {
|
|
2942
3225
|
stream.next({
|
|
2943
3226
|
...invitation,
|
|
2944
|
-
state:
|
|
3227
|
+
state: import_services8.Invitation.State.CANCELLED
|
|
2945
3228
|
});
|
|
2946
3229
|
await ctx.dispose();
|
|
2947
3230
|
}
|
|
@@ -2952,8 +3235,73 @@ var InvitationsManager = class {
|
|
|
2952
3235
|
observableInvitation
|
|
2953
3236
|
};
|
|
2954
3237
|
}
|
|
3238
|
+
_createObservableAcceptingInvitation(handler, initialState) {
|
|
3239
|
+
const otpEnteredTrigger = new import_async10.Trigger();
|
|
3240
|
+
const stream = new import_async10.PushStream();
|
|
3241
|
+
const ctx = new import_context8.Context({
|
|
3242
|
+
onError: (err) => {
|
|
3243
|
+
if (err instanceof import_async10.TimeoutError) {
|
|
3244
|
+
(0, import_log9.log)("timeout", {
|
|
3245
|
+
...handler.toJSON()
|
|
3246
|
+
}, {
|
|
3247
|
+
F: __dxlog_file11,
|
|
3248
|
+
L: 253,
|
|
3249
|
+
S: this,
|
|
3250
|
+
C: (f, a) => f(...a)
|
|
3251
|
+
});
|
|
3252
|
+
stream.next({
|
|
3253
|
+
...initialState,
|
|
3254
|
+
state: import_services8.Invitation.State.TIMEOUT
|
|
3255
|
+
});
|
|
3256
|
+
} else {
|
|
3257
|
+
import_log9.log.warn("auth failed", err, {
|
|
3258
|
+
F: __dxlog_file11,
|
|
3259
|
+
L: 256,
|
|
3260
|
+
S: this,
|
|
3261
|
+
C: (f, a) => f(...a)
|
|
3262
|
+
});
|
|
3263
|
+
stream.next({
|
|
3264
|
+
...initialState,
|
|
3265
|
+
state: import_services8.Invitation.State.ERROR
|
|
3266
|
+
});
|
|
3267
|
+
}
|
|
3268
|
+
void ctx.dispose();
|
|
3269
|
+
}
|
|
3270
|
+
});
|
|
3271
|
+
ctx.onDispose(() => {
|
|
3272
|
+
(0, import_log9.log)("complete", {
|
|
3273
|
+
...handler.toJSON()
|
|
3274
|
+
}, {
|
|
3275
|
+
F: __dxlog_file11,
|
|
3276
|
+
L: 263,
|
|
3277
|
+
S: this,
|
|
3278
|
+
C: (f, a) => f(...a)
|
|
3279
|
+
});
|
|
3280
|
+
stream.complete();
|
|
3281
|
+
});
|
|
3282
|
+
const invitation = new import_client_protocol3.AuthenticatingInvitation({
|
|
3283
|
+
initialInvitation: initialState,
|
|
3284
|
+
subscriber: stream.observable,
|
|
3285
|
+
onCancel: async () => {
|
|
3286
|
+
stream.next({
|
|
3287
|
+
...initialState,
|
|
3288
|
+
state: import_services8.Invitation.State.CANCELLED
|
|
3289
|
+
});
|
|
3290
|
+
await ctx.dispose();
|
|
3291
|
+
},
|
|
3292
|
+
onAuthenticate: async (code) => {
|
|
3293
|
+
otpEnteredTrigger.wake(code);
|
|
3294
|
+
}
|
|
3295
|
+
});
|
|
3296
|
+
return {
|
|
3297
|
+
ctx,
|
|
3298
|
+
invitation,
|
|
3299
|
+
stream,
|
|
3300
|
+
otpEnteredTrigger
|
|
3301
|
+
};
|
|
3302
|
+
}
|
|
2955
3303
|
async _persistIfRequired(handler, changeStream, invitation) {
|
|
2956
|
-
if (invitation.type ===
|
|
3304
|
+
if (invitation.type === import_services8.Invitation.Type.DELEGATED && invitation.delegationCredentialId == null) {
|
|
2957
3305
|
const delegationCredentialId = await handler.delegate(invitation);
|
|
2958
3306
|
changeStream.next({
|
|
2959
3307
|
...invitation,
|
|
@@ -2968,9 +3316,9 @@ var InvitationsManager = class {
|
|
|
2968
3316
|
try {
|
|
2969
3317
|
await this._metadataStore.removeInvitation(invitation.invitationId);
|
|
2970
3318
|
} catch (err) {
|
|
2971
|
-
|
|
2972
|
-
F:
|
|
2973
|
-
L:
|
|
3319
|
+
import_log9.log.catch(err, void 0, {
|
|
3320
|
+
F: __dxlog_file11,
|
|
3321
|
+
L: 299,
|
|
2974
3322
|
S: this,
|
|
2975
3323
|
C: (f, a) => f(...a)
|
|
2976
3324
|
});
|
|
@@ -3062,7 +3410,7 @@ var AutomergeSpaceState = class {
|
|
|
3062
3410
|
this._onNewRoot = _onNewRoot;
|
|
3063
3411
|
this.rootUrl = void 0;
|
|
3064
3412
|
this.lastEpoch = void 0;
|
|
3065
|
-
this.onNewEpoch = new
|
|
3413
|
+
this.onNewEpoch = new import_async12.Event();
|
|
3066
3414
|
this._isProcessingRootDocs = false;
|
|
3067
3415
|
}
|
|
3068
3416
|
async processCredential(credential) {
|
|
@@ -3091,18 +3439,18 @@ var AutomergeSpaceState = class {
|
|
|
3091
3439
|
await this.onNewEpoch.waitForCondition(() => !!this.lastEpoch);
|
|
3092
3440
|
}
|
|
3093
3441
|
};
|
|
3094
|
-
var
|
|
3442
|
+
var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
|
|
3095
3443
|
var DEFAULT_RETRY_TIMEOUT = 1e3;
|
|
3096
3444
|
var DEFAULT_SUCCESS_DELAY = 1e3;
|
|
3097
3445
|
var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
|
|
3098
3446
|
var WRITER_NOT_SET_ERROR_CODE = "WRITER_NOT_SET";
|
|
3099
3447
|
var NotarizationPlugin = class {
|
|
3100
3448
|
constructor() {
|
|
3101
|
-
this._ctx = new
|
|
3102
|
-
this._extensionOpened = new
|
|
3449
|
+
this._ctx = new import_context10.Context();
|
|
3450
|
+
this._extensionOpened = new import_async13.Event();
|
|
3103
3451
|
this._extensions = /* @__PURE__ */ new Set();
|
|
3104
|
-
this._processedCredentials = new
|
|
3105
|
-
this._processCredentialsTriggers = new
|
|
3452
|
+
this._processedCredentials = new import_util7.ComplexSet(import_keys10.PublicKey.hash);
|
|
3453
|
+
this._processCredentialsTriggers = new import_util7.ComplexMap(import_keys10.PublicKey.hash);
|
|
3106
3454
|
}
|
|
3107
3455
|
get hasWriter() {
|
|
3108
3456
|
return !!this._writer;
|
|
@@ -3116,16 +3464,16 @@ var NotarizationPlugin = class {
|
|
|
3116
3464
|
* Request credentials to be notarized.
|
|
3117
3465
|
*/
|
|
3118
3466
|
async notarize({ ctx: opCtx, credentials, timeout = DEFAULT_NOTARIZE_TIMEOUT, retryTimeout = DEFAULT_RETRY_TIMEOUT, successDelay = DEFAULT_SUCCESS_DELAY }) {
|
|
3119
|
-
(0,
|
|
3467
|
+
(0, import_log11.log)("notarize", {
|
|
3120
3468
|
credentials
|
|
3121
3469
|
}, {
|
|
3122
|
-
F:
|
|
3470
|
+
F: __dxlog_file12,
|
|
3123
3471
|
L: 90,
|
|
3124
3472
|
S: this,
|
|
3125
3473
|
C: (f, a) => f(...a)
|
|
3126
3474
|
});
|
|
3127
|
-
(0,
|
|
3128
|
-
F:
|
|
3475
|
+
(0, import_invariant12.invariant)(credentials.every((credential) => credential.id), "Credentials must have an id", {
|
|
3476
|
+
F: __dxlog_file12,
|
|
3129
3477
|
L: 91,
|
|
3130
3478
|
S: this,
|
|
3131
3479
|
A: [
|
|
@@ -3133,13 +3481,13 @@ var NotarizationPlugin = class {
|
|
|
3133
3481
|
"'Credentials must have an id'"
|
|
3134
3482
|
]
|
|
3135
3483
|
});
|
|
3136
|
-
const errors = new
|
|
3484
|
+
const errors = new import_async13.Trigger();
|
|
3137
3485
|
const ctx = this._ctx.derive({
|
|
3138
3486
|
onError: (err) => {
|
|
3139
|
-
|
|
3487
|
+
import_log11.log.warn("Notarization error", {
|
|
3140
3488
|
err
|
|
3141
3489
|
}, {
|
|
3142
|
-
F:
|
|
3490
|
+
F: __dxlog_file12,
|
|
3143
3491
|
L: 99,
|
|
3144
3492
|
S: this,
|
|
3145
3493
|
C: (f, a) => f(...a)
|
|
@@ -3150,23 +3498,23 @@ var NotarizationPlugin = class {
|
|
|
3150
3498
|
});
|
|
3151
3499
|
opCtx?.onDispose(() => ctx.dispose());
|
|
3152
3500
|
if (timeout !== 0) {
|
|
3153
|
-
(0,
|
|
3154
|
-
|
|
3501
|
+
(0, import_async13.scheduleTask)(ctx, () => {
|
|
3502
|
+
import_log11.log.warn("Notarization timeout", {
|
|
3155
3503
|
timeout,
|
|
3156
3504
|
peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
|
|
3157
3505
|
}, {
|
|
3158
|
-
F:
|
|
3506
|
+
F: __dxlog_file12,
|
|
3159
3507
|
L: 111,
|
|
3160
3508
|
S: this,
|
|
3161
3509
|
C: (f, a) => f(...a)
|
|
3162
3510
|
});
|
|
3163
3511
|
void ctx.dispose();
|
|
3164
|
-
errors.throw(new
|
|
3512
|
+
errors.throw(new import_async13.TimeoutError(timeout, "Notarization timed out"));
|
|
3165
3513
|
}, timeout);
|
|
3166
3514
|
}
|
|
3167
3515
|
const allNotarized = Promise.all(credentials.map((credential) => this._waitUntilProcessed(credential.id)));
|
|
3168
3516
|
const peersTried = /* @__PURE__ */ new Set();
|
|
3169
|
-
const notarizeTask = new
|
|
3517
|
+
const notarizeTask = new import_async13.DeferredTask(ctx, async () => {
|
|
3170
3518
|
try {
|
|
3171
3519
|
if (this._extensions.size === 0) {
|
|
3172
3520
|
return;
|
|
@@ -3175,24 +3523,24 @@ var NotarizationPlugin = class {
|
|
|
3175
3523
|
...this._extensions
|
|
3176
3524
|
].find((peer2) => !peersTried.has(peer2));
|
|
3177
3525
|
if (!peer) {
|
|
3178
|
-
|
|
3526
|
+
import_log11.log.info("Exhausted all peers to notarize with", {
|
|
3179
3527
|
retryIn: retryTimeout
|
|
3180
3528
|
}, {
|
|
3181
|
-
F:
|
|
3529
|
+
F: __dxlog_file12,
|
|
3182
3530
|
L: 136,
|
|
3183
3531
|
S: this,
|
|
3184
3532
|
C: (f, a) => f(...a)
|
|
3185
3533
|
});
|
|
3186
3534
|
peersTried.clear();
|
|
3187
|
-
(0,
|
|
3535
|
+
(0, import_async13.scheduleTask)(ctx, () => notarizeTask.schedule(), retryTimeout);
|
|
3188
3536
|
return;
|
|
3189
3537
|
}
|
|
3190
3538
|
peersTried.add(peer);
|
|
3191
|
-
(0,
|
|
3539
|
+
(0, import_log11.log)("try notarizing", {
|
|
3192
3540
|
peer: peer.localPeerId,
|
|
3193
3541
|
credentialId: credentials.map((credential) => credential.id)
|
|
3194
3542
|
}, {
|
|
3195
|
-
F:
|
|
3543
|
+
F: __dxlog_file12,
|
|
3196
3544
|
L: 143,
|
|
3197
3545
|
S: this,
|
|
3198
3546
|
C: (f, a) => f(...a)
|
|
@@ -3200,17 +3548,17 @@ var NotarizationPlugin = class {
|
|
|
3200
3548
|
await peer.rpc.NotarizationService.notarize({
|
|
3201
3549
|
credentials: credentials.filter((credential) => !this._processedCredentials.has(credential.id))
|
|
3202
3550
|
});
|
|
3203
|
-
(0,
|
|
3204
|
-
F:
|
|
3551
|
+
(0, import_log11.log)("success", void 0, {
|
|
3552
|
+
F: __dxlog_file12,
|
|
3205
3553
|
L: 147,
|
|
3206
3554
|
S: this,
|
|
3207
3555
|
C: (f, a) => f(...a)
|
|
3208
3556
|
});
|
|
3209
|
-
await (0,
|
|
3557
|
+
await (0, import_async13.sleep)(successDelay);
|
|
3210
3558
|
} catch (err) {
|
|
3211
3559
|
if (!ctx.disposed && !err.message.includes(WRITER_NOT_SET_ERROR_CODE)) {
|
|
3212
|
-
|
|
3213
|
-
F:
|
|
3560
|
+
import_log11.log.info("error notarizing (recoverable)", err, {
|
|
3561
|
+
F: __dxlog_file12,
|
|
3214
3562
|
L: 151,
|
|
3215
3563
|
S: this,
|
|
3216
3564
|
C: (f, a) => f(...a)
|
|
@@ -3223,12 +3571,12 @@ var NotarizationPlugin = class {
|
|
|
3223
3571
|
this._extensionOpened.on(ctx, () => notarizeTask.schedule());
|
|
3224
3572
|
try {
|
|
3225
3573
|
await Promise.race([
|
|
3226
|
-
(0,
|
|
3574
|
+
(0, import_context10.rejectOnDispose)(ctx),
|
|
3227
3575
|
allNotarized,
|
|
3228
3576
|
errors.wait()
|
|
3229
3577
|
]);
|
|
3230
|
-
(0,
|
|
3231
|
-
F:
|
|
3578
|
+
(0, import_log11.log)("done", void 0, {
|
|
3579
|
+
F: __dxlog_file12,
|
|
3232
3580
|
L: 162,
|
|
3233
3581
|
S: this,
|
|
3234
3582
|
C: (f, a) => f(...a)
|
|
@@ -3249,8 +3597,8 @@ var NotarizationPlugin = class {
|
|
|
3249
3597
|
this._processCredentialsTriggers.delete(credential.id);
|
|
3250
3598
|
}
|
|
3251
3599
|
setWriter(writer) {
|
|
3252
|
-
(0,
|
|
3253
|
-
F:
|
|
3600
|
+
(0, import_invariant12.invariant)(!this._writer, "Writer already set.", {
|
|
3601
|
+
F: __dxlog_file12,
|
|
3254
3602
|
L: 181,
|
|
3255
3603
|
S: this,
|
|
3256
3604
|
A: [
|
|
@@ -3264,7 +3612,7 @@ var NotarizationPlugin = class {
|
|
|
3264
3612
|
if (this._processedCredentials.has(id)) {
|
|
3265
3613
|
return;
|
|
3266
3614
|
}
|
|
3267
|
-
await (0,
|
|
3615
|
+
await (0, import_util7.entry)(this._processCredentialsTriggers, id).orInsert(new import_async13.Trigger()).value.wait();
|
|
3268
3616
|
}
|
|
3269
3617
|
/**
|
|
3270
3618
|
* Requests from other peers to notarize credentials.
|
|
@@ -3274,8 +3622,8 @@ var NotarizationPlugin = class {
|
|
|
3274
3622
|
throw new Error(WRITER_NOT_SET_ERROR_CODE);
|
|
3275
3623
|
}
|
|
3276
3624
|
for (const credential of request.credentials ?? []) {
|
|
3277
|
-
(0,
|
|
3278
|
-
F:
|
|
3625
|
+
(0, import_invariant12.invariant)(credential.id, "Credential must have an id", {
|
|
3626
|
+
F: __dxlog_file12,
|
|
3279
3627
|
L: 200,
|
|
3280
3628
|
S: this,
|
|
3281
3629
|
A: [
|
|
@@ -3292,10 +3640,10 @@ var NotarizationPlugin = class {
|
|
|
3292
3640
|
createExtension() {
|
|
3293
3641
|
const extension = new NotarizationTeleportExtension({
|
|
3294
3642
|
onOpen: async () => {
|
|
3295
|
-
(0,
|
|
3643
|
+
(0, import_log11.log)("extension opened", {
|
|
3296
3644
|
peer: extension.localPeerId
|
|
3297
3645
|
}, {
|
|
3298
|
-
F:
|
|
3646
|
+
F: __dxlog_file12,
|
|
3299
3647
|
L: 211,
|
|
3300
3648
|
S: this,
|
|
3301
3649
|
C: (f, a) => f(...a)
|
|
@@ -3304,10 +3652,10 @@ var NotarizationPlugin = class {
|
|
|
3304
3652
|
this._extensionOpened.emit();
|
|
3305
3653
|
},
|
|
3306
3654
|
onClose: async () => {
|
|
3307
|
-
(0,
|
|
3655
|
+
(0, import_log11.log)("extension closed", {
|
|
3308
3656
|
peer: extension.localPeerId
|
|
3309
3657
|
}, {
|
|
3310
|
-
F:
|
|
3658
|
+
F: __dxlog_file12,
|
|
3311
3659
|
L: 216,
|
|
3312
3660
|
S: this,
|
|
3313
3661
|
C: (f, a) => f(...a)
|
|
@@ -3319,14 +3667,14 @@ var NotarizationPlugin = class {
|
|
|
3319
3667
|
return extension;
|
|
3320
3668
|
}
|
|
3321
3669
|
};
|
|
3322
|
-
var NotarizationTeleportExtension = class extends
|
|
3670
|
+
var NotarizationTeleportExtension = class extends import_teleport3.RpcExtension {
|
|
3323
3671
|
constructor(_params) {
|
|
3324
3672
|
super({
|
|
3325
3673
|
requested: {
|
|
3326
|
-
NotarizationService:
|
|
3674
|
+
NotarizationService: import_protocols9.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
|
|
3327
3675
|
},
|
|
3328
3676
|
exposed: {
|
|
3329
|
-
NotarizationService:
|
|
3677
|
+
NotarizationService: import_protocols9.schema.getService("dxos.mesh.teleport.notarization.NotarizationService")
|
|
3330
3678
|
}
|
|
3331
3679
|
});
|
|
3332
3680
|
this._params = _params;
|
|
@@ -3359,16 +3707,16 @@ function _ts_decorate4(decorators, target, key, desc) {
|
|
|
3359
3707
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
3360
3708
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3361
3709
|
}
|
|
3362
|
-
var
|
|
3710
|
+
var __dxlog_file13 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
|
|
3363
3711
|
var DataSpace = class {
|
|
3364
3712
|
constructor(params) {
|
|
3365
|
-
this._ctx = new
|
|
3713
|
+
this._ctx = new import_context9.Context();
|
|
3366
3714
|
this._notarizationPlugin = new NotarizationPlugin();
|
|
3367
3715
|
this._cache = void 0;
|
|
3368
3716
|
this._automergeSpaceState = new AutomergeSpaceState((rootUrl) => this._onNewAutomergeRoot(rootUrl));
|
|
3369
|
-
this._state =
|
|
3717
|
+
this._state = import_services9.SpaceState.CLOSED;
|
|
3370
3718
|
this.error = void 0;
|
|
3371
|
-
this.stateUpdate = new
|
|
3719
|
+
this.stateUpdate = new import_async11.Event();
|
|
3372
3720
|
this.metrics = {};
|
|
3373
3721
|
this._inner = params.inner;
|
|
3374
3722
|
this._inner.stateUpdate.on(this._ctx, () => this.stateUpdate.emit());
|
|
@@ -3381,17 +3729,17 @@ var DataSpace = class {
|
|
|
3381
3729
|
this._callbacks = params.callbacks ?? {};
|
|
3382
3730
|
this._echoHost = params.echoHost;
|
|
3383
3731
|
this.authVerifier = new TrustedKeySetAuthVerifier({
|
|
3384
|
-
trustedKeysProvider: () => new
|
|
3732
|
+
trustedKeysProvider: () => new import_util6.ComplexSet(import_keys9.PublicKey.hash, Array.from(this._inner.spaceState.members.values()).filter((member) => !member.removed).map((member) => member.key)),
|
|
3385
3733
|
update: this._inner.stateUpdate,
|
|
3386
3734
|
authTimeout: import_client_protocol4.AUTH_TIMEOUT
|
|
3387
3735
|
});
|
|
3388
3736
|
this._cache = params.cache;
|
|
3389
3737
|
this._state = params.initialState;
|
|
3390
|
-
(0,
|
|
3391
|
-
state:
|
|
3738
|
+
(0, import_log10.log)("new state", {
|
|
3739
|
+
state: import_services9.SpaceState[this._state]
|
|
3392
3740
|
}, {
|
|
3393
|
-
F:
|
|
3394
|
-
L:
|
|
3741
|
+
F: __dxlog_file13,
|
|
3742
|
+
L: 136,
|
|
3395
3743
|
S: this,
|
|
3396
3744
|
C: (f, a) => f(...a)
|
|
3397
3745
|
});
|
|
@@ -3435,13 +3783,13 @@ var DataSpace = class {
|
|
|
3435
3783
|
await this._notarizationPlugin.open();
|
|
3436
3784
|
await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
|
|
3437
3785
|
await this._inner.spaceState.addCredentialProcessor(this._automergeSpaceState);
|
|
3438
|
-
await this._inner.open(new
|
|
3439
|
-
this._state =
|
|
3440
|
-
(0,
|
|
3441
|
-
state:
|
|
3786
|
+
await this._inner.open(new import_context9.Context());
|
|
3787
|
+
this._state = import_services9.SpaceState.CONTROL_ONLY;
|
|
3788
|
+
(0, import_log10.log)("new state", {
|
|
3789
|
+
state: import_services9.SpaceState[this._state]
|
|
3442
3790
|
}, {
|
|
3443
|
-
F:
|
|
3444
|
-
L:
|
|
3791
|
+
F: __dxlog_file13,
|
|
3792
|
+
L: 194,
|
|
3445
3793
|
S: this,
|
|
3446
3794
|
C: (f, a) => f(...a)
|
|
3447
3795
|
});
|
|
@@ -3454,17 +3802,17 @@ var DataSpace = class {
|
|
|
3454
3802
|
}
|
|
3455
3803
|
async _close() {
|
|
3456
3804
|
await this._callbacks.beforeClose?.();
|
|
3457
|
-
this._state =
|
|
3458
|
-
(0,
|
|
3459
|
-
state:
|
|
3805
|
+
this._state = import_services9.SpaceState.CLOSED;
|
|
3806
|
+
(0, import_log10.log)("new state", {
|
|
3807
|
+
state: import_services9.SpaceState[this._state]
|
|
3460
3808
|
}, {
|
|
3461
|
-
F:
|
|
3462
|
-
L:
|
|
3809
|
+
F: __dxlog_file13,
|
|
3810
|
+
L: 208,
|
|
3463
3811
|
S: this,
|
|
3464
3812
|
C: (f, a) => f(...a)
|
|
3465
3813
|
});
|
|
3466
3814
|
await this._ctx.dispose();
|
|
3467
|
-
this._ctx = new
|
|
3815
|
+
this._ctx = new import_context9.Context();
|
|
3468
3816
|
await this.authVerifier.close();
|
|
3469
3817
|
await this._inner.close();
|
|
3470
3818
|
await this._inner.spaceState.removeCredentialProcessor(this._automergeSpaceState);
|
|
@@ -3483,32 +3831,32 @@ var DataSpace = class {
|
|
|
3483
3831
|
* Initialize the data pipeline in a separate task.
|
|
3484
3832
|
*/
|
|
3485
3833
|
initializeDataPipelineAsync() {
|
|
3486
|
-
(0,
|
|
3834
|
+
(0, import_async11.scheduleTask)(this._ctx, async () => {
|
|
3487
3835
|
try {
|
|
3488
3836
|
this.metrics.pipelineInitBegin = /* @__PURE__ */ new Date();
|
|
3489
3837
|
await this.initializeDataPipeline();
|
|
3490
3838
|
} catch (err) {
|
|
3491
|
-
if (err instanceof
|
|
3492
|
-
(0,
|
|
3493
|
-
F:
|
|
3494
|
-
L:
|
|
3839
|
+
if (err instanceof import_protocols8.CancelledError || err instanceof import_context9.ContextDisposedError) {
|
|
3840
|
+
(0, import_log10.log)("data pipeline initialization cancelled", err, {
|
|
3841
|
+
F: __dxlog_file13,
|
|
3842
|
+
L: 241,
|
|
3495
3843
|
S: this,
|
|
3496
3844
|
C: (f, a) => f(...a)
|
|
3497
3845
|
});
|
|
3498
3846
|
return;
|
|
3499
3847
|
}
|
|
3500
|
-
|
|
3501
|
-
F:
|
|
3502
|
-
L:
|
|
3848
|
+
import_log10.log.error("Error initializing data pipeline", err, {
|
|
3849
|
+
F: __dxlog_file13,
|
|
3850
|
+
L: 245,
|
|
3503
3851
|
S: this,
|
|
3504
3852
|
C: (f, a) => f(...a)
|
|
3505
3853
|
});
|
|
3506
|
-
this._state =
|
|
3507
|
-
(0,
|
|
3508
|
-
state:
|
|
3854
|
+
this._state = import_services9.SpaceState.ERROR;
|
|
3855
|
+
(0, import_log10.log)("new state", {
|
|
3856
|
+
state: import_services9.SpaceState[this._state]
|
|
3509
3857
|
}, {
|
|
3510
|
-
F:
|
|
3511
|
-
L:
|
|
3858
|
+
F: __dxlog_file13,
|
|
3859
|
+
L: 247,
|
|
3512
3860
|
S: this,
|
|
3513
3861
|
C: (f, a) => f(...a)
|
|
3514
3862
|
});
|
|
@@ -3520,35 +3868,35 @@ var DataSpace = class {
|
|
|
3520
3868
|
});
|
|
3521
3869
|
}
|
|
3522
3870
|
async initializeDataPipeline() {
|
|
3523
|
-
if (this._state !==
|
|
3524
|
-
throw new
|
|
3871
|
+
if (this._state !== import_services9.SpaceState.CONTROL_ONLY) {
|
|
3872
|
+
throw new import_protocols8.SystemError("Invalid operation");
|
|
3525
3873
|
}
|
|
3526
|
-
this._state =
|
|
3527
|
-
(0,
|
|
3528
|
-
state:
|
|
3874
|
+
this._state = import_services9.SpaceState.INITIALIZING;
|
|
3875
|
+
(0, import_log10.log)("new state", {
|
|
3876
|
+
state: import_services9.SpaceState[this._state]
|
|
3529
3877
|
}, {
|
|
3530
|
-
F:
|
|
3531
|
-
L:
|
|
3878
|
+
F: __dxlog_file13,
|
|
3879
|
+
L: 263,
|
|
3532
3880
|
S: this,
|
|
3533
3881
|
C: (f, a) => f(...a)
|
|
3534
3882
|
});
|
|
3535
3883
|
await this._initializeAndReadControlPipeline();
|
|
3536
|
-
await (0,
|
|
3884
|
+
await (0, import_async11.sleep)(1);
|
|
3537
3885
|
this._automergeSpaceState.startProcessingRootDocs();
|
|
3538
|
-
await (0,
|
|
3539
|
-
(0,
|
|
3540
|
-
F:
|
|
3541
|
-
L:
|
|
3886
|
+
await (0, import_context9.cancelWithContext)(this._ctx, this.automergeSpaceState.ensureEpochInitialized());
|
|
3887
|
+
(0, import_log10.log)("data pipeline ready", void 0, {
|
|
3888
|
+
F: __dxlog_file13,
|
|
3889
|
+
L: 275,
|
|
3542
3890
|
S: this,
|
|
3543
3891
|
C: (f, a) => f(...a)
|
|
3544
3892
|
});
|
|
3545
3893
|
await this._callbacks.beforeReady?.();
|
|
3546
|
-
this._state =
|
|
3547
|
-
(0,
|
|
3548
|
-
state:
|
|
3894
|
+
this._state = import_services9.SpaceState.READY;
|
|
3895
|
+
(0, import_log10.log)("new state", {
|
|
3896
|
+
state: import_services9.SpaceState[this._state]
|
|
3549
3897
|
}, {
|
|
3550
|
-
F:
|
|
3551
|
-
L:
|
|
3898
|
+
F: __dxlog_file13,
|
|
3899
|
+
L: 279,
|
|
3552
3900
|
S: this,
|
|
3553
3901
|
C: (f, a) => f(...a)
|
|
3554
3902
|
});
|
|
@@ -3562,9 +3910,9 @@ var DataSpace = class {
|
|
|
3562
3910
|
});
|
|
3563
3911
|
this.metrics.controlPipelineReady = /* @__PURE__ */ new Date();
|
|
3564
3912
|
await this._createWritableFeeds();
|
|
3565
|
-
(0,
|
|
3566
|
-
F:
|
|
3567
|
-
L:
|
|
3913
|
+
(0, import_log10.log)("writable feeds created", void 0, {
|
|
3914
|
+
F: __dxlog_file13,
|
|
3915
|
+
L: 295,
|
|
3568
3916
|
S: this,
|
|
3569
3917
|
C: (f, a) => f(...a)
|
|
3570
3918
|
});
|
|
@@ -3622,12 +3970,12 @@ var DataSpace = class {
|
|
|
3622
3970
|
}
|
|
3623
3971
|
}
|
|
3624
3972
|
_onNewAutomergeRoot(rootUrl) {
|
|
3625
|
-
(0,
|
|
3973
|
+
(0, import_log10.log)("loading automerge root doc for space", {
|
|
3626
3974
|
space: this.key,
|
|
3627
3975
|
rootUrl
|
|
3628
3976
|
}, {
|
|
3629
|
-
F:
|
|
3630
|
-
L:
|
|
3977
|
+
F: __dxlog_file13,
|
|
3978
|
+
L: 361,
|
|
3631
3979
|
S: this,
|
|
3632
3980
|
C: (f, a) => f(...a)
|
|
3633
3981
|
});
|
|
@@ -3636,12 +3984,12 @@ var DataSpace = class {
|
|
|
3636
3984
|
queueMicrotask(async () => {
|
|
3637
3985
|
try {
|
|
3638
3986
|
await (0, import_debug3.warnAfterTimeout)(5e3, "Automerge root doc load timeout (DataSpace)", async () => {
|
|
3639
|
-
await (0,
|
|
3987
|
+
await (0, import_context9.cancelWithContext)(this._ctx, handle.whenReady());
|
|
3640
3988
|
});
|
|
3641
3989
|
if (this._ctx.disposed) {
|
|
3642
3990
|
return;
|
|
3643
3991
|
}
|
|
3644
|
-
const doc = handle.docSync() ?? (0,
|
|
3992
|
+
const doc = handle.docSync() ?? (0, import_invariant11.failedInvariant)();
|
|
3645
3993
|
if (!doc.access?.spaceKey) {
|
|
3646
3994
|
handle.change((doc2) => {
|
|
3647
3995
|
doc2.access = {
|
|
@@ -3650,16 +3998,16 @@ var DataSpace = class {
|
|
|
3650
3998
|
});
|
|
3651
3999
|
}
|
|
3652
4000
|
} catch (err) {
|
|
3653
|
-
if (err instanceof
|
|
4001
|
+
if (err instanceof import_context9.ContextDisposedError) {
|
|
3654
4002
|
return;
|
|
3655
4003
|
}
|
|
3656
|
-
|
|
4004
|
+
import_log10.log.warn("error loading automerge root doc", {
|
|
3657
4005
|
space: this.key,
|
|
3658
4006
|
rootUrl,
|
|
3659
4007
|
err
|
|
3660
4008
|
}, {
|
|
3661
|
-
F:
|
|
3662
|
-
L:
|
|
4009
|
+
F: __dxlog_file13,
|
|
4010
|
+
L: 384,
|
|
3663
4011
|
S: this,
|
|
3664
4012
|
C: (f, a) => f(...a)
|
|
3665
4013
|
});
|
|
@@ -3685,7 +4033,7 @@ var DataSpace = class {
|
|
|
3685
4033
|
let epoch;
|
|
3686
4034
|
switch (options?.migration) {
|
|
3687
4035
|
case void 0:
|
|
3688
|
-
case
|
|
4036
|
+
case import_services9.CreateEpochRequest.Migration.NONE:
|
|
3689
4037
|
{
|
|
3690
4038
|
epoch = {
|
|
3691
4039
|
previousId: this._automergeSpaceState.lastEpoch?.id,
|
|
@@ -3695,7 +4043,7 @@ var DataSpace = class {
|
|
|
3695
4043
|
};
|
|
3696
4044
|
}
|
|
3697
4045
|
break;
|
|
3698
|
-
case
|
|
4046
|
+
case import_services9.CreateEpochRequest.Migration.INIT_AUTOMERGE:
|
|
3699
4047
|
{
|
|
3700
4048
|
const document = this._echoHost.automergeRepo.create();
|
|
3701
4049
|
epoch = {
|
|
@@ -3706,15 +4054,15 @@ var DataSpace = class {
|
|
|
3706
4054
|
};
|
|
3707
4055
|
}
|
|
3708
4056
|
break;
|
|
3709
|
-
case
|
|
4057
|
+
case import_services9.CreateEpochRequest.Migration.PRUNE_AUTOMERGE_ROOT_HISTORY:
|
|
3710
4058
|
{
|
|
3711
4059
|
const currentRootUrl = this._automergeSpaceState.rootUrl;
|
|
3712
4060
|
const rootHandle = this._echoHost.automergeRepo.find(currentRootUrl);
|
|
3713
|
-
await (0,
|
|
4061
|
+
await (0, import_context9.cancelWithContext)(this._ctx, (0, import_async11.asyncTimeout)(rootHandle.whenReady(), 1e4));
|
|
3714
4062
|
const newRoot = this._echoHost.automergeRepo.create(rootHandle.docSync());
|
|
3715
|
-
(0,
|
|
3716
|
-
F:
|
|
3717
|
-
L:
|
|
4063
|
+
(0, import_invariant11.invariant)(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
|
|
4064
|
+
F: __dxlog_file13,
|
|
4065
|
+
L: 434,
|
|
3718
4066
|
S: this,
|
|
3719
4067
|
A: [
|
|
3720
4068
|
"typeof newRoot.url === 'string' && newRoot.url.length > 0",
|
|
@@ -3729,23 +4077,23 @@ var DataSpace = class {
|
|
|
3729
4077
|
};
|
|
3730
4078
|
}
|
|
3731
4079
|
break;
|
|
3732
|
-
case
|
|
4080
|
+
case import_services9.CreateEpochRequest.Migration.FRAGMENT_AUTOMERGE_ROOT:
|
|
3733
4081
|
{
|
|
3734
|
-
|
|
3735
|
-
F:
|
|
3736
|
-
L:
|
|
4082
|
+
import_log10.log.info("Fragmenting", void 0, {
|
|
4083
|
+
F: __dxlog_file13,
|
|
4084
|
+
L: 446,
|
|
3737
4085
|
S: this,
|
|
3738
4086
|
C: (f, a) => f(...a)
|
|
3739
4087
|
});
|
|
3740
4088
|
const currentRootUrl = this._automergeSpaceState.rootUrl;
|
|
3741
4089
|
const rootHandle = this._echoHost.automergeRepo.find(currentRootUrl);
|
|
3742
|
-
await (0,
|
|
4090
|
+
await (0, import_context9.cancelWithContext)(this._ctx, (0, import_async11.asyncTimeout)(rootHandle.whenReady(), 1e4));
|
|
3743
4091
|
const objects = Object.entries(rootHandle.docSync().objects);
|
|
3744
4092
|
const properties = objects.find(([_, value]) => value.system.type?.itemId === import_echo_schema.TYPE_PROPERTIES);
|
|
3745
4093
|
const otherObjects = objects.filter(([key]) => key !== properties?.[0]);
|
|
3746
|
-
(0,
|
|
3747
|
-
F:
|
|
3748
|
-
L:
|
|
4094
|
+
(0, import_invariant11.invariant)(properties, "Properties not found", {
|
|
4095
|
+
F: __dxlog_file13,
|
|
4096
|
+
L: 456,
|
|
3749
4097
|
S: this,
|
|
3750
4098
|
A: [
|
|
3751
4099
|
"properties",
|
|
@@ -3759,9 +4107,9 @@ var DataSpace = class {
|
|
|
3759
4107
|
])
|
|
3760
4108
|
};
|
|
3761
4109
|
const newRoot = this._echoHost.automergeRepo.create(newSpaceDoc);
|
|
3762
|
-
(0,
|
|
3763
|
-
F:
|
|
3764
|
-
L:
|
|
4110
|
+
(0, import_invariant11.invariant)(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
|
|
4111
|
+
F: __dxlog_file13,
|
|
4112
|
+
L: 461,
|
|
3765
4113
|
S: this,
|
|
3766
4114
|
A: [
|
|
3767
4115
|
"typeof newRoot.url === 'string' && newRoot.url.length > 0",
|
|
@@ -3775,7 +4123,7 @@ var DataSpace = class {
|
|
|
3775
4123
|
otherObjects.forEach(([key, value]) => {
|
|
3776
4124
|
const handle = docLoader.createDocumentForObject(key);
|
|
3777
4125
|
handle.change((doc) => {
|
|
3778
|
-
(0,
|
|
4126
|
+
(0, import_util6.assignDeep)(doc, [
|
|
3779
4127
|
"objects",
|
|
3780
4128
|
key
|
|
3781
4129
|
], value);
|
|
@@ -3812,25 +4160,25 @@ var DataSpace = class {
|
|
|
3812
4160
|
]));
|
|
3813
4161
|
}
|
|
3814
4162
|
async activate() {
|
|
3815
|
-
if (this._state !==
|
|
4163
|
+
if (this._state !== import_services9.SpaceState.INACTIVE) {
|
|
3816
4164
|
return;
|
|
3817
4165
|
}
|
|
3818
|
-
await this._metadataStore.setSpaceState(this.key,
|
|
4166
|
+
await this._metadataStore.setSpaceState(this.key, import_services9.SpaceState.ACTIVE);
|
|
3819
4167
|
await this._open();
|
|
3820
4168
|
this.initializeDataPipelineAsync();
|
|
3821
4169
|
}
|
|
3822
4170
|
async deactivate() {
|
|
3823
|
-
if (this._state ===
|
|
4171
|
+
if (this._state === import_services9.SpaceState.INACTIVE) {
|
|
3824
4172
|
return;
|
|
3825
4173
|
}
|
|
3826
|
-
await this._metadataStore.setSpaceState(this.key,
|
|
4174
|
+
await this._metadataStore.setSpaceState(this.key, import_services9.SpaceState.INACTIVE);
|
|
3827
4175
|
await this._close();
|
|
3828
|
-
this._state =
|
|
3829
|
-
(0,
|
|
3830
|
-
state:
|
|
4176
|
+
this._state = import_services9.SpaceState.INACTIVE;
|
|
4177
|
+
(0, import_log10.log)("new state", {
|
|
4178
|
+
state: import_services9.SpaceState[this._state]
|
|
3831
4179
|
}, {
|
|
3832
|
-
F:
|
|
3833
|
-
L:
|
|
4180
|
+
F: __dxlog_file13,
|
|
4181
|
+
L: 527,
|
|
3834
4182
|
S: this,
|
|
3835
4183
|
C: (f, a) => f(...a)
|
|
3836
4184
|
});
|
|
@@ -3845,7 +4193,7 @@ _ts_decorate4([
|
|
|
3845
4193
|
], DataSpace.prototype, "key", null);
|
|
3846
4194
|
_ts_decorate4([
|
|
3847
4195
|
import_tracing4.trace.info({
|
|
3848
|
-
enum:
|
|
4196
|
+
enum: import_services9.SpaceState
|
|
3849
4197
|
})
|
|
3850
4198
|
], DataSpace.prototype, "state", null);
|
|
3851
4199
|
_ts_decorate4([
|
|
@@ -3854,10 +4202,10 @@ _ts_decorate4([
|
|
|
3854
4202
|
})
|
|
3855
4203
|
], DataSpace.prototype, "_automergeInfo", null);
|
|
3856
4204
|
_ts_decorate4([
|
|
3857
|
-
|
|
4205
|
+
import_async11.synchronized
|
|
3858
4206
|
], DataSpace.prototype, "open", null);
|
|
3859
4207
|
_ts_decorate4([
|
|
3860
|
-
|
|
4208
|
+
import_async11.synchronized
|
|
3861
4209
|
], DataSpace.prototype, "close", null);
|
|
3862
4210
|
_ts_decorate4([
|
|
3863
4211
|
import_tracing4.trace.span({
|
|
@@ -3873,13 +4221,13 @@ _ts_decorate4([
|
|
|
3873
4221
|
(0, import_debug3.timed)(1e4)
|
|
3874
4222
|
], DataSpace.prototype, "_createWritableFeeds", null);
|
|
3875
4223
|
_ts_decorate4([
|
|
3876
|
-
|
|
4224
|
+
import_async11.synchronized
|
|
3877
4225
|
], DataSpace.prototype, "activate", null);
|
|
3878
4226
|
_ts_decorate4([
|
|
3879
|
-
|
|
4227
|
+
import_async11.synchronized
|
|
3880
4228
|
], DataSpace.prototype, "deactivate", null);
|
|
3881
4229
|
DataSpace = _ts_decorate4([
|
|
3882
|
-
(0,
|
|
4230
|
+
(0, import_async11.trackLeaks)("open", "close"),
|
|
3883
4231
|
import_tracing4.trace.resource()
|
|
3884
4232
|
], DataSpace);
|
|
3885
4233
|
var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
|
|
@@ -3956,7 +4304,7 @@ function _ts_decorate5(decorators, target, key, desc) {
|
|
|
3956
4304
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
3957
4305
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
3958
4306
|
}
|
|
3959
|
-
var
|
|
4307
|
+
var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
|
|
3960
4308
|
var PRESENCE_ANNOUNCE_INTERVAL = 1e4;
|
|
3961
4309
|
var PRESENCE_OFFLINE_TIMEOUT = 2e4;
|
|
3962
4310
|
var DataSpaceManager = class {
|
|
@@ -3968,11 +4316,11 @@ var DataSpaceManager = class {
|
|
|
3968
4316
|
this._feedStore = _feedStore;
|
|
3969
4317
|
this._echoHost = _echoHost;
|
|
3970
4318
|
this._invitationsManager = _invitationsManager;
|
|
3971
|
-
this._ctx = new
|
|
3972
|
-
this.updated = new
|
|
3973
|
-
this._spaces = new
|
|
4319
|
+
this._ctx = new import_context11.Context();
|
|
4320
|
+
this.updated = new import_async14.Event();
|
|
4321
|
+
this._spaces = new import_util8.ComplexMap(import_keys11.PublicKey.hash);
|
|
3974
4322
|
this._isOpen = false;
|
|
3975
|
-
this._instanceId =
|
|
4323
|
+
this._instanceId = import_keys11.PublicKey.random().toHex();
|
|
3976
4324
|
const { spaceMemberPresenceAnnounceInterval = PRESENCE_ANNOUNCE_INTERVAL, spaceMemberPresenceOfflineTimeout = PRESENCE_OFFLINE_TIMEOUT } = params ?? {};
|
|
3977
4325
|
this._spaceMemberPresenceAnnounceInterval = spaceMemberPresenceAnnounceInterval;
|
|
3978
4326
|
this._spaceMemberPresenceOfflineTimeout = spaceMemberPresenceOfflineTimeout;
|
|
@@ -3982,45 +4330,45 @@ var DataSpaceManager = class {
|
|
|
3982
4330
|
return this._spaces;
|
|
3983
4331
|
}
|
|
3984
4332
|
async open() {
|
|
3985
|
-
(0,
|
|
3986
|
-
F:
|
|
4333
|
+
(0, import_log12.log)("open", void 0, {
|
|
4334
|
+
F: __dxlog_file14,
|
|
3987
4335
|
L: 102,
|
|
3988
4336
|
S: this,
|
|
3989
4337
|
C: (f, a) => f(...a)
|
|
3990
4338
|
});
|
|
3991
|
-
|
|
4339
|
+
import_log12.log.trace("dxos.echo.data-space-manager.open", import_protocols10.trace.begin({
|
|
3992
4340
|
id: this._instanceId
|
|
3993
4341
|
}), {
|
|
3994
|
-
F:
|
|
4342
|
+
F: __dxlog_file14,
|
|
3995
4343
|
L: 103,
|
|
3996
4344
|
S: this,
|
|
3997
4345
|
C: (f, a) => f(...a)
|
|
3998
4346
|
});
|
|
3999
|
-
(0,
|
|
4347
|
+
(0, import_log12.log)("metadata loaded", {
|
|
4000
4348
|
spaces: this._metadataStore.spaces.length
|
|
4001
4349
|
}, {
|
|
4002
|
-
F:
|
|
4350
|
+
F: __dxlog_file14,
|
|
4003
4351
|
L: 104,
|
|
4004
4352
|
S: this,
|
|
4005
4353
|
C: (f, a) => f(...a)
|
|
4006
4354
|
});
|
|
4007
|
-
await (0,
|
|
4355
|
+
await (0, import_util8.forEachAsync)(this._metadataStore.spaces, async (spaceMetadata) => {
|
|
4008
4356
|
try {
|
|
4009
|
-
(0,
|
|
4357
|
+
(0, import_log12.log)("load space", {
|
|
4010
4358
|
spaceMetadata
|
|
4011
4359
|
}, {
|
|
4012
|
-
F:
|
|
4360
|
+
F: __dxlog_file14,
|
|
4013
4361
|
L: 108,
|
|
4014
4362
|
S: this,
|
|
4015
4363
|
C: (f, a) => f(...a)
|
|
4016
4364
|
});
|
|
4017
4365
|
await this._constructSpace(spaceMetadata);
|
|
4018
4366
|
} catch (err) {
|
|
4019
|
-
|
|
4367
|
+
import_log12.log.error("Error loading space", {
|
|
4020
4368
|
spaceMetadata,
|
|
4021
4369
|
err
|
|
4022
4370
|
}, {
|
|
4023
|
-
F:
|
|
4371
|
+
F: __dxlog_file14,
|
|
4024
4372
|
L: 111,
|
|
4025
4373
|
S: this,
|
|
4026
4374
|
C: (f, a) => f(...a)
|
|
@@ -4030,22 +4378,22 @@ var DataSpaceManager = class {
|
|
|
4030
4378
|
this._isOpen = true;
|
|
4031
4379
|
this.updated.emit();
|
|
4032
4380
|
for (const space of this._spaces.values()) {
|
|
4033
|
-
if (space.state !==
|
|
4381
|
+
if (space.state !== import_services10.SpaceState.INACTIVE) {
|
|
4034
4382
|
space.initializeDataPipelineAsync();
|
|
4035
4383
|
}
|
|
4036
4384
|
}
|
|
4037
|
-
|
|
4385
|
+
import_log12.log.trace("dxos.echo.data-space-manager.open", import_protocols10.trace.end({
|
|
4038
4386
|
id: this._instanceId
|
|
4039
4387
|
}), {
|
|
4040
|
-
F:
|
|
4388
|
+
F: __dxlog_file14,
|
|
4041
4389
|
L: 124,
|
|
4042
4390
|
S: this,
|
|
4043
4391
|
C: (f, a) => f(...a)
|
|
4044
4392
|
});
|
|
4045
4393
|
}
|
|
4046
4394
|
async close() {
|
|
4047
|
-
(0,
|
|
4048
|
-
F:
|
|
4395
|
+
(0, import_log12.log)("close", void 0, {
|
|
4396
|
+
F: __dxlog_file14,
|
|
4049
4397
|
L: 129,
|
|
4050
4398
|
S: this,
|
|
4051
4399
|
C: (f, a) => f(...a)
|
|
@@ -4060,8 +4408,8 @@ var DataSpaceManager = class {
|
|
|
4060
4408
|
* Creates a new space writing the genesis credentials to the control feed.
|
|
4061
4409
|
*/
|
|
4062
4410
|
async createSpace() {
|
|
4063
|
-
(0,
|
|
4064
|
-
F:
|
|
4411
|
+
(0, import_invariant13.invariant)(this._isOpen, "Not open.", {
|
|
4412
|
+
F: __dxlog_file14,
|
|
4065
4413
|
L: 142,
|
|
4066
4414
|
S: this,
|
|
4067
4415
|
A: [
|
|
@@ -4077,12 +4425,12 @@ var DataSpaceManager = class {
|
|
|
4077
4425
|
genesisFeedKey: controlFeedKey,
|
|
4078
4426
|
controlFeedKey,
|
|
4079
4427
|
dataFeedKey,
|
|
4080
|
-
state:
|
|
4428
|
+
state: import_services10.SpaceState.ACTIVE
|
|
4081
4429
|
};
|
|
4082
|
-
(0,
|
|
4430
|
+
(0, import_log12.log)("creating space...", {
|
|
4083
4431
|
spaceKey
|
|
4084
4432
|
}, {
|
|
4085
|
-
F:
|
|
4433
|
+
F: __dxlog_file14,
|
|
4086
4434
|
L: 154,
|
|
4087
4435
|
S: this,
|
|
4088
4436
|
C: (f, a) => f(...a)
|
|
@@ -4092,8 +4440,8 @@ var DataSpaceManager = class {
|
|
|
4092
4440
|
const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner, automergeRootUrl);
|
|
4093
4441
|
await this._metadataStore.addSpace(metadata);
|
|
4094
4442
|
const memberCredential = credentials[1];
|
|
4095
|
-
(0,
|
|
4096
|
-
F:
|
|
4443
|
+
(0, import_invariant13.invariant)((0, import_credentials12.getCredentialAssertion)(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
|
|
4444
|
+
F: __dxlog_file14,
|
|
4097
4445
|
L: 163,
|
|
4098
4446
|
S: this,
|
|
4099
4447
|
A: [
|
|
@@ -4108,16 +4456,16 @@ var DataSpaceManager = class {
|
|
|
4108
4456
|
}
|
|
4109
4457
|
// TODO(burdon): Rename join space.
|
|
4110
4458
|
async acceptSpace(opts) {
|
|
4111
|
-
(0,
|
|
4459
|
+
(0, import_log12.log)("accept space", {
|
|
4112
4460
|
opts
|
|
4113
4461
|
}, {
|
|
4114
|
-
F:
|
|
4462
|
+
F: __dxlog_file14,
|
|
4115
4463
|
L: 175,
|
|
4116
4464
|
S: this,
|
|
4117
4465
|
C: (f, a) => f(...a)
|
|
4118
4466
|
});
|
|
4119
|
-
(0,
|
|
4120
|
-
F:
|
|
4467
|
+
(0, import_invariant13.invariant)(this._isOpen, "Not open.", {
|
|
4468
|
+
F: __dxlog_file14,
|
|
4121
4469
|
L: 176,
|
|
4122
4470
|
S: this,
|
|
4123
4471
|
A: [
|
|
@@ -4125,8 +4473,8 @@ var DataSpaceManager = class {
|
|
|
4125
4473
|
"'Not open.'"
|
|
4126
4474
|
]
|
|
4127
4475
|
});
|
|
4128
|
-
(0,
|
|
4129
|
-
F:
|
|
4476
|
+
(0, import_invariant13.invariant)(!this._spaces.has(opts.spaceKey), "Space already exists.", {
|
|
4477
|
+
F: __dxlog_file14,
|
|
4130
4478
|
L: 177,
|
|
4131
4479
|
S: this,
|
|
4132
4480
|
A: [
|
|
@@ -4152,16 +4500,16 @@ var DataSpaceManager = class {
|
|
|
4152
4500
|
* TODO(dmaretskyi): Consider removing.
|
|
4153
4501
|
*/
|
|
4154
4502
|
async waitUntilSpaceReady(spaceKey) {
|
|
4155
|
-
await (0,
|
|
4503
|
+
await (0, import_context11.cancelWithContext)(this._ctx, this.updated.waitForCondition(() => {
|
|
4156
4504
|
const space = this._spaces.get(spaceKey);
|
|
4157
|
-
return !!space && space.state ===
|
|
4505
|
+
return !!space && space.state === import_services10.SpaceState.READY;
|
|
4158
4506
|
}));
|
|
4159
4507
|
}
|
|
4160
4508
|
async _constructSpace(metadata) {
|
|
4161
|
-
(0,
|
|
4509
|
+
(0, import_log12.log)("construct space", {
|
|
4162
4510
|
metadata
|
|
4163
4511
|
}, {
|
|
4164
|
-
F:
|
|
4512
|
+
F: __dxlog_file14,
|
|
4165
4513
|
L: 210,
|
|
4166
4514
|
S: this,
|
|
4167
4515
|
C: (f, a) => f(...a)
|
|
@@ -4187,7 +4535,7 @@ var DataSpaceManager = class {
|
|
|
4187
4535
|
swarmIdentity: {
|
|
4188
4536
|
peerKey: this._signingContext.deviceKey,
|
|
4189
4537
|
credentialProvider: createAuthProvider(this._signingContext.credentialSigner),
|
|
4190
|
-
credentialAuthenticator: (0,
|
|
4538
|
+
credentialAuthenticator: (0, import_util8.deferFunction)(() => dataSpace.authVerifier.verifier)
|
|
4191
4539
|
},
|
|
4192
4540
|
onAuthorizedConnection: (session) => {
|
|
4193
4541
|
session.addExtension("dxos.mesh.teleport.gossip", gossip.createExtension({
|
|
@@ -4198,8 +4546,8 @@ var DataSpaceManager = class {
|
|
|
4198
4546
|
session.addExtension("dxos.mesh.teleport.automerge", this._echoHost.createReplicationExtension());
|
|
4199
4547
|
},
|
|
4200
4548
|
onAuthFailure: () => {
|
|
4201
|
-
|
|
4202
|
-
F:
|
|
4549
|
+
import_log12.log.warn("auth failure", void 0, {
|
|
4550
|
+
F: __dxlog_file14,
|
|
4203
4551
|
L: 247,
|
|
4204
4552
|
S: this,
|
|
4205
4553
|
C: (f, a) => f(...a)
|
|
@@ -4214,7 +4562,7 @@ var DataSpaceManager = class {
|
|
|
4214
4562
|
dataFeed && await space.setDataFeed(dataFeed);
|
|
4215
4563
|
const dataSpace = new DataSpace({
|
|
4216
4564
|
inner: space,
|
|
4217
|
-
initialState: metadata.state ===
|
|
4565
|
+
initialState: metadata.state === import_services10.SpaceState.INACTIVE ? import_services10.SpaceState.INACTIVE : import_services10.SpaceState.CLOSED,
|
|
4218
4566
|
metadataStore: this._metadataStore,
|
|
4219
4567
|
gossip,
|
|
4220
4568
|
presence,
|
|
@@ -4224,21 +4572,21 @@ var DataSpaceManager = class {
|
|
|
4224
4572
|
signingContext: this._signingContext,
|
|
4225
4573
|
callbacks: {
|
|
4226
4574
|
beforeReady: async () => {
|
|
4227
|
-
(0,
|
|
4575
|
+
(0, import_log12.log)("before space ready", {
|
|
4228
4576
|
space: space.key
|
|
4229
4577
|
}, {
|
|
4230
|
-
F:
|
|
4578
|
+
F: __dxlog_file14,
|
|
4231
4579
|
L: 269,
|
|
4232
4580
|
S: this,
|
|
4233
4581
|
C: (f, a) => f(...a)
|
|
4234
4582
|
});
|
|
4235
4583
|
},
|
|
4236
4584
|
afterReady: async () => {
|
|
4237
|
-
(0,
|
|
4585
|
+
(0, import_log12.log)("after space ready", {
|
|
4238
4586
|
space: space.key,
|
|
4239
4587
|
open: this._isOpen
|
|
4240
4588
|
}, {
|
|
4241
|
-
F:
|
|
4589
|
+
F: __dxlog_file14,
|
|
4242
4590
|
L: 272,
|
|
4243
4591
|
S: this,
|
|
4244
4592
|
C: (f, a) => f(...a)
|
|
@@ -4251,10 +4599,10 @@ var DataSpaceManager = class {
|
|
|
4251
4599
|
}
|
|
4252
4600
|
},
|
|
4253
4601
|
beforeClose: async () => {
|
|
4254
|
-
(0,
|
|
4602
|
+
(0, import_log12.log)("before space close", {
|
|
4255
4603
|
space: space.key
|
|
4256
4604
|
}, {
|
|
4257
|
-
F:
|
|
4605
|
+
F: __dxlog_file14,
|
|
4258
4606
|
L: 279,
|
|
4259
4607
|
S: this,
|
|
4260
4608
|
C: (f, a) => f(...a)
|
|
@@ -4263,7 +4611,7 @@ var DataSpaceManager = class {
|
|
|
4263
4611
|
},
|
|
4264
4612
|
cache: metadata.cache
|
|
4265
4613
|
});
|
|
4266
|
-
if (metadata.state !==
|
|
4614
|
+
if (metadata.state !== import_services10.SpaceState.INACTIVE) {
|
|
4267
4615
|
await dataSpace.open();
|
|
4268
4616
|
}
|
|
4269
4617
|
if (metadata.controlTimeframe) {
|
|
@@ -4273,7 +4621,7 @@ var DataSpaceManager = class {
|
|
|
4273
4621
|
return dataSpace;
|
|
4274
4622
|
}
|
|
4275
4623
|
async _handleInvitationStatusChange(dataSpace, delegatedInvitation, isActive) {
|
|
4276
|
-
if (dataSpace?.state !==
|
|
4624
|
+
if (dataSpace?.state !== import_services10.SpaceState.READY) {
|
|
4277
4625
|
return;
|
|
4278
4626
|
}
|
|
4279
4627
|
if (isActive) {
|
|
@@ -4290,8 +4638,8 @@ var DataSpaceManager = class {
|
|
|
4290
4638
|
async _createDelegatedInvitations(space, invitations) {
|
|
4291
4639
|
const tasks = invitations.map(([credentialId, invitation]) => {
|
|
4292
4640
|
return this._invitationsManager.createInvitation({
|
|
4293
|
-
type:
|
|
4294
|
-
kind:
|
|
4641
|
+
type: import_services10.Invitation.Type.DELEGATED,
|
|
4642
|
+
kind: import_services10.Invitation.Kind.SPACE,
|
|
4295
4643
|
spaceKey: space.key,
|
|
4296
4644
|
authMethod: invitation.authMethod,
|
|
4297
4645
|
invitationId: invitation.invitationId,
|
|
@@ -4309,21 +4657,21 @@ var DataSpaceManager = class {
|
|
|
4309
4657
|
}
|
|
4310
4658
|
};
|
|
4311
4659
|
_ts_decorate5([
|
|
4312
|
-
|
|
4660
|
+
import_async14.synchronized
|
|
4313
4661
|
], DataSpaceManager.prototype, "open", null);
|
|
4314
4662
|
_ts_decorate5([
|
|
4315
|
-
|
|
4663
|
+
import_async14.synchronized
|
|
4316
4664
|
], DataSpaceManager.prototype, "close", null);
|
|
4317
4665
|
_ts_decorate5([
|
|
4318
|
-
|
|
4666
|
+
import_async14.synchronized
|
|
4319
4667
|
], DataSpaceManager.prototype, "createSpace", null);
|
|
4320
4668
|
_ts_decorate5([
|
|
4321
|
-
|
|
4669
|
+
import_async14.synchronized
|
|
4322
4670
|
], DataSpaceManager.prototype, "acceptSpace", null);
|
|
4323
4671
|
DataSpaceManager = _ts_decorate5([
|
|
4324
|
-
(0,
|
|
4672
|
+
(0, import_async14.trackLeaks)("open", "close")
|
|
4325
4673
|
], DataSpaceManager);
|
|
4326
|
-
var
|
|
4674
|
+
var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
|
|
4327
4675
|
var SpacesServiceImpl = class {
|
|
4328
4676
|
constructor(_identityManager, _spaceManager, _getDataSpaceManager) {
|
|
4329
4677
|
this._identityManager = _identityManager;
|
|
@@ -4340,29 +4688,29 @@ var SpacesServiceImpl = class {
|
|
|
4340
4688
|
}
|
|
4341
4689
|
async updateSpace({ spaceKey, state }) {
|
|
4342
4690
|
const dataSpaceManager = await this._getDataSpaceManager();
|
|
4343
|
-
const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new
|
|
4691
|
+
const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
|
|
4344
4692
|
if (state) {
|
|
4345
4693
|
switch (state) {
|
|
4346
|
-
case
|
|
4694
|
+
case import_services11.SpaceState.ACTIVE:
|
|
4347
4695
|
await space.activate();
|
|
4348
4696
|
break;
|
|
4349
|
-
case
|
|
4697
|
+
case import_services11.SpaceState.INACTIVE:
|
|
4350
4698
|
await space.deactivate();
|
|
4351
4699
|
break;
|
|
4352
4700
|
default:
|
|
4353
|
-
throw new
|
|
4701
|
+
throw new import_protocols11.ApiError("Invalid space state");
|
|
4354
4702
|
}
|
|
4355
4703
|
}
|
|
4356
4704
|
}
|
|
4357
4705
|
querySpaces() {
|
|
4358
4706
|
return new import_codec_protobuf10.Stream(({ next, ctx }) => {
|
|
4359
|
-
const scheduler = new
|
|
4707
|
+
const scheduler = new import_async15.UpdateScheduler(ctx, async () => {
|
|
4360
4708
|
const dataSpaceManager = await this._getDataSpaceManager();
|
|
4361
4709
|
const spaces = Array.from(dataSpaceManager.spaces.values()).map((space) => this._serializeSpace(space));
|
|
4362
|
-
(0,
|
|
4710
|
+
(0, import_log13.log)("update", {
|
|
4363
4711
|
spaces
|
|
4364
4712
|
}, {
|
|
4365
|
-
F:
|
|
4713
|
+
F: __dxlog_file15,
|
|
4366
4714
|
L: 77,
|
|
4367
4715
|
S: this,
|
|
4368
4716
|
C: (f, a) => f(...a)
|
|
@@ -4373,9 +4721,9 @@ var SpacesServiceImpl = class {
|
|
|
4373
4721
|
}, {
|
|
4374
4722
|
maxFrequency: process.env.NODE_ENV === "test" ? void 0 : 2
|
|
4375
4723
|
});
|
|
4376
|
-
(0,
|
|
4724
|
+
(0, import_async15.scheduleTask)(ctx, async () => {
|
|
4377
4725
|
const dataSpaceManager = await this._getDataSpaceManager();
|
|
4378
|
-
const subscriptions = new
|
|
4726
|
+
const subscriptions = new import_async15.EventSubscriptions();
|
|
4379
4727
|
ctx.onDispose(() => subscriptions.clear());
|
|
4380
4728
|
const subscribeSpaces = () => {
|
|
4381
4729
|
subscriptions.clear();
|
|
@@ -4402,14 +4750,14 @@ var SpacesServiceImpl = class {
|
|
|
4402
4750
|
}
|
|
4403
4751
|
async postMessage({ spaceKey, channel, message }) {
|
|
4404
4752
|
const dataSpaceManager = await this._getDataSpaceManager();
|
|
4405
|
-
const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new
|
|
4753
|
+
const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
|
|
4406
4754
|
await space.postMessage(getChannelId(channel), message);
|
|
4407
4755
|
}
|
|
4408
4756
|
subscribeMessages({ spaceKey, channel }) {
|
|
4409
4757
|
return new import_codec_protobuf10.Stream(({ ctx, next }) => {
|
|
4410
|
-
(0,
|
|
4758
|
+
(0, import_async15.scheduleTask)(ctx, async () => {
|
|
4411
4759
|
const dataSpaceManager = await this._getDataSpaceManager();
|
|
4412
|
-
const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new
|
|
4760
|
+
const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
|
|
4413
4761
|
const handle = space.listen(getChannelId(channel), (message) => {
|
|
4414
4762
|
next(message);
|
|
4415
4763
|
});
|
|
@@ -4419,14 +4767,14 @@ var SpacesServiceImpl = class {
|
|
|
4419
4767
|
}
|
|
4420
4768
|
queryCredentials({ spaceKey, noTail }) {
|
|
4421
4769
|
return new import_codec_protobuf10.Stream(({ ctx, next, close }) => {
|
|
4422
|
-
const space = this._spaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new
|
|
4770
|
+
const space = this._spaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
|
|
4423
4771
|
const processor = {
|
|
4424
4772
|
processCredential: async (credential) => {
|
|
4425
4773
|
next(credential);
|
|
4426
4774
|
}
|
|
4427
4775
|
};
|
|
4428
4776
|
ctx.onDispose(() => space.spaceState.removeCredentialProcessor(processor));
|
|
4429
|
-
(0,
|
|
4777
|
+
(0, import_async15.scheduleTask)(ctx, async () => {
|
|
4430
4778
|
await space.spaceState.addCredentialProcessor(processor);
|
|
4431
4779
|
if (noTail) {
|
|
4432
4780
|
close();
|
|
@@ -4435,7 +4783,7 @@ var SpacesServiceImpl = class {
|
|
|
4435
4783
|
});
|
|
4436
4784
|
}
|
|
4437
4785
|
async writeCredentials({ spaceKey, credentials }) {
|
|
4438
|
-
const space = this._spaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new
|
|
4786
|
+
const space = this._spaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
|
|
4439
4787
|
for (const credential of credentials ?? []) {
|
|
4440
4788
|
if (credential.proof) {
|
|
4441
4789
|
await space.controlPipeline.writer.write({
|
|
@@ -4444,8 +4792,8 @@ var SpacesServiceImpl = class {
|
|
|
4444
4792
|
}
|
|
4445
4793
|
});
|
|
4446
4794
|
} else {
|
|
4447
|
-
(0,
|
|
4448
|
-
F:
|
|
4795
|
+
(0, import_invariant14.invariant)(!credential.id, "Id on unsigned credentials is not allowed", {
|
|
4796
|
+
F: __dxlog_file15,
|
|
4449
4797
|
L: 164,
|
|
4450
4798
|
S: this,
|
|
4451
4799
|
A: [
|
|
@@ -4453,8 +4801,8 @@ var SpacesServiceImpl = class {
|
|
|
4453
4801
|
"'Id on unsigned credentials is not allowed'"
|
|
4454
4802
|
]
|
|
4455
4803
|
});
|
|
4456
|
-
(0,
|
|
4457
|
-
F:
|
|
4804
|
+
(0, import_invariant14.invariant)(this._identityManager.identity, "Identity is not available", {
|
|
4805
|
+
F: __dxlog_file15,
|
|
4458
4806
|
L: 165,
|
|
4459
4807
|
S: this,
|
|
4460
4808
|
A: [
|
|
@@ -4463,8 +4811,8 @@ var SpacesServiceImpl = class {
|
|
|
4463
4811
|
]
|
|
4464
4812
|
});
|
|
4465
4813
|
const signer = this._identityManager.identity.getIdentityCredentialSigner();
|
|
4466
|
-
(0,
|
|
4467
|
-
F:
|
|
4814
|
+
(0, import_invariant14.invariant)(credential.issuer.equals(signer.getIssuer()), void 0, {
|
|
4815
|
+
F: __dxlog_file15,
|
|
4468
4816
|
L: 167,
|
|
4469
4817
|
S: this,
|
|
4470
4818
|
A: [
|
|
@@ -4486,7 +4834,7 @@ var SpacesServiceImpl = class {
|
|
|
4486
4834
|
}
|
|
4487
4835
|
async createEpoch({ spaceKey, migration }) {
|
|
4488
4836
|
const dataSpaceManager = await this._getDataSpaceManager();
|
|
4489
|
-
const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new
|
|
4837
|
+
const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
|
|
4490
4838
|
await space.createEpoch({
|
|
4491
4839
|
migration
|
|
4492
4840
|
});
|
|
@@ -4495,7 +4843,7 @@ var SpacesServiceImpl = class {
|
|
|
4495
4843
|
return {
|
|
4496
4844
|
spaceKey: space.key,
|
|
4497
4845
|
state: space.state,
|
|
4498
|
-
error: space.error ? (0,
|
|
4846
|
+
error: space.error ? (0, import_protocols11.encodeError)(space.error) : void 0,
|
|
4499
4847
|
pipeline: {
|
|
4500
4848
|
currentEpoch: space.automergeSpaceState.lastEpoch,
|
|
4501
4849
|
appliedEpoch: space.automergeSpaceState.lastEpoch,
|
|
@@ -4520,7 +4868,7 @@ var SpacesServiceImpl = class {
|
|
|
4520
4868
|
identityKey: member.key,
|
|
4521
4869
|
profile: member.profile ?? {}
|
|
4522
4870
|
},
|
|
4523
|
-
presence: member.removed ?
|
|
4871
|
+
presence: member.removed ? import_services11.SpaceMember.PresenceState.REMOVED : isMe || peers.length > 0 ? import_services11.SpaceMember.PresenceState.ONLINE : import_services11.SpaceMember.PresenceState.OFFLINE,
|
|
4524
4872
|
peerStates: peers
|
|
4525
4873
|
};
|
|
4526
4874
|
}),
|
|
@@ -4541,8 +4889,8 @@ function _ts_decorate6(decorators, target, key, desc) {
|
|
|
4541
4889
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
4542
4890
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
4543
4891
|
}
|
|
4544
|
-
var
|
|
4545
|
-
var ServiceContext = class extends
|
|
4892
|
+
var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
|
|
4893
|
+
var ServiceContext = class extends import_context12.Resource {
|
|
4546
4894
|
constructor(storage, level, networkManager, signalManager, _runtimeParams) {
|
|
4547
4895
|
super();
|
|
4548
4896
|
this.storage = storage;
|
|
@@ -4550,9 +4898,9 @@ var ServiceContext = class extends import_context10.Resource {
|
|
|
4550
4898
|
this.networkManager = networkManager;
|
|
4551
4899
|
this.signalManager = signalManager;
|
|
4552
4900
|
this._runtimeParams = _runtimeParams;
|
|
4553
|
-
this.initialized = new
|
|
4901
|
+
this.initialized = new import_async16.Trigger();
|
|
4554
4902
|
this._handlerFactories = /* @__PURE__ */ new Map();
|
|
4555
|
-
this._instanceId =
|
|
4903
|
+
this._instanceId = import_keys12.PublicKey.random().toHex();
|
|
4556
4904
|
this.metadataStore = new import_echo_pipeline4.MetadataStore(storage.createDirectory("metadata"));
|
|
4557
4905
|
this.snapshotStore = new import_echo_pipeline4.SnapshotStore(storage.createDirectory("snapshots"));
|
|
4558
4906
|
this.blobStore = new import_teleport_extension_object_sync.BlobStore(storage.createDirectory("blobs"));
|
|
@@ -4579,23 +4927,23 @@ var ServiceContext = class extends import_context10.Resource {
|
|
|
4579
4927
|
kv: this.level,
|
|
4580
4928
|
storage: this.storage
|
|
4581
4929
|
});
|
|
4582
|
-
this.invitations = new InvitationsHandler(this.networkManager);
|
|
4930
|
+
this.invitations = new InvitationsHandler(this.networkManager, _runtimeParams?.invitationConnectionDefaultParams);
|
|
4583
4931
|
this.invitationsManager = new InvitationsManager(this.invitations, (invitation) => this.getInvitationHandler(invitation), this.metadataStore);
|
|
4584
|
-
this._handlerFactories.set(
|
|
4932
|
+
this._handlerFactories.set(import_services12.Invitation.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? (0, import_debug6.failUndefined)(), this._acceptIdentity.bind(this)));
|
|
4585
4933
|
}
|
|
4586
4934
|
async _open(ctx) {
|
|
4587
4935
|
await this._checkStorageVersion();
|
|
4588
|
-
(0,
|
|
4589
|
-
F:
|
|
4590
|
-
L:
|
|
4936
|
+
(0, import_log14.log)("opening...", void 0, {
|
|
4937
|
+
F: __dxlog_file16,
|
|
4938
|
+
L: 152,
|
|
4591
4939
|
S: this,
|
|
4592
4940
|
C: (f, a) => f(...a)
|
|
4593
4941
|
});
|
|
4594
|
-
|
|
4942
|
+
import_log14.log.trace("dxos.sdk.service-context.open", import_protocols12.trace.begin({
|
|
4595
4943
|
id: this._instanceId
|
|
4596
4944
|
}), {
|
|
4597
|
-
F:
|
|
4598
|
-
L:
|
|
4945
|
+
F: __dxlog_file16,
|
|
4946
|
+
L: 153,
|
|
4599
4947
|
S: this,
|
|
4600
4948
|
C: (f, a) => f(...a)
|
|
4601
4949
|
});
|
|
@@ -4609,33 +4957,33 @@ var ServiceContext = class extends import_context10.Resource {
|
|
|
4609
4957
|
await this._initialize(ctx);
|
|
4610
4958
|
}
|
|
4611
4959
|
const loadedInvitations = await this.invitationsManager.loadPersistentInvitations();
|
|
4612
|
-
(0,
|
|
4960
|
+
(0, import_log14.log)("loaded persistent invitations", {
|
|
4613
4961
|
count: loadedInvitations.invitations?.length
|
|
4614
4962
|
}, {
|
|
4615
|
-
F:
|
|
4616
|
-
L:
|
|
4963
|
+
F: __dxlog_file16,
|
|
4964
|
+
L: 166,
|
|
4617
4965
|
S: this,
|
|
4618
4966
|
C: (f, a) => f(...a)
|
|
4619
4967
|
});
|
|
4620
|
-
|
|
4968
|
+
import_log14.log.trace("dxos.sdk.service-context.open", import_protocols12.trace.end({
|
|
4621
4969
|
id: this._instanceId
|
|
4622
4970
|
}), {
|
|
4623
|
-
F:
|
|
4624
|
-
L:
|
|
4971
|
+
F: __dxlog_file16,
|
|
4972
|
+
L: 168,
|
|
4625
4973
|
S: this,
|
|
4626
4974
|
C: (f, a) => f(...a)
|
|
4627
4975
|
});
|
|
4628
|
-
(0,
|
|
4629
|
-
F:
|
|
4630
|
-
L:
|
|
4976
|
+
(0, import_log14.log)("opened", void 0, {
|
|
4977
|
+
F: __dxlog_file16,
|
|
4978
|
+
L: 169,
|
|
4631
4979
|
S: this,
|
|
4632
4980
|
C: (f, a) => f(...a)
|
|
4633
4981
|
});
|
|
4634
4982
|
}
|
|
4635
4983
|
async _close(ctx) {
|
|
4636
|
-
(0,
|
|
4637
|
-
F:
|
|
4638
|
-
L:
|
|
4984
|
+
(0, import_log14.log)("closing...", void 0, {
|
|
4985
|
+
F: __dxlog_file16,
|
|
4986
|
+
L: 173,
|
|
4639
4987
|
S: this,
|
|
4640
4988
|
C: (f, a) => f(...a)
|
|
4641
4989
|
});
|
|
@@ -4650,23 +4998,23 @@ var ServiceContext = class extends import_context10.Resource {
|
|
|
4650
4998
|
await this.echoHost.close(ctx);
|
|
4651
4999
|
await this.networkManager.close();
|
|
4652
5000
|
await this.signalManager.close();
|
|
4653
|
-
(0,
|
|
4654
|
-
F:
|
|
4655
|
-
L:
|
|
5001
|
+
(0, import_log14.log)("closed", void 0, {
|
|
5002
|
+
F: __dxlog_file16,
|
|
5003
|
+
L: 185,
|
|
4656
5004
|
S: this,
|
|
4657
5005
|
C: (f, a) => f(...a)
|
|
4658
5006
|
});
|
|
4659
5007
|
}
|
|
4660
5008
|
async createIdentity(params = {}) {
|
|
4661
5009
|
const identity = await this.identityManager.createIdentity(params);
|
|
4662
|
-
await this._initialize(new
|
|
5010
|
+
await this._initialize(new import_context12.Context());
|
|
4663
5011
|
return identity;
|
|
4664
5012
|
}
|
|
4665
5013
|
getInvitationHandler(invitation) {
|
|
4666
5014
|
const factory = this._handlerFactories.get(invitation.kind);
|
|
4667
|
-
(0,
|
|
4668
|
-
F:
|
|
4669
|
-
L:
|
|
5015
|
+
(0, import_invariant15.invariant)(factory, `Unknown invitation kind: ${invitation.kind}`, {
|
|
5016
|
+
F: __dxlog_file16,
|
|
5017
|
+
L: 196,
|
|
4670
5018
|
S: this,
|
|
4671
5019
|
A: [
|
|
4672
5020
|
"factory",
|
|
@@ -4685,20 +5033,20 @@ var ServiceContext = class extends import_context10.Resource {
|
|
|
4685
5033
|
}
|
|
4686
5034
|
async _acceptIdentity(params) {
|
|
4687
5035
|
const identity = await this.identityManager.acceptIdentity(params);
|
|
4688
|
-
await this._initialize(new
|
|
5036
|
+
await this._initialize(new import_context12.Context());
|
|
4689
5037
|
return identity;
|
|
4690
5038
|
}
|
|
4691
5039
|
async _checkStorageVersion() {
|
|
4692
5040
|
await this.metadataStore.load();
|
|
4693
|
-
if (this.metadataStore.version !==
|
|
4694
|
-
throw new
|
|
5041
|
+
if (this.metadataStore.version !== import_protocols12.STORAGE_VERSION) {
|
|
5042
|
+
throw new import_protocols12.InvalidStorageVersionError(import_protocols12.STORAGE_VERSION, this.metadataStore.version);
|
|
4695
5043
|
}
|
|
4696
5044
|
}
|
|
4697
5045
|
// Called when identity is created.
|
|
4698
5046
|
async _initialize(ctx) {
|
|
4699
|
-
(0,
|
|
4700
|
-
F:
|
|
4701
|
-
L:
|
|
5047
|
+
(0, import_log14.log)("initializing spaces...", void 0, {
|
|
5048
|
+
F: __dxlog_file16,
|
|
5049
|
+
L: 227,
|
|
4702
5050
|
S: this,
|
|
4703
5051
|
C: (f, a) => f(...a)
|
|
4704
5052
|
});
|
|
@@ -4718,10 +5066,10 @@ var ServiceContext = class extends import_context10.Resource {
|
|
|
4718
5066
|
};
|
|
4719
5067
|
this.dataSpaceManager = new DataSpaceManager(this.spaceManager, this.metadataStore, this.keyring, signingContext, this.feedStore, this.echoHost, this.invitationsManager, this._runtimeParams);
|
|
4720
5068
|
await this.dataSpaceManager.open();
|
|
4721
|
-
this._handlerFactories.set(
|
|
4722
|
-
(0,
|
|
4723
|
-
F:
|
|
4724
|
-
L:
|
|
5069
|
+
this._handlerFactories.set(import_services12.Invitation.Kind.SPACE, (invitation) => {
|
|
5070
|
+
(0, import_invariant15.invariant)(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
|
|
5071
|
+
F: __dxlog_file16,
|
|
5072
|
+
L: 252,
|
|
4725
5073
|
S: this,
|
|
4726
5074
|
A: [
|
|
4727
5075
|
"this.dataSpaceManager",
|
|
@@ -4741,33 +5089,33 @@ var ServiceContext = class extends import_context10.Resource {
|
|
|
4741
5089
|
return;
|
|
4742
5090
|
}
|
|
4743
5091
|
if (!this.dataSpaceManager) {
|
|
4744
|
-
(0,
|
|
5092
|
+
(0, import_log14.log)("dataSpaceManager not initialized yet, ignoring space admission", {
|
|
4745
5093
|
details: assertion
|
|
4746
5094
|
}, {
|
|
4747
|
-
F:
|
|
4748
|
-
L:
|
|
5095
|
+
F: __dxlog_file16,
|
|
5096
|
+
L: 268,
|
|
4749
5097
|
S: this,
|
|
4750
5098
|
C: (f, a) => f(...a)
|
|
4751
5099
|
});
|
|
4752
5100
|
return;
|
|
4753
5101
|
}
|
|
4754
5102
|
if (this.dataSpaceManager.spaces.has(assertion.spaceKey)) {
|
|
4755
|
-
(0,
|
|
5103
|
+
(0, import_log14.log)("space already exists, ignoring space admission", {
|
|
4756
5104
|
details: assertion
|
|
4757
5105
|
}, {
|
|
4758
|
-
F:
|
|
4759
|
-
L:
|
|
5106
|
+
F: __dxlog_file16,
|
|
5107
|
+
L: 272,
|
|
4760
5108
|
S: this,
|
|
4761
5109
|
C: (f, a) => f(...a)
|
|
4762
5110
|
});
|
|
4763
5111
|
return;
|
|
4764
5112
|
}
|
|
4765
5113
|
try {
|
|
4766
|
-
(0,
|
|
5114
|
+
(0, import_log14.log)("accepting space recorded in halo", {
|
|
4767
5115
|
details: assertion
|
|
4768
5116
|
}, {
|
|
4769
|
-
F:
|
|
4770
|
-
L:
|
|
5117
|
+
F: __dxlog_file16,
|
|
5118
|
+
L: 277,
|
|
4771
5119
|
S: this,
|
|
4772
5120
|
C: (f, a) => f(...a)
|
|
4773
5121
|
});
|
|
@@ -4776,9 +5124,9 @@ var ServiceContext = class extends import_context10.Resource {
|
|
|
4776
5124
|
genesisFeedKey: assertion.genesisFeedKey
|
|
4777
5125
|
});
|
|
4778
5126
|
} catch (err) {
|
|
4779
|
-
|
|
4780
|
-
F:
|
|
4781
|
-
L:
|
|
5127
|
+
import_log14.log.catch(err, void 0, {
|
|
5128
|
+
F: __dxlog_file16,
|
|
5129
|
+
L: 283,
|
|
4782
5130
|
S: this,
|
|
4783
5131
|
C: (f, a) => f(...a)
|
|
4784
5132
|
});
|
|
@@ -4795,7 +5143,7 @@ _ts_decorate6([
|
|
|
4795
5143
|
import_tracing5.trace.span()
|
|
4796
5144
|
], ServiceContext.prototype, "_initialize", null);
|
|
4797
5145
|
ServiceContext = _ts_decorate6([
|
|
4798
|
-
(0,
|
|
5146
|
+
(0, import_util9.safeInstanceof)("dxos.client-services.ServiceContext"),
|
|
4799
5147
|
import_tracing5.trace.resource()
|
|
4800
5148
|
], ServiceContext);
|
|
4801
5149
|
var ServiceRegistry = class {
|
|
@@ -4820,26 +5168,26 @@ var ServiceRegistry = class {
|
|
|
4820
5168
|
delete this._handlers[name];
|
|
4821
5169
|
}
|
|
4822
5170
|
};
|
|
4823
|
-
var DXOS_VERSION = "0.5.1-
|
|
5171
|
+
var DXOS_VERSION = "0.5.1-next.0ef769d";
|
|
4824
5172
|
var getPlatform = () => {
|
|
4825
5173
|
if (process.browser) {
|
|
4826
5174
|
if (typeof window !== "undefined") {
|
|
4827
5175
|
const { userAgent } = window.navigator;
|
|
4828
5176
|
return {
|
|
4829
|
-
type:
|
|
5177
|
+
type: import_services14.Platform.PLATFORM_TYPE.BROWSER,
|
|
4830
5178
|
userAgent,
|
|
4831
5179
|
uptime: Math.floor((Date.now() - window.performance.timeOrigin) / 1e3)
|
|
4832
5180
|
};
|
|
4833
5181
|
} else {
|
|
4834
5182
|
return {
|
|
4835
|
-
type:
|
|
5183
|
+
type: import_services14.Platform.PLATFORM_TYPE.SHARED_WORKER,
|
|
4836
5184
|
uptime: Math.floor((Date.now() - performance.timeOrigin) / 1e3)
|
|
4837
5185
|
};
|
|
4838
5186
|
}
|
|
4839
5187
|
} else {
|
|
4840
5188
|
const { platform: platform2, version, arch } = process;
|
|
4841
5189
|
return {
|
|
4842
|
-
type:
|
|
5190
|
+
type: import_services14.Platform.PLATFORM_TYPE.NODE,
|
|
4843
5191
|
platform: platform2,
|
|
4844
5192
|
arch,
|
|
4845
5193
|
runtime: version,
|
|
@@ -4848,7 +5196,7 @@ var getPlatform = () => {
|
|
|
4848
5196
|
};
|
|
4849
5197
|
}
|
|
4850
5198
|
};
|
|
4851
|
-
var
|
|
5199
|
+
var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/diagnostics/diagnostics.ts";
|
|
4852
5200
|
var DEFAULT_TIMEOUT = 1e3;
|
|
4853
5201
|
var createDiagnostics = async (clientServices, serviceContext, config) => {
|
|
4854
5202
|
const diagnostics = {
|
|
@@ -4857,14 +5205,14 @@ var createDiagnostics = async (clientServices, serviceContext, config) => {
|
|
|
4857
5205
|
client: {
|
|
4858
5206
|
version: DXOS_VERSION,
|
|
4859
5207
|
storage: {
|
|
4860
|
-
version:
|
|
5208
|
+
version: import_protocols13.STORAGE_VERSION
|
|
4861
5209
|
}
|
|
4862
5210
|
},
|
|
4863
5211
|
trace: import_tracing6.TRACE_PROCESSOR.getDiagnostics()
|
|
4864
5212
|
};
|
|
4865
5213
|
{
|
|
4866
|
-
(0,
|
|
4867
|
-
F:
|
|
5214
|
+
(0, import_invariant16.invariant)(clientServices.LoggingService, "SystemService is not available.", {
|
|
5215
|
+
F: __dxlog_file17,
|
|
4868
5216
|
L: 108,
|
|
4869
5217
|
S: void 0,
|
|
4870
5218
|
A: [
|
|
@@ -4937,7 +5285,7 @@ var getSpaceStats = async (space) => {
|
|
|
4937
5285
|
displayName: member.assertion.profile?.displayName
|
|
4938
5286
|
}
|
|
4939
5287
|
},
|
|
4940
|
-
presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ?
|
|
5288
|
+
presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? import_services13.SpaceMember.PresenceState.ONLINE : import_services13.SpaceMember.PresenceState.OFFLINE
|
|
4941
5289
|
})),
|
|
4942
5290
|
pipeline: {
|
|
4943
5291
|
// TODO(burdon): Pick properties from credentials if needed.
|
|
@@ -4968,7 +5316,7 @@ var createCollectDiagnosticsBroadcastHandler = (_) => {
|
|
|
4968
5316
|
}
|
|
4969
5317
|
};
|
|
4970
5318
|
};
|
|
4971
|
-
var
|
|
5319
|
+
var __dxlog_file18 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
|
|
4972
5320
|
var DevicesServiceImpl = class {
|
|
4973
5321
|
constructor(_identityManager) {
|
|
4974
5322
|
this._identityManager = _identityManager;
|
|
@@ -4985,8 +5333,8 @@ var DevicesServiceImpl = class {
|
|
|
4985
5333
|
devices: []
|
|
4986
5334
|
});
|
|
4987
5335
|
} else {
|
|
4988
|
-
(0,
|
|
4989
|
-
F:
|
|
5336
|
+
(0, import_invariant18.invariant)(this._identityManager.identity?.presence, "presence not present", {
|
|
5337
|
+
F: __dxlog_file18,
|
|
4990
5338
|
L: 32,
|
|
4991
5339
|
S: this,
|
|
4992
5340
|
A: [
|
|
@@ -5001,9 +5349,9 @@ var DevicesServiceImpl = class {
|
|
|
5001
5349
|
const peerState = peers.find((peer) => peer.identityKey.equals(key));
|
|
5002
5350
|
return {
|
|
5003
5351
|
deviceKey: key,
|
|
5004
|
-
kind: this._identityManager.identity?.deviceKey.equals(key) ?
|
|
5352
|
+
kind: this._identityManager.identity?.deviceKey.equals(key) ? import_services17.DeviceKind.CURRENT : import_services17.DeviceKind.TRUSTED,
|
|
5005
5353
|
profile,
|
|
5006
|
-
presence: isMe ?
|
|
5354
|
+
presence: isMe ? import_services17.Device.PresenceState.ONLINE : peerState ? import_services17.Device.PresenceState.ONLINE : import_services17.Device.PresenceState.OFFLINE
|
|
5007
5355
|
};
|
|
5008
5356
|
})
|
|
5009
5357
|
});
|
|
@@ -5027,7 +5375,7 @@ var DevicesServiceImpl = class {
|
|
|
5027
5375
|
presenceSubscribed = true;
|
|
5028
5376
|
}
|
|
5029
5377
|
};
|
|
5030
|
-
const subscriptions = new
|
|
5378
|
+
const subscriptions = new import_async18.EventSubscriptions();
|
|
5031
5379
|
if (this._identityManager.identity) {
|
|
5032
5380
|
subscribeIdentity();
|
|
5033
5381
|
subscribePresence();
|
|
@@ -5054,7 +5402,7 @@ function _ts_decorate7(decorators, target, key, desc) {
|
|
|
5054
5402
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5055
5403
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
5056
5404
|
}
|
|
5057
|
-
var
|
|
5405
|
+
var __dxlog_file19 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/node.ts";
|
|
5058
5406
|
var Lock = class {
|
|
5059
5407
|
constructor({ lockKey: lockPath, onAcquire, onRelease }) {
|
|
5060
5408
|
this._lockPath = lockPath;
|
|
@@ -5065,16 +5413,16 @@ var Lock = class {
|
|
|
5065
5413
|
return this._lockPath;
|
|
5066
5414
|
}
|
|
5067
5415
|
async acquire() {
|
|
5068
|
-
(0,
|
|
5069
|
-
F:
|
|
5416
|
+
(0, import_log16.log)("acquiring lock...", void 0, {
|
|
5417
|
+
F: __dxlog_file19,
|
|
5070
5418
|
L: 32,
|
|
5071
5419
|
S: this,
|
|
5072
5420
|
C: (f, a) => f(...a)
|
|
5073
5421
|
});
|
|
5074
5422
|
this._fileHandle = await import_lock_file.LockFile.acquire(this._lockPath);
|
|
5075
5423
|
await this._onAcquire?.();
|
|
5076
|
-
(0,
|
|
5077
|
-
F:
|
|
5424
|
+
(0, import_log16.log)("acquired lock", void 0, {
|
|
5425
|
+
F: __dxlog_file19,
|
|
5078
5426
|
L: 37,
|
|
5079
5427
|
S: this,
|
|
5080
5428
|
C: (f, a) => f(...a)
|
|
@@ -5082,8 +5430,8 @@ var Lock = class {
|
|
|
5082
5430
|
}
|
|
5083
5431
|
async release() {
|
|
5084
5432
|
await this._onRelease?.();
|
|
5085
|
-
(0,
|
|
5086
|
-
F:
|
|
5433
|
+
(0, import_invariant19.invariant)(this._fileHandle, "Lock is not acquired", {
|
|
5434
|
+
F: __dxlog_file19,
|
|
5087
5435
|
L: 42,
|
|
5088
5436
|
S: this,
|
|
5089
5437
|
A: [
|
|
@@ -5095,36 +5443,36 @@ var Lock = class {
|
|
|
5095
5443
|
}
|
|
5096
5444
|
};
|
|
5097
5445
|
_ts_decorate7([
|
|
5098
|
-
|
|
5446
|
+
import_log16.logInfo
|
|
5099
5447
|
], Lock.prototype, "lockKey", null);
|
|
5100
5448
|
var isLocked = (lockPath) => import_lock_file.LockFile.isLocked(lockPath);
|
|
5101
5449
|
var LoggingServiceImpl = class {
|
|
5102
5450
|
constructor() {
|
|
5103
|
-
this._logs = new
|
|
5451
|
+
this._logs = new import_async19.Event();
|
|
5104
5452
|
this._started = Date.now();
|
|
5105
|
-
this._sessionId =
|
|
5453
|
+
this._sessionId = import_keys14.PublicKey.random().toHex();
|
|
5106
5454
|
this._logProcessor = (_config, entry2) => {
|
|
5107
5455
|
this._logs.emit(entry2);
|
|
5108
5456
|
};
|
|
5109
5457
|
}
|
|
5110
5458
|
async open() {
|
|
5111
|
-
|
|
5459
|
+
import_log17.log.runtimeConfig.processors.push(this._logProcessor);
|
|
5112
5460
|
}
|
|
5113
5461
|
async close() {
|
|
5114
|
-
const index =
|
|
5115
|
-
|
|
5462
|
+
const index = import_log17.log.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
|
|
5463
|
+
import_log17.log.runtimeConfig.processors.splice(index, 1);
|
|
5116
5464
|
}
|
|
5117
5465
|
async controlMetrics({ reset, record }) {
|
|
5118
5466
|
if (reset) {
|
|
5119
|
-
|
|
5467
|
+
import_util12.tracer.clear();
|
|
5120
5468
|
}
|
|
5121
5469
|
if (record === true) {
|
|
5122
|
-
|
|
5470
|
+
import_util12.tracer.start();
|
|
5123
5471
|
} else if (record === false) {
|
|
5124
|
-
|
|
5472
|
+
import_util12.tracer.stop();
|
|
5125
5473
|
}
|
|
5126
5474
|
return {
|
|
5127
|
-
recording:
|
|
5475
|
+
recording: import_util12.tracer.recording
|
|
5128
5476
|
};
|
|
5129
5477
|
}
|
|
5130
5478
|
/**
|
|
@@ -5132,10 +5480,10 @@ var LoggingServiceImpl = class {
|
|
|
5132
5480
|
*/
|
|
5133
5481
|
queryMetrics({ interval = 5e3 }) {
|
|
5134
5482
|
const getNumericalValues = (key) => {
|
|
5135
|
-
const events =
|
|
5483
|
+
const events = import_util12.tracer.get(key) ?? [];
|
|
5136
5484
|
return {
|
|
5137
5485
|
key,
|
|
5138
|
-
stats: (0,
|
|
5486
|
+
stats: (0, import_util12.numericalValues)(events, "duration")
|
|
5139
5487
|
};
|
|
5140
5488
|
};
|
|
5141
5489
|
return new import_codec_protobuf13.Stream(({ next }) => {
|
|
@@ -5173,7 +5521,7 @@ var LoggingServiceImpl = class {
|
|
|
5173
5521
|
}
|
|
5174
5522
|
const record = {
|
|
5175
5523
|
...entry2,
|
|
5176
|
-
context: (0,
|
|
5524
|
+
context: (0, import_util12.jsonify)((0, import_log17.getContextFromEntry)(entry2)),
|
|
5177
5525
|
timestamp: /* @__PURE__ */ new Date(),
|
|
5178
5526
|
meta: {
|
|
5179
5527
|
// TODO(dmaretskyi): Fix proto.
|
|
@@ -5182,7 +5530,7 @@ var LoggingServiceImpl = class {
|
|
|
5182
5530
|
scope: {
|
|
5183
5531
|
hostSessionId: this._sessionId,
|
|
5184
5532
|
uptimeSeconds: (Date.now() - this._started) / 1e3,
|
|
5185
|
-
name: (0,
|
|
5533
|
+
name: (0, import_util12.getDebugName)(entry2.meta?.S)
|
|
5186
5534
|
}
|
|
5187
5535
|
}
|
|
5188
5536
|
};
|
|
@@ -5199,16 +5547,16 @@ var LoggingServiceImpl = class {
|
|
|
5199
5547
|
};
|
|
5200
5548
|
var matchFilter = (filter, level, path2, options) => {
|
|
5201
5549
|
switch (options) {
|
|
5202
|
-
case
|
|
5550
|
+
case import_services18.QueryLogsRequest.MatchingOptions.INCLUSIVE:
|
|
5203
5551
|
return level >= filter.level && (!filter.pattern || path2.includes(filter.pattern));
|
|
5204
|
-
case
|
|
5552
|
+
case import_services18.QueryLogsRequest.MatchingOptions.EXPLICIT:
|
|
5205
5553
|
return level === filter.level && (!filter.pattern || path2.includes(filter.pattern));
|
|
5206
5554
|
}
|
|
5207
5555
|
};
|
|
5208
5556
|
var shouldLog = (entry2, request) => {
|
|
5209
|
-
const options = request.options ??
|
|
5557
|
+
const options = request.options ?? import_services18.QueryLogsRequest.MatchingOptions.INCLUSIVE;
|
|
5210
5558
|
if (request.filters === void 0) {
|
|
5211
|
-
return options ===
|
|
5559
|
+
return options === import_services18.QueryLogsRequest.MatchingOptions.INCLUSIVE;
|
|
5212
5560
|
} else {
|
|
5213
5561
|
return request.filters.some((filter) => matchFilter(filter, entry2.level, entry2.meta?.F ?? "", options));
|
|
5214
5562
|
}
|
|
@@ -5245,7 +5593,7 @@ var NetworkServiceImpl = class {
|
|
|
5245
5593
|
}
|
|
5246
5594
|
};
|
|
5247
5595
|
var getRootPath = (config) => {
|
|
5248
|
-
const { dataRoot = (0,
|
|
5596
|
+
const { dataRoot = (0, import_util13.isNode)() ? import_client_protocol6.DX_DATA : "dxos/storage" } = config ?? {};
|
|
5249
5597
|
return `${dataRoot}/`;
|
|
5250
5598
|
};
|
|
5251
5599
|
var isPersistent = (config) => {
|
|
@@ -5256,16 +5604,16 @@ var StorageDriver = import_config2.Runtime.Client.Storage.StorageDriver;
|
|
|
5256
5604
|
var createStorageObjects = (config) => {
|
|
5257
5605
|
const { persistent = false, keyStore, dataStore } = config ?? {};
|
|
5258
5606
|
if (persistent && dataStore === StorageDriver.RAM) {
|
|
5259
|
-
throw new
|
|
5607
|
+
throw new import_protocols15.InvalidConfigError("RAM storage cannot be used in persistent mode.");
|
|
5260
5608
|
}
|
|
5261
5609
|
if (!persistent && dataStore !== void 0 && dataStore !== StorageDriver.RAM) {
|
|
5262
|
-
throw new
|
|
5610
|
+
throw new import_protocols15.InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
|
|
5263
5611
|
}
|
|
5264
5612
|
if (persistent && keyStore === StorageDriver.RAM) {
|
|
5265
|
-
throw new
|
|
5613
|
+
throw new import_protocols15.InvalidConfigError("RAM key storage cannot be used in persistent mode.");
|
|
5266
5614
|
}
|
|
5267
5615
|
if (!persistent && keyStore !== StorageDriver.RAM && keyStore !== void 0) {
|
|
5268
|
-
throw new
|
|
5616
|
+
throw new import_protocols15.InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
|
|
5269
5617
|
}
|
|
5270
5618
|
return {
|
|
5271
5619
|
storage: (0, import_random_access_storage.createStorage)({
|
|
@@ -5296,8 +5644,8 @@ var toStorageType = (type) => {
|
|
|
5296
5644
|
};
|
|
5297
5645
|
var createLevel = async (config) => {
|
|
5298
5646
|
const persistent = isPersistent(config);
|
|
5299
|
-
const storagePath = persistent ? import_node_path.default.join(getRootPath(config), "level") : `/tmp/dxos-${
|
|
5300
|
-
const level =
|
|
5647
|
+
const storagePath = persistent ? import_node_path.default.join(getRootPath(config), "level") : `/tmp/dxos-${import_keys15.PublicKey.random().toHex()}`;
|
|
5648
|
+
const level = (0, import_kv_store.createLevel)(storagePath);
|
|
5301
5649
|
await level.open();
|
|
5302
5650
|
return level;
|
|
5303
5651
|
};
|
|
@@ -5320,9 +5668,9 @@ var SystemServiceImpl = class {
|
|
|
5320
5668
|
const diagnostics = await this._getDiagnostics();
|
|
5321
5669
|
return {
|
|
5322
5670
|
timestamp: /* @__PURE__ */ new Date(),
|
|
5323
|
-
diagnostics: JSON.parse(JSON.stringify(diagnostics, (0,
|
|
5324
|
-
truncate: keys ===
|
|
5325
|
-
humanize: keys ===
|
|
5671
|
+
diagnostics: JSON.parse(JSON.stringify(diagnostics, (0, import_util14.jsonKeyReplacer)({
|
|
5672
|
+
truncate: keys === import_services19.GetDiagnosticsRequest.KEY_OPTION.TRUNCATE,
|
|
5673
|
+
humanize: keys === import_services19.GetDiagnosticsRequest.KEY_OPTION.HUMANIZE
|
|
5326
5674
|
})))
|
|
5327
5675
|
};
|
|
5328
5676
|
}
|
|
@@ -5363,7 +5711,7 @@ function _ts_decorate8(decorators, target, key, desc) {
|
|
|
5363
5711
|
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5364
5712
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
5365
5713
|
}
|
|
5366
|
-
var
|
|
5714
|
+
var __dxlog_file20 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
|
|
5367
5715
|
var ClientServicesHost = class {
|
|
5368
5716
|
constructor({
|
|
5369
5717
|
config,
|
|
@@ -5377,7 +5725,7 @@ var ClientServicesHost = class {
|
|
|
5377
5725
|
runtimeParams
|
|
5378
5726
|
} = {}) {
|
|
5379
5727
|
this._tracingService = import_tracing8.TRACE_PROCESSOR.createTraceSender();
|
|
5380
|
-
this._statusUpdate = new
|
|
5728
|
+
this._statusUpdate = new import_async17.Event();
|
|
5381
5729
|
this._opening = false;
|
|
5382
5730
|
this._open = false;
|
|
5383
5731
|
this._storage = storage;
|
|
@@ -5396,7 +5744,7 @@ var ClientServicesHost = class {
|
|
|
5396
5744
|
lockKey,
|
|
5397
5745
|
onAcquire: () => {
|
|
5398
5746
|
if (!this._opening) {
|
|
5399
|
-
void this.open(new
|
|
5747
|
+
void this.open(new import_context13.Context());
|
|
5400
5748
|
}
|
|
5401
5749
|
},
|
|
5402
5750
|
onRelease: () => this.close()
|
|
@@ -5405,14 +5753,14 @@ var ClientServicesHost = class {
|
|
|
5405
5753
|
this._systemService = new SystemServiceImpl({
|
|
5406
5754
|
config: () => this._config,
|
|
5407
5755
|
statusUpdate: this._statusUpdate,
|
|
5408
|
-
getCurrentStatus: () => this.isOpen ?
|
|
5756
|
+
getCurrentStatus: () => this.isOpen ? import_services16.SystemStatus.ACTIVE : import_services16.SystemStatus.INACTIVE,
|
|
5409
5757
|
getDiagnostics: () => {
|
|
5410
5758
|
return createDiagnostics(this._serviceRegistry.services, this._serviceContext, this._config);
|
|
5411
5759
|
},
|
|
5412
5760
|
onUpdateStatus: async (status) => {
|
|
5413
|
-
if (!this.isOpen && status ===
|
|
5761
|
+
if (!this.isOpen && status === import_services16.SystemStatus.ACTIVE) {
|
|
5414
5762
|
await this._resourceLock?.acquire();
|
|
5415
|
-
} else if (this.isOpen && status ===
|
|
5763
|
+
} else if (this.isOpen && status === import_services16.SystemStatus.INACTIVE) {
|
|
5416
5764
|
await this._resourceLock?.release();
|
|
5417
5765
|
}
|
|
5418
5766
|
},
|
|
@@ -5451,25 +5799,25 @@ var ClientServicesHost = class {
|
|
|
5451
5799
|
* Can only be called once.
|
|
5452
5800
|
*/
|
|
5453
5801
|
initialize({ config, ...options }) {
|
|
5454
|
-
(0,
|
|
5455
|
-
F:
|
|
5456
|
-
L:
|
|
5802
|
+
(0, import_invariant17.invariant)(!this._open, "service host is open", {
|
|
5803
|
+
F: __dxlog_file20,
|
|
5804
|
+
L: 189,
|
|
5457
5805
|
S: this,
|
|
5458
5806
|
A: [
|
|
5459
5807
|
"!this._open",
|
|
5460
5808
|
"'service host is open'"
|
|
5461
5809
|
]
|
|
5462
5810
|
});
|
|
5463
|
-
(0,
|
|
5464
|
-
F:
|
|
5465
|
-
L:
|
|
5811
|
+
(0, import_log15.log)("initializing...", void 0, {
|
|
5812
|
+
F: __dxlog_file20,
|
|
5813
|
+
L: 190,
|
|
5466
5814
|
S: this,
|
|
5467
5815
|
C: (f, a) => f(...a)
|
|
5468
5816
|
});
|
|
5469
5817
|
if (config) {
|
|
5470
|
-
(0,
|
|
5471
|
-
F:
|
|
5472
|
-
L:
|
|
5818
|
+
(0, import_invariant17.invariant)(!this._config, "config already set", {
|
|
5819
|
+
F: __dxlog_file20,
|
|
5820
|
+
L: 193,
|
|
5473
5821
|
S: this,
|
|
5474
5822
|
A: [
|
|
5475
5823
|
"!this._config",
|
|
@@ -5482,9 +5830,9 @@ var ClientServicesHost = class {
|
|
|
5482
5830
|
}
|
|
5483
5831
|
}
|
|
5484
5832
|
if (!options.signalManager) {
|
|
5485
|
-
|
|
5486
|
-
F:
|
|
5487
|
-
L:
|
|
5833
|
+
import_log15.log.warn("running signaling without telemetry metadata.", void 0, {
|
|
5834
|
+
F: __dxlog_file20,
|
|
5835
|
+
L: 201,
|
|
5488
5836
|
S: this,
|
|
5489
5837
|
C: (f, a) => f(...a)
|
|
5490
5838
|
});
|
|
@@ -5493,9 +5841,9 @@ var ClientServicesHost = class {
|
|
|
5493
5841
|
iceServers: this._config?.get("runtime.services.ice")
|
|
5494
5842
|
}), signalManager = new import_messaging.WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
|
|
5495
5843
|
this._signalManager = signalManager;
|
|
5496
|
-
(0,
|
|
5497
|
-
F:
|
|
5498
|
-
L:
|
|
5844
|
+
(0, import_invariant17.invariant)(!this._networkManager, "network manager already set", {
|
|
5845
|
+
F: __dxlog_file20,
|
|
5846
|
+
L: 212,
|
|
5499
5847
|
S: this,
|
|
5500
5848
|
A: [
|
|
5501
5849
|
"!this._networkManager",
|
|
@@ -5507,9 +5855,9 @@ var ClientServicesHost = class {
|
|
|
5507
5855
|
transportFactory,
|
|
5508
5856
|
signalManager
|
|
5509
5857
|
});
|
|
5510
|
-
(0,
|
|
5511
|
-
F:
|
|
5512
|
-
L:
|
|
5858
|
+
(0, import_log15.log)("initialized", void 0, {
|
|
5859
|
+
F: __dxlog_file20,
|
|
5860
|
+
L: 219,
|
|
5513
5861
|
S: this,
|
|
5514
5862
|
C: (f, a) => f(...a)
|
|
5515
5863
|
});
|
|
@@ -5518,45 +5866,45 @@ var ClientServicesHost = class {
|
|
|
5518
5866
|
if (this._open) {
|
|
5519
5867
|
return;
|
|
5520
5868
|
}
|
|
5521
|
-
const traceId =
|
|
5522
|
-
|
|
5869
|
+
const traceId = import_keys13.PublicKey.random().toHex();
|
|
5870
|
+
import_log15.log.trace("dxos.client-services.host.open", import_protocols14.trace.begin({
|
|
5523
5871
|
id: traceId
|
|
5524
5872
|
}), {
|
|
5525
|
-
F:
|
|
5526
|
-
L:
|
|
5873
|
+
F: __dxlog_file20,
|
|
5874
|
+
L: 230,
|
|
5527
5875
|
S: this,
|
|
5528
5876
|
C: (f, a) => f(...a)
|
|
5529
5877
|
});
|
|
5530
|
-
(0,
|
|
5531
|
-
F:
|
|
5532
|
-
L:
|
|
5878
|
+
(0, import_invariant17.invariant)(this._config, "config not set", {
|
|
5879
|
+
F: __dxlog_file20,
|
|
5880
|
+
L: 232,
|
|
5533
5881
|
S: this,
|
|
5534
5882
|
A: [
|
|
5535
5883
|
"this._config",
|
|
5536
5884
|
"'config not set'"
|
|
5537
5885
|
]
|
|
5538
5886
|
});
|
|
5539
|
-
(0,
|
|
5540
|
-
F:
|
|
5541
|
-
L:
|
|
5887
|
+
(0, import_invariant17.invariant)(this._storage, "storage not set", {
|
|
5888
|
+
F: __dxlog_file20,
|
|
5889
|
+
L: 233,
|
|
5542
5890
|
S: this,
|
|
5543
5891
|
A: [
|
|
5544
5892
|
"this._storage",
|
|
5545
5893
|
"'storage not set'"
|
|
5546
5894
|
]
|
|
5547
5895
|
});
|
|
5548
|
-
(0,
|
|
5549
|
-
F:
|
|
5550
|
-
L:
|
|
5896
|
+
(0, import_invariant17.invariant)(this._signalManager, "signal manager not set", {
|
|
5897
|
+
F: __dxlog_file20,
|
|
5898
|
+
L: 234,
|
|
5551
5899
|
S: this,
|
|
5552
5900
|
A: [
|
|
5553
5901
|
"this._signalManager",
|
|
5554
5902
|
"'signal manager not set'"
|
|
5555
5903
|
]
|
|
5556
5904
|
});
|
|
5557
|
-
(0,
|
|
5558
|
-
F:
|
|
5559
|
-
L:
|
|
5905
|
+
(0, import_invariant17.invariant)(this._networkManager, "network manager not set", {
|
|
5906
|
+
F: __dxlog_file20,
|
|
5907
|
+
L: 235,
|
|
5560
5908
|
S: this,
|
|
5561
5909
|
A: [
|
|
5562
5910
|
"this._networkManager",
|
|
@@ -5564,11 +5912,11 @@ var ClientServicesHost = class {
|
|
|
5564
5912
|
]
|
|
5565
5913
|
});
|
|
5566
5914
|
this._opening = true;
|
|
5567
|
-
(0,
|
|
5915
|
+
(0, import_log15.log)("opening...", {
|
|
5568
5916
|
lockKey: this._resourceLock?.lockKey
|
|
5569
5917
|
}, {
|
|
5570
|
-
F:
|
|
5571
|
-
L:
|
|
5918
|
+
F: __dxlog_file20,
|
|
5919
|
+
L: 238,
|
|
5572
5920
|
S: this,
|
|
5573
5921
|
C: (f, a) => f(...a)
|
|
5574
5922
|
});
|
|
@@ -5616,19 +5964,19 @@ var ClientServicesHost = class {
|
|
|
5616
5964
|
this._open = true;
|
|
5617
5965
|
this._statusUpdate.emit();
|
|
5618
5966
|
const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
|
|
5619
|
-
(0,
|
|
5967
|
+
(0, import_log15.log)("opened", {
|
|
5620
5968
|
deviceKey
|
|
5621
5969
|
}, {
|
|
5622
|
-
F:
|
|
5623
|
-
L:
|
|
5970
|
+
F: __dxlog_file20,
|
|
5971
|
+
L: 314,
|
|
5624
5972
|
S: this,
|
|
5625
5973
|
C: (f, a) => f(...a)
|
|
5626
5974
|
});
|
|
5627
|
-
|
|
5975
|
+
import_log15.log.trace("dxos.client-services.host.open", import_protocols14.trace.end({
|
|
5628
5976
|
id: traceId
|
|
5629
5977
|
}), {
|
|
5630
|
-
F:
|
|
5631
|
-
L:
|
|
5978
|
+
F: __dxlog_file20,
|
|
5979
|
+
L: 315,
|
|
5632
5980
|
S: this,
|
|
5633
5981
|
C: (f, a) => f(...a)
|
|
5634
5982
|
});
|
|
@@ -5638,11 +5986,11 @@ var ClientServicesHost = class {
|
|
|
5638
5986
|
return;
|
|
5639
5987
|
}
|
|
5640
5988
|
const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
|
|
5641
|
-
(0,
|
|
5989
|
+
(0, import_log15.log)("closing...", {
|
|
5642
5990
|
deviceKey
|
|
5643
5991
|
}, {
|
|
5644
|
-
F:
|
|
5645
|
-
L:
|
|
5992
|
+
F: __dxlog_file20,
|
|
5993
|
+
L: 326,
|
|
5646
5994
|
S: this,
|
|
5647
5995
|
C: (f, a) => f(...a)
|
|
5648
5996
|
});
|
|
@@ -5656,44 +6004,44 @@ var ClientServicesHost = class {
|
|
|
5656
6004
|
await this._level?.close();
|
|
5657
6005
|
this._open = false;
|
|
5658
6006
|
this._statusUpdate.emit();
|
|
5659
|
-
(0,
|
|
6007
|
+
(0, import_log15.log)("closed", {
|
|
5660
6008
|
deviceKey
|
|
5661
6009
|
}, {
|
|
5662
|
-
F:
|
|
5663
|
-
L:
|
|
6010
|
+
F: __dxlog_file20,
|
|
6011
|
+
L: 335,
|
|
5664
6012
|
S: this,
|
|
5665
6013
|
C: (f, a) => f(...a)
|
|
5666
6014
|
});
|
|
5667
6015
|
}
|
|
5668
6016
|
async reset() {
|
|
5669
|
-
const traceId =
|
|
5670
|
-
|
|
6017
|
+
const traceId = import_keys13.PublicKey.random().toHex();
|
|
6018
|
+
import_log15.log.trace("dxos.sdk.client-services-host.reset", import_protocols14.trace.begin({
|
|
5671
6019
|
id: traceId
|
|
5672
6020
|
}), {
|
|
5673
|
-
F:
|
|
5674
|
-
L:
|
|
6021
|
+
F: __dxlog_file20,
|
|
6022
|
+
L: 340,
|
|
5675
6023
|
S: this,
|
|
5676
6024
|
C: (f, a) => f(...a)
|
|
5677
6025
|
});
|
|
5678
|
-
(0,
|
|
5679
|
-
F:
|
|
5680
|
-
L:
|
|
6026
|
+
(0, import_log15.log)("resetting...", void 0, {
|
|
6027
|
+
F: __dxlog_file20,
|
|
6028
|
+
L: 342,
|
|
5681
6029
|
S: this,
|
|
5682
6030
|
C: (f, a) => f(...a)
|
|
5683
6031
|
});
|
|
5684
6032
|
await this._serviceContext?.close();
|
|
5685
6033
|
await this._storage.reset();
|
|
5686
|
-
(0,
|
|
5687
|
-
F:
|
|
5688
|
-
L:
|
|
6034
|
+
(0, import_log15.log)("reset", void 0, {
|
|
6035
|
+
F: __dxlog_file20,
|
|
6036
|
+
L: 345,
|
|
5689
6037
|
S: this,
|
|
5690
6038
|
C: (f, a) => f(...a)
|
|
5691
6039
|
});
|
|
5692
|
-
|
|
6040
|
+
import_log15.log.trace("dxos.sdk.client-services-host.reset", import_protocols14.trace.end({
|
|
5693
6041
|
id: traceId
|
|
5694
6042
|
}), {
|
|
5695
|
-
F:
|
|
5696
|
-
L:
|
|
6043
|
+
F: __dxlog_file20,
|
|
6044
|
+
L: 346,
|
|
5697
6045
|
S: this,
|
|
5698
6046
|
C: (f, a) => f(...a)
|
|
5699
6047
|
});
|
|
@@ -5704,9 +6052,9 @@ var ClientServicesHost = class {
|
|
|
5704
6052
|
await this._serviceContext.initialized.wait();
|
|
5705
6053
|
const space = await this._serviceContext.dataSpaceManager.createSpace();
|
|
5706
6054
|
const automergeIndex = space.automergeSpaceState.rootUrl;
|
|
5707
|
-
(0,
|
|
5708
|
-
F:
|
|
5709
|
-
L:
|
|
6055
|
+
(0, import_invariant17.invariant)(automergeIndex, void 0, {
|
|
6056
|
+
F: __dxlog_file20,
|
|
6057
|
+
L: 358,
|
|
5710
6058
|
S: this,
|
|
5711
6059
|
A: [
|
|
5712
6060
|
"automergeIndex",
|
|
@@ -5717,7 +6065,7 @@ var ClientServicesHost = class {
|
|
|
5717
6065
|
await document.whenReady();
|
|
5718
6066
|
const properties = {
|
|
5719
6067
|
system: {
|
|
5720
|
-
type: (0,
|
|
6068
|
+
type: (0, import_echo_protocol.encodeReference)((0, import_echo_schema2.getTypeReference)(import_client_protocol5.Properties))
|
|
5721
6069
|
},
|
|
5722
6070
|
data: {
|
|
5723
6071
|
[import_client_protocol5.defaultKey]: identity.identityKey.toHex()
|
|
@@ -5726,9 +6074,9 @@ var ClientServicesHost = class {
|
|
|
5726
6074
|
keys: []
|
|
5727
6075
|
}
|
|
5728
6076
|
};
|
|
5729
|
-
const propertiesId =
|
|
6077
|
+
const propertiesId = import_keys13.PublicKey.random().toHex();
|
|
5730
6078
|
document.change((doc) => {
|
|
5731
|
-
(0,
|
|
6079
|
+
(0, import_util11.assignDeep)(doc, [
|
|
5732
6080
|
"objects",
|
|
5733
6081
|
propertiesId
|
|
5734
6082
|
], properties);
|
|
@@ -5744,11 +6092,11 @@ _ts_decorate8([
|
|
|
5744
6092
|
import_tracing8.trace.info()
|
|
5745
6093
|
], ClientServicesHost.prototype, "_open", void 0);
|
|
5746
6094
|
_ts_decorate8([
|
|
5747
|
-
|
|
6095
|
+
import_async17.synchronized,
|
|
5748
6096
|
import_tracing8.trace.span()
|
|
5749
6097
|
], ClientServicesHost.prototype, "open", null);
|
|
5750
6098
|
_ts_decorate8([
|
|
5751
|
-
|
|
6099
|
+
import_async17.synchronized,
|
|
5752
6100
|
import_tracing8.trace.span()
|
|
5753
6101
|
], ClientServicesHost.prototype, "close", null);
|
|
5754
6102
|
ClientServicesHost = _ts_decorate8([
|
|
@@ -5761,7 +6109,7 @@ var DiagnosticsCollector = class {
|
|
|
5761
6109
|
}
|
|
5762
6110
|
static async collect(config = findConfigs(), services = findSystemServiceProvider(), options = {}) {
|
|
5763
6111
|
const serviceDiagnostics = await services?.services?.SystemService?.getDiagnostics({
|
|
5764
|
-
keys: options.humanize ?
|
|
6112
|
+
keys: options.humanize ? import_services15.GetDiagnosticsRequest.KEY_OPTION.HUMANIZE : options.truncate ? import_services15.GetDiagnosticsRequest.KEY_OPTION.TRUNCATE : void 0
|
|
5765
6113
|
});
|
|
5766
6114
|
const clientDiagnostics = {
|
|
5767
6115
|
config,
|
|
@@ -5774,7 +6122,7 @@ var DiagnosticsCollector = class {
|
|
|
5774
6122
|
client: clientDiagnostics,
|
|
5775
6123
|
broadcast: await this.broadcastSender.broadcastDiagnosticsRequest()
|
|
5776
6124
|
};
|
|
5777
|
-
return JSON.parse(JSON.stringify(diagnostics, (0,
|
|
6125
|
+
return JSON.parse(JSON.stringify(diagnostics, (0, import_util10.jsonKeyReplacer)(options)));
|
|
5778
6126
|
}
|
|
5779
6127
|
};
|
|
5780
6128
|
var findSystemServiceProvider = () => {
|
|
@@ -5784,7 +6132,7 @@ var findSystemServiceProvider = () => {
|
|
|
5784
6132
|
};
|
|
5785
6133
|
var findConfigs = () => {
|
|
5786
6134
|
const configs = import_tracing7.TRACE_PROCESSOR.findByAnnotation(import_config.ConfigResource);
|
|
5787
|
-
return configs.map((r) => r.instance.deref()).filter(
|
|
6135
|
+
return configs.map((r) => r.instance.deref()).filter(import_util10.nonNullable);
|
|
5788
6136
|
};
|
|
5789
6137
|
// Annotate the CommonJS export names for ESM import in node:
|
|
5790
6138
|
0 && (module.exports = {
|
|
@@ -5826,4 +6174,4 @@ var findConfigs = () => {
|
|
|
5826
6174
|
subscribeToSpaces,
|
|
5827
6175
|
subscribeToSwarmInfo
|
|
5828
6176
|
});
|
|
5829
|
-
//# sourceMappingURL=chunk-
|
|
6177
|
+
//# sourceMappingURL=chunk-4E7K7B6U.cjs.map
|