@dxos/client-services 0.6.12-main.15a606f → 0.6.12-main.568932b

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 (59) hide show
  1. package/dist/lib/browser/{chunk-BDGSOBZV.mjs → chunk-AHZ7ASHC.mjs} +695 -268
  2. package/dist/lib/browser/chunk-AHZ7ASHC.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 +2 -2
  6. package/dist/lib/browser/testing/index.mjs.map +2 -2
  7. package/dist/lib/node/{chunk-EBZ7KFXS.cjs → chunk-YJWFC43Y.cjs} +803 -376
  8. package/dist/lib/node/chunk-YJWFC43Y.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 +8 -8
  12. package/dist/lib/node/testing/index.cjs.map +2 -2
  13. package/dist/lib/node-esm/{chunk-LDBJYNPL.mjs → chunk-7ADUGZEP.mjs} +695 -268
  14. package/dist/lib/node-esm/chunk-7ADUGZEP.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 +2 -2
  18. package/dist/lib/node-esm/testing/index.mjs.map +2 -2
  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/services/service-context.d.ts +4 -2
  25. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  26. package/dist/types/src/packlets/services/service-host.d.ts +1 -0
  27. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  28. package/dist/types/src/packlets/spaces/data-space-manager.d.ts +5 -1
  29. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  30. package/dist/types/src/packlets/spaces/data-space.d.ts +3 -1
  31. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  32. package/dist/types/src/packlets/spaces/edge-feed-replicator.d.ts +3 -0
  33. package/dist/types/src/packlets/spaces/edge-feed-replicator.d.ts.map +1 -1
  34. package/dist/types/src/packlets/spaces/edge-feed-replicator.test.d.ts +2 -0
  35. package/dist/types/src/packlets/spaces/edge-feed-replicator.test.d.ts.map +1 -0
  36. package/dist/types/src/packlets/spaces/notarization-plugin.d.ts +31 -6
  37. package/dist/types/src/packlets/spaces/notarization-plugin.d.ts.map +1 -1
  38. package/dist/types/src/packlets/spaces/spaces-service.d.ts +1 -1
  39. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  40. package/dist/types/src/version.d.ts +1 -1
  41. package/package.json +39 -38
  42. package/src/packlets/identity/authenticator.ts +5 -2
  43. package/src/packlets/identity/contacts-service.ts +1 -1
  44. package/src/packlets/identity/identity.test.ts +4 -0
  45. package/src/packlets/identity/identity.ts +4 -0
  46. package/src/packlets/services/service-context.ts +41 -17
  47. package/src/packlets/services/service-host.ts +7 -5
  48. package/src/packlets/spaces/data-space-manager.ts +34 -4
  49. package/src/packlets/spaces/data-space.ts +27 -4
  50. package/src/packlets/spaces/edge-feed-replicator.test.ts +251 -0
  51. package/src/packlets/spaces/edge-feed-replicator.ts +72 -19
  52. package/src/packlets/spaces/notarization-plugin.test.ts +8 -4
  53. package/src/packlets/spaces/notarization-plugin.ts +169 -29
  54. package/src/packlets/spaces/spaces-service.ts +6 -1
  55. package/src/packlets/testing/test-builder.ts +1 -1
  56. package/src/version.ts +1 -1
  57. package/dist/lib/browser/chunk-BDGSOBZV.mjs.map +0 -7
  58. package/dist/lib/node/chunk-EBZ7KFXS.cjs.map +0 -7
  59. 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.568932b";
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,20 @@ 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
+ }
2339
2611
  });
2340
2612
  dataSpace.preClose.append(async () => {
2341
- await this._echoEdgeReplicator?.disconnectFromSpace(dataSpace.id);
2613
+ const setting = dataSpace.getEdgeReplicationSetting();
2614
+ if (setting === EdgeReplicationSetting.ENABLED) {
2615
+ await this._echoEdgeReplicator?.disconnectFromSpace(dataSpace.id);
2616
+ }
2342
2617
  });
2343
2618
  presence.newPeer.on((peerState) => {
2344
2619
  if (dataSpace.state === SpaceState.SPACE_READY) {
@@ -2358,7 +2633,7 @@ var DataSpaceManager = class extends Resource3 {
2358
2633
  space: space.key
2359
2634
  }, {
2360
2635
  F: __dxlog_file10,
2361
- L: 511,
2636
+ L: 541,
2362
2637
  S: this,
2363
2638
  C: (f, a) => f(...a)
2364
2639
  });
@@ -2391,7 +2666,7 @@ var DataSpaceManager = class extends Resource3 {
2391
2666
  closedSessions
2392
2667
  }, {
2393
2668
  F: __dxlog_file10,
2394
- L: 537,
2669
+ L: 567,
2395
2670
  S: this,
2396
2671
  C: (f, a) => f(...a)
2397
2672
  });
@@ -2406,7 +2681,7 @@ var DataSpaceManager = class extends Resource3 {
2406
2681
  peerId: peerState.peerId
2407
2682
  }, {
2408
2683
  F: __dxlog_file10,
2409
- L: 551,
2684
+ L: 581,
2410
2685
  S: this,
2411
2686
  C: (f, a) => f(...a)
2412
2687
  });
@@ -2450,19 +2725,19 @@ var DataSpaceManager = class extends Resource3 {
2450
2725
  await Promise.all(tasks);
2451
2726
  }
2452
2727
  };
2453
- _ts_decorate([
2728
+ _ts_decorate3([
2454
2729
  synchronized
2455
2730
  ], DataSpaceManager.prototype, "_open", null);
2456
- _ts_decorate([
2731
+ _ts_decorate3([
2457
2732
  synchronized
2458
2733
  ], DataSpaceManager.prototype, "_close", null);
2459
- _ts_decorate([
2734
+ _ts_decorate3([
2460
2735
  synchronized
2461
2736
  ], DataSpaceManager.prototype, "createSpace", null);
2462
- _ts_decorate([
2737
+ _ts_decorate3([
2463
2738
  synchronized
2464
2739
  ], DataSpaceManager.prototype, "acceptSpace", null);
2465
- DataSpaceManager = _ts_decorate([
2740
+ DataSpaceManager = _ts_decorate3([
2466
2741
  trackLeaks("open", "close")
2467
2742
  ], DataSpaceManager);
2468
2743
 
@@ -2491,7 +2766,7 @@ var SpacesServiceImpl = class {
2491
2766
  await this._updateMetrics();
2492
2767
  return this._serializeSpace(space);
2493
2768
  }
2494
- async updateSpace({ spaceKey, state }) {
2769
+ async updateSpace({ spaceKey, state, edgeReplication }) {
2495
2770
  const dataSpaceManager = await this._getDataSpaceManager();
2496
2771
  const space = dataSpaceManager.spaces.get(spaceKey) ?? raise(new SpaceNotFoundError(spaceKey));
2497
2772
  if (state) {
@@ -2506,6 +2781,9 @@ var SpacesServiceImpl = class {
2506
2781
  throw new ApiError("Invalid space state");
2507
2782
  }
2508
2783
  }
2784
+ if (edgeReplication !== void 0) {
2785
+ await dataSpaceManager.setSpaceEdgeReplicationSetting(spaceKey, edgeReplication);
2786
+ }
2509
2787
  }
2510
2788
  async updateMemberRole(request) {
2511
2789
  const identity = this._requireIdentity();
@@ -2522,7 +2800,7 @@ var SpacesServiceImpl = class {
2522
2800
  const credentials = await createAdmissionCredentials2(identity.getIdentityCredentialSigner(), request.memberKey, space.key, space.genesisFeedKey, request.newRole, space.spaceState.membershipChainHeads);
2523
2801
  invariant6(credentials[0].credential, void 0, {
2524
2802
  F: __dxlog_file11,
2525
- L: 102,
2803
+ L: 106,
2526
2804
  S: this,
2527
2805
  A: [
2528
2806
  "credentials[0].credential",
@@ -2532,7 +2810,7 @@ var SpacesServiceImpl = class {
2532
2810
  const spaceMemberCredential = credentials[0].credential.credential;
2533
2811
  invariant6(getCredentialAssertion3(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2534
2812
  F: __dxlog_file11,
2535
- L: 104,
2813
+ L: 108,
2536
2814
  S: this,
2537
2815
  A: [
2538
2816
  "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2550,7 +2828,7 @@ var SpacesServiceImpl = class {
2550
2828
  ids: spaces.map((space) => space.id)
2551
2829
  }), {
2552
2830
  F: __dxlog_file11,
2553
- L: 115,
2831
+ L: 119,
2554
2832
  S: this,
2555
2833
  C: (f, a) => f(...a)
2556
2834
  });
@@ -2642,7 +2920,7 @@ var SpacesServiceImpl = class {
2642
2920
  } else {
2643
2921
  invariant6(!credential.id, "Id on unsigned credentials is not allowed", {
2644
2922
  F: __dxlog_file11,
2645
- L: 213,
2923
+ L: 217,
2646
2924
  S: this,
2647
2925
  A: [
2648
2926
  "!credential.id",
@@ -2651,7 +2929,7 @@ var SpacesServiceImpl = class {
2651
2929
  });
2652
2930
  invariant6(this._identityManager.identity, "Identity is not available", {
2653
2931
  F: __dxlog_file11,
2654
- L: 214,
2932
+ L: 218,
2655
2933
  S: this,
2656
2934
  A: [
2657
2935
  "this._identityManager.identity",
@@ -2661,7 +2939,7 @@ var SpacesServiceImpl = class {
2661
2939
  const signer = this._identityManager.identity.getIdentityCredentialSigner();
2662
2940
  invariant6(credential.issuer.equals(signer.getIssuer()), void 0, {
2663
2941
  F: __dxlog_file11,
2664
- L: 216,
2942
+ L: 220,
2665
2943
  S: this,
2666
2944
  A: [
2667
2945
  "credential.issuer.equals(signer.getIssuer())",
@@ -2711,7 +2989,7 @@ var SpacesServiceImpl = class {
2711
2989
  const assertion = getCredentialAssertion3(credential);
2712
2990
  invariant6(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
2713
2991
  F: __dxlog_file11,
2714
- L: 250,
2992
+ L: 254,
2715
2993
  S: this,
2716
2994
  A: [
2717
2995
  "assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2721,7 +2999,7 @@ var SpacesServiceImpl = class {
2721
2999
  const myIdentity = this._identityManager.identity;
2722
3000
  invariant6(myIdentity && credential.subject.id.equals(myIdentity.identityKey), void 0, {
2723
3001
  F: __dxlog_file11,
2724
- L: 252,
3002
+ L: 256,
2725
3003
  S: this,
2726
3004
  A: [
2727
3005
  "myIdentity && credential.subject.id.equals(myIdentity.identityKey)",
@@ -2783,7 +3061,8 @@ var SpacesServiceImpl = class {
2783
3061
  }),
2784
3062
  creator: space.inner.spaceState.creator?.key,
2785
3063
  cache: space.cache,
2786
- metrics: space.metrics
3064
+ metrics: space.metrics,
3065
+ edgeReplication: space.getEdgeReplicationSetting()
2787
3066
  };
2788
3067
  }
2789
3068
  _requireIdentity() {
@@ -2807,7 +3086,7 @@ var SpacesServiceImpl = class {
2807
3086
  var getChannelId = (channel) => `user-channel/${channel}`;
2808
3087
 
2809
3088
  // packages/sdk/client-services/src/packlets/identity/identity.ts
2810
- function _ts_decorate2(decorators, target, key, desc) {
3089
+ function _ts_decorate4(decorators, target, key, desc) {
2811
3090
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2812
3091
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2813
3092
  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 +3195,9 @@ var Identity = class {
2916
3195
  get presence() {
2917
3196
  return this._presence;
2918
3197
  }
3198
+ get signer() {
3199
+ return this._signer;
3200
+ }
2919
3201
  /**
2920
3202
  * Issues credentials as identity.
2921
3203
  * Requires identity to be ready.
@@ -2923,7 +3205,7 @@ var Identity = class {
2923
3205
  getIdentityCredentialSigner() {
2924
3206
  invariant7(this._deviceStateMachine.deviceCredentialChain, "Device credential chain is not ready.", {
2925
3207
  F: __dxlog_file12,
2926
- L: 185,
3208
+ L: 189,
2927
3209
  S: this,
2928
3210
  A: [
2929
3211
  "this._deviceStateMachine.deviceCredentialChain",
@@ -2967,7 +3249,7 @@ var Identity = class {
2967
3249
  dataFeedKey
2968
3250
  }, {
2969
3251
  F: __dxlog_file12,
2970
- L: 210,
3252
+ L: 214,
2971
3253
  S: this,
2972
3254
  C: (f, a) => f(...a)
2973
3255
  });
@@ -3008,13 +3290,13 @@ var Identity = class {
3008
3290
  })));
3009
3291
  }
3010
3292
  };
3011
- _ts_decorate2([
3293
+ _ts_decorate4([
3012
3294
  trace3.span()
3013
3295
  ], Identity.prototype, "open", null);
3014
- _ts_decorate2([
3296
+ _ts_decorate4([
3015
3297
  trace3.span()
3016
3298
  ], Identity.prototype, "close", null);
3017
- Identity = _ts_decorate2([
3299
+ Identity = _ts_decorate4([
3018
3300
  trace3.resource()
3019
3301
  ], Identity);
3020
3302
 
@@ -3033,7 +3315,7 @@ import { Gossip as Gossip2, Presence as Presence2 } from "@dxos/teleport-extensi
3033
3315
  import { Timeframe as Timeframe3 } from "@dxos/timeframe";
3034
3316
  import { trace as Trace2 } from "@dxos/tracing";
3035
3317
  import { isNode, deferFunction as deferFunction2 } from "@dxos/util";
3036
- function _ts_decorate3(decorators, target, key, desc) {
3318
+ function _ts_decorate5(decorators, target, key, desc) {
3037
3319
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3038
3320
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
3039
3321
  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 +3766,19 @@ var IdentityManager = class {
3484
3766
  });
3485
3767
  }
3486
3768
  };
3487
- _ts_decorate3([
3769
+ _ts_decorate5([
3488
3770
  Trace2.span({
3489
3771
  showInBrowserTimeline: true
3490
3772
  })
3491
3773
  ], IdentityManager.prototype, "open", null);
3492
- IdentityManager = _ts_decorate3([
3774
+ IdentityManager = _ts_decorate5([
3493
3775
  Trace2.resource()
3494
3776
  ], IdentityManager);
3495
3777
 
3496
3778
  // packages/sdk/client-services/src/packlets/identity/identity-service.ts
3497
3779
  import { Trigger as Trigger4, sleep as sleep2 } from "@dxos/async";
3498
3780
  import { Stream as Stream8 } from "@dxos/codec-protobuf";
3499
- import { Resource as Resource4 } from "@dxos/context";
3781
+ import { Resource as Resource5 } from "@dxos/context";
3500
3782
  import { signPresentation } from "@dxos/credentials";
3501
3783
  import { todo } from "@dxos/debug";
3502
3784
  import { invariant as invariant9 } from "@dxos/invariant";
@@ -3505,7 +3787,7 @@ import { SpaceState as SpaceState3 } from "@dxos/protocols/proto/dxos/client/ser
3505
3787
  import { safeAwaitAll } from "@dxos/util";
3506
3788
  var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-service.ts";
3507
3789
  var DEFAULT_SPACE_SEARCH_TIMEOUT = 1e4;
3508
- var IdentityServiceImpl = class extends Resource4 {
3790
+ var IdentityServiceImpl = class extends Resource5 {
3509
3791
  constructor(_identityManager, _keyring, _dataSpaceManagerProvider, _createIdentity, _onProfileUpdate) {
3510
3792
  super();
3511
3793
  this._identityManager = _identityManager;
@@ -3649,7 +3931,7 @@ var IdentityServiceImpl = class extends Resource4 {
3649
3931
  };
3650
3932
 
3651
3933
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
3652
- function _ts_decorate4(decorators, target, key, desc) {
3934
+ function _ts_decorate6(decorators, target, key, desc) {
3653
3935
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3654
3936
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
3655
3937
  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 +4004,8 @@ var DataSpace = class {
3722
4004
  constructor(params) {
3723
4005
  this._ctx = new Context5(void 0, {
3724
4006
  F: __dxlog_file15,
3725
- L: 94
4007
+ L: 95
3726
4008
  });
3727
- this._notarizationPlugin = new NotarizationPlugin();
3728
4009
  this._cache = void 0;
3729
4010
  this._edgeFeedReplicator = void 0;
3730
4011
  // TODO(dmaretskyi): Move into Space?
@@ -3753,6 +4034,11 @@ var DataSpace = class {
3753
4034
  this._signingContext = params.signingContext;
3754
4035
  this._callbacks = params.callbacks ?? {};
3755
4036
  this._echoHost = params.echoHost;
4037
+ this._notarizationPlugin = new NotarizationPlugin({
4038
+ spaceId: this._inner.id,
4039
+ edgeClient: params.edgeHttpClient,
4040
+ edgeFeatures: params.edgeFeatures
4041
+ });
3756
4042
  this.authVerifier = new TrustedKeySetAuthVerifier({
3757
4043
  trustedKeysProvider: () => new ComplexSet3(PublicKey8.hash, Array.from(this._inner.spaceState.members.values()).filter((member) => member.role !== SpaceMember5.Role.REMOVED).map((member) => member.key)),
3758
4044
  update: this._inner.stateUpdate,
@@ -3770,7 +4056,7 @@ var DataSpace = class {
3770
4056
  state: SpaceState4[this._state]
3771
4057
  }, {
3772
4058
  F: __dxlog_file15,
3773
- L: 164,
4059
+ L: 170,
3774
4060
  S: this,
3775
4061
  C: (f, a) => f(...a)
3776
4062
  });
@@ -3829,7 +4115,7 @@ var DataSpace = class {
3829
4115
  }
3830
4116
  await this._inner.open(new Context5(void 0, {
3831
4117
  F: __dxlog_file15,
3832
- L: 238
4118
+ L: 244
3833
4119
  }));
3834
4120
  await this._edgeFeedReplicator?.open();
3835
4121
  this._state = SpaceState4.SPACE_CONTROL_ONLY;
@@ -3837,7 +4123,7 @@ var DataSpace = class {
3837
4123
  state: SpaceState4[this._state]
3838
4124
  }, {
3839
4125
  F: __dxlog_file15,
3840
- L: 243,
4126
+ L: 249,
3841
4127
  S: this,
3842
4128
  C: (f, a) => f(...a)
3843
4129
  });
@@ -3857,14 +4143,14 @@ var DataSpace = class {
3857
4143
  state: SpaceState4[this._state]
3858
4144
  }, {
3859
4145
  F: __dxlog_file15,
3860
- L: 262,
4146
+ L: 268,
3861
4147
  S: this,
3862
4148
  C: (f, a) => f(...a)
3863
4149
  });
3864
4150
  await this._ctx.dispose();
3865
4151
  this._ctx = new Context5(void 0, {
3866
4152
  F: __dxlog_file15,
3867
- L: 264
4153
+ L: 270
3868
4154
  });
3869
4155
  if (this._edgeFeedReplicator) {
3870
4156
  this.inner.protocol.feedAdded.remove(this._onFeedAdded);
@@ -3897,7 +4183,7 @@ var DataSpace = class {
3897
4183
  if (err instanceof CancelledError || err instanceof ContextDisposedError) {
3898
4184
  log13("data pipeline initialization cancelled", err, {
3899
4185
  F: __dxlog_file15,
3900
- L: 302,
4186
+ L: 308,
3901
4187
  S: this,
3902
4188
  C: (f, a) => f(...a)
3903
4189
  });
@@ -3905,7 +4191,7 @@ var DataSpace = class {
3905
4191
  }
3906
4192
  log13.error("Error initializing data pipeline", err, {
3907
4193
  F: __dxlog_file15,
3908
- L: 306,
4194
+ L: 312,
3909
4195
  S: this,
3910
4196
  C: (f, a) => f(...a)
3911
4197
  });
@@ -3914,7 +4200,7 @@ var DataSpace = class {
3914
4200
  state: SpaceState4[this._state]
3915
4201
  }, {
3916
4202
  F: __dxlog_file15,
3917
- L: 308,
4203
+ L: 314,
3918
4204
  S: this,
3919
4205
  C: (f, a) => f(...a)
3920
4206
  });
@@ -3934,15 +4220,39 @@ var DataSpace = class {
3934
4220
  state: SpaceState4[this._state]
3935
4221
  }, {
3936
4222
  F: __dxlog_file15,
3937
- L: 324,
4223
+ L: 330,
4224
+ S: this,
4225
+ C: (f, a) => f(...a)
4226
+ });
4227
+ log13("initializing control pipeline", void 0, {
4228
+ F: __dxlog_file15,
4229
+ L: 332,
3938
4230
  S: this,
3939
4231
  C: (f, a) => f(...a)
3940
4232
  });
3941
4233
  await this._initializeAndReadControlPipeline();
3942
4234
  await sleep3(1);
3943
4235
  const ready = this.stateUpdate.waitForCondition(() => this._state === SpaceState4.SPACE_READY);
4236
+ log13("initializing automerge root", void 0, {
4237
+ F: __dxlog_file15,
4238
+ L: 340,
4239
+ S: this,
4240
+ C: (f, a) => f(...a)
4241
+ });
3944
4242
  this._automergeSpaceState.startProcessingRootDocs();
4243
+ log13("waiting for space to be ready", void 0, {
4244
+ F: __dxlog_file15,
4245
+ L: 344,
4246
+ S: this,
4247
+ C: (f, a) => f(...a)
4248
+ });
3945
4249
  await ready;
4250
+ log13("space is ready", void 0, {
4251
+ F: __dxlog_file15,
4252
+ L: 346,
4253
+ S: this,
4254
+ C: (f, a) => f(...a)
4255
+ });
3946
4256
  }
3947
4257
  async _enterReadyState() {
3948
4258
  await this._callbacks.beforeReady?.();
@@ -3951,7 +4261,7 @@ var DataSpace = class {
3951
4261
  state: SpaceState4[this._state]
3952
4262
  }, {
3953
4263
  F: __dxlog_file15,
3954
- L: 343,
4264
+ L: 353,
3955
4265
  S: this,
3956
4266
  C: (f, a) => f(...a)
3957
4267
  });
@@ -3961,13 +4271,14 @@ var DataSpace = class {
3961
4271
  async _initializeAndReadControlPipeline() {
3962
4272
  await this._inner.controlPipeline.state.waitUntilReachedTargetTimeframe({
3963
4273
  ctx: this._ctx,
4274
+ timeout: 1e4,
3964
4275
  breakOnStall: false
3965
4276
  });
3966
4277
  this.metrics.controlPipelineReady = /* @__PURE__ */ new Date();
3967
4278
  await this._createWritableFeeds();
3968
4279
  log13("writable feeds created", void 0, {
3969
4280
  F: __dxlog_file15,
3970
- L: 359,
4281
+ L: 370,
3971
4282
  S: this,
3972
4283
  C: (f, a) => f(...a)
3973
4284
  });
@@ -4016,11 +4327,35 @@ var DataSpace = class {
4016
4327
  }));
4017
4328
  }
4018
4329
  if (credentials.length > 0) {
4019
- await this.notarizationPlugin.notarize({
4020
- ctx: this._ctx,
4021
- credentials,
4022
- timeout: 0
4023
- });
4330
+ try {
4331
+ log13("will notarize credentials for feed admission", {
4332
+ count: credentials.length
4333
+ }, {
4334
+ F: __dxlog_file15,
4335
+ L: 428,
4336
+ S: this,
4337
+ C: (f, a) => f(...a)
4338
+ });
4339
+ await this.notarizationPlugin.notarize({
4340
+ ctx: this._ctx,
4341
+ credentials,
4342
+ timeout: 0
4343
+ });
4344
+ log13("credentials notarized", void 0, {
4345
+ F: __dxlog_file15,
4346
+ L: 432,
4347
+ S: this,
4348
+ C: (f, a) => f(...a)
4349
+ });
4350
+ } catch (err) {
4351
+ log13.error("error notarizing credentials for feed admission", err, {
4352
+ F: __dxlog_file15,
4353
+ L: 434,
4354
+ S: this,
4355
+ C: (f, a) => f(...a)
4356
+ });
4357
+ throw err;
4358
+ }
4024
4359
  await this._metadataStore.setWritableFeedKeys(this.key, this.inner.controlFeedKey, this.inner.dataFeedKey);
4025
4360
  }
4026
4361
  }
@@ -4030,7 +4365,7 @@ var DataSpace = class {
4030
4365
  rootUrl
4031
4366
  }, {
4032
4367
  F: __dxlog_file15,
4033
- L: 425,
4368
+ L: 444,
4034
4369
  S: this,
4035
4370
  C: (f, a) => f(...a)
4036
4371
  });
@@ -4082,7 +4417,7 @@ var DataSpace = class {
4082
4417
  err
4083
4418
  }, {
4084
4419
  F: __dxlog_file15,
4085
- L: 468,
4420
+ L: 487,
4086
4421
  S: this,
4087
4422
  C: (f, a) => f(...a)
4088
4423
  });
@@ -4172,58 +4507,61 @@ var DataSpace = class {
4172
4507
  state: SpaceState4[this._state]
4173
4508
  }, {
4174
4509
  F: __dxlog_file15,
4175
- L: 550,
4510
+ L: 569,
4176
4511
  S: this,
4177
4512
  C: (f, a) => f(...a)
4178
4513
  });
4179
4514
  this.stateUpdate.emit();
4180
4515
  }
4516
+ getEdgeReplicationSetting() {
4517
+ return this._metadataStore.getSpaceEdgeReplicationSetting(this.key);
4518
+ }
4181
4519
  };
4182
- _ts_decorate4([
4520
+ _ts_decorate6([
4183
4521
  trace5.info()
4184
4522
  ], DataSpace.prototype, "_inner", void 0);
4185
- _ts_decorate4([
4523
+ _ts_decorate6([
4186
4524
  trace5.info()
4187
4525
  ], DataSpace.prototype, "id", null);
4188
- _ts_decorate4([
4526
+ _ts_decorate6([
4189
4527
  trace5.info()
4190
4528
  ], DataSpace.prototype, "key", null);
4191
- _ts_decorate4([
4529
+ _ts_decorate6([
4192
4530
  trace5.info({
4193
4531
  enum: SpaceState4
4194
4532
  })
4195
4533
  ], DataSpace.prototype, "state", null);
4196
- _ts_decorate4([
4534
+ _ts_decorate6([
4197
4535
  trace5.info({
4198
4536
  depth: null
4199
4537
  })
4200
4538
  ], DataSpace.prototype, "_automergeInfo", null);
4201
- _ts_decorate4([
4539
+ _ts_decorate6([
4202
4540
  synchronized2
4203
4541
  ], DataSpace.prototype, "open", null);
4204
- _ts_decorate4([
4542
+ _ts_decorate6([
4205
4543
  synchronized2
4206
4544
  ], DataSpace.prototype, "close", null);
4207
- _ts_decorate4([
4545
+ _ts_decorate6([
4208
4546
  trace5.span({
4209
4547
  showInBrowserTimeline: true
4210
4548
  })
4211
4549
  ], DataSpace.prototype, "initializeDataPipeline", null);
4212
- _ts_decorate4([
4550
+ _ts_decorate6([
4213
4551
  trace5.span({
4214
4552
  showInBrowserTimeline: true
4215
4553
  })
4216
4554
  ], DataSpace.prototype, "_initializeAndReadControlPipeline", null);
4217
- _ts_decorate4([
4555
+ _ts_decorate6([
4218
4556
  timed(1e4)
4219
4557
  ], DataSpace.prototype, "_createWritableFeeds", null);
4220
- _ts_decorate4([
4558
+ _ts_decorate6([
4221
4559
  synchronized2
4222
4560
  ], DataSpace.prototype, "activate", null);
4223
- _ts_decorate4([
4561
+ _ts_decorate6([
4224
4562
  synchronized2
4225
4563
  ], DataSpace.prototype, "deactivate", null);
4226
- DataSpace = _ts_decorate4([
4564
+ DataSpace = _ts_decorate6([
4227
4565
  trackLeaks2("open", "close"),
4228
4566
  trace5.resource()
4229
4567
  ], DataSpace);
@@ -6282,8 +6620,8 @@ var InvitationsManager = class {
6282
6620
  // packages/sdk/client-services/src/packlets/locks/browser.ts
6283
6621
  import { asyncTimeout as asyncTimeout2, Trigger as Trigger8 } from "@dxos/async";
6284
6622
  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) {
6623
+ import { log as log20, logInfo as logInfo3 } from "@dxos/log";
6624
+ function _ts_decorate7(decorators, target, key, desc) {
6287
6625
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
6288
6626
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
6289
6627
  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;
@@ -6392,8 +6730,8 @@ var Lock = class {
6392
6730
  });
6393
6731
  }
6394
6732
  };
6395
- _ts_decorate5([
6396
- logInfo
6733
+ _ts_decorate7([
6734
+ logInfo3
6397
6735
  ], Lock.prototype, "lockKey", null);
6398
6736
  var isLocked = (lockPath) => {
6399
6737
  throw new Error("Not implemented");
@@ -6404,7 +6742,7 @@ import { Stream as Stream10 } from "@dxos/codec-protobuf";
6404
6742
  import { raise as raise2 } from "@dxos/debug";
6405
6743
  import { parseMethodName, RpcPeer } from "@dxos/rpc";
6406
6744
  import { MapCounter, trace as trace8 } from "@dxos/tracing";
6407
- function _ts_decorate6(decorators, target, key, desc) {
6745
+ function _ts_decorate8(decorators, target, key, desc) {
6408
6746
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
6409
6747
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
6410
6748
  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,22 +6804,23 @@ var ClientRpcServer = class {
6466
6804
  return this._handlerCache.get(serviceName);
6467
6805
  }
6468
6806
  };
6469
- _ts_decorate6([
6807
+ _ts_decorate8([
6470
6808
  trace8.metricsCounter()
6471
6809
  ], ClientRpcServer.prototype, "_callMetrics", void 0);
6472
- _ts_decorate6([
6810
+ _ts_decorate8([
6473
6811
  trace8.info()
6474
6812
  ], ClientRpcServer.prototype, "_services", null);
6475
- ClientRpcServer = _ts_decorate6([
6813
+ ClientRpcServer = _ts_decorate8([
6476
6814
  trace8.resource()
6477
6815
  ], ClientRpcServer);
6478
6816
 
6479
6817
  // 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";
6818
+ import { Mutex as Mutex4, scheduleMicroTask as scheduleMicroTask3, Trigger as Trigger9 } from "@dxos/async";
6819
+ import { Context as Context9, Resource as Resource6 } from "@dxos/context";
6482
6820
  import { getCredentialAssertion as getCredentialAssertion5 } from "@dxos/credentials";
6483
- import { failUndefined as failUndefined2 } from "@dxos/debug";
6821
+ import { failUndefined as failUndefined2, warnAfterTimeout as warnAfterTimeout2 } from "@dxos/debug";
6484
6822
  import { EchoEdgeReplicator, EchoHost, MeshEchoReplicator, MetadataStore, SpaceManager, valueEncoding } from "@dxos/echo-pipeline";
6823
+ import { createChainEdgeIdentity, createEphemeralEdgeIdentity } from "@dxos/edge-client";
6485
6824
  import { FeedFactory, FeedStore } from "@dxos/feed-store";
6486
6825
  import { invariant as invariant17 } from "@dxos/invariant";
6487
6826
  import { Keyring } from "@dxos/keyring";
@@ -6492,23 +6831,87 @@ import { Invitation as Invitation8 } from "@dxos/protocols/proto/dxos/client/ser
6492
6831
  import { BlobStore } from "@dxos/teleport-extension-object-sync";
6493
6832
  import { trace as Trace3 } from "@dxos/tracing";
6494
6833
  import { safeInstanceof } from "@dxos/util";
6495
- function _ts_decorate7(decorators, target, key, desc) {
6834
+ function _ts_decorate9(decorators, target, key, desc) {
6496
6835
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
6497
6836
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
6498
6837
  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
6838
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6500
6839
  }
6840
+ function _using_ctx3() {
6841
+ var _disposeSuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed) {
6842
+ var err = new Error();
6843
+ err.name = "SuppressedError";
6844
+ err.suppressed = suppressed;
6845
+ err.error = error;
6846
+ return err;
6847
+ }, empty = {}, stack = [];
6848
+ function using(isAwait, value) {
6849
+ if (value != null) {
6850
+ if (Object(value) !== value) {
6851
+ throw new TypeError("using declarations can only be used with objects, functions, null, or undefined.");
6852
+ }
6853
+ if (isAwait) {
6854
+ var dispose = value[Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose")];
6855
+ }
6856
+ if (dispose == null) {
6857
+ dispose = value[Symbol.dispose || Symbol.for("Symbol.dispose")];
6858
+ }
6859
+ if (typeof dispose !== "function") {
6860
+ throw new TypeError(`Property [Symbol.dispose] is not a function.`);
6861
+ }
6862
+ stack.push({
6863
+ v: value,
6864
+ d: dispose,
6865
+ a: isAwait
6866
+ });
6867
+ } else if (isAwait) {
6868
+ stack.push({
6869
+ d: value,
6870
+ a: isAwait
6871
+ });
6872
+ }
6873
+ return value;
6874
+ }
6875
+ return {
6876
+ e: empty,
6877
+ u: using.bind(null, false),
6878
+ a: using.bind(null, true),
6879
+ d: function() {
6880
+ var error = this.e;
6881
+ function next() {
6882
+ while (resource = stack.pop()) {
6883
+ try {
6884
+ var resource, disposalResult = resource.d && resource.d.call(resource.v);
6885
+ if (resource.a) {
6886
+ return Promise.resolve(disposalResult).then(next, err);
6887
+ }
6888
+ } catch (e) {
6889
+ return err(e);
6890
+ }
6891
+ }
6892
+ if (error !== empty) throw error;
6893
+ }
6894
+ function err(e) {
6895
+ error = error !== empty ? new _disposeSuppressedError(error, e) : e;
6896
+ return next();
6897
+ }
6898
+ return next();
6899
+ }
6900
+ };
6901
+ }
6501
6902
  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) {
6903
+ var ServiceContext = class extends Resource6 {
6904
+ constructor(storage, level, networkManager, signalManager, _edgeConnection, _edgeHttpClient, _runtimeParams, _edgeFeatures) {
6504
6905
  super();
6505
6906
  this.storage = storage;
6506
6907
  this.level = level;
6507
6908
  this.networkManager = networkManager;
6508
6909
  this.signalManager = signalManager;
6509
6910
  this._edgeConnection = _edgeConnection;
6911
+ this._edgeHttpClient = _edgeHttpClient;
6510
6912
  this._runtimeParams = _runtimeParams;
6511
6913
  this._edgeFeatures = _edgeFeatures;
6914
+ this._edgeIdentityUpdateMutex = new Mutex4();
6512
6915
  this.initialized = new Trigger9();
6513
6916
  this._meshReplicator = void 0;
6514
6917
  this._echoEdgeReplicator = void 0;
@@ -6546,23 +6949,42 @@ var ServiceContext = class extends Resource5 {
6546
6949
  callbacks: {
6547
6950
  onIdentityConstruction: (identity) => {
6548
6951
  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()
6952
+ scheduleMicroTask3(this._ctx, async () => {
6953
+ try {
6954
+ var _usingCtx = _using_ctx3();
6955
+ const _ = _usingCtx.u(await this._edgeIdentityUpdateMutex.acquire());
6956
+ log21.info("Setting identity on edge connection", {
6957
+ identity: identity.identityKey.toHex(),
6958
+ oldIdentity: this._edgeConnection.identityKey,
6959
+ swarms: this.networkManager.topics
6960
+ }, {
6961
+ F: __dxlog_file24,
6962
+ L: 147,
6963
+ S: this,
6964
+ C: (f, a) => f(...a)
6965
+ });
6966
+ await warnAfterTimeout2(1e4, "Waiting for identity to be ready for edge connection", async () => {
6967
+ await identity.ready();
6968
+ });
6969
+ invariant17(identity.deviceCredentialChain, void 0, {
6970
+ F: __dxlog_file24,
6971
+ L: 157,
6972
+ S: this,
6973
+ A: [
6974
+ "identity.deviceCredentialChain",
6975
+ ""
6976
+ ]
6977
+ });
6978
+ this._edgeConnection.setIdentity(await createChainEdgeIdentity(identity.signer, identity.identityKey, identity.deviceKey, identity.deviceCredentialChain, []));
6979
+ this.networkManager.setPeerInfo({
6980
+ identityKey: identity.identityKey.toHex(),
6981
+ peerKey: identity.deviceKey.toHex()
6982
+ });
6983
+ } catch (_) {
6984
+ _usingCtx.e = _;
6985
+ } finally {
6986
+ _usingCtx.d();
6987
+ }
6566
6988
  });
6567
6989
  }
6568
6990
  }
@@ -6588,7 +7010,7 @@ var ServiceContext = class extends Resource5 {
6588
7010
  await this._checkStorageVersion();
6589
7011
  log21("opening...", void 0, {
6590
7012
  F: __dxlog_file24,
6591
- L: 198,
7013
+ L: 217,
6592
7014
  S: this,
6593
7015
  C: (f, a) => f(...a)
6594
7016
  });
@@ -6596,11 +7018,14 @@ var ServiceContext = class extends Resource5 {
6596
7018
  id: this._instanceId
6597
7019
  }), {
6598
7020
  F: __dxlog_file24,
6599
- L: 199,
7021
+ L: 218,
6600
7022
  S: this,
6601
7023
  C: (f, a) => f(...a)
6602
7024
  });
6603
- await this._edgeConnection?.open();
7025
+ if (this._edgeConnection) {
7026
+ this._edgeConnection.setIdentity(await createEphemeralEdgeIdentity());
7027
+ await this._edgeConnection.open();
7028
+ }
6604
7029
  await this.signalManager.open();
6605
7030
  await this.networkManager.open();
6606
7031
  await this.echoHost.open(ctx);
@@ -6621,7 +7046,7 @@ var ServiceContext = class extends Resource5 {
6621
7046
  count: loadedInvitations.invitations?.length
6622
7047
  }, {
6623
7048
  F: __dxlog_file24,
6624
- L: 222,
7049
+ L: 245,
6625
7050
  S: this,
6626
7051
  C: (f, a) => f(...a)
6627
7052
  });
@@ -6629,13 +7054,13 @@ var ServiceContext = class extends Resource5 {
6629
7054
  id: this._instanceId
6630
7055
  }), {
6631
7056
  F: __dxlog_file24,
6632
- L: 224,
7057
+ L: 247,
6633
7058
  S: this,
6634
7059
  C: (f, a) => f(...a)
6635
7060
  });
6636
7061
  log21("opened", void 0, {
6637
7062
  F: __dxlog_file24,
6638
- L: 225,
7063
+ L: 248,
6639
7064
  S: this,
6640
7065
  C: (f, a) => f(...a)
6641
7066
  });
@@ -6643,7 +7068,7 @@ var ServiceContext = class extends Resource5 {
6643
7068
  async _close(ctx) {
6644
7069
  log21("closing...", void 0, {
6645
7070
  F: __dxlog_file24,
6646
- L: 229,
7071
+ L: 252,
6647
7072
  S: this,
6648
7073
  C: (f, a) => f(...a)
6649
7074
  });
@@ -6661,7 +7086,7 @@ var ServiceContext = class extends Resource5 {
6661
7086
  await this._edgeConnection?.close();
6662
7087
  log21("closed", void 0, {
6663
7088
  F: __dxlog_file24,
6664
- L: 244,
7089
+ L: 267,
6665
7090
  S: this,
6666
7091
  C: (f, a) => f(...a)
6667
7092
  });
@@ -6670,7 +7095,7 @@ var ServiceContext = class extends Resource5 {
6670
7095
  const identity = await this.identityManager.createIdentity(params);
6671
7096
  await this._initialize(new Context9(void 0, {
6672
7097
  F: __dxlog_file24,
6673
- L: 249
7098
+ L: 272
6674
7099
  }));
6675
7100
  return identity;
6676
7101
  }
@@ -6678,7 +7103,7 @@ var ServiceContext = class extends Resource5 {
6678
7103
  const factory = this._handlerFactories.get(invitation.kind);
6679
7104
  invariant17(factory, `Unknown invitation kind: ${invitation.kind}`, {
6680
7105
  F: __dxlog_file24,
6681
- L: 255,
7106
+ L: 278,
6682
7107
  S: this,
6683
7108
  A: [
6684
7109
  "factory",
@@ -6699,7 +7124,7 @@ var ServiceContext = class extends Resource5 {
6699
7124
  const identity = await this.identityManager.acceptIdentity(params);
6700
7125
  await this._initialize(new Context9(void 0, {
6701
7126
  F: __dxlog_file24,
6702
- L: 271
7127
+ L: 294
6703
7128
  }));
6704
7129
  return identity;
6705
7130
  }
@@ -6713,7 +7138,7 @@ var ServiceContext = class extends Resource5 {
6713
7138
  async _initialize(ctx) {
6714
7139
  log21("initializing spaces...", void 0, {
6715
7140
  F: __dxlog_file24,
6716
- L: 286,
7141
+ L: 309,
6717
7142
  S: this,
6718
7143
  C: (f, a) => f(...a)
6719
7144
  });
@@ -6740,6 +7165,7 @@ var ServiceContext = class extends Resource5 {
6740
7165
  echoHost: this.echoHost,
6741
7166
  invitationsManager: this.invitationsManager,
6742
7167
  edgeConnection: this._edgeConnection,
7168
+ edgeHttpClient: this._edgeHttpClient,
6743
7169
  echoEdgeReplicator: this._echoEdgeReplicator,
6744
7170
  meshReplicator: this._meshReplicator,
6745
7171
  runtimeParams: this._runtimeParams,
@@ -6749,7 +7175,7 @@ var ServiceContext = class extends Resource5 {
6749
7175
  this._handlerFactories.set(Invitation8.Kind.SPACE, (invitation) => {
6750
7176
  invariant17(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
6751
7177
  F: __dxlog_file24,
6752
- L: 315,
7178
+ L: 339,
6753
7179
  S: this,
6754
7180
  A: [
6755
7181
  "this.dataSpaceManager",
@@ -6773,7 +7199,7 @@ var ServiceContext = class extends Resource5 {
6773
7199
  details: assertion
6774
7200
  }, {
6775
7201
  F: __dxlog_file24,
6776
- L: 331,
7202
+ L: 355,
6777
7203
  S: this,
6778
7204
  C: (f, a) => f(...a)
6779
7205
  });
@@ -6784,7 +7210,7 @@ var ServiceContext = class extends Resource5 {
6784
7210
  details: assertion
6785
7211
  }, {
6786
7212
  F: __dxlog_file24,
6787
- L: 335,
7213
+ L: 359,
6788
7214
  S: this,
6789
7215
  C: (f, a) => f(...a)
6790
7216
  });
@@ -6795,7 +7221,7 @@ var ServiceContext = class extends Resource5 {
6795
7221
  details: assertion
6796
7222
  }, {
6797
7223
  F: __dxlog_file24,
6798
- L: 340,
7224
+ L: 364,
6799
7225
  S: this,
6800
7226
  C: (f, a) => f(...a)
6801
7227
  });
@@ -6806,7 +7232,7 @@ var ServiceContext = class extends Resource5 {
6806
7232
  } catch (err) {
6807
7233
  log21.catch(err, void 0, {
6808
7234
  F: __dxlog_file24,
6809
- L: 346,
7235
+ L: 370,
6810
7236
  S: this,
6811
7237
  C: (f, a) => f(...a)
6812
7238
  });
@@ -6816,13 +7242,13 @@ var ServiceContext = class extends Resource5 {
6816
7242
  await identity.space.spaceState.addCredentialProcessor(this._deviceSpaceSync);
6817
7243
  }
6818
7244
  };
6819
- _ts_decorate7([
7245
+ _ts_decorate9([
6820
7246
  Trace3.span()
6821
7247
  ], ServiceContext.prototype, "_open", null);
6822
- _ts_decorate7([
7248
+ _ts_decorate9([
6823
7249
  Trace3.span()
6824
7250
  ], ServiceContext.prototype, "_initialize", null);
6825
- ServiceContext = _ts_decorate7([
7251
+ ServiceContext = _ts_decorate9([
6826
7252
  safeInstanceof("dxos.client-services.ServiceContext"),
6827
7253
  Trace3.resource()
6828
7254
  ], ServiceContext);
@@ -7088,7 +7514,7 @@ var importProfileData = async ({ storage, level }, archive) => {
7088
7514
  import { Event as Event10, synchronized as synchronized3 } from "@dxos/async";
7089
7515
  import { clientServiceBundle } from "@dxos/client-protocol";
7090
7516
  import { Context as Context10 } from "@dxos/context";
7091
- import { EdgeClient } from "@dxos/edge-client";
7517
+ import { EdgeClient, EdgeHttpClient, createStubEdgeIdentity } from "@dxos/edge-client";
7092
7518
  import { invariant as invariant20 } from "@dxos/invariant";
7093
7519
  import { PublicKey as PublicKey17 } from "@dxos/keys";
7094
7520
  import { log as log24 } from "@dxos/log";
@@ -7479,7 +7905,7 @@ var SystemServiceImpl = class {
7479
7905
  };
7480
7906
 
7481
7907
  // packages/sdk/client-services/src/packlets/services/service-host.ts
7482
- function _ts_decorate8(decorators, target, key, desc) {
7908
+ function _ts_decorate10(decorators, target, key, desc) {
7483
7909
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
7484
7910
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
7485
7911
  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;
@@ -7501,6 +7927,7 @@ var ClientServicesHost = class {
7501
7927
  this._tracingService = TRACE_PROCESSOR3.createTraceSender();
7502
7928
  this._statusUpdate = new Event10();
7503
7929
  this._edgeConnection = void 0;
7930
+ this._edgeHttpClient = void 0;
7504
7931
  this._opening = false;
7505
7932
  this._open = false;
7506
7933
  this._storage = storage;
@@ -7524,7 +7951,7 @@ var ClientServicesHost = class {
7524
7951
  if (!this._opening) {
7525
7952
  void this.open(new Context10(void 0, {
7526
7953
  F: __dxlog_file27,
7527
- L: 132
7954
+ L: 133
7528
7955
  }));
7529
7956
  }
7530
7957
  },
@@ -7582,7 +8009,7 @@ var ClientServicesHost = class {
7582
8009
  initialize({ config, ...options }) {
7583
8010
  invariant20(!this._open, "service host is open", {
7584
8011
  F: __dxlog_file27,
7585
- L: 198,
8012
+ L: 199,
7586
8013
  S: this,
7587
8014
  A: [
7588
8015
  "!this._open",
@@ -7591,14 +8018,14 @@ var ClientServicesHost = class {
7591
8018
  });
7592
8019
  log24("initializing...", void 0, {
7593
8020
  F: __dxlog_file27,
7594
- L: 199,
8021
+ L: 200,
7595
8022
  S: this,
7596
8023
  C: (f, a) => f(...a)
7597
8024
  });
7598
8025
  if (config) {
7599
8026
  invariant20(!this._config, "config already set", {
7600
8027
  F: __dxlog_file27,
7601
- L: 202,
8028
+ L: 203,
7602
8029
  S: this,
7603
8030
  A: [
7604
8031
  "!this._config",
@@ -7613,17 +8040,17 @@ var ClientServicesHost = class {
7613
8040
  if (!options.signalManager) {
7614
8041
  log24.warn("running signaling without telemetry metadata.", void 0, {
7615
8042
  F: __dxlog_file27,
7616
- L: 210,
8043
+ L: 211,
7617
8044
  S: this,
7618
8045
  C: (f, a) => f(...a)
7619
8046
  });
7620
8047
  }
7621
8048
  const edgeEndpoint = config?.get("runtime.services.edge.url");
7622
8049
  if (edgeEndpoint) {
7623
- const randomKey = PublicKey17.random().toHex();
7624
- this._edgeConnection = new EdgeClient(randomKey, randomKey, {
8050
+ this._edgeConnection = new EdgeClient(createStubEdgeIdentity(), {
7625
8051
  socketEndpoint: edgeEndpoint
7626
8052
  });
8053
+ this._edgeHttpClient = new EdgeHttpClient(edgeEndpoint);
7627
8054
  }
7628
8055
  const { connectionLog = true, transportFactory = createRtcTransportFactory({
7629
8056
  iceServers: this._config?.get("runtime.services.ice")
@@ -7633,7 +8060,7 @@ var ClientServicesHost = class {
7633
8060
  this._signalManager = signalManager;
7634
8061
  invariant20(!this._networkManager, "network manager already set", {
7635
8062
  F: __dxlog_file27,
7636
- L: 232,
8063
+ L: 233,
7637
8064
  S: this,
7638
8065
  A: [
7639
8066
  "!this._networkManager",
@@ -7651,7 +8078,7 @@ var ClientServicesHost = class {
7651
8078
  });
7652
8079
  log24("initialized", void 0, {
7653
8080
  F: __dxlog_file27,
7654
- L: 245,
8081
+ L: 246,
7655
8082
  S: this,
7656
8083
  C: (f, a) => f(...a)
7657
8084
  });
@@ -7665,13 +8092,13 @@ var ClientServicesHost = class {
7665
8092
  id: traceId
7666
8093
  }), {
7667
8094
  F: __dxlog_file27,
7668
- L: 256,
8095
+ L: 257,
7669
8096
  S: this,
7670
8097
  C: (f, a) => f(...a)
7671
8098
  });
7672
8099
  invariant20(this._config, "config not set", {
7673
8100
  F: __dxlog_file27,
7674
- L: 258,
8101
+ L: 259,
7675
8102
  S: this,
7676
8103
  A: [
7677
8104
  "this._config",
@@ -7680,7 +8107,7 @@ var ClientServicesHost = class {
7680
8107
  });
7681
8108
  invariant20(this._storage, "storage not set", {
7682
8109
  F: __dxlog_file27,
7683
- L: 259,
8110
+ L: 260,
7684
8111
  S: this,
7685
8112
  A: [
7686
8113
  "this._storage",
@@ -7689,7 +8116,7 @@ var ClientServicesHost = class {
7689
8116
  });
7690
8117
  invariant20(this._signalManager, "signal manager not set", {
7691
8118
  F: __dxlog_file27,
7692
- L: 260,
8119
+ L: 261,
7693
8120
  S: this,
7694
8121
  A: [
7695
8122
  "this._signalManager",
@@ -7698,7 +8125,7 @@ var ClientServicesHost = class {
7698
8125
  });
7699
8126
  invariant20(this._networkManager, "network manager not set", {
7700
8127
  F: __dxlog_file27,
7701
- L: 261,
8128
+ L: 262,
7702
8129
  S: this,
7703
8130
  A: [
7704
8131
  "this._networkManager",
@@ -7710,7 +8137,7 @@ var ClientServicesHost = class {
7710
8137
  lockKey: this._resourceLock?.lockKey
7711
8138
  }, {
7712
8139
  F: __dxlog_file27,
7713
- L: 264,
8140
+ L: 265,
7714
8141
  S: this,
7715
8142
  C: (f, a) => f(...a)
7716
8143
  });
@@ -7720,7 +8147,7 @@ var ClientServicesHost = class {
7720
8147
  }
7721
8148
  await this._level.open();
7722
8149
  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"));
8150
+ 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
8151
  const dataSpaceManagerProvider = async () => {
7725
8152
  await this._serviceContext.initialized.wait();
7726
8153
  return this._serviceContext.dataSpaceManager;
@@ -7766,7 +8193,7 @@ var ClientServicesHost = class {
7766
8193
  deviceKey
7767
8194
  }, {
7768
8195
  F: __dxlog_file27,
7769
- L: 352,
8196
+ L: 354,
7770
8197
  S: this,
7771
8198
  C: (f, a) => f(...a)
7772
8199
  });
@@ -7774,7 +8201,7 @@ var ClientServicesHost = class {
7774
8201
  id: traceId
7775
8202
  }), {
7776
8203
  F: __dxlog_file27,
7777
- L: 353,
8204
+ L: 355,
7778
8205
  S: this,
7779
8206
  C: (f, a) => f(...a)
7780
8207
  });
@@ -7788,7 +8215,7 @@ var ClientServicesHost = class {
7788
8215
  deviceKey
7789
8216
  }, {
7790
8217
  F: __dxlog_file27,
7791
- L: 364,
8218
+ L: 366,
7792
8219
  S: this,
7793
8220
  C: (f, a) => f(...a)
7794
8221
  });
@@ -7806,7 +8233,7 @@ var ClientServicesHost = class {
7806
8233
  deviceKey
7807
8234
  }, {
7808
8235
  F: __dxlog_file27,
7809
- L: 373,
8236
+ L: 375,
7810
8237
  S: this,
7811
8238
  C: (f, a) => f(...a)
7812
8239
  });
@@ -7817,13 +8244,13 @@ var ClientServicesHost = class {
7817
8244
  id: traceId
7818
8245
  }), {
7819
8246
  F: __dxlog_file27,
7820
- L: 378,
8247
+ L: 380,
7821
8248
  S: this,
7822
8249
  C: (f, a) => f(...a)
7823
8250
  });
7824
8251
  log24.info("resetting...", void 0, {
7825
8252
  F: __dxlog_file27,
7826
- L: 380,
8253
+ L: 382,
7827
8254
  S: this,
7828
8255
  C: (f, a) => f(...a)
7829
8256
  });
@@ -7831,7 +8258,7 @@ var ClientServicesHost = class {
7831
8258
  await this._storage.reset();
7832
8259
  log24.info("reset", void 0, {
7833
8260
  F: __dxlog_file27,
7834
- L: 383,
8261
+ L: 385,
7835
8262
  S: this,
7836
8263
  C: (f, a) => f(...a)
7837
8264
  });
@@ -7839,7 +8266,7 @@ var ClientServicesHost = class {
7839
8266
  id: traceId
7840
8267
  }), {
7841
8268
  F: __dxlog_file27,
7842
- L: 384,
8269
+ L: 386,
7843
8270
  S: this,
7844
8271
  C: (f, a) => f(...a)
7845
8272
  });
@@ -7851,21 +8278,21 @@ var ClientServicesHost = class {
7851
8278
  return identity;
7852
8279
  }
7853
8280
  };
7854
- _ts_decorate8([
8281
+ _ts_decorate10([
7855
8282
  Trace4.info()
7856
8283
  ], ClientServicesHost.prototype, "_opening", void 0);
7857
- _ts_decorate8([
8284
+ _ts_decorate10([
7858
8285
  Trace4.info()
7859
8286
  ], ClientServicesHost.prototype, "_open", void 0);
7860
- _ts_decorate8([
8287
+ _ts_decorate10([
7861
8288
  synchronized3,
7862
8289
  Trace4.span()
7863
8290
  ], ClientServicesHost.prototype, "open", null);
7864
- _ts_decorate8([
8291
+ _ts_decorate10([
7865
8292
  synchronized3,
7866
8293
  Trace4.span()
7867
8294
  ], ClientServicesHost.prototype, "close", null);
7868
- ClientServicesHost = _ts_decorate8([
8295
+ ClientServicesHost = _ts_decorate10([
7869
8296
  Trace4.resource()
7870
8297
  ], ClientServicesHost);
7871
8298
 
@@ -7913,4 +8340,4 @@ export {
7913
8340
  importProfileData,
7914
8341
  ClientServicesHost
7915
8342
  };
7916
- //# sourceMappingURL=chunk-BDGSOBZV.mjs.map
8343
+ //# sourceMappingURL=chunk-AHZ7ASHC.mjs.map