@dxos/client-services 0.6.12-main.78ddbdf → 0.6.12-main.7907542

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 (56) hide show
  1. package/dist/lib/browser/{chunk-XSFLJVDP.mjs → chunk-6UTFANWL.mjs} +686 -304
  2. package/dist/lib/browser/chunk-6UTFANWL.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-F3WGFGEN.cjs → chunk-2UUETFZ2.cjs} +776 -394
  8. package/dist/lib/node/chunk-2UUETFZ2.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-3HDLTAT2.mjs → chunk-EQAI46LQ.mjs} +686 -304
  14. package/dist/lib/node-esm/chunk-EQAI46LQ.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 +2 -0
  33. package/dist/types/src/packlets/spaces/edge-feed-replicator.d.ts.map +1 -1
  34. package/dist/types/src/packlets/spaces/notarization-plugin.d.ts +31 -6
  35. package/dist/types/src/packlets/spaces/notarization-plugin.d.ts.map +1 -1
  36. package/dist/types/src/packlets/spaces/spaces-service.d.ts +1 -1
  37. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  38. package/dist/types/src/version.d.ts +1 -1
  39. package/package.json +38 -38
  40. package/src/packlets/identity/authenticator.ts +5 -2
  41. package/src/packlets/identity/contacts-service.ts +1 -1
  42. package/src/packlets/identity/identity.ts +4 -0
  43. package/src/packlets/services/service-context.ts +41 -17
  44. package/src/packlets/services/service-host.ts +7 -5
  45. package/src/packlets/spaces/data-space-manager.ts +32 -4
  46. package/src/packlets/spaces/data-space.ts +27 -4
  47. package/src/packlets/spaces/edge-feed-replicator.test.ts +22 -15
  48. package/src/packlets/spaces/edge-feed-replicator.ts +45 -25
  49. package/src/packlets/spaces/notarization-plugin.test.ts +8 -4
  50. package/src/packlets/spaces/notarization-plugin.ts +169 -29
  51. package/src/packlets/spaces/spaces-service.ts +6 -1
  52. package/src/packlets/testing/test-builder.ts +1 -1
  53. package/src/version.ts +1 -1
  54. package/dist/lib/browser/chunk-XSFLJVDP.mjs.map +0 -7
  55. package/dist/lib/node/chunk-F3WGFGEN.cjs.map +0 -7
  56. package/dist/lib/node-esm/chunk-3HDLTAT2.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.78ddbdf";
407
+ var DXOS_VERSION = "0.6.12-main.7907542";
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,
@@ -815,11 +818,17 @@ import { Context as Context3, Resource } from "@dxos/context";
815
818
  import { EdgeConnectionClosedError, EdgeIdentityChangedError } from "@dxos/edge-client";
816
819
  import { invariant as invariant2 } from "@dxos/invariant";
817
820
  import { PublicKey as PublicKey3 } from "@dxos/keys";
818
- import { log as log4 } from "@dxos/log";
821
+ import { log as log4, logInfo } from "@dxos/log";
819
822
  import { EdgeService } from "@dxos/protocols";
820
823
  import { buf } from "@dxos/protocols/buf";
821
824
  import { MessageSchema as RouterMessageSchema } from "@dxos/protocols/buf/dxos/edge/messenger_pb";
822
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
+ }
823
832
  function _using_ctx() {
824
833
  var _disposeSuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed) {
825
834
  var err = new Error();
@@ -901,6 +910,12 @@ var EdgeFeedReplicator = class extends Resource {
901
910
  this._spaceId = spaceId;
902
911
  }
903
912
  async _open() {
913
+ log4("open", void 0, {
914
+ F: __dxlog_file6,
915
+ L: 56,
916
+ S: this,
917
+ C: (f, a) => f(...a)
918
+ });
904
919
  this._ctx.onDispose(this._messenger.addListener((message) => {
905
920
  if (!message.serviceId) {
906
921
  return;
@@ -916,20 +931,20 @@ var EdgeFeedReplicator = class extends Resource {
916
931
  _spaceId: this._spaceId
917
932
  }, {
918
933
  F: __dxlog_file6,
919
- L: 66,
934
+ L: 70,
920
935
  S: this,
921
936
  C: (f, a) => f(...a)
922
937
  });
923
938
  return;
924
939
  }
925
940
  const payload = decodeCbor(message.payload.value);
926
- log4.info("receive", {
941
+ log4("receive", {
927
942
  from: message.source,
928
943
  feedKey: payload.feedKey,
929
944
  type: payload.type
930
945
  }, {
931
946
  F: __dxlog_file6,
932
- L: 71,
947
+ L: 75,
933
948
  S: this,
934
949
  C: (f, a) => f(...a)
935
950
  });
@@ -937,46 +952,44 @@ var EdgeFeedReplicator = class extends Resource {
937
952
  }));
938
953
  this._messenger.connected.on(this._ctx, async () => {
939
954
  await this._resetConnection();
940
- this._connected = true;
941
- const connectionCtx = new Context3({
942
- onError: async (err) => {
943
- if (connectionCtx !== this._connectionCtx) {
944
- return;
945
- }
946
- if (err instanceof EdgeIdentityChangedError || err instanceof EdgeConnectionClosedError) {
947
- log4("resetting on reconnect", void 0, {
948
- F: __dxlog_file6,
949
- L: 86,
950
- S: this,
951
- C: (f, a) => f(...a)
952
- });
953
- await this._resetConnection();
954
- } else {
955
- this._ctx.raise(err);
956
- }
957
- }
958
- }, {
959
- F: __dxlog_file6,
960
- L: 80
961
- });
962
- this._connectionCtx = connectionCtx;
963
- log4("connection context created", void 0, {
964
- F: __dxlog_file6,
965
- L: 94,
966
- S: this,
967
- C: (f, a) => f(...a)
968
- });
969
- scheduleMicroTask(connectionCtx, async () => {
970
- for (const feed of this._feeds.values()) {
971
- await this._replicateFeed(connectionCtx, feed);
972
- }
973
- });
955
+ this._startReplication();
974
956
  });
957
+ if (this._messenger.isConnected) {
958
+ this._startReplication();
959
+ }
975
960
  }
976
961
  async _close() {
962
+ log4("close", void 0, {
963
+ F: __dxlog_file6,
964
+ L: 91,
965
+ S: this,
966
+ C: (f, a) => f(...a)
967
+ });
977
968
  await this._resetConnection();
978
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
+ }
979
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
+ });
980
993
  this._connected = false;
981
994
  await this._connectionCtx?.dispose();
982
995
  this._connectionCtx = void 0;
@@ -984,10 +997,12 @@ var EdgeFeedReplicator = class extends Resource {
984
997
  }
985
998
  async addFeed(feed) {
986
999
  log4.info("addFeed", {
987
- key: feed.key
1000
+ key: feed.key,
1001
+ connected: this._connected,
1002
+ hasConnectionCtx: !!this._connectionCtx
988
1003
  }, {
989
1004
  F: __dxlog_file6,
990
- L: 115,
1005
+ L: 116,
991
1006
  S: this,
992
1007
  C: (f, a) => f(...a)
993
1008
  });
@@ -1000,6 +1015,14 @@ var EdgeFeedReplicator = class extends Resource {
1000
1015
  return defaultMap(this._pushMutex, key, () => new Mutex());
1001
1016
  }
1002
1017
  async _replicateFeed(ctx, feed) {
1018
+ log4("replicateFeed", {
1019
+ key: feed.key
1020
+ }, {
1021
+ F: __dxlog_file6,
1022
+ L: 129,
1023
+ S: this,
1024
+ C: (f, a) => f(...a)
1025
+ });
1003
1026
  await this._sendMessage({
1004
1027
  type: "get-metadata",
1005
1028
  feedKey: feed.key.toHex()
@@ -1012,7 +1035,7 @@ var EdgeFeedReplicator = class extends Resource {
1012
1035
  if (!this._connectionCtx) {
1013
1036
  log4.info("message dropped because connection was disposed", void 0, {
1014
1037
  F: __dxlog_file6,
1015
- L: 140,
1038
+ L: 142,
1016
1039
  S: this,
1017
1040
  C: (f, a) => f(...a)
1018
1041
  });
@@ -1026,13 +1049,13 @@ var EdgeFeedReplicator = class extends Resource {
1026
1049
  };
1027
1050
  log4.info("sending message", logPayload, {
1028
1051
  F: __dxlog_file6,
1029
- L: 146,
1052
+ L: 148,
1030
1053
  S: this,
1031
1054
  C: (f, a) => f(...a)
1032
1055
  });
1033
1056
  invariant2(message.feedKey, void 0, {
1034
1057
  F: __dxlog_file6,
1035
- L: 148,
1058
+ L: 150,
1036
1059
  S: this,
1037
1060
  A: [
1038
1061
  "message.feedKey",
@@ -1040,6 +1063,14 @@ var EdgeFeedReplicator = class extends Resource {
1040
1063
  ]
1041
1064
  });
1042
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
+ });
1043
1074
  await this._messenger.send(buf.create(RouterMessageSchema, {
1044
1075
  source: {
1045
1076
  identityKey: this._messenger.identityKey,
@@ -1055,7 +1086,7 @@ var EdgeFeedReplicator = class extends Resource {
1055
1086
  if (!this._connectionCtx) {
1056
1087
  log4.warn("received message after connection context was disposed", void 0, {
1057
1088
  F: __dxlog_file6,
1058
- L: 165,
1089
+ L: 168,
1059
1090
  S: this,
1060
1091
  C: (f, a) => f(...a)
1061
1092
  });
@@ -1070,7 +1101,7 @@ var EdgeFeedReplicator = class extends Resource {
1070
1101
  message
1071
1102
  }, {
1072
1103
  F: __dxlog_file6,
1073
- L: 171,
1104
+ L: 174,
1074
1105
  S: this,
1075
1106
  C: (f, a) => f(...a)
1076
1107
  });
@@ -1081,7 +1112,7 @@ var EdgeFeedReplicator = class extends Resource {
1081
1112
  feedKey
1082
1113
  }, {
1083
1114
  F: __dxlog_file6,
1084
- L: 176,
1115
+ L: 179,
1085
1116
  S: this,
1086
1117
  C: (f, a) => f(...a)
1087
1118
  });
@@ -1114,7 +1145,7 @@ var EdgeFeedReplicator = class extends Resource {
1114
1145
  blocks: message.blocks.map((b) => b.index)
1115
1146
  }, {
1116
1147
  F: __dxlog_file6,
1117
- L: 198,
1148
+ L: 201,
1118
1149
  S: this,
1119
1150
  C: (f, a) => f(...a)
1120
1151
  });
@@ -1125,7 +1156,7 @@ var EdgeFeedReplicator = class extends Resource {
1125
1156
  feedKey
1126
1157
  }, {
1127
1158
  F: __dxlog_file6,
1128
- L: 203,
1159
+ L: 206,
1129
1160
  S: this,
1130
1161
  C: (f, a) => f(...a)
1131
1162
  });
@@ -1139,7 +1170,7 @@ var EdgeFeedReplicator = class extends Resource {
1139
1170
  ...message
1140
1171
  }, {
1141
1172
  F: __dxlog_file6,
1142
- L: 212,
1173
+ L: 215,
1143
1174
  S: this,
1144
1175
  C: (f, a) => f(...a)
1145
1176
  });
@@ -1154,7 +1185,7 @@ var EdgeFeedReplicator = class extends Resource {
1154
1185
  to
1155
1186
  }, {
1156
1187
  F: __dxlog_file6,
1157
- L: 219,
1188
+ L: 222,
1158
1189
  S: this,
1159
1190
  C: (f, a) => f(...a)
1160
1191
  });
@@ -1164,7 +1195,7 @@ var EdgeFeedReplicator = class extends Resource {
1164
1195
  });
1165
1196
  invariant2(data instanceof Uint8Array, void 0, {
1166
1197
  F: __dxlog_file6,
1167
- L: 224,
1198
+ L: 227,
1168
1199
  S: this,
1169
1200
  A: [
1170
1201
  "data instanceof Uint8Array",
@@ -1192,7 +1223,7 @@ var EdgeFeedReplicator = class extends Resource {
1192
1223
  blocks: blocks.length
1193
1224
  }, {
1194
1225
  F: __dxlog_file6,
1195
- L: 245,
1226
+ L: 248,
1196
1227
  S: this,
1197
1228
  C: (f, a) => f(...a)
1198
1229
  });
@@ -1214,7 +1245,7 @@ var EdgeFeedReplicator = class extends Resource {
1214
1245
  if (!this._remoteLength.has(feed.key)) {
1215
1246
  log4("blocks not pushed because remote length is unknown", void 0, {
1216
1247
  F: __dxlog_file6,
1217
- L: 266,
1248
+ L: 269,
1218
1249
  S: this,
1219
1250
  C: (f, a) => f(...a)
1220
1251
  });
@@ -1230,7 +1261,34 @@ var EdgeFeedReplicator = class extends Resource {
1230
1261
  _usingCtx.d();
1231
1262
  }
1232
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
+ }
1233
1288
  };
1289
+ _ts_decorate([
1290
+ logInfo
1291
+ ], EdgeFeedReplicator.prototype, "_spaceId", void 0);
1234
1292
  var bufferizeBlock = (block) => ({
1235
1293
  index: block.index,
1236
1294
  data: arrayToBuffer(block.data),
@@ -1245,7 +1303,7 @@ var bufferizeBlock = (block) => ({
1245
1303
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
1246
1304
  import { Event as Event7, Mutex as Mutex2, scheduleTask as scheduleTask4, sleep as sleep3, synchronized as synchronized2, trackLeaks as trackLeaks2 } from "@dxos/async";
1247
1305
  import { AUTH_TIMEOUT as AUTH_TIMEOUT2 } from "@dxos/client-protocol";
1248
- import { Context as Context6, ContextDisposedError, cancelWithContext as cancelWithContext2 } from "@dxos/context";
1306
+ import { Context as Context5, ContextDisposedError, cancelWithContext as cancelWithContext2 } from "@dxos/context";
1249
1307
  import { timed, warnAfterTimeout } from "@dxos/debug";
1250
1308
  import { createMappedFeedWriter } from "@dxos/echo-pipeline";
1251
1309
  import { SpaceDocVersion as SpaceDocVersion3 } from "@dxos/echo-protocol";
@@ -1480,53 +1538,67 @@ var runEpochMigration = async (ctx, context) => {
1480
1538
  };
1481
1539
 
1482
1540
  // packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
1483
- import { DeferredTask, Event as Event3, scheduleTask as scheduleTask2, sleep, TimeoutError, Trigger as Trigger3 } from "@dxos/async";
1484
- import { Context as Context4, 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";
1485
1544
  import { invariant as invariant4 } from "@dxos/invariant";
1486
1545
  import { PublicKey as PublicKey4 } from "@dxos/keys";
1487
- import { log as log6 } from "@dxos/log";
1546
+ import { logInfo as logInfo2, log as log6 } from "@dxos/log";
1547
+ import { EdgeCallFailedError } from "@dxos/protocols";
1488
1548
  import { schema as schema2 } from "@dxos/protocols/proto";
1489
1549
  import { RpcExtension } from "@dxos/teleport";
1490
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
+ }
1491
1557
  var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
1492
1558
  var DEFAULT_RETRY_TIMEOUT = 1e3;
1493
1559
  var DEFAULT_SUCCESS_DELAY = 1e3;
1494
1560
  var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
1561
+ var MAX_EDGE_RETRIES = 2;
1495
1562
  var WRITER_NOT_SET_ERROR_CODE = "WRITER_NOT_SET";
1496
- var NotarizationPlugin = class {
1497
- constructor() {
1498
- this._ctx = new Context4(void 0, {
1499
- F: __dxlog_file8,
1500
- L: 62
1501
- });
1563
+ var credentialCodec = schema2.getCodecForType("dxos.halo.credentials.Credential");
1564
+ var NotarizationPlugin = class extends Resource3 {
1565
+ constructor(params) {
1566
+ super();
1502
1567
  this._extensionOpened = new Event3();
1503
1568
  this._extensions = /* @__PURE__ */ new Set();
1504
1569
  this._processedCredentials = new ComplexSet(PublicKey4.hash);
1505
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
+ }
1506
1575
  }
1507
1576
  get hasWriter() {
1508
1577
  return !!this._writer;
1509
1578
  }
1510
- async open() {
1579
+ async _open() {
1580
+ if (this._edgeClient && this._writer) {
1581
+ this._notarizePendingEdgeCredentials(this._edgeClient, this._writer);
1582
+ }
1511
1583
  }
1512
- async close() {
1584
+ async _close() {
1513
1585
  await this._ctx.dispose();
1514
1586
  }
1515
1587
  /**
1516
1588
  * Request credentials to be notarized.
1517
1589
  */
1518
- 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 }) {
1519
1591
  log6("notarize", {
1520
1592
  credentials
1521
1593
  }, {
1522
1594
  F: __dxlog_file8,
1523
- L: 90,
1595
+ L: 126,
1524
1596
  S: this,
1525
1597
  C: (f, a) => f(...a)
1526
1598
  });
1527
1599
  invariant4(credentials.every((credential) => credential.id), "Credentials must have an id", {
1528
1600
  F: __dxlog_file8,
1529
- L: 91,
1601
+ L: 127,
1530
1602
  S: this,
1531
1603
  A: [
1532
1604
  "credentials.every((credential) => credential.id)",
@@ -1540,7 +1612,7 @@ var NotarizationPlugin = class {
1540
1612
  err
1541
1613
  }, {
1542
1614
  F: __dxlog_file8,
1543
- L: 99,
1615
+ L: 135,
1544
1616
  S: this,
1545
1617
  C: (f, a) => f(...a)
1546
1618
  });
@@ -1550,21 +1622,37 @@ var NotarizationPlugin = class {
1550
1622
  });
1551
1623
  opCtx?.onDispose(() => ctx.dispose());
1552
1624
  if (timeout !== 0) {
1553
- scheduleTask2(ctx, () => {
1554
- log6.warn("Notarization timeout", {
1555
- timeout,
1556
- peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
1557
- }, {
1558
- F: __dxlog_file8,
1559
- L: 111,
1560
- S: this,
1561
- C: (f, a) => f(...a)
1562
- });
1563
- void ctx.dispose();
1564
- errors.throw(new TimeoutError(timeout, "Notarization timed out"));
1565
- }, timeout);
1625
+ this._scheduleTimeout(ctx, errors, timeout);
1566
1626
  }
1567
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 }) {
1568
1656
  const peersTried = /* @__PURE__ */ new Set();
1569
1657
  const notarizeTask = new DeferredTask(ctx, async () => {
1570
1658
  try {
@@ -1579,7 +1667,7 @@ var NotarizationPlugin = class {
1579
1667
  retryIn: retryTimeout
1580
1668
  }, {
1581
1669
  F: __dxlog_file8,
1582
- L: 136,
1670
+ L: 183,
1583
1671
  S: this,
1584
1672
  C: (f, a) => f(...a)
1585
1673
  });
@@ -1593,7 +1681,7 @@ var NotarizationPlugin = class {
1593
1681
  credentialId: credentials.map((credential) => credential.id)
1594
1682
  }, {
1595
1683
  F: __dxlog_file8,
1596
- L: 143,
1684
+ L: 190,
1597
1685
  S: this,
1598
1686
  C: (f, a) => f(...a)
1599
1687
  });
@@ -1602,7 +1690,7 @@ var NotarizationPlugin = class {
1602
1690
  });
1603
1691
  log6("success", void 0, {
1604
1692
  F: __dxlog_file8,
1605
- L: 147,
1693
+ L: 194,
1606
1694
  S: this,
1607
1695
  C: (f, a) => f(...a)
1608
1696
  });
@@ -1611,7 +1699,7 @@ var NotarizationPlugin = class {
1611
1699
  if (!ctx.disposed && !err.message.includes(WRITER_NOT_SET_ERROR_CODE)) {
1612
1700
  log6.info("error notarizing (recoverable)", err, {
1613
1701
  F: __dxlog_file8,
1614
- L: 151,
1702
+ L: 199,
1615
1703
  S: this,
1616
1704
  C: (f, a) => f(...a)
1617
1705
  });
@@ -1621,21 +1709,33 @@ var NotarizationPlugin = class {
1621
1709
  });
1622
1710
  notarizeTask.schedule();
1623
1711
  this._extensionOpened.on(ctx, () => notarizeTask.schedule());
1624
- try {
1625
- await Promise.race([
1626
- rejectOnDispose(ctx),
1627
- allNotarized,
1628
- errors.wait()
1629
- ]);
1630
- log6("done", void 0, {
1631
- F: __dxlog_file8,
1632
- L: 162,
1633
- S: this,
1634
- C: (f, a) => f(...a)
1635
- });
1636
- } finally {
1637
- await ctx.dispose();
1638
- }
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
+ });
1639
1739
  }
1640
1740
  /**
1641
1741
  * Called with credentials arriving from the control pipeline.
@@ -1651,7 +1751,7 @@ var NotarizationPlugin = class {
1651
1751
  setWriter(writer) {
1652
1752
  invariant4(!this._writer, "Writer already set.", {
1653
1753
  F: __dxlog_file8,
1654
- L: 181,
1754
+ L: 247,
1655
1755
  S: this,
1656
1756
  A: [
1657
1757
  "!this._writer",
@@ -1659,6 +1759,59 @@ var NotarizationPlugin = class {
1659
1759
  ]
1660
1760
  });
1661
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
+ });
1662
1815
  }
1663
1816
  async _waitUntilProcessed(id) {
1664
1817
  if (this._processedCredentials.has(id)) {
@@ -1673,10 +1826,13 @@ var NotarizationPlugin = class {
1673
1826
  if (!this._writer) {
1674
1827
  throw new Error(WRITER_NOT_SET_ERROR_CODE);
1675
1828
  }
1676
- 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) {
1677
1833
  invariant4(credential.id, "Credential must have an id", {
1678
1834
  F: __dxlog_file8,
1679
- L: 200,
1835
+ L: 308,
1680
1836
  S: this,
1681
1837
  A: [
1682
1838
  "credential.id",
@@ -1686,7 +1842,11 @@ var NotarizationPlugin = class {
1686
1842
  if (this._processedCredentials.has(credential.id)) {
1687
1843
  continue;
1688
1844
  }
1689
- 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);
1690
1850
  }
1691
1851
  }
1692
1852
  createExtension() {
@@ -1696,7 +1856,7 @@ var NotarizationPlugin = class {
1696
1856
  peer: extension.localPeerId
1697
1857
  }, {
1698
1858
  F: __dxlog_file8,
1699
- L: 211,
1859
+ L: 323,
1700
1860
  S: this,
1701
1861
  C: (f, a) => f(...a)
1702
1862
  });
@@ -1708,7 +1868,7 @@ var NotarizationPlugin = class {
1708
1868
  peer: extension.localPeerId
1709
1869
  }, {
1710
1870
  F: __dxlog_file8,
1711
- L: 216,
1871
+ L: 328,
1712
1872
  S: this,
1713
1873
  C: (f, a) => f(...a)
1714
1874
  });
@@ -1718,6 +1878,43 @@ var NotarizationPlugin = class {
1718
1878
  });
1719
1879
  return extension;
1720
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
+ }
1721
1918
  };
1722
1919
  var NotarizationTeleportExtension = class extends RpcExtension {
1723
1920
  constructor(_params) {
@@ -1812,7 +2009,7 @@ var DefaultSpaceStateMachine = class {
1812
2009
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
1813
2010
  import { Event as Event4, synchronized, trackLeaks } from "@dxos/async";
1814
2011
  import { PropertiesType } from "@dxos/client-protocol";
1815
- import { LifecycleState, Resource as Resource3, cancelWithContext } from "@dxos/context";
2012
+ import { LifecycleState, Resource as Resource4, cancelWithContext } from "@dxos/context";
1816
2013
  import { createAdmissionCredentials, getCredentialAssertion as getCredentialAssertion2 } from "@dxos/credentials";
1817
2014
  import { convertLegacyReferences as convertLegacyReferences2, findInlineObjectOfType as findInlineObjectOfType2, AuthStatus, CredentialServerExtension } from "@dxos/echo-pipeline";
1818
2015
  import { LEGACY_TYPE_PROPERTIES, SpaceDocVersion as SpaceDocVersion2, encodeReference } from "@dxos/echo-protocol";
@@ -1823,6 +2020,7 @@ import { PublicKey as PublicKey5 } from "@dxos/keys";
1823
2020
  import { log as log8 } from "@dxos/log";
1824
2021
  import { AlreadyJoinedError, trace as Trace } from "@dxos/protocols";
1825
2022
  import { Invitation, SpaceState } from "@dxos/protocols/proto/dxos/client/services";
2023
+ import { EdgeReplicationSetting } from "@dxos/protocols/proto/dxos/echo/metadata";
1826
2024
  import { SpaceMember as SpaceMember3 } from "@dxos/protocols/proto/dxos/halo/credentials";
1827
2025
  import { Gossip, Presence } from "@dxos/teleport-extension-gossip";
1828
2026
  import { trace } from "@dxos/tracing";
@@ -1899,7 +2097,7 @@ var spaceGenesis = async (keyring, signingContext, space, automergeRoot) => {
1899
2097
  };
1900
2098
 
1901
2099
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
1902
- function _ts_decorate(decorators, target, key, desc) {
2100
+ function _ts_decorate3(decorators, target, key, desc) {
1903
2101
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1904
2102
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1905
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;
@@ -1909,13 +2107,14 @@ var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/s
1909
2107
  var PRESENCE_ANNOUNCE_INTERVAL = 1e4;
1910
2108
  var PRESENCE_OFFLINE_TIMEOUT = 2e4;
1911
2109
  var DEFAULT_SPACE_KEY = "__DEFAULT__";
1912
- var DataSpaceManager = class extends Resource3 {
2110
+ var DataSpaceManager = class extends Resource4 {
1913
2111
  constructor(params) {
1914
2112
  super();
1915
2113
  this.updated = new Event4();
1916
2114
  this._spaces = new ComplexMap4(PublicKey5.hash);
1917
2115
  this._instanceId = PublicKey5.random().toHex();
1918
2116
  this._edgeConnection = void 0;
2117
+ this._edgeHttpClient = void 0;
1919
2118
  this._edgeFeatures = void 0;
1920
2119
  this._meshReplicator = void 0;
1921
2120
  this._echoEdgeReplicator = void 0;
@@ -1931,6 +2130,7 @@ var DataSpaceManager = class extends Resource3 {
1931
2130
  this._edgeConnection = params.edgeConnection;
1932
2131
  this._edgeFeatures = params.edgeFeatures;
1933
2132
  this._echoEdgeReplicator = params.echoEdgeReplicator;
2133
+ this._edgeHttpClient = params.edgeHttpClient;
1934
2134
  this._runtimeParams = params.runtimeParams;
1935
2135
  trace.diagnostic({
1936
2136
  id: "spaces",
@@ -1962,7 +2162,7 @@ var DataSpaceManager = class extends Resource3 {
1962
2162
  async _open() {
1963
2163
  log8("open", void 0, {
1964
2164
  F: __dxlog_file10,
1965
- L: 195,
2165
+ L: 198,
1966
2166
  S: this,
1967
2167
  C: (f, a) => f(...a)
1968
2168
  });
@@ -1970,7 +2170,7 @@ var DataSpaceManager = class extends Resource3 {
1970
2170
  id: this._instanceId
1971
2171
  }), {
1972
2172
  F: __dxlog_file10,
1973
- L: 196,
2173
+ L: 199,
1974
2174
  S: this,
1975
2175
  C: (f, a) => f(...a)
1976
2176
  });
@@ -1978,7 +2178,7 @@ var DataSpaceManager = class extends Resource3 {
1978
2178
  spaces: this._metadataStore.spaces.length
1979
2179
  }, {
1980
2180
  F: __dxlog_file10,
1981
- L: 197,
2181
+ L: 200,
1982
2182
  S: this,
1983
2183
  C: (f, a) => f(...a)
1984
2184
  });
@@ -1988,7 +2188,7 @@ var DataSpaceManager = class extends Resource3 {
1988
2188
  spaceMetadata
1989
2189
  }, {
1990
2190
  F: __dxlog_file10,
1991
- L: 201,
2191
+ L: 204,
1992
2192
  S: this,
1993
2193
  C: (f, a) => f(...a)
1994
2194
  });
@@ -1999,7 +2199,7 @@ var DataSpaceManager = class extends Resource3 {
1999
2199
  err
2000
2200
  }, {
2001
2201
  F: __dxlog_file10,
2002
- L: 204,
2202
+ L: 207,
2003
2203
  S: this,
2004
2204
  C: (f, a) => f(...a)
2005
2205
  });
@@ -2010,7 +2210,7 @@ var DataSpaceManager = class extends Resource3 {
2010
2210
  id: this._instanceId
2011
2211
  }), {
2012
2212
  F: __dxlog_file10,
2013
- L: 210,
2213
+ L: 213,
2014
2214
  S: this,
2015
2215
  C: (f, a) => f(...a)
2016
2216
  });
@@ -2018,7 +2218,7 @@ var DataSpaceManager = class extends Resource3 {
2018
2218
  async _close() {
2019
2219
  log8("close", void 0, {
2020
2220
  F: __dxlog_file10,
2021
- L: 215,
2221
+ L: 218,
2022
2222
  S: this,
2023
2223
  C: (f, a) => f(...a)
2024
2224
  });
@@ -2033,7 +2233,7 @@ var DataSpaceManager = class extends Resource3 {
2033
2233
  async createSpace() {
2034
2234
  invariant5(this._lifecycleState === LifecycleState.OPEN, "Not open.", {
2035
2235
  F: __dxlog_file10,
2036
- L: 227,
2236
+ L: 230,
2037
2237
  S: this,
2038
2238
  A: [
2039
2239
  "this._lifecycleState === LifecycleState.OPEN",
@@ -2054,7 +2254,7 @@ var DataSpaceManager = class extends Resource3 {
2054
2254
  spaceKey
2055
2255
  }, {
2056
2256
  F: __dxlog_file10,
2057
- L: 239,
2257
+ L: 242,
2058
2258
  S: this,
2059
2259
  C: (f, a) => f(...a)
2060
2260
  });
@@ -2066,7 +2266,7 @@ var DataSpaceManager = class extends Resource3 {
2066
2266
  const memberCredential = credentials[1];
2067
2267
  invariant5(getCredentialAssertion2(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2068
2268
  F: __dxlog_file10,
2069
- L: 249,
2269
+ L: 252,
2070
2270
  S: this,
2071
2271
  A: [
2072
2272
  "getCredentialAssertion(memberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2098,7 +2298,7 @@ var DataSpaceManager = class extends Resource3 {
2098
2298
  spaceId: space.id
2099
2299
  }, {
2100
2300
  F: __dxlog_file10,
2101
- L: 274,
2301
+ L: 277,
2102
2302
  S: this,
2103
2303
  C: (f, a) => f(...a)
2104
2304
  });
@@ -2133,7 +2333,7 @@ var DataSpaceManager = class extends Resource3 {
2133
2333
  const automergeIndex = space.automergeSpaceState.rootUrl;
2134
2334
  invariant5(automergeIndex, void 0, {
2135
2335
  F: __dxlog_file10,
2136
- L: 307,
2336
+ L: 310,
2137
2337
  S: this,
2138
2338
  A: [
2139
2339
  "automergeIndex",
@@ -2150,13 +2350,13 @@ var DataSpaceManager = class extends Resource3 {
2150
2350
  opts
2151
2351
  }, {
2152
2352
  F: __dxlog_file10,
2153
- L: 316,
2353
+ L: 319,
2154
2354
  S: this,
2155
2355
  C: (f, a) => f(...a)
2156
2356
  });
2157
2357
  invariant5(this._lifecycleState === LifecycleState.OPEN, "Not open.", {
2158
2358
  F: __dxlog_file10,
2159
- L: 317,
2359
+ L: 320,
2160
2360
  S: this,
2161
2361
  A: [
2162
2362
  "this._lifecycleState === LifecycleState.OPEN",
@@ -2165,7 +2365,7 @@ var DataSpaceManager = class extends Resource3 {
2165
2365
  });
2166
2366
  invariant5(!this._spaces.has(opts.spaceKey), "Space already exists.", {
2167
2367
  F: __dxlog_file10,
2168
- L: 318,
2368
+ L: 321,
2169
2369
  S: this,
2170
2370
  A: [
2171
2371
  "!this._spaces.has(opts.spaceKey)",
@@ -2189,7 +2389,7 @@ var DataSpaceManager = class extends Resource3 {
2189
2389
  const space = this._spaceManager.spaces.get(options.spaceKey);
2190
2390
  invariant5(space, void 0, {
2191
2391
  F: __dxlog_file10,
2192
- L: 338,
2392
+ L: 341,
2193
2393
  S: this,
2194
2394
  A: [
2195
2395
  "space",
@@ -2202,7 +2402,7 @@ var DataSpaceManager = class extends Resource3 {
2202
2402
  const credentials = await createAdmissionCredentials(this._signingContext.credentialSigner, options.identityKey, space.key, space.genesisFeedKey, options.role, space.spaceState.membershipChainHeads, options.profile, options.delegationCredentialId);
2203
2403
  invariant5(credentials[0].credential, void 0, {
2204
2404
  F: __dxlog_file10,
2205
- L: 357,
2405
+ L: 360,
2206
2406
  S: this,
2207
2407
  A: [
2208
2408
  "credentials[0].credential",
@@ -2212,7 +2412,7 @@ var DataSpaceManager = class extends Resource3 {
2212
2412
  const spaceMemberCredential = credentials[0].credential.credential;
2213
2413
  invariant5(getCredentialAssertion2(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2214
2414
  F: __dxlog_file10,
2215
- L: 359,
2415
+ L: 362,
2216
2416
  S: this,
2217
2417
  A: [
2218
2418
  "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2246,12 +2446,35 @@ var DataSpaceManager = class extends Resource3 {
2246
2446
  }
2247
2447
  });
2248
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
+ }
2249
2472
  async _constructSpace(metadata) {
2250
2473
  log8("construct space", {
2251
2474
  metadata
2252
2475
  }, {
2253
2476
  F: __dxlog_file10,
2254
- L: 395,
2477
+ L: 416,
2255
2478
  S: this,
2256
2479
  C: (f, a) => f(...a)
2257
2480
  });
@@ -2295,7 +2518,7 @@ var DataSpaceManager = class extends Resource3 {
2295
2518
  err
2296
2519
  }, {
2297
2520
  F: __dxlog_file10,
2298
- L: 437,
2521
+ L: 458,
2299
2522
  S: this,
2300
2523
  C: (f, a) => f(...a)
2301
2524
  });
@@ -2305,7 +2528,7 @@ var DataSpaceManager = class extends Resource3 {
2305
2528
  onAuthFailure: () => {
2306
2529
  log8.warn("auth failure", void 0, {
2307
2530
  F: __dxlog_file10,
2308
- L: 442,
2531
+ L: 463,
2309
2532
  S: this,
2310
2533
  C: (f, a) => f(...a)
2311
2534
  });
@@ -2338,7 +2561,7 @@ var DataSpaceManager = class extends Resource3 {
2338
2561
  space: space.key
2339
2562
  }, {
2340
2563
  F: __dxlog_file10,
2341
- L: 469,
2564
+ L: 490,
2342
2565
  S: this,
2343
2566
  C: (f, a) => f(...a)
2344
2567
  });
@@ -2349,7 +2572,7 @@ var DataSpaceManager = class extends Resource3 {
2349
2572
  open: this._lifecycleState === LifecycleState.OPEN
2350
2573
  }, {
2351
2574
  F: __dxlog_file10,
2352
- L: 472,
2575
+ L: 493,
2353
2576
  S: this,
2354
2577
  C: (f, a) => f(...a)
2355
2578
  });
@@ -2368,7 +2591,7 @@ var DataSpaceManager = class extends Resource3 {
2368
2591
  space: space.key
2369
2592
  }, {
2370
2593
  F: __dxlog_file10,
2371
- L: 480,
2594
+ L: 501,
2372
2595
  S: this,
2373
2596
  C: (f, a) => f(...a)
2374
2597
  });
@@ -2376,13 +2599,20 @@ var DataSpaceManager = class extends Resource3 {
2376
2599
  },
2377
2600
  cache: metadata.cache,
2378
2601
  edgeConnection: this._edgeConnection,
2602
+ edgeHttpClient: this._edgeHttpClient,
2379
2603
  edgeFeatures: this._edgeFeatures
2380
2604
  });
2381
2605
  dataSpace.postOpen.append(async () => {
2382
- await this._echoEdgeReplicator?.connectToSpace(dataSpace.id);
2606
+ const setting = dataSpace.getEdgeReplicationSetting();
2607
+ if (setting === EdgeReplicationSetting.ENABLED) {
2608
+ await this._echoEdgeReplicator?.connectToSpace(dataSpace.id);
2609
+ }
2383
2610
  });
2384
2611
  dataSpace.preClose.append(async () => {
2385
- await this._echoEdgeReplicator?.disconnectFromSpace(dataSpace.id);
2612
+ const setting = dataSpace.getEdgeReplicationSetting();
2613
+ if (setting === EdgeReplicationSetting.ENABLED) {
2614
+ await this._echoEdgeReplicator?.disconnectFromSpace(dataSpace.id);
2615
+ }
2386
2616
  });
2387
2617
  presence.newPeer.on((peerState) => {
2388
2618
  if (dataSpace.state === SpaceState.SPACE_READY) {
@@ -2402,7 +2632,7 @@ var DataSpaceManager = class extends Resource3 {
2402
2632
  space: space.key
2403
2633
  }, {
2404
2634
  F: __dxlog_file10,
2405
- L: 511,
2635
+ L: 539,
2406
2636
  S: this,
2407
2637
  C: (f, a) => f(...a)
2408
2638
  });
@@ -2435,7 +2665,7 @@ var DataSpaceManager = class extends Resource3 {
2435
2665
  closedSessions
2436
2666
  }, {
2437
2667
  F: __dxlog_file10,
2438
- L: 537,
2668
+ L: 565,
2439
2669
  S: this,
2440
2670
  C: (f, a) => f(...a)
2441
2671
  });
@@ -2450,7 +2680,7 @@ var DataSpaceManager = class extends Resource3 {
2450
2680
  peerId: peerState.peerId
2451
2681
  }, {
2452
2682
  F: __dxlog_file10,
2453
- L: 551,
2683
+ L: 579,
2454
2684
  S: this,
2455
2685
  C: (f, a) => f(...a)
2456
2686
  });
@@ -2494,19 +2724,19 @@ var DataSpaceManager = class extends Resource3 {
2494
2724
  await Promise.all(tasks);
2495
2725
  }
2496
2726
  };
2497
- _ts_decorate([
2727
+ _ts_decorate3([
2498
2728
  synchronized
2499
2729
  ], DataSpaceManager.prototype, "_open", null);
2500
- _ts_decorate([
2730
+ _ts_decorate3([
2501
2731
  synchronized
2502
2732
  ], DataSpaceManager.prototype, "_close", null);
2503
- _ts_decorate([
2733
+ _ts_decorate3([
2504
2734
  synchronized
2505
2735
  ], DataSpaceManager.prototype, "createSpace", null);
2506
- _ts_decorate([
2736
+ _ts_decorate3([
2507
2737
  synchronized
2508
2738
  ], DataSpaceManager.prototype, "acceptSpace", null);
2509
- DataSpaceManager = _ts_decorate([
2739
+ DataSpaceManager = _ts_decorate3([
2510
2740
  trackLeaks("open", "close")
2511
2741
  ], DataSpaceManager);
2512
2742
 
@@ -2535,7 +2765,7 @@ var SpacesServiceImpl = class {
2535
2765
  await this._updateMetrics();
2536
2766
  return this._serializeSpace(space);
2537
2767
  }
2538
- async updateSpace({ spaceKey, state }) {
2768
+ async updateSpace({ spaceKey, state, edgeReplication }) {
2539
2769
  const dataSpaceManager = await this._getDataSpaceManager();
2540
2770
  const space = dataSpaceManager.spaces.get(spaceKey) ?? raise(new SpaceNotFoundError(spaceKey));
2541
2771
  if (state) {
@@ -2550,6 +2780,9 @@ var SpacesServiceImpl = class {
2550
2780
  throw new ApiError("Invalid space state");
2551
2781
  }
2552
2782
  }
2783
+ if (edgeReplication !== void 0) {
2784
+ await dataSpaceManager.setSpaceEdgeReplicationSetting(spaceKey, edgeReplication);
2785
+ }
2553
2786
  }
2554
2787
  async updateMemberRole(request) {
2555
2788
  const identity = this._requireIdentity();
@@ -2566,7 +2799,7 @@ var SpacesServiceImpl = class {
2566
2799
  const credentials = await createAdmissionCredentials2(identity.getIdentityCredentialSigner(), request.memberKey, space.key, space.genesisFeedKey, request.newRole, space.spaceState.membershipChainHeads);
2567
2800
  invariant6(credentials[0].credential, void 0, {
2568
2801
  F: __dxlog_file11,
2569
- L: 102,
2802
+ L: 106,
2570
2803
  S: this,
2571
2804
  A: [
2572
2805
  "credentials[0].credential",
@@ -2576,7 +2809,7 @@ var SpacesServiceImpl = class {
2576
2809
  const spaceMemberCredential = credentials[0].credential.credential;
2577
2810
  invariant6(getCredentialAssertion3(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2578
2811
  F: __dxlog_file11,
2579
- L: 104,
2812
+ L: 108,
2580
2813
  S: this,
2581
2814
  A: [
2582
2815
  "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2594,7 +2827,7 @@ var SpacesServiceImpl = class {
2594
2827
  ids: spaces.map((space) => space.id)
2595
2828
  }), {
2596
2829
  F: __dxlog_file11,
2597
- L: 115,
2830
+ L: 119,
2598
2831
  S: this,
2599
2832
  C: (f, a) => f(...a)
2600
2833
  });
@@ -2686,7 +2919,7 @@ var SpacesServiceImpl = class {
2686
2919
  } else {
2687
2920
  invariant6(!credential.id, "Id on unsigned credentials is not allowed", {
2688
2921
  F: __dxlog_file11,
2689
- L: 213,
2922
+ L: 217,
2690
2923
  S: this,
2691
2924
  A: [
2692
2925
  "!credential.id",
@@ -2695,7 +2928,7 @@ var SpacesServiceImpl = class {
2695
2928
  });
2696
2929
  invariant6(this._identityManager.identity, "Identity is not available", {
2697
2930
  F: __dxlog_file11,
2698
- L: 214,
2931
+ L: 218,
2699
2932
  S: this,
2700
2933
  A: [
2701
2934
  "this._identityManager.identity",
@@ -2705,7 +2938,7 @@ var SpacesServiceImpl = class {
2705
2938
  const signer = this._identityManager.identity.getIdentityCredentialSigner();
2706
2939
  invariant6(credential.issuer.equals(signer.getIssuer()), void 0, {
2707
2940
  F: __dxlog_file11,
2708
- L: 216,
2941
+ L: 220,
2709
2942
  S: this,
2710
2943
  A: [
2711
2944
  "credential.issuer.equals(signer.getIssuer())",
@@ -2755,7 +2988,7 @@ var SpacesServiceImpl = class {
2755
2988
  const assertion = getCredentialAssertion3(credential);
2756
2989
  invariant6(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
2757
2990
  F: __dxlog_file11,
2758
- L: 250,
2991
+ L: 254,
2759
2992
  S: this,
2760
2993
  A: [
2761
2994
  "assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2765,7 +2998,7 @@ var SpacesServiceImpl = class {
2765
2998
  const myIdentity = this._identityManager.identity;
2766
2999
  invariant6(myIdentity && credential.subject.id.equals(myIdentity.identityKey), void 0, {
2767
3000
  F: __dxlog_file11,
2768
- L: 252,
3001
+ L: 256,
2769
3002
  S: this,
2770
3003
  A: [
2771
3004
  "myIdentity && credential.subject.id.equals(myIdentity.identityKey)",
@@ -2827,7 +3060,8 @@ var SpacesServiceImpl = class {
2827
3060
  }),
2828
3061
  creator: space.inner.spaceState.creator?.key,
2829
3062
  cache: space.cache,
2830
- metrics: space.metrics
3063
+ metrics: space.metrics,
3064
+ edgeReplication: space.getEdgeReplicationSetting()
2831
3065
  };
2832
3066
  }
2833
3067
  _requireIdentity() {
@@ -2851,7 +3085,7 @@ var SpacesServiceImpl = class {
2851
3085
  var getChannelId = (channel) => `user-channel/${channel}`;
2852
3086
 
2853
3087
  // packages/sdk/client-services/src/packlets/identity/identity.ts
2854
- function _ts_decorate2(decorators, target, key, desc) {
3088
+ function _ts_decorate4(decorators, target, key, desc) {
2855
3089
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2856
3090
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
2857
3091
  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;
@@ -2960,6 +3194,9 @@ var Identity = class {
2960
3194
  get presence() {
2961
3195
  return this._presence;
2962
3196
  }
3197
+ get signer() {
3198
+ return this._signer;
3199
+ }
2963
3200
  /**
2964
3201
  * Issues credentials as identity.
2965
3202
  * Requires identity to be ready.
@@ -2967,7 +3204,7 @@ var Identity = class {
2967
3204
  getIdentityCredentialSigner() {
2968
3205
  invariant7(this._deviceStateMachine.deviceCredentialChain, "Device credential chain is not ready.", {
2969
3206
  F: __dxlog_file12,
2970
- L: 185,
3207
+ L: 189,
2971
3208
  S: this,
2972
3209
  A: [
2973
3210
  "this._deviceStateMachine.deviceCredentialChain",
@@ -3011,7 +3248,7 @@ var Identity = class {
3011
3248
  dataFeedKey
3012
3249
  }, {
3013
3250
  F: __dxlog_file12,
3014
- L: 210,
3251
+ L: 214,
3015
3252
  S: this,
3016
3253
  C: (f, a) => f(...a)
3017
3254
  });
@@ -3052,20 +3289,20 @@ var Identity = class {
3052
3289
  })));
3053
3290
  }
3054
3291
  };
3055
- _ts_decorate2([
3292
+ _ts_decorate4([
3056
3293
  trace3.span()
3057
3294
  ], Identity.prototype, "open", null);
3058
- _ts_decorate2([
3295
+ _ts_decorate4([
3059
3296
  trace3.span()
3060
3297
  ], Identity.prototype, "close", null);
3061
- Identity = _ts_decorate2([
3298
+ Identity = _ts_decorate4([
3062
3299
  trace3.resource()
3063
3300
  ], Identity);
3064
3301
 
3065
3302
  // packages/sdk/client-services/src/packlets/identity/identity-manager.ts
3066
3303
  import platform from "platform";
3067
3304
  import { Event as Event6 } from "@dxos/async";
3068
- import { Context as Context5 } from "@dxos/context";
3305
+ import { Context as Context4 } from "@dxos/context";
3069
3306
  import { createCredentialSignerWithKey as createCredentialSignerWithKey2, CredentialGenerator } from "@dxos/credentials";
3070
3307
  import { invariant as invariant8 } from "@dxos/invariant";
3071
3308
  import { PublicKey as PublicKey7 } from "@dxos/keys";
@@ -3077,7 +3314,7 @@ import { Gossip as Gossip2, Presence as Presence2 } from "@dxos/teleport-extensi
3077
3314
  import { Timeframe as Timeframe3 } from "@dxos/timeframe";
3078
3315
  import { trace as Trace2 } from "@dxos/tracing";
3079
3316
  import { isNode, deferFunction as deferFunction2 } from "@dxos/util";
3080
- function _ts_decorate3(decorators, target, key, desc) {
3317
+ function _ts_decorate5(decorators, target, key, desc) {
3081
3318
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3082
3319
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
3083
3320
  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;
@@ -3147,7 +3384,7 @@ var IdentityManager = class {
3147
3384
  });
3148
3385
  }
3149
3386
  async close() {
3150
- await this._identity?.close(new Context5(void 0, {
3387
+ await this._identity?.close(new Context4(void 0, {
3151
3388
  F: __dxlog_file13,
3152
3389
  L: 140
3153
3390
  }));
@@ -3180,7 +3417,7 @@ var IdentityManager = class {
3180
3417
  }
3181
3418
  };
3182
3419
  const identity = await this._constructIdentity(identityRecord);
3183
- await identity.open(new Context5(void 0, {
3420
+ await identity.open(new Context4(void 0, {
3184
3421
  F: __dxlog_file13,
3185
3422
  L: 161
3186
3423
  }));
@@ -3309,7 +3546,7 @@ var IdentityManager = class {
3309
3546
  }
3310
3547
  };
3311
3548
  const identity = await this._constructIdentity(identityRecord);
3312
- await identity.open(new Context5(void 0, {
3549
+ await identity.open(new Context4(void 0, {
3313
3550
  F: __dxlog_file13,
3314
3551
  L: 268
3315
3552
  }));
@@ -3528,19 +3765,19 @@ var IdentityManager = class {
3528
3765
  });
3529
3766
  }
3530
3767
  };
3531
- _ts_decorate3([
3768
+ _ts_decorate5([
3532
3769
  Trace2.span({
3533
3770
  showInBrowserTimeline: true
3534
3771
  })
3535
3772
  ], IdentityManager.prototype, "open", null);
3536
- IdentityManager = _ts_decorate3([
3773
+ IdentityManager = _ts_decorate5([
3537
3774
  Trace2.resource()
3538
3775
  ], IdentityManager);
3539
3776
 
3540
3777
  // packages/sdk/client-services/src/packlets/identity/identity-service.ts
3541
3778
  import { Trigger as Trigger4, sleep as sleep2 } from "@dxos/async";
3542
3779
  import { Stream as Stream8 } from "@dxos/codec-protobuf";
3543
- import { Resource as Resource4 } from "@dxos/context";
3780
+ import { Resource as Resource5 } from "@dxos/context";
3544
3781
  import { signPresentation } from "@dxos/credentials";
3545
3782
  import { todo } from "@dxos/debug";
3546
3783
  import { invariant as invariant9 } from "@dxos/invariant";
@@ -3549,7 +3786,7 @@ import { SpaceState as SpaceState3 } from "@dxos/protocols/proto/dxos/client/ser
3549
3786
  import { safeAwaitAll } from "@dxos/util";
3550
3787
  var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-service.ts";
3551
3788
  var DEFAULT_SPACE_SEARCH_TIMEOUT = 1e4;
3552
- var IdentityServiceImpl = class extends Resource4 {
3789
+ var IdentityServiceImpl = class extends Resource5 {
3553
3790
  constructor(_identityManager, _keyring, _dataSpaceManagerProvider, _createIdentity, _onProfileUpdate) {
3554
3791
  super();
3555
3792
  this._identityManager = _identityManager;
@@ -3693,7 +3930,7 @@ var IdentityServiceImpl = class extends Resource4 {
3693
3930
  };
3694
3931
 
3695
3932
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
3696
- function _ts_decorate4(decorators, target, key, desc) {
3933
+ function _ts_decorate6(decorators, target, key, desc) {
3697
3934
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3698
3935
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
3699
3936
  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;
@@ -3764,11 +4001,10 @@ function _using_ctx2() {
3764
4001
  var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
3765
4002
  var DataSpace = class {
3766
4003
  constructor(params) {
3767
- this._ctx = new Context6(void 0, {
4004
+ this._ctx = new Context5(void 0, {
3768
4005
  F: __dxlog_file15,
3769
- L: 94
4006
+ L: 95
3770
4007
  });
3771
- this._notarizationPlugin = new NotarizationPlugin();
3772
4008
  this._cache = void 0;
3773
4009
  this._edgeFeedReplicator = void 0;
3774
4010
  // TODO(dmaretskyi): Move into Space?
@@ -3797,6 +4033,11 @@ var DataSpace = class {
3797
4033
  this._signingContext = params.signingContext;
3798
4034
  this._callbacks = params.callbacks ?? {};
3799
4035
  this._echoHost = params.echoHost;
4036
+ this._notarizationPlugin = new NotarizationPlugin({
4037
+ spaceId: this._inner.id,
4038
+ edgeClient: params.edgeHttpClient,
4039
+ edgeFeatures: params.edgeFeatures
4040
+ });
3800
4041
  this.authVerifier = new TrustedKeySetAuthVerifier({
3801
4042
  trustedKeysProvider: () => new ComplexSet3(PublicKey8.hash, Array.from(this._inner.spaceState.members.values()).filter((member) => member.role !== SpaceMember5.Role.REMOVED).map((member) => member.key)),
3802
4043
  update: this._inner.stateUpdate,
@@ -3814,7 +4055,7 @@ var DataSpace = class {
3814
4055
  state: SpaceState4[this._state]
3815
4056
  }, {
3816
4057
  F: __dxlog_file15,
3817
- L: 164,
4058
+ L: 170,
3818
4059
  S: this,
3819
4060
  C: (f, a) => f(...a)
3820
4061
  });
@@ -3871,9 +4112,9 @@ var DataSpace = class {
3871
4112
  if (this._edgeFeedReplicator) {
3872
4113
  this.inner.protocol.feedAdded.append(this._onFeedAdded);
3873
4114
  }
3874
- await this._inner.open(new Context6(void 0, {
4115
+ await this._inner.open(new Context5(void 0, {
3875
4116
  F: __dxlog_file15,
3876
- L: 238
4117
+ L: 244
3877
4118
  }));
3878
4119
  await this._edgeFeedReplicator?.open();
3879
4120
  this._state = SpaceState4.SPACE_CONTROL_ONLY;
@@ -3881,7 +4122,7 @@ var DataSpace = class {
3881
4122
  state: SpaceState4[this._state]
3882
4123
  }, {
3883
4124
  F: __dxlog_file15,
3884
- L: 243,
4125
+ L: 249,
3885
4126
  S: this,
3886
4127
  C: (f, a) => f(...a)
3887
4128
  });
@@ -3901,14 +4142,14 @@ var DataSpace = class {
3901
4142
  state: SpaceState4[this._state]
3902
4143
  }, {
3903
4144
  F: __dxlog_file15,
3904
- L: 262,
4145
+ L: 268,
3905
4146
  S: this,
3906
4147
  C: (f, a) => f(...a)
3907
4148
  });
3908
4149
  await this._ctx.dispose();
3909
- this._ctx = new Context6(void 0, {
4150
+ this._ctx = new Context5(void 0, {
3910
4151
  F: __dxlog_file15,
3911
- L: 264
4152
+ L: 270
3912
4153
  });
3913
4154
  if (this._edgeFeedReplicator) {
3914
4155
  this.inner.protocol.feedAdded.remove(this._onFeedAdded);
@@ -3941,7 +4182,7 @@ var DataSpace = class {
3941
4182
  if (err instanceof CancelledError || err instanceof ContextDisposedError) {
3942
4183
  log13("data pipeline initialization cancelled", err, {
3943
4184
  F: __dxlog_file15,
3944
- L: 302,
4185
+ L: 308,
3945
4186
  S: this,
3946
4187
  C: (f, a) => f(...a)
3947
4188
  });
@@ -3949,7 +4190,7 @@ var DataSpace = class {
3949
4190
  }
3950
4191
  log13.error("Error initializing data pipeline", err, {
3951
4192
  F: __dxlog_file15,
3952
- L: 306,
4193
+ L: 312,
3953
4194
  S: this,
3954
4195
  C: (f, a) => f(...a)
3955
4196
  });
@@ -3958,7 +4199,7 @@ var DataSpace = class {
3958
4199
  state: SpaceState4[this._state]
3959
4200
  }, {
3960
4201
  F: __dxlog_file15,
3961
- L: 308,
4202
+ L: 314,
3962
4203
  S: this,
3963
4204
  C: (f, a) => f(...a)
3964
4205
  });
@@ -3978,15 +4219,39 @@ var DataSpace = class {
3978
4219
  state: SpaceState4[this._state]
3979
4220
  }, {
3980
4221
  F: __dxlog_file15,
3981
- L: 324,
4222
+ L: 330,
4223
+ S: this,
4224
+ C: (f, a) => f(...a)
4225
+ });
4226
+ log13("initializing control pipeline", void 0, {
4227
+ F: __dxlog_file15,
4228
+ L: 332,
3982
4229
  S: this,
3983
4230
  C: (f, a) => f(...a)
3984
4231
  });
3985
4232
  await this._initializeAndReadControlPipeline();
3986
4233
  await sleep3(1);
3987
4234
  const ready = this.stateUpdate.waitForCondition(() => this._state === SpaceState4.SPACE_READY);
4235
+ log13("initializing automerge root", void 0, {
4236
+ F: __dxlog_file15,
4237
+ L: 340,
4238
+ S: this,
4239
+ C: (f, a) => f(...a)
4240
+ });
3988
4241
  this._automergeSpaceState.startProcessingRootDocs();
4242
+ log13("waiting for space to be ready", void 0, {
4243
+ F: __dxlog_file15,
4244
+ L: 344,
4245
+ S: this,
4246
+ C: (f, a) => f(...a)
4247
+ });
3989
4248
  await ready;
4249
+ log13("space is ready", void 0, {
4250
+ F: __dxlog_file15,
4251
+ L: 346,
4252
+ S: this,
4253
+ C: (f, a) => f(...a)
4254
+ });
3990
4255
  }
3991
4256
  async _enterReadyState() {
3992
4257
  await this._callbacks.beforeReady?.();
@@ -3995,7 +4260,7 @@ var DataSpace = class {
3995
4260
  state: SpaceState4[this._state]
3996
4261
  }, {
3997
4262
  F: __dxlog_file15,
3998
- L: 343,
4263
+ L: 353,
3999
4264
  S: this,
4000
4265
  C: (f, a) => f(...a)
4001
4266
  });
@@ -4005,13 +4270,14 @@ var DataSpace = class {
4005
4270
  async _initializeAndReadControlPipeline() {
4006
4271
  await this._inner.controlPipeline.state.waitUntilReachedTargetTimeframe({
4007
4272
  ctx: this._ctx,
4273
+ timeout: 1e4,
4008
4274
  breakOnStall: false
4009
4275
  });
4010
4276
  this.metrics.controlPipelineReady = /* @__PURE__ */ new Date();
4011
4277
  await this._createWritableFeeds();
4012
4278
  log13("writable feeds created", void 0, {
4013
4279
  F: __dxlog_file15,
4014
- L: 359,
4280
+ L: 370,
4015
4281
  S: this,
4016
4282
  C: (f, a) => f(...a)
4017
4283
  });
@@ -4060,11 +4326,35 @@ var DataSpace = class {
4060
4326
  }));
4061
4327
  }
4062
4328
  if (credentials.length > 0) {
4063
- await this.notarizationPlugin.notarize({
4064
- ctx: this._ctx,
4065
- credentials,
4066
- timeout: 0
4067
- });
4329
+ try {
4330
+ log13("will notarize credentials for feed admission", {
4331
+ count: credentials.length
4332
+ }, {
4333
+ F: __dxlog_file15,
4334
+ L: 428,
4335
+ S: this,
4336
+ C: (f, a) => f(...a)
4337
+ });
4338
+ await this.notarizationPlugin.notarize({
4339
+ ctx: this._ctx,
4340
+ credentials,
4341
+ timeout: 0
4342
+ });
4343
+ log13("credentials notarized", void 0, {
4344
+ F: __dxlog_file15,
4345
+ L: 432,
4346
+ S: this,
4347
+ C: (f, a) => f(...a)
4348
+ });
4349
+ } catch (err) {
4350
+ log13.error("error notarizing credentials for feed admission", err, {
4351
+ F: __dxlog_file15,
4352
+ L: 434,
4353
+ S: this,
4354
+ C: (f, a) => f(...a)
4355
+ });
4356
+ throw err;
4357
+ }
4068
4358
  await this._metadataStore.setWritableFeedKeys(this.key, this.inner.controlFeedKey, this.inner.dataFeedKey);
4069
4359
  }
4070
4360
  }
@@ -4074,7 +4364,7 @@ var DataSpace = class {
4074
4364
  rootUrl
4075
4365
  }, {
4076
4366
  F: __dxlog_file15,
4077
- L: 425,
4367
+ L: 444,
4078
4368
  S: this,
4079
4369
  C: (f, a) => f(...a)
4080
4370
  });
@@ -4126,7 +4416,7 @@ var DataSpace = class {
4126
4416
  err
4127
4417
  }, {
4128
4418
  F: __dxlog_file15,
4129
- L: 468,
4419
+ L: 487,
4130
4420
  S: this,
4131
4421
  C: (f, a) => f(...a)
4132
4422
  });
@@ -4216,58 +4506,61 @@ var DataSpace = class {
4216
4506
  state: SpaceState4[this._state]
4217
4507
  }, {
4218
4508
  F: __dxlog_file15,
4219
- L: 550,
4509
+ L: 569,
4220
4510
  S: this,
4221
4511
  C: (f, a) => f(...a)
4222
4512
  });
4223
4513
  this.stateUpdate.emit();
4224
4514
  }
4515
+ getEdgeReplicationSetting() {
4516
+ return this._metadataStore.getSpaceEdgeReplicationSetting(this.key);
4517
+ }
4225
4518
  };
4226
- _ts_decorate4([
4519
+ _ts_decorate6([
4227
4520
  trace5.info()
4228
4521
  ], DataSpace.prototype, "_inner", void 0);
4229
- _ts_decorate4([
4522
+ _ts_decorate6([
4230
4523
  trace5.info()
4231
4524
  ], DataSpace.prototype, "id", null);
4232
- _ts_decorate4([
4525
+ _ts_decorate6([
4233
4526
  trace5.info()
4234
4527
  ], DataSpace.prototype, "key", null);
4235
- _ts_decorate4([
4528
+ _ts_decorate6([
4236
4529
  trace5.info({
4237
4530
  enum: SpaceState4
4238
4531
  })
4239
4532
  ], DataSpace.prototype, "state", null);
4240
- _ts_decorate4([
4533
+ _ts_decorate6([
4241
4534
  trace5.info({
4242
4535
  depth: null
4243
4536
  })
4244
4537
  ], DataSpace.prototype, "_automergeInfo", null);
4245
- _ts_decorate4([
4538
+ _ts_decorate6([
4246
4539
  synchronized2
4247
4540
  ], DataSpace.prototype, "open", null);
4248
- _ts_decorate4([
4541
+ _ts_decorate6([
4249
4542
  synchronized2
4250
4543
  ], DataSpace.prototype, "close", null);
4251
- _ts_decorate4([
4544
+ _ts_decorate6([
4252
4545
  trace5.span({
4253
4546
  showInBrowserTimeline: true
4254
4547
  })
4255
4548
  ], DataSpace.prototype, "initializeDataPipeline", null);
4256
- _ts_decorate4([
4549
+ _ts_decorate6([
4257
4550
  trace5.span({
4258
4551
  showInBrowserTimeline: true
4259
4552
  })
4260
4553
  ], DataSpace.prototype, "_initializeAndReadControlPipeline", null);
4261
- _ts_decorate4([
4554
+ _ts_decorate6([
4262
4555
  timed(1e4)
4263
4556
  ], DataSpace.prototype, "_createWritableFeeds", null);
4264
- _ts_decorate4([
4557
+ _ts_decorate6([
4265
4558
  synchronized2
4266
4559
  ], DataSpace.prototype, "activate", null);
4267
- _ts_decorate4([
4560
+ _ts_decorate6([
4268
4561
  synchronized2
4269
4562
  ], DataSpace.prototype, "deactivate", null);
4270
- DataSpace = _ts_decorate4([
4563
+ DataSpace = _ts_decorate6([
4271
4564
  trackLeaks2("open", "close"),
4272
4565
  trace5.resource()
4273
4566
  ], DataSpace);
@@ -4401,7 +4694,7 @@ import { ComplexSet as ComplexSet5 } from "@dxos/util";
4401
4694
 
4402
4695
  // packages/sdk/client-services/src/packlets/invitations/invitation-guest-extenstion.ts
4403
4696
  import { Trigger as Trigger5 } from "@dxos/async";
4404
- import { cancelWithContext as cancelWithContext4, Context as Context7 } from "@dxos/context";
4697
+ import { cancelWithContext as cancelWithContext4, Context as Context6 } from "@dxos/context";
4405
4698
  import { invariant as invariant11 } from "@dxos/invariant";
4406
4699
  import { log as log14 } from "@dxos/log";
4407
4700
  import { InvalidInvitationExtensionRoleError } from "@dxos/protocols";
@@ -4443,7 +4736,7 @@ var InvitationGuestExtension = class extends RpcExtension2 {
4443
4736
  });
4444
4737
  this._invitationFlowMutex = _invitationFlowMutex;
4445
4738
  this._callbacks = _callbacks;
4446
- this._ctx = new Context7(void 0, {
4739
+ this._ctx = new Context6(void 0, {
4447
4740
  F: __dxlog_file17,
4448
4741
  L: 34
4449
4742
  });
@@ -4555,7 +4848,7 @@ var InvitationGuestExtension = class extends RpcExtension2 {
4555
4848
 
4556
4849
  // packages/sdk/client-services/src/packlets/invitations/invitation-host-extension.ts
4557
4850
  import { Trigger as Trigger6, scheduleTask as scheduleTask5 } from "@dxos/async";
4558
- import { cancelWithContext as cancelWithContext5, Context as Context8 } from "@dxos/context";
4851
+ import { cancelWithContext as cancelWithContext5, Context as Context7 } from "@dxos/context";
4559
4852
  import { randomBytes, verify } from "@dxos/crypto";
4560
4853
  import { invariant as invariant12, InvariantViolation } from "@dxos/invariant";
4561
4854
  import { PublicKey as PublicKey9 } from "@dxos/keys";
@@ -4580,7 +4873,7 @@ var InvitationHostExtension = class extends RpcExtension3 {
4580
4873
  });
4581
4874
  this._invitationFlowMutex = _invitationFlowMutex;
4582
4875
  this._callbacks = _callbacks;
4583
- this._ctx = new Context8(void 0, {
4876
+ this._ctx = new Context7(void 0, {
4584
4877
  F: __dxlog_file18,
4585
4878
  L: 53
4586
4879
  });
@@ -5955,7 +6248,7 @@ var SpaceInvitationProtocol = class {
5955
6248
  // packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts
5956
6249
  import { Event as Event8, PushStream, TimeoutError as TimeoutError3, Trigger as Trigger7 } from "@dxos/async";
5957
6250
  import { AuthenticatingInvitation, AUTHENTICATION_CODE_LENGTH, CancellableInvitation, INVITATION_TIMEOUT as INVITATION_TIMEOUT2 } from "@dxos/client-protocol";
5958
- import { Context as Context9 } from "@dxos/context";
6251
+ import { Context as Context8 } from "@dxos/context";
5959
6252
  import { generatePasscode } from "@dxos/credentials";
5960
6253
  import { hasInvitationExpired } from "@dxos/echo-pipeline";
5961
6254
  import { invariant as invariant16 } from "@dxos/invariant";
@@ -6187,7 +6480,7 @@ var InvitationsManager = class {
6187
6480
  }
6188
6481
  _createObservableInvitation(handler, invitation) {
6189
6482
  const stream = new PushStream();
6190
- const ctx = new Context9({
6483
+ const ctx = new Context8({
6191
6484
  onError: (err) => {
6192
6485
  stream.error(err);
6193
6486
  void ctx.dispose();
@@ -6227,7 +6520,7 @@ var InvitationsManager = class {
6227
6520
  _createObservableAcceptingInvitation(handler, initialState) {
6228
6521
  const otpEnteredTrigger = new Trigger7();
6229
6522
  const stream = new PushStream();
6230
- const ctx = new Context9({
6523
+ const ctx = new Context8({
6231
6524
  onError: (err) => {
6232
6525
  if (err instanceof TimeoutError3) {
6233
6526
  log19("timeout", {
@@ -6326,8 +6619,8 @@ var InvitationsManager = class {
6326
6619
  // packages/sdk/client-services/src/packlets/locks/browser.ts
6327
6620
  import { asyncTimeout as asyncTimeout2, Trigger as Trigger8 } from "@dxos/async";
6328
6621
  import { RESOURCE_LOCK_TIMEOUT } from "@dxos/client-protocol";
6329
- import { log as log20, logInfo } from "@dxos/log";
6330
- function _ts_decorate5(decorators, target, key, desc) {
6622
+ import { log as log20, logInfo as logInfo3 } from "@dxos/log";
6623
+ function _ts_decorate7(decorators, target, key, desc) {
6331
6624
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
6332
6625
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
6333
6626
  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;
@@ -6436,8 +6729,8 @@ var Lock = class {
6436
6729
  });
6437
6730
  }
6438
6731
  };
6439
- _ts_decorate5([
6440
- logInfo
6732
+ _ts_decorate7([
6733
+ logInfo3
6441
6734
  ], Lock.prototype, "lockKey", null);
6442
6735
  var isLocked = (lockPath) => {
6443
6736
  throw new Error("Not implemented");
@@ -6448,7 +6741,7 @@ import { Stream as Stream10 } from "@dxos/codec-protobuf";
6448
6741
  import { raise as raise2 } from "@dxos/debug";
6449
6742
  import { parseMethodName, RpcPeer } from "@dxos/rpc";
6450
6743
  import { MapCounter, trace as trace8 } from "@dxos/tracing";
6451
- function _ts_decorate6(decorators, target, key, desc) {
6744
+ function _ts_decorate8(decorators, target, key, desc) {
6452
6745
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
6453
6746
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
6454
6747
  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;
@@ -6510,22 +6803,23 @@ var ClientRpcServer = class {
6510
6803
  return this._handlerCache.get(serviceName);
6511
6804
  }
6512
6805
  };
6513
- _ts_decorate6([
6806
+ _ts_decorate8([
6514
6807
  trace8.metricsCounter()
6515
6808
  ], ClientRpcServer.prototype, "_callMetrics", void 0);
6516
- _ts_decorate6([
6809
+ _ts_decorate8([
6517
6810
  trace8.info()
6518
6811
  ], ClientRpcServer.prototype, "_services", null);
6519
- ClientRpcServer = _ts_decorate6([
6812
+ ClientRpcServer = _ts_decorate8([
6520
6813
  trace8.resource()
6521
6814
  ], ClientRpcServer);
6522
6815
 
6523
6816
  // packages/sdk/client-services/src/packlets/services/service-context.ts
6524
- import { Trigger as Trigger9 } from "@dxos/async";
6525
- import { Context as Context10, Resource as Resource5 } from "@dxos/context";
6817
+ import { Mutex as Mutex4, scheduleMicroTask as scheduleMicroTask3, Trigger as Trigger9 } from "@dxos/async";
6818
+ import { Context as Context9, Resource as Resource6 } from "@dxos/context";
6526
6819
  import { getCredentialAssertion as getCredentialAssertion5 } from "@dxos/credentials";
6527
- import { failUndefined as failUndefined2 } from "@dxos/debug";
6820
+ import { failUndefined as failUndefined2, warnAfterTimeout as warnAfterTimeout2 } from "@dxos/debug";
6528
6821
  import { EchoEdgeReplicator, EchoHost, MeshEchoReplicator, MetadataStore, SpaceManager, valueEncoding } from "@dxos/echo-pipeline";
6822
+ import { createChainEdgeIdentity, createEphemeralEdgeIdentity } from "@dxos/edge-client";
6529
6823
  import { FeedFactory, FeedStore } from "@dxos/feed-store";
6530
6824
  import { invariant as invariant17 } from "@dxos/invariant";
6531
6825
  import { Keyring } from "@dxos/keyring";
@@ -6536,23 +6830,87 @@ import { Invitation as Invitation8 } from "@dxos/protocols/proto/dxos/client/ser
6536
6830
  import { BlobStore } from "@dxos/teleport-extension-object-sync";
6537
6831
  import { trace as Trace3 } from "@dxos/tracing";
6538
6832
  import { safeInstanceof } from "@dxos/util";
6539
- function _ts_decorate7(decorators, target, key, desc) {
6833
+ function _ts_decorate9(decorators, target, key, desc) {
6540
6834
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
6541
6835
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
6542
6836
  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;
6543
6837
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6544
6838
  }
6839
+ function _using_ctx3() {
6840
+ var _disposeSuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed) {
6841
+ var err = new Error();
6842
+ err.name = "SuppressedError";
6843
+ err.suppressed = suppressed;
6844
+ err.error = error;
6845
+ return err;
6846
+ }, empty = {}, stack = [];
6847
+ function using(isAwait, value) {
6848
+ if (value != null) {
6849
+ if (Object(value) !== value) {
6850
+ throw new TypeError("using declarations can only be used with objects, functions, null, or undefined.");
6851
+ }
6852
+ if (isAwait) {
6853
+ var dispose = value[Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose")];
6854
+ }
6855
+ if (dispose == null) {
6856
+ dispose = value[Symbol.dispose || Symbol.for("Symbol.dispose")];
6857
+ }
6858
+ if (typeof dispose !== "function") {
6859
+ throw new TypeError(`Property [Symbol.dispose] is not a function.`);
6860
+ }
6861
+ stack.push({
6862
+ v: value,
6863
+ d: dispose,
6864
+ a: isAwait
6865
+ });
6866
+ } else if (isAwait) {
6867
+ stack.push({
6868
+ d: value,
6869
+ a: isAwait
6870
+ });
6871
+ }
6872
+ return value;
6873
+ }
6874
+ return {
6875
+ e: empty,
6876
+ u: using.bind(null, false),
6877
+ a: using.bind(null, true),
6878
+ d: function() {
6879
+ var error = this.e;
6880
+ function next() {
6881
+ while (resource = stack.pop()) {
6882
+ try {
6883
+ var resource, disposalResult = resource.d && resource.d.call(resource.v);
6884
+ if (resource.a) {
6885
+ return Promise.resolve(disposalResult).then(next, err);
6886
+ }
6887
+ } catch (e) {
6888
+ return err(e);
6889
+ }
6890
+ }
6891
+ if (error !== empty) throw error;
6892
+ }
6893
+ function err(e) {
6894
+ error = error !== empty ? new _disposeSuppressedError(error, e) : e;
6895
+ return next();
6896
+ }
6897
+ return next();
6898
+ }
6899
+ };
6900
+ }
6545
6901
  var __dxlog_file24 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
6546
- var ServiceContext = class extends Resource5 {
6547
- constructor(storage, level, networkManager, signalManager, _edgeConnection, _runtimeParams, _edgeFeatures) {
6902
+ var ServiceContext = class extends Resource6 {
6903
+ constructor(storage, level, networkManager, signalManager, _edgeConnection, _edgeHttpClient, _runtimeParams, _edgeFeatures) {
6548
6904
  super();
6549
6905
  this.storage = storage;
6550
6906
  this.level = level;
6551
6907
  this.networkManager = networkManager;
6552
6908
  this.signalManager = signalManager;
6553
6909
  this._edgeConnection = _edgeConnection;
6910
+ this._edgeHttpClient = _edgeHttpClient;
6554
6911
  this._runtimeParams = _runtimeParams;
6555
6912
  this._edgeFeatures = _edgeFeatures;
6913
+ this._edgeIdentityUpdateMutex = new Mutex4();
6556
6914
  this.initialized = new Trigger9();
6557
6915
  this._meshReplicator = void 0;
6558
6916
  this._echoEdgeReplicator = void 0;
@@ -6590,23 +6948,42 @@ var ServiceContext = class extends Resource5 {
6590
6948
  callbacks: {
6591
6949
  onIdentityConstruction: (identity) => {
6592
6950
  if (this._edgeConnection) {
6593
- log21.info("Setting identity on edge connection", {
6594
- identity: identity.identityKey.toHex(),
6595
- oldIdentity: this._edgeConnection.identityKey,
6596
- swarms: this.networkManager.topics
6597
- }, {
6598
- F: __dxlog_file24,
6599
- L: 140,
6600
- S: this,
6601
- C: (f, a) => f(...a)
6602
- });
6603
- this._edgeConnection.setIdentity({
6604
- peerKey: identity.deviceKey.toHex(),
6605
- identityKey: identity.identityKey.toHex()
6606
- });
6607
- this.networkManager.setPeerInfo({
6608
- identityKey: identity.identityKey.toHex(),
6609
- peerKey: identity.deviceKey.toHex()
6951
+ scheduleMicroTask3(this._ctx, async () => {
6952
+ try {
6953
+ var _usingCtx = _using_ctx3();
6954
+ const _ = _usingCtx.u(await this._edgeIdentityUpdateMutex.acquire());
6955
+ log21.info("Setting identity on edge connection", {
6956
+ identity: identity.identityKey.toHex(),
6957
+ oldIdentity: this._edgeConnection.identityKey,
6958
+ swarms: this.networkManager.topics
6959
+ }, {
6960
+ F: __dxlog_file24,
6961
+ L: 147,
6962
+ S: this,
6963
+ C: (f, a) => f(...a)
6964
+ });
6965
+ await warnAfterTimeout2(1e4, "Waiting for identity to be ready for edge connection", async () => {
6966
+ await identity.ready();
6967
+ });
6968
+ invariant17(identity.deviceCredentialChain, void 0, {
6969
+ F: __dxlog_file24,
6970
+ L: 157,
6971
+ S: this,
6972
+ A: [
6973
+ "identity.deviceCredentialChain",
6974
+ ""
6975
+ ]
6976
+ });
6977
+ this._edgeConnection.setIdentity(await createChainEdgeIdentity(identity.signer, identity.identityKey, identity.deviceKey, identity.deviceCredentialChain, []));
6978
+ this.networkManager.setPeerInfo({
6979
+ identityKey: identity.identityKey.toHex(),
6980
+ peerKey: identity.deviceKey.toHex()
6981
+ });
6982
+ } catch (_) {
6983
+ _usingCtx.e = _;
6984
+ } finally {
6985
+ _usingCtx.d();
6986
+ }
6610
6987
  });
6611
6988
  }
6612
6989
  }
@@ -6632,7 +7009,7 @@ var ServiceContext = class extends Resource5 {
6632
7009
  await this._checkStorageVersion();
6633
7010
  log21("opening...", void 0, {
6634
7011
  F: __dxlog_file24,
6635
- L: 198,
7012
+ L: 217,
6636
7013
  S: this,
6637
7014
  C: (f, a) => f(...a)
6638
7015
  });
@@ -6640,11 +7017,14 @@ var ServiceContext = class extends Resource5 {
6640
7017
  id: this._instanceId
6641
7018
  }), {
6642
7019
  F: __dxlog_file24,
6643
- L: 199,
7020
+ L: 218,
6644
7021
  S: this,
6645
7022
  C: (f, a) => f(...a)
6646
7023
  });
6647
- await this._edgeConnection?.open();
7024
+ if (this._edgeConnection) {
7025
+ this._edgeConnection.setIdentity(await createEphemeralEdgeIdentity());
7026
+ await this._edgeConnection.open();
7027
+ }
6648
7028
  await this.signalManager.open();
6649
7029
  await this.networkManager.open();
6650
7030
  await this.echoHost.open(ctx);
@@ -6665,7 +7045,7 @@ var ServiceContext = class extends Resource5 {
6665
7045
  count: loadedInvitations.invitations?.length
6666
7046
  }, {
6667
7047
  F: __dxlog_file24,
6668
- L: 222,
7048
+ L: 245,
6669
7049
  S: this,
6670
7050
  C: (f, a) => f(...a)
6671
7051
  });
@@ -6673,13 +7053,13 @@ var ServiceContext = class extends Resource5 {
6673
7053
  id: this._instanceId
6674
7054
  }), {
6675
7055
  F: __dxlog_file24,
6676
- L: 224,
7056
+ L: 247,
6677
7057
  S: this,
6678
7058
  C: (f, a) => f(...a)
6679
7059
  });
6680
7060
  log21("opened", void 0, {
6681
7061
  F: __dxlog_file24,
6682
- L: 225,
7062
+ L: 248,
6683
7063
  S: this,
6684
7064
  C: (f, a) => f(...a)
6685
7065
  });
@@ -6687,7 +7067,7 @@ var ServiceContext = class extends Resource5 {
6687
7067
  async _close(ctx) {
6688
7068
  log21("closing...", void 0, {
6689
7069
  F: __dxlog_file24,
6690
- L: 229,
7070
+ L: 252,
6691
7071
  S: this,
6692
7072
  C: (f, a) => f(...a)
6693
7073
  });
@@ -6705,16 +7085,16 @@ var ServiceContext = class extends Resource5 {
6705
7085
  await this._edgeConnection?.close();
6706
7086
  log21("closed", void 0, {
6707
7087
  F: __dxlog_file24,
6708
- L: 244,
7088
+ L: 267,
6709
7089
  S: this,
6710
7090
  C: (f, a) => f(...a)
6711
7091
  });
6712
7092
  }
6713
7093
  async createIdentity(params = {}) {
6714
7094
  const identity = await this.identityManager.createIdentity(params);
6715
- await this._initialize(new Context10(void 0, {
7095
+ await this._initialize(new Context9(void 0, {
6716
7096
  F: __dxlog_file24,
6717
- L: 249
7097
+ L: 272
6718
7098
  }));
6719
7099
  return identity;
6720
7100
  }
@@ -6722,7 +7102,7 @@ var ServiceContext = class extends Resource5 {
6722
7102
  const factory = this._handlerFactories.get(invitation.kind);
6723
7103
  invariant17(factory, `Unknown invitation kind: ${invitation.kind}`, {
6724
7104
  F: __dxlog_file24,
6725
- L: 255,
7105
+ L: 278,
6726
7106
  S: this,
6727
7107
  A: [
6728
7108
  "factory",
@@ -6741,9 +7121,9 @@ var ServiceContext = class extends Resource5 {
6741
7121
  }
6742
7122
  async _acceptIdentity(params) {
6743
7123
  const identity = await this.identityManager.acceptIdentity(params);
6744
- await this._initialize(new Context10(void 0, {
7124
+ await this._initialize(new Context9(void 0, {
6745
7125
  F: __dxlog_file24,
6746
- L: 271
7126
+ L: 294
6747
7127
  }));
6748
7128
  return identity;
6749
7129
  }
@@ -6757,7 +7137,7 @@ var ServiceContext = class extends Resource5 {
6757
7137
  async _initialize(ctx) {
6758
7138
  log21("initializing spaces...", void 0, {
6759
7139
  F: __dxlog_file24,
6760
- L: 286,
7140
+ L: 309,
6761
7141
  S: this,
6762
7142
  C: (f, a) => f(...a)
6763
7143
  });
@@ -6784,6 +7164,7 @@ var ServiceContext = class extends Resource5 {
6784
7164
  echoHost: this.echoHost,
6785
7165
  invitationsManager: this.invitationsManager,
6786
7166
  edgeConnection: this._edgeConnection,
7167
+ edgeHttpClient: this._edgeHttpClient,
6787
7168
  echoEdgeReplicator: this._echoEdgeReplicator,
6788
7169
  meshReplicator: this._meshReplicator,
6789
7170
  runtimeParams: this._runtimeParams,
@@ -6793,7 +7174,7 @@ var ServiceContext = class extends Resource5 {
6793
7174
  this._handlerFactories.set(Invitation8.Kind.SPACE, (invitation) => {
6794
7175
  invariant17(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
6795
7176
  F: __dxlog_file24,
6796
- L: 315,
7177
+ L: 339,
6797
7178
  S: this,
6798
7179
  A: [
6799
7180
  "this.dataSpaceManager",
@@ -6817,7 +7198,7 @@ var ServiceContext = class extends Resource5 {
6817
7198
  details: assertion
6818
7199
  }, {
6819
7200
  F: __dxlog_file24,
6820
- L: 331,
7201
+ L: 355,
6821
7202
  S: this,
6822
7203
  C: (f, a) => f(...a)
6823
7204
  });
@@ -6828,7 +7209,7 @@ var ServiceContext = class extends Resource5 {
6828
7209
  details: assertion
6829
7210
  }, {
6830
7211
  F: __dxlog_file24,
6831
- L: 335,
7212
+ L: 359,
6832
7213
  S: this,
6833
7214
  C: (f, a) => f(...a)
6834
7215
  });
@@ -6839,7 +7220,7 @@ var ServiceContext = class extends Resource5 {
6839
7220
  details: assertion
6840
7221
  }, {
6841
7222
  F: __dxlog_file24,
6842
- L: 340,
7223
+ L: 364,
6843
7224
  S: this,
6844
7225
  C: (f, a) => f(...a)
6845
7226
  });
@@ -6850,7 +7231,7 @@ var ServiceContext = class extends Resource5 {
6850
7231
  } catch (err) {
6851
7232
  log21.catch(err, void 0, {
6852
7233
  F: __dxlog_file24,
6853
- L: 346,
7234
+ L: 370,
6854
7235
  S: this,
6855
7236
  C: (f, a) => f(...a)
6856
7237
  });
@@ -6860,13 +7241,13 @@ var ServiceContext = class extends Resource5 {
6860
7241
  await identity.space.spaceState.addCredentialProcessor(this._deviceSpaceSync);
6861
7242
  }
6862
7243
  };
6863
- _ts_decorate7([
7244
+ _ts_decorate9([
6864
7245
  Trace3.span()
6865
7246
  ], ServiceContext.prototype, "_open", null);
6866
- _ts_decorate7([
7247
+ _ts_decorate9([
6867
7248
  Trace3.span()
6868
7249
  ], ServiceContext.prototype, "_initialize", null);
6869
- ServiceContext = _ts_decorate7([
7250
+ ServiceContext = _ts_decorate9([
6870
7251
  safeInstanceof("dxos.client-services.ServiceContext"),
6871
7252
  Trace3.resource()
6872
7253
  ], ServiceContext);
@@ -7131,8 +7512,8 @@ var importProfileData = async ({ storage, level }, archive) => {
7131
7512
  // packages/sdk/client-services/src/packlets/services/service-host.ts
7132
7513
  import { Event as Event10, synchronized as synchronized3 } from "@dxos/async";
7133
7514
  import { clientServiceBundle } from "@dxos/client-protocol";
7134
- import { Context as Context11 } from "@dxos/context";
7135
- import { EdgeClient } from "@dxos/edge-client";
7515
+ import { Context as Context10 } from "@dxos/context";
7516
+ import { EdgeClient, EdgeHttpClient, createStubEdgeIdentity } from "@dxos/edge-client";
7136
7517
  import { invariant as invariant20 } from "@dxos/invariant";
7137
7518
  import { PublicKey as PublicKey17 } from "@dxos/keys";
7138
7519
  import { log as log24 } from "@dxos/log";
@@ -7523,7 +7904,7 @@ var SystemServiceImpl = class {
7523
7904
  };
7524
7905
 
7525
7906
  // packages/sdk/client-services/src/packlets/services/service-host.ts
7526
- function _ts_decorate8(decorators, target, key, desc) {
7907
+ function _ts_decorate10(decorators, target, key, desc) {
7527
7908
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
7528
7909
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
7529
7910
  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;
@@ -7545,6 +7926,7 @@ var ClientServicesHost = class {
7545
7926
  this._tracingService = TRACE_PROCESSOR3.createTraceSender();
7546
7927
  this._statusUpdate = new Event10();
7547
7928
  this._edgeConnection = void 0;
7929
+ this._edgeHttpClient = void 0;
7548
7930
  this._opening = false;
7549
7931
  this._open = false;
7550
7932
  this._storage = storage;
@@ -7566,9 +7948,9 @@ var ClientServicesHost = class {
7566
7948
  lockKey,
7567
7949
  onAcquire: () => {
7568
7950
  if (!this._opening) {
7569
- void this.open(new Context11(void 0, {
7951
+ void this.open(new Context10(void 0, {
7570
7952
  F: __dxlog_file27,
7571
- L: 132
7953
+ L: 133
7572
7954
  }));
7573
7955
  }
7574
7956
  },
@@ -7626,7 +8008,7 @@ var ClientServicesHost = class {
7626
8008
  initialize({ config, ...options }) {
7627
8009
  invariant20(!this._open, "service host is open", {
7628
8010
  F: __dxlog_file27,
7629
- L: 198,
8011
+ L: 199,
7630
8012
  S: this,
7631
8013
  A: [
7632
8014
  "!this._open",
@@ -7635,14 +8017,14 @@ var ClientServicesHost = class {
7635
8017
  });
7636
8018
  log24("initializing...", void 0, {
7637
8019
  F: __dxlog_file27,
7638
- L: 199,
8020
+ L: 200,
7639
8021
  S: this,
7640
8022
  C: (f, a) => f(...a)
7641
8023
  });
7642
8024
  if (config) {
7643
8025
  invariant20(!this._config, "config already set", {
7644
8026
  F: __dxlog_file27,
7645
- L: 202,
8027
+ L: 203,
7646
8028
  S: this,
7647
8029
  A: [
7648
8030
  "!this._config",
@@ -7657,17 +8039,17 @@ var ClientServicesHost = class {
7657
8039
  if (!options.signalManager) {
7658
8040
  log24.warn("running signaling without telemetry metadata.", void 0, {
7659
8041
  F: __dxlog_file27,
7660
- L: 210,
8042
+ L: 211,
7661
8043
  S: this,
7662
8044
  C: (f, a) => f(...a)
7663
8045
  });
7664
8046
  }
7665
8047
  const edgeEndpoint = config?.get("runtime.services.edge.url");
7666
8048
  if (edgeEndpoint) {
7667
- const randomKey = PublicKey17.random().toHex();
7668
- this._edgeConnection = new EdgeClient(randomKey, randomKey, {
8049
+ this._edgeConnection = new EdgeClient(createStubEdgeIdentity(), {
7669
8050
  socketEndpoint: edgeEndpoint
7670
8051
  });
8052
+ this._edgeHttpClient = new EdgeHttpClient(edgeEndpoint);
7671
8053
  }
7672
8054
  const { connectionLog = true, transportFactory = createRtcTransportFactory({
7673
8055
  iceServers: this._config?.get("runtime.services.ice")
@@ -7677,7 +8059,7 @@ var ClientServicesHost = class {
7677
8059
  this._signalManager = signalManager;
7678
8060
  invariant20(!this._networkManager, "network manager already set", {
7679
8061
  F: __dxlog_file27,
7680
- L: 232,
8062
+ L: 233,
7681
8063
  S: this,
7682
8064
  A: [
7683
8065
  "!this._networkManager",
@@ -7695,7 +8077,7 @@ var ClientServicesHost = class {
7695
8077
  });
7696
8078
  log24("initialized", void 0, {
7697
8079
  F: __dxlog_file27,
7698
- L: 245,
8080
+ L: 246,
7699
8081
  S: this,
7700
8082
  C: (f, a) => f(...a)
7701
8083
  });
@@ -7709,13 +8091,13 @@ var ClientServicesHost = class {
7709
8091
  id: traceId
7710
8092
  }), {
7711
8093
  F: __dxlog_file27,
7712
- L: 256,
8094
+ L: 257,
7713
8095
  S: this,
7714
8096
  C: (f, a) => f(...a)
7715
8097
  });
7716
8098
  invariant20(this._config, "config not set", {
7717
8099
  F: __dxlog_file27,
7718
- L: 258,
8100
+ L: 259,
7719
8101
  S: this,
7720
8102
  A: [
7721
8103
  "this._config",
@@ -7724,7 +8106,7 @@ var ClientServicesHost = class {
7724
8106
  });
7725
8107
  invariant20(this._storage, "storage not set", {
7726
8108
  F: __dxlog_file27,
7727
- L: 259,
8109
+ L: 260,
7728
8110
  S: this,
7729
8111
  A: [
7730
8112
  "this._storage",
@@ -7733,7 +8115,7 @@ var ClientServicesHost = class {
7733
8115
  });
7734
8116
  invariant20(this._signalManager, "signal manager not set", {
7735
8117
  F: __dxlog_file27,
7736
- L: 260,
8118
+ L: 261,
7737
8119
  S: this,
7738
8120
  A: [
7739
8121
  "this._signalManager",
@@ -7742,7 +8124,7 @@ var ClientServicesHost = class {
7742
8124
  });
7743
8125
  invariant20(this._networkManager, "network manager not set", {
7744
8126
  F: __dxlog_file27,
7745
- L: 261,
8127
+ L: 262,
7746
8128
  S: this,
7747
8129
  A: [
7748
8130
  "this._networkManager",
@@ -7754,7 +8136,7 @@ var ClientServicesHost = class {
7754
8136
  lockKey: this._resourceLock?.lockKey
7755
8137
  }, {
7756
8138
  F: __dxlog_file27,
7757
- L: 264,
8139
+ L: 265,
7758
8140
  S: this,
7759
8141
  C: (f, a) => f(...a)
7760
8142
  });
@@ -7764,7 +8146,7 @@ var ClientServicesHost = class {
7764
8146
  }
7765
8147
  await this._level.open();
7766
8148
  await this._loggingService.open();
7767
- this._serviceContext = new ServiceContext(this._storage, this._level, this._networkManager, this._signalManager, this._edgeConnection, this._runtimeParams, this._config.get("runtime.client.edgeFeatures"));
8149
+ this._serviceContext = new ServiceContext(this._storage, this._level, this._networkManager, this._signalManager, this._edgeConnection, this._edgeHttpClient, this._runtimeParams, this._config.get("runtime.client.edgeFeatures"));
7768
8150
  const dataSpaceManagerProvider = async () => {
7769
8151
  await this._serviceContext.initialized.wait();
7770
8152
  return this._serviceContext.dataSpaceManager;
@@ -7810,7 +8192,7 @@ var ClientServicesHost = class {
7810
8192
  deviceKey
7811
8193
  }, {
7812
8194
  F: __dxlog_file27,
7813
- L: 352,
8195
+ L: 354,
7814
8196
  S: this,
7815
8197
  C: (f, a) => f(...a)
7816
8198
  });
@@ -7818,7 +8200,7 @@ var ClientServicesHost = class {
7818
8200
  id: traceId
7819
8201
  }), {
7820
8202
  F: __dxlog_file27,
7821
- L: 353,
8203
+ L: 355,
7822
8204
  S: this,
7823
8205
  C: (f, a) => f(...a)
7824
8206
  });
@@ -7832,7 +8214,7 @@ var ClientServicesHost = class {
7832
8214
  deviceKey
7833
8215
  }, {
7834
8216
  F: __dxlog_file27,
7835
- L: 364,
8217
+ L: 366,
7836
8218
  S: this,
7837
8219
  C: (f, a) => f(...a)
7838
8220
  });
@@ -7850,7 +8232,7 @@ var ClientServicesHost = class {
7850
8232
  deviceKey
7851
8233
  }, {
7852
8234
  F: __dxlog_file27,
7853
- L: 373,
8235
+ L: 375,
7854
8236
  S: this,
7855
8237
  C: (f, a) => f(...a)
7856
8238
  });
@@ -7861,13 +8243,13 @@ var ClientServicesHost = class {
7861
8243
  id: traceId
7862
8244
  }), {
7863
8245
  F: __dxlog_file27,
7864
- L: 378,
8246
+ L: 380,
7865
8247
  S: this,
7866
8248
  C: (f, a) => f(...a)
7867
8249
  });
7868
8250
  log24.info("resetting...", void 0, {
7869
8251
  F: __dxlog_file27,
7870
- L: 380,
8252
+ L: 382,
7871
8253
  S: this,
7872
8254
  C: (f, a) => f(...a)
7873
8255
  });
@@ -7875,7 +8257,7 @@ var ClientServicesHost = class {
7875
8257
  await this._storage.reset();
7876
8258
  log24.info("reset", void 0, {
7877
8259
  F: __dxlog_file27,
7878
- L: 383,
8260
+ L: 385,
7879
8261
  S: this,
7880
8262
  C: (f, a) => f(...a)
7881
8263
  });
@@ -7883,7 +8265,7 @@ var ClientServicesHost = class {
7883
8265
  id: traceId
7884
8266
  }), {
7885
8267
  F: __dxlog_file27,
7886
- L: 384,
8268
+ L: 386,
7887
8269
  S: this,
7888
8270
  C: (f, a) => f(...a)
7889
8271
  });
@@ -7895,21 +8277,21 @@ var ClientServicesHost = class {
7895
8277
  return identity;
7896
8278
  }
7897
8279
  };
7898
- _ts_decorate8([
8280
+ _ts_decorate10([
7899
8281
  Trace4.info()
7900
8282
  ], ClientServicesHost.prototype, "_opening", void 0);
7901
- _ts_decorate8([
8283
+ _ts_decorate10([
7902
8284
  Trace4.info()
7903
8285
  ], ClientServicesHost.prototype, "_open", void 0);
7904
- _ts_decorate8([
8286
+ _ts_decorate10([
7905
8287
  synchronized3,
7906
8288
  Trace4.span()
7907
8289
  ], ClientServicesHost.prototype, "open", null);
7908
- _ts_decorate8([
8290
+ _ts_decorate10([
7909
8291
  synchronized3,
7910
8292
  Trace4.span()
7911
8293
  ], ClientServicesHost.prototype, "close", null);
7912
- ClientServicesHost = _ts_decorate8([
8294
+ ClientServicesHost = _ts_decorate10([
7913
8295
  Trace4.resource()
7914
8296
  ], ClientServicesHost);
7915
8297
 
@@ -7957,4 +8339,4 @@ export {
7957
8339
  importProfileData,
7958
8340
  ClientServicesHost
7959
8341
  };
7960
- //# sourceMappingURL=chunk-XSFLJVDP.mjs.map
8342
+ //# sourceMappingURL=chunk-6UTFANWL.mjs.map