@dxos/client-services 0.6.12-main.15a606f → 0.6.12-main.2d19bf1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/dist/lib/browser/{chunk-BDGSOBZV.mjs → chunk-WU4ZS3F3.mjs} +1480 -842
  2. package/dist/lib/browser/chunk-WU4ZS3F3.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +1 -1
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/browser/testing/index.mjs +5 -3
  6. package/dist/lib/browser/testing/index.mjs.map +3 -3
  7. package/dist/lib/node/{chunk-EBZ7KFXS.cjs → chunk-LMQGWSYX.cjs} +1583 -949
  8. package/dist/lib/node/chunk-LMQGWSYX.cjs.map +7 -0
  9. package/dist/lib/node/index.cjs +45 -45
  10. package/dist/lib/node/meta.json +1 -1
  11. package/dist/lib/node/testing/index.cjs +11 -9
  12. package/dist/lib/node/testing/index.cjs.map +3 -3
  13. package/dist/lib/node-esm/{chunk-LDBJYNPL.mjs → chunk-HI7CKA67.mjs} +1470 -832
  14. package/dist/lib/node-esm/chunk-HI7CKA67.mjs.map +7 -0
  15. package/dist/lib/node-esm/index.mjs +1 -1
  16. package/dist/lib/node-esm/meta.json +1 -1
  17. package/dist/lib/node-esm/testing/index.mjs +5 -3
  18. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  19. package/dist/types/src/packlets/identity/authenticator.d.ts.map +1 -1
  20. package/dist/types/src/packlets/identity/contacts-service.d.ts +1 -1
  21. package/dist/types/src/packlets/identity/contacts-service.d.ts.map +1 -1
  22. package/dist/types/src/packlets/identity/identity.d.ts +1 -0
  23. package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
  24. package/dist/types/src/packlets/invitations/edge-invitation-handler.d.ts +30 -0
  25. package/dist/types/src/packlets/invitations/edge-invitation-handler.d.ts.map +1 -0
  26. package/dist/types/src/packlets/invitations/invitation-guest-extenstion.d.ts +2 -1
  27. package/dist/types/src/packlets/invitations/invitation-guest-extenstion.d.ts.map +1 -1
  28. package/dist/types/src/packlets/invitations/invitation-host-extension.d.ts +2 -1
  29. package/dist/types/src/packlets/invitations/invitation-host-extension.d.ts.map +1 -1
  30. package/dist/types/src/packlets/invitations/invitation-state.d.ts +19 -0
  31. package/dist/types/src/packlets/invitations/invitation-state.d.ts.map +1 -0
  32. package/dist/types/src/packlets/invitations/invitations-handler.d.ts +8 -8
  33. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  34. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
  35. package/dist/types/src/packlets/services/service-context.d.ts +6 -5
  36. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  37. package/dist/types/src/packlets/services/service-host.d.ts +1 -0
  38. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  39. package/dist/types/src/packlets/spaces/data-space-manager.d.ts +5 -1
  40. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  41. package/dist/types/src/packlets/spaces/data-space.d.ts +3 -1
  42. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  43. package/dist/types/src/packlets/spaces/edge-feed-replicator.d.ts +3 -0
  44. package/dist/types/src/packlets/spaces/edge-feed-replicator.d.ts.map +1 -1
  45. package/dist/types/src/packlets/spaces/edge-feed-replicator.test.d.ts +2 -0
  46. package/dist/types/src/packlets/spaces/edge-feed-replicator.test.d.ts.map +1 -0
  47. package/dist/types/src/packlets/spaces/notarization-plugin.d.ts +31 -6
  48. package/dist/types/src/packlets/spaces/notarization-plugin.d.ts.map +1 -1
  49. package/dist/types/src/packlets/spaces/spaces-service.d.ts +1 -1
  50. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  51. package/dist/types/src/version.d.ts +1 -1
  52. package/package.json +39 -38
  53. package/src/packlets/identity/authenticator.ts +5 -2
  54. package/src/packlets/identity/contacts-service.ts +1 -1
  55. package/src/packlets/identity/identity.test.ts +4 -0
  56. package/src/packlets/identity/identity.ts +4 -0
  57. package/src/packlets/invitations/edge-invitation-handler.ts +184 -0
  58. package/src/packlets/invitations/invitation-guest-extenstion.ts +8 -4
  59. package/src/packlets/invitations/invitation-host-extension.ts +8 -4
  60. package/src/packlets/invitations/invitation-state.ts +111 -0
  61. package/src/packlets/invitations/invitations-handler.test.ts +2 -2
  62. package/src/packlets/invitations/invitations-handler.ts +23 -92
  63. package/src/packlets/invitations/space-invitation-protocol.ts +4 -0
  64. package/src/packlets/services/service-context.ts +45 -20
  65. package/src/packlets/services/service-host.ts +7 -5
  66. package/src/packlets/spaces/data-space-manager.ts +36 -4
  67. package/src/packlets/spaces/data-space.ts +27 -4
  68. package/src/packlets/spaces/edge-feed-replicator.test.ts +253 -0
  69. package/src/packlets/spaces/edge-feed-replicator.ts +72 -19
  70. package/src/packlets/spaces/notarization-plugin.test.ts +8 -4
  71. package/src/packlets/spaces/notarization-plugin.ts +169 -29
  72. package/src/packlets/spaces/spaces-service.ts +6 -1
  73. package/src/packlets/testing/test-builder.ts +2 -2
  74. package/src/version.ts +1 -1
  75. package/dist/lib/browser/chunk-BDGSOBZV.mjs.map +0 -7
  76. package/dist/lib/node/chunk-EBZ7KFXS.cjs.map +0 -7
  77. package/dist/lib/node-esm/chunk-LDBJYNPL.mjs.map +0 -7
@@ -404,7 +404,7 @@ import { SpaceMember } from "@dxos/protocols/proto/dxos/client/services";
404
404
  import { TRACE_PROCESSOR } from "@dxos/tracing";
405
405
 
406
406
  // packages/sdk/client-services/src/version.ts
407
- var DXOS_VERSION = "0.6.12-main.15a606f";
407
+ var DXOS_VERSION = "0.6.12-main.2d19bf1";
408
408
 
409
409
  // packages/sdk/client-services/src/packlets/services/platform.ts
410
410
  import { Platform } from "@dxos/protocols/proto/dxos/client/services";
@@ -755,7 +755,7 @@ var TrustedKeySetAuthVerifier = class {
755
755
  return false;
756
756
  }
757
757
  if (this._isTrustedKey(credential.issuer)) {
758
- log3("key is not currently in trusted set, waiting...", {
758
+ log3("key is trusted -- auth success", {
759
759
  key: credential.issuer
760
760
  }, {
761
761
  F: __dxlog_file5,
@@ -782,7 +782,10 @@ var TrustedKeySetAuthVerifier = class {
782
782
  trigger.wake(true);
783
783
  } else {
784
784
  log3("key is not currently in trusted set, waiting...", {
785
- key: credential.issuer
785
+ key: credential.issuer,
786
+ trusted: [
787
+ ...this._params.trustedKeysProvider()
788
+ ]
786
789
  }, {
787
790
  F: __dxlog_file5,
788
791
  L: 84,
@@ -811,14 +814,21 @@ var TrustedKeySetAuthVerifier = class {
811
814
  // packages/sdk/client-services/src/packlets/spaces/edge-feed-replicator.ts
812
815
  import { decode as decodeCbor, encode as encodeCbor } from "cbor-x";
813
816
  import { Event, Mutex, scheduleMicroTask } from "@dxos/async";
814
- import { Resource } from "@dxos/context";
817
+ import { Context as Context3, Resource } from "@dxos/context";
818
+ import { EdgeConnectionClosedError, EdgeIdentityChangedError } from "@dxos/edge-client";
815
819
  import { invariant as invariant2 } from "@dxos/invariant";
816
820
  import { PublicKey as PublicKey3 } from "@dxos/keys";
817
- import { log as log4 } from "@dxos/log";
821
+ import { log as log4, logInfo } from "@dxos/log";
818
822
  import { EdgeService } from "@dxos/protocols";
819
823
  import { buf } from "@dxos/protocols/buf";
820
824
  import { MessageSchema as RouterMessageSchema } from "@dxos/protocols/buf/dxos/edge/messenger_pb";
821
825
  import { ComplexMap as ComplexMap2, arrayToBuffer, bufferToArray, defaultMap, rangeFromTo } from "@dxos/util";
826
+ function _ts_decorate(decorators, target, key, desc) {
827
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
828
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
829
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
830
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
831
+ }
822
832
  function _using_ctx() {
823
833
  var _disposeSuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed) {
824
834
  var err = new Error();
@@ -900,7 +910,13 @@ var EdgeFeedReplicator = class extends Resource {
900
910
  this._spaceId = spaceId;
901
911
  }
902
912
  async _open() {
903
- this._ctx.onDispose(this._messenger.addListener(async (message) => {
913
+ log4("open", void 0, {
914
+ F: __dxlog_file6,
915
+ L: 56,
916
+ S: this,
917
+ C: (f, a) => f(...a)
918
+ });
919
+ this._ctx.onDispose(this._messenger.addListener((message) => {
904
920
  if (!message.serviceId) {
905
921
  return;
906
922
  }
@@ -915,33 +931,65 @@ var EdgeFeedReplicator = class extends Resource {
915
931
  _spaceId: this._spaceId
916
932
  }, {
917
933
  F: __dxlog_file6,
918
- L: 62,
934
+ L: 70,
919
935
  S: this,
920
936
  C: (f, a) => f(...a)
921
937
  });
922
938
  return;
923
939
  }
924
940
  const payload = decodeCbor(message.payload.value);
925
- log4.info("receive", {
941
+ log4("receive", {
926
942
  from: message.source,
927
943
  feedKey: payload.feedKey,
928
944
  type: payload.type
929
945
  }, {
930
946
  F: __dxlog_file6,
931
- L: 67,
947
+ L: 75,
932
948
  S: this,
933
949
  C: (f, a) => f(...a)
934
950
  });
935
951
  this._onMessage(payload);
936
952
  }));
937
- this._connected = true;
938
- this._connectionCtx = this._ctx.derive();
939
- for (const feed of this._feeds.values()) {
940
- await this._replicateFeed(feed);
953
+ this._messenger.connected.on(this._ctx, async () => {
954
+ await this._resetConnection();
955
+ this._startReplication();
956
+ });
957
+ if (this._messenger.isConnected) {
958
+ this._startReplication();
941
959
  }
942
960
  }
943
961
  async _close() {
944
- this._connected = false;
962
+ log4("close", void 0, {
963
+ F: __dxlog_file6,
964
+ L: 91,
965
+ S: this,
966
+ C: (f, a) => f(...a)
967
+ });
968
+ await this._resetConnection();
969
+ }
970
+ _startReplication() {
971
+ this._connected = true;
972
+ const connectionCtx = this._createConnectionContext();
973
+ this._connectionCtx = connectionCtx;
974
+ log4("connection context created", void 0, {
975
+ F: __dxlog_file6,
976
+ L: 99,
977
+ S: this,
978
+ C: (f, a) => f(...a)
979
+ });
980
+ scheduleMicroTask(connectionCtx, async () => {
981
+ for (const feed of this._feeds.values()) {
982
+ await this._replicateFeed(connectionCtx, feed);
983
+ }
984
+ });
985
+ }
986
+ async _resetConnection() {
987
+ log4("resetConnection", void 0, {
988
+ F: __dxlog_file6,
989
+ L: 108,
990
+ S: this,
991
+ C: (f, a) => f(...a)
992
+ });
945
993
  this._connected = false;
946
994
  await this._connectionCtx?.dispose();
947
995
  this._connectionCtx = void 0;
@@ -949,40 +997,50 @@ var EdgeFeedReplicator = class extends Resource {
949
997
  }
950
998
  async addFeed(feed) {
951
999
  log4.info("addFeed", {
952
- key: feed.key
1000
+ key: feed.key,
1001
+ connected: this._connected,
1002
+ hasConnectionCtx: !!this._connectionCtx
953
1003
  }, {
954
1004
  F: __dxlog_file6,
955
- L: 89,
1005
+ L: 116,
956
1006
  S: this,
957
1007
  C: (f, a) => f(...a)
958
1008
  });
959
1009
  this._feeds.set(feed.key, feed);
960
- if (this._connected) {
961
- await this._replicateFeed(feed);
1010
+ if (this._connected && this._connectionCtx) {
1011
+ await this._replicateFeed(this._connectionCtx, feed);
962
1012
  }
963
1013
  }
964
1014
  _getPushMutex(key) {
965
1015
  return defaultMap(this._pushMutex, key, () => new Mutex());
966
1016
  }
967
- async _replicateFeed(feed) {
968
- invariant2(this._connectionCtx, void 0, {
1017
+ async _replicateFeed(ctx, feed) {
1018
+ log4("replicateFeed", {
1019
+ key: feed.key
1020
+ }, {
969
1021
  F: __dxlog_file6,
970
- L: 102,
1022
+ L: 129,
971
1023
  S: this,
972
- A: [
973
- "this._connectionCtx",
974
- ""
975
- ]
1024
+ C: (f, a) => f(...a)
976
1025
  });
977
1026
  await this._sendMessage({
978
1027
  type: "get-metadata",
979
1028
  feedKey: feed.key.toHex()
980
1029
  });
981
- Event.wrap(feed.core, "append").on(this._connectionCtx, async () => {
1030
+ Event.wrap(feed.core, "append").on(ctx, async () => {
982
1031
  await this._pushBlocksIfNeeded(feed);
983
1032
  });
984
1033
  }
985
1034
  async _sendMessage(message) {
1035
+ if (!this._connectionCtx) {
1036
+ log4.info("message dropped because connection was disposed", void 0, {
1037
+ F: __dxlog_file6,
1038
+ L: 142,
1039
+ S: this,
1040
+ C: (f, a) => f(...a)
1041
+ });
1042
+ return;
1043
+ }
986
1044
  const logPayload = message.type === "data" ? {
987
1045
  feedKey: message.feedKey,
988
1046
  blocks: message.blocks.map((b) => b.index)
@@ -991,13 +1049,13 @@ var EdgeFeedReplicator = class extends Resource {
991
1049
  };
992
1050
  log4.info("sending message", logPayload, {
993
1051
  F: __dxlog_file6,
994
- L: 117,
1052
+ L: 148,
995
1053
  S: this,
996
1054
  C: (f, a) => f(...a)
997
1055
  });
998
1056
  invariant2(message.feedKey, void 0, {
999
1057
  F: __dxlog_file6,
1000
- L: 119,
1058
+ L: 150,
1001
1059
  S: this,
1002
1060
  A: [
1003
1061
  "message.feedKey",
@@ -1005,6 +1063,14 @@ var EdgeFeedReplicator = class extends Resource {
1005
1063
  ]
1006
1064
  });
1007
1065
  const payloadValue = bufferToArray(encodeCbor(message));
1066
+ log4("send", {
1067
+ type: message.type
1068
+ }, {
1069
+ F: __dxlog_file6,
1070
+ L: 153,
1071
+ S: this,
1072
+ C: (f, a) => f(...a)
1073
+ });
1008
1074
  await this._messenger.send(buf.create(RouterMessageSchema, {
1009
1075
  source: {
1010
1076
  identityKey: this._messenger.identityKey,
@@ -1017,7 +1083,16 @@ var EdgeFeedReplicator = class extends Resource {
1017
1083
  }));
1018
1084
  }
1019
1085
  _onMessage(message) {
1020
- scheduleMicroTask(this._ctx, async () => {
1086
+ if (!this._connectionCtx) {
1087
+ log4.warn("received message after connection context was disposed", void 0, {
1088
+ F: __dxlog_file6,
1089
+ L: 168,
1090
+ S: this,
1091
+ C: (f, a) => f(...a)
1092
+ });
1093
+ return;
1094
+ }
1095
+ scheduleMicroTask(this._connectionCtx, async () => {
1021
1096
  switch (message.type) {
1022
1097
  case "metadata": {
1023
1098
  try {
@@ -1026,7 +1101,7 @@ var EdgeFeedReplicator = class extends Resource {
1026
1101
  message
1027
1102
  }, {
1028
1103
  F: __dxlog_file6,
1029
- L: 138,
1104
+ L: 174,
1030
1105
  S: this,
1031
1106
  C: (f, a) => f(...a)
1032
1107
  });
@@ -1037,7 +1112,7 @@ var EdgeFeedReplicator = class extends Resource {
1037
1112
  feedKey
1038
1113
  }, {
1039
1114
  F: __dxlog_file6,
1040
- L: 143,
1115
+ L: 179,
1041
1116
  S: this,
1042
1117
  C: (f, a) => f(...a)
1043
1118
  });
@@ -1070,7 +1145,7 @@ var EdgeFeedReplicator = class extends Resource {
1070
1145
  blocks: message.blocks.map((b) => b.index)
1071
1146
  }, {
1072
1147
  F: __dxlog_file6,
1073
- L: 165,
1148
+ L: 201,
1074
1149
  S: this,
1075
1150
  C: (f, a) => f(...a)
1076
1151
  });
@@ -1081,7 +1156,7 @@ var EdgeFeedReplicator = class extends Resource {
1081
1156
  feedKey
1082
1157
  }, {
1083
1158
  F: __dxlog_file6,
1084
- L: 170,
1159
+ L: 206,
1085
1160
  S: this,
1086
1161
  C: (f, a) => f(...a)
1087
1162
  });
@@ -1095,7 +1170,7 @@ var EdgeFeedReplicator = class extends Resource {
1095
1170
  ...message
1096
1171
  }, {
1097
1172
  F: __dxlog_file6,
1098
- L: 179,
1173
+ L: 215,
1099
1174
  S: this,
1100
1175
  C: (f, a) => f(...a)
1101
1176
  });
@@ -1110,7 +1185,7 @@ var EdgeFeedReplicator = class extends Resource {
1110
1185
  to
1111
1186
  }, {
1112
1187
  F: __dxlog_file6,
1113
- L: 186,
1188
+ L: 222,
1114
1189
  S: this,
1115
1190
  C: (f, a) => f(...a)
1116
1191
  });
@@ -1120,7 +1195,7 @@ var EdgeFeedReplicator = class extends Resource {
1120
1195
  });
1121
1196
  invariant2(data instanceof Uint8Array, void 0, {
1122
1197
  F: __dxlog_file6,
1123
- L: 191,
1198
+ L: 227,
1124
1199
  S: this,
1125
1200
  A: [
1126
1201
  "data instanceof Uint8Array",
@@ -1148,7 +1223,7 @@ var EdgeFeedReplicator = class extends Resource {
1148
1223
  blocks: blocks.length
1149
1224
  }, {
1150
1225
  F: __dxlog_file6,
1151
- L: 212,
1226
+ L: 248,
1152
1227
  S: this,
1153
1228
  C: (f, a) => f(...a)
1154
1229
  });
@@ -1166,11 +1241,11 @@ var EdgeFeedReplicator = class extends Resource {
1166
1241
  async _pushBlocksIfNeeded(feed) {
1167
1242
  try {
1168
1243
  var _usingCtx = _using_ctx();
1169
- const _guard = _usingCtx.u(await this._getPushMutex(feed.key).acquire());
1244
+ const _ = _usingCtx.u(await this._getPushMutex(feed.key).acquire());
1170
1245
  if (!this._remoteLength.has(feed.key)) {
1171
1246
  log4("blocks not pushed because remote length is unknown", void 0, {
1172
1247
  F: __dxlog_file6,
1173
- L: 233,
1248
+ L: 269,
1174
1249
  S: this,
1175
1250
  C: (f, a) => f(...a)
1176
1251
  });
@@ -1186,7 +1261,34 @@ var EdgeFeedReplicator = class extends Resource {
1186
1261
  _usingCtx.d();
1187
1262
  }
1188
1263
  }
1264
+ _createConnectionContext() {
1265
+ const connectionCtx = new Context3({
1266
+ onError: async (err) => {
1267
+ if (connectionCtx !== this._connectionCtx) {
1268
+ return;
1269
+ }
1270
+ if (err instanceof EdgeIdentityChangedError || err instanceof EdgeConnectionClosedError) {
1271
+ log4("resetting on reconnect", void 0, {
1272
+ F: __dxlog_file6,
1273
+ L: 286,
1274
+ S: this,
1275
+ C: (f, a) => f(...a)
1276
+ });
1277
+ await this._resetConnection();
1278
+ } else {
1279
+ this._ctx.raise(err);
1280
+ }
1281
+ }
1282
+ }, {
1283
+ F: __dxlog_file6,
1284
+ L: 280
1285
+ });
1286
+ return connectionCtx;
1287
+ }
1189
1288
  };
1289
+ _ts_decorate([
1290
+ logInfo
1291
+ ], EdgeFeedReplicator.prototype, "_spaceId", void 0);
1190
1292
  var bufferizeBlock = (block) => ({
1191
1293
  index: block.index,
1192
1294
  data: arrayToBuffer(block.data),
@@ -1436,53 +1538,67 @@ var runEpochMigration = async (ctx, context) => {
1436
1538
  };
1437
1539
 
1438
1540
  // packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
1439
- import { DeferredTask, Event as Event3, scheduleTask as scheduleTask2, sleep, TimeoutError, Trigger as Trigger3 } from "@dxos/async";
1440
- import { Context as Context3, rejectOnDispose } from "@dxos/context";
1541
+ import { DeferredTask, Event as Event3, scheduleTask as scheduleTask2, sleep, TimeoutError, Trigger as Trigger3, scheduleMicroTask as scheduleMicroTask2 } from "@dxos/async";
1542
+ import { rejectOnDispose, Resource as Resource3 } from "@dxos/context";
1543
+ import { verifyCredential as verifyCredential2 } from "@dxos/credentials";
1441
1544
  import { invariant as invariant4 } from "@dxos/invariant";
1442
1545
  import { PublicKey as PublicKey4 } from "@dxos/keys";
1443
- import { log as log6 } from "@dxos/log";
1546
+ import { logInfo as logInfo2, log as log6 } from "@dxos/log";
1547
+ import { EdgeCallFailedError } from "@dxos/protocols";
1444
1548
  import { schema as schema2 } from "@dxos/protocols/proto";
1445
1549
  import { RpcExtension } from "@dxos/teleport";
1446
1550
  import { ComplexMap as ComplexMap3, ComplexSet, entry } from "@dxos/util";
1551
+ function _ts_decorate2(decorators, target, key, desc) {
1552
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1553
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1554
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1555
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1556
+ }
1447
1557
  var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
1448
1558
  var DEFAULT_RETRY_TIMEOUT = 1e3;
1449
1559
  var DEFAULT_SUCCESS_DELAY = 1e3;
1450
1560
  var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
1561
+ var MAX_EDGE_RETRIES = 2;
1451
1562
  var WRITER_NOT_SET_ERROR_CODE = "WRITER_NOT_SET";
1452
- var NotarizationPlugin = class {
1453
- constructor() {
1454
- this._ctx = new Context3(void 0, {
1455
- F: __dxlog_file8,
1456
- L: 62
1457
- });
1563
+ var credentialCodec = schema2.getCodecForType("dxos.halo.credentials.Credential");
1564
+ var NotarizationPlugin = class extends Resource3 {
1565
+ constructor(params) {
1566
+ super();
1458
1567
  this._extensionOpened = new Event3();
1459
1568
  this._extensions = /* @__PURE__ */ new Set();
1460
1569
  this._processedCredentials = new ComplexSet(PublicKey4.hash);
1461
1570
  this._processCredentialsTriggers = new ComplexMap3(PublicKey4.hash);
1571
+ this._spaceId = params.spaceId;
1572
+ if (params.edgeClient && params.edgeFeatures?.feedReplicator) {
1573
+ this._edgeClient = params.edgeClient;
1574
+ }
1462
1575
  }
1463
1576
  get hasWriter() {
1464
1577
  return !!this._writer;
1465
1578
  }
1466
- async open() {
1579
+ async _open() {
1580
+ if (this._edgeClient && this._writer) {
1581
+ this._notarizePendingEdgeCredentials(this._edgeClient, this._writer);
1582
+ }
1467
1583
  }
1468
- async close() {
1584
+ async _close() {
1469
1585
  await this._ctx.dispose();
1470
1586
  }
1471
1587
  /**
1472
1588
  * Request credentials to be notarized.
1473
1589
  */
1474
- async notarize({ ctx: opCtx, credentials, timeout = DEFAULT_NOTARIZE_TIMEOUT, retryTimeout = DEFAULT_RETRY_TIMEOUT, successDelay = DEFAULT_SUCCESS_DELAY }) {
1590
+ async notarize({ ctx: opCtx, credentials, timeout = DEFAULT_NOTARIZE_TIMEOUT, retryTimeout = DEFAULT_RETRY_TIMEOUT, successDelay = DEFAULT_SUCCESS_DELAY, edgeRetryJitter }) {
1475
1591
  log6("notarize", {
1476
1592
  credentials
1477
1593
  }, {
1478
1594
  F: __dxlog_file8,
1479
- L: 90,
1595
+ L: 126,
1480
1596
  S: this,
1481
1597
  C: (f, a) => f(...a)
1482
1598
  });
1483
1599
  invariant4(credentials.every((credential) => credential.id), "Credentials must have an id", {
1484
1600
  F: __dxlog_file8,
1485
- L: 91,
1601
+ L: 127,
1486
1602
  S: this,
1487
1603
  A: [
1488
1604
  "credentials.every((credential) => credential.id)",
@@ -1496,7 +1612,7 @@ var NotarizationPlugin = class {
1496
1612
  err
1497
1613
  }, {
1498
1614
  F: __dxlog_file8,
1499
- L: 99,
1615
+ L: 135,
1500
1616
  S: this,
1501
1617
  C: (f, a) => f(...a)
1502
1618
  });
@@ -1506,21 +1622,37 @@ var NotarizationPlugin = class {
1506
1622
  });
1507
1623
  opCtx?.onDispose(() => ctx.dispose());
1508
1624
  if (timeout !== 0) {
1509
- scheduleTask2(ctx, () => {
1510
- log6.warn("Notarization timeout", {
1511
- timeout,
1512
- peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
1513
- }, {
1514
- F: __dxlog_file8,
1515
- L: 111,
1516
- S: this,
1517
- C: (f, a) => f(...a)
1518
- });
1519
- void ctx.dispose();
1520
- errors.throw(new TimeoutError(timeout, "Notarization timed out"));
1521
- }, timeout);
1625
+ this._scheduleTimeout(ctx, errors, timeout);
1522
1626
  }
1523
1627
  const allNotarized = Promise.all(credentials.map((credential) => this._waitUntilProcessed(credential.id)));
1628
+ this._tryNotarizeCredentialsWithPeers(ctx, credentials, {
1629
+ retryTimeout,
1630
+ successDelay
1631
+ });
1632
+ if (this._edgeClient) {
1633
+ this._tryNotarizeCredentialsWithEdge(ctx, this._edgeClient, credentials, {
1634
+ retryTimeout,
1635
+ successDelay,
1636
+ jitter: edgeRetryJitter
1637
+ });
1638
+ }
1639
+ try {
1640
+ await Promise.race([
1641
+ rejectOnDispose(ctx),
1642
+ allNotarized,
1643
+ errors.wait()
1644
+ ]);
1645
+ log6("done", void 0, {
1646
+ F: __dxlog_file8,
1647
+ L: 160,
1648
+ S: this,
1649
+ C: (f, a) => f(...a)
1650
+ });
1651
+ } finally {
1652
+ await ctx.dispose();
1653
+ }
1654
+ }
1655
+ _tryNotarizeCredentialsWithPeers(ctx, credentials, { retryTimeout, successDelay }) {
1524
1656
  const peersTried = /* @__PURE__ */ new Set();
1525
1657
  const notarizeTask = new DeferredTask(ctx, async () => {
1526
1658
  try {
@@ -1535,7 +1667,7 @@ var NotarizationPlugin = class {
1535
1667
  retryIn: retryTimeout
1536
1668
  }, {
1537
1669
  F: __dxlog_file8,
1538
- L: 136,
1670
+ L: 183,
1539
1671
  S: this,
1540
1672
  C: (f, a) => f(...a)
1541
1673
  });
@@ -1549,7 +1681,7 @@ var NotarizationPlugin = class {
1549
1681
  credentialId: credentials.map((credential) => credential.id)
1550
1682
  }, {
1551
1683
  F: __dxlog_file8,
1552
- L: 143,
1684
+ L: 190,
1553
1685
  S: this,
1554
1686
  C: (f, a) => f(...a)
1555
1687
  });
@@ -1558,7 +1690,7 @@ var NotarizationPlugin = class {
1558
1690
  });
1559
1691
  log6("success", void 0, {
1560
1692
  F: __dxlog_file8,
1561
- L: 147,
1693
+ L: 194,
1562
1694
  S: this,
1563
1695
  C: (f, a) => f(...a)
1564
1696
  });
@@ -1567,7 +1699,7 @@ var NotarizationPlugin = class {
1567
1699
  if (!ctx.disposed && !err.message.includes(WRITER_NOT_SET_ERROR_CODE)) {
1568
1700
  log6.info("error notarizing (recoverable)", err, {
1569
1701
  F: __dxlog_file8,
1570
- L: 151,
1702
+ L: 199,
1571
1703
  S: this,
1572
1704
  C: (f, a) => f(...a)
1573
1705
  });
@@ -1577,21 +1709,33 @@ var NotarizationPlugin = class {
1577
1709
  });
1578
1710
  notarizeTask.schedule();
1579
1711
  this._extensionOpened.on(ctx, () => notarizeTask.schedule());
1580
- try {
1581
- await Promise.race([
1582
- rejectOnDispose(ctx),
1583
- allNotarized,
1584
- errors.wait()
1585
- ]);
1586
- log6("done", void 0, {
1587
- F: __dxlog_file8,
1588
- L: 162,
1589
- S: this,
1590
- C: (f, a) => f(...a)
1591
- });
1592
- } finally {
1593
- await ctx.dispose();
1594
- }
1712
+ }
1713
+ _tryNotarizeCredentialsWithEdge(ctx, client, credentials, timeouts) {
1714
+ const encodedCredentials = credentials.map((credential) => {
1715
+ const binary = credentialCodec.encode(credential);
1716
+ return Buffer.from(binary).toString("base64");
1717
+ });
1718
+ scheduleTask2(ctx, async () => {
1719
+ try {
1720
+ await client.notarizeCredentials(this._spaceId, {
1721
+ credentials: encodedCredentials
1722
+ }, {
1723
+ retry: {
1724
+ count: MAX_EDGE_RETRIES,
1725
+ timeout: timeouts.retryTimeout,
1726
+ jitter: timeouts.jitter
1727
+ }
1728
+ });
1729
+ log6("edge notarization success", void 0, {
1730
+ F: __dxlog_file8,
1731
+ L: 227,
1732
+ S: this,
1733
+ C: (f, a) => f(...a)
1734
+ });
1735
+ } catch (error) {
1736
+ handleEdgeError(error);
1737
+ }
1738
+ });
1595
1739
  }
1596
1740
  /**
1597
1741
  * Called with credentials arriving from the control pipeline.
@@ -1607,7 +1751,7 @@ var NotarizationPlugin = class {
1607
1751
  setWriter(writer) {
1608
1752
  invariant4(!this._writer, "Writer already set.", {
1609
1753
  F: __dxlog_file8,
1610
- L: 181,
1754
+ L: 247,
1611
1755
  S: this,
1612
1756
  A: [
1613
1757
  "!this._writer",
@@ -1615,6 +1759,59 @@ var NotarizationPlugin = class {
1615
1759
  ]
1616
1760
  });
1617
1761
  this._writer = writer;
1762
+ if (this._edgeClient) {
1763
+ this._notarizePendingEdgeCredentials(this._edgeClient, writer);
1764
+ }
1765
+ }
1766
+ /**
1767
+ * The method is used only for adding agent feeds to spaces.
1768
+ * When an agent is created we can admit them into all the existing spaces. In case the operation fails
1769
+ * this method will fix it on the next space open.
1770
+ * Given how rarely this happens there's no need to poll the endpoint.
1771
+ */
1772
+ _notarizePendingEdgeCredentials(client, writer) {
1773
+ scheduleMicroTask2(this._ctx, async () => {
1774
+ try {
1775
+ const response = await client.getCredentialsForNotarization(this._spaceId, {
1776
+ retry: {
1777
+ count: MAX_EDGE_RETRIES
1778
+ }
1779
+ });
1780
+ const credentials = response.awaitingNotarization.credentials;
1781
+ if (!credentials.length) {
1782
+ log6("edge did not return credentials for notarization", void 0, {
1783
+ F: __dxlog_file8,
1784
+ L: 269,
1785
+ S: this,
1786
+ C: (f, a) => f(...a)
1787
+ });
1788
+ return;
1789
+ }
1790
+ log6("got edge credentials for notarization", {
1791
+ count: credentials.length
1792
+ }, {
1793
+ F: __dxlog_file8,
1794
+ L: 273,
1795
+ S: this,
1796
+ C: (f, a) => f(...a)
1797
+ });
1798
+ const decodedCredentials = credentials.map((credential) => {
1799
+ const binary = Buffer.from(credential, "base64");
1800
+ return credentialCodec.decode(binary);
1801
+ });
1802
+ await this._notarizeCredentials(writer, decodedCredentials);
1803
+ log6.info("notarized edge credentials", {
1804
+ count: decodedCredentials.length
1805
+ }, {
1806
+ F: __dxlog_file8,
1807
+ L: 282,
1808
+ S: this,
1809
+ C: (f, a) => f(...a)
1810
+ });
1811
+ } catch (error) {
1812
+ handleEdgeError(error);
1813
+ }
1814
+ });
1618
1815
  }
1619
1816
  async _waitUntilProcessed(id) {
1620
1817
  if (this._processedCredentials.has(id)) {
@@ -1629,10 +1826,13 @@ var NotarizationPlugin = class {
1629
1826
  if (!this._writer) {
1630
1827
  throw new Error(WRITER_NOT_SET_ERROR_CODE);
1631
1828
  }
1632
- for (const credential of request.credentials ?? []) {
1829
+ await this._notarizeCredentials(this._writer, request.credentials ?? []);
1830
+ }
1831
+ async _notarizeCredentials(writer, credentials) {
1832
+ for (const credential of credentials) {
1633
1833
  invariant4(credential.id, "Credential must have an id", {
1634
1834
  F: __dxlog_file8,
1635
- L: 200,
1835
+ L: 308,
1636
1836
  S: this,
1637
1837
  A: [
1638
1838
  "credential.id",
@@ -1642,7 +1842,11 @@ var NotarizationPlugin = class {
1642
1842
  if (this._processedCredentials.has(credential.id)) {
1643
1843
  continue;
1644
1844
  }
1645
- await this._writer.write(credential);
1845
+ const verificationResult = await verifyCredential2(credential);
1846
+ if (verificationResult.kind === "fail") {
1847
+ throw new Error(`Credential verification failed: ${verificationResult.errors.join("\n")}.`);
1848
+ }
1849
+ await writer.write(credential);
1646
1850
  }
1647
1851
  }
1648
1852
  createExtension() {
@@ -1652,7 +1856,7 @@ var NotarizationPlugin = class {
1652
1856
  peer: extension.localPeerId
1653
1857
  }, {
1654
1858
  F: __dxlog_file8,
1655
- L: 211,
1859
+ L: 323,
1656
1860
  S: this,
1657
1861
  C: (f, a) => f(...a)
1658
1862
  });
@@ -1664,7 +1868,7 @@ var NotarizationPlugin = class {
1664
1868
  peer: extension.localPeerId
1665
1869
  }, {
1666
1870
  F: __dxlog_file8,
1667
- L: 216,
1871
+ L: 328,
1668
1872
  S: this,
1669
1873
  C: (f, a) => f(...a)
1670
1874
  });
@@ -1674,6 +1878,43 @@ var NotarizationPlugin = class {
1674
1878
  });
1675
1879
  return extension;
1676
1880
  }
1881
+ _scheduleTimeout(ctx, errors, timeout) {
1882
+ scheduleTask2(ctx, () => {
1883
+ log6.warn("Notarization timeout", {
1884
+ timeout,
1885
+ peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
1886
+ }, {
1887
+ F: __dxlog_file8,
1888
+ L: 340,
1889
+ S: this,
1890
+ C: (f, a) => f(...a)
1891
+ });
1892
+ void ctx.dispose();
1893
+ errors.throw(new TimeoutError(timeout, "Notarization timed out"));
1894
+ }, timeout);
1895
+ }
1896
+ };
1897
+ _ts_decorate2([
1898
+ logInfo2
1899
+ ], NotarizationPlugin.prototype, "_spaceId", void 0);
1900
+ var handleEdgeError = (error) => {
1901
+ if (!(error instanceof EdgeCallFailedError) || error.errorData) {
1902
+ log6.catch(error, void 0, {
1903
+ F: __dxlog_file8,
1904
+ L: 354,
1905
+ S: void 0,
1906
+ C: (f, a) => f(...a)
1907
+ });
1908
+ } else {
1909
+ log6.info("Edge notarization failure", {
1910
+ reason: error.reason
1911
+ }, {
1912
+ F: __dxlog_file8,
1913
+ L: 356,
1914
+ S: void 0,
1915
+ C: (f, a) => f(...a)
1916
+ });
1917
+ }
1677
1918
  };
1678
1919
  var NotarizationTeleportExtension = class extends RpcExtension {
1679
1920
  constructor(_params) {
@@ -1768,7 +2009,7 @@ var DefaultSpaceStateMachine = class {
1768
2009
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
1769
2010
  import { Event as Event4, synchronized, trackLeaks } from "@dxos/async";
1770
2011
  import { PropertiesType } from "@dxos/client-protocol";
1771
- import { LifecycleState, Resource as Resource3, cancelWithContext } from "@dxos/context";
2012
+ import { LifecycleState, Resource as Resource4, cancelWithContext } from "@dxos/context";
1772
2013
  import { createAdmissionCredentials, getCredentialAssertion as getCredentialAssertion2 } from "@dxos/credentials";
1773
2014
  import { convertLegacyReferences as convertLegacyReferences2, findInlineObjectOfType as findInlineObjectOfType2, AuthStatus, CredentialServerExtension } from "@dxos/echo-pipeline";
1774
2015
  import { LEGACY_TYPE_PROPERTIES, SpaceDocVersion as SpaceDocVersion2, encodeReference } from "@dxos/echo-protocol";
@@ -1779,6 +2020,7 @@ import { PublicKey as PublicKey5 } from "@dxos/keys";
1779
2020
  import { log as log8 } from "@dxos/log";
1780
2021
  import { AlreadyJoinedError, trace as Trace } from "@dxos/protocols";
1781
2022
  import { Invitation, SpaceState } from "@dxos/protocols/proto/dxos/client/services";
2023
+ import { EdgeReplicationSetting } from "@dxos/protocols/proto/dxos/echo/metadata";
1782
2024
  import { SpaceMember as SpaceMember3 } from "@dxos/protocols/proto/dxos/halo/credentials";
1783
2025
  import { Gossip, Presence } from "@dxos/teleport-extension-gossip";
1784
2026
  import { trace } from "@dxos/tracing";
@@ -1855,7 +2097,7 @@ var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
1855
2097
  };
1856
2098
 
1857
2099
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
1858
- function _ts_decorate(decorators, target, key, desc) {
2100
+ function _ts_decorate3(decorators, target, key, desc) {
1859
2101
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1860
2102
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1861
2103
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
@@ -1865,13 +2107,14 @@ var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/s
1865
2107
  var PRESENCE_ANNOUNCE_INTERVAL = 1e4;
1866
2108
  var PRESENCE_OFFLINE_TIMEOUT = 2e4;
1867
2109
  var DEFAULT_SPACE_KEY = "__DEFAULT__";
1868
- var DataSpaceManager = class extends Resource3 {
2110
+ var DataSpaceManager = class extends Resource4 {
1869
2111
  constructor(params) {
1870
2112
  super();
1871
2113
  this.updated = new Event4();
1872
2114
  this._spaces = new ComplexMap4(PublicKey5.hash);
1873
2115
  this._instanceId = PublicKey5.random().toHex();
1874
2116
  this._edgeConnection = void 0;
2117
+ this._edgeHttpClient = void 0;
1875
2118
  this._edgeFeatures = void 0;
1876
2119
  this._meshReplicator = void 0;
1877
2120
  this._echoEdgeReplicator = void 0;
@@ -1887,6 +2130,7 @@ var DataSpaceManager = class extends Resource3 {
1887
2130
  this._edgeConnection = params.edgeConnection;
1888
2131
  this._edgeFeatures = params.edgeFeatures;
1889
2132
  this._echoEdgeReplicator = params.echoEdgeReplicator;
2133
+ this._edgeHttpClient = params.edgeHttpClient;
1890
2134
  this._runtimeParams = params.runtimeParams;
1891
2135
  trace.diagnostic({
1892
2136
  id: "spaces",
@@ -1918,7 +2162,7 @@ var DataSpaceManager = class extends Resource3 {
1918
2162
  async _open() {
1919
2163
  log8("open", void 0, {
1920
2164
  F: __dxlog_file10,
1921
- L: 195,
2165
+ L: 198,
1922
2166
  S: this,
1923
2167
  C: (f, a) => f(...a)
1924
2168
  });
@@ -1926,7 +2170,7 @@ var DataSpaceManager = class extends Resource3 {
1926
2170
  id: this._instanceId
1927
2171
  }), {
1928
2172
  F: __dxlog_file10,
1929
- L: 196,
2173
+ L: 199,
1930
2174
  S: this,
1931
2175
  C: (f, a) => f(...a)
1932
2176
  });
@@ -1934,7 +2178,7 @@ var DataSpaceManager = class extends Resource3 {
1934
2178
  spaces: this._metadataStore.spaces.length
1935
2179
  }, {
1936
2180
  F: __dxlog_file10,
1937
- L: 197,
2181
+ L: 200,
1938
2182
  S: this,
1939
2183
  C: (f, a) => f(...a)
1940
2184
  });
@@ -1944,7 +2188,7 @@ var DataSpaceManager = class extends Resource3 {
1944
2188
  spaceMetadata
1945
2189
  }, {
1946
2190
  F: __dxlog_file10,
1947
- L: 201,
2191
+ L: 204,
1948
2192
  S: this,
1949
2193
  C: (f, a) => f(...a)
1950
2194
  });
@@ -1955,7 +2199,7 @@ var DataSpaceManager = class extends Resource3 {
1955
2199
  err
1956
2200
  }, {
1957
2201
  F: __dxlog_file10,
1958
- L: 204,
2202
+ L: 207,
1959
2203
  S: this,
1960
2204
  C: (f, a) => f(...a)
1961
2205
  });
@@ -1966,7 +2210,7 @@ var DataSpaceManager = class extends Resource3 {
1966
2210
  id: this._instanceId
1967
2211
  }), {
1968
2212
  F: __dxlog_file10,
1969
- L: 210,
2213
+ L: 213,
1970
2214
  S: this,
1971
2215
  C: (f, a) => f(...a)
1972
2216
  });
@@ -1974,7 +2218,7 @@ var DataSpaceManager = class extends Resource3 {
1974
2218
  async _close() {
1975
2219
  log8("close", void 0, {
1976
2220
  F: __dxlog_file10,
1977
- L: 215,
2221
+ L: 218,
1978
2222
  S: this,
1979
2223
  C: (f, a) => f(...a)
1980
2224
  });
@@ -1989,7 +2233,7 @@ var DataSpaceManager = class extends Resource3 {
1989
2233
  async createSpace() {
1990
2234
  invariant5(this._lifecycleState === LifecycleState.OPEN, "Not open.", {
1991
2235
  F: __dxlog_file10,
1992
- L: 227,
2236
+ L: 230,
1993
2237
  S: this,
1994
2238
  A: [
1995
2239
  "this._lifecycleState === LifecycleState.OPEN",
@@ -2010,7 +2254,7 @@ var DataSpaceManager = class extends Resource3 {
2010
2254
  spaceKey
2011
2255
  }, {
2012
2256
  F: __dxlog_file10,
2013
- L: 239,
2257
+ L: 242,
2014
2258
  S: this,
2015
2259
  C: (f, a) => f(...a)
2016
2260
  });
@@ -2022,7 +2266,7 @@ var DataSpaceManager = class extends Resource3 {
2022
2266
  const memberCredential = credentials[1];
2023
2267
  invariant5(getCredentialAssertion2(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2024
2268
  F: __dxlog_file10,
2025
- L: 249,
2269
+ L: 252,
2026
2270
  S: this,
2027
2271
  A: [
2028
2272
  "getCredentialAssertion(memberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2054,7 +2298,7 @@ var DataSpaceManager = class extends Resource3 {
2054
2298
  spaceId: space.id
2055
2299
  }, {
2056
2300
  F: __dxlog_file10,
2057
- L: 274,
2301
+ L: 277,
2058
2302
  S: this,
2059
2303
  C: (f, a) => f(...a)
2060
2304
  });
@@ -2089,7 +2333,7 @@ var DataSpaceManager = class extends Resource3 {
2089
2333
  const automergeIndex = space.automergeSpaceState.rootUrl;
2090
2334
  invariant5(automergeIndex, void 0, {
2091
2335
  F: __dxlog_file10,
2092
- L: 307,
2336
+ L: 310,
2093
2337
  S: this,
2094
2338
  A: [
2095
2339
  "automergeIndex",
@@ -2106,13 +2350,13 @@ var DataSpaceManager = class extends Resource3 {
2106
2350
  opts
2107
2351
  }, {
2108
2352
  F: __dxlog_file10,
2109
- L: 316,
2353
+ L: 319,
2110
2354
  S: this,
2111
2355
  C: (f, a) => f(...a)
2112
2356
  });
2113
2357
  invariant5(this._lifecycleState === LifecycleState.OPEN, "Not open.", {
2114
2358
  F: __dxlog_file10,
2115
- L: 317,
2359
+ L: 320,
2116
2360
  S: this,
2117
2361
  A: [
2118
2362
  "this._lifecycleState === LifecycleState.OPEN",
@@ -2121,7 +2365,7 @@ var DataSpaceManager = class extends Resource3 {
2121
2365
  });
2122
2366
  invariant5(!this._spaces.has(opts.spaceKey), "Space already exists.", {
2123
2367
  F: __dxlog_file10,
2124
- L: 318,
2368
+ L: 321,
2125
2369
  S: this,
2126
2370
  A: [
2127
2371
  "!this._spaces.has(opts.spaceKey)",
@@ -2145,7 +2389,7 @@ var DataSpaceManager = class extends Resource3 {
2145
2389
  const space = this._spaceManager.spaces.get(options.spaceKey);
2146
2390
  invariant5(space, void 0, {
2147
2391
  F: __dxlog_file10,
2148
- L: 338,
2392
+ L: 341,
2149
2393
  S: this,
2150
2394
  A: [
2151
2395
  "space",
@@ -2158,7 +2402,7 @@ var DataSpaceManager = class extends Resource3 {
2158
2402
  const credentials = await createAdmissionCredentials(this._signingContext.credentialSigner, options.identityKey, space.key, space.genesisFeedKey, options.role, space.spaceState.membershipChainHeads, options.profile, options.delegationCredentialId);
2159
2403
  invariant5(credentials[0].credential, void 0, {
2160
2404
  F: __dxlog_file10,
2161
- L: 357,
2405
+ L: 360,
2162
2406
  S: this,
2163
2407
  A: [
2164
2408
  "credentials[0].credential",
@@ -2168,7 +2412,7 @@ var DataSpaceManager = class extends Resource3 {
2168
2412
  const spaceMemberCredential = credentials[0].credential.credential;
2169
2413
  invariant5(getCredentialAssertion2(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2170
2414
  F: __dxlog_file10,
2171
- L: 359,
2415
+ L: 362,
2172
2416
  S: this,
2173
2417
  A: [
2174
2418
  "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2202,12 +2446,36 @@ var DataSpaceManager = class extends Resource3 {
2202
2446
  }
2203
2447
  });
2204
2448
  }
2449
+ async setSpaceEdgeReplicationSetting(spaceKey, setting) {
2450
+ const space = this._spaces.get(spaceKey);
2451
+ invariant5(space, "Space not found.", {
2452
+ F: __dxlog_file10,
2453
+ L: 399,
2454
+ S: this,
2455
+ A: [
2456
+ "space",
2457
+ "'Space not found.'"
2458
+ ]
2459
+ });
2460
+ await this._metadataStore.setSpaceEdgeReplicationSetting(spaceKey, setting);
2461
+ if (space.isOpen) {
2462
+ switch (setting) {
2463
+ case EdgeReplicationSetting.DISABLED:
2464
+ await this._echoEdgeReplicator?.disconnectFromSpace(space.id);
2465
+ break;
2466
+ case EdgeReplicationSetting.ENABLED:
2467
+ await this._echoEdgeReplicator?.connectToSpace(space.id);
2468
+ break;
2469
+ }
2470
+ }
2471
+ space.stateUpdate.emit();
2472
+ }
2205
2473
  async _constructSpace(metadata) {
2206
2474
  log8("construct space", {
2207
2475
  metadata
2208
2476
  }, {
2209
2477
  F: __dxlog_file10,
2210
- L: 395,
2478
+ L: 418,
2211
2479
  S: this,
2212
2480
  C: (f, a) => f(...a)
2213
2481
  });
@@ -2251,7 +2519,7 @@ var DataSpaceManager = class extends Resource3 {
2251
2519
  err
2252
2520
  }, {
2253
2521
  F: __dxlog_file10,
2254
- L: 437,
2522
+ L: 460,
2255
2523
  S: this,
2256
2524
  C: (f, a) => f(...a)
2257
2525
  });
@@ -2261,7 +2529,7 @@ var DataSpaceManager = class extends Resource3 {
2261
2529
  onAuthFailure: () => {
2262
2530
  log8.warn("auth failure", void 0, {
2263
2531
  F: __dxlog_file10,
2264
- L: 442,
2532
+ L: 465,
2265
2533
  S: this,
2266
2534
  C: (f, a) => f(...a)
2267
2535
  });
@@ -2294,7 +2562,7 @@ var DataSpaceManager = class extends Resource3 {
2294
2562
  space: space.key
2295
2563
  }, {
2296
2564
  F: __dxlog_file10,
2297
- L: 469,
2565
+ L: 492,
2298
2566
  S: this,
2299
2567
  C: (f, a) => f(...a)
2300
2568
  });
@@ -2305,7 +2573,7 @@ var DataSpaceManager = class extends Resource3 {
2305
2573
  open: this._lifecycleState === LifecycleState.OPEN
2306
2574
  }, {
2307
2575
  F: __dxlog_file10,
2308
- L: 472,
2576
+ L: 495,
2309
2577
  S: this,
2310
2578
  C: (f, a) => f(...a)
2311
2579
  });
@@ -2324,7 +2592,7 @@ var DataSpaceManager = class extends Resource3 {
2324
2592
  space: space.key
2325
2593
  }, {
2326
2594
  F: __dxlog_file10,
2327
- L: 480,
2595
+ L: 503,
2328
2596
  S: this,
2329
2597
  C: (f, a) => f(...a)
2330
2598
  });
@@ -2332,13 +2600,29 @@ var DataSpaceManager = class extends Resource3 {
2332
2600
  },
2333
2601
  cache: metadata.cache,
2334
2602
  edgeConnection: this._edgeConnection,
2603
+ edgeHttpClient: this._edgeHttpClient,
2335
2604
  edgeFeatures: this._edgeFeatures
2336
2605
  });
2337
2606
  dataSpace.postOpen.append(async () => {
2338
- await this._echoEdgeReplicator?.connectToSpace(dataSpace.id);
2607
+ const setting = dataSpace.getEdgeReplicationSetting();
2608
+ if (setting === EdgeReplicationSetting.ENABLED) {
2609
+ await this._echoEdgeReplicator?.connectToSpace(dataSpace.id);
2610
+ } else if (this._echoEdgeReplicator) {
2611
+ log8("not connecting EchoEdgeReplicator because of EdgeReplicationSetting", {
2612
+ spaceId: dataSpace.id
2613
+ }, {
2614
+ F: __dxlog_file10,
2615
+ L: 516,
2616
+ S: this,
2617
+ C: (f, a) => f(...a)
2618
+ });
2619
+ }
2339
2620
  });
2340
2621
  dataSpace.preClose.append(async () => {
2341
- await this._echoEdgeReplicator?.disconnectFromSpace(dataSpace.id);
2622
+ const setting = dataSpace.getEdgeReplicationSetting();
2623
+ if (setting === EdgeReplicationSetting.ENABLED) {
2624
+ await this._echoEdgeReplicator?.disconnectFromSpace(dataSpace.id);
2625
+ }
2342
2626
  });
2343
2627
  presence.newPeer.on((peerState) => {
2344
2628
  if (dataSpace.state === SpaceState.SPACE_READY) {
@@ -2358,7 +2642,7 @@ var DataSpaceManager = class extends Resource3 {
2358
2642
  space: space.key
2359
2643
  }, {
2360
2644
  F: __dxlog_file10,
2361
- L: 511,
2645
+ L: 543,
2362
2646
  S: this,
2363
2647
  C: (f, a) => f(...a)
2364
2648
  });
@@ -2391,7 +2675,7 @@ var DataSpaceManager = class extends Resource3 {
2391
2675
  closedSessions
2392
2676
  }, {
2393
2677
  F: __dxlog_file10,
2394
- L: 537,
2678
+ L: 569,
2395
2679
  S: this,
2396
2680
  C: (f, a) => f(...a)
2397
2681
  });
@@ -2406,7 +2690,7 @@ var DataSpaceManager = class extends Resource3 {
2406
2690
  peerId: peerState.peerId
2407
2691
  }, {
2408
2692
  F: __dxlog_file10,
2409
- L: 551,
2693
+ L: 583,
2410
2694
  S: this,
2411
2695
  C: (f, a) => f(...a)
2412
2696
  });
@@ -2450,19 +2734,19 @@ var DataSpaceManager = class extends Resource3 {
2450
2734
  await Promise.all(tasks);
2451
2735
  }
2452
2736
  };
2453
- _ts_decorate([
2737
+ _ts_decorate3([
2454
2738
  synchronized
2455
2739
  ], DataSpaceManager.prototype, "_open", null);
2456
- _ts_decorate([
2740
+ _ts_decorate3([
2457
2741
  synchronized
2458
2742
  ], DataSpaceManager.prototype, "_close", null);
2459
- _ts_decorate([
2743
+ _ts_decorate3([
2460
2744
  synchronized
2461
2745
  ], DataSpaceManager.prototype, "createSpace", null);
2462
- _ts_decorate([
2746
+ _ts_decorate3([
2463
2747
  synchronized
2464
2748
  ], DataSpaceManager.prototype, "acceptSpace", null);
2465
- DataSpaceManager = _ts_decorate([
2749
+ DataSpaceManager = _ts_decorate3([
2466
2750
  trackLeaks("open", "close")
2467
2751
  ], DataSpaceManager);
2468
2752
 
@@ -2491,7 +2775,7 @@ var SpacesServiceImpl = class {
2491
2775
  await this._updateMetrics();
2492
2776
  return this._serializeSpace(space);
2493
2777
  }
2494
- async updateSpace({ spaceKey, state }) {
2778
+ async updateSpace({ spaceKey, state, edgeReplication }) {
2495
2779
  const dataSpaceManager = await this._getDataSpaceManager();
2496
2780
  const space = dataSpaceManager.spaces.get(spaceKey) ?? raise(new SpaceNotFoundError(spaceKey));
2497
2781
  if (state) {
@@ -2506,6 +2790,9 @@ var SpacesServiceImpl = class {
2506
2790
  throw new ApiError("Invalid space state");
2507
2791
  }
2508
2792
  }
2793
+ if (edgeReplication !== void 0) {
2794
+ await dataSpaceManager.setSpaceEdgeReplicationSetting(spaceKey, edgeReplication);
2795
+ }
2509
2796
  }
2510
2797
  async updateMemberRole(request) {
2511
2798
  const identity = this._requireIdentity();
@@ -2522,7 +2809,7 @@ var SpacesServiceImpl = class {
2522
2809
  const credentials = await createAdmissionCredentials2(identity.getIdentityCredentialSigner(), request.memberKey, space.key, space.genesisFeedKey, request.newRole, space.spaceState.membershipChainHeads);
2523
2810
  invariant6(credentials[0].credential, void 0, {
2524
2811
  F: __dxlog_file11,
2525
- L: 102,
2812
+ L: 106,
2526
2813
  S: this,
2527
2814
  A: [
2528
2815
  "credentials[0].credential",
@@ -2532,7 +2819,7 @@ var SpacesServiceImpl = class {
2532
2819
  const spaceMemberCredential = credentials[0].credential.credential;
2533
2820
  invariant6(getCredentialAssertion3(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2534
2821
  F: __dxlog_file11,
2535
- L: 104,
2822
+ L: 108,
2536
2823
  S: this,
2537
2824
  A: [
2538
2825
  "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2550,7 +2837,7 @@ var SpacesServiceImpl = class {
2550
2837
  ids: spaces.map((space) => space.id)
2551
2838
  }), {
2552
2839
  F: __dxlog_file11,
2553
- L: 115,
2840
+ L: 119,
2554
2841
  S: this,
2555
2842
  C: (f, a) => f(...a)
2556
2843
  });
@@ -2642,7 +2929,7 @@ var SpacesServiceImpl = class {
2642
2929
  } else {
2643
2930
  invariant6(!credential.id, "Id on unsigned credentials is not allowed", {
2644
2931
  F: __dxlog_file11,
2645
- L: 213,
2932
+ L: 217,
2646
2933
  S: this,
2647
2934
  A: [
2648
2935
  "!credential.id",
@@ -2651,7 +2938,7 @@ var SpacesServiceImpl = class {
2651
2938
  });
2652
2939
  invariant6(this._identityManager.identity, "Identity is not available", {
2653
2940
  F: __dxlog_file11,
2654
- L: 214,
2941
+ L: 218,
2655
2942
  S: this,
2656
2943
  A: [
2657
2944
  "this._identityManager.identity",
@@ -2661,7 +2948,7 @@ var SpacesServiceImpl = class {
2661
2948
  const signer = this._identityManager.identity.getIdentityCredentialSigner();
2662
2949
  invariant6(credential.issuer.equals(signer.getIssuer()), void 0, {
2663
2950
  F: __dxlog_file11,
2664
- L: 216,
2951
+ L: 220,
2665
2952
  S: this,
2666
2953
  A: [
2667
2954
  "credential.issuer.equals(signer.getIssuer())",
@@ -2711,7 +2998,7 @@ var SpacesServiceImpl = class {
2711
2998
  const assertion = getCredentialAssertion3(credential);
2712
2999
  invariant6(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
2713
3000
  F: __dxlog_file11,
2714
- L: 250,
3001
+ L: 254,
2715
3002
  S: this,
2716
3003
  A: [
2717
3004
  "assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2721,7 +3008,7 @@ var SpacesServiceImpl = class {
2721
3008
  const myIdentity = this._identityManager.identity;
2722
3009
  invariant6(myIdentity && credential.subject.id.equals(myIdentity.identityKey), void 0, {
2723
3010
  F: __dxlog_file11,
2724
- L: 252,
3011
+ L: 256,
2725
3012
  S: this,
2726
3013
  A: [
2727
3014
  "myIdentity && credential.subject.id.equals(myIdentity.identityKey)",
@@ -2783,7 +3070,8 @@ var SpacesServiceImpl = class {
2783
3070
  }),
2784
3071
  creator: space.inner.spaceState.creator?.key,
2785
3072
  cache: space.cache,
2786
- metrics: space.metrics
3073
+ metrics: space.metrics,
3074
+ edgeReplication: space.getEdgeReplicationSetting()
2787
3075
  };
2788
3076
  }
2789
3077
  _requireIdentity() {
@@ -2807,7 +3095,7 @@ var SpacesServiceImpl = class {
2807
3095
  var getChannelId = (channel) => `user-channel/${channel}`;
2808
3096
 
2809
3097
  // packages/sdk/client-services/src/packlets/identity/identity.ts
2810
- function _ts_decorate2(decorators, target, key, desc) {
3098
+ function _ts_decorate4(decorators, target, key, desc) {
2811
3099
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2812
3100
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2813
3101
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
@@ -2916,6 +3204,9 @@ var Identity = class {
2916
3204
  get presence() {
2917
3205
  return this._presence;
2918
3206
  }
3207
+ get signer() {
3208
+ return this._signer;
3209
+ }
2919
3210
  /**
2920
3211
  * Issues credentials as identity.
2921
3212
  * Requires identity to be ready.
@@ -2923,7 +3214,7 @@ var Identity = class {
2923
3214
  getIdentityCredentialSigner() {
2924
3215
  invariant7(this._deviceStateMachine.deviceCredentialChain, "Device credential chain is not ready.", {
2925
3216
  F: __dxlog_file12,
2926
- L: 185,
3217
+ L: 189,
2927
3218
  S: this,
2928
3219
  A: [
2929
3220
  "this._deviceStateMachine.deviceCredentialChain",
@@ -2967,7 +3258,7 @@ var Identity = class {
2967
3258
  dataFeedKey
2968
3259
  }, {
2969
3260
  F: __dxlog_file12,
2970
- L: 210,
3261
+ L: 214,
2971
3262
  S: this,
2972
3263
  C: (f, a) => f(...a)
2973
3264
  });
@@ -3008,13 +3299,13 @@ var Identity = class {
3008
3299
  })));
3009
3300
  }
3010
3301
  };
3011
- _ts_decorate2([
3302
+ _ts_decorate4([
3012
3303
  trace3.span()
3013
3304
  ], Identity.prototype, "open", null);
3014
- _ts_decorate2([
3305
+ _ts_decorate4([
3015
3306
  trace3.span()
3016
3307
  ], Identity.prototype, "close", null);
3017
- Identity = _ts_decorate2([
3308
+ Identity = _ts_decorate4([
3018
3309
  trace3.resource()
3019
3310
  ], Identity);
3020
3311
 
@@ -3033,7 +3324,7 @@ import { Gossip as Gossip2, Presence as Presence2 } from "@dxos/teleport-extensi
3033
3324
  import { Timeframe as Timeframe3 } from "@dxos/timeframe";
3034
3325
  import { trace as Trace2 } from "@dxos/tracing";
3035
3326
  import { isNode, deferFunction as deferFunction2 } from "@dxos/util";
3036
- function _ts_decorate3(decorators, target, key, desc) {
3327
+ function _ts_decorate5(decorators, target, key, desc) {
3037
3328
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3038
3329
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
3039
3330
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
@@ -3484,19 +3775,19 @@ var IdentityManager = class {
3484
3775
  });
3485
3776
  }
3486
3777
  };
3487
- _ts_decorate3([
3778
+ _ts_decorate5([
3488
3779
  Trace2.span({
3489
3780
  showInBrowserTimeline: true
3490
3781
  })
3491
3782
  ], IdentityManager.prototype, "open", null);
3492
- IdentityManager = _ts_decorate3([
3783
+ IdentityManager = _ts_decorate5([
3493
3784
  Trace2.resource()
3494
3785
  ], IdentityManager);
3495
3786
 
3496
3787
  // packages/sdk/client-services/src/packlets/identity/identity-service.ts
3497
3788
  import { Trigger as Trigger4, sleep as sleep2 } from "@dxos/async";
3498
3789
  import { Stream as Stream8 } from "@dxos/codec-protobuf";
3499
- import { Resource as Resource4 } from "@dxos/context";
3790
+ import { Resource as Resource5 } from "@dxos/context";
3500
3791
  import { signPresentation } from "@dxos/credentials";
3501
3792
  import { todo } from "@dxos/debug";
3502
3793
  import { invariant as invariant9 } from "@dxos/invariant";
@@ -3505,7 +3796,7 @@ import { SpaceState as SpaceState3 } from "@dxos/protocols/proto/dxos/client/ser
3505
3796
  import { safeAwaitAll } from "@dxos/util";
3506
3797
  var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-service.ts";
3507
3798
  var DEFAULT_SPACE_SEARCH_TIMEOUT = 1e4;
3508
- var IdentityServiceImpl = class extends Resource4 {
3799
+ var IdentityServiceImpl = class extends Resource5 {
3509
3800
  constructor(_identityManager, _keyring, _dataSpaceManagerProvider, _createIdentity, _onProfileUpdate) {
3510
3801
  super();
3511
3802
  this._identityManager = _identityManager;
@@ -3649,7 +3940,7 @@ var IdentityServiceImpl = class extends Resource4 {
3649
3940
  };
3650
3941
 
3651
3942
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
3652
- function _ts_decorate4(decorators, target, key, desc) {
3943
+ function _ts_decorate6(decorators, target, key, desc) {
3653
3944
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3654
3945
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
3655
3946
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
@@ -3722,9 +4013,8 @@ var DataSpace = class {
3722
4013
  constructor(params) {
3723
4014
  this._ctx = new Context5(void 0, {
3724
4015
  F: __dxlog_file15,
3725
- L: 94
4016
+ L: 95
3726
4017
  });
3727
- this._notarizationPlugin = new NotarizationPlugin();
3728
4018
  this._cache = void 0;
3729
4019
  this._edgeFeedReplicator = void 0;
3730
4020
  // TODO(dmaretskyi): Move into Space?
@@ -3753,6 +4043,11 @@ var DataSpace = class {
3753
4043
  this._signingContext = params.signingContext;
3754
4044
  this._callbacks = params.callbacks ?? {};
3755
4045
  this._echoHost = params.echoHost;
4046
+ this._notarizationPlugin = new NotarizationPlugin({
4047
+ spaceId: this._inner.id,
4048
+ edgeClient: params.edgeHttpClient,
4049
+ edgeFeatures: params.edgeFeatures
4050
+ });
3756
4051
  this.authVerifier = new TrustedKeySetAuthVerifier({
3757
4052
  trustedKeysProvider: () => new ComplexSet3(PublicKey8.hash, Array.from(this._inner.spaceState.members.values()).filter((member) => member.role !== SpaceMember5.Role.REMOVED).map((member) => member.key)),
3758
4053
  update: this._inner.stateUpdate,
@@ -3770,7 +4065,7 @@ var DataSpace = class {
3770
4065
  state: SpaceState4[this._state]
3771
4066
  }, {
3772
4067
  F: __dxlog_file15,
3773
- L: 164,
4068
+ L: 170,
3774
4069
  S: this,
3775
4070
  C: (f, a) => f(...a)
3776
4071
  });
@@ -3829,7 +4124,7 @@ var DataSpace = class {
3829
4124
  }
3830
4125
  await this._inner.open(new Context5(void 0, {
3831
4126
  F: __dxlog_file15,
3832
- L: 238
4127
+ L: 244
3833
4128
  }));
3834
4129
  await this._edgeFeedReplicator?.open();
3835
4130
  this._state = SpaceState4.SPACE_CONTROL_ONLY;
@@ -3837,7 +4132,7 @@ var DataSpace = class {
3837
4132
  state: SpaceState4[this._state]
3838
4133
  }, {
3839
4134
  F: __dxlog_file15,
3840
- L: 243,
4135
+ L: 249,
3841
4136
  S: this,
3842
4137
  C: (f, a) => f(...a)
3843
4138
  });
@@ -3857,14 +4152,14 @@ var DataSpace = class {
3857
4152
  state: SpaceState4[this._state]
3858
4153
  }, {
3859
4154
  F: __dxlog_file15,
3860
- L: 262,
4155
+ L: 268,
3861
4156
  S: this,
3862
4157
  C: (f, a) => f(...a)
3863
4158
  });
3864
4159
  await this._ctx.dispose();
3865
4160
  this._ctx = new Context5(void 0, {
3866
4161
  F: __dxlog_file15,
3867
- L: 264
4162
+ L: 270
3868
4163
  });
3869
4164
  if (this._edgeFeedReplicator) {
3870
4165
  this.inner.protocol.feedAdded.remove(this._onFeedAdded);
@@ -3897,7 +4192,7 @@ var DataSpace = class {
3897
4192
  if (err instanceof CancelledError || err instanceof ContextDisposedError) {
3898
4193
  log13("data pipeline initialization cancelled", err, {
3899
4194
  F: __dxlog_file15,
3900
- L: 302,
4195
+ L: 308,
3901
4196
  S: this,
3902
4197
  C: (f, a) => f(...a)
3903
4198
  });
@@ -3905,7 +4200,7 @@ var DataSpace = class {
3905
4200
  }
3906
4201
  log13.error("Error initializing data pipeline", err, {
3907
4202
  F: __dxlog_file15,
3908
- L: 306,
4203
+ L: 312,
3909
4204
  S: this,
3910
4205
  C: (f, a) => f(...a)
3911
4206
  });
@@ -3914,7 +4209,7 @@ var DataSpace = class {
3914
4209
  state: SpaceState4[this._state]
3915
4210
  }, {
3916
4211
  F: __dxlog_file15,
3917
- L: 308,
4212
+ L: 314,
3918
4213
  S: this,
3919
4214
  C: (f, a) => f(...a)
3920
4215
  });
@@ -3934,15 +4229,39 @@ var DataSpace = class {
3934
4229
  state: SpaceState4[this._state]
3935
4230
  }, {
3936
4231
  F: __dxlog_file15,
3937
- L: 324,
4232
+ L: 330,
4233
+ S: this,
4234
+ C: (f, a) => f(...a)
4235
+ });
4236
+ log13("initializing control pipeline", void 0, {
4237
+ F: __dxlog_file15,
4238
+ L: 332,
3938
4239
  S: this,
3939
4240
  C: (f, a) => f(...a)
3940
4241
  });
3941
4242
  await this._initializeAndReadControlPipeline();
3942
4243
  await sleep3(1);
3943
4244
  const ready = this.stateUpdate.waitForCondition(() => this._state === SpaceState4.SPACE_READY);
4245
+ log13("initializing automerge root", void 0, {
4246
+ F: __dxlog_file15,
4247
+ L: 340,
4248
+ S: this,
4249
+ C: (f, a) => f(...a)
4250
+ });
3944
4251
  this._automergeSpaceState.startProcessingRootDocs();
4252
+ log13("waiting for space to be ready", void 0, {
4253
+ F: __dxlog_file15,
4254
+ L: 344,
4255
+ S: this,
4256
+ C: (f, a) => f(...a)
4257
+ });
3945
4258
  await ready;
4259
+ log13("space is ready", void 0, {
4260
+ F: __dxlog_file15,
4261
+ L: 346,
4262
+ S: this,
4263
+ C: (f, a) => f(...a)
4264
+ });
3946
4265
  }
3947
4266
  async _enterReadyState() {
3948
4267
  await this._callbacks.beforeReady?.();
@@ -3951,7 +4270,7 @@ var DataSpace = class {
3951
4270
  state: SpaceState4[this._state]
3952
4271
  }, {
3953
4272
  F: __dxlog_file15,
3954
- L: 343,
4273
+ L: 353,
3955
4274
  S: this,
3956
4275
  C: (f, a) => f(...a)
3957
4276
  });
@@ -3961,13 +4280,14 @@ var DataSpace = class {
3961
4280
  async _initializeAndReadControlPipeline() {
3962
4281
  await this._inner.controlPipeline.state.waitUntilReachedTargetTimeframe({
3963
4282
  ctx: this._ctx,
4283
+ timeout: 1e4,
3964
4284
  breakOnStall: false
3965
4285
  });
3966
4286
  this.metrics.controlPipelineReady = /* @__PURE__ */ new Date();
3967
4287
  await this._createWritableFeeds();
3968
4288
  log13("writable feeds created", void 0, {
3969
4289
  F: __dxlog_file15,
3970
- L: 359,
4290
+ L: 370,
3971
4291
  S: this,
3972
4292
  C: (f, a) => f(...a)
3973
4293
  });
@@ -4016,11 +4336,35 @@ var DataSpace = class {
4016
4336
  }));
4017
4337
  }
4018
4338
  if (credentials.length > 0) {
4019
- await this.notarizationPlugin.notarize({
4020
- ctx: this._ctx,
4021
- credentials,
4022
- timeout: 0
4023
- });
4339
+ try {
4340
+ log13("will notarize credentials for feed admission", {
4341
+ count: credentials.length
4342
+ }, {
4343
+ F: __dxlog_file15,
4344
+ L: 428,
4345
+ S: this,
4346
+ C: (f, a) => f(...a)
4347
+ });
4348
+ await this.notarizationPlugin.notarize({
4349
+ ctx: this._ctx,
4350
+ credentials,
4351
+ timeout: 0
4352
+ });
4353
+ log13("credentials notarized", void 0, {
4354
+ F: __dxlog_file15,
4355
+ L: 432,
4356
+ S: this,
4357
+ C: (f, a) => f(...a)
4358
+ });
4359
+ } catch (err) {
4360
+ log13.error("error notarizing credentials for feed admission", err, {
4361
+ F: __dxlog_file15,
4362
+ L: 434,
4363
+ S: this,
4364
+ C: (f, a) => f(...a)
4365
+ });
4366
+ throw err;
4367
+ }
4024
4368
  await this._metadataStore.setWritableFeedKeys(this.key, this.inner.controlFeedKey, this.inner.dataFeedKey);
4025
4369
  }
4026
4370
  }
@@ -4030,7 +4374,7 @@ var DataSpace = class {
4030
4374
  rootUrl
4031
4375
  }, {
4032
4376
  F: __dxlog_file15,
4033
- L: 425,
4377
+ L: 444,
4034
4378
  S: this,
4035
4379
  C: (f, a) => f(...a)
4036
4380
  });
@@ -4082,7 +4426,7 @@ var DataSpace = class {
4082
4426
  err
4083
4427
  }, {
4084
4428
  F: __dxlog_file15,
4085
- L: 468,
4429
+ L: 487,
4086
4430
  S: this,
4087
4431
  C: (f, a) => f(...a)
4088
4432
  });
@@ -4172,58 +4516,61 @@ var DataSpace = class {
4172
4516
  state: SpaceState4[this._state]
4173
4517
  }, {
4174
4518
  F: __dxlog_file15,
4175
- L: 550,
4519
+ L: 569,
4176
4520
  S: this,
4177
4521
  C: (f, a) => f(...a)
4178
4522
  });
4179
4523
  this.stateUpdate.emit();
4180
4524
  }
4525
+ getEdgeReplicationSetting() {
4526
+ return this._metadataStore.getSpaceEdgeReplicationSetting(this.key);
4527
+ }
4181
4528
  };
4182
- _ts_decorate4([
4529
+ _ts_decorate6([
4183
4530
  trace5.info()
4184
4531
  ], DataSpace.prototype, "_inner", void 0);
4185
- _ts_decorate4([
4532
+ _ts_decorate6([
4186
4533
  trace5.info()
4187
4534
  ], DataSpace.prototype, "id", null);
4188
- _ts_decorate4([
4535
+ _ts_decorate6([
4189
4536
  trace5.info()
4190
4537
  ], DataSpace.prototype, "key", null);
4191
- _ts_decorate4([
4538
+ _ts_decorate6([
4192
4539
  trace5.info({
4193
4540
  enum: SpaceState4
4194
4541
  })
4195
4542
  ], DataSpace.prototype, "state", null);
4196
- _ts_decorate4([
4543
+ _ts_decorate6([
4197
4544
  trace5.info({
4198
4545
  depth: null
4199
4546
  })
4200
4547
  ], DataSpace.prototype, "_automergeInfo", null);
4201
- _ts_decorate4([
4548
+ _ts_decorate6([
4202
4549
  synchronized2
4203
4550
  ], DataSpace.prototype, "open", null);
4204
- _ts_decorate4([
4551
+ _ts_decorate6([
4205
4552
  synchronized2
4206
4553
  ], DataSpace.prototype, "close", null);
4207
- _ts_decorate4([
4554
+ _ts_decorate6([
4208
4555
  trace5.span({
4209
4556
  showInBrowserTimeline: true
4210
4557
  })
4211
4558
  ], DataSpace.prototype, "initializeDataPipeline", null);
4212
- _ts_decorate4([
4559
+ _ts_decorate6([
4213
4560
  trace5.span({
4214
4561
  showInBrowserTimeline: true
4215
4562
  })
4216
4563
  ], DataSpace.prototype, "_initializeAndReadControlPipeline", null);
4217
- _ts_decorate4([
4564
+ _ts_decorate6([
4218
4565
  timed(1e4)
4219
4566
  ], DataSpace.prototype, "_createWritableFeeds", null);
4220
- _ts_decorate4([
4567
+ _ts_decorate6([
4221
4568
  synchronized2
4222
4569
  ], DataSpace.prototype, "activate", null);
4223
- _ts_decorate4([
4570
+ _ts_decorate6([
4224
4571
  synchronized2
4225
4572
  ], DataSpace.prototype, "deactivate", null);
4226
- DataSpace = _ts_decorate4([
4573
+ DataSpace = _ts_decorate6([
4227
4574
  trackLeaks2("open", "close"),
4228
4575
  trace5.resource()
4229
4576
  ], DataSpace);
@@ -4340,30 +4687,30 @@ var DeviceInvitationProtocol = class {
4340
4687
  };
4341
4688
 
4342
4689
  // packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
4343
- import { Mutex as Mutex3, scheduleTask as scheduleTask6, TimeoutError as TimeoutError2 } from "@dxos/async";
4690
+ import { scheduleTask as scheduleTask7, TimeoutError as TimeoutError2 } from "@dxos/async";
4344
4691
  import { INVITATION_TIMEOUT } from "@dxos/client-protocol";
4345
4692
  import { ContextDisposedError as ContextDisposedError3 } from "@dxos/context";
4346
4693
  import { createKeyPair, sign } from "@dxos/crypto";
4347
- import { invariant as invariant14 } from "@dxos/invariant";
4694
+ import { invariant as invariant15 } from "@dxos/invariant";
4348
4695
  import { PublicKey as PublicKey11 } from "@dxos/keys";
4349
- import { log as log17 } from "@dxos/log";
4696
+ import { log as log19 } from "@dxos/log";
4350
4697
  import { createTeleportProtocolFactory } from "@dxos/network-manager";
4351
4698
  import { InvalidInvitationExtensionRoleError as InvalidInvitationExtensionRoleError3, trace as trace7 } from "@dxos/protocols";
4352
- import { Invitation as Invitation5 } from "@dxos/protocols/proto/dxos/client/services";
4699
+ import { Invitation as Invitation7 } from "@dxos/protocols/proto/dxos/client/services";
4353
4700
  import { AuthenticationResponse as AuthenticationResponse2 } from "@dxos/protocols/proto/dxos/halo/invitations";
4354
4701
  import { InvitationOptions as InvitationOptions4 } from "@dxos/protocols/proto/dxos/halo/invitations";
4355
4702
  import { trace as _trace } from "@dxos/tracing";
4356
4703
  import { ComplexSet as ComplexSet5 } from "@dxos/util";
4357
4704
 
4358
- // packages/sdk/client-services/src/packlets/invitations/invitation-guest-extenstion.ts
4359
- import { Trigger as Trigger5 } from "@dxos/async";
4360
- import { cancelWithContext as cancelWithContext4, Context as Context6 } from "@dxos/context";
4705
+ // packages/sdk/client-services/src/packlets/invitations/edge-invitation-handler.ts
4706
+ import { scheduleMicroTask as scheduleMicroTask3, scheduleTask as scheduleTask5 } from "@dxos/async";
4707
+ import { ed25519Signature } from "@dxos/crypto";
4361
4708
  import { invariant as invariant11 } from "@dxos/invariant";
4709
+ import { SpaceId as SpaceId2 } from "@dxos/keys";
4362
4710
  import { log as log14 } from "@dxos/log";
4363
- import { InvalidInvitationExtensionRoleError } from "@dxos/protocols";
4711
+ import { EdgeAuthChallengeError, EdgeCallFailedError as EdgeCallFailedError2 } from "@dxos/protocols";
4364
4712
  import { schema as schema3 } from "@dxos/protocols/proto";
4365
- import { InvitationOptions } from "@dxos/protocols/proto/dxos/halo/invitations";
4366
- import { RpcExtension as RpcExtension2 } from "@dxos/teleport";
4713
+ import { Invitation as Invitation4 } from "@dxos/protocols/proto/dxos/client/services";
4367
4714
 
4368
4715
  // packages/sdk/client-services/src/packlets/invitations/utils.ts
4369
4716
  import { cancelWithContext as cancelWithContext3, ContextDisposedError as ContextDisposedError2 } from "@dxos/context";
@@ -4384,24 +4731,184 @@ var tryAcquireBeforeContextDisposed = async (ctx, mutex) => {
4384
4731
  })());
4385
4732
  };
4386
4733
 
4734
+ // packages/sdk/client-services/src/packlets/invitations/edge-invitation-handler.ts
4735
+ var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/edge-invitation-handler.ts";
4736
+ var DEFAULT_REQUEST_RETRY_INTERVAL_MS = 3e3;
4737
+ var DEFAULT_REQUEST_RETRY_JITTER_MS = 500;
4738
+ var EdgeInvitationHandler = class {
4739
+ constructor(config, _client, _callbacks) {
4740
+ this._client = _client;
4741
+ this._callbacks = _callbacks;
4742
+ this._retryInterval = config?.retryInterval ?? DEFAULT_REQUEST_RETRY_INTERVAL_MS;
4743
+ this._retryJitter = config?.retryJitter ?? DEFAULT_REQUEST_RETRY_JITTER_MS;
4744
+ }
4745
+ handle(ctx, guardedState, protocol, deviceProfile) {
4746
+ if (!this._client) {
4747
+ log14("edge disabled", void 0, {
4748
+ F: __dxlog_file17,
4749
+ L: 65,
4750
+ S: this,
4751
+ C: (f, a) => f(...a)
4752
+ });
4753
+ return;
4754
+ }
4755
+ const invitation = guardedState.current;
4756
+ const spaceId = invitation.spaceId;
4757
+ const canBeHandledByEdge = invitation.authMethod !== Invitation4.AuthMethod.SHARED_SECRET && invitation.type === Invitation4.Type.DELEGATED && invitation.kind === Invitation4.Kind.SPACE && spaceId != null && SpaceId2.isValid(spaceId);
4758
+ if (!canBeHandledByEdge) {
4759
+ log14("invitation could not be handled by edge", {
4760
+ invitation
4761
+ }, {
4762
+ F: __dxlog_file17,
4763
+ L: 79,
4764
+ S: this,
4765
+ C: (f, a) => f(...a)
4766
+ });
4767
+ return;
4768
+ }
4769
+ ctx.onDispose(() => {
4770
+ this._flowLock?.release();
4771
+ this._flowLock = void 0;
4772
+ });
4773
+ const tryHandleInvitation = async () => {
4774
+ const admissionRequest = await protocol.createAdmissionRequest(deviceProfile);
4775
+ if (admissionRequest.space) {
4776
+ try {
4777
+ await this._handleSpaceInvitationFlow(ctx, guardedState, admissionRequest.space, spaceId);
4778
+ } catch (error) {
4779
+ if (error instanceof EdgeCallFailedError2) {
4780
+ log14.info("join space with edge unsuccessful", {
4781
+ reason: error.message,
4782
+ retryable: error.isRetryable,
4783
+ after: error.retryAfterMs ?? this._calculateNextRetryMs()
4784
+ }, {
4785
+ F: __dxlog_file17,
4786
+ L: 95,
4787
+ S: this,
4788
+ C: (f, a) => f(...a)
4789
+ });
4790
+ if (error.isRetryable) {
4791
+ scheduleTask5(ctx, tryHandleInvitation, error.retryAfterMs ?? this._calculateNextRetryMs());
4792
+ }
4793
+ } else {
4794
+ log14.info("failed to handle invitation with edge", {
4795
+ error
4796
+ }, {
4797
+ F: __dxlog_file17,
4798
+ L: 104,
4799
+ S: this,
4800
+ C: (f, a) => f(...a)
4801
+ });
4802
+ scheduleTask5(ctx, tryHandleInvitation, this._calculateNextRetryMs());
4803
+ }
4804
+ }
4805
+ }
4806
+ };
4807
+ scheduleMicroTask3(ctx, tryHandleInvitation);
4808
+ }
4809
+ async _handleSpaceInvitationFlow(ctx, guardedState, admissionRequest, spaceId) {
4810
+ try {
4811
+ log14("edge invitation flow", void 0, {
4812
+ F: __dxlog_file17,
4813
+ L: 120,
4814
+ S: this,
4815
+ C: (f, a) => f(...a)
4816
+ });
4817
+ this._flowLock = await tryAcquireBeforeContextDisposed(ctx, guardedState.mutex);
4818
+ log14("edge invitation flow acquired the lock", void 0, {
4819
+ F: __dxlog_file17,
4820
+ L: 122,
4821
+ S: this,
4822
+ C: (f, a) => f(...a)
4823
+ });
4824
+ guardedState.set(this, Invitation4.State.CONNECTING);
4825
+ const response = await this._joinSpaceByInvitation(guardedState, spaceId, {
4826
+ identityKey: admissionRequest.identityKey.toHex(),
4827
+ invitationId: guardedState.current.invitationId
4828
+ });
4829
+ const admissionResponse = await this._mapToAdmissionResponse(response);
4830
+ await this._callbacks.onInvitationSuccess(admissionResponse, {
4831
+ space: admissionRequest
4832
+ });
4833
+ } catch (error) {
4834
+ guardedState.set(this, Invitation4.State.ERROR);
4835
+ throw error;
4836
+ } finally {
4837
+ this._flowLock?.release();
4838
+ this._flowLock = void 0;
4839
+ }
4840
+ }
4841
+ async _mapToAdmissionResponse(edgeResponse) {
4842
+ const credentialBytes = Buffer.from(edgeResponse.spaceMemberCredential, "base64");
4843
+ const codec = schema3.getCodecForType("dxos.halo.credentials.Credential");
4844
+ return {
4845
+ space: {
4846
+ credential: codec.decode(credentialBytes)
4847
+ }
4848
+ };
4849
+ }
4850
+ async _joinSpaceByInvitation(guardedState, spaceId, request) {
4851
+ invariant11(this._client, void 0, {
4852
+ F: __dxlog_file17,
4853
+ L: 157,
4854
+ S: this,
4855
+ A: [
4856
+ "this._client",
4857
+ ""
4858
+ ]
4859
+ });
4860
+ try {
4861
+ return await this._client.joinSpaceByInvitation(spaceId, request);
4862
+ } catch (error) {
4863
+ if (error instanceof EdgeAuthChallengeError) {
4864
+ guardedState.set(this, Invitation4.State.AUTHENTICATING);
4865
+ const publicKey = guardedState.current.guestKeypair?.publicKey;
4866
+ const privateKey = guardedState.current.guestKeypair?.privateKey;
4867
+ if (!privateKey || !publicKey) {
4868
+ throw error;
4869
+ }
4870
+ const signature = await ed25519Signature(privateKey, Buffer.from(error.challenge, "base64"));
4871
+ request.signature = Buffer.from(signature).toString("base64");
4872
+ return this._client.joinSpaceByInvitation(spaceId, request);
4873
+ } else {
4874
+ throw error;
4875
+ }
4876
+ }
4877
+ }
4878
+ hasFlowLock() {
4879
+ return this._flowLock != null;
4880
+ }
4881
+ _calculateNextRetryMs() {
4882
+ return this._retryInterval + Math.random() * this._retryJitter;
4883
+ }
4884
+ };
4885
+
4387
4886
  // packages/sdk/client-services/src/packlets/invitations/invitation-guest-extenstion.ts
4388
- var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-guest-extenstion.ts";
4887
+ import { Trigger as Trigger5 } from "@dxos/async";
4888
+ import { cancelWithContext as cancelWithContext4, Context as Context6 } from "@dxos/context";
4889
+ import { invariant as invariant12 } from "@dxos/invariant";
4890
+ import { log as log15 } from "@dxos/log";
4891
+ import { InvalidInvitationExtensionRoleError } from "@dxos/protocols";
4892
+ import { schema as schema4 } from "@dxos/protocols/proto";
4893
+ import { InvitationOptions } from "@dxos/protocols/proto/dxos/halo/invitations";
4894
+ import { RpcExtension as RpcExtension2 } from "@dxos/teleport";
4895
+ var __dxlog_file18 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-guest-extenstion.ts";
4389
4896
  var OPTIONS_TIMEOUT = 1e4;
4390
4897
  var InvitationGuestExtension = class extends RpcExtension2 {
4391
4898
  constructor(_invitationFlowMutex, _callbacks) {
4392
4899
  super({
4393
4900
  requested: {
4394
- InvitationHostService: schema3.getService("dxos.halo.invitations.InvitationHostService")
4901
+ InvitationHostService: schema4.getService("dxos.halo.invitations.InvitationHostService")
4395
4902
  },
4396
4903
  exposed: {
4397
- InvitationHostService: schema3.getService("dxos.halo.invitations.InvitationHostService")
4904
+ InvitationHostService: schema4.getService("dxos.halo.invitations.InvitationHostService")
4398
4905
  }
4399
4906
  });
4400
4907
  this._invitationFlowMutex = _invitationFlowMutex;
4401
4908
  this._callbacks = _callbacks;
4402
4909
  this._ctx = new Context6(void 0, {
4403
- F: __dxlog_file17,
4404
- L: 34
4910
+ F: __dxlog_file18,
4911
+ L: 38
4405
4912
  });
4406
4913
  this._remoteOptionsTrigger = new Trigger5();
4407
4914
  this._invitationFlowLock = null;
@@ -4413,9 +4920,9 @@ var InvitationGuestExtension = class extends RpcExtension2 {
4413
4920
  return {
4414
4921
  InvitationHostService: {
4415
4922
  options: async (options) => {
4416
- invariant11(!this._remoteOptions, "Remote options already set.", {
4417
- F: __dxlog_file17,
4418
- L: 64,
4923
+ invariant12(!this._remoteOptions, "Remote options already set.", {
4924
+ F: __dxlog_file18,
4925
+ L: 68,
4419
4926
  S: this,
4420
4927
  A: [
4421
4928
  "!this._remoteOptions",
@@ -4440,34 +4947,34 @@ var InvitationGuestExtension = class extends RpcExtension2 {
4440
4947
  async onOpen(context) {
4441
4948
  await super.onOpen(context);
4442
4949
  try {
4443
- log14("guest acquire lock", void 0, {
4444
- F: __dxlog_file17,
4445
- L: 85,
4950
+ log15("guest acquire lock", void 0, {
4951
+ F: __dxlog_file18,
4952
+ L: 89,
4446
4953
  S: this,
4447
4954
  C: (f, a) => f(...a)
4448
4955
  });
4449
4956
  this._invitationFlowLock = await tryAcquireBeforeContextDisposed(this._ctx, this._invitationFlowMutex);
4450
- log14("guest lock acquired", void 0, {
4451
- F: __dxlog_file17,
4452
- L: 87,
4957
+ log15("guest lock acquired", void 0, {
4958
+ F: __dxlog_file18,
4959
+ L: 91,
4453
4960
  S: this,
4454
4961
  C: (f, a) => f(...a)
4455
4962
  });
4456
4963
  await cancelWithContext4(this._ctx, this.rpc.InvitationHostService.options({
4457
4964
  role: InvitationOptions.Role.GUEST
4458
4965
  }));
4459
- log14("options sent", void 0, {
4460
- F: __dxlog_file17,
4461
- L: 92,
4966
+ log15("options sent", void 0, {
4967
+ F: __dxlog_file18,
4968
+ L: 96,
4462
4969
  S: this,
4463
4970
  C: (f, a) => f(...a)
4464
4971
  });
4465
4972
  await cancelWithContext4(this._ctx, this._remoteOptionsTrigger.wait({
4466
4973
  timeout: OPTIONS_TIMEOUT
4467
4974
  }));
4468
- log14("options received", void 0, {
4469
- F: __dxlog_file17,
4470
- L: 94,
4975
+ log15("options received", void 0, {
4976
+ F: __dxlog_file18,
4977
+ L: 98,
4471
4978
  S: this,
4472
4979
  C: (f, a) => f(...a)
4473
4980
  });
@@ -4499,9 +5006,9 @@ var InvitationGuestExtension = class extends RpcExtension2 {
4499
5006
  if (this._invitationFlowLock != null) {
4500
5007
  this._invitationFlowLock.release();
4501
5008
  this._invitationFlowLock = null;
4502
- log14("invitation flow lock released", void 0, {
4503
- F: __dxlog_file17,
4504
- L: 127,
5009
+ log15("invitation flow lock released", void 0, {
5010
+ F: __dxlog_file18,
5011
+ L: 131,
4505
5012
  S: this,
4506
5013
  C: (f, a) => f(...a)
4507
5014
  });
@@ -4510,35 +5017,35 @@ var InvitationGuestExtension = class extends RpcExtension2 {
4510
5017
  };
4511
5018
 
4512
5019
  // packages/sdk/client-services/src/packlets/invitations/invitation-host-extension.ts
4513
- import { Trigger as Trigger6, scheduleTask as scheduleTask5 } from "@dxos/async";
5020
+ import { Trigger as Trigger6, scheduleTask as scheduleTask6 } from "@dxos/async";
4514
5021
  import { cancelWithContext as cancelWithContext5, Context as Context7 } from "@dxos/context";
4515
5022
  import { randomBytes, verify } from "@dxos/crypto";
4516
- import { invariant as invariant12, InvariantViolation } from "@dxos/invariant";
5023
+ import { invariant as invariant13, InvariantViolation } from "@dxos/invariant";
4517
5024
  import { PublicKey as PublicKey9 } from "@dxos/keys";
4518
- import { log as log15 } from "@dxos/log";
5025
+ import { log as log16 } from "@dxos/log";
4519
5026
  import { InvalidInvitationExtensionRoleError as InvalidInvitationExtensionRoleError2, trace as trace6 } from "@dxos/protocols";
4520
- import { schema as schema4 } from "@dxos/protocols/proto";
4521
- import { Invitation as Invitation4 } from "@dxos/protocols/proto/dxos/client/services";
5027
+ import { schema as schema5 } from "@dxos/protocols/proto";
5028
+ import { Invitation as Invitation5 } from "@dxos/protocols/proto/dxos/client/services";
4522
5029
  import { AuthenticationResponse, InvitationOptions as InvitationOptions2 } from "@dxos/protocols/proto/dxos/halo/invitations";
4523
5030
  import { RpcExtension as RpcExtension3 } from "@dxos/teleport";
4524
- var __dxlog_file18 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-host-extension.ts";
5031
+ var __dxlog_file19 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-host-extension.ts";
4525
5032
  var OPTIONS_TIMEOUT2 = 1e4;
4526
5033
  var MAX_OTP_ATTEMPTS = 3;
4527
5034
  var InvitationHostExtension = class extends RpcExtension3 {
4528
5035
  constructor(_invitationFlowMutex, _callbacks) {
4529
5036
  super({
4530
5037
  requested: {
4531
- InvitationHostService: schema4.getService("dxos.halo.invitations.InvitationHostService")
5038
+ InvitationHostService: schema5.getService("dxos.halo.invitations.InvitationHostService")
4532
5039
  },
4533
5040
  exposed: {
4534
- InvitationHostService: schema4.getService("dxos.halo.invitations.InvitationHostService")
5041
+ InvitationHostService: schema5.getService("dxos.halo.invitations.InvitationHostService")
4535
5042
  }
4536
5043
  });
4537
5044
  this._invitationFlowMutex = _invitationFlowMutex;
4538
5045
  this._callbacks = _callbacks;
4539
5046
  this._ctx = new Context7(void 0, {
4540
- F: __dxlog_file18,
4541
- L: 53
5047
+ F: __dxlog_file19,
5048
+ L: 57
4542
5049
  });
4543
5050
  this._remoteOptionsTrigger = new Trigger6();
4544
5051
  this._challenge = void 0;
@@ -4557,9 +5064,9 @@ var InvitationHostExtension = class extends RpcExtension3 {
4557
5064
  // Perhaps in the future we will have more complex logic here.
4558
5065
  InvitationHostService: {
4559
5066
  options: async (options) => {
4560
- invariant12(!this._remoteOptions, "Remote options already set.", {
4561
- F: __dxlog_file18,
4562
- L: 102,
5067
+ invariant13(!this._remoteOptions, "Remote options already set.", {
5068
+ F: __dxlog_file19,
5069
+ L: 106,
4563
5070
  S: this,
4564
5071
  A: [
4565
5072
  "!this._remoteOptions",
@@ -4572,48 +5079,48 @@ var InvitationHostExtension = class extends RpcExtension3 {
4572
5079
  introduce: async (request) => {
4573
5080
  const { profile, invitationId } = request;
4574
5081
  const traceId = PublicKey9.random().toHex();
4575
- log15.trace("dxos.sdk.invitation-handler.host.introduce", trace6.begin({
5082
+ log16.trace("dxos.sdk.invitation-handler.host.introduce", trace6.begin({
4576
5083
  id: traceId
4577
5084
  }), {
4578
- F: __dxlog_file18,
4579
- L: 110,
5085
+ F: __dxlog_file19,
5086
+ L: 114,
4580
5087
  S: this,
4581
5088
  C: (f, a) => f(...a)
4582
5089
  });
4583
5090
  const invitation = this._requireActiveInvitation();
4584
- this._assertInvitationState(Invitation4.State.CONNECTED);
5091
+ this._assertInvitationState(Invitation5.State.CONNECTED);
4585
5092
  if (invitationId !== invitation?.invitationId) {
4586
- log15.warn("incorrect invitationId", {
5093
+ log16.warn("incorrect invitationId", {
4587
5094
  expected: invitation.invitationId,
4588
5095
  actual: invitationId
4589
5096
  }, {
4590
- F: __dxlog_file18,
4591
- L: 115,
5097
+ F: __dxlog_file19,
5098
+ L: 119,
4592
5099
  S: this,
4593
5100
  C: (f, a) => f(...a)
4594
5101
  });
4595
5102
  this._callbacks.onError(new Error("Incorrect invitationId."));
4596
- scheduleTask5(this._ctx, () => this.close());
5103
+ scheduleTask6(this._ctx, () => this.close());
4597
5104
  return {
4598
- authMethod: Invitation4.AuthMethod.NONE
5105
+ authMethod: Invitation5.AuthMethod.NONE
4599
5106
  };
4600
5107
  }
4601
- log15("guest introduced themselves", {
5108
+ log16("guest introduced themselves", {
4602
5109
  guestProfile: profile
4603
5110
  }, {
4604
- F: __dxlog_file18,
4605
- L: 124,
5111
+ F: __dxlog_file19,
5112
+ L: 128,
4606
5113
  S: this,
4607
5114
  C: (f, a) => f(...a)
4608
5115
  });
4609
5116
  this.guestProfile = profile;
4610
- this._callbacks.onStateUpdate(Invitation4.State.READY_FOR_AUTHENTICATION);
4611
- this._challenge = invitation.authMethod === Invitation4.AuthMethod.KNOWN_PUBLIC_KEY ? randomBytes(32) : void 0;
4612
- log15.trace("dxos.sdk.invitation-handler.host.introduce", trace6.end({
5117
+ this._callbacks.onStateUpdate(Invitation5.State.READY_FOR_AUTHENTICATION);
5118
+ this._challenge = invitation.authMethod === Invitation5.AuthMethod.KNOWN_PUBLIC_KEY ? randomBytes(32) : void 0;
5119
+ log16.trace("dxos.sdk.invitation-handler.host.introduce", trace6.end({
4613
5120
  id: traceId
4614
5121
  }), {
4615
- F: __dxlog_file18,
4616
- L: 130,
5122
+ F: __dxlog_file19,
5123
+ L: 134,
4617
5124
  S: this,
4618
5125
  C: (f, a) => f(...a)
4619
5126
  });
@@ -4624,34 +5131,34 @@ var InvitationHostExtension = class extends RpcExtension3 {
4624
5131
  },
4625
5132
  authenticate: async ({ authCode: code, signedChallenge }) => {
4626
5133
  const traceId = PublicKey9.random().toHex();
4627
- log15.trace("dxos.sdk.invitation-handler.host.authenticate", trace6.begin({
5134
+ log16.trace("dxos.sdk.invitation-handler.host.authenticate", trace6.begin({
4628
5135
  id: traceId
4629
5136
  }), {
4630
- F: __dxlog_file18,
4631
- L: 139,
5137
+ F: __dxlog_file19,
5138
+ L: 143,
4632
5139
  S: this,
4633
5140
  C: (f, a) => f(...a)
4634
5141
  });
4635
5142
  const invitation = this._requireActiveInvitation();
4636
- log15("received authentication request", {
5143
+ log16("received authentication request", {
4637
5144
  authCode: code
4638
5145
  }, {
4639
- F: __dxlog_file18,
4640
- L: 142,
5146
+ F: __dxlog_file19,
5147
+ L: 146,
4641
5148
  S: this,
4642
5149
  C: (f, a) => f(...a)
4643
5150
  });
4644
5151
  let status = AuthenticationResponse.Status.OK;
4645
5152
  this._assertInvitationState([
4646
- Invitation4.State.AUTHENTICATING,
4647
- Invitation4.State.READY_FOR_AUTHENTICATION
5153
+ Invitation5.State.AUTHENTICATING,
5154
+ Invitation5.State.READY_FOR_AUTHENTICATION
4648
5155
  ]);
4649
- this._callbacks.onStateUpdate(Invitation4.State.AUTHENTICATING);
5156
+ this._callbacks.onStateUpdate(Invitation5.State.AUTHENTICATING);
4650
5157
  switch (invitation.authMethod) {
4651
- case Invitation4.AuthMethod.NONE: {
4652
- log15("authentication not required", void 0, {
4653
- F: __dxlog_file18,
4654
- L: 150,
5158
+ case Invitation5.AuthMethod.NONE: {
5159
+ log16("authentication not required", void 0, {
5160
+ F: __dxlog_file19,
5161
+ L: 154,
4655
5162
  S: this,
4656
5163
  C: (f, a) => f(...a)
4657
5164
  });
@@ -4659,7 +5166,7 @@ var InvitationHostExtension = class extends RpcExtension3 {
4659
5166
  status: AuthenticationResponse.Status.OK
4660
5167
  };
4661
5168
  }
4662
- case Invitation4.AuthMethod.SHARED_SECRET: {
5169
+ case Invitation5.AuthMethod.SHARED_SECRET: {
4663
5170
  if (invitation.authCode) {
4664
5171
  if (this.authenticationRetry++ > MAX_OTP_ATTEMPTS) {
4665
5172
  status = AuthenticationResponse.Status.INVALID_OPT_ATTEMPTS;
@@ -4671,7 +5178,7 @@ var InvitationHostExtension = class extends RpcExtension3 {
4671
5178
  }
4672
5179
  break;
4673
5180
  }
4674
- case Invitation4.AuthMethod.KNOWN_PUBLIC_KEY: {
5181
+ case Invitation5.AuthMethod.KNOWN_PUBLIC_KEY: {
4675
5182
  if (!invitation.guestKeypair) {
4676
5183
  status = AuthenticationResponse.Status.INTERNAL_ERROR;
4677
5184
  break;
@@ -4685,11 +5192,11 @@ var InvitationHostExtension = class extends RpcExtension3 {
4685
5192
  break;
4686
5193
  }
4687
5194
  default: {
4688
- log15.error("invalid authentication method", {
5195
+ log16.error("invalid authentication method", {
4689
5196
  authMethod: invitation.authMethod
4690
5197
  }, {
4691
- F: __dxlog_file18,
4692
- L: 188,
5198
+ F: __dxlog_file19,
5199
+ L: 192,
4693
5200
  S: this,
4694
5201
  C: (f, a) => f(...a)
4695
5202
  });
@@ -4702,19 +5209,19 @@ var InvitationHostExtension = class extends RpcExtension3 {
4702
5209
  AuthenticationResponse.Status.INVALID_OTP
4703
5210
  ].includes(status)) {
4704
5211
  this._callbacks.onError(new Error(`Authentication failed, with status=${status}`));
4705
- scheduleTask5(this._ctx, () => this.close());
5212
+ scheduleTask6(this._ctx, () => this.close());
4706
5213
  return {
4707
5214
  status
4708
5215
  };
4709
5216
  }
4710
- log15.trace("dxos.sdk.invitation-handler.host.authenticate", trace6.end({
5217
+ log16.trace("dxos.sdk.invitation-handler.host.authenticate", trace6.end({
4711
5218
  id: traceId,
4712
5219
  data: {
4713
5220
  status
4714
5221
  }
4715
5222
  }), {
4716
- F: __dxlog_file18,
4717
- L: 200,
5223
+ F: __dxlog_file19,
5224
+ L: 204,
4718
5225
  S: this,
4719
5226
  C: (f, a) => f(...a)
4720
5227
  });
@@ -4724,28 +5231,28 @@ var InvitationHostExtension = class extends RpcExtension3 {
4724
5231
  },
4725
5232
  admit: async (request) => {
4726
5233
  const traceId = PublicKey9.random().toHex();
4727
- log15.trace("dxos.sdk.invitation-handler.host.admit", trace6.begin({
5234
+ log16.trace("dxos.sdk.invitation-handler.host.admit", trace6.begin({
4728
5235
  id: traceId
4729
5236
  }), {
4730
- F: __dxlog_file18,
4731
- L: 206,
5237
+ F: __dxlog_file19,
5238
+ L: 210,
4732
5239
  S: this,
4733
5240
  C: (f, a) => f(...a)
4734
5241
  });
4735
5242
  const invitation = this._requireActiveInvitation();
4736
5243
  try {
4737
5244
  if (isAuthenticationRequired(invitation)) {
4738
- this._assertInvitationState(Invitation4.State.AUTHENTICATING);
5245
+ this._assertInvitationState(Invitation5.State.AUTHENTICATING);
4739
5246
  if (!this.authenticationPassed) {
4740
5247
  throw new Error("Not authenticated");
4741
5248
  }
4742
5249
  }
4743
5250
  const response = await this._callbacks.admit(request);
4744
- log15.trace("dxos.sdk.invitation-handler.host.admit", trace6.end({
5251
+ log16.trace("dxos.sdk.invitation-handler.host.admit", trace6.end({
4745
5252
  id: traceId
4746
5253
  }), {
4747
- F: __dxlog_file18,
4748
- L: 220,
5254
+ F: __dxlog_file19,
5255
+ L: 224,
4749
5256
  S: this,
4750
5257
  C: (f, a) => f(...a)
4751
5258
  });
@@ -4761,36 +5268,36 @@ var InvitationHostExtension = class extends RpcExtension3 {
4761
5268
  async onOpen(context) {
4762
5269
  await super.onOpen(context);
4763
5270
  try {
4764
- log15("host acquire lock", void 0, {
4765
- F: __dxlog_file18,
4766
- L: 235,
5271
+ log16("host acquire lock", void 0, {
5272
+ F: __dxlog_file19,
5273
+ L: 239,
4767
5274
  S: this,
4768
5275
  C: (f, a) => f(...a)
4769
5276
  });
4770
5277
  this._invitationFlowLock = await tryAcquireBeforeContextDisposed(this._ctx, this._invitationFlowMutex);
4771
- log15("host lock acquired", void 0, {
4772
- F: __dxlog_file18,
4773
- L: 237,
5278
+ log16("host lock acquired", void 0, {
5279
+ F: __dxlog_file19,
5280
+ L: 241,
4774
5281
  S: this,
4775
5282
  C: (f, a) => f(...a)
4776
5283
  });
4777
5284
  const lastState = this._requireActiveInvitation().state;
4778
- this._callbacks.onStateUpdate(Invitation4.State.CONNECTING);
5285
+ this._callbacks.onStateUpdate(Invitation5.State.CONNECTING);
4779
5286
  await this.rpc.InvitationHostService.options({
4780
5287
  role: InvitationOptions2.Role.HOST
4781
5288
  });
4782
- log15("options sent", void 0, {
4783
- F: __dxlog_file18,
4784
- L: 241,
5289
+ log16("options sent", void 0, {
5290
+ F: __dxlog_file19,
5291
+ L: 245,
4785
5292
  S: this,
4786
5293
  C: (f, a) => f(...a)
4787
5294
  });
4788
5295
  await cancelWithContext5(this._ctx, this._remoteOptionsTrigger.wait({
4789
5296
  timeout: OPTIONS_TIMEOUT2
4790
5297
  }));
4791
- log15("options received", void 0, {
4792
- F: __dxlog_file18,
4793
- L: 243,
5298
+ log16("options received", void 0, {
5299
+ F: __dxlog_file19,
5300
+ L: 247,
4794
5301
  S: this,
4795
5302
  C: (f, a) => f(...a)
4796
5303
  });
@@ -4802,7 +5309,7 @@ var InvitationHostExtension = class extends RpcExtension3 {
4802
5309
  remotePeerId: context.remotePeerId
4803
5310
  });
4804
5311
  }
4805
- this._callbacks.onStateUpdate(Invitation4.State.CONNECTED);
5312
+ this._callbacks.onStateUpdate(Invitation5.State.CONNECTED);
4806
5313
  this._callbacks.onOpen(this._ctx, context);
4807
5314
  } catch (err) {
4808
5315
  if (this._invitationFlowLock != null) {
@@ -4816,7 +5323,7 @@ var InvitationHostExtension = class extends RpcExtension3 {
4816
5323
  _requireActiveInvitation() {
4817
5324
  const invitation = this._callbacks.activeInvitation;
4818
5325
  if (invitation == null) {
4819
- scheduleTask5(this._ctx, () => this.close());
5326
+ scheduleTask6(this._ctx, () => this.close());
4820
5327
  throw new Error("Active invitation not found");
4821
5328
  }
4822
5329
  return invitation;
@@ -4827,7 +5334,7 @@ var InvitationHostExtension = class extends RpcExtension3 {
4827
5334
  stateOrMany
4828
5335
  ];
4829
5336
  if (!validStates.includes(invitation.state)) {
4830
- scheduleTask5(this._ctx, () => this.close());
5337
+ scheduleTask6(this._ctx, () => this.close());
4831
5338
  throw new InvariantViolation(`Expected ${stateToString(invitation.state)} to be one of [${validStates.map(stateToString).join(", ")}]`);
4832
5339
  }
4833
5340
  }
@@ -4842,32 +5349,127 @@ var InvitationHostExtension = class extends RpcExtension3 {
4842
5349
  if (this._invitationFlowLock != null) {
4843
5350
  this._invitationFlowLock?.release();
4844
5351
  this._invitationFlowLock = null;
4845
- log15("invitation flow lock released", void 0, {
4846
- F: __dxlog_file18,
4847
- L: 298,
5352
+ log16("invitation flow lock released", void 0, {
5353
+ F: __dxlog_file19,
5354
+ L: 302,
4848
5355
  S: this,
4849
5356
  C: (f, a) => f(...a)
4850
5357
  });
4851
5358
  }
4852
5359
  }
4853
5360
  };
4854
- var isAuthenticationRequired = (invitation) => invitation.authMethod !== Invitation4.AuthMethod.NONE;
5361
+ var isAuthenticationRequired = (invitation) => invitation.authMethod !== Invitation5.AuthMethod.NONE;
5362
+
5363
+ // packages/sdk/client-services/src/packlets/invitations/invitation-state.ts
5364
+ import { Mutex as Mutex3 } from "@dxos/async";
5365
+ import { log as log17 } from "@dxos/log";
5366
+ import { Invitation as Invitation6 } from "@dxos/protocols/proto/dxos/client/services";
5367
+ var __dxlog_file20 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-state.ts";
5368
+ var createGuardedInvitationState = (ctx, invitation, stream) => {
5369
+ const mutex = new Mutex3();
5370
+ let lastActiveLockHolder = null;
5371
+ let currentInvitation = {
5372
+ ...invitation
5373
+ };
5374
+ const isStateChangeAllowed = (lockHolder) => {
5375
+ if (ctx.disposed || lockHolder !== null && mutex.isLocked() && !lockHolder.hasFlowLock()) {
5376
+ return false;
5377
+ }
5378
+ return lockHolder == null || lastActiveLockHolder !== lockHolder || isNonTerminalState(currentInvitation.state);
5379
+ };
5380
+ return {
5381
+ mutex,
5382
+ get current() {
5383
+ return currentInvitation;
5384
+ },
5385
+ // disposing context prevents any further state updates
5386
+ complete: (newState) => {
5387
+ currentInvitation = {
5388
+ ...currentInvitation,
5389
+ ...newState
5390
+ };
5391
+ stream.next(currentInvitation);
5392
+ return ctx.dispose();
5393
+ },
5394
+ set: (lockHolder, newState) => {
5395
+ if (isStateChangeAllowed(lockHolder)) {
5396
+ logStateUpdate(currentInvitation, lockHolder, newState);
5397
+ currentInvitation = {
5398
+ ...currentInvitation,
5399
+ state: newState
5400
+ };
5401
+ stream.next(currentInvitation);
5402
+ lastActiveLockHolder = lockHolder;
5403
+ return true;
5404
+ }
5405
+ return false;
5406
+ },
5407
+ error: (lockHolder, error) => {
5408
+ if (isStateChangeAllowed(lockHolder)) {
5409
+ logStateUpdate(currentInvitation, lockHolder, Invitation6.State.ERROR);
5410
+ currentInvitation = {
5411
+ ...currentInvitation,
5412
+ state: Invitation6.State.ERROR
5413
+ };
5414
+ stream.next(currentInvitation);
5415
+ stream.error(error);
5416
+ lastActiveLockHolder = lockHolder;
5417
+ return true;
5418
+ }
5419
+ return false;
5420
+ }
5421
+ };
5422
+ };
5423
+ var logStateUpdate = (invitation, actor, newState) => {
5424
+ if (isNonTerminalState(newState)) {
5425
+ log17("invitation state update", {
5426
+ actor: actor?.constructor.name,
5427
+ newState: stateToString(newState),
5428
+ oldState: stateToString(invitation.state)
5429
+ }, {
5430
+ F: __dxlog_file20,
5431
+ L: 89,
5432
+ S: void 0,
5433
+ C: (f, a) => f(...a)
5434
+ });
5435
+ } else {
5436
+ log17.info("invitation state update", {
5437
+ actor: actor?.constructor.name,
5438
+ newState: stateToString(newState),
5439
+ oldState: stateToString(invitation.state)
5440
+ }, {
5441
+ F: __dxlog_file20,
5442
+ L: 95,
5443
+ S: void 0,
5444
+ C: (f, a) => f(...a)
5445
+ });
5446
+ }
5447
+ };
5448
+ var isNonTerminalState = (currentState) => {
5449
+ return ![
5450
+ Invitation6.State.SUCCESS,
5451
+ Invitation6.State.ERROR,
5452
+ Invitation6.State.CANCELLED,
5453
+ Invitation6.State.TIMEOUT,
5454
+ Invitation6.State.EXPIRED
5455
+ ].includes(currentState);
5456
+ };
4855
5457
 
4856
5458
  // packages/sdk/client-services/src/packlets/invitations/invitation-topology.ts
4857
- import { invariant as invariant13 } from "@dxos/invariant";
5459
+ import { invariant as invariant14 } from "@dxos/invariant";
4858
5460
  import { PublicKey as PublicKey10 } from "@dxos/keys";
4859
- import { log as log16 } from "@dxos/log";
5461
+ import { log as log18 } from "@dxos/log";
4860
5462
  import { InvitationOptions as InvitationOptions3 } from "@dxos/protocols/proto/dxos/halo/invitations";
4861
5463
  import { ComplexSet as ComplexSet4 } from "@dxos/util";
4862
- var __dxlog_file19 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-topology.ts";
5464
+ var __dxlog_file21 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-topology.ts";
4863
5465
  var InvitationTopology = class {
4864
5466
  constructor(_role) {
4865
5467
  this._role = _role;
4866
5468
  this._seenPeers = new ComplexSet4(PublicKey10.hash);
4867
5469
  }
4868
5470
  init(controller) {
4869
- invariant13(!this._controller, "Already initialized.", {
4870
- F: __dxlog_file19,
5471
+ invariant14(!this._controller, "Already initialized.", {
5472
+ F: __dxlog_file21,
4871
5473
  L: 42,
4872
5474
  S: this,
4873
5475
  A: [
@@ -4878,8 +5480,8 @@ var InvitationTopology = class {
4878
5480
  this._controller = controller;
4879
5481
  }
4880
5482
  update() {
4881
- invariant13(this._controller, "Not initialized.", {
4882
- F: __dxlog_file19,
5483
+ invariant14(this._controller, "Not initialized.", {
5484
+ F: __dxlog_file21,
4883
5485
  L: 47,
4884
5486
  S: this,
4885
5487
  A: [
@@ -4898,11 +5500,11 @@ var InvitationTopology = class {
4898
5500
  const firstUnknownPeer = candidates.find((peerId) => !this._seenPeers.has(peerId));
4899
5501
  this._seenPeers = new ComplexSet4(PublicKey10.hash, allPeers.filter((peerId) => this._seenPeers.has(peerId)));
4900
5502
  if (firstUnknownPeer != null) {
4901
- log16("invitation connect", {
5503
+ log18("invitation connect", {
4902
5504
  ownPeerId,
4903
5505
  remotePeerId: firstUnknownPeer
4904
5506
  }, {
4905
- F: __dxlog_file19,
5507
+ F: __dxlog_file21,
4906
5508
  L: 69,
4907
5509
  S: this,
4908
5510
  C: (f, a) => f(...a)
@@ -4912,8 +5514,8 @@ var InvitationTopology = class {
4912
5514
  }
4913
5515
  }
4914
5516
  async onOffer(peer) {
4915
- invariant13(this._controller, "Not initialized.", {
4916
- F: __dxlog_file19,
5517
+ invariant14(this._controller, "Not initialized.", {
5518
+ F: __dxlog_file21,
4917
5519
  L: 76,
4918
5520
  S: this,
4919
5521
  A: [
@@ -4932,20 +5534,21 @@ var InvitationTopology = class {
4932
5534
  };
4933
5535
 
4934
5536
  // packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
4935
- var __dxlog_file20 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts";
5537
+ var __dxlog_file22 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts";
4936
5538
  var metrics = _trace.metrics;
4937
5539
  var MAX_DELEGATED_INVITATION_HOST_TRIES = 3;
4938
5540
  var InvitationsHandler = class {
4939
5541
  /**
4940
5542
  * @internal
4941
5543
  */
4942
- constructor(_networkManager, _defaultTeleportParams) {
5544
+ constructor(_networkManager, _edgeClient, _connectionParams) {
4943
5545
  this._networkManager = _networkManager;
4944
- this._defaultTeleportParams = _defaultTeleportParams;
5546
+ this._edgeClient = _edgeClient;
5547
+ this._connectionParams = _connectionParams;
4945
5548
  }
4946
5549
  handleInvitationFlow(ctx, stream, protocol, invitation) {
4947
5550
  metrics.increment("dxos.invitation.created");
4948
- const guardedState = this._createGuardedState(ctx, invitation, stream);
5551
+ const guardedState = createGuardedInvitationState(ctx, invitation, stream);
4949
5552
  const createExtension = () => {
4950
5553
  const extension = new InvitationHostExtension(guardedState.mutex, {
4951
5554
  get activeInvitation() {
@@ -4958,9 +5561,9 @@ var InvitationsHandler = class {
4958
5561
  admit: async (admissionRequest) => {
4959
5562
  try {
4960
5563
  const deviceKey = admissionRequest.device?.deviceKey ?? admissionRequest.space?.deviceKey;
4961
- invariant14(deviceKey, void 0, {
4962
- F: __dxlog_file20,
4963
- L: 94,
5564
+ invariant15(deviceKey, void 0, {
5565
+ F: __dxlog_file22,
5566
+ L: 100,
4964
5567
  S: this,
4965
5568
  A: [
4966
5569
  "deviceKey",
@@ -4982,44 +5585,44 @@ var InvitationsHandler = class {
4982
5585
  guardedState.error(extension, new ContextDisposedError3());
4983
5586
  }
4984
5587
  });
4985
- scheduleTask6(connectionCtx, async () => {
5588
+ scheduleTask7(connectionCtx, async () => {
4986
5589
  const traceId = PublicKey11.random().toHex();
4987
5590
  try {
4988
- log17.trace("dxos.sdk.invitations-handler.host.onOpen", trace7.begin({
5591
+ log19.trace("dxos.sdk.invitations-handler.host.onOpen", trace7.begin({
4989
5592
  id: traceId
4990
5593
  }), {
4991
- F: __dxlog_file20,
4992
- L: 119,
5594
+ F: __dxlog_file22,
5595
+ L: 125,
4993
5596
  S: this,
4994
5597
  C: (f, a) => f(...a)
4995
5598
  });
4996
- log17("connected", {
5599
+ log19("connected", {
4997
5600
  ...protocol.toJSON()
4998
5601
  }, {
4999
- F: __dxlog_file20,
5000
- L: 120,
5602
+ F: __dxlog_file22,
5603
+ L: 126,
5001
5604
  S: this,
5002
5605
  C: (f, a) => f(...a)
5003
5606
  });
5004
5607
  const deviceKey = await extension.completedTrigger.wait({
5005
5608
  timeout: invitation.timeout
5006
5609
  });
5007
- log17("admitted guest", {
5610
+ log19("admitted guest", {
5008
5611
  guest: deviceKey,
5009
5612
  ...protocol.toJSON()
5010
5613
  }, {
5011
- F: __dxlog_file20,
5012
- L: 122,
5614
+ F: __dxlog_file22,
5615
+ L: 128,
5013
5616
  S: this,
5014
5617
  C: (f, a) => f(...a)
5015
5618
  });
5016
- guardedState.set(extension, Invitation5.State.SUCCESS);
5619
+ guardedState.set(extension, Invitation7.State.SUCCESS);
5017
5620
  metrics.increment("dxos.invitation.success");
5018
- log17.trace("dxos.sdk.invitations-handler.host.onOpen", trace7.end({
5621
+ log19.trace("dxos.sdk.invitations-handler.host.onOpen", trace7.end({
5019
5622
  id: traceId
5020
5623
  }), {
5021
- F: __dxlog_file20,
5022
- L: 125,
5624
+ F: __dxlog_file22,
5625
+ L: 131,
5023
5626
  S: this,
5024
5627
  C: (f, a) => f(...a)
5025
5628
  });
@@ -5029,13 +5632,13 @@ var InvitationsHandler = class {
5029
5632
  }
5030
5633
  } catch (err) {
5031
5634
  if (err instanceof TimeoutError2) {
5032
- if (guardedState.set(extension, Invitation5.State.TIMEOUT)) {
5635
+ if (guardedState.set(extension, Invitation7.State.TIMEOUT)) {
5033
5636
  metrics.increment("dxos.invitation.timeout");
5034
- log17("timeout", {
5637
+ log19("timeout", {
5035
5638
  ...protocol.toJSON()
5036
5639
  }, {
5037
- F: __dxlog_file20,
5038
- L: 135,
5640
+ F: __dxlog_file22,
5641
+ L: 141,
5039
5642
  S: this,
5040
5643
  C: (f, a) => f(...a)
5041
5644
  });
@@ -5043,20 +5646,20 @@ var InvitationsHandler = class {
5043
5646
  } else {
5044
5647
  if (guardedState.error(extension, err)) {
5045
5648
  metrics.increment("dxos.invitation.failed");
5046
- log17.error("failed", err, {
5047
- F: __dxlog_file20,
5048
- L: 140,
5649
+ log19.error("failed", err, {
5650
+ F: __dxlog_file22,
5651
+ L: 146,
5049
5652
  S: this,
5050
5653
  C: (f, a) => f(...a)
5051
5654
  });
5052
5655
  }
5053
5656
  }
5054
- log17.trace("dxos.sdk.invitations-handler.host.onOpen", trace7.error({
5657
+ log19.trace("dxos.sdk.invitations-handler.host.onOpen", trace7.error({
5055
5658
  id: traceId,
5056
5659
  error: err
5057
5660
  }), {
5058
- F: __dxlog_file20,
5059
- L: 143,
5661
+ F: __dxlog_file22,
5662
+ L: 149,
5060
5663
  S: this,
5061
5664
  C: (f, a) => f(...a)
5062
5665
  });
@@ -5066,24 +5669,24 @@ var InvitationsHandler = class {
5066
5669
  },
5067
5670
  onError: (err) => {
5068
5671
  if (err instanceof InvalidInvitationExtensionRoleError3) {
5069
- log17("invalid role", {
5672
+ log19("invalid role", {
5070
5673
  ...err.context
5071
5674
  }, {
5072
- F: __dxlog_file20,
5073
- L: 151,
5675
+ F: __dxlog_file22,
5676
+ L: 157,
5074
5677
  S: this,
5075
5678
  C: (f, a) => f(...a)
5076
5679
  });
5077
5680
  return;
5078
5681
  }
5079
5682
  if (err instanceof TimeoutError2) {
5080
- if (guardedState.set(extension, Invitation5.State.TIMEOUT)) {
5683
+ if (guardedState.set(extension, Invitation7.State.TIMEOUT)) {
5081
5684
  metrics.increment("dxos.invitation.timeout");
5082
- log17("timeout", {
5685
+ log19("timeout", {
5083
5686
  err
5084
5687
  }, {
5085
- F: __dxlog_file20,
5086
- L: 157,
5688
+ F: __dxlog_file22,
5689
+ L: 163,
5087
5690
  S: this,
5088
5691
  C: (f, a) => f(...a)
5089
5692
  });
@@ -5091,9 +5694,9 @@ var InvitationsHandler = class {
5091
5694
  } else {
5092
5695
  if (guardedState.error(extension, err)) {
5093
5696
  metrics.increment("dxos.invitation.failed");
5094
- log17.error("failed", err, {
5095
- F: __dxlog_file20,
5096
- L: 162,
5697
+ log19.error("failed", err, {
5698
+ F: __dxlog_file22,
5699
+ L: 168,
5097
5700
  S: this,
5098
5701
  C: (f, a) => f(...a)
5099
5702
  });
@@ -5105,33 +5708,33 @@ var InvitationsHandler = class {
5105
5708
  };
5106
5709
  if (invitation.lifetime && invitation.created) {
5107
5710
  if (invitation.created.getTime() + invitation.lifetime * 1e3 < Date.now()) {
5108
- log17.warn("invitation has already expired", void 0, {
5109
- F: __dxlog_file20,
5110
- L: 173,
5711
+ log19.warn("invitation has already expired", void 0, {
5712
+ F: __dxlog_file22,
5713
+ L: 179,
5111
5714
  S: this,
5112
5715
  C: (f, a) => f(...a)
5113
5716
  });
5114
5717
  } else {
5115
- scheduleTask6(ctx, async () => {
5718
+ scheduleTask7(ctx, async () => {
5116
5719
  await swarmConnection.close();
5117
- guardedState.set(null, Invitation5.State.EXPIRED);
5720
+ guardedState.set(null, Invitation7.State.EXPIRED);
5118
5721
  metrics.increment("dxos.invitation.expired");
5119
5722
  await ctx.dispose();
5120
5723
  }, invitation.created.getTime() + invitation.lifetime * 1e3 - Date.now());
5121
5724
  }
5122
5725
  }
5123
5726
  let swarmConnection;
5124
- scheduleTask6(ctx, async () => {
5727
+ scheduleTask7(ctx, async () => {
5125
5728
  swarmConnection = await this._joinSwarm(ctx, invitation, InvitationOptions4.Role.HOST, createExtension);
5126
- guardedState.set(null, Invitation5.State.CONNECTING);
5729
+ guardedState.set(null, Invitation7.State.CONNECTING);
5127
5730
  });
5128
5731
  }
5129
5732
  acceptInvitation(ctx, stream, protocol, invitation, otpEnteredTrigger, deviceProfile) {
5130
5733
  const { timeout = INVITATION_TIMEOUT } = invitation;
5131
5734
  if (deviceProfile) {
5132
- invariant14(invitation.kind === Invitation5.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
5133
- F: __dxlog_file20,
5134
- L: 207,
5735
+ invariant15(invitation.kind === Invitation7.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
5736
+ F: __dxlog_file22,
5737
+ L: 213,
5135
5738
  S: this,
5136
5739
  A: [
5137
5740
  "invitation.kind === Invitation.Kind.DEVICE",
@@ -5140,23 +5743,23 @@ var InvitationsHandler = class {
5140
5743
  });
5141
5744
  }
5142
5745
  const triedPeersIds = new ComplexSet5(PublicKey11.hash);
5143
- const guardedState = this._createGuardedState(ctx, invitation, stream);
5746
+ const guardedState = createGuardedInvitationState(ctx, invitation, stream);
5144
5747
  const shouldCancelInvitationFlow = (extension) => {
5145
5748
  const isLockedByAnotherConnection = guardedState.mutex.isLocked() && !extension.hasFlowLock();
5146
- log17("should cancel invitation flow", {
5749
+ log19("should cancel invitation flow", {
5147
5750
  isLockedByAnotherConnection,
5148
- invitationType: Invitation5.Type.DELEGATED,
5751
+ invitationType: Invitation7.Type.DELEGATED,
5149
5752
  triedPeers: triedPeersIds.size
5150
5753
  }, {
5151
- F: __dxlog_file20,
5152
- L: 215,
5754
+ F: __dxlog_file22,
5755
+ L: 221,
5153
5756
  S: this,
5154
5757
  C: (f, a) => f(...a)
5155
5758
  });
5156
5759
  if (isLockedByAnotherConnection) {
5157
5760
  return false;
5158
5761
  }
5159
- return invitation.type !== Invitation5.Type.DELEGATED || triedPeersIds.size >= MAX_DELEGATED_INVITATION_HOST_TRIES;
5762
+ return invitation.type !== Invitation7.Type.DELEGATED || triedPeersIds.size >= MAX_DELEGATED_INVITATION_HOST_TRIES;
5160
5763
  };
5161
5764
  let admitted = false;
5162
5765
  const createExtension = () => {
@@ -5171,12 +5774,12 @@ var InvitationsHandler = class {
5171
5774
  return;
5172
5775
  }
5173
5776
  connectionCtx.onDispose(async () => {
5174
- log17("extension disposed", {
5777
+ log19("extension disposed", {
5175
5778
  admitted,
5176
5779
  currentState: guardedState.current.state
5177
5780
  }, {
5178
- F: __dxlog_file20,
5179
- L: 243,
5781
+ F: __dxlog_file22,
5782
+ L: 249,
5180
5783
  S: this,
5181
5784
  C: (f, a) => f(...a)
5182
5785
  });
@@ -5187,35 +5790,35 @@ var InvitationsHandler = class {
5187
5790
  }
5188
5791
  }
5189
5792
  });
5190
- scheduleTask6(connectionCtx, async () => {
5793
+ scheduleTask7(connectionCtx, async () => {
5191
5794
  const traceId = PublicKey11.random().toHex();
5192
5795
  try {
5193
- log17.trace("dxos.sdk.invitations-handler.guest.onOpen", trace7.begin({
5796
+ log19.trace("dxos.sdk.invitations-handler.guest.onOpen", trace7.begin({
5194
5797
  id: traceId
5195
5798
  }), {
5196
- F: __dxlog_file20,
5197
- L: 255,
5799
+ F: __dxlog_file22,
5800
+ L: 261,
5198
5801
  S: this,
5199
5802
  C: (f, a) => f(...a)
5200
5803
  });
5201
- scheduleTask6(connectionCtx, () => {
5202
- guardedState.set(extension, Invitation5.State.TIMEOUT);
5804
+ scheduleTask7(connectionCtx, () => {
5805
+ guardedState.set(extension, Invitation7.State.TIMEOUT);
5203
5806
  extensionCtx.close();
5204
5807
  }, timeout);
5205
- log17("connected", {
5808
+ log19("connected", {
5206
5809
  ...protocol.toJSON()
5207
5810
  }, {
5208
- F: __dxlog_file20,
5209
- L: 266,
5811
+ F: __dxlog_file22,
5812
+ L: 272,
5210
5813
  S: this,
5211
5814
  C: (f, a) => f(...a)
5212
5815
  });
5213
- guardedState.set(extension, Invitation5.State.CONNECTED);
5214
- log17("introduce", {
5816
+ guardedState.set(extension, Invitation7.State.CONNECTED);
5817
+ log19("introduce", {
5215
5818
  ...protocol.toJSON()
5216
5819
  }, {
5217
- F: __dxlog_file20,
5218
- L: 270,
5820
+ F: __dxlog_file22,
5821
+ L: 276,
5219
5822
  S: this,
5220
5823
  C: (f, a) => f(...a)
5221
5824
  });
@@ -5223,33 +5826,33 @@ var InvitationsHandler = class {
5223
5826
  invitationId: invitation.invitationId,
5224
5827
  ...protocol.createIntroduction()
5225
5828
  });
5226
- log17("introduce response", {
5829
+ log19("introduce response", {
5227
5830
  ...protocol.toJSON(),
5228
5831
  response: introductionResponse
5229
5832
  }, {
5230
- F: __dxlog_file20,
5231
- L: 275,
5833
+ F: __dxlog_file22,
5834
+ L: 281,
5232
5835
  S: this,
5233
5836
  C: (f, a) => f(...a)
5234
5837
  });
5235
5838
  invitation.authMethod = introductionResponse.authMethod;
5236
5839
  if (isAuthenticationRequired(invitation)) {
5237
5840
  switch (invitation.authMethod) {
5238
- case Invitation5.AuthMethod.SHARED_SECRET:
5841
+ case Invitation7.AuthMethod.SHARED_SECRET:
5239
5842
  await this._handleGuestOtpAuth(extension, (state) => guardedState.set(extension, state), otpEnteredTrigger, {
5240
5843
  timeout
5241
5844
  });
5242
5845
  break;
5243
- case Invitation5.AuthMethod.KNOWN_PUBLIC_KEY:
5846
+ case Invitation7.AuthMethod.KNOWN_PUBLIC_KEY:
5244
5847
  await this._handleGuestKpkAuth(extension, (state) => guardedState.set(extension, state), invitation, introductionResponse);
5245
5848
  break;
5246
5849
  }
5247
5850
  }
5248
- log17("request admission", {
5851
+ log19("request admission", {
5249
5852
  ...protocol.toJSON()
5250
5853
  }, {
5251
- F: __dxlog_file20,
5252
- L: 301,
5854
+ F: __dxlog_file22,
5855
+ L: 307,
5253
5856
  S: this,
5254
5857
  C: (f, a) => f(...a)
5255
5858
  });
@@ -5257,54 +5860,54 @@ var InvitationsHandler = class {
5257
5860
  const admissionResponse = await extension.rpc.InvitationHostService.admit(admissionRequest);
5258
5861
  admitted = true;
5259
5862
  const result = await protocol.accept(admissionResponse, admissionRequest);
5260
- log17("admitted by host", {
5863
+ log19("admitted by host", {
5261
5864
  ...protocol.toJSON()
5262
5865
  }, {
5263
- F: __dxlog_file20,
5264
- L: 312,
5866
+ F: __dxlog_file22,
5867
+ L: 318,
5265
5868
  S: this,
5266
5869
  C: (f, a) => f(...a)
5267
5870
  });
5268
- await guardedState.complete({
5871
+ guardedState.complete({
5269
5872
  ...guardedState.current,
5270
5873
  ...result,
5271
- state: Invitation5.State.SUCCESS
5874
+ state: Invitation7.State.SUCCESS
5272
5875
  });
5273
- log17.trace("dxos.sdk.invitations-handler.guest.onOpen", trace7.end({
5876
+ log19.trace("dxos.sdk.invitations-handler.guest.onOpen", trace7.end({
5274
5877
  id: traceId
5275
5878
  }), {
5276
- F: __dxlog_file20,
5277
- L: 318,
5879
+ F: __dxlog_file22,
5880
+ L: 324,
5278
5881
  S: this,
5279
5882
  C: (f, a) => f(...a)
5280
5883
  });
5281
5884
  } catch (err) {
5282
5885
  if (err instanceof TimeoutError2) {
5283
- log17("timeout", {
5886
+ log19("timeout", {
5284
5887
  ...protocol.toJSON()
5285
5888
  }, {
5286
- F: __dxlog_file20,
5287
- L: 321,
5889
+ F: __dxlog_file22,
5890
+ L: 327,
5288
5891
  S: this,
5289
5892
  C: (f, a) => f(...a)
5290
5893
  });
5291
- guardedState.set(extension, Invitation5.State.TIMEOUT);
5894
+ guardedState.set(extension, Invitation7.State.TIMEOUT);
5292
5895
  } else {
5293
- log17("auth failed", err, {
5294
- F: __dxlog_file20,
5295
- L: 324,
5896
+ log19("auth failed", err, {
5897
+ F: __dxlog_file22,
5898
+ L: 330,
5296
5899
  S: this,
5297
5900
  C: (f, a) => f(...a)
5298
5901
  });
5299
5902
  guardedState.error(extension, err);
5300
5903
  }
5301
5904
  extensionCtx.close(err);
5302
- log17.trace("dxos.sdk.invitations-handler.guest.onOpen", trace7.error({
5905
+ log19.trace("dxos.sdk.invitations-handler.guest.onOpen", trace7.error({
5303
5906
  id: traceId,
5304
5907
  error: err
5305
5908
  }), {
5306
- F: __dxlog_file20,
5307
- L: 328,
5909
+ F: __dxlog_file22,
5910
+ L: 334,
5308
5911
  S: this,
5309
5912
  C: (f, a) => f(...a)
5310
5913
  });
@@ -5316,19 +5919,19 @@ var InvitationsHandler = class {
5316
5919
  return;
5317
5920
  }
5318
5921
  if (err instanceof TimeoutError2) {
5319
- log17("timeout", {
5922
+ log19("timeout", {
5320
5923
  ...protocol.toJSON()
5321
5924
  }, {
5322
- F: __dxlog_file20,
5323
- L: 337,
5925
+ F: __dxlog_file22,
5926
+ L: 343,
5324
5927
  S: this,
5325
5928
  C: (f, a) => f(...a)
5326
5929
  });
5327
- guardedState.set(extension, Invitation5.State.TIMEOUT);
5930
+ guardedState.set(extension, Invitation7.State.TIMEOUT);
5328
5931
  } else {
5329
- log17("auth failed", err, {
5330
- F: __dxlog_file20,
5331
- L: 340,
5932
+ log19("auth failed", err, {
5933
+ F: __dxlog_file22,
5934
+ L: 346,
5332
5935
  S: this,
5333
5936
  C: (f, a) => f(...a)
5334
5937
  });
@@ -5338,15 +5941,34 @@ var InvitationsHandler = class {
5338
5941
  });
5339
5942
  return extension;
5340
5943
  };
5341
- scheduleTask6(ctx, async () => {
5944
+ const edgeInvitationHandler = new EdgeInvitationHandler(this._connectionParams?.edgeInvitations, this._edgeClient, {
5945
+ onInvitationSuccess: async (admissionResponse, admissionRequest) => {
5946
+ const result = await protocol.accept(admissionResponse, admissionRequest);
5947
+ log19("admitted by edge", {
5948
+ ...protocol.toJSON()
5949
+ }, {
5950
+ F: __dxlog_file22,
5951
+ L: 358,
5952
+ S: this,
5953
+ C: (f, a) => f(...a)
5954
+ });
5955
+ guardedState.complete({
5956
+ ...guardedState.current,
5957
+ ...result,
5958
+ state: Invitation7.State.SUCCESS
5959
+ });
5960
+ }
5961
+ });
5962
+ edgeInvitationHandler.handle(ctx, guardedState, protocol, deviceProfile);
5963
+ scheduleTask7(ctx, async () => {
5342
5964
  const error = protocol.checkInvitation(invitation);
5343
5965
  if (error) {
5344
5966
  stream.error(error);
5345
5967
  await ctx.dispose();
5346
5968
  } else {
5347
- invariant14(invitation.swarmKey, void 0, {
5348
- F: __dxlog_file20,
5349
- L: 355,
5969
+ invariant15(invitation.swarmKey, void 0, {
5970
+ F: __dxlog_file22,
5971
+ L: 370,
5350
5972
  S: this,
5351
5973
  A: [
5352
5974
  "invitation.swarmKey",
@@ -5355,14 +5977,14 @@ var InvitationsHandler = class {
5355
5977
  });
5356
5978
  const timeoutInactive = () => {
5357
5979
  if (guardedState.mutex.isLocked()) {
5358
- scheduleTask6(ctx, timeoutInactive, timeout);
5980
+ scheduleTask7(ctx, timeoutInactive, timeout);
5359
5981
  } else {
5360
- guardedState.set(null, Invitation5.State.TIMEOUT);
5982
+ guardedState.set(null, Invitation7.State.TIMEOUT);
5361
5983
  }
5362
5984
  };
5363
- scheduleTask6(ctx, timeoutInactive, timeout);
5985
+ scheduleTask7(ctx, timeoutInactive, timeout);
5364
5986
  await this._joinSwarm(ctx, invitation, InvitationOptions4.Role.GUEST, createExtension);
5365
- guardedState.set(null, Invitation5.State.CONNECTING);
5987
+ guardedState.set(null, Invitation7.State.CONNECTING);
5366
5988
  }
5367
5989
  });
5368
5990
  }
@@ -5370,7 +5992,7 @@ var InvitationsHandler = class {
5370
5992
  let label;
5371
5993
  if (role === InvitationOptions4.Role.GUEST) {
5372
5994
  label = "invitation guest";
5373
- } else if (invitation.kind === Invitation5.Kind.DEVICE) {
5995
+ } else if (invitation.kind === Invitation7.Kind.DEVICE) {
5374
5996
  label = "invitation host for device";
5375
5997
  } else {
5376
5998
  label = `invitation host for space ${invitation.spaceKey?.truncate()}`;
@@ -5379,123 +6001,30 @@ var InvitationsHandler = class {
5379
6001
  topic: invitation.swarmKey,
5380
6002
  protocolProvider: createTeleportProtocolFactory(async (teleport) => {
5381
6003
  teleport.addExtension("dxos.halo.invitations", extensionFactory());
5382
- }, this._defaultTeleportParams),
6004
+ }, this._connectionParams?.teleport),
5383
6005
  topology: new InvitationTopology(role),
5384
6006
  label
5385
6007
  });
5386
6008
  ctx.onDispose(() => swarmConnection.close());
5387
6009
  return swarmConnection;
5388
6010
  }
5389
- /**
5390
- * A utility object for serializing invitation state changes by multiple concurrent
5391
- * invitation flow connections.
5392
- */
5393
- _createGuardedState(ctx, invitation, stream) {
5394
- const mutex = new Mutex3();
5395
- let lastActiveExtension = null;
5396
- let currentInvitation = {
5397
- ...invitation
5398
- };
5399
- const isStateChangeAllowed = (extension) => {
5400
- if (ctx.disposed || extension !== null && mutex.isLocked() && !extension.hasFlowLock()) {
5401
- return false;
5402
- }
5403
- return extension == null || lastActiveExtension !== extension || this._isNotTerminal(currentInvitation.state);
5404
- };
5405
- return {
5406
- mutex,
5407
- get current() {
5408
- return currentInvitation;
5409
- },
5410
- // disposing context prevents any further state updates
5411
- complete: (newState) => {
5412
- currentInvitation = {
5413
- ...currentInvitation,
5414
- ...newState
5415
- };
5416
- stream.next(currentInvitation);
5417
- return ctx.dispose();
5418
- },
5419
- set: (extension, newState) => {
5420
- if (isStateChangeAllowed(extension)) {
5421
- this._logStateUpdate(currentInvitation, extension, newState);
5422
- currentInvitation = {
5423
- ...currentInvitation,
5424
- state: newState
5425
- };
5426
- stream.next(currentInvitation);
5427
- lastActiveExtension = extension;
5428
- return true;
5429
- }
5430
- return false;
5431
- },
5432
- error: (extension, error) => {
5433
- if (isStateChangeAllowed(extension)) {
5434
- this._logStateUpdate(currentInvitation, extension, Invitation5.State.ERROR);
5435
- currentInvitation = {
5436
- ...currentInvitation,
5437
- state: Invitation5.State.ERROR
5438
- };
5439
- stream.next(currentInvitation);
5440
- stream.error(error);
5441
- lastActiveExtension = extension;
5442
- return true;
5443
- }
5444
- return false;
5445
- }
5446
- };
5447
- }
5448
- _logStateUpdate(invitation, actor, newState) {
5449
- if (this._isNotTerminal(newState)) {
5450
- log17("invitation state update", {
5451
- actor: actor?.constructor.name,
5452
- newState: stateToString(newState),
5453
- oldState: stateToString(invitation.state)
5454
- }, {
5455
- F: __dxlog_file20,
5456
- L: 460,
5457
- S: this,
5458
- C: (f, a) => f(...a)
5459
- });
5460
- } else {
5461
- log17("invitation state update", {
5462
- actor: actor?.constructor.name,
5463
- newState: stateToString(newState),
5464
- oldState: stateToString(invitation.state)
5465
- }, {
5466
- F: __dxlog_file20,
5467
- L: 466,
5468
- S: this,
5469
- C: (f, a) => f(...a)
5470
- });
5471
- }
5472
- }
5473
- _isNotTerminal(currentState) {
5474
- return ![
5475
- Invitation5.State.SUCCESS,
5476
- Invitation5.State.ERROR,
5477
- Invitation5.State.CANCELLED,
5478
- Invitation5.State.TIMEOUT,
5479
- Invitation5.State.EXPIRED
5480
- ].includes(currentState);
5481
- }
5482
6011
  async _handleGuestOtpAuth(extension, setState, authenticated, options) {
5483
6012
  for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
5484
- log17("guest waiting for authentication code...", void 0, {
5485
- F: __dxlog_file20,
5486
- L: 491,
6013
+ log19("guest waiting for authentication code...", void 0, {
6014
+ F: __dxlog_file22,
6015
+ L: 422,
5487
6016
  S: this,
5488
6017
  C: (f, a) => f(...a)
5489
6018
  });
5490
- setState(Invitation5.State.READY_FOR_AUTHENTICATION);
6019
+ setState(Invitation7.State.READY_FOR_AUTHENTICATION);
5491
6020
  const authCode = await authenticated.wait(options);
5492
- log17("sending authentication request", void 0, {
5493
- F: __dxlog_file20,
5494
- L: 495,
6021
+ log19("sending authentication request", void 0, {
6022
+ F: __dxlog_file22,
6023
+ L: 426,
5495
6024
  S: this,
5496
6025
  C: (f, a) => f(...a)
5497
6026
  });
5498
- setState(Invitation5.State.AUTHENTICATING);
6027
+ setState(Invitation7.State.AUTHENTICATING);
5499
6028
  const response = await extension.rpc.InvitationHostService.authenticate({
5500
6029
  authCode
5501
6030
  });
@@ -5506,11 +6035,11 @@ var InvitationsHandler = class {
5506
6035
  if (attempt === MAX_OTP_ATTEMPTS) {
5507
6036
  throw new Error(`Maximum retry attempts: ${MAX_OTP_ATTEMPTS}`);
5508
6037
  } else {
5509
- log17("retrying invalid code", {
6038
+ log19("retrying invalid code", {
5510
6039
  attempt
5511
6040
  }, {
5512
- F: __dxlog_file20,
5513
- L: 506,
6041
+ F: __dxlog_file22,
6042
+ L: 437,
5514
6043
  S: this,
5515
6044
  C: (f, a) => f(...a)
5516
6045
  });
@@ -5526,13 +6055,13 @@ var InvitationsHandler = class {
5526
6055
  if (introductionResponse.challenge == null) {
5527
6056
  throw new Error("challenge missing in the introduction");
5528
6057
  }
5529
- log17("sending authentication request", void 0, {
5530
- F: __dxlog_file20,
5531
- L: 525,
6058
+ log19("sending authentication request", void 0, {
6059
+ F: __dxlog_file22,
6060
+ L: 456,
5532
6061
  S: this,
5533
6062
  C: (f, a) => f(...a)
5534
6063
  });
5535
- setState(Invitation5.State.AUTHENTICATING);
6064
+ setState(Invitation7.State.AUTHENTICATING);
5536
6065
  const signature = sign(Buffer.from(introductionResponse.challenge), invitation.guestKeypair.privateKey);
5537
6066
  const response = await extension.rpc.InvitationHostService.authenticate({
5538
6067
  signedChallenge: signature
@@ -5650,12 +6179,12 @@ var InvitationsServiceImpl = class {
5650
6179
  // packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts
5651
6180
  import { createCancelDelegatedSpaceInvitationCredential, createDelegatedSpaceInvitationCredential, getCredentialAssertion as getCredentialAssertion4 } from "@dxos/credentials";
5652
6181
  import { writeMessages as writeMessages4 } from "@dxos/feed-store";
5653
- import { invariant as invariant15 } from "@dxos/invariant";
5654
- import { log as log18 } from "@dxos/log";
6182
+ import { invariant as invariant16 } from "@dxos/invariant";
6183
+ import { log as log20 } from "@dxos/log";
5655
6184
  import { AlreadyJoinedError as AlreadyJoinedError3, AuthorizationError as AuthorizationError2, InvalidInvitationError, SpaceNotFoundError as SpaceNotFoundError2 } from "@dxos/protocols";
5656
- import { Invitation as Invitation6 } from "@dxos/protocols/proto/dxos/client/services";
6185
+ import { Invitation as Invitation8 } from "@dxos/protocols/proto/dxos/client/services";
5657
6186
  import { SpaceMember as SpaceMember6 } from "@dxos/protocols/proto/dxos/halo/credentials";
5658
- var __dxlog_file21 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
6187
+ var __dxlog_file23 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
5659
6188
  var SpaceInvitationProtocol = class {
5660
6189
  constructor(_spaceManager, _signingContext, _keyring, _spaceKey) {
5661
6190
  this._spaceManager = _spaceManager;
@@ -5683,27 +6212,47 @@ var SpaceInvitationProtocol = class {
5683
6212
  return void 0;
5684
6213
  }
5685
6214
  getInvitationContext() {
6215
+ invariant16(this._spaceKey, void 0, {
6216
+ F: __dxlog_file23,
6217
+ L: 63,
6218
+ S: this,
6219
+ A: [
6220
+ "this._spaceKey",
6221
+ ""
6222
+ ]
6223
+ });
6224
+ const space = this._spaceManager.spaces.get(this._spaceKey);
6225
+ invariant16(space, void 0, {
6226
+ F: __dxlog_file23,
6227
+ L: 65,
6228
+ S: this,
6229
+ A: [
6230
+ "space",
6231
+ ""
6232
+ ]
6233
+ });
5686
6234
  return {
5687
- kind: Invitation6.Kind.SPACE,
5688
- spaceKey: this._spaceKey
6235
+ kind: Invitation8.Kind.SPACE,
6236
+ spaceKey: this._spaceKey,
6237
+ spaceId: space.id
5689
6238
  };
5690
6239
  }
5691
6240
  async admit(invitation, request, guestProfile) {
5692
- invariant15(this._spaceKey && request.space, void 0, {
5693
- F: __dxlog_file21,
5694
- L: 74,
6241
+ invariant16(this._spaceKey && request.space, void 0, {
6242
+ F: __dxlog_file23,
6243
+ L: 78,
5695
6244
  S: this,
5696
6245
  A: [
5697
6246
  "this._spaceKey && request.space",
5698
6247
  ""
5699
6248
  ]
5700
6249
  });
5701
- log18("writing guest credentials", {
6250
+ log20("writing guest credentials", {
5702
6251
  host: this._signingContext.deviceKey,
5703
6252
  guest: request.space.deviceKey
5704
6253
  }, {
5705
- F: __dxlog_file21,
5706
- L: 75,
6254
+ F: __dxlog_file23,
6255
+ L: 79,
5707
6256
  S: this,
5708
6257
  C: (f, a) => f(...a)
5709
6258
  });
@@ -5723,29 +6272,29 @@ var SpaceInvitationProtocol = class {
5723
6272
  };
5724
6273
  }
5725
6274
  async delegate(invitation) {
5726
- invariant15(this._spaceKey, void 0, {
5727
- F: __dxlog_file21,
5728
- L: 95,
6275
+ invariant16(this._spaceKey, void 0, {
6276
+ F: __dxlog_file23,
6277
+ L: 99,
5729
6278
  S: this,
5730
6279
  A: [
5731
6280
  "this._spaceKey",
5732
6281
  ""
5733
6282
  ]
5734
6283
  });
5735
- const space = this._spaceManager.spaces.get(this._spaceKey);
5736
- invariant15(space, void 0, {
5737
- F: __dxlog_file21,
5738
- L: 97,
6284
+ const space = this._spaceManager.spaces.get(this._spaceKey);
6285
+ invariant16(space, void 0, {
6286
+ F: __dxlog_file23,
6287
+ L: 101,
5739
6288
  S: this,
5740
6289
  A: [
5741
6290
  "space",
5742
6291
  ""
5743
6292
  ]
5744
6293
  });
5745
- if (invitation.authMethod === Invitation6.AuthMethod.KNOWN_PUBLIC_KEY) {
5746
- invariant15(invitation.guestKeypair?.publicKey, void 0, {
5747
- F: __dxlog_file21,
5748
- L: 99,
6294
+ if (invitation.authMethod === Invitation8.AuthMethod.KNOWN_PUBLIC_KEY) {
6295
+ invariant16(invitation.guestKeypair?.publicKey, void 0, {
6296
+ F: __dxlog_file23,
6297
+ L: 103,
5749
6298
  S: this,
5750
6299
  A: [
5751
6300
  "invitation.guestKeypair?.publicKey",
@@ -5753,12 +6302,12 @@ var SpaceInvitationProtocol = class {
5753
6302
  ]
5754
6303
  });
5755
6304
  }
5756
- log18("writing delegate space invitation", {
6305
+ log20("writing delegate space invitation", {
5757
6306
  host: this._signingContext.deviceKey,
5758
6307
  id: invitation.invitationId
5759
6308
  }, {
5760
- F: __dxlog_file21,
5761
- L: 102,
6309
+ F: __dxlog_file23,
6310
+ L: 106,
5762
6311
  S: this,
5763
6312
  C: (f, a) => f(...a)
5764
6313
  });
@@ -5769,11 +6318,11 @@ var SpaceInvitationProtocol = class {
5769
6318
  role: invitation.role ?? SpaceMember6.Role.ADMIN,
5770
6319
  expiresOn: invitation.lifetime ? new Date((invitation.created?.getTime() ?? Date.now()) + invitation.lifetime) : void 0,
5771
6320
  multiUse: invitation.multiUse ?? false,
5772
- guestKey: invitation.authMethod === Invitation6.AuthMethod.KNOWN_PUBLIC_KEY ? invitation.guestKeypair.publicKey : void 0
6321
+ guestKey: invitation.authMethod === Invitation8.AuthMethod.KNOWN_PUBLIC_KEY ? invitation.guestKeypair.publicKey : void 0
5773
6322
  });
5774
- invariant15(credential.credential, void 0, {
5775
- F: __dxlog_file21,
5776
- L: 122,
6323
+ invariant16(credential.credential, void 0, {
6324
+ F: __dxlog_file23,
6325
+ L: 126,
5777
6326
  S: this,
5778
6327
  A: [
5779
6328
  "credential.credential",
@@ -5786,18 +6335,18 @@ var SpaceInvitationProtocol = class {
5786
6335
  return credential.credential.credential.id;
5787
6336
  }
5788
6337
  async cancelDelegation(invitation) {
5789
- invariant15(this._spaceKey, void 0, {
5790
- F: __dxlog_file21,
5791
- L: 128,
6338
+ invariant16(this._spaceKey, void 0, {
6339
+ F: __dxlog_file23,
6340
+ L: 132,
5792
6341
  S: this,
5793
6342
  A: [
5794
6343
  "this._spaceKey",
5795
6344
  ""
5796
6345
  ]
5797
6346
  });
5798
- invariant15(invitation.type === Invitation6.Type.DELEGATED && invitation.delegationCredentialId, void 0, {
5799
- F: __dxlog_file21,
5800
- L: 129,
6347
+ invariant16(invitation.type === Invitation8.Type.DELEGATED && invitation.delegationCredentialId, void 0, {
6348
+ F: __dxlog_file23,
6349
+ L: 133,
5801
6350
  S: this,
5802
6351
  A: [
5803
6352
  "invitation.type === Invitation.Type.DELEGATED && invitation.delegationCredentialId",
@@ -5805,28 +6354,28 @@ var SpaceInvitationProtocol = class {
5805
6354
  ]
5806
6355
  });
5807
6356
  const space = this._spaceManager.spaces.get(this._spaceKey);
5808
- invariant15(space, void 0, {
5809
- F: __dxlog_file21,
5810
- L: 131,
6357
+ invariant16(space, void 0, {
6358
+ F: __dxlog_file23,
6359
+ L: 135,
5811
6360
  S: this,
5812
6361
  A: [
5813
6362
  "space",
5814
6363
  ""
5815
6364
  ]
5816
6365
  });
5817
- log18("cancelling delegated space invitation", {
6366
+ log20("cancelling delegated space invitation", {
5818
6367
  host: this._signingContext.deviceKey,
5819
6368
  id: invitation.invitationId
5820
6369
  }, {
5821
- F: __dxlog_file21,
5822
- L: 133,
6370
+ F: __dxlog_file23,
6371
+ L: 137,
5823
6372
  S: this,
5824
6373
  C: (f, a) => f(...a)
5825
6374
  });
5826
6375
  const credential = await createCancelDelegatedSpaceInvitationCredential(this._signingContext.credentialSigner, space.key, invitation.delegationCredentialId);
5827
- invariant15(credential.credential, void 0, {
5828
- F: __dxlog_file21,
5829
- L: 140,
6376
+ invariant16(credential.credential, void 0, {
6377
+ F: __dxlog_file23,
6378
+ L: 144,
5830
6379
  S: this,
5831
6380
  A: [
5832
6381
  "credential.credential",
@@ -5863,9 +6412,9 @@ var SpaceInvitationProtocol = class {
5863
6412
  };
5864
6413
  }
5865
6414
  async accept(response) {
5866
- invariant15(response.space, void 0, {
5867
- F: __dxlog_file21,
5868
- L: 175,
6415
+ invariant16(response.space, void 0, {
6416
+ F: __dxlog_file23,
6417
+ L: 179,
5869
6418
  S: this,
5870
6419
  A: [
5871
6420
  "response.space",
@@ -5874,18 +6423,18 @@ var SpaceInvitationProtocol = class {
5874
6423
  });
5875
6424
  const { credential, controlTimeframe, dataTimeframe } = response.space;
5876
6425
  const assertion = getCredentialAssertion4(credential);
5877
- invariant15(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
5878
- F: __dxlog_file21,
5879
- L: 178,
6426
+ invariant16(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
6427
+ F: __dxlog_file23,
6428
+ L: 182,
5880
6429
  S: this,
5881
6430
  A: [
5882
6431
  "assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
5883
6432
  "'Invalid credential'"
5884
6433
  ]
5885
6434
  });
5886
- invariant15(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
5887
- F: __dxlog_file21,
5888
- L: 179,
6435
+ invariant16(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
6436
+ F: __dxlog_file23,
6437
+ L: 183,
5889
6438
  S: this,
5890
6439
  A: [
5891
6440
  "credential.subject.id.equals(this._signingContext.identityKey)",
@@ -5914,12 +6463,12 @@ import { AuthenticatingInvitation, AUTHENTICATION_CODE_LENGTH, CancellableInvita
5914
6463
  import { Context as Context8 } from "@dxos/context";
5915
6464
  import { generatePasscode } from "@dxos/credentials";
5916
6465
  import { hasInvitationExpired } from "@dxos/echo-pipeline";
5917
- import { invariant as invariant16 } from "@dxos/invariant";
6466
+ import { invariant as invariant17 } from "@dxos/invariant";
5918
6467
  import { PublicKey as PublicKey12 } from "@dxos/keys";
5919
- import { log as log19 } from "@dxos/log";
5920
- import { Invitation as Invitation7 } from "@dxos/protocols/proto/dxos/client/services";
6468
+ import { log as log21 } from "@dxos/log";
6469
+ import { Invitation as Invitation9 } from "@dxos/protocols/proto/dxos/client/services";
5921
6470
  import { SpaceMember as SpaceMember7 } from "@dxos/protocols/proto/dxos/halo/credentials";
5922
- var __dxlog_file22 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts";
6471
+ var __dxlog_file24 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts";
5923
6472
  var InvitationsManager = class {
5924
6473
  constructor(_invitationsHandler, _getHandler, _metadataStore) {
5925
6474
  this._invitationsHandler = _invitationsHandler;
@@ -5961,8 +6510,8 @@ var InvitationsManager = class {
5961
6510
  try {
5962
6511
  await this._persistIfRequired(handler, stream, invitation);
5963
6512
  } catch (err) {
5964
- log19.catch(err, void 0, {
5965
- F: __dxlog_file22,
6513
+ log21.catch(err, void 0, {
6514
+ F: __dxlog_file24,
5966
6515
  L: 82,
5967
6516
  S: this,
5968
6517
  C: (f, a) => f(...a)
@@ -5984,8 +6533,8 @@ var InvitationsManager = class {
5984
6533
  const persistentInvitations = this._metadataStore.getInvitations();
5985
6534
  const freshInvitations = persistentInvitations.filter((invitation) => !hasInvitationExpired(invitation));
5986
6535
  const loadTasks = freshInvitations.map((persistentInvitation) => {
5987
- invariant16(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
5988
- F: __dxlog_file22,
6536
+ invariant17(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
6537
+ F: __dxlog_file24,
5989
6538
  L: 103,
5990
6539
  S: this,
5991
6540
  A: [
@@ -6003,8 +6552,8 @@ var InvitationsManager = class {
6003
6552
  invitations: cInvitations.map((invitation) => invitation.get())
6004
6553
  };
6005
6554
  } catch (err) {
6006
- log19.catch(err, void 0, {
6007
- F: __dxlog_file22,
6555
+ log21.catch(err, void 0, {
6556
+ F: __dxlog_file24,
6008
6557
  L: 110,
6009
6558
  S: this,
6010
6559
  C: (f, a) => f(...a)
@@ -6035,14 +6584,14 @@ var InvitationsManager = class {
6035
6584
  return invitation;
6036
6585
  }
6037
6586
  async authenticate({ invitationId, authCode }) {
6038
- log19("authenticating...", void 0, {
6039
- F: __dxlog_file22,
6587
+ log21("authenticating...", void 0, {
6588
+ F: __dxlog_file24,
6040
6589
  L: 140,
6041
6590
  S: this,
6042
6591
  C: (f, a) => f(...a)
6043
6592
  });
6044
- invariant16(invitationId, void 0, {
6045
- F: __dxlog_file22,
6593
+ invariant17(invitationId, void 0, {
6594
+ F: __dxlog_file24,
6046
6595
  L: 141,
6047
6596
  S: this,
6048
6597
  A: [
@@ -6052,10 +6601,10 @@ var InvitationsManager = class {
6052
6601
  });
6053
6602
  const observable = this._acceptInvitations.get(invitationId);
6054
6603
  if (!observable) {
6055
- log19.warn("invalid invitation", {
6604
+ log21.warn("invalid invitation", {
6056
6605
  invitationId
6057
6606
  }, {
6058
- F: __dxlog_file22,
6607
+ F: __dxlog_file24,
6059
6608
  L: 144,
6060
6609
  S: this,
6061
6610
  C: (f, a) => f(...a)
@@ -6065,16 +6614,16 @@ var InvitationsManager = class {
6065
6614
  }
6066
6615
  }
6067
6616
  async cancelInvitation({ invitationId }) {
6068
- log19("cancelInvitation...", {
6617
+ log21("cancelInvitation...", {
6069
6618
  invitationId
6070
6619
  }, {
6071
- F: __dxlog_file22,
6620
+ F: __dxlog_file24,
6072
6621
  L: 151,
6073
6622
  S: this,
6074
6623
  C: (f, a) => f(...a)
6075
6624
  });
6076
- invariant16(invitationId, void 0, {
6077
- F: __dxlog_file22,
6625
+ invariant17(invitationId, void 0, {
6626
+ F: __dxlog_file24,
6078
6627
  L: 152,
6079
6628
  S: this,
6080
6629
  A: [
@@ -6087,7 +6636,7 @@ var InvitationsManager = class {
6087
6636
  if (created.get().persistent) {
6088
6637
  await this._metadataStore.removeInvitation(invitationId);
6089
6638
  }
6090
- if (created.get().type === Invitation7.Type.DELEGATED) {
6639
+ if (created.get().type === Invitation9.Type.DELEGATED) {
6091
6640
  const handler = this._getHandler(created.get());
6092
6641
  await handler.cancelDelegation(created.get());
6093
6642
  }
@@ -6121,8 +6670,8 @@ var InvitationsManager = class {
6121
6670
  }
6122
6671
  }
6123
6672
  _createInvitation(protocol, options) {
6124
- const { invitationId = PublicKey12.random().toHex(), type = Invitation7.Type.INTERACTIVE, authMethod = Invitation7.AuthMethod.SHARED_SECRET, state = Invitation7.State.INIT, timeout = INVITATION_TIMEOUT2, swarmKey = PublicKey12.random(), persistent = options?.authMethod !== Invitation7.AuthMethod.KNOWN_PUBLIC_KEY, created = /* @__PURE__ */ new Date(), guestKeypair = void 0, role = SpaceMember7.Role.ADMIN, lifetime = 86400, multiUse = false } = options ?? {};
6125
- const authCode = options?.authCode ?? (authMethod === Invitation7.AuthMethod.SHARED_SECRET ? generatePasscode(AUTHENTICATION_CODE_LENGTH) : void 0);
6673
+ const { invitationId = PublicKey12.random().toHex(), type = Invitation9.Type.INTERACTIVE, authMethod = Invitation9.AuthMethod.SHARED_SECRET, state = Invitation9.State.INIT, timeout = INVITATION_TIMEOUT2, swarmKey = PublicKey12.random(), persistent = options?.authMethod !== Invitation9.AuthMethod.KNOWN_PUBLIC_KEY, created = /* @__PURE__ */ new Date(), guestKeypair = void 0, role = SpaceMember7.Role.ADMIN, lifetime = 86400, multiUse = false } = options ?? {};
6674
+ const authCode = options?.authCode ?? (authMethod === Invitation9.AuthMethod.SHARED_SECRET ? generatePasscode(AUTHENTICATION_CODE_LENGTH) : void 0);
6126
6675
  return {
6127
6676
  invitationId,
6128
6677
  type,
@@ -6131,8 +6680,8 @@ var InvitationsManager = class {
6131
6680
  swarmKey,
6132
6681
  authCode,
6133
6682
  timeout,
6134
- persistent: persistent && type !== Invitation7.Type.DELEGATED,
6135
- guestKeypair: guestKeypair ?? (authMethod === Invitation7.AuthMethod.KNOWN_PUBLIC_KEY ? createAdmissionKeypair() : void 0),
6683
+ persistent: persistent && type !== Invitation9.Type.DELEGATED,
6684
+ guestKeypair: guestKeypair ?? (authMethod === Invitation9.AuthMethod.KNOWN_PUBLIC_KEY ? createAdmissionKeypair() : void 0),
6136
6685
  created,
6137
6686
  lifetime,
6138
6687
  role,
@@ -6149,14 +6698,14 @@ var InvitationsManager = class {
6149
6698
  void ctx.dispose();
6150
6699
  }
6151
6700
  }, {
6152
- F: __dxlog_file22,
6701
+ F: __dxlog_file24,
6153
6702
  L: 234
6154
6703
  });
6155
6704
  ctx.onDispose(() => {
6156
- log19("complete", {
6705
+ log21("complete", {
6157
6706
  ...handler.toJSON()
6158
6707
  }, {
6159
- F: __dxlog_file22,
6708
+ F: __dxlog_file24,
6160
6709
  L: 241,
6161
6710
  S: this,
6162
6711
  C: (f, a) => f(...a)
@@ -6169,7 +6718,7 @@ var InvitationsManager = class {
6169
6718
  onCancel: async () => {
6170
6719
  stream.next({
6171
6720
  ...invitation,
6172
- state: Invitation7.State.CANCELLED
6721
+ state: Invitation9.State.CANCELLED
6173
6722
  });
6174
6723
  await ctx.dispose();
6175
6724
  }
@@ -6186,41 +6735,41 @@ var InvitationsManager = class {
6186
6735
  const ctx = new Context8({
6187
6736
  onError: (err) => {
6188
6737
  if (err instanceof TimeoutError3) {
6189
- log19("timeout", {
6738
+ log21("timeout", {
6190
6739
  ...handler.toJSON()
6191
6740
  }, {
6192
- F: __dxlog_file22,
6741
+ F: __dxlog_file24,
6193
6742
  L: 261,
6194
6743
  S: this,
6195
6744
  C: (f, a) => f(...a)
6196
6745
  });
6197
6746
  stream.next({
6198
6747
  ...initialState,
6199
- state: Invitation7.State.TIMEOUT
6748
+ state: Invitation9.State.TIMEOUT
6200
6749
  });
6201
6750
  } else {
6202
- log19.warn("auth failed", err, {
6203
- F: __dxlog_file22,
6751
+ log21.warn("auth failed", err, {
6752
+ F: __dxlog_file24,
6204
6753
  L: 264,
6205
6754
  S: this,
6206
6755
  C: (f, a) => f(...a)
6207
6756
  });
6208
6757
  stream.next({
6209
6758
  ...initialState,
6210
- state: Invitation7.State.ERROR
6759
+ state: Invitation9.State.ERROR
6211
6760
  });
6212
6761
  }
6213
6762
  void ctx.dispose();
6214
6763
  }
6215
6764
  }, {
6216
- F: __dxlog_file22,
6765
+ F: __dxlog_file24,
6217
6766
  L: 258
6218
6767
  });
6219
6768
  ctx.onDispose(() => {
6220
- log19("complete", {
6769
+ log21("complete", {
6221
6770
  ...handler.toJSON()
6222
6771
  }, {
6223
- F: __dxlog_file22,
6772
+ F: __dxlog_file24,
6224
6773
  L: 271,
6225
6774
  S: this,
6226
6775
  C: (f, a) => f(...a)
@@ -6233,7 +6782,7 @@ var InvitationsManager = class {
6233
6782
  onCancel: async () => {
6234
6783
  stream.next({
6235
6784
  ...initialState,
6236
- state: Invitation7.State.CANCELLED
6785
+ state: Invitation9.State.CANCELLED
6237
6786
  });
6238
6787
  await ctx.dispose();
6239
6788
  },
@@ -6249,7 +6798,7 @@ var InvitationsManager = class {
6249
6798
  };
6250
6799
  }
6251
6800
  async _persistIfRequired(handler, changeStream, invitation) {
6252
- if (invitation.type === Invitation7.Type.DELEGATED && invitation.delegationCredentialId == null) {
6801
+ if (invitation.type === Invitation9.Type.DELEGATED && invitation.delegationCredentialId == null) {
6253
6802
  const delegationCredentialId = await handler.delegate(invitation);
6254
6803
  changeStream.next({
6255
6804
  ...invitation,
@@ -6264,8 +6813,8 @@ var InvitationsManager = class {
6264
6813
  try {
6265
6814
  await this._metadataStore.removeInvitation(invitation.invitationId);
6266
6815
  } catch (err) {
6267
- log19.catch(err, void 0, {
6268
- F: __dxlog_file22,
6816
+ log21.catch(err, void 0, {
6817
+ F: __dxlog_file24,
6269
6818
  L: 307,
6270
6819
  S: this,
6271
6820
  C: (f, a) => f(...a)
@@ -6282,14 +6831,14 @@ var InvitationsManager = class {
6282
6831
  // packages/sdk/client-services/src/packlets/locks/browser.ts
6283
6832
  import { asyncTimeout as asyncTimeout2, Trigger as Trigger8 } from "@dxos/async";
6284
6833
  import { RESOURCE_LOCK_TIMEOUT } from "@dxos/client-protocol";
6285
- import { log as log20, logInfo } from "@dxos/log";
6286
- function _ts_decorate5(decorators, target, key, desc) {
6834
+ import { log as log22, logInfo as logInfo3 } from "@dxos/log";
6835
+ function _ts_decorate7(decorators, target, key, desc) {
6287
6836
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
6288
6837
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
6289
6838
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6290
6839
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6291
6840
  }
6292
- var __dxlog_file23 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
6841
+ var __dxlog_file25 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
6293
6842
  var Message;
6294
6843
  (function(Message2) {
6295
6844
  Message2["ACQUIRING"] = "acquiring";
@@ -6311,29 +6860,29 @@ var Lock = class {
6311
6860
  message: "acquiring"
6312
6861
  });
6313
6862
  try {
6314
- log20("aquiring lock...", void 0, {
6315
- F: __dxlog_file23,
6863
+ log22("aquiring lock...", void 0, {
6864
+ F: __dxlog_file25,
6316
6865
  L: 42,
6317
6866
  S: this,
6318
6867
  C: (f, a) => f(...a)
6319
6868
  });
6320
6869
  await asyncTimeout2(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
6321
- log20("acquired lock", void 0, {
6322
- F: __dxlog_file23,
6870
+ log22("acquired lock", void 0, {
6871
+ F: __dxlog_file25,
6323
6872
  L: 44,
6324
6873
  S: this,
6325
6874
  C: (f, a) => f(...a)
6326
6875
  });
6327
6876
  } catch {
6328
- log20("stealing lock...", void 0, {
6329
- F: __dxlog_file23,
6877
+ log22("stealing lock...", void 0, {
6878
+ F: __dxlog_file25,
6330
6879
  L: 46,
6331
6880
  S: this,
6332
6881
  C: (f, a) => f(...a)
6333
6882
  });
6334
6883
  await this._requestLock(true);
6335
- log20("stolen lock", void 0, {
6336
- F: __dxlog_file23,
6884
+ log22("stolen lock", void 0, {
6885
+ F: __dxlog_file25,
6337
6886
  L: 48,
6338
6887
  S: this,
6339
6888
  C: (f, a) => f(...a)
@@ -6349,10 +6898,10 @@ var Lock = class {
6349
6898
  }
6350
6899
  }
6351
6900
  async _requestLock(steal = false) {
6352
- log20("requesting lock...", {
6901
+ log22("requesting lock...", {
6353
6902
  steal
6354
6903
  }, {
6355
- F: __dxlog_file23,
6904
+ F: __dxlog_file25,
6356
6905
  L: 63,
6357
6906
  S: this,
6358
6907
  C: (f, a) => f(...a)
@@ -6365,15 +6914,15 @@ var Lock = class {
6365
6914
  acquired.wake();
6366
6915
  this._releaseTrigger = new Trigger8();
6367
6916
  await this._releaseTrigger.wait();
6368
- log20("releasing lock...", void 0, {
6369
- F: __dxlog_file23,
6917
+ log22("releasing lock...", void 0, {
6918
+ F: __dxlog_file25,
6370
6919
  L: 72,
6371
6920
  S: this,
6372
6921
  C: (f, a) => f(...a)
6373
6922
  });
6374
6923
  await this._onRelease?.();
6375
- log20("released lock", void 0, {
6376
- F: __dxlog_file23,
6924
+ log22("released lock", void 0, {
6925
+ F: __dxlog_file25,
6377
6926
  L: 74,
6378
6927
  S: this,
6379
6928
  C: (f, a) => f(...a)
@@ -6382,18 +6931,18 @@ var Lock = class {
6382
6931
  await this._onRelease?.();
6383
6932
  });
6384
6933
  await acquired.wait();
6385
- log20("recieved lock", {
6934
+ log22("recieved lock", {
6386
6935
  steal
6387
6936
  }, {
6388
- F: __dxlog_file23,
6937
+ F: __dxlog_file25,
6389
6938
  L: 81,
6390
6939
  S: this,
6391
6940
  C: (f, a) => f(...a)
6392
6941
  });
6393
6942
  }
6394
6943
  };
6395
- _ts_decorate5([
6396
- logInfo
6944
+ _ts_decorate7([
6945
+ logInfo3
6397
6946
  ], Lock.prototype, "lockKey", null);
6398
6947
  var isLocked = (lockPath) => {
6399
6948
  throw new Error("Not implemented");
@@ -6404,7 +6953,7 @@ import { Stream as Stream10 } from "@dxos/codec-protobuf";
6404
6953
  import { raise as raise2 } from "@dxos/debug";
6405
6954
  import { parseMethodName, RpcPeer } from "@dxos/rpc";
6406
6955
  import { MapCounter, trace as trace8 } from "@dxos/tracing";
6407
- function _ts_decorate6(decorators, target, key, desc) {
6956
+ function _ts_decorate8(decorators, target, key, desc) {
6408
6957
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
6409
6958
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
6410
6959
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
@@ -6466,49 +7015,114 @@ var ClientRpcServer = class {
6466
7015
  return this._handlerCache.get(serviceName);
6467
7016
  }
6468
7017
  };
6469
- _ts_decorate6([
7018
+ _ts_decorate8([
6470
7019
  trace8.metricsCounter()
6471
7020
  ], ClientRpcServer.prototype, "_callMetrics", void 0);
6472
- _ts_decorate6([
7021
+ _ts_decorate8([
6473
7022
  trace8.info()
6474
7023
  ], ClientRpcServer.prototype, "_services", null);
6475
- ClientRpcServer = _ts_decorate6([
7024
+ ClientRpcServer = _ts_decorate8([
6476
7025
  trace8.resource()
6477
7026
  ], ClientRpcServer);
6478
7027
 
6479
7028
  // packages/sdk/client-services/src/packlets/services/service-context.ts
6480
- import { Trigger as Trigger9 } from "@dxos/async";
6481
- import { Context as Context9, Resource as Resource5 } from "@dxos/context";
7029
+ import { Mutex as Mutex4, scheduleMicroTask as scheduleMicroTask4, Trigger as Trigger9 } from "@dxos/async";
7030
+ import { Context as Context9, Resource as Resource6 } from "@dxos/context";
6482
7031
  import { getCredentialAssertion as getCredentialAssertion5 } from "@dxos/credentials";
6483
- import { failUndefined as failUndefined2 } from "@dxos/debug";
7032
+ import { failUndefined as failUndefined2, warnAfterTimeout as warnAfterTimeout2 } from "@dxos/debug";
6484
7033
  import { EchoEdgeReplicator, EchoHost, MeshEchoReplicator, MetadataStore, SpaceManager, valueEncoding } from "@dxos/echo-pipeline";
7034
+ import { createChainEdgeIdentity, createEphemeralEdgeIdentity } from "@dxos/edge-client";
6485
7035
  import { FeedFactory, FeedStore } from "@dxos/feed-store";
6486
- import { invariant as invariant17 } from "@dxos/invariant";
7036
+ import { invariant as invariant18 } from "@dxos/invariant";
6487
7037
  import { Keyring } from "@dxos/keyring";
6488
7038
  import { PublicKey as PublicKey13 } from "@dxos/keys";
6489
- import { log as log21 } from "@dxos/log";
7039
+ import { log as log23 } from "@dxos/log";
6490
7040
  import { InvalidStorageVersionError, STORAGE_VERSION as STORAGE_VERSION2, trace as trace9 } from "@dxos/protocols";
6491
- import { Invitation as Invitation8 } from "@dxos/protocols/proto/dxos/client/services";
7041
+ import { Invitation as Invitation10 } from "@dxos/protocols/proto/dxos/client/services";
6492
7042
  import { BlobStore } from "@dxos/teleport-extension-object-sync";
6493
7043
  import { trace as Trace3 } from "@dxos/tracing";
6494
7044
  import { safeInstanceof } from "@dxos/util";
6495
- function _ts_decorate7(decorators, target, key, desc) {
7045
+ function _ts_decorate9(decorators, target, key, desc) {
6496
7046
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
6497
7047
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
6498
7048
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6499
7049
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6500
7050
  }
6501
- var __dxlog_file24 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
6502
- var ServiceContext = class extends Resource5 {
6503
- constructor(storage, level, networkManager, signalManager, _edgeConnection, _runtimeParams, _edgeFeatures) {
7051
+ function _using_ctx3() {
7052
+ var _disposeSuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed) {
7053
+ var err = new Error();
7054
+ err.name = "SuppressedError";
7055
+ err.suppressed = suppressed;
7056
+ err.error = error;
7057
+ return err;
7058
+ }, empty = {}, stack = [];
7059
+ function using(isAwait, value) {
7060
+ if (value != null) {
7061
+ if (Object(value) !== value) {
7062
+ throw new TypeError("using declarations can only be used with objects, functions, null, or undefined.");
7063
+ }
7064
+ if (isAwait) {
7065
+ var dispose = value[Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose")];
7066
+ }
7067
+ if (dispose == null) {
7068
+ dispose = value[Symbol.dispose || Symbol.for("Symbol.dispose")];
7069
+ }
7070
+ if (typeof dispose !== "function") {
7071
+ throw new TypeError(`Property [Symbol.dispose] is not a function.`);
7072
+ }
7073
+ stack.push({
7074
+ v: value,
7075
+ d: dispose,
7076
+ a: isAwait
7077
+ });
7078
+ } else if (isAwait) {
7079
+ stack.push({
7080
+ d: value,
7081
+ a: isAwait
7082
+ });
7083
+ }
7084
+ return value;
7085
+ }
7086
+ return {
7087
+ e: empty,
7088
+ u: using.bind(null, false),
7089
+ a: using.bind(null, true),
7090
+ d: function() {
7091
+ var error = this.e;
7092
+ function next() {
7093
+ while (resource = stack.pop()) {
7094
+ try {
7095
+ var resource, disposalResult = resource.d && resource.d.call(resource.v);
7096
+ if (resource.a) {
7097
+ return Promise.resolve(disposalResult).then(next, err);
7098
+ }
7099
+ } catch (e) {
7100
+ return err(e);
7101
+ }
7102
+ }
7103
+ if (error !== empty) throw error;
7104
+ }
7105
+ function err(e) {
7106
+ error = error !== empty ? new _disposeSuppressedError(error, e) : e;
7107
+ return next();
7108
+ }
7109
+ return next();
7110
+ }
7111
+ };
7112
+ }
7113
+ var __dxlog_file26 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
7114
+ var ServiceContext = class extends Resource6 {
7115
+ constructor(storage, level, networkManager, signalManager, _edgeConnection, _edgeHttpClient, _runtimeParams, _edgeFeatures) {
6504
7116
  super();
6505
7117
  this.storage = storage;
6506
7118
  this.level = level;
6507
7119
  this.networkManager = networkManager;
6508
7120
  this.signalManager = signalManager;
6509
7121
  this._edgeConnection = _edgeConnection;
7122
+ this._edgeHttpClient = _edgeHttpClient;
6510
7123
  this._runtimeParams = _runtimeParams;
6511
7124
  this._edgeFeatures = _edgeFeatures;
7125
+ this._edgeIdentityUpdateMutex = new Mutex4();
6512
7126
  this.initialized = new Trigger9();
6513
7127
  this._meshReplicator = void 0;
6514
7128
  this._echoEdgeReplicator = void 0;
@@ -6546,23 +7160,42 @@ var ServiceContext = class extends Resource5 {
6546
7160
  callbacks: {
6547
7161
  onIdentityConstruction: (identity) => {
6548
7162
  if (this._edgeConnection) {
6549
- log21.info("Setting identity on edge connection", {
6550
- identity: identity.identityKey.toHex(),
6551
- oldIdentity: this._edgeConnection.identityKey,
6552
- swarms: this.networkManager.topics
6553
- }, {
6554
- F: __dxlog_file24,
6555
- L: 140,
6556
- S: this,
6557
- C: (f, a) => f(...a)
6558
- });
6559
- this._edgeConnection.setIdentity({
6560
- peerKey: identity.deviceKey.toHex(),
6561
- identityKey: identity.identityKey.toHex()
6562
- });
6563
- this.networkManager.setPeerInfo({
6564
- identityKey: identity.identityKey.toHex(),
6565
- peerKey: identity.deviceKey.toHex()
7163
+ scheduleMicroTask4(this._ctx, async () => {
7164
+ try {
7165
+ var _usingCtx = _using_ctx3();
7166
+ const _ = _usingCtx.u(await this._edgeIdentityUpdateMutex.acquire());
7167
+ log23.info("Setting identity on edge connection", {
7168
+ identity: identity.identityKey.toHex(),
7169
+ oldIdentity: this._edgeConnection.identityKey,
7170
+ swarms: this.networkManager.topics
7171
+ }, {
7172
+ F: __dxlog_file26,
7173
+ L: 147,
7174
+ S: this,
7175
+ C: (f, a) => f(...a)
7176
+ });
7177
+ await warnAfterTimeout2(1e4, "Waiting for identity to be ready for edge connection", async () => {
7178
+ await identity.ready();
7179
+ });
7180
+ invariant18(identity.deviceCredentialChain, void 0, {
7181
+ F: __dxlog_file26,
7182
+ L: 157,
7183
+ S: this,
7184
+ A: [
7185
+ "identity.deviceCredentialChain",
7186
+ ""
7187
+ ]
7188
+ });
7189
+ this._edgeConnection.setIdentity(await createChainEdgeIdentity(identity.signer, identity.identityKey, identity.deviceKey, identity.deviceCredentialChain, []));
7190
+ this.networkManager.setPeerInfo({
7191
+ identityKey: identity.identityKey.toHex(),
7192
+ peerKey: identity.deviceKey.toHex()
7193
+ });
7194
+ } catch (_) {
7195
+ _usingCtx.e = _;
7196
+ } finally {
7197
+ _usingCtx.d();
7198
+ }
6566
7199
  });
6567
7200
  }
6568
7201
  }
@@ -6572,9 +7205,9 @@ var ServiceContext = class extends Resource5 {
6572
7205
  kv: this.level
6573
7206
  });
6574
7207
  this._meshReplicator = new MeshEchoReplicator();
6575
- this.invitations = new InvitationsHandler(this.networkManager, _runtimeParams?.invitationConnectionDefaultParams);
7208
+ this.invitations = new InvitationsHandler(this.networkManager, this._edgeHttpClient, _runtimeParams?.invitationConnectionDefaultParams);
6576
7209
  this.invitationsManager = new InvitationsManager(this.invitations, (invitation) => this.getInvitationHandler(invitation), this.metadataStore);
6577
- this._handlerFactories.set(Invitation8.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? failUndefined2(), this._acceptIdentity.bind(this)));
7210
+ this._handlerFactories.set(Invitation10.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? failUndefined2(), this._acceptIdentity.bind(this)));
6578
7211
  if (!this._runtimeParams?.disableP2pReplication) {
6579
7212
  this._meshReplicator = new MeshEchoReplicator();
6580
7213
  }
@@ -6586,21 +7219,24 @@ var ServiceContext = class extends Resource5 {
6586
7219
  }
6587
7220
  async _open(ctx) {
6588
7221
  await this._checkStorageVersion();
6589
- log21("opening...", void 0, {
6590
- F: __dxlog_file24,
6591
- L: 198,
7222
+ log23("opening...", void 0, {
7223
+ F: __dxlog_file26,
7224
+ L: 218,
6592
7225
  S: this,
6593
7226
  C: (f, a) => f(...a)
6594
7227
  });
6595
- log21.trace("dxos.sdk.service-context.open", trace9.begin({
7228
+ log23.trace("dxos.sdk.service-context.open", trace9.begin({
6596
7229
  id: this._instanceId
6597
7230
  }), {
6598
- F: __dxlog_file24,
6599
- L: 199,
7231
+ F: __dxlog_file26,
7232
+ L: 219,
6600
7233
  S: this,
6601
7234
  C: (f, a) => f(...a)
6602
7235
  });
6603
- await this._edgeConnection?.open();
7236
+ if (this._edgeConnection) {
7237
+ this._edgeConnection.setIdentity(await createEphemeralEdgeIdentity());
7238
+ await this._edgeConnection.open();
7239
+ }
6604
7240
  await this.signalManager.open();
6605
7241
  await this.networkManager.open();
6606
7242
  await this.echoHost.open(ctx);
@@ -6617,33 +7253,33 @@ var ServiceContext = class extends Resource5 {
6617
7253
  await this._initialize(ctx);
6618
7254
  }
6619
7255
  const loadedInvitations = await this.invitationsManager.loadPersistentInvitations();
6620
- log21("loaded persistent invitations", {
7256
+ log23("loaded persistent invitations", {
6621
7257
  count: loadedInvitations.invitations?.length
6622
7258
  }, {
6623
- F: __dxlog_file24,
6624
- L: 222,
7259
+ F: __dxlog_file26,
7260
+ L: 246,
6625
7261
  S: this,
6626
7262
  C: (f, a) => f(...a)
6627
7263
  });
6628
- log21.trace("dxos.sdk.service-context.open", trace9.end({
7264
+ log23.trace("dxos.sdk.service-context.open", trace9.end({
6629
7265
  id: this._instanceId
6630
7266
  }), {
6631
- F: __dxlog_file24,
6632
- L: 224,
7267
+ F: __dxlog_file26,
7268
+ L: 248,
6633
7269
  S: this,
6634
7270
  C: (f, a) => f(...a)
6635
7271
  });
6636
- log21("opened", void 0, {
6637
- F: __dxlog_file24,
6638
- L: 225,
7272
+ log23("opened", void 0, {
7273
+ F: __dxlog_file26,
7274
+ L: 249,
6639
7275
  S: this,
6640
7276
  C: (f, a) => f(...a)
6641
7277
  });
6642
7278
  }
6643
7279
  async _close(ctx) {
6644
- log21("closing...", void 0, {
6645
- F: __dxlog_file24,
6646
- L: 229,
7280
+ log23("closing...", void 0, {
7281
+ F: __dxlog_file26,
7282
+ L: 253,
6647
7283
  S: this,
6648
7284
  C: (f, a) => f(...a)
6649
7285
  });
@@ -6659,9 +7295,9 @@ var ServiceContext = class extends Resource5 {
6659
7295
  await this.networkManager.close();
6660
7296
  await this.signalManager.close();
6661
7297
  await this._edgeConnection?.close();
6662
- log21("closed", void 0, {
6663
- F: __dxlog_file24,
6664
- L: 244,
7298
+ log23("closed", void 0, {
7299
+ F: __dxlog_file26,
7300
+ L: 268,
6665
7301
  S: this,
6666
7302
  C: (f, a) => f(...a)
6667
7303
  });
@@ -6669,16 +7305,16 @@ var ServiceContext = class extends Resource5 {
6669
7305
  async createIdentity(params = {}) {
6670
7306
  const identity = await this.identityManager.createIdentity(params);
6671
7307
  await this._initialize(new Context9(void 0, {
6672
- F: __dxlog_file24,
6673
- L: 249
7308
+ F: __dxlog_file26,
7309
+ L: 273
6674
7310
  }));
6675
7311
  return identity;
6676
7312
  }
6677
7313
  getInvitationHandler(invitation) {
6678
7314
  const factory = this._handlerFactories.get(invitation.kind);
6679
- invariant17(factory, `Unknown invitation kind: ${invitation.kind}`, {
6680
- F: __dxlog_file24,
6681
- L: 255,
7315
+ invariant18(factory, `Unknown invitation kind: ${invitation.kind}`, {
7316
+ F: __dxlog_file26,
7317
+ L: 279,
6682
7318
  S: this,
6683
7319
  A: [
6684
7320
  "factory",
@@ -6698,8 +7334,8 @@ var ServiceContext = class extends Resource5 {
6698
7334
  async _acceptIdentity(params) {
6699
7335
  const identity = await this.identityManager.acceptIdentity(params);
6700
7336
  await this._initialize(new Context9(void 0, {
6701
- F: __dxlog_file24,
6702
- L: 271
7337
+ F: __dxlog_file26,
7338
+ L: 295
6703
7339
  }));
6704
7340
  return identity;
6705
7341
  }
@@ -6711,9 +7347,9 @@ var ServiceContext = class extends Resource5 {
6711
7347
  }
6712
7348
  // Called when identity is created.
6713
7349
  async _initialize(ctx) {
6714
- log21("initializing spaces...", void 0, {
6715
- F: __dxlog_file24,
6716
- L: 286,
7350
+ log23("initializing spaces...", void 0, {
7351
+ F: __dxlog_file26,
7352
+ L: 310,
6717
7353
  S: this,
6718
7354
  C: (f, a) => f(...a)
6719
7355
  });
@@ -6740,16 +7376,17 @@ var ServiceContext = class extends Resource5 {
6740
7376
  echoHost: this.echoHost,
6741
7377
  invitationsManager: this.invitationsManager,
6742
7378
  edgeConnection: this._edgeConnection,
7379
+ edgeHttpClient: this._edgeHttpClient,
6743
7380
  echoEdgeReplicator: this._echoEdgeReplicator,
6744
7381
  meshReplicator: this._meshReplicator,
6745
7382
  runtimeParams: this._runtimeParams,
6746
7383
  edgeFeatures: this._edgeFeatures
6747
7384
  });
6748
7385
  await this.dataSpaceManager.open();
6749
- this._handlerFactories.set(Invitation8.Kind.SPACE, (invitation) => {
6750
- invariant17(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
6751
- F: __dxlog_file24,
6752
- L: 315,
7386
+ this._handlerFactories.set(Invitation10.Kind.SPACE, (invitation) => {
7387
+ invariant18(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
7388
+ F: __dxlog_file26,
7389
+ L: 340,
6753
7390
  S: this,
6754
7391
  A: [
6755
7392
  "this.dataSpaceManager",
@@ -6769,33 +7406,33 @@ var ServiceContext = class extends Resource5 {
6769
7406
  return;
6770
7407
  }
6771
7408
  if (!this.dataSpaceManager) {
6772
- log21("dataSpaceManager not initialized yet, ignoring space admission", {
7409
+ log23("dataSpaceManager not initialized yet, ignoring space admission", {
6773
7410
  details: assertion
6774
7411
  }, {
6775
- F: __dxlog_file24,
6776
- L: 331,
7412
+ F: __dxlog_file26,
7413
+ L: 356,
6777
7414
  S: this,
6778
7415
  C: (f, a) => f(...a)
6779
7416
  });
6780
7417
  return;
6781
7418
  }
6782
7419
  if (this.dataSpaceManager.spaces.has(assertion.spaceKey)) {
6783
- log21("space already exists, ignoring space admission", {
7420
+ log23("space already exists, ignoring space admission", {
6784
7421
  details: assertion
6785
7422
  }, {
6786
- F: __dxlog_file24,
6787
- L: 335,
7423
+ F: __dxlog_file26,
7424
+ L: 360,
6788
7425
  S: this,
6789
7426
  C: (f, a) => f(...a)
6790
7427
  });
6791
7428
  return;
6792
7429
  }
6793
7430
  try {
6794
- log21("accepting space recorded in halo", {
7431
+ log23("accepting space recorded in halo", {
6795
7432
  details: assertion
6796
7433
  }, {
6797
- F: __dxlog_file24,
6798
- L: 340,
7434
+ F: __dxlog_file26,
7435
+ L: 365,
6799
7436
  S: this,
6800
7437
  C: (f, a) => f(...a)
6801
7438
  });
@@ -6804,9 +7441,9 @@ var ServiceContext = class extends Resource5 {
6804
7441
  genesisFeedKey: assertion.genesisFeedKey
6805
7442
  });
6806
7443
  } catch (err) {
6807
- log21.catch(err, void 0, {
6808
- F: __dxlog_file24,
6809
- L: 346,
7444
+ log23.catch(err, void 0, {
7445
+ F: __dxlog_file26,
7446
+ L: 371,
6810
7447
  S: this,
6811
7448
  C: (f, a) => f(...a)
6812
7449
  });
@@ -6816,13 +7453,13 @@ var ServiceContext = class extends Resource5 {
6816
7453
  await identity.space.spaceState.addCredentialProcessor(this._deviceSpaceSync);
6817
7454
  }
6818
7455
  };
6819
- _ts_decorate7([
7456
+ _ts_decorate9([
6820
7457
  Trace3.span()
6821
7458
  ], ServiceContext.prototype, "_open", null);
6822
- _ts_decorate7([
7459
+ _ts_decorate9([
6823
7460
  Trace3.span()
6824
7461
  ], ServiceContext.prototype, "_initialize", null);
6825
- ServiceContext = _ts_decorate7([
7462
+ ServiceContext = _ts_decorate9([
6826
7463
  safeInstanceof("dxos.client-services.ServiceContext"),
6827
7464
  Trace3.resource()
6828
7465
  ], ServiceContext);
@@ -6927,11 +7564,11 @@ var createLevel = async (config) => {
6927
7564
 
6928
7565
  // packages/sdk/client-services/src/packlets/storage/profile-archive.ts
6929
7566
  import { cbor } from "@dxos/automerge/automerge-repo";
6930
- import { invariant as invariant18 } from "@dxos/invariant";
6931
- import { log as log22 } from "@dxos/log";
7567
+ import { invariant as invariant19 } from "@dxos/invariant";
7568
+ import { log as log24 } from "@dxos/log";
6932
7569
  import { ProfileArchiveEntryType } from "@dxos/protocols";
6933
7570
  import { arrayToBuffer as arrayToBuffer2 } from "@dxos/util";
6934
- var __dxlog_file25 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/storage/profile-archive.ts";
7571
+ var __dxlog_file27 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/storage/profile-archive.ts";
6935
7572
  var encodeProfileArchive = (profile) => cbor.encode(profile);
6936
7573
  var decodeProfileArchive = (data) => cbor.decode(data);
6937
7574
  var exportProfileData = async ({ storage, level }) => {
@@ -6944,10 +7581,10 @@ var exportProfileData = async ({ storage, level }) => {
6944
7581
  {
6945
7582
  const directory = await storage.createDirectory();
6946
7583
  const files = await directory.list();
6947
- log22.info("begin exporting files", {
7584
+ log24.info("begin exporting files", {
6948
7585
  count: files.length
6949
7586
  }, {
6950
- F: __dxlog_file25,
7587
+ F: __dxlog_file27,
6951
7588
  L: 30,
6952
7589
  S: void 0,
6953
7590
  C: (f, a) => f(...a)
@@ -6962,18 +7599,18 @@ var exportProfileData = async ({ storage, level }) => {
6962
7599
  value: data
6963
7600
  });
6964
7601
  }
6965
- log22.info("done exporting files", {
7602
+ log24.info("done exporting files", {
6966
7603
  count: files.length
6967
7604
  }, {
6968
- F: __dxlog_file25,
7605
+ F: __dxlog_file27,
6969
7606
  L: 41,
6970
7607
  S: void 0,
6971
7608
  C: (f, a) => f(...a)
6972
7609
  });
6973
7610
  }
6974
7611
  {
6975
- log22.info("begin exporting kv pairs", void 0, {
6976
- F: __dxlog_file25,
7612
+ log24.info("begin exporting kv pairs", void 0, {
7613
+ F: __dxlog_file27,
6977
7614
  L: 45,
6978
7615
  S: void 0,
6979
7616
  C: (f, a) => f(...a)
@@ -6991,10 +7628,10 @@ var exportProfileData = async ({ storage, level }) => {
6991
7628
  });
6992
7629
  count++;
6993
7630
  }
6994
- log22.info("done exporting kv pairs", {
7631
+ log24.info("done exporting kv pairs", {
6995
7632
  count
6996
7633
  }, {
6997
- F: __dxlog_file25,
7634
+ F: __dxlog_file27,
6998
7635
  L: 56,
6999
7636
  S: void 0,
7000
7637
  C: (f, a) => f(...a)
@@ -7009,8 +7646,8 @@ var importProfileData = async ({ storage, level }, archive) => {
7009
7646
  switch (entry2.type) {
7010
7647
  case ProfileArchiveEntryType.FILE: {
7011
7648
  const directory = await storage.createDirectory();
7012
- invariant18(typeof entry2.key === "string", "Invalid key type", {
7013
- F: __dxlog_file25,
7649
+ invariant19(typeof entry2.key === "string", "Invalid key type", {
7650
+ F: __dxlog_file27,
7014
7651
  L: 79,
7015
7652
  S: void 0,
7016
7653
  A: [
@@ -7019,8 +7656,8 @@ var importProfileData = async ({ storage, level }, archive) => {
7019
7656
  ]
7020
7657
  });
7021
7658
  const file = await directory.getOrCreateFile(entry2.key);
7022
- invariant18(entry2.value instanceof Uint8Array, "Invalid value type", {
7023
- F: __dxlog_file25,
7659
+ invariant19(entry2.value instanceof Uint8Array, "Invalid value type", {
7660
+ F: __dxlog_file27,
7024
7661
  L: 81,
7025
7662
  S: void 0,
7026
7663
  A: [
@@ -7033,8 +7670,8 @@ var importProfileData = async ({ storage, level }, archive) => {
7033
7670
  break;
7034
7671
  }
7035
7672
  case ProfileArchiveEntryType.KEY_VALUE: {
7036
- invariant18(entry2.key instanceof Uint8Array, "Invalid key type", {
7037
- F: __dxlog_file25,
7673
+ invariant19(entry2.key instanceof Uint8Array, "Invalid key type", {
7674
+ F: __dxlog_file27,
7038
7675
  L: 87,
7039
7676
  S: void 0,
7040
7677
  A: [
@@ -7042,8 +7679,8 @@ var importProfileData = async ({ storage, level }, archive) => {
7042
7679
  "'Invalid key type'"
7043
7680
  ]
7044
7681
  });
7045
- invariant18(entry2.value instanceof Uint8Array, "Invalid value type", {
7046
- F: __dxlog_file25,
7682
+ invariant19(entry2.value instanceof Uint8Array, "Invalid value type", {
7683
+ F: __dxlog_file27,
7047
7684
  L: 88,
7048
7685
  S: void 0,
7049
7686
  A: [
@@ -7063,20 +7700,20 @@ var importProfileData = async ({ storage, level }, archive) => {
7063
7700
  if (++count % 1e3 === 0) {
7064
7701
  await batch.write();
7065
7702
  batch = level.batch();
7066
- log22.info("importing", {
7703
+ log24.info("importing", {
7067
7704
  count,
7068
7705
  total: archive.storage.length,
7069
7706
  progress: `${(count / archive.storage.length * 100).toFixed()}%`
7070
7707
  }, {
7071
- F: __dxlog_file25,
7708
+ F: __dxlog_file27,
7072
7709
  L: 101,
7073
7710
  S: void 0,
7074
7711
  C: (f, a) => f(...a)
7075
7712
  });
7076
7713
  }
7077
7714
  }
7078
- log22.info("committing changes..", void 0, {
7079
- F: __dxlog_file25,
7715
+ log24.info("committing changes..", void 0, {
7716
+ F: __dxlog_file27,
7080
7717
  L: 109,
7081
7718
  S: void 0,
7082
7719
  C: (f, a) => f(...a)
@@ -7088,10 +7725,10 @@ var importProfileData = async ({ storage, level }, archive) => {
7088
7725
  import { Event as Event10, synchronized as synchronized3 } from "@dxos/async";
7089
7726
  import { clientServiceBundle } from "@dxos/client-protocol";
7090
7727
  import { Context as Context10 } from "@dxos/context";
7091
- import { EdgeClient } from "@dxos/edge-client";
7092
- import { invariant as invariant20 } from "@dxos/invariant";
7728
+ import { EdgeClient, EdgeHttpClient, createStubEdgeIdentity } from "@dxos/edge-client";
7729
+ import { invariant as invariant21 } from "@dxos/invariant";
7093
7730
  import { PublicKey as PublicKey17 } from "@dxos/keys";
7094
- import { log as log24 } from "@dxos/log";
7731
+ import { log as log26 } from "@dxos/log";
7095
7732
  import { EdgeSignalManager, WebsocketSignalManager } from "@dxos/messaging";
7096
7733
  import { SwarmNetworkManager, createIceProvider, createRtcTransportFactory } from "@dxos/network-manager";
7097
7734
  import { trace as trace10 } from "@dxos/protocols";
@@ -7102,9 +7739,9 @@ import { WebsocketRpcClient } from "@dxos/websocket-rpc";
7102
7739
  // packages/sdk/client-services/src/packlets/devices/devices-service.ts
7103
7740
  import { EventSubscriptions as EventSubscriptions3 } from "@dxos/async";
7104
7741
  import { Stream as Stream11 } from "@dxos/codec-protobuf";
7105
- import { invariant as invariant19 } from "@dxos/invariant";
7742
+ import { invariant as invariant20 } from "@dxos/invariant";
7106
7743
  import { Device as Device2, DeviceKind as DeviceKind2 } from "@dxos/protocols/proto/dxos/client/services";
7107
- var __dxlog_file26 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
7744
+ var __dxlog_file28 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
7108
7745
  var DevicesServiceImpl = class {
7109
7746
  constructor(_identityManager) {
7110
7747
  this._identityManager = _identityManager;
@@ -7121,8 +7758,8 @@ var DevicesServiceImpl = class {
7121
7758
  devices: []
7122
7759
  });
7123
7760
  } else {
7124
- invariant19(this._identityManager.identity?.presence, "presence not present", {
7125
- F: __dxlog_file26,
7761
+ invariant20(this._identityManager.identity?.presence, "presence not present", {
7762
+ F: __dxlog_file28,
7126
7763
  L: 32,
7127
7764
  S: this,
7128
7765
  A: [
@@ -7182,7 +7819,7 @@ var DevicesServiceImpl = class {
7182
7819
  };
7183
7820
 
7184
7821
  // packages/sdk/client-services/src/packlets/identity/contacts-service.ts
7185
- import { EventSubscriptions as EventSubscriptions4, scheduleTask as scheduleTask7, UpdateScheduler as UpdateScheduler2 } from "@dxos/async";
7822
+ import { EventSubscriptions as EventSubscriptions4, scheduleTask as scheduleTask8, UpdateScheduler as UpdateScheduler2 } from "@dxos/async";
7186
7823
  import { Stream as Stream12 } from "@dxos/codec-protobuf";
7187
7824
  import { PublicKey as PublicKey15 } from "@dxos/keys";
7188
7825
  import { ComplexMap as ComplexMap5, ComplexSet as ComplexSet6 } from "@dxos/util";
@@ -7241,7 +7878,7 @@ var ContactsServiceImpl = class {
7241
7878
  }, {
7242
7879
  maxFrequency: 2
7243
7880
  });
7244
- scheduleTask7(ctx, async () => {
7881
+ scheduleTask8(ctx, async () => {
7245
7882
  const subscriptions = new EventSubscriptions4();
7246
7883
  ctx.onDispose(() => subscriptions.clear());
7247
7884
  const subscribeToSpaceAndUpdate = () => {
@@ -7268,7 +7905,7 @@ var ContactsServiceImpl = class {
7268
7905
  import { Event as Event9 } from "@dxos/async";
7269
7906
  import { Stream as Stream13 } from "@dxos/codec-protobuf";
7270
7907
  import { PublicKey as PublicKey16 } from "@dxos/keys";
7271
- import { getContextFromEntry, log as log23 } from "@dxos/log";
7908
+ import { getContextFromEntry, log as log25 } from "@dxos/log";
7272
7909
  import { QueryLogsRequest } from "@dxos/protocols/proto/dxos/client/services";
7273
7910
  import { getDebugName, jsonify, numericalValues, tracer } from "@dxos/util";
7274
7911
  var LoggingServiceImpl = class {
@@ -7281,11 +7918,11 @@ var LoggingServiceImpl = class {
7281
7918
  };
7282
7919
  }
7283
7920
  async open() {
7284
- log23.runtimeConfig.processors.push(this._logProcessor);
7921
+ log25.runtimeConfig.processors.push(this._logProcessor);
7285
7922
  }
7286
7923
  async close() {
7287
- const index = log23.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
7288
- log23.runtimeConfig.processors.splice(index, 1);
7924
+ const index = log25.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
7925
+ log25.runtimeConfig.processors.splice(index, 1);
7289
7926
  }
7290
7927
  async controlMetrics({ reset, record }) {
7291
7928
  if (reset) {
@@ -7479,13 +8116,13 @@ var SystemServiceImpl = class {
7479
8116
  };
7480
8117
 
7481
8118
  // packages/sdk/client-services/src/packlets/services/service-host.ts
7482
- function _ts_decorate8(decorators, target, key, desc) {
8119
+ function _ts_decorate10(decorators, target, key, desc) {
7483
8120
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
7484
8121
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
7485
8122
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
7486
8123
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7487
8124
  }
7488
- var __dxlog_file27 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
8125
+ var __dxlog_file29 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
7489
8126
  var ClientServicesHost = class {
7490
8127
  constructor({
7491
8128
  config,
@@ -7501,6 +8138,7 @@ var ClientServicesHost = class {
7501
8138
  this._tracingService = TRACE_PROCESSOR3.createTraceSender();
7502
8139
  this._statusUpdate = new Event10();
7503
8140
  this._edgeConnection = void 0;
8141
+ this._edgeHttpClient = void 0;
7504
8142
  this._opening = false;
7505
8143
  this._open = false;
7506
8144
  this._storage = storage;
@@ -7523,8 +8161,8 @@ var ClientServicesHost = class {
7523
8161
  onAcquire: () => {
7524
8162
  if (!this._opening) {
7525
8163
  void this.open(new Context10(void 0, {
7526
- F: __dxlog_file27,
7527
- L: 132
8164
+ F: __dxlog_file29,
8165
+ L: 133
7528
8166
  }));
7529
8167
  }
7530
8168
  },
@@ -7580,25 +8218,25 @@ var ClientServicesHost = class {
7580
8218
  * Can only be called once.
7581
8219
  */
7582
8220
  initialize({ config, ...options }) {
7583
- invariant20(!this._open, "service host is open", {
7584
- F: __dxlog_file27,
7585
- L: 198,
8221
+ invariant21(!this._open, "service host is open", {
8222
+ F: __dxlog_file29,
8223
+ L: 199,
7586
8224
  S: this,
7587
8225
  A: [
7588
8226
  "!this._open",
7589
8227
  "'service host is open'"
7590
8228
  ]
7591
8229
  });
7592
- log24("initializing...", void 0, {
7593
- F: __dxlog_file27,
7594
- L: 199,
8230
+ log26("initializing...", void 0, {
8231
+ F: __dxlog_file29,
8232
+ L: 200,
7595
8233
  S: this,
7596
8234
  C: (f, a) => f(...a)
7597
8235
  });
7598
8236
  if (config) {
7599
- invariant20(!this._config, "config already set", {
7600
- F: __dxlog_file27,
7601
- L: 202,
8237
+ invariant21(!this._config, "config already set", {
8238
+ F: __dxlog_file29,
8239
+ L: 203,
7602
8240
  S: this,
7603
8241
  A: [
7604
8242
  "!this._config",
@@ -7611,19 +8249,19 @@ var ClientServicesHost = class {
7611
8249
  }
7612
8250
  }
7613
8251
  if (!options.signalManager) {
7614
- log24.warn("running signaling without telemetry metadata.", void 0, {
7615
- F: __dxlog_file27,
7616
- L: 210,
8252
+ log26.warn("running signaling without telemetry metadata.", void 0, {
8253
+ F: __dxlog_file29,
8254
+ L: 211,
7617
8255
  S: this,
7618
8256
  C: (f, a) => f(...a)
7619
8257
  });
7620
8258
  }
7621
8259
  const edgeEndpoint = config?.get("runtime.services.edge.url");
7622
8260
  if (edgeEndpoint) {
7623
- const randomKey = PublicKey17.random().toHex();
7624
- this._edgeConnection = new EdgeClient(randomKey, randomKey, {
8261
+ this._edgeConnection = new EdgeClient(createStubEdgeIdentity(), {
7625
8262
  socketEndpoint: edgeEndpoint
7626
8263
  });
8264
+ this._edgeHttpClient = new EdgeHttpClient(edgeEndpoint);
7627
8265
  }
7628
8266
  const { connectionLog = true, transportFactory = createRtcTransportFactory({
7629
8267
  iceServers: this._config?.get("runtime.services.ice")
@@ -7631,9 +8269,9 @@ var ClientServicesHost = class {
7631
8269
  edgeConnection: this._edgeConnection
7632
8270
  }) : new WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
7633
8271
  this._signalManager = signalManager;
7634
- invariant20(!this._networkManager, "network manager already set", {
7635
- F: __dxlog_file27,
7636
- L: 232,
8272
+ invariant21(!this._networkManager, "network manager already set", {
8273
+ F: __dxlog_file29,
8274
+ L: 233,
7637
8275
  S: this,
7638
8276
  A: [
7639
8277
  "!this._networkManager",
@@ -7649,9 +8287,9 @@ var ClientServicesHost = class {
7649
8287
  peerKey: this._edgeConnection.peerKey
7650
8288
  } : void 0
7651
8289
  });
7652
- log24("initialized", void 0, {
7653
- F: __dxlog_file27,
7654
- L: 245,
8290
+ log26("initialized", void 0, {
8291
+ F: __dxlog_file29,
8292
+ L: 246,
7655
8293
  S: this,
7656
8294
  C: (f, a) => f(...a)
7657
8295
  });
@@ -7661,44 +8299,44 @@ var ClientServicesHost = class {
7661
8299
  return;
7662
8300
  }
7663
8301
  const traceId = PublicKey17.random().toHex();
7664
- log24.trace("dxos.client-services.host.open", trace10.begin({
8302
+ log26.trace("dxos.client-services.host.open", trace10.begin({
7665
8303
  id: traceId
7666
8304
  }), {
7667
- F: __dxlog_file27,
7668
- L: 256,
8305
+ F: __dxlog_file29,
8306
+ L: 257,
7669
8307
  S: this,
7670
8308
  C: (f, a) => f(...a)
7671
8309
  });
7672
- invariant20(this._config, "config not set", {
7673
- F: __dxlog_file27,
7674
- L: 258,
8310
+ invariant21(this._config, "config not set", {
8311
+ F: __dxlog_file29,
8312
+ L: 259,
7675
8313
  S: this,
7676
8314
  A: [
7677
8315
  "this._config",
7678
8316
  "'config not set'"
7679
8317
  ]
7680
8318
  });
7681
- invariant20(this._storage, "storage not set", {
7682
- F: __dxlog_file27,
7683
- L: 259,
8319
+ invariant21(this._storage, "storage not set", {
8320
+ F: __dxlog_file29,
8321
+ L: 260,
7684
8322
  S: this,
7685
8323
  A: [
7686
8324
  "this._storage",
7687
8325
  "'storage not set'"
7688
8326
  ]
7689
8327
  });
7690
- invariant20(this._signalManager, "signal manager not set", {
7691
- F: __dxlog_file27,
7692
- L: 260,
8328
+ invariant21(this._signalManager, "signal manager not set", {
8329
+ F: __dxlog_file29,
8330
+ L: 261,
7693
8331
  S: this,
7694
8332
  A: [
7695
8333
  "this._signalManager",
7696
8334
  "'signal manager not set'"
7697
8335
  ]
7698
8336
  });
7699
- invariant20(this._networkManager, "network manager not set", {
7700
- F: __dxlog_file27,
7701
- L: 261,
8337
+ invariant21(this._networkManager, "network manager not set", {
8338
+ F: __dxlog_file29,
8339
+ L: 262,
7702
8340
  S: this,
7703
8341
  A: [
7704
8342
  "this._networkManager",
@@ -7706,11 +8344,11 @@ var ClientServicesHost = class {
7706
8344
  ]
7707
8345
  });
7708
8346
  this._opening = true;
7709
- log24("opening...", {
8347
+ log26("opening...", {
7710
8348
  lockKey: this._resourceLock?.lockKey
7711
8349
  }, {
7712
- F: __dxlog_file27,
7713
- L: 264,
8350
+ F: __dxlog_file29,
8351
+ L: 265,
7714
8352
  S: this,
7715
8353
  C: (f, a) => f(...a)
7716
8354
  });
@@ -7720,7 +8358,7 @@ var ClientServicesHost = class {
7720
8358
  }
7721
8359
  await this._level.open();
7722
8360
  await this._loggingService.open();
7723
- this._serviceContext = new ServiceContext(this._storage, this._level, this._networkManager, this._signalManager, this._edgeConnection, this._runtimeParams, this._config.get("runtime.client.edgeFeatures"));
8361
+ this._serviceContext = new ServiceContext(this._storage, this._level, this._networkManager, this._signalManager, this._edgeConnection, this._edgeHttpClient, this._runtimeParams, this._config.get("runtime.client.edgeFeatures"));
7724
8362
  const dataSpaceManagerProvider = async () => {
7725
8363
  await this._serviceContext.initialized.wait();
7726
8364
  return this._serviceContext.dataSpaceManager;
@@ -7762,19 +8400,19 @@ var ClientServicesHost = class {
7762
8400
  this._open = true;
7763
8401
  this._statusUpdate.emit();
7764
8402
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
7765
- log24("opened", {
8403
+ log26("opened", {
7766
8404
  deviceKey
7767
8405
  }, {
7768
- F: __dxlog_file27,
7769
- L: 352,
8406
+ F: __dxlog_file29,
8407
+ L: 354,
7770
8408
  S: this,
7771
8409
  C: (f, a) => f(...a)
7772
8410
  });
7773
- log24.trace("dxos.client-services.host.open", trace10.end({
8411
+ log26.trace("dxos.client-services.host.open", trace10.end({
7774
8412
  id: traceId
7775
8413
  }), {
7776
- F: __dxlog_file27,
7777
- L: 353,
8414
+ F: __dxlog_file29,
8415
+ L: 355,
7778
8416
  S: this,
7779
8417
  C: (f, a) => f(...a)
7780
8418
  });
@@ -7784,11 +8422,11 @@ var ClientServicesHost = class {
7784
8422
  return;
7785
8423
  }
7786
8424
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
7787
- log24("closing...", {
8425
+ log26("closing...", {
7788
8426
  deviceKey
7789
8427
  }, {
7790
- F: __dxlog_file27,
7791
- L: 364,
8428
+ F: __dxlog_file29,
8429
+ L: 366,
7792
8430
  S: this,
7793
8431
  C: (f, a) => f(...a)
7794
8432
  });
@@ -7802,44 +8440,44 @@ var ClientServicesHost = class {
7802
8440
  await this._level?.close();
7803
8441
  this._open = false;
7804
8442
  this._statusUpdate.emit();
7805
- log24("closed", {
8443
+ log26("closed", {
7806
8444
  deviceKey
7807
8445
  }, {
7808
- F: __dxlog_file27,
7809
- L: 373,
8446
+ F: __dxlog_file29,
8447
+ L: 375,
7810
8448
  S: this,
7811
8449
  C: (f, a) => f(...a)
7812
8450
  });
7813
8451
  }
7814
8452
  async reset() {
7815
8453
  const traceId = PublicKey17.random().toHex();
7816
- log24.trace("dxos.sdk.client-services-host.reset", trace10.begin({
8454
+ log26.trace("dxos.sdk.client-services-host.reset", trace10.begin({
7817
8455
  id: traceId
7818
8456
  }), {
7819
- F: __dxlog_file27,
7820
- L: 378,
8457
+ F: __dxlog_file29,
8458
+ L: 380,
7821
8459
  S: this,
7822
8460
  C: (f, a) => f(...a)
7823
8461
  });
7824
- log24.info("resetting...", void 0, {
7825
- F: __dxlog_file27,
7826
- L: 380,
8462
+ log26.info("resetting...", void 0, {
8463
+ F: __dxlog_file29,
8464
+ L: 382,
7827
8465
  S: this,
7828
8466
  C: (f, a) => f(...a)
7829
8467
  });
7830
8468
  await this._serviceContext?.close();
7831
8469
  await this._storage.reset();
7832
- log24.info("reset", void 0, {
7833
- F: __dxlog_file27,
7834
- L: 383,
8470
+ log26.info("reset", void 0, {
8471
+ F: __dxlog_file29,
8472
+ L: 385,
7835
8473
  S: this,
7836
8474
  C: (f, a) => f(...a)
7837
8475
  });
7838
- log24.trace("dxos.sdk.client-services-host.reset", trace10.end({
8476
+ log26.trace("dxos.sdk.client-services-host.reset", trace10.end({
7839
8477
  id: traceId
7840
8478
  }), {
7841
- F: __dxlog_file27,
7842
- L: 384,
8479
+ F: __dxlog_file29,
8480
+ L: 386,
7843
8481
  S: this,
7844
8482
  C: (f, a) => f(...a)
7845
8483
  });
@@ -7851,21 +8489,21 @@ var ClientServicesHost = class {
7851
8489
  return identity;
7852
8490
  }
7853
8491
  };
7854
- _ts_decorate8([
8492
+ _ts_decorate10([
7855
8493
  Trace4.info()
7856
8494
  ], ClientServicesHost.prototype, "_opening", void 0);
7857
- _ts_decorate8([
8495
+ _ts_decorate10([
7858
8496
  Trace4.info()
7859
8497
  ], ClientServicesHost.prototype, "_open", void 0);
7860
- _ts_decorate8([
8498
+ _ts_decorate10([
7861
8499
  synchronized3,
7862
8500
  Trace4.span()
7863
8501
  ], ClientServicesHost.prototype, "open", null);
7864
- _ts_decorate8([
8502
+ _ts_decorate10([
7865
8503
  synchronized3,
7866
8504
  Trace4.span()
7867
8505
  ], ClientServicesHost.prototype, "close", null);
7868
- ClientServicesHost = _ts_decorate8([
8506
+ ClientServicesHost = _ts_decorate10([
7869
8507
  Trace4.resource()
7870
8508
  ], ClientServicesHost);
7871
8509
 
@@ -7913,4 +8551,4 @@ export {
7913
8551
  importProfileData,
7914
8552
  ClientServicesHost
7915
8553
  };
7916
- //# sourceMappingURL=chunk-BDGSOBZV.mjs.map
8554
+ //# sourceMappingURL=chunk-WU4ZS3F3.mjs.map