@dxos/client-services 0.7.4 → 0.7.5-labs.071a3e2

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 (96) hide show
  1. package/dist/lib/browser/{chunk-423GRVVV.mjs → chunk-SKOL3Q2R.mjs} +379 -267
  2. package/dist/lib/browser/chunk-SKOL3Q2R.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 +1 -1
  6. package/dist/lib/node/{chunk-ZS24HRVA.cjs → chunk-XTM3FUCM.cjs} +405 -293
  7. package/dist/lib/node/chunk-XTM3FUCM.cjs.map +7 -0
  8. package/dist/lib/node/index.cjs +47 -47
  9. package/dist/lib/node/meta.json +1 -1
  10. package/dist/lib/node/testing/index.cjs +8 -8
  11. package/dist/lib/node-esm/{chunk-OQOXRHWF.mjs → chunk-EQU6BG5J.mjs} +379 -267
  12. package/dist/lib/node-esm/chunk-EQU6BG5J.mjs.map +7 -0
  13. package/dist/lib/node-esm/index.mjs +1 -1
  14. package/dist/lib/node-esm/meta.json +1 -1
  15. package/dist/lib/node-esm/testing/index.mjs +1 -1
  16. package/dist/types/src/packlets/agents/edge-agent-service.d.ts +1 -1
  17. package/dist/types/src/packlets/agents/edge-agent-service.d.ts.map +1 -1
  18. package/dist/types/src/packlets/devices/devices-service.d.ts +1 -1
  19. package/dist/types/src/packlets/devices/devices-service.d.ts.map +1 -1
  20. package/dist/types/src/packlets/devtools/devtools.d.ts +1 -1
  21. package/dist/types/src/packlets/devtools/devtools.d.ts.map +1 -1
  22. package/dist/types/src/packlets/devtools/feeds.d.ts +1 -1
  23. package/dist/types/src/packlets/devtools/feeds.d.ts.map +1 -1
  24. package/dist/types/src/packlets/devtools/keys.d.ts +1 -1
  25. package/dist/types/src/packlets/devtools/keys.d.ts.map +1 -1
  26. package/dist/types/src/packlets/devtools/metadata.d.ts +1 -1
  27. package/dist/types/src/packlets/devtools/metadata.d.ts.map +1 -1
  28. package/dist/types/src/packlets/devtools/network.d.ts +1 -1
  29. package/dist/types/src/packlets/devtools/network.d.ts.map +1 -1
  30. package/dist/types/src/packlets/devtools/spaces.d.ts +1 -1
  31. package/dist/types/src/packlets/devtools/spaces.d.ts.map +1 -1
  32. package/dist/types/src/packlets/diagnostics/diagnostics.d.ts.map +1 -1
  33. package/dist/types/src/packlets/identity/contacts-service.d.ts +1 -1
  34. package/dist/types/src/packlets/identity/contacts-service.d.ts.map +1 -1
  35. package/dist/types/src/packlets/identity/identity-manager.d.ts +0 -3
  36. package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
  37. package/dist/types/src/packlets/identity/identity-recovery-manager.d.ts +12 -4
  38. package/dist/types/src/packlets/identity/identity-recovery-manager.d.ts.map +1 -1
  39. package/dist/types/src/packlets/identity/identity-service.d.ts +9 -4
  40. package/dist/types/src/packlets/identity/identity-service.d.ts.map +1 -1
  41. package/dist/types/src/packlets/identity/identity.d.ts +3 -1
  42. package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
  43. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  44. package/dist/types/src/packlets/invitations/invitations-service.d.ts +1 -1
  45. package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
  46. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
  47. package/dist/types/src/packlets/invitations/utils.d.ts +1 -0
  48. package/dist/types/src/packlets/invitations/utils.d.ts.map +1 -1
  49. package/dist/types/src/packlets/logging/logging-service.d.ts +1 -1
  50. package/dist/types/src/packlets/logging/logging-service.d.ts.map +1 -1
  51. package/dist/types/src/packlets/network/network-service.d.ts +9 -2
  52. package/dist/types/src/packlets/network/network-service.d.ts.map +1 -1
  53. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  54. package/dist/types/src/packlets/spaces/edge-feed-replicator.d.ts.map +1 -1
  55. package/dist/types/src/packlets/spaces/notarization-plugin.d.ts +3 -0
  56. package/dist/types/src/packlets/spaces/notarization-plugin.d.ts.map +1 -1
  57. package/dist/types/src/packlets/spaces/spaces-service.d.ts +1 -1
  58. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  59. package/dist/types/src/packlets/system/system-service.d.ts +1 -1
  60. package/dist/types/src/packlets/system/system-service.d.ts.map +1 -1
  61. package/dist/types/src/version.d.ts +1 -1
  62. package/dist/types/src/version.d.ts.map +1 -1
  63. package/dist/types/tsconfig.tsbuildinfo +1 -0
  64. package/package.json +38 -38
  65. package/src/packlets/agents/edge-agent-service.ts +1 -1
  66. package/src/packlets/devices/devices-service.ts +1 -1
  67. package/src/packlets/devtools/devtools.ts +1 -1
  68. package/src/packlets/devtools/feeds.ts +1 -1
  69. package/src/packlets/devtools/keys.ts +1 -1
  70. package/src/packlets/devtools/metadata.ts +1 -1
  71. package/src/packlets/devtools/network.ts +1 -1
  72. package/src/packlets/devtools/spaces.ts +1 -1
  73. package/src/packlets/diagnostics/diagnostics.ts +17 -13
  74. package/src/packlets/identity/contacts-service.ts +1 -1
  75. package/src/packlets/identity/identity-manager.ts +3 -29
  76. package/src/packlets/identity/identity-recovery-manager.ts +86 -9
  77. package/src/packlets/identity/identity-service.ts +17 -4
  78. package/src/packlets/identity/identity.test.ts +2 -1
  79. package/src/packlets/identity/identity.ts +4 -1
  80. package/src/packlets/invitations/invitations-handler.ts +15 -6
  81. package/src/packlets/invitations/invitations-manager.ts +1 -1
  82. package/src/packlets/invitations/invitations-service.ts +1 -1
  83. package/src/packlets/invitations/space-invitation-protocol.ts +2 -3
  84. package/src/packlets/invitations/utils.ts +7 -0
  85. package/src/packlets/logging/logging-service.ts +1 -1
  86. package/src/packlets/network/network-service.ts +39 -1
  87. package/src/packlets/services/service-context.ts +3 -1
  88. package/src/packlets/spaces/data-space-manager.ts +1 -1
  89. package/src/packlets/spaces/edge-feed-replicator.ts +16 -10
  90. package/src/packlets/spaces/notarization-plugin.ts +32 -17
  91. package/src/packlets/spaces/spaces-service.ts +31 -21
  92. package/src/packlets/system/system-service.ts +1 -1
  93. package/src/version.ts +1 -5
  94. package/dist/lib/browser/chunk-423GRVVV.mjs.map +0 -7
  95. package/dist/lib/node/chunk-ZS24HRVA.cjs.map +0 -7
  96. package/dist/lib/node-esm/chunk-OQOXRHWF.mjs.map +0 -7
@@ -2,7 +2,7 @@ import { createRequire } from 'node:module';const require = createRequire(import
2
2
 
3
3
  // packages/sdk/client-services/src/packlets/devtools/feeds.ts
4
4
  import { EventSubscriptions } from "@dxos/async";
5
- import { Stream } from "@dxos/codec-protobuf";
5
+ import { Stream } from "@dxos/codec-protobuf/stream";
6
6
  import { FeedIterator } from "@dxos/feed-store";
7
7
  import { PublicKey } from "@dxos/keys";
8
8
  import { log } from "@dxos/log";
@@ -113,7 +113,7 @@ var subscribeToFeedBlocks = ({ feedStore }, { feedKey, maxBlocks = 10 }) => {
113
113
  };
114
114
 
115
115
  // packages/sdk/client-services/src/packlets/devtools/network.ts
116
- import { Stream as Stream2 } from "@dxos/codec-protobuf";
116
+ import { Stream as Stream2 } from "@dxos/codec-protobuf/stream";
117
117
  import { Context } from "@dxos/context";
118
118
  import { PublicKey as PublicKey2 } from "@dxos/keys";
119
119
  var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devtools/network.ts";
@@ -210,7 +210,7 @@ var getNetworkPeers = ({ networkManager }, request) => {
210
210
  };
211
211
 
212
212
  // packages/sdk/client-services/src/packlets/devtools/spaces.ts
213
- import { Stream as Stream3 } from "@dxos/codec-protobuf";
213
+ import { Stream as Stream3 } from "@dxos/codec-protobuf/stream";
214
214
  var subscribeToSpaces = (context, { spaceKeys = [] }) => {
215
215
  return new Stream3(({ next }) => {
216
216
  let unsubscribe;
@@ -247,11 +247,11 @@ var subscribeToSpaces = (context, { spaceKeys = [] }) => {
247
247
 
248
248
  // packages/sdk/client-services/src/packlets/devtools/devtools.ts
249
249
  import { Event as AsyncEvent } from "@dxos/async";
250
- import { Stream as Stream6 } from "@dxos/codec-protobuf";
250
+ import { Stream as Stream6 } from "@dxos/codec-protobuf/stream";
251
251
 
252
252
  // packages/sdk/client-services/src/packlets/devtools/keys.ts
253
253
  import { scheduleTask } from "@dxos/async";
254
- import { Stream as Stream4 } from "@dxos/codec-protobuf";
254
+ import { Stream as Stream4 } from "@dxos/codec-protobuf/stream";
255
255
  var subscribeToKeyringKeys = ({ keyring }) => new Stream4(({ next, ctx }) => {
256
256
  const update = async () => {
257
257
  next({
@@ -263,7 +263,7 @@ var subscribeToKeyringKeys = ({ keyring }) => new Stream4(({ next, ctx }) => {
263
263
  });
264
264
 
265
265
  // packages/sdk/client-services/src/packlets/devtools/metadata.ts
266
- import { Stream as Stream5 } from "@dxos/codec-protobuf";
266
+ import { Stream as Stream5 } from "@dxos/codec-protobuf/stream";
267
267
  var subscribeToMetadata = ({ context }) => new Stream5(({ next, ctx }) => {
268
268
  context.metadataStore.update.on(ctx, (data) => next({
269
269
  metadata: data
@@ -390,14 +390,14 @@ var DevtoolsServiceImpl = class {
390
390
  // packages/sdk/client-services/src/packlets/diagnostics/diagnostics.ts
391
391
  import { asyncTimeout } from "@dxos/async";
392
392
  import { getFirstStreamValue } from "@dxos/codec-protobuf";
393
- import { credentialTypeFilter } from "@dxos/credentials";
393
+ import { createDidFromIdentityKey, credentialTypeFilter } from "@dxos/credentials";
394
394
  import { invariant } from "@dxos/invariant";
395
395
  import { STORAGE_VERSION } from "@dxos/protocols";
396
396
  import { SpaceMember } from "@dxos/protocols/proto/dxos/client/services";
397
397
  import { TRACE_PROCESSOR } from "@dxos/tracing";
398
398
 
399
399
  // packages/sdk/client-services/src/version.ts
400
- var DXOS_VERSION = "0.7.4";
400
+ var DXOS_VERSION = "0.7.5-labs.071a3e2";
401
401
 
402
402
  // packages/sdk/client-services/src/packlets/services/platform.ts
403
403
  import { Platform } from "@dxos/protocols/proto/dxos/client/services";
@@ -466,6 +466,7 @@ var createDiagnostics = async (clientServices, serviceContext, config) => {
466
466
  const identity = serviceContext.identityManager.identity;
467
467
  if (identity) {
468
468
  diagnostics.identity = {
469
+ did: identity.did,
469
470
  identityKey: identity.identityKey,
470
471
  spaceKey: identity.space.key,
471
472
  profile: identity.profileDocument
@@ -504,16 +505,17 @@ var getSpaceStats = async (space) => {
504
505
  ...credential.subject.assertion,
505
506
  id: credential.id
506
507
  })),
507
- members: Array.from(space.inner.spaceState.members.values()).map((member) => ({
508
+ members: await Promise.all(Array.from(space.inner.spaceState.members.values()).map(async (member) => ({
508
509
  role: member.role,
509
510
  identity: {
511
+ did: await createDidFromIdentityKey(member.key),
510
512
  identityKey: member.key,
511
513
  profile: {
512
514
  displayName: member.assertion.profile?.displayName
513
515
  }
514
516
  },
515
517
  presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? SpaceMember.PresenceState.ONLINE : SpaceMember.PresenceState.OFFLINE
516
- })),
518
+ }))),
517
519
  pipeline: {
518
520
  // TODO(burdon): Pick properties from credentials if needed.
519
521
  currentEpoch: space.automergeSpaceState.lastEpoch,
@@ -913,7 +915,7 @@ var EdgeFeedReplicator = class extends Resource {
913
915
  this._remoteLength.clear();
914
916
  }
915
917
  async addFeed(feed) {
916
- log3.info("addFeed", {
918
+ log3("addFeed", {
917
919
  key: feed.key,
918
920
  connected: this._connected,
919
921
  hasConnectionCtx: !!this._connectionCtx
@@ -950,7 +952,7 @@ var EdgeFeedReplicator = class extends Resource {
950
952
  }
951
953
  async _sendMessage(message) {
952
954
  if (!this._connectionCtx) {
953
- log3.info("message dropped because connection was disposed", void 0, {
955
+ log3("message dropped because connection was disposed", void 0, {
954
956
  F: __dxlog_file5,
955
957
  L: 146,
956
958
  S: this,
@@ -958,21 +960,20 @@ var EdgeFeedReplicator = class extends Resource {
958
960
  });
959
961
  return;
960
962
  }
961
- const logPayload = message.type === "data" ? {
962
- feedKey: message.feedKey,
963
- blocks: message.blocks.map((b) => b.index)
964
- } : {
965
- message
966
- };
967
- log3.info("sending message", logPayload, {
968
- F: __dxlog_file5,
969
- L: 152,
970
- S: this,
971
- C: (f, a) => f(...a)
972
- });
963
+ if (message.type === "data") {
964
+ log3("sending blocks", {
965
+ feedKey: message.feedKey,
966
+ blocks: message.blocks.map((b) => b.index)
967
+ }, {
968
+ F: __dxlog_file5,
969
+ L: 151,
970
+ S: this,
971
+ C: (f, a) => f(...a)
972
+ });
973
+ }
973
974
  invariant2(message.feedKey, void 0, {
974
975
  F: __dxlog_file5,
975
- L: 154,
976
+ L: 157,
976
977
  S: this,
977
978
  A: [
978
979
  "message.feedKey",
@@ -984,7 +985,7 @@ var EdgeFeedReplicator = class extends Resource {
984
985
  type: message.type
985
986
  }, {
986
987
  F: __dxlog_file5,
987
- L: 157,
988
+ L: 160,
988
989
  S: this,
989
990
  C: (f, a) => f(...a)
990
991
  });
@@ -1003,7 +1004,7 @@ var EdgeFeedReplicator = class extends Resource {
1003
1004
  if (!this._connectionCtx) {
1004
1005
  log3.warn("received message after connection context was disposed", void 0, {
1005
1006
  F: __dxlog_file5,
1006
- L: 172,
1007
+ L: 175,
1007
1008
  S: this,
1008
1009
  C: (f, a) => f(...a)
1009
1010
  });
@@ -1014,14 +1015,6 @@ var EdgeFeedReplicator = class extends Resource {
1014
1015
  case "metadata": {
1015
1016
  try {
1016
1017
  var _usingCtx = _using_ctx();
1017
- log3.info("received metadata", {
1018
- message
1019
- }, {
1020
- F: __dxlog_file5,
1021
- L: 178,
1022
- S: this,
1023
- C: (f, a) => f(...a)
1024
- });
1025
1018
  const feedKey = PublicKey3.fromHex(message.feedKey);
1026
1019
  const feed = this._feeds.get(feedKey);
1027
1020
  if (!feed) {
@@ -1029,7 +1022,7 @@ var EdgeFeedReplicator = class extends Resource {
1029
1022
  feedKey
1030
1023
  }, {
1031
1024
  F: __dxlog_file5,
1032
- L: 183,
1025
+ L: 184,
1033
1026
  S: this,
1034
1027
  C: (f, a) => f(...a)
1035
1028
  });
@@ -1037,7 +1030,18 @@ var EdgeFeedReplicator = class extends Resource {
1037
1030
  }
1038
1031
  const _guard = _usingCtx.u(await this._getPushMutex(feed.key).acquire());
1039
1032
  this._remoteLength.set(feedKey, message.length);
1033
+ const logMeta = {
1034
+ localLength: feed.length,
1035
+ remoteLength: message.length,
1036
+ feedKey
1037
+ };
1040
1038
  if (message.length > feed.length) {
1039
+ log3("requesting missing blocks", logMeta, {
1040
+ F: __dxlog_file5,
1041
+ L: 194,
1042
+ S: this,
1043
+ C: (f, a) => f(...a)
1044
+ });
1041
1045
  await this._sendMessage({
1042
1046
  type: "request",
1043
1047
  feedKey: feedKey.toHex(),
@@ -1047,6 +1051,12 @@ var EdgeFeedReplicator = class extends Resource {
1047
1051
  }
1048
1052
  });
1049
1053
  } else if (message.length < feed.length) {
1054
+ log3("pushing blocks to remote", logMeta, {
1055
+ F: __dxlog_file5,
1056
+ L: 202,
1057
+ S: this,
1058
+ C: (f, a) => f(...a)
1059
+ });
1050
1060
  await this._pushBlocks(feed, message.length, feed.length);
1051
1061
  }
1052
1062
  break;
@@ -1057,12 +1067,12 @@ var EdgeFeedReplicator = class extends Resource {
1057
1067
  }
1058
1068
  }
1059
1069
  case "data": {
1060
- log3.info("received data", {
1070
+ log3("received data", {
1061
1071
  feed: message.feedKey,
1062
1072
  blocks: message.blocks.map((b) => b.index)
1063
1073
  }, {
1064
1074
  F: __dxlog_file5,
1065
- L: 205,
1075
+ L: 211,
1066
1076
  S: this,
1067
1077
  C: (f, a) => f(...a)
1068
1078
  });
@@ -1073,7 +1083,7 @@ var EdgeFeedReplicator = class extends Resource {
1073
1083
  feedKey
1074
1084
  }, {
1075
1085
  F: __dxlog_file5,
1076
- L: 210,
1086
+ L: 216,
1077
1087
  S: this,
1078
1088
  C: (f, a) => f(...a)
1079
1089
  });
@@ -1087,7 +1097,7 @@ var EdgeFeedReplicator = class extends Resource {
1087
1097
  ...message
1088
1098
  }, {
1089
1099
  F: __dxlog_file5,
1090
- L: 219,
1100
+ L: 225,
1091
1101
  S: this,
1092
1102
  C: (f, a) => f(...a)
1093
1103
  });
@@ -1096,13 +1106,13 @@ var EdgeFeedReplicator = class extends Resource {
1096
1106
  });
1097
1107
  }
1098
1108
  async _pushBlocks(feed, from, to) {
1099
- log3.info("pushing blocks", {
1109
+ log3("pushing blocks", {
1100
1110
  feed: feed.key.toHex(),
1101
1111
  from,
1102
1112
  to
1103
1113
  }, {
1104
1114
  F: __dxlog_file5,
1105
- L: 226,
1115
+ L: 232,
1106
1116
  S: this,
1107
1117
  C: (f, a) => f(...a)
1108
1118
  });
@@ -1112,7 +1122,7 @@ var EdgeFeedReplicator = class extends Resource {
1112
1122
  });
1113
1123
  invariant2(data instanceof Uint8Array, void 0, {
1114
1124
  F: __dxlog_file5,
1115
- L: 231,
1125
+ L: 237,
1116
1126
  S: this,
1117
1127
  A: [
1118
1128
  "data instanceof Uint8Array",
@@ -1135,12 +1145,12 @@ var EdgeFeedReplicator = class extends Resource {
1135
1145
  this._remoteLength.set(feed.key, to);
1136
1146
  }
1137
1147
  async _integrateBlocks(feed, blocks) {
1138
- log3.info("integrating blocks", {
1148
+ log3("integrating blocks", {
1139
1149
  feed: feed.key.toHex(),
1140
1150
  blocks: blocks.length
1141
1151
  }, {
1142
1152
  F: __dxlog_file5,
1143
- L: 252,
1153
+ L: 258,
1144
1154
  S: this,
1145
1155
  C: (f, a) => f(...a)
1146
1156
  });
@@ -1162,7 +1172,7 @@ var EdgeFeedReplicator = class extends Resource {
1162
1172
  if (!this._remoteLength.has(feed.key)) {
1163
1173
  log3("blocks not pushed because remote length is unknown", void 0, {
1164
1174
  F: __dxlog_file5,
1165
- L: 273,
1175
+ L: 279,
1166
1176
  S: this,
1167
1177
  C: (f, a) => f(...a)
1168
1178
  });
@@ -1187,7 +1197,7 @@ var EdgeFeedReplicator = class extends Resource {
1187
1197
  if (err instanceof EdgeIdentityChangedError || err instanceof EdgeConnectionClosedError) {
1188
1198
  log3("resetting on reconnect", void 0, {
1189
1199
  F: __dxlog_file5,
1190
- L: 290,
1200
+ L: 296,
1191
1201
  S: this,
1192
1202
  C: (f, a) => f(...a)
1193
1203
  });
@@ -1198,7 +1208,7 @@ var EdgeFeedReplicator = class extends Resource {
1198
1208
  }
1199
1209
  }, {
1200
1210
  F: __dxlog_file5,
1201
- L: 284
1211
+ L: 290
1202
1212
  });
1203
1213
  return connectionCtx;
1204
1214
  }
@@ -1365,6 +1375,7 @@ var NotarizationPlugin = class extends Resource3 {
1365
1375
  this._processedCredentials = new ComplexSet(PublicKey4.hash);
1366
1376
  this._processCredentialsTriggers = new ComplexMap3(PublicKey4.hash);
1367
1377
  this._activeEdgePollingIntervalHandle = void 0;
1378
+ this._activeEdgePollingEnabled = false;
1368
1379
  this._spaceId = params.spaceId;
1369
1380
  this._activeEdgePollingInterval = params.activeEdgePollingInterval ?? DEFAULT_ACTIVE_EDGE_POLLING_INTERVAL;
1370
1381
  if (params.edgeClient && params.edgeFeatures?.feedReplicator) {
@@ -1372,15 +1383,6 @@ var NotarizationPlugin = class extends Resource3 {
1372
1383
  }
1373
1384
  }
1374
1385
  setActiveEdgePollingEnabled(enabled) {
1375
- invariant4(this.isOpen, void 0, {
1376
- F: __dxlog_file7,
1377
- L: 109,
1378
- S: this,
1379
- A: [
1380
- "this.isOpen",
1381
- ""
1382
- ]
1383
- });
1384
1386
  const client = this._edgeClient;
1385
1387
  invariant4(client, void 0, {
1386
1388
  F: __dxlog_file7,
@@ -1391,30 +1393,30 @@ var NotarizationPlugin = class extends Resource3 {
1391
1393
  ""
1392
1394
  ]
1393
1395
  });
1394
- if (enabled && !this._activeEdgePollingIntervalHandle) {
1395
- this._activeEdgePollingIntervalHandle = setInterval(() => {
1396
- if (this._writer) {
1397
- this._notarizePendingEdgeCredentials(client, this._writer);
1398
- }
1399
- }, this._activeEdgePollingInterval);
1400
- } else if (!enabled && this._activeEdgePollingIntervalHandle) {
1401
- clearInterval(this._activeEdgePollingIntervalHandle);
1402
- this._activeEdgePollingIntervalHandle = void 0;
1396
+ this._activeEdgePollingEnabled = enabled;
1397
+ if (this.isOpen) {
1398
+ if (enabled && !this._activeEdgePollingIntervalHandle) {
1399
+ this._startPeriodicEdgePolling(client);
1400
+ } else if (!enabled && this._activeEdgePollingIntervalHandle) {
1401
+ this._stopPeriodicEdgePolling();
1402
+ }
1403
1403
  }
1404
1404
  }
1405
1405
  get hasWriter() {
1406
1406
  return !!this._writer;
1407
1407
  }
1408
1408
  async _open() {
1409
- if (this._edgeClient && this._writer) {
1410
- this._notarizePendingEdgeCredentials(this._edgeClient, this._writer);
1409
+ if (this._edgeClient) {
1410
+ if (this._activeEdgePollingEnabled) {
1411
+ this._startPeriodicEdgePolling(this._edgeClient);
1412
+ }
1413
+ if (this._writer) {
1414
+ this._notarizePendingEdgeCredentials(this._edgeClient, this._writer);
1415
+ }
1411
1416
  }
1412
1417
  }
1413
1418
  async _close() {
1414
- if (this._activeEdgePollingIntervalHandle) {
1415
- clearInterval(this._activeEdgePollingIntervalHandle);
1416
- this._activeEdgePollingIntervalHandle = void 0;
1417
- }
1419
+ this._stopPeriodicEdgePolling();
1418
1420
  await this._ctx.dispose();
1419
1421
  }
1420
1422
  /**
@@ -1592,10 +1594,23 @@ var NotarizationPlugin = class extends Resource3 {
1592
1594
  ]
1593
1595
  });
1594
1596
  this._writer = writer;
1595
- if (this._edgeClient) {
1597
+ if (this._edgeClient && this.isOpen) {
1596
1598
  this._notarizePendingEdgeCredentials(this._edgeClient, writer);
1597
1599
  }
1598
1600
  }
1601
+ _startPeriodicEdgePolling(client) {
1602
+ this._activeEdgePollingIntervalHandle = setInterval(() => {
1603
+ if (this._writer) {
1604
+ this._notarizePendingEdgeCredentials(client, this._writer);
1605
+ }
1606
+ }, this._activeEdgePollingInterval);
1607
+ }
1608
+ _stopPeriodicEdgePolling() {
1609
+ if (this._activeEdgePollingIntervalHandle) {
1610
+ clearInterval(this._activeEdgePollingIntervalHandle);
1611
+ this._activeEdgePollingIntervalHandle = void 0;
1612
+ }
1613
+ }
1599
1614
  /**
1600
1615
  * The method is used only for adding agent feeds to spaces.
1601
1616
  * When an agent is created we can admit them into all the existing spaces. In case the operation fails
@@ -1614,7 +1629,7 @@ var NotarizationPlugin = class extends Resource3 {
1614
1629
  if (!credentials.length) {
1615
1630
  log4("edge did not return credentials for notarization", void 0, {
1616
1631
  F: __dxlog_file7,
1617
- L: 296,
1632
+ L: 311,
1618
1633
  S: this,
1619
1634
  C: (f, a) => f(...a)
1620
1635
  });
@@ -1624,7 +1639,7 @@ var NotarizationPlugin = class extends Resource3 {
1624
1639
  count: credentials.length
1625
1640
  }, {
1626
1641
  F: __dxlog_file7,
1627
- L: 300,
1642
+ L: 315,
1628
1643
  S: this,
1629
1644
  C: (f, a) => f(...a)
1630
1645
  });
@@ -1637,7 +1652,7 @@ var NotarizationPlugin = class extends Resource3 {
1637
1652
  count: decodedCredentials.length
1638
1653
  }, {
1639
1654
  F: __dxlog_file7,
1640
- L: 309,
1655
+ L: 324,
1641
1656
  S: this,
1642
1657
  C: (f, a) => f(...a)
1643
1658
  });
@@ -1665,7 +1680,7 @@ var NotarizationPlugin = class extends Resource3 {
1665
1680
  for (const credential of credentials) {
1666
1681
  invariant4(credential.id, "Credential must have an id", {
1667
1682
  F: __dxlog_file7,
1668
- L: 335,
1683
+ L: 350,
1669
1684
  S: this,
1670
1685
  A: [
1671
1686
  "credential.id",
@@ -1689,7 +1704,7 @@ var NotarizationPlugin = class extends Resource3 {
1689
1704
  peer: extension.localPeerId
1690
1705
  }, {
1691
1706
  F: __dxlog_file7,
1692
- L: 350,
1707
+ L: 365,
1693
1708
  S: this,
1694
1709
  C: (f, a) => f(...a)
1695
1710
  });
@@ -1701,7 +1716,7 @@ var NotarizationPlugin = class extends Resource3 {
1701
1716
  peer: extension.localPeerId
1702
1717
  }, {
1703
1718
  F: __dxlog_file7,
1704
- L: 355,
1719
+ L: 370,
1705
1720
  S: this,
1706
1721
  C: (f, a) => f(...a)
1707
1722
  });
@@ -1718,7 +1733,7 @@ var NotarizationPlugin = class extends Resource3 {
1718
1733
  peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
1719
1734
  }, {
1720
1735
  F: __dxlog_file7,
1721
- L: 367,
1736
+ L: 382,
1722
1737
  S: this,
1723
1738
  C: (f, a) => f(...a)
1724
1739
  });
@@ -1734,7 +1749,7 @@ var handleEdgeError = (error) => {
1734
1749
  if (!(error instanceof EdgeCallFailedError) || error.errorData) {
1735
1750
  log4.catch(error, void 0, {
1736
1751
  F: __dxlog_file7,
1737
- L: 381,
1752
+ L: 396,
1738
1753
  S: void 0,
1739
1754
  C: (f, a) => f(...a)
1740
1755
  });
@@ -1743,7 +1758,7 @@ var handleEdgeError = (error) => {
1743
1758
  reason: error.reason
1744
1759
  }, {
1745
1760
  F: __dxlog_file7,
1746
- L: 383,
1761
+ L: 398,
1747
1762
  S: void 0,
1748
1763
  C: (f, a) => f(...a)
1749
1764
  });
@@ -2557,7 +2572,7 @@ var DataSpaceManager = class extends Resource4 {
2557
2572
  guestKeypair: invitation.guestKey ? {
2558
2573
  publicKey: invitation.guestKey
2559
2574
  } : void 0,
2560
- lifetime: invitation.expiresOn ? invitation.expiresOn.getTime() - Date.now() : void 0,
2575
+ lifetime: invitation.expiresOn ? (invitation.expiresOn.getTime() - Date.now()) / 1e3 : void 0,
2561
2576
  multiUse: invitation.multiUse,
2562
2577
  delegationCredentialId: credentialId,
2563
2578
  persistent: false
@@ -2584,8 +2599,8 @@ DataSpaceManager = _ts_decorate3([
2584
2599
 
2585
2600
  // packages/sdk/client-services/src/packlets/spaces/spaces-service.ts
2586
2601
  import { EventSubscriptions as EventSubscriptions2, UpdateScheduler, scheduleTask as scheduleTask3 } from "@dxos/async";
2587
- import { Stream as Stream7 } from "@dxos/codec-protobuf";
2588
- import { createAdmissionCredentials as createAdmissionCredentials2, getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
2602
+ import { Stream as Stream7 } from "@dxos/codec-protobuf/stream";
2603
+ import { createAdmissionCredentials as createAdmissionCredentials2, createDidFromIdentityKey as createDidFromIdentityKey2, getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
2589
2604
  import { raise } from "@dxos/debug";
2590
2605
  import { writeMessages as writeMessages2 } from "@dxos/feed-store";
2591
2606
  import { invariant as invariant6 } from "@dxos/invariant";
@@ -2641,7 +2656,7 @@ var SpacesServiceImpl = class {
2641
2656
  const credentials = await createAdmissionCredentials2(identity.getIdentityCredentialSigner(), request.memberKey, space.key, space.genesisFeedKey, request.newRole, space.spaceState.membershipChainHeads);
2642
2657
  invariant6(credentials[0].credential, void 0, {
2643
2658
  F: __dxlog_file10,
2644
- L: 106,
2659
+ L: 111,
2645
2660
  S: this,
2646
2661
  A: [
2647
2662
  "credentials[0].credential",
@@ -2651,7 +2666,7 @@ var SpacesServiceImpl = class {
2651
2666
  const spaceMemberCredential = credentials[0].credential.credential;
2652
2667
  invariant6(getCredentialAssertion3(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2653
2668
  F: __dxlog_file10,
2654
- L: 108,
2669
+ L: 113,
2655
2670
  S: this,
2656
2671
  A: [
2657
2672
  "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2664,12 +2679,12 @@ var SpacesServiceImpl = class {
2664
2679
  return new Stream7(({ next, ctx }) => {
2665
2680
  const scheduler = new UpdateScheduler(ctx, async () => {
2666
2681
  const dataSpaceManager = await this._getDataSpaceManager();
2667
- const spaces = Array.from(dataSpaceManager.spaces.values()).map((space) => this._serializeSpace(space));
2682
+ const spaces = await Promise.all(Array.from(dataSpaceManager.spaces.values()).map((space) => this._serializeSpace(space)));
2668
2683
  log7("update", () => ({
2669
2684
  ids: spaces.map((space) => space.id)
2670
2685
  }), {
2671
2686
  F: __dxlog_file10,
2672
- L: 119,
2687
+ L: 126,
2673
2688
  S: this,
2674
2689
  C: (f, a) => f(...a)
2675
2690
  });
@@ -2761,7 +2776,7 @@ var SpacesServiceImpl = class {
2761
2776
  } else {
2762
2777
  invariant6(!credential.id, "Id on unsigned credentials is not allowed", {
2763
2778
  F: __dxlog_file10,
2764
- L: 217,
2779
+ L: 224,
2765
2780
  S: this,
2766
2781
  A: [
2767
2782
  "!credential.id",
@@ -2770,7 +2785,7 @@ var SpacesServiceImpl = class {
2770
2785
  });
2771
2786
  invariant6(this._identityManager.identity, "Identity is not available", {
2772
2787
  F: __dxlog_file10,
2773
- L: 218,
2788
+ L: 225,
2774
2789
  S: this,
2775
2790
  A: [
2776
2791
  "this._identityManager.identity",
@@ -2780,7 +2795,7 @@ var SpacesServiceImpl = class {
2780
2795
  const signer = this._identityManager.identity.getIdentityCredentialSigner();
2781
2796
  invariant6(credential.issuer.equals(signer.getIssuer()), void 0, {
2782
2797
  F: __dxlog_file10,
2783
- L: 220,
2798
+ L: 227,
2784
2799
  S: this,
2785
2800
  A: [
2786
2801
  "credential.issuer.equals(signer.getIssuer())",
@@ -2830,7 +2845,7 @@ var SpacesServiceImpl = class {
2830
2845
  const assertion = getCredentialAssertion3(credential);
2831
2846
  invariant6(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
2832
2847
  F: __dxlog_file10,
2833
- L: 254,
2848
+ L: 261,
2834
2849
  S: this,
2835
2850
  A: [
2836
2851
  "assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2840,7 +2855,7 @@ var SpacesServiceImpl = class {
2840
2855
  const myIdentity = this._identityManager.identity;
2841
2856
  invariant6(myIdentity && credential.subject.id.equals(myIdentity.identityKey), void 0, {
2842
2857
  F: __dxlog_file10,
2843
- L: 256,
2858
+ L: 263,
2844
2859
  S: this,
2845
2860
  A: [
2846
2861
  "myIdentity && credential.subject.id.equals(myIdentity.identityKey)",
@@ -2861,10 +2876,10 @@ var SpacesServiceImpl = class {
2861
2876
  });
2862
2877
  }
2863
2878
  return {
2864
- space: this._serializeSpace(dataSpace)
2879
+ space: await this._serializeSpace(dataSpace)
2865
2880
  };
2866
2881
  }
2867
- _serializeSpace(space) {
2882
+ async _serializeSpace(space) {
2868
2883
  return {
2869
2884
  id: space.id,
2870
2885
  spaceKey: space.key,
@@ -2884,7 +2899,7 @@ var SpacesServiceImpl = class {
2884
2899
  totalDataTimeframe: void 0,
2885
2900
  spaceRootUrl: space.databaseRoot?.url
2886
2901
  },
2887
- members: Array.from(space.inner.spaceState.members.values()).map((member) => {
2902
+ members: await Promise.all(Array.from(space.inner.spaceState.members.values()).map(async (member) => {
2888
2903
  const peers = space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key));
2889
2904
  const isMe = this._identityManager.identity?.identityKey.equals(member.key);
2890
2905
  if (isMe) {
@@ -2892,6 +2907,7 @@ var SpacesServiceImpl = class {
2892
2907
  }
2893
2908
  return {
2894
2909
  identity: {
2910
+ did: await createDidFromIdentityKey2(member.key),
2895
2911
  identityKey: member.key,
2896
2912
  profile: member.profile ?? {}
2897
2913
  },
@@ -2899,7 +2915,7 @@ var SpacesServiceImpl = class {
2899
2915
  presence: peers.length > 0 ? SpaceMember4.PresenceState.ONLINE : SpaceMember4.PresenceState.OFFLINE,
2900
2916
  peerStates: peers
2901
2917
  };
2902
- }),
2918
+ })),
2903
2919
  creator: space.inner.spaceState.creator?.key,
2904
2920
  cache: space.cache,
2905
2921
  metrics: space.metrics,
@@ -2944,13 +2960,14 @@ var Identity = class {
2944
2960
  this.space = params.space;
2945
2961
  this._signer = params.signer;
2946
2962
  this._presence = params.presence;
2963
+ this.did = params.did;
2947
2964
  this.identityKey = params.identityKey;
2948
2965
  this.deviceKey = params.deviceKey;
2949
2966
  log8.trace("dxos.halo.device", {
2950
2967
  deviceKey: params.deviceKey
2951
2968
  }, {
2952
2969
  F: __dxlog_file11,
2953
- L: 79,
2970
+ L: 82,
2954
2971
  S: this,
2955
2972
  C: (f, a) => f(...a)
2956
2973
  });
@@ -3052,7 +3069,7 @@ var Identity = class {
3052
3069
  getIdentityCredentialSigner() {
3053
3070
  invariant7(this._deviceStateMachine.deviceCredentialChain, "Device credential chain is not ready.", {
3054
3071
  F: __dxlog_file11,
3055
- L: 195,
3072
+ L: 198,
3056
3073
  S: this,
3057
3074
  A: [
3058
3075
  "this._deviceStateMachine.deviceCredentialChain",
@@ -3096,7 +3113,7 @@ var Identity = class {
3096
3113
  dataFeedKey
3097
3114
  }, {
3098
3115
  F: __dxlog_file11,
3099
- L: 220,
3116
+ L: 223,
3100
3117
  S: this,
3101
3118
  C: (f, a) => f(...a)
3102
3119
  });
@@ -3153,7 +3170,7 @@ Identity = _ts_decorate4([
3153
3170
  import platform from "platform";
3154
3171
  import { Event as Event6 } from "@dxos/async";
3155
3172
  import { Context as Context4 } from "@dxos/context";
3156
- import { createCredentialSignerWithKey as createCredentialSignerWithKey2, CredentialGenerator, generateSeedPhrase, keyPairFromSeedPhrase } from "@dxos/credentials";
3173
+ import { createCredentialSignerWithKey as createCredentialSignerWithKey2, createDidFromIdentityKey as createDidFromIdentityKey3, CredentialGenerator } from "@dxos/credentials";
3157
3174
  import { invariant as invariant8 } from "@dxos/invariant";
3158
3175
  import { PublicKey as PublicKey7 } from "@dxos/keys";
3159
3176
  import { log as log9 } from "@dxos/log";
@@ -3195,7 +3212,7 @@ var IdentityManager = class {
3195
3212
  id: traceId
3196
3213
  }), {
3197
3214
  F: __dxlog_file12,
3198
- L: 121,
3215
+ L: 116,
3199
3216
  S: this,
3200
3217
  C: (f, a) => f(...a)
3201
3218
  });
@@ -3204,7 +3221,7 @@ var IdentityManager = class {
3204
3221
  identityRecord
3205
3222
  }, {
3206
3223
  F: __dxlog_file12,
3207
- L: 124,
3224
+ L: 119,
3208
3225
  S: this,
3209
3226
  C: (f, a) => f(...a)
3210
3227
  });
@@ -3217,7 +3234,7 @@ var IdentityManager = class {
3217
3234
  displayName: this._identity.profileDocument?.displayName
3218
3235
  }, {
3219
3236
  F: __dxlog_file12,
3220
- L: 129,
3237
+ L: 124,
3221
3238
  S: this,
3222
3239
  C: (f, a) => f(...a)
3223
3240
  });
@@ -3227,7 +3244,7 @@ var IdentityManager = class {
3227
3244
  id: traceId
3228
3245
  }), {
3229
3246
  F: __dxlog_file12,
3230
- L: 136,
3247
+ L: 131,
3231
3248
  S: this,
3232
3249
  C: (f, a) => f(...a)
3233
3250
  });
@@ -3235,13 +3252,13 @@ var IdentityManager = class {
3235
3252
  async close() {
3236
3253
  await this._identity?.close(new Context4(void 0, {
3237
3254
  F: __dxlog_file12,
3238
- L: 140
3255
+ L: 135
3239
3256
  }));
3240
3257
  }
3241
3258
  async createIdentity({ displayName, deviceProfile } = {}) {
3242
3259
  invariant8(!this._identity, "Identity already exists.", {
3243
3260
  F: __dxlog_file12,
3244
- L: 145,
3261
+ L: 140,
3245
3262
  S: this,
3246
3263
  A: [
3247
3264
  "!this._identity",
@@ -3250,7 +3267,7 @@ var IdentityManager = class {
3250
3267
  });
3251
3268
  log9("creating identity...", void 0, {
3252
3269
  F: __dxlog_file12,
3253
- L: 146,
3270
+ L: 141,
3254
3271
  S: this,
3255
3272
  C: (f, a) => f(...a)
3256
3273
  });
@@ -3268,13 +3285,13 @@ var IdentityManager = class {
3268
3285
  const identity = await this._constructIdentity(identityRecord);
3269
3286
  await identity.open(new Context4(void 0, {
3270
3287
  F: __dxlog_file12,
3271
- L: 161
3288
+ L: 156
3272
3289
  }));
3273
3290
  {
3274
3291
  const generator = new CredentialGenerator(this._keyring, identityRecord.identityKey, identityRecord.deviceKey);
3275
3292
  invariant8(identityRecord.haloSpace.genesisFeedKey, "Genesis feed key is required.", {
3276
3293
  F: __dxlog_file12,
3277
- L: 165,
3294
+ L: 160,
3278
3295
  S: this,
3279
3296
  A: [
3280
3297
  "identityRecord.haloSpace.genesisFeedKey",
@@ -3283,7 +3300,7 @@ var IdentityManager = class {
3283
3300
  });
3284
3301
  invariant8(identityRecord.haloSpace.dataFeedKey, "Data feed key is required.", {
3285
3302
  F: __dxlog_file12,
3286
- L: 166,
3303
+ L: 161,
3287
3304
  S: this,
3288
3305
  A: [
3289
3306
  "identityRecord.haloSpace.dataFeedKey",
@@ -3322,7 +3339,7 @@ var IdentityManager = class {
3322
3339
  displayName: this._identity.profileDocument?.displayName
3323
3340
  }, {
3324
3341
  F: __dxlog_file12,
3325
- L: 204,
3342
+ L: 199,
3326
3343
  S: this,
3327
3344
  C: (f, a) => f(...a)
3328
3345
  });
@@ -3333,7 +3350,7 @@ var IdentityManager = class {
3333
3350
  profile: identity.profileDocument
3334
3351
  }, {
3335
3352
  F: __dxlog_file12,
3336
- L: 210,
3353
+ L: 205,
3337
3354
  S: this,
3338
3355
  C: (f, a) => f(...a)
3339
3356
  });
@@ -3370,13 +3387,13 @@ var IdentityManager = class {
3370
3387
  params
3371
3388
  }, {
3372
3389
  F: __dxlog_file12,
3373
- L: 249,
3390
+ L: 244,
3374
3391
  S: this,
3375
3392
  C: (f, a) => f(...a)
3376
3393
  });
3377
3394
  invariant8(!this._identity, "Identity already exists.", {
3378
3395
  F: __dxlog_file12,
3379
- L: 250,
3396
+ L: 245,
3380
3397
  S: this,
3381
3398
  A: [
3382
3399
  "!this._identity",
@@ -3397,7 +3414,7 @@ var IdentityManager = class {
3397
3414
  const identity = await this._constructIdentity(identityRecord);
3398
3415
  await identity.open(new Context4(void 0, {
3399
3416
  F: __dxlog_file12,
3400
- L: 264
3417
+ L: 259
3401
3418
  }));
3402
3419
  return {
3403
3420
  identity,
@@ -3416,7 +3433,7 @@ var IdentityManager = class {
3416
3433
  displayName: this._identity.profileDocument?.displayName
3417
3434
  }, {
3418
3435
  F: __dxlog_file12,
3419
- L: 278,
3436
+ L: 273,
3420
3437
  S: this,
3421
3438
  C: (f, a) => f(...a)
3422
3439
  });
@@ -3430,7 +3447,7 @@ var IdentityManager = class {
3430
3447
  deviceKey: identity.deviceKey
3431
3448
  }, {
3432
3449
  F: __dxlog_file12,
3433
- L: 289,
3450
+ L: 284,
3434
3451
  S: this,
3435
3452
  C: (f, a) => f(...a)
3436
3453
  });
@@ -3441,7 +3458,7 @@ var IdentityManager = class {
3441
3458
  async updateProfile(profile) {
3442
3459
  invariant8(this._identity, "Identity not initialized.", {
3443
3460
  F: __dxlog_file12,
3444
- L: 296,
3461
+ L: 291,
3445
3462
  S: this,
3446
3463
  A: [
3447
3464
  "this._identity",
@@ -3472,7 +3489,7 @@ var IdentityManager = class {
3472
3489
  async updateDeviceProfile(profile) {
3473
3490
  invariant8(this._identity, "Identity not initialized.", {
3474
3491
  F: __dxlog_file12,
3475
- L: 313,
3492
+ L: 308,
3476
3493
  S: this,
3477
3494
  A: [
3478
3495
  "this._identity",
@@ -3505,48 +3522,10 @@ var IdentityManager = class {
3505
3522
  profile
3506
3523
  };
3507
3524
  }
3508
- async createRecoveryPhrase() {
3509
- const identity = this._identity;
3510
- invariant8(identity, void 0, {
3511
- F: __dxlog_file12,
3512
- L: 340,
3513
- S: this,
3514
- A: [
3515
- "identity",
3516
- ""
3517
- ]
3518
- });
3519
- const seedphrase = generateSeedPhrase();
3520
- const keypair = keyPairFromSeedPhrase(seedphrase);
3521
- const recoveryKey = PublicKey7.from(keypair.publicKey);
3522
- const identityKey = identity.identityKey;
3523
- const credential = await identity.getIdentityCredentialSigner().createCredential({
3524
- subject: identityKey,
3525
- assertion: {
3526
- "@type": "dxos.halo.credentials.IdentityRecovery",
3527
- recoveryKey,
3528
- identityKey
3529
- }
3530
- });
3531
- const receipt = await identity.controlPipeline.writer.write({
3532
- credential: {
3533
- credential
3534
- }
3535
- });
3536
- await identity.controlPipeline.state.waitUntilTimeframe(new Timeframe3([
3537
- [
3538
- receipt.feedKey,
3539
- receipt.seq
3540
- ]
3541
- ]));
3542
- return {
3543
- seedphrase
3544
- };
3545
- }
3546
3525
  async _constructIdentity(identityRecord) {
3547
3526
  invariant8(!this._identity, void 0, {
3548
3527
  F: __dxlog_file12,
3549
- L: 362,
3528
+ L: 334,
3550
3529
  S: this,
3551
3530
  A: [
3552
3531
  "!this._identity",
@@ -3557,7 +3536,7 @@ var IdentityManager = class {
3557
3536
  identityRecord
3558
3537
  }, {
3559
3538
  F: __dxlog_file12,
3560
- L: 363,
3539
+ L: 335,
3561
3540
  S: this,
3562
3541
  C: (f, a) => f(...a)
3563
3542
  });
@@ -3572,7 +3551,7 @@ var IdentityManager = class {
3572
3551
  });
3573
3552
  invariant8(identityRecord.haloSpace.controlFeedKey, void 0, {
3574
3553
  F: __dxlog_file12,
3575
- L: 376,
3554
+ L: 348,
3576
3555
  S: this,
3577
3556
  A: [
3578
3557
  "identityRecord.haloSpace.controlFeedKey",
@@ -3584,7 +3563,7 @@ var IdentityManager = class {
3584
3563
  });
3585
3564
  invariant8(identityRecord.haloSpace.dataFeedKey, void 0, {
3586
3565
  F: __dxlog_file12,
3587
- L: 380,
3566
+ L: 352,
3588
3567
  S: this,
3589
3568
  A: [
3590
3569
  "identityRecord.haloSpace.dataFeedKey",
@@ -3608,10 +3587,12 @@ var IdentityManager = class {
3608
3587
  });
3609
3588
  await space.setControlFeed(controlFeed);
3610
3589
  await space.setDataFeed(dataFeed);
3590
+ const did = await createDidFromIdentityKey3(identityRecord.identityKey);
3611
3591
  const identity = new Identity({
3612
3592
  space,
3613
3593
  presence,
3614
3594
  signer: this._keyring,
3595
+ did,
3615
3596
  identityKey: identityRecord.identityKey,
3616
3597
  deviceKey: identityRecord.deviceKey,
3617
3598
  edgeConnection: this._edgeConnection,
@@ -3621,7 +3602,7 @@ var IdentityManager = class {
3621
3602
  identityKey: identityRecord.identityKey
3622
3603
  }, {
3623
3604
  F: __dxlog_file12,
3624
- L: 409,
3605
+ L: 383,
3625
3606
  S: this,
3626
3607
  C: (f, a) => f(...a)
3627
3608
  });
@@ -3646,7 +3627,7 @@ var IdentityManager = class {
3646
3627
  onAuthFailure: () => {
3647
3628
  log9.warn("auth failure", void 0, {
3648
3629
  F: __dxlog_file12,
3649
- L: 434,
3630
+ L: 408,
3650
3631
  S: this,
3651
3632
  C: (f, a) => f(...a)
3652
3633
  });
@@ -3670,7 +3651,7 @@ IdentityManager = _ts_decorate5([
3670
3651
 
3671
3652
  // packages/sdk/client-services/src/packlets/identity/identity-service.ts
3672
3653
  import { Trigger as Trigger3, sleep as sleep2 } from "@dxos/async";
3673
- import { Stream as Stream8 } from "@dxos/codec-protobuf";
3654
+ import { Stream as Stream8 } from "@dxos/codec-protobuf/stream";
3674
3655
  import { Resource as Resource5 } from "@dxos/context";
3675
3656
  import { createCredential as createCredential2, signPresentation } from "@dxos/credentials";
3676
3657
  import { invariant as invariant9 } from "@dxos/invariant";
@@ -3709,7 +3690,7 @@ var IdentityServiceImpl = class extends Resource5 {
3709
3690
  const identity = this._identityManager.identity;
3710
3691
  invariant9(identity, void 0, {
3711
3692
  F: __dxlog_file13,
3712
- L: 60,
3693
+ L: 61,
3713
3694
  S: this,
3714
3695
  A: [
3715
3696
  "identity",
@@ -3732,6 +3713,7 @@ var IdentityServiceImpl = class extends Resource5 {
3732
3713
  return void 0;
3733
3714
  }
3734
3715
  return {
3716
+ did: this._identityManager.identity.did,
3735
3717
  identityKey: this._identityManager.identity.identityKey,
3736
3718
  spaceKey: this._identityManager.identity.space.key,
3737
3719
  profile: this._identityManager.identity.profileDocument
@@ -3740,7 +3722,7 @@ var IdentityServiceImpl = class extends Resource5 {
3740
3722
  async updateProfile(profile) {
3741
3723
  invariant9(this._identityManager.identity, "Identity not initialized.", {
3742
3724
  F: __dxlog_file13,
3743
- L: 86,
3725
+ L: 88,
3744
3726
  S: this,
3745
3727
  A: [
3746
3728
  "this._identityManager.identity",
@@ -3751,18 +3733,29 @@ var IdentityServiceImpl = class extends Resource5 {
3751
3733
  await this._onProfileUpdate?.(this._identityManager.identity.profileDocument);
3752
3734
  return this._getIdentity();
3753
3735
  }
3754
- async createRecoveryPhrase() {
3755
- return this._recoveryManager.createRecoveryPhrase();
3736
+ async createRecoveryCredential(request) {
3737
+ return this._recoveryManager.createRecoveryCredential(request);
3738
+ }
3739
+ async requestRecoveryChallenge() {
3740
+ return this._recoveryManager.requestRecoveryChallenge();
3756
3741
  }
3757
3742
  async recoverIdentity(request) {
3758
- await this._recoveryManager.recoverIdentity(request);
3743
+ if (request.recoveryCode) {
3744
+ await this._recoveryManager.recoverIdentity({
3745
+ recoveryCode: request.recoveryCode
3746
+ });
3747
+ } else if (request.external) {
3748
+ await this._recoveryManager.recoverIdentityWithExternalSignature(request.external);
3749
+ } else {
3750
+ throw new Error("Invalid request.");
3751
+ }
3759
3752
  return this._getIdentity();
3760
3753
  }
3761
3754
  // TODO(burdon): Rename createPresentation?
3762
3755
  async signPresentation({ presentation, nonce }) {
3763
3756
  invariant9(this._identityManager.identity, "Identity not initialized.", {
3764
3757
  F: __dxlog_file13,
3765
- L: 103,
3758
+ L: 116,
3766
3759
  S: this,
3767
3760
  A: [
3768
3761
  "this._identityManager.identity",
@@ -3781,7 +3774,7 @@ var IdentityServiceImpl = class extends Resource5 {
3781
3774
  const identity = this._identityManager.identity;
3782
3775
  invariant9(identity, "Identity not initialized.", {
3783
3776
  F: __dxlog_file13,
3784
- L: 117,
3777
+ L: 130,
3785
3778
  S: this,
3786
3779
  A: [
3787
3780
  "identity",
@@ -3819,7 +3812,7 @@ var IdentityServiceImpl = class extends Resource5 {
3819
3812
  duplicate: space.id
3820
3813
  }, {
3821
3814
  F: __dxlog_file13,
3822
- L: 151,
3815
+ L: 164,
3823
3816
  S: this,
3824
3817
  C: (f, a) => f(...a)
3825
3818
  });
@@ -3833,7 +3826,7 @@ var IdentityServiceImpl = class extends Resource5 {
3833
3826
  }, (err) => {
3834
3827
  log10.catch(err, void 0, {
3835
3828
  F: __dxlog_file13,
3836
- L: 162,
3829
+ L: 175,
3837
3830
  S: this,
3838
3831
  C: (f, a) => f(...a)
3839
3832
  });
@@ -4614,14 +4607,14 @@ var DeviceInvitationProtocol = class {
4614
4607
 
4615
4608
  // packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
4616
4609
  import { scheduleTask as scheduleTask7, TimeoutError as TimeoutError2 } from "@dxos/async";
4617
- import { INVITATION_TIMEOUT } from "@dxos/client-protocol";
4610
+ import { INVITATION_TIMEOUT, getExpirationTime } from "@dxos/client-protocol";
4618
4611
  import { ContextDisposedError as ContextDisposedError3 } from "@dxos/context";
4619
4612
  import { createKeyPair, sign as sign2 } from "@dxos/crypto";
4620
4613
  import { invariant as invariant15 } from "@dxos/invariant";
4621
4614
  import { PublicKey as PublicKey11 } from "@dxos/keys";
4622
4615
  import { log as log17 } from "@dxos/log";
4623
4616
  import { createTeleportProtocolFactory } from "@dxos/network-manager";
4624
- import { InvalidInvitationExtensionRoleError as InvalidInvitationExtensionRoleError3, trace as trace7 } from "@dxos/protocols";
4617
+ import { InvalidInvitationError, InvalidInvitationExtensionRoleError as InvalidInvitationExtensionRoleError3, trace as trace7 } from "@dxos/protocols";
4625
4618
  import { Invitation as Invitation7 } from "@dxos/protocols/proto/dxos/client/services";
4626
4619
  import { AuthenticationResponse as AuthenticationResponse2 } from "@dxos/protocols/proto/dxos/halo/invitations";
4627
4620
  import { InvitationOptions as InvitationOptions4 } from "@dxos/protocols/proto/dxos/halo/invitations";
@@ -4644,6 +4637,12 @@ import { Invitation as Invitation3 } from "@dxos/protocols/proto/dxos/client/ser
4644
4637
  var stateToString = (state) => {
4645
4638
  return Object.entries(Invitation3.State).find(([key, val]) => val === state)?.[0] ?? "unknown";
4646
4639
  };
4640
+ var computeExpirationTime = (invitation) => {
4641
+ if (!invitation.lifetime) {
4642
+ return;
4643
+ }
4644
+ return new Date((invitation.created?.getTime() ?? Date.now()) + invitation.lifetime * 1e3);
4645
+ };
4647
4646
  var tryAcquireBeforeContextDisposed = async (ctx, mutex) => {
4648
4647
  let guard;
4649
4648
  return cancelWithContext3(ctx, (async () => {
@@ -5659,18 +5658,19 @@ var InvitationsHandler = class {
5659
5658
  });
5660
5659
  return extension;
5661
5660
  };
5662
- if (invitation.lifetime && invitation.created) {
5663
- if (invitation.created.getTime() + invitation.lifetime * 1e3 < Date.now()) {
5661
+ const expiresOn = getExpirationTime(invitation);
5662
+ if (expiresOn) {
5663
+ if (expiresOn.getTime() < Date.now()) {
5664
5664
  log17.warn("invitation has already expired", void 0, {
5665
5665
  F: __dxlog_file21,
5666
- L: 193,
5666
+ L: 194,
5667
5667
  S: this,
5668
5668
  C: (f, a) => f(...a)
5669
5669
  });
5670
5670
  guardedState.set(null, Invitation7.State.EXPIRED);
5671
5671
  void ctx.dispose().catch((err) => log17.catch(err, void 0, {
5672
5672
  F: __dxlog_file21,
5673
- L: 195,
5673
+ L: 196,
5674
5674
  S: this,
5675
5675
  C: (f, a) => f(...a)
5676
5676
  }));
@@ -5681,7 +5681,7 @@ var InvitationsHandler = class {
5681
5681
  guardedState.set(null, Invitation7.State.EXPIRED);
5682
5682
  metrics.increment("dxos.invitation.expired");
5683
5683
  await ctx.dispose();
5684
- }, invitation.created.getTime() + invitation.lifetime * 1e3 - Date.now());
5684
+ }, expiresOn.getTime() - Date.now());
5685
5685
  }
5686
5686
  let swarmConnection;
5687
5687
  scheduleTask7(ctx, async () => {
@@ -5697,7 +5697,7 @@ var InvitationsHandler = class {
5697
5697
  type: invitation.type
5698
5698
  }, {
5699
5699
  F: __dxlog_file21,
5700
- L: 226,
5700
+ L: 227,
5701
5701
  S: this,
5702
5702
  C: (f, a) => f(...a)
5703
5703
  });
@@ -5705,7 +5705,7 @@ var InvitationsHandler = class {
5705
5705
  if (deviceProfile) {
5706
5706
  invariant15(invitation.kind === Invitation7.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
5707
5707
  F: __dxlog_file21,
5708
- L: 235,
5708
+ L: 236,
5709
5709
  S: this,
5710
5710
  A: [
5711
5711
  "invitation.kind === Invitation.Kind.DEVICE",
@@ -5723,7 +5723,7 @@ var InvitationsHandler = class {
5723
5723
  triedPeers: triedPeersIds.size
5724
5724
  }, {
5725
5725
  F: __dxlog_file21,
5726
- L: 243,
5726
+ L: 244,
5727
5727
  S: this,
5728
5728
  C: (f, a) => f(...a)
5729
5729
  });
@@ -5750,7 +5750,7 @@ var InvitationsHandler = class {
5750
5750
  currentState: guardedState.current.state
5751
5751
  }, {
5752
5752
  F: __dxlog_file21,
5753
- L: 271,
5753
+ L: 272,
5754
5754
  S: this,
5755
5755
  C: (f, a) => f(...a)
5756
5756
  });
@@ -5768,7 +5768,7 @@ var InvitationsHandler = class {
5768
5768
  id: traceId
5769
5769
  }), {
5770
5770
  F: __dxlog_file21,
5771
- L: 283,
5771
+ L: 284,
5772
5772
  S: this,
5773
5773
  C: (f, a) => f(...a)
5774
5774
  });
@@ -5780,7 +5780,7 @@ var InvitationsHandler = class {
5780
5780
  ...protocol.toJSON()
5781
5781
  }, {
5782
5782
  F: __dxlog_file21,
5783
- L: 294,
5783
+ L: 295,
5784
5784
  S: this,
5785
5785
  C: (f, a) => f(...a)
5786
5786
  });
@@ -5790,7 +5790,7 @@ var InvitationsHandler = class {
5790
5790
  ...protocol.toJSON()
5791
5791
  }, {
5792
5792
  F: __dxlog_file21,
5793
- L: 298,
5793
+ L: 299,
5794
5794
  S: this,
5795
5795
  C: (f, a) => f(...a)
5796
5796
  });
@@ -5804,7 +5804,7 @@ var InvitationsHandler = class {
5804
5804
  authMethod: introductionResponse.authMethod
5805
5805
  }, {
5806
5806
  F: __dxlog_file21,
5807
- L: 306,
5807
+ L: 307,
5808
5808
  S: this,
5809
5809
  C: (f, a) => f(...a)
5810
5810
  });
@@ -5826,7 +5826,7 @@ var InvitationsHandler = class {
5826
5826
  ...protocol.toJSON()
5827
5827
  }, {
5828
5828
  F: __dxlog_file21,
5829
- L: 336,
5829
+ L: 337,
5830
5830
  S: this,
5831
5831
  C: (f, a) => f(...a)
5832
5832
  });
@@ -5839,7 +5839,7 @@ var InvitationsHandler = class {
5839
5839
  ...protocol.toJSON()
5840
5840
  }, {
5841
5841
  F: __dxlog_file21,
5842
- L: 350,
5842
+ L: 351,
5843
5843
  S: this,
5844
5844
  C: (f, a) => f(...a)
5845
5845
  });
@@ -5852,7 +5852,7 @@ var InvitationsHandler = class {
5852
5852
  id: traceId
5853
5853
  }), {
5854
5854
  F: __dxlog_file21,
5855
- L: 359,
5855
+ L: 360,
5856
5856
  S: this,
5857
5857
  C: (f, a) => f(...a)
5858
5858
  });
@@ -5862,7 +5862,7 @@ var InvitationsHandler = class {
5862
5862
  ...protocol.toJSON()
5863
5863
  }, {
5864
5864
  F: __dxlog_file21,
5865
- L: 362,
5865
+ L: 363,
5866
5866
  S: this,
5867
5867
  C: (f, a) => f(...a)
5868
5868
  });
@@ -5870,7 +5870,7 @@ var InvitationsHandler = class {
5870
5870
  } else {
5871
5871
  log17.verbose("auth failed", err, {
5872
5872
  F: __dxlog_file21,
5873
- L: 365,
5873
+ L: 366,
5874
5874
  S: this,
5875
5875
  C: (f, a) => f(...a)
5876
5876
  });
@@ -5882,7 +5882,7 @@ var InvitationsHandler = class {
5882
5882
  error: err
5883
5883
  }), {
5884
5884
  F: __dxlog_file21,
5885
- L: 369,
5885
+ L: 370,
5886
5886
  S: this,
5887
5887
  C: (f, a) => f(...a)
5888
5888
  });
@@ -5898,7 +5898,7 @@ var InvitationsHandler = class {
5898
5898
  ...protocol.toJSON()
5899
5899
  }, {
5900
5900
  F: __dxlog_file21,
5901
- L: 378,
5901
+ L: 379,
5902
5902
  S: this,
5903
5903
  C: (f, a) => f(...a)
5904
5904
  });
@@ -5906,7 +5906,7 @@ var InvitationsHandler = class {
5906
5906
  } else {
5907
5907
  log17.verbose("auth failed", err, {
5908
5908
  F: __dxlog_file21,
5909
- L: 381,
5909
+ L: 382,
5910
5910
  S: this,
5911
5911
  C: (f, a) => f(...a)
5912
5912
  });
@@ -5923,7 +5923,7 @@ var InvitationsHandler = class {
5923
5923
  ...protocol.toJSON()
5924
5924
  }, {
5925
5925
  F: __dxlog_file21,
5926
- L: 393,
5926
+ L: 394,
5927
5927
  S: this,
5928
5928
  C: (f, a) => f(...a)
5929
5929
  });
@@ -5936,14 +5936,14 @@ var InvitationsHandler = class {
5936
5936
  });
5937
5937
  edgeInvitationHandler.handle(ctx, guardedState, protocol, deviceProfile);
5938
5938
  scheduleTask7(ctx, async () => {
5939
- const error = protocol.checkInvitation(invitation);
5939
+ const error = checkInvitation(protocol, invitation);
5940
5940
  if (error) {
5941
5941
  stream.error(error);
5942
5942
  await ctx.dispose();
5943
5943
  } else {
5944
5944
  invariant15(invitation.swarmKey, void 0, {
5945
5945
  F: __dxlog_file21,
5946
- L: 405,
5946
+ L: 406,
5947
5947
  S: this,
5948
5948
  A: [
5949
5949
  "invitation.swarmKey",
@@ -5987,7 +5987,7 @@ var InvitationsHandler = class {
5987
5987
  for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
5988
5988
  log17("guest waiting for authentication code...", void 0, {
5989
5989
  F: __dxlog_file21,
5990
- L: 457,
5990
+ L: 458,
5991
5991
  S: this,
5992
5992
  C: (f, a) => f(...a)
5993
5993
  });
@@ -5995,7 +5995,7 @@ var InvitationsHandler = class {
5995
5995
  const authCode = await authenticated.wait(options);
5996
5996
  log17("sending authentication request", void 0, {
5997
5997
  F: __dxlog_file21,
5998
- L: 461,
5998
+ L: 462,
5999
5999
  S: this,
6000
6000
  C: (f, a) => f(...a)
6001
6001
  });
@@ -6014,7 +6014,7 @@ var InvitationsHandler = class {
6014
6014
  attempt
6015
6015
  }, {
6016
6016
  F: __dxlog_file21,
6017
- L: 472,
6017
+ L: 473,
6018
6018
  S: this,
6019
6019
  C: (f, a) => f(...a)
6020
6020
  });
@@ -6032,7 +6032,7 @@ var InvitationsHandler = class {
6032
6032
  }
6033
6033
  log17("sending authentication request", void 0, {
6034
6034
  F: __dxlog_file21,
6035
- L: 491,
6035
+ L: 492,
6036
6036
  S: this,
6037
6037
  C: (f, a) => f(...a)
6038
6038
  });
@@ -6045,6 +6045,13 @@ var InvitationsHandler = class {
6045
6045
  }
6046
6046
  }
6047
6047
  };
6048
+ var checkInvitation = (protocol, invitation) => {
6049
+ const expiresOn = getExpirationTime(invitation);
6050
+ if (expiresOn && expiresOn.getTime() < Date.now()) {
6051
+ return new InvalidInvitationError("Invitation already expired.");
6052
+ }
6053
+ return protocol.checkInvitation(invitation);
6054
+ };
6048
6055
  var createAdmissionKeypair = () => {
6049
6056
  const keypair = createKeyPair();
6050
6057
  return {
@@ -6054,7 +6061,7 @@ var createAdmissionKeypair = () => {
6054
6061
  };
6055
6062
 
6056
6063
  // packages/sdk/client-services/src/packlets/invitations/invitations-service.ts
6057
- import { Stream as Stream9 } from "@dxos/codec-protobuf";
6064
+ import { Stream as Stream9 } from "@dxos/codec-protobuf/stream";
6058
6065
  import { QueryInvitationsResponse } from "@dxos/protocols/proto/dxos/client/services";
6059
6066
  import { trace as trace8 } from "@dxos/tracing";
6060
6067
  var InvitationsServiceImpl = class {
@@ -6159,7 +6166,7 @@ import { createCancelDelegatedSpaceInvitationCredential, createDelegatedSpaceInv
6159
6166
  import { writeMessages as writeMessages4 } from "@dxos/feed-store";
6160
6167
  import { invariant as invariant16 } from "@dxos/invariant";
6161
6168
  import { log as log18 } from "@dxos/log";
6162
- import { AlreadyJoinedError as AlreadyJoinedError3, AuthorizationError as AuthorizationError2, InvalidInvitationError, SpaceNotFoundError as SpaceNotFoundError2 } from "@dxos/protocols";
6169
+ import { AlreadyJoinedError as AlreadyJoinedError3, AuthorizationError as AuthorizationError2, InvalidInvitationError as InvalidInvitationError2, SpaceNotFoundError as SpaceNotFoundError2 } from "@dxos/protocols";
6163
6170
  import { Invitation as Invitation8 } from "@dxos/protocols/proto/dxos/client/services";
6164
6171
  import { SpaceMember as SpaceMember6 } from "@dxos/protocols/proto/dxos/halo/credentials";
6165
6172
  var __dxlog_file22 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
@@ -6179,7 +6186,7 @@ var SpaceInvitationProtocol = class {
6179
6186
  }
6180
6187
  checkCanInviteNewMembers() {
6181
6188
  if (this._spaceKey == null) {
6182
- return new InvalidInvitationError("No spaceKey was provided for a space invitation.");
6189
+ return new InvalidInvitationError2("No spaceKey was provided for a space invitation.");
6183
6190
  }
6184
6191
  const space = this._spaceManager.spaces.get(this._spaceKey);
6185
6192
  if (space == null) {
@@ -6193,7 +6200,7 @@ var SpaceInvitationProtocol = class {
6193
6200
  getInvitationContext() {
6194
6201
  invariant16(this._spaceKey, void 0, {
6195
6202
  F: __dxlog_file22,
6196
- L: 64,
6203
+ L: 65,
6197
6204
  S: this,
6198
6205
  A: [
6199
6206
  "this._spaceKey",
@@ -6203,7 +6210,7 @@ var SpaceInvitationProtocol = class {
6203
6210
  const space = this._spaceManager.spaces.get(this._spaceKey);
6204
6211
  invariant16(space, void 0, {
6205
6212
  F: __dxlog_file22,
6206
- L: 66,
6213
+ L: 67,
6207
6214
  S: this,
6208
6215
  A: [
6209
6216
  "space",
@@ -6219,7 +6226,7 @@ var SpaceInvitationProtocol = class {
6219
6226
  async admit(invitation, request, guestProfile) {
6220
6227
  invariant16(this._spaceKey && request.space, void 0, {
6221
6228
  F: __dxlog_file22,
6222
- L: 79,
6229
+ L: 80,
6223
6230
  S: this,
6224
6231
  A: [
6225
6232
  "this._spaceKey && request.space",
@@ -6231,7 +6238,7 @@ var SpaceInvitationProtocol = class {
6231
6238
  guest: request.space.deviceKey
6232
6239
  }, {
6233
6240
  F: __dxlog_file22,
6234
- L: 80,
6241
+ L: 81,
6235
6242
  S: this,
6236
6243
  C: (f, a) => f(...a)
6237
6244
  });
@@ -6253,7 +6260,7 @@ var SpaceInvitationProtocol = class {
6253
6260
  async delegate(invitation) {
6254
6261
  invariant16(this._spaceKey, void 0, {
6255
6262
  F: __dxlog_file22,
6256
- L: 100,
6263
+ L: 101,
6257
6264
  S: this,
6258
6265
  A: [
6259
6266
  "this._spaceKey",
@@ -6263,7 +6270,7 @@ var SpaceInvitationProtocol = class {
6263
6270
  const space = this._spaceManager.spaces.get(this._spaceKey);
6264
6271
  invariant16(space, void 0, {
6265
6272
  F: __dxlog_file22,
6266
- L: 102,
6273
+ L: 103,
6267
6274
  S: this,
6268
6275
  A: [
6269
6276
  "space",
@@ -6273,7 +6280,7 @@ var SpaceInvitationProtocol = class {
6273
6280
  if (invitation.authMethod === Invitation8.AuthMethod.KNOWN_PUBLIC_KEY) {
6274
6281
  invariant16(invitation.guestKeypair?.publicKey, void 0, {
6275
6282
  F: __dxlog_file22,
6276
- L: 104,
6283
+ L: 105,
6277
6284
  S: this,
6278
6285
  A: [
6279
6286
  "invitation.guestKeypair?.publicKey",
@@ -6286,7 +6293,7 @@ var SpaceInvitationProtocol = class {
6286
6293
  id: invitation.invitationId
6287
6294
  }, {
6288
6295
  F: __dxlog_file22,
6289
- L: 107,
6296
+ L: 108,
6290
6297
  S: this,
6291
6298
  C: (f, a) => f(...a)
6292
6299
  });
@@ -6295,13 +6302,13 @@ var SpaceInvitationProtocol = class {
6295
6302
  authMethod: invitation.authMethod,
6296
6303
  swarmKey: invitation.swarmKey,
6297
6304
  role: invitation.role ?? SpaceMember6.Role.ADMIN,
6298
- expiresOn: invitation.lifetime ? new Date((invitation.created?.getTime() ?? Date.now()) + invitation.lifetime) : void 0,
6305
+ expiresOn: computeExpirationTime(invitation),
6299
6306
  multiUse: invitation.multiUse ?? false,
6300
6307
  guestKey: invitation.authMethod === Invitation8.AuthMethod.KNOWN_PUBLIC_KEY ? invitation.guestKeypair.publicKey : void 0
6301
6308
  });
6302
6309
  invariant16(credential.credential, void 0, {
6303
6310
  F: __dxlog_file22,
6304
- L: 127,
6311
+ L: 126,
6305
6312
  S: this,
6306
6313
  A: [
6307
6314
  "credential.credential",
@@ -6316,7 +6323,7 @@ var SpaceInvitationProtocol = class {
6316
6323
  async cancelDelegation(invitation) {
6317
6324
  invariant16(this._spaceKey, void 0, {
6318
6325
  F: __dxlog_file22,
6319
- L: 133,
6326
+ L: 132,
6320
6327
  S: this,
6321
6328
  A: [
6322
6329
  "this._spaceKey",
@@ -6325,7 +6332,7 @@ var SpaceInvitationProtocol = class {
6325
6332
  });
6326
6333
  invariant16(invitation.type === Invitation8.Type.DELEGATED && invitation.delegationCredentialId, void 0, {
6327
6334
  F: __dxlog_file22,
6328
- L: 134,
6335
+ L: 133,
6329
6336
  S: this,
6330
6337
  A: [
6331
6338
  "invitation.type === Invitation.Type.DELEGATED && invitation.delegationCredentialId",
@@ -6335,7 +6342,7 @@ var SpaceInvitationProtocol = class {
6335
6342
  const space = this._spaceManager.spaces.get(this._spaceKey);
6336
6343
  invariant16(space, void 0, {
6337
6344
  F: __dxlog_file22,
6338
- L: 136,
6345
+ L: 135,
6339
6346
  S: this,
6340
6347
  A: [
6341
6348
  "space",
@@ -6347,14 +6354,14 @@ var SpaceInvitationProtocol = class {
6347
6354
  id: invitation.invitationId
6348
6355
  }, {
6349
6356
  F: __dxlog_file22,
6350
- L: 138,
6357
+ L: 137,
6351
6358
  S: this,
6352
6359
  C: (f, a) => f(...a)
6353
6360
  });
6354
6361
  const credential = await createCancelDelegatedSpaceInvitationCredential(this._signingContext.credentialSigner, space.key, invitation.delegationCredentialId);
6355
6362
  invariant16(credential.credential, void 0, {
6356
6363
  F: __dxlog_file22,
6357
- L: 145,
6364
+ L: 144,
6358
6365
  S: this,
6359
6366
  A: [
6360
6367
  "credential.credential",
@@ -6367,7 +6374,7 @@ var SpaceInvitationProtocol = class {
6367
6374
  }
6368
6375
  checkInvitation(invitation) {
6369
6376
  if (invitation.spaceKey == null) {
6370
- return new InvalidInvitationError("No spaceKey was provided for a space invitation.");
6377
+ return new InvalidInvitationError2("No spaceKey was provided for a space invitation.");
6371
6378
  }
6372
6379
  if (this._spaceManager.spaces.has(invitation.spaceKey)) {
6373
6380
  return new AlreadyJoinedError3("Already joined space.");
@@ -6393,7 +6400,7 @@ var SpaceInvitationProtocol = class {
6393
6400
  async accept(response) {
6394
6401
  invariant16(response.space, void 0, {
6395
6402
  F: __dxlog_file22,
6396
- L: 180,
6403
+ L: 179,
6397
6404
  S: this,
6398
6405
  A: [
6399
6406
  "response.space",
@@ -6404,7 +6411,7 @@ var SpaceInvitationProtocol = class {
6404
6411
  const assertion = getCredentialAssertion5(credential);
6405
6412
  invariant16(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
6406
6413
  F: __dxlog_file22,
6407
- L: 183,
6414
+ L: 182,
6408
6415
  S: this,
6409
6416
  A: [
6410
6417
  "assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -6413,7 +6420,7 @@ var SpaceInvitationProtocol = class {
6413
6420
  });
6414
6421
  invariant16(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
6415
6422
  F: __dxlog_file22,
6416
- L: 184,
6423
+ L: 183,
6417
6424
  S: this,
6418
6425
  A: [
6419
6426
  "credential.subject.id.equals(this._signingContext.identityKey)",
@@ -6649,7 +6656,7 @@ var InvitationsManager = class {
6649
6656
  }
6650
6657
  }
6651
6658
  _createInvitation(protocol, _options) {
6652
- const { invitationId = PublicKey12.random().toHex(), type = Invitation9.Type.INTERACTIVE, authMethod = Invitation9.AuthMethod.SHARED_SECRET, state = Invitation9.State.INIT, timeout = INVITATION_TIMEOUT2, swarmKey = PublicKey12.random(), persistent = _options?.authMethod !== Invitation9.AuthMethod.KNOWN_PUBLIC_KEY, created = /* @__PURE__ */ new Date(), guestKeypair = void 0, role = SpaceMember7.Role.ADMIN, lifetime = 86400, multiUse = false, ...options } = _options ?? {};
6659
+ const { invitationId = PublicKey12.random().toHex(), type = Invitation9.Type.INTERACTIVE, authMethod = Invitation9.AuthMethod.SHARED_SECRET, state = Invitation9.State.INIT, timeout = INVITATION_TIMEOUT2, swarmKey = PublicKey12.random(), persistent = _options?.authMethod !== Invitation9.AuthMethod.KNOWN_PUBLIC_KEY, created = /* @__PURE__ */ new Date(), guestKeypair = void 0, role = SpaceMember7.Role.ADMIN, lifetime = 86400 * 7, multiUse = false, ...options } = _options ?? {};
6653
6660
  const authCode = options?.authCode ?? (authMethod === Invitation9.AuthMethod.SHARED_SECRET ? generatePasscode(AUTHENTICATION_CODE_LENGTH) : void 0);
6654
6661
  return {
6655
6662
  invitationId,
@@ -7171,7 +7178,7 @@ _ts_decorate9([
7171
7178
  ], EdgeAgentManager.prototype, "createAgent", null);
7172
7179
 
7173
7180
  // packages/sdk/client-services/src/packlets/agents/edge-agent-service.ts
7174
- import { Stream as Stream11 } from "@dxos/codec-protobuf";
7181
+ import { Stream as Stream11 } from "@dxos/codec-protobuf/stream";
7175
7182
  import { EdgeAgentStatus as EdgeAgentStatus2 } from "@dxos/protocols";
7176
7183
  import { QueryAgentStatusResponse, QueryEdgeStatusResponse } from "@dxos/protocols/proto/dxos/client/services";
7177
7184
  var EdgeAgentServiceImpl = class {
@@ -7250,7 +7257,7 @@ import { trace as Trace3 } from "@dxos/tracing";
7250
7257
  import { safeInstanceof } from "@dxos/util";
7251
7258
 
7252
7259
  // packages/sdk/client-services/src/packlets/identity/identity-recovery-manager.ts
7253
- import { generateSeedPhrase as generateSeedPhrase2, keyPairFromSeedPhrase as keyPairFromSeedPhrase2 } from "@dxos/credentials";
7260
+ import { generateSeedPhrase, keyPairFromSeedPhrase } from "@dxos/credentials";
7254
7261
  import { sign as sign3 } from "@dxos/crypto";
7255
7262
  import { invariant as invariant20 } from "@dxos/invariant";
7256
7263
  import { PublicKey as PublicKey14 } from "@dxos/keys";
@@ -7266,27 +7273,41 @@ var EdgeIdentityRecoveryManager = class {
7266
7273
  this._identityProvider = _identityProvider;
7267
7274
  this._acceptRecoveredIdentity = _acceptRecoveredIdentity;
7268
7275
  }
7269
- async createRecoveryPhrase() {
7276
+ async createRecoveryCredential({ recoveryKey, algorithm }) {
7270
7277
  const identity = this._identityProvider();
7271
7278
  invariant20(identity, void 0, {
7272
7279
  F: __dxlog_file26,
7273
- L: 29,
7280
+ L: 37,
7274
7281
  S: this,
7275
7282
  A: [
7276
7283
  "identity",
7277
7284
  ""
7278
7285
  ]
7279
7286
  });
7280
- const seedphrase = generateSeedPhrase2();
7281
- const keypair = keyPairFromSeedPhrase2(seedphrase);
7282
- const recoveryKey = PublicKey14.from(keypair.publicKey);
7287
+ let recoveryCode;
7288
+ if (!recoveryKey) {
7289
+ recoveryCode = generateSeedPhrase();
7290
+ const keypair = keyPairFromSeedPhrase(recoveryCode);
7291
+ recoveryKey = PublicKey14.from(keypair.publicKey);
7292
+ algorithm = -8;
7293
+ }
7294
+ invariant20(algorithm, "Algorithm is required.", {
7295
+ F: __dxlog_file26,
7296
+ L: 47,
7297
+ S: this,
7298
+ A: [
7299
+ "algorithm",
7300
+ "'Algorithm is required.'"
7301
+ ]
7302
+ });
7283
7303
  const identityKey = identity.identityKey;
7284
7304
  const credential = await identity.getIdentityCredentialSigner().createCredential({
7285
7305
  subject: identityKey,
7286
7306
  assertion: {
7287
7307
  "@type": "dxos.halo.credentials.IdentityRecovery",
7288
7308
  recoveryKey,
7289
- identityKey
7309
+ identityKey,
7310
+ algorithm
7290
7311
  }
7291
7312
  });
7292
7313
  const receipt = await identity.controlPipeline.writer.write({
@@ -7301,20 +7322,81 @@ var EdgeIdentityRecoveryManager = class {
7301
7322
  ]
7302
7323
  ]));
7303
7324
  return {
7304
- seedphrase
7325
+ recoveryCode
7305
7326
  };
7306
7327
  }
7307
- async recoverIdentity(args) {
7328
+ async requestRecoveryChallenge() {
7308
7329
  invariant20(this._edgeClient, "Not connected to EDGE.", {
7309
7330
  F: __dxlog_file26,
7310
- L: 51,
7331
+ L: 66,
7311
7332
  S: this,
7312
7333
  A: [
7313
7334
  "this._edgeClient",
7314
7335
  "'Not connected to EDGE.'"
7315
7336
  ]
7316
7337
  });
7317
- const recoveryKeypair = keyPairFromSeedPhrase2(args.seedphrase);
7338
+ const deviceKey = await this._keyring.createKey();
7339
+ const controlFeedKey = await this._keyring.createKey();
7340
+ const request = {
7341
+ deviceKey: deviceKey.toHex(),
7342
+ controlFeedKey: controlFeedKey.toHex()
7343
+ };
7344
+ try {
7345
+ await this._edgeClient.recoverIdentity(request);
7346
+ throw new Error("No challenge received.");
7347
+ } catch (error) {
7348
+ if (!(error instanceof EdgeAuthChallengeError2)) {
7349
+ throw error;
7350
+ }
7351
+ return {
7352
+ deviceKey,
7353
+ controlFeedKey,
7354
+ challenge: error.challenge
7355
+ };
7356
+ }
7357
+ }
7358
+ async recoverIdentityWithExternalSignature({ identityDid, deviceKey, controlFeedKey, signature, clientDataJson, authenticatorData }) {
7359
+ invariant20(this._edgeClient, "Not connected to EDGE.", {
7360
+ F: __dxlog_file26,
7361
+ L: 98,
7362
+ S: this,
7363
+ A: [
7364
+ "this._edgeClient",
7365
+ "'Not connected to EDGE.'"
7366
+ ]
7367
+ });
7368
+ const request = {
7369
+ identityDid,
7370
+ deviceKey: deviceKey.toHex(),
7371
+ controlFeedKey: controlFeedKey.toHex(),
7372
+ signature: clientDataJson && authenticatorData ? {
7373
+ signature: Buffer.from(signature).toString("base64"),
7374
+ clientDataJson: Buffer.from(clientDataJson).toString("base64"),
7375
+ authenticatorData: Buffer.from(authenticatorData).toString("base64")
7376
+ } : Buffer.from(signature).toString("base64")
7377
+ };
7378
+ const response = await this._edgeClient.recoverIdentity(request);
7379
+ await this._acceptRecoveredIdentity({
7380
+ authorizedDeviceCredential: decodeCredential(response.deviceAuthCredential),
7381
+ haloGenesisFeedKey: PublicKey14.fromHex(response.genesisFeedKey),
7382
+ haloSpaceKey: PublicKey14.fromHex(response.haloSpaceKey),
7383
+ identityKey: PublicKey14.fromHex(response.identityKey),
7384
+ deviceKey,
7385
+ controlFeedKey,
7386
+ dataFeedKey: await this._keyring.createKey()
7387
+ });
7388
+ }
7389
+ async recoverIdentity({ recoveryCode }) {
7390
+ invariant20(this._edgeClient, "Not connected to EDGE.", {
7391
+ F: __dxlog_file26,
7392
+ L: 128,
7393
+ S: this,
7394
+ A: [
7395
+ "this._edgeClient",
7396
+ "'Not connected to EDGE.'"
7397
+ ]
7398
+ });
7399
+ const recoveryKeypair = keyPairFromSeedPhrase(recoveryCode);
7318
7400
  const recoveryKey = PublicKey14.from(recoveryKeypair.publicKey);
7319
7401
  const deviceKey = await this._keyring.createKey();
7320
7402
  const controlFeedKey = await this._keyring.createKey();
@@ -7338,7 +7420,7 @@ var EdgeIdentityRecoveryManager = class {
7338
7420
  }
7339
7421
  log22.info("recovering identity", response, {
7340
7422
  F: __dxlog_file26,
7341
- L: 77,
7423
+ L: 154,
7342
7424
  S: this,
7343
7425
  C: (f, a) => f(...a)
7344
7426
  });
@@ -7479,7 +7561,8 @@ var ServiceContext = class extends Resource7 {
7479
7561
  this.recoveryManager = new EdgeIdentityRecoveryManager(this.keyring, this._edgeHttpClient, () => this.identityManager.identity, this._acceptIdentity.bind(this));
7480
7562
  this.echoHost = new EchoHost({
7481
7563
  kv: this.level,
7482
- peerIdProvider: () => this.identityManager.identity?.deviceKey?.toHex()
7564
+ peerIdProvider: () => this.identityManager.identity?.deviceKey?.toHex(),
7565
+ getSpaceKeyByRootDocumentId: (documentId) => this.spaceManager.findSpaceByRootDocumentId(documentId)?.key
7483
7566
  });
7484
7567
  this._meshReplicator = new MeshEchoReplicator();
7485
7568
  this.invitations = new InvitationsHandler(this.networkManager, this._edgeHttpClient, _runtimeParams?.invitationConnectionDefaultParams);
@@ -7498,7 +7581,7 @@ var ServiceContext = class extends Resource7 {
7498
7581
  await this._checkStorageVersion();
7499
7582
  log23("opening...", void 0, {
7500
7583
  F: __dxlog_file27,
7501
- L: 198,
7584
+ L: 199,
7502
7585
  S: this,
7503
7586
  C: (f, a) => f(...a)
7504
7587
  });
@@ -7506,7 +7589,7 @@ var ServiceContext = class extends Resource7 {
7506
7589
  id: this._instanceId
7507
7590
  }), {
7508
7591
  F: __dxlog_file27,
7509
- L: 199,
7592
+ L: 200,
7510
7593
  S: this,
7511
7594
  C: (f, a) => f(...a)
7512
7595
  });
@@ -7533,7 +7616,7 @@ var ServiceContext = class extends Resource7 {
7533
7616
  count: loadedInvitations.invitations?.length
7534
7617
  }, {
7535
7618
  F: __dxlog_file27,
7536
- L: 227,
7619
+ L: 228,
7537
7620
  S: this,
7538
7621
  C: (f, a) => f(...a)
7539
7622
  });
@@ -7541,13 +7624,13 @@ var ServiceContext = class extends Resource7 {
7541
7624
  id: this._instanceId
7542
7625
  }), {
7543
7626
  F: __dxlog_file27,
7544
- L: 229,
7627
+ L: 230,
7545
7628
  S: this,
7546
7629
  C: (f, a) => f(...a)
7547
7630
  });
7548
7631
  log23("opened", void 0, {
7549
7632
  F: __dxlog_file27,
7550
- L: 230,
7633
+ L: 231,
7551
7634
  S: this,
7552
7635
  C: (f, a) => f(...a)
7553
7636
  });
@@ -7555,7 +7638,7 @@ var ServiceContext = class extends Resource7 {
7555
7638
  async _close(ctx) {
7556
7639
  log23("closing...", void 0, {
7557
7640
  F: __dxlog_file27,
7558
- L: 234,
7641
+ L: 235,
7559
7642
  S: this,
7560
7643
  C: (f, a) => f(...a)
7561
7644
  });
@@ -7574,7 +7657,7 @@ var ServiceContext = class extends Resource7 {
7574
7657
  await this._edgeConnection?.close();
7575
7658
  log23("closed", void 0, {
7576
7659
  F: __dxlog_file27,
7577
- L: 250,
7660
+ L: 251,
7578
7661
  S: this,
7579
7662
  C: (f, a) => f(...a)
7580
7663
  });
@@ -7585,7 +7668,7 @@ var ServiceContext = class extends Resource7 {
7585
7668
  await identity.joinNetwork();
7586
7669
  await this._initialize(new Context9(void 0, {
7587
7670
  F: __dxlog_file27,
7588
- L: 257
7671
+ L: 258
7589
7672
  }));
7590
7673
  return identity;
7591
7674
  }
@@ -7596,7 +7679,7 @@ var ServiceContext = class extends Resource7 {
7596
7679
  const factory = this._handlerFactories.get(invitation.kind);
7597
7680
  invariant21(factory, `Unknown invitation kind: ${invitation.kind}`, {
7598
7681
  F: __dxlog_file27,
7599
- L: 266,
7682
+ L: 267,
7600
7683
  S: this,
7601
7684
  A: [
7602
7685
  "factory",
@@ -7622,7 +7705,7 @@ var ServiceContext = class extends Resource7 {
7622
7705
  await this.identityManager.acceptIdentity(identity, identityRecord, params.deviceProfile);
7623
7706
  await this._initialize(new Context9(void 0, {
7624
7707
  F: __dxlog_file27,
7625
- L: 285
7708
+ L: 286
7626
7709
  }));
7627
7710
  return identity;
7628
7711
  }
@@ -7636,7 +7719,7 @@ var ServiceContext = class extends Resource7 {
7636
7719
  async _initialize(ctx) {
7637
7720
  log23("initializing spaces...", void 0, {
7638
7721
  F: __dxlog_file27,
7639
- L: 300,
7722
+ L: 301,
7640
7723
  S: this,
7641
7724
  C: (f, a) => f(...a)
7642
7725
  });
@@ -7675,7 +7758,7 @@ var ServiceContext = class extends Resource7 {
7675
7758
  this._handlerFactories.set(Invitation10.Kind.SPACE, (invitation) => {
7676
7759
  invariant21(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
7677
7760
  F: __dxlog_file27,
7678
- L: 338,
7761
+ L: 339,
7679
7762
  S: this,
7680
7763
  A: [
7681
7764
  "this.dataSpaceManager",
@@ -7699,7 +7782,7 @@ var ServiceContext = class extends Resource7 {
7699
7782
  details: assertion
7700
7783
  }, {
7701
7784
  F: __dxlog_file27,
7702
- L: 354,
7785
+ L: 355,
7703
7786
  S: this,
7704
7787
  C: (f, a) => f(...a)
7705
7788
  });
@@ -7710,7 +7793,7 @@ var ServiceContext = class extends Resource7 {
7710
7793
  details: assertion
7711
7794
  }, {
7712
7795
  F: __dxlog_file27,
7713
- L: 358,
7796
+ L: 359,
7714
7797
  S: this,
7715
7798
  C: (f, a) => f(...a)
7716
7799
  });
@@ -7721,7 +7804,7 @@ var ServiceContext = class extends Resource7 {
7721
7804
  details: assertion
7722
7805
  }, {
7723
7806
  F: __dxlog_file27,
7724
- L: 363,
7807
+ L: 364,
7725
7808
  S: this,
7726
7809
  C: (f, a) => f(...a)
7727
7810
  });
@@ -7732,7 +7815,7 @@ var ServiceContext = class extends Resource7 {
7732
7815
  } catch (err) {
7733
7816
  log23.catch(err, void 0, {
7734
7817
  F: __dxlog_file27,
7735
- L: 369,
7818
+ L: 370,
7736
7819
  S: this,
7737
7820
  C: (f, a) => f(...a)
7738
7821
  });
@@ -7748,12 +7831,12 @@ var ServiceContext = class extends Resource7 {
7748
7831
  let edgeIdentity;
7749
7832
  const identity = this.identityManager.identity;
7750
7833
  if (identity) {
7751
- log23.info("Setting identity on edge connection", {
7834
+ log23("setting identity on edge connection", {
7752
7835
  identity: identity.identityKey.toHex(),
7753
7836
  swarms: this.networkManager.topics
7754
7837
  }, {
7755
7838
  F: __dxlog_file27,
7756
- L: 383,
7839
+ L: 384,
7757
7840
  S: this,
7758
7841
  C: (f, a) => f(...a)
7759
7842
  });
@@ -7767,7 +7850,7 @@ var ServiceContext = class extends Resource7 {
7767
7850
  });
7768
7851
  invariant21(identity.deviceCredentialChain, void 0, {
7769
7852
  F: __dxlog_file27,
7770
- L: 401,
7853
+ L: 403,
7771
7854
  S: this,
7772
7855
  A: [
7773
7856
  "identity.deviceCredentialChain",
@@ -8077,7 +8160,7 @@ import { WebsocketRpcClient } from "@dxos/websocket-rpc";
8077
8160
 
8078
8161
  // packages/sdk/client-services/src/packlets/devices/devices-service.ts
8079
8162
  import { EventSubscriptions as EventSubscriptions3 } from "@dxos/async";
8080
- import { Stream as Stream12 } from "@dxos/codec-protobuf";
8163
+ import { Stream as Stream12 } from "@dxos/codec-protobuf/stream";
8081
8164
  import { invariant as invariant23 } from "@dxos/invariant";
8082
8165
  import { Device as Device2, DeviceKind as DeviceKind2 } from "@dxos/protocols/proto/dxos/client/services";
8083
8166
  var __dxlog_file29 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
@@ -8167,7 +8250,7 @@ var DevicesServiceImpl = class {
8167
8250
 
8168
8251
  // packages/sdk/client-services/src/packlets/identity/contacts-service.ts
8169
8252
  import { EventSubscriptions as EventSubscriptions4, scheduleTask as scheduleTask9, UpdateScheduler as UpdateScheduler2 } from "@dxos/async";
8170
- import { Stream as Stream13 } from "@dxos/codec-protobuf";
8253
+ import { Stream as Stream13 } from "@dxos/codec-protobuf/stream";
8171
8254
  import { PublicKey as PublicKey17 } from "@dxos/keys";
8172
8255
  import { ComplexMap as ComplexMap5, ComplexSet as ComplexSet6 } from "@dxos/util";
8173
8256
  var ContactsServiceImpl = class {
@@ -8250,7 +8333,7 @@ var ContactsServiceImpl = class {
8250
8333
 
8251
8334
  // packages/sdk/client-services/src/packlets/logging/logging-service.ts
8252
8335
  import { Event as Event10 } from "@dxos/async";
8253
- import { Stream as Stream14 } from "@dxos/codec-protobuf";
8336
+ import { Stream as Stream14 } from "@dxos/codec-protobuf/stream";
8254
8337
  import { PublicKey as PublicKey18 } from "@dxos/keys";
8255
8338
  import { getContextFromEntry, log as log25 } from "@dxos/log";
8256
8339
  import { QueryLogsRequest } from "@dxos/protocols/proto/dxos/client/services";
@@ -8373,7 +8456,7 @@ var shouldLog = (entry2, request) => {
8373
8456
  var LOG_PROCESSING = 0;
8374
8457
 
8375
8458
  // packages/sdk/client-services/src/packlets/network/network-service.ts
8376
- import { Stream as Stream15 } from "@dxos/codec-protobuf";
8459
+ import { Stream as Stream15 } from "@dxos/codec-protobuf/stream";
8377
8460
  var NetworkServiceImpl = class {
8378
8461
  constructor(networkManager, signalManager) {
8379
8462
  this.networkManager = networkManager;
@@ -8403,10 +8486,39 @@ var NetworkServiceImpl = class {
8403
8486
  async updateConfig(request) {
8404
8487
  await this.networkManager.setConnectionState(request.swarm);
8405
8488
  }
8489
+ async joinSwarm(request) {
8490
+ return this.signalManager.join(request);
8491
+ }
8492
+ async leaveSwarm(request) {
8493
+ return this.signalManager.leave(request);
8494
+ }
8495
+ subscribeSwarmState(request) {
8496
+ return new Stream15(({ next }) => {
8497
+ const unsubscribe = this.signalManager.swarmState?.on((state) => {
8498
+ if (request.topic.equals(state.swarmKey)) {
8499
+ next(state);
8500
+ }
8501
+ });
8502
+ return unsubscribe;
8503
+ });
8504
+ }
8505
+ async sendMessage(message) {
8506
+ return this.signalManager.sendMessage(message);
8507
+ }
8508
+ subscribeMessages(peer) {
8509
+ return new Stream15(({ next }) => {
8510
+ const unsubscribe = this.signalManager.onMessage.on((message) => {
8511
+ if (message.recipient.peerKey === peer.peerKey) {
8512
+ next(message);
8513
+ }
8514
+ });
8515
+ return unsubscribe;
8516
+ });
8517
+ }
8406
8518
  };
8407
8519
 
8408
8520
  // packages/sdk/client-services/src/packlets/system/system-service.ts
8409
- import { Stream as Stream16 } from "@dxos/codec-protobuf";
8521
+ import { Stream as Stream16 } from "@dxos/codec-protobuf/stream";
8410
8522
  import { GetDiagnosticsRequest as GetDiagnosticsRequest2 } from "@dxos/protocols/proto/dxos/client/services";
8411
8523
  import { jsonKeyReplacer as jsonKeyReplacer2 } from "@dxos/util";
8412
8524
  var SystemServiceImpl = class {
@@ -8910,4 +9022,4 @@ export {
8910
9022
  importProfileData,
8911
9023
  ClientServicesHost
8912
9024
  };
8913
- //# sourceMappingURL=chunk-OQOXRHWF.mjs.map
9025
+ //# sourceMappingURL=chunk-EQU6BG5J.mjs.map