@dxos/client-services 0.7.5-main.2567c87 → 0.7.5-main.5ae2ba8

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 (95) hide show
  1. package/dist/lib/browser/{chunk-443F7E4C.mjs → chunk-C6HAFZX6.mjs} +276 -195
  2. package/dist/lib/browser/chunk-C6HAFZX6.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-LKVY5GQC.cjs → chunk-F7R4IRLD.cjs} +303 -222
  7. package/dist/lib/node/chunk-F7R4IRLD.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-RZEXZLYL.mjs → chunk-EBNDRSDP.mjs} +276 -195
  12. package/dist/lib/node-esm/chunk-EBNDRSDP.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-manager.d.ts.map +1 -1
  17. package/dist/types/src/packlets/agents/edge-agent-service.d.ts +1 -1
  18. package/dist/types/src/packlets/agents/edge-agent-service.d.ts.map +1 -1
  19. package/dist/types/src/packlets/devices/devices-service.d.ts +1 -1
  20. package/dist/types/src/packlets/devices/devices-service.d.ts.map +1 -1
  21. package/dist/types/src/packlets/devtools/devtools.d.ts +1 -1
  22. package/dist/types/src/packlets/devtools/devtools.d.ts.map +1 -1
  23. package/dist/types/src/packlets/devtools/feeds.d.ts +1 -1
  24. package/dist/types/src/packlets/devtools/feeds.d.ts.map +1 -1
  25. package/dist/types/src/packlets/devtools/keys.d.ts +1 -1
  26. package/dist/types/src/packlets/devtools/keys.d.ts.map +1 -1
  27. package/dist/types/src/packlets/devtools/metadata.d.ts +1 -1
  28. package/dist/types/src/packlets/devtools/metadata.d.ts.map +1 -1
  29. package/dist/types/src/packlets/devtools/network.d.ts +1 -1
  30. package/dist/types/src/packlets/devtools/network.d.ts.map +1 -1
  31. package/dist/types/src/packlets/devtools/spaces.d.ts +1 -1
  32. package/dist/types/src/packlets/devtools/spaces.d.ts.map +1 -1
  33. package/dist/types/src/packlets/diagnostics/diagnostics-collector.d.ts.map +1 -1
  34. package/dist/types/src/packlets/diagnostics/diagnostics.d.ts.map +1 -1
  35. package/dist/types/src/packlets/identity/contacts-service.d.ts +1 -1
  36. package/dist/types/src/packlets/identity/contacts-service.d.ts.map +1 -1
  37. package/dist/types/src/packlets/identity/identity-manager.d.ts +0 -3
  38. package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
  39. package/dist/types/src/packlets/identity/identity-recovery-manager.d.ts +12 -4
  40. package/dist/types/src/packlets/identity/identity-recovery-manager.d.ts.map +1 -1
  41. package/dist/types/src/packlets/identity/identity-service.d.ts +9 -4
  42. package/dist/types/src/packlets/identity/identity-service.d.ts.map +1 -1
  43. package/dist/types/src/packlets/identity/identity.d.ts +3 -1
  44. package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
  45. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  46. package/dist/types/src/packlets/invitations/invitations-service.d.ts +1 -1
  47. package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
  48. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
  49. package/dist/types/src/packlets/invitations/utils.d.ts +1 -0
  50. package/dist/types/src/packlets/invitations/utils.d.ts.map +1 -1
  51. package/dist/types/src/packlets/logging/logging-service.d.ts +1 -1
  52. package/dist/types/src/packlets/logging/logging-service.d.ts.map +1 -1
  53. package/dist/types/src/packlets/network/network-service.d.ts +1 -1
  54. package/dist/types/src/packlets/network/network-service.d.ts.map +1 -1
  55. package/dist/types/src/packlets/services/service-host.d.ts +1 -1
  56. package/dist/types/src/packlets/services/service-host.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/package.json +39 -38
  63. package/src/packlets/agents/edge-agent-manager.ts +6 -0
  64. package/src/packlets/agents/edge-agent-service.ts +1 -1
  65. package/src/packlets/devices/devices-service.ts +1 -1
  66. package/src/packlets/devtools/devtools.ts +1 -1
  67. package/src/packlets/devtools/feeds.ts +1 -1
  68. package/src/packlets/devtools/keys.ts +1 -1
  69. package/src/packlets/devtools/metadata.ts +1 -1
  70. package/src/packlets/devtools/network.ts +1 -1
  71. package/src/packlets/devtools/spaces.ts +1 -1
  72. package/src/packlets/diagnostics/diagnostics-collector.ts +2 -2
  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 +1 -1
  87. package/src/packlets/spaces/data-space-manager.ts +3 -3
  88. package/src/packlets/spaces/data-space.ts +2 -2
  89. package/src/packlets/spaces/edge-feed-replicator.ts +8 -8
  90. package/src/packlets/spaces/spaces-service.ts +31 -21
  91. package/src/packlets/system/system-service.ts +1 -1
  92. package/src/version.ts +1 -1
  93. package/dist/lib/browser/chunk-443F7E4C.mjs.map +0 -7
  94. package/dist/lib/node/chunk-LKVY5GQC.cjs.map +0 -7
  95. package/dist/lib/node-esm/chunk-RZEXZLYL.mjs.map +0 -7
@@ -2,7 +2,7 @@ import "@dxos/node-std/globals";
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.5-main.2567c87";
400
+ var DXOS_VERSION = "0.7.5-main.5ae2ba8";
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,
@@ -647,7 +649,7 @@ import { ClientServicesProviderResource } from "@dxos/client-protocol";
647
649
  import { ConfigResource } from "@dxos/config";
648
650
  import { GetDiagnosticsRequest } from "@dxos/protocols/proto/dxos/client/services";
649
651
  import { TRACE_PROCESSOR as TRACE_PROCESSOR2 } from "@dxos/tracing";
650
- import { jsonKeyReplacer, nonNullable } from "@dxos/util";
652
+ import { jsonKeyReplacer, isNonNullable } from "@dxos/util";
651
653
  var GET_DIAGNOSTICS_RPC_TIMEOUT = 1e4;
652
654
  var DiagnosticsCollector = class {
653
655
  static {
@@ -680,7 +682,7 @@ var findSystemServiceProvider = () => {
680
682
  };
681
683
  var findConfigs = () => {
682
684
  const configs = TRACE_PROCESSOR2.findResourcesByAnnotation(ConfigResource);
683
- return configs.map((r) => r.instance.deref()).filter(nonNullable);
685
+ return configs.map((r) => r.instance.deref()).filter(isNonNullable);
684
686
  };
685
687
 
686
688
  // packages/sdk/client-services/src/packlets/identity/authenticator.ts
@@ -991,7 +993,7 @@ var EdgeFeedReplicator = class extends Resource {
991
993
  this._remoteLength.clear();
992
994
  }
993
995
  async addFeed(feed) {
994
- log4.info("addFeed", {
996
+ log4("addFeed", {
995
997
  key: feed.key,
996
998
  connected: this._connected,
997
999
  hasConnectionCtx: !!this._connectionCtx
@@ -1028,7 +1030,7 @@ var EdgeFeedReplicator = class extends Resource {
1028
1030
  }
1029
1031
  async _sendMessage(message) {
1030
1032
  if (!this._connectionCtx) {
1031
- log4.info("message dropped because connection was disposed", void 0, {
1033
+ log4("message dropped because connection was disposed", void 0, {
1032
1034
  F: __dxlog_file6,
1033
1035
  L: 146,
1034
1036
  S: this,
@@ -1037,7 +1039,7 @@ var EdgeFeedReplicator = class extends Resource {
1037
1039
  return;
1038
1040
  }
1039
1041
  if (message.type === "data") {
1040
- log4.info("sending blocks", {
1042
+ log4("sending blocks", {
1041
1043
  feedKey: message.feedKey,
1042
1044
  blocks: message.blocks.map((b) => b.index)
1043
1045
  }, {
@@ -1112,7 +1114,7 @@ var EdgeFeedReplicator = class extends Resource {
1112
1114
  feedKey
1113
1115
  };
1114
1116
  if (message.length > feed.length) {
1115
- log4.info("requesting missing blocks", logMeta, {
1117
+ log4("requesting missing blocks", logMeta, {
1116
1118
  F: __dxlog_file6,
1117
1119
  L: 194,
1118
1120
  S: this,
@@ -1127,7 +1129,7 @@ var EdgeFeedReplicator = class extends Resource {
1127
1129
  }
1128
1130
  });
1129
1131
  } else if (message.length < feed.length) {
1130
- log4.info("pushing blocks to remote", logMeta, {
1132
+ log4("pushing blocks to remote", logMeta, {
1131
1133
  F: __dxlog_file6,
1132
1134
  L: 202,
1133
1135
  S: this,
@@ -1143,7 +1145,7 @@ var EdgeFeedReplicator = class extends Resource {
1143
1145
  }
1144
1146
  }
1145
1147
  case "data": {
1146
- log4.info("received data", {
1148
+ log4("received data", {
1147
1149
  feed: message.feedKey,
1148
1150
  blocks: message.blocks.map((b) => b.index)
1149
1151
  }, {
@@ -1182,7 +1184,7 @@ var EdgeFeedReplicator = class extends Resource {
1182
1184
  });
1183
1185
  }
1184
1186
  async _pushBlocks(feed, from, to) {
1185
- log4.info("pushing blocks", {
1187
+ log4("pushing blocks", {
1186
1188
  feed: feed.key.toHex(),
1187
1189
  from,
1188
1190
  to
@@ -1221,7 +1223,7 @@ var EdgeFeedReplicator = class extends Resource {
1221
1223
  this._remoteLength.set(feed.key, to);
1222
1224
  }
1223
1225
  async _integrateBlocks(feed, blocks) {
1224
- log4.info("integrating blocks", {
1226
+ log4("integrating blocks", {
1225
1227
  feed: feed.key.toHex(),
1226
1228
  blocks: blocks.length
1227
1229
  }, {
@@ -2528,7 +2530,7 @@ var DataSpaceManager = class extends Resource4 {
2528
2530
  });
2529
2531
  dataSpace.postOpen.append(async () => {
2530
2532
  const setting = dataSpace.getEdgeReplicationSetting();
2531
- if (setting === EdgeReplicationSetting.ENABLED) {
2533
+ if (!setting || setting === EdgeReplicationSetting.ENABLED) {
2532
2534
  await this._echoEdgeReplicator?.connectToSpace(dataSpace.id);
2533
2535
  } else if (this._echoEdgeReplicator) {
2534
2536
  log7("not connecting EchoEdgeReplicator because of EdgeReplicationSetting", {
@@ -2543,7 +2545,7 @@ var DataSpaceManager = class extends Resource4 {
2543
2545
  });
2544
2546
  dataSpace.preClose.append(async () => {
2545
2547
  const setting = dataSpace.getEdgeReplicationSetting();
2546
- if (setting === EdgeReplicationSetting.ENABLED) {
2548
+ if (!setting || setting === EdgeReplicationSetting.ENABLED) {
2547
2549
  await this._echoEdgeReplicator?.disconnectFromSpace(dataSpace.id);
2548
2550
  }
2549
2551
  });
@@ -2648,7 +2650,7 @@ var DataSpaceManager = class extends Resource4 {
2648
2650
  guestKeypair: invitation.guestKey ? {
2649
2651
  publicKey: invitation.guestKey
2650
2652
  } : void 0,
2651
- lifetime: invitation.expiresOn ? invitation.expiresOn.getTime() - Date.now() : void 0,
2653
+ lifetime: invitation.expiresOn ? (invitation.expiresOn.getTime() - Date.now()) / 1e3 : void 0,
2652
2654
  multiUse: invitation.multiUse,
2653
2655
  delegationCredentialId: credentialId,
2654
2656
  persistent: false
@@ -2675,8 +2677,8 @@ DataSpaceManager = _ts_decorate3([
2675
2677
 
2676
2678
  // packages/sdk/client-services/src/packlets/spaces/spaces-service.ts
2677
2679
  import { EventSubscriptions as EventSubscriptions2, UpdateScheduler, scheduleTask as scheduleTask3 } from "@dxos/async";
2678
- import { Stream as Stream7 } from "@dxos/codec-protobuf";
2679
- import { createAdmissionCredentials as createAdmissionCredentials2, getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
2680
+ import { Stream as Stream7 } from "@dxos/codec-protobuf/stream";
2681
+ import { createAdmissionCredentials as createAdmissionCredentials2, createDidFromIdentityKey as createDidFromIdentityKey2, getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
2680
2682
  import { raise } from "@dxos/debug";
2681
2683
  import { writeMessages as writeMessages2 } from "@dxos/feed-store";
2682
2684
  import { invariant as invariant6 } from "@dxos/invariant";
@@ -2732,7 +2734,7 @@ var SpacesServiceImpl = class {
2732
2734
  const credentials = await createAdmissionCredentials2(identity.getIdentityCredentialSigner(), request.memberKey, space.key, space.genesisFeedKey, request.newRole, space.spaceState.membershipChainHeads);
2733
2735
  invariant6(credentials[0].credential, void 0, {
2734
2736
  F: __dxlog_file11,
2735
- L: 106,
2737
+ L: 111,
2736
2738
  S: this,
2737
2739
  A: [
2738
2740
  "credentials[0].credential",
@@ -2742,7 +2744,7 @@ var SpacesServiceImpl = class {
2742
2744
  const spaceMemberCredential = credentials[0].credential.credential;
2743
2745
  invariant6(getCredentialAssertion3(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2744
2746
  F: __dxlog_file11,
2745
- L: 108,
2747
+ L: 113,
2746
2748
  S: this,
2747
2749
  A: [
2748
2750
  "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2755,12 +2757,12 @@ var SpacesServiceImpl = class {
2755
2757
  return new Stream7(({ next, ctx }) => {
2756
2758
  const scheduler = new UpdateScheduler(ctx, async () => {
2757
2759
  const dataSpaceManager = await this._getDataSpaceManager();
2758
- const spaces = Array.from(dataSpaceManager.spaces.values()).map((space) => this._serializeSpace(space));
2760
+ const spaces = await Promise.all(Array.from(dataSpaceManager.spaces.values()).map((space) => this._serializeSpace(space)));
2759
2761
  log8("update", () => ({
2760
2762
  ids: spaces.map((space) => space.id)
2761
2763
  }), {
2762
2764
  F: __dxlog_file11,
2763
- L: 119,
2765
+ L: 126,
2764
2766
  S: this,
2765
2767
  C: (f, a) => f(...a)
2766
2768
  });
@@ -2852,7 +2854,7 @@ var SpacesServiceImpl = class {
2852
2854
  } else {
2853
2855
  invariant6(!credential.id, "Id on unsigned credentials is not allowed", {
2854
2856
  F: __dxlog_file11,
2855
- L: 217,
2857
+ L: 224,
2856
2858
  S: this,
2857
2859
  A: [
2858
2860
  "!credential.id",
@@ -2861,7 +2863,7 @@ var SpacesServiceImpl = class {
2861
2863
  });
2862
2864
  invariant6(this._identityManager.identity, "Identity is not available", {
2863
2865
  F: __dxlog_file11,
2864
- L: 218,
2866
+ L: 225,
2865
2867
  S: this,
2866
2868
  A: [
2867
2869
  "this._identityManager.identity",
@@ -2871,7 +2873,7 @@ var SpacesServiceImpl = class {
2871
2873
  const signer = this._identityManager.identity.getIdentityCredentialSigner();
2872
2874
  invariant6(credential.issuer.equals(signer.getIssuer()), void 0, {
2873
2875
  F: __dxlog_file11,
2874
- L: 220,
2876
+ L: 227,
2875
2877
  S: this,
2876
2878
  A: [
2877
2879
  "credential.issuer.equals(signer.getIssuer())",
@@ -2921,7 +2923,7 @@ var SpacesServiceImpl = class {
2921
2923
  const assertion = getCredentialAssertion3(credential);
2922
2924
  invariant6(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
2923
2925
  F: __dxlog_file11,
2924
- L: 254,
2926
+ L: 261,
2925
2927
  S: this,
2926
2928
  A: [
2927
2929
  "assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2931,7 +2933,7 @@ var SpacesServiceImpl = class {
2931
2933
  const myIdentity = this._identityManager.identity;
2932
2934
  invariant6(myIdentity && credential.subject.id.equals(myIdentity.identityKey), void 0, {
2933
2935
  F: __dxlog_file11,
2934
- L: 256,
2936
+ L: 263,
2935
2937
  S: this,
2936
2938
  A: [
2937
2939
  "myIdentity && credential.subject.id.equals(myIdentity.identityKey)",
@@ -2952,10 +2954,10 @@ var SpacesServiceImpl = class {
2952
2954
  });
2953
2955
  }
2954
2956
  return {
2955
- space: this._serializeSpace(dataSpace)
2957
+ space: await this._serializeSpace(dataSpace)
2956
2958
  };
2957
2959
  }
2958
- _serializeSpace(space) {
2960
+ async _serializeSpace(space) {
2959
2961
  return {
2960
2962
  id: space.id,
2961
2963
  spaceKey: space.key,
@@ -2975,7 +2977,7 @@ var SpacesServiceImpl = class {
2975
2977
  totalDataTimeframe: void 0,
2976
2978
  spaceRootUrl: space.databaseRoot?.url
2977
2979
  },
2978
- members: Array.from(space.inner.spaceState.members.values()).map((member) => {
2980
+ members: await Promise.all(Array.from(space.inner.spaceState.members.values()).map(async (member) => {
2979
2981
  const peers = space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key));
2980
2982
  const isMe = this._identityManager.identity?.identityKey.equals(member.key);
2981
2983
  if (isMe) {
@@ -2983,6 +2985,7 @@ var SpacesServiceImpl = class {
2983
2985
  }
2984
2986
  return {
2985
2987
  identity: {
2988
+ did: await createDidFromIdentityKey2(member.key),
2986
2989
  identityKey: member.key,
2987
2990
  profile: member.profile ?? {}
2988
2991
  },
@@ -2990,7 +2993,7 @@ var SpacesServiceImpl = class {
2990
2993
  presence: peers.length > 0 ? SpaceMember4.PresenceState.ONLINE : SpaceMember4.PresenceState.OFFLINE,
2991
2994
  peerStates: peers
2992
2995
  };
2993
- }),
2996
+ })),
2994
2997
  creator: space.inner.spaceState.creator?.key,
2995
2998
  cache: space.cache,
2996
2999
  metrics: space.metrics,
@@ -3035,13 +3038,14 @@ var Identity = class {
3035
3038
  this.space = params.space;
3036
3039
  this._signer = params.signer;
3037
3040
  this._presence = params.presence;
3041
+ this.did = params.did;
3038
3042
  this.identityKey = params.identityKey;
3039
3043
  this.deviceKey = params.deviceKey;
3040
3044
  log9.trace("dxos.halo.device", {
3041
3045
  deviceKey: params.deviceKey
3042
3046
  }, {
3043
3047
  F: __dxlog_file12,
3044
- L: 79,
3048
+ L: 82,
3045
3049
  S: this,
3046
3050
  C: (f, a) => f(...a)
3047
3051
  });
@@ -3143,7 +3147,7 @@ var Identity = class {
3143
3147
  getIdentityCredentialSigner() {
3144
3148
  invariant7(this._deviceStateMachine.deviceCredentialChain, "Device credential chain is not ready.", {
3145
3149
  F: __dxlog_file12,
3146
- L: 195,
3150
+ L: 198,
3147
3151
  S: this,
3148
3152
  A: [
3149
3153
  "this._deviceStateMachine.deviceCredentialChain",
@@ -3187,7 +3191,7 @@ var Identity = class {
3187
3191
  dataFeedKey
3188
3192
  }, {
3189
3193
  F: __dxlog_file12,
3190
- L: 220,
3194
+ L: 223,
3191
3195
  S: this,
3192
3196
  C: (f, a) => f(...a)
3193
3197
  });
@@ -3244,7 +3248,7 @@ Identity = _ts_decorate4([
3244
3248
  import platform from "platform";
3245
3249
  import { Event as Event6 } from "@dxos/async";
3246
3250
  import { Context as Context4 } from "@dxos/context";
3247
- import { createCredentialSignerWithKey as createCredentialSignerWithKey2, CredentialGenerator, generateSeedPhrase, keyPairFromSeedPhrase } from "@dxos/credentials";
3251
+ import { createCredentialSignerWithKey as createCredentialSignerWithKey2, createDidFromIdentityKey as createDidFromIdentityKey3, CredentialGenerator } from "@dxos/credentials";
3248
3252
  import { invariant as invariant8 } from "@dxos/invariant";
3249
3253
  import { PublicKey as PublicKey7 } from "@dxos/keys";
3250
3254
  import { log as log10 } from "@dxos/log";
@@ -3286,7 +3290,7 @@ var IdentityManager = class {
3286
3290
  id: traceId
3287
3291
  }), {
3288
3292
  F: __dxlog_file13,
3289
- L: 121,
3293
+ L: 116,
3290
3294
  S: this,
3291
3295
  C: (f, a) => f(...a)
3292
3296
  });
@@ -3295,7 +3299,7 @@ var IdentityManager = class {
3295
3299
  identityRecord
3296
3300
  }, {
3297
3301
  F: __dxlog_file13,
3298
- L: 124,
3302
+ L: 119,
3299
3303
  S: this,
3300
3304
  C: (f, a) => f(...a)
3301
3305
  });
@@ -3308,7 +3312,7 @@ var IdentityManager = class {
3308
3312
  displayName: this._identity.profileDocument?.displayName
3309
3313
  }, {
3310
3314
  F: __dxlog_file13,
3311
- L: 129,
3315
+ L: 124,
3312
3316
  S: this,
3313
3317
  C: (f, a) => f(...a)
3314
3318
  });
@@ -3318,7 +3322,7 @@ var IdentityManager = class {
3318
3322
  id: traceId
3319
3323
  }), {
3320
3324
  F: __dxlog_file13,
3321
- L: 136,
3325
+ L: 131,
3322
3326
  S: this,
3323
3327
  C: (f, a) => f(...a)
3324
3328
  });
@@ -3326,13 +3330,13 @@ var IdentityManager = class {
3326
3330
  async close() {
3327
3331
  await this._identity?.close(new Context4(void 0, {
3328
3332
  F: __dxlog_file13,
3329
- L: 140
3333
+ L: 135
3330
3334
  }));
3331
3335
  }
3332
3336
  async createIdentity({ displayName, deviceProfile } = {}) {
3333
3337
  invariant8(!this._identity, "Identity already exists.", {
3334
3338
  F: __dxlog_file13,
3335
- L: 145,
3339
+ L: 140,
3336
3340
  S: this,
3337
3341
  A: [
3338
3342
  "!this._identity",
@@ -3341,7 +3345,7 @@ var IdentityManager = class {
3341
3345
  });
3342
3346
  log10("creating identity...", void 0, {
3343
3347
  F: __dxlog_file13,
3344
- L: 146,
3348
+ L: 141,
3345
3349
  S: this,
3346
3350
  C: (f, a) => f(...a)
3347
3351
  });
@@ -3359,13 +3363,13 @@ var IdentityManager = class {
3359
3363
  const identity = await this._constructIdentity(identityRecord);
3360
3364
  await identity.open(new Context4(void 0, {
3361
3365
  F: __dxlog_file13,
3362
- L: 161
3366
+ L: 156
3363
3367
  }));
3364
3368
  {
3365
3369
  const generator = new CredentialGenerator(this._keyring, identityRecord.identityKey, identityRecord.deviceKey);
3366
3370
  invariant8(identityRecord.haloSpace.genesisFeedKey, "Genesis feed key is required.", {
3367
3371
  F: __dxlog_file13,
3368
- L: 165,
3372
+ L: 160,
3369
3373
  S: this,
3370
3374
  A: [
3371
3375
  "identityRecord.haloSpace.genesisFeedKey",
@@ -3374,7 +3378,7 @@ var IdentityManager = class {
3374
3378
  });
3375
3379
  invariant8(identityRecord.haloSpace.dataFeedKey, "Data feed key is required.", {
3376
3380
  F: __dxlog_file13,
3377
- L: 166,
3381
+ L: 161,
3378
3382
  S: this,
3379
3383
  A: [
3380
3384
  "identityRecord.haloSpace.dataFeedKey",
@@ -3413,7 +3417,7 @@ var IdentityManager = class {
3413
3417
  displayName: this._identity.profileDocument?.displayName
3414
3418
  }, {
3415
3419
  F: __dxlog_file13,
3416
- L: 204,
3420
+ L: 199,
3417
3421
  S: this,
3418
3422
  C: (f, a) => f(...a)
3419
3423
  });
@@ -3424,7 +3428,7 @@ var IdentityManager = class {
3424
3428
  profile: identity.profileDocument
3425
3429
  }, {
3426
3430
  F: __dxlog_file13,
3427
- L: 210,
3431
+ L: 205,
3428
3432
  S: this,
3429
3433
  C: (f, a) => f(...a)
3430
3434
  });
@@ -3461,13 +3465,13 @@ var IdentityManager = class {
3461
3465
  params
3462
3466
  }, {
3463
3467
  F: __dxlog_file13,
3464
- L: 249,
3468
+ L: 244,
3465
3469
  S: this,
3466
3470
  C: (f, a) => f(...a)
3467
3471
  });
3468
3472
  invariant8(!this._identity, "Identity already exists.", {
3469
3473
  F: __dxlog_file13,
3470
- L: 250,
3474
+ L: 245,
3471
3475
  S: this,
3472
3476
  A: [
3473
3477
  "!this._identity",
@@ -3488,7 +3492,7 @@ var IdentityManager = class {
3488
3492
  const identity = await this._constructIdentity(identityRecord);
3489
3493
  await identity.open(new Context4(void 0, {
3490
3494
  F: __dxlog_file13,
3491
- L: 264
3495
+ L: 259
3492
3496
  }));
3493
3497
  return {
3494
3498
  identity,
@@ -3507,7 +3511,7 @@ var IdentityManager = class {
3507
3511
  displayName: this._identity.profileDocument?.displayName
3508
3512
  }, {
3509
3513
  F: __dxlog_file13,
3510
- L: 278,
3514
+ L: 273,
3511
3515
  S: this,
3512
3516
  C: (f, a) => f(...a)
3513
3517
  });
@@ -3521,7 +3525,7 @@ var IdentityManager = class {
3521
3525
  deviceKey: identity.deviceKey
3522
3526
  }, {
3523
3527
  F: __dxlog_file13,
3524
- L: 289,
3528
+ L: 284,
3525
3529
  S: this,
3526
3530
  C: (f, a) => f(...a)
3527
3531
  });
@@ -3532,7 +3536,7 @@ var IdentityManager = class {
3532
3536
  async updateProfile(profile) {
3533
3537
  invariant8(this._identity, "Identity not initialized.", {
3534
3538
  F: __dxlog_file13,
3535
- L: 296,
3539
+ L: 291,
3536
3540
  S: this,
3537
3541
  A: [
3538
3542
  "this._identity",
@@ -3563,7 +3567,7 @@ var IdentityManager = class {
3563
3567
  async updateDeviceProfile(profile) {
3564
3568
  invariant8(this._identity, "Identity not initialized.", {
3565
3569
  F: __dxlog_file13,
3566
- L: 313,
3570
+ L: 308,
3567
3571
  S: this,
3568
3572
  A: [
3569
3573
  "this._identity",
@@ -3596,48 +3600,10 @@ var IdentityManager = class {
3596
3600
  profile
3597
3601
  };
3598
3602
  }
3599
- async createRecoveryPhrase() {
3600
- const identity = this._identity;
3601
- invariant8(identity, void 0, {
3602
- F: __dxlog_file13,
3603
- L: 340,
3604
- S: this,
3605
- A: [
3606
- "identity",
3607
- ""
3608
- ]
3609
- });
3610
- const seedphrase = generateSeedPhrase();
3611
- const keypair = keyPairFromSeedPhrase(seedphrase);
3612
- const recoveryKey = PublicKey7.from(keypair.publicKey);
3613
- const identityKey = identity.identityKey;
3614
- const credential = await identity.getIdentityCredentialSigner().createCredential({
3615
- subject: identityKey,
3616
- assertion: {
3617
- "@type": "dxos.halo.credentials.IdentityRecovery",
3618
- recoveryKey,
3619
- identityKey
3620
- }
3621
- });
3622
- const receipt = await identity.controlPipeline.writer.write({
3623
- credential: {
3624
- credential
3625
- }
3626
- });
3627
- await identity.controlPipeline.state.waitUntilTimeframe(new Timeframe3([
3628
- [
3629
- receipt.feedKey,
3630
- receipt.seq
3631
- ]
3632
- ]));
3633
- return {
3634
- seedphrase
3635
- };
3636
- }
3637
3603
  async _constructIdentity(identityRecord) {
3638
3604
  invariant8(!this._identity, void 0, {
3639
3605
  F: __dxlog_file13,
3640
- L: 362,
3606
+ L: 334,
3641
3607
  S: this,
3642
3608
  A: [
3643
3609
  "!this._identity",
@@ -3648,7 +3614,7 @@ var IdentityManager = class {
3648
3614
  identityRecord
3649
3615
  }, {
3650
3616
  F: __dxlog_file13,
3651
- L: 363,
3617
+ L: 335,
3652
3618
  S: this,
3653
3619
  C: (f, a) => f(...a)
3654
3620
  });
@@ -3663,7 +3629,7 @@ var IdentityManager = class {
3663
3629
  });
3664
3630
  invariant8(identityRecord.haloSpace.controlFeedKey, void 0, {
3665
3631
  F: __dxlog_file13,
3666
- L: 376,
3632
+ L: 348,
3667
3633
  S: this,
3668
3634
  A: [
3669
3635
  "identityRecord.haloSpace.controlFeedKey",
@@ -3675,7 +3641,7 @@ var IdentityManager = class {
3675
3641
  });
3676
3642
  invariant8(identityRecord.haloSpace.dataFeedKey, void 0, {
3677
3643
  F: __dxlog_file13,
3678
- L: 380,
3644
+ L: 352,
3679
3645
  S: this,
3680
3646
  A: [
3681
3647
  "identityRecord.haloSpace.dataFeedKey",
@@ -3699,10 +3665,12 @@ var IdentityManager = class {
3699
3665
  });
3700
3666
  await space.setControlFeed(controlFeed);
3701
3667
  await space.setDataFeed(dataFeed);
3668
+ const did = await createDidFromIdentityKey3(identityRecord.identityKey);
3702
3669
  const identity = new Identity({
3703
3670
  space,
3704
3671
  presence,
3705
3672
  signer: this._keyring,
3673
+ did,
3706
3674
  identityKey: identityRecord.identityKey,
3707
3675
  deviceKey: identityRecord.deviceKey,
3708
3676
  edgeConnection: this._edgeConnection,
@@ -3712,7 +3680,7 @@ var IdentityManager = class {
3712
3680
  identityKey: identityRecord.identityKey
3713
3681
  }, {
3714
3682
  F: __dxlog_file13,
3715
- L: 409,
3683
+ L: 383,
3716
3684
  S: this,
3717
3685
  C: (f, a) => f(...a)
3718
3686
  });
@@ -3737,7 +3705,7 @@ var IdentityManager = class {
3737
3705
  onAuthFailure: () => {
3738
3706
  log10.warn("auth failure", void 0, {
3739
3707
  F: __dxlog_file13,
3740
- L: 434,
3708
+ L: 408,
3741
3709
  S: this,
3742
3710
  C: (f, a) => f(...a)
3743
3711
  });
@@ -3761,7 +3729,7 @@ IdentityManager = _ts_decorate5([
3761
3729
 
3762
3730
  // packages/sdk/client-services/src/packlets/identity/identity-service.ts
3763
3731
  import { Trigger as Trigger4, sleep as sleep2 } from "@dxos/async";
3764
- import { Stream as Stream8 } from "@dxos/codec-protobuf";
3732
+ import { Stream as Stream8 } from "@dxos/codec-protobuf/stream";
3765
3733
  import { Resource as Resource5 } from "@dxos/context";
3766
3734
  import { createCredential as createCredential2, signPresentation } from "@dxos/credentials";
3767
3735
  import { invariant as invariant9 } from "@dxos/invariant";
@@ -3800,7 +3768,7 @@ var IdentityServiceImpl = class extends Resource5 {
3800
3768
  const identity = this._identityManager.identity;
3801
3769
  invariant9(identity, void 0, {
3802
3770
  F: __dxlog_file14,
3803
- L: 60,
3771
+ L: 61,
3804
3772
  S: this,
3805
3773
  A: [
3806
3774
  "identity",
@@ -3823,6 +3791,7 @@ var IdentityServiceImpl = class extends Resource5 {
3823
3791
  return void 0;
3824
3792
  }
3825
3793
  return {
3794
+ did: this._identityManager.identity.did,
3826
3795
  identityKey: this._identityManager.identity.identityKey,
3827
3796
  spaceKey: this._identityManager.identity.space.key,
3828
3797
  profile: this._identityManager.identity.profileDocument
@@ -3831,7 +3800,7 @@ var IdentityServiceImpl = class extends Resource5 {
3831
3800
  async updateProfile(profile) {
3832
3801
  invariant9(this._identityManager.identity, "Identity not initialized.", {
3833
3802
  F: __dxlog_file14,
3834
- L: 86,
3803
+ L: 88,
3835
3804
  S: this,
3836
3805
  A: [
3837
3806
  "this._identityManager.identity",
@@ -3842,18 +3811,29 @@ var IdentityServiceImpl = class extends Resource5 {
3842
3811
  await this._onProfileUpdate?.(this._identityManager.identity.profileDocument);
3843
3812
  return this._getIdentity();
3844
3813
  }
3845
- async createRecoveryPhrase() {
3846
- return this._recoveryManager.createRecoveryPhrase();
3814
+ async createRecoveryCredential(request) {
3815
+ return this._recoveryManager.createRecoveryCredential(request);
3816
+ }
3817
+ async requestRecoveryChallenge() {
3818
+ return this._recoveryManager.requestRecoveryChallenge();
3847
3819
  }
3848
3820
  async recoverIdentity(request) {
3849
- await this._recoveryManager.recoverIdentity(request);
3821
+ if (request.recoveryCode) {
3822
+ await this._recoveryManager.recoverIdentity({
3823
+ recoveryCode: request.recoveryCode
3824
+ });
3825
+ } else if (request.external) {
3826
+ await this._recoveryManager.recoverIdentityWithExternalSignature(request.external);
3827
+ } else {
3828
+ throw new Error("Invalid request.");
3829
+ }
3850
3830
  return this._getIdentity();
3851
3831
  }
3852
3832
  // TODO(burdon): Rename createPresentation?
3853
3833
  async signPresentation({ presentation, nonce }) {
3854
3834
  invariant9(this._identityManager.identity, "Identity not initialized.", {
3855
3835
  F: __dxlog_file14,
3856
- L: 103,
3836
+ L: 116,
3857
3837
  S: this,
3858
3838
  A: [
3859
3839
  "this._identityManager.identity",
@@ -3872,7 +3852,7 @@ var IdentityServiceImpl = class extends Resource5 {
3872
3852
  const identity = this._identityManager.identity;
3873
3853
  invariant9(identity, "Identity not initialized.", {
3874
3854
  F: __dxlog_file14,
3875
- L: 117,
3855
+ L: 130,
3876
3856
  S: this,
3877
3857
  A: [
3878
3858
  "identity",
@@ -3910,7 +3890,7 @@ var IdentityServiceImpl = class extends Resource5 {
3910
3890
  duplicate: space.id
3911
3891
  }, {
3912
3892
  F: __dxlog_file14,
3913
- L: 151,
3893
+ L: 164,
3914
3894
  S: this,
3915
3895
  C: (f, a) => f(...a)
3916
3896
  });
@@ -3924,7 +3904,7 @@ var IdentityServiceImpl = class extends Resource5 {
3924
3904
  }, (err) => {
3925
3905
  log11.catch(err, void 0, {
3926
3906
  F: __dxlog_file14,
3927
- L: 162,
3907
+ L: 175,
3928
3908
  S: this,
3929
3909
  C: (f, a) => f(...a)
3930
3910
  });
@@ -4705,14 +4685,14 @@ var DeviceInvitationProtocol = class {
4705
4685
 
4706
4686
  // packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
4707
4687
  import { scheduleTask as scheduleTask7, TimeoutError as TimeoutError2 } from "@dxos/async";
4708
- import { INVITATION_TIMEOUT } from "@dxos/client-protocol";
4688
+ import { INVITATION_TIMEOUT, getExpirationTime } from "@dxos/client-protocol";
4709
4689
  import { ContextDisposedError as ContextDisposedError3 } from "@dxos/context";
4710
4690
  import { createKeyPair, sign as sign2 } from "@dxos/crypto";
4711
4691
  import { invariant as invariant15 } from "@dxos/invariant";
4712
4692
  import { PublicKey as PublicKey11 } from "@dxos/keys";
4713
4693
  import { log as log18 } from "@dxos/log";
4714
4694
  import { createTeleportProtocolFactory } from "@dxos/network-manager";
4715
- import { InvalidInvitationExtensionRoleError as InvalidInvitationExtensionRoleError3, trace as trace7 } from "@dxos/protocols";
4695
+ import { InvalidInvitationError, InvalidInvitationExtensionRoleError as InvalidInvitationExtensionRoleError3, trace as trace7 } from "@dxos/protocols";
4716
4696
  import { Invitation as Invitation7 } from "@dxos/protocols/proto/dxos/client/services";
4717
4697
  import { AuthenticationResponse as AuthenticationResponse2 } from "@dxos/protocols/proto/dxos/halo/invitations";
4718
4698
  import { InvitationOptions as InvitationOptions4 } from "@dxos/protocols/proto/dxos/halo/invitations";
@@ -4735,6 +4715,12 @@ import { Invitation as Invitation3 } from "@dxos/protocols/proto/dxos/client/ser
4735
4715
  var stateToString = (state) => {
4736
4716
  return Object.entries(Invitation3.State).find(([key, val]) => val === state)?.[0] ?? "unknown";
4737
4717
  };
4718
+ var computeExpirationTime = (invitation) => {
4719
+ if (!invitation.lifetime) {
4720
+ return;
4721
+ }
4722
+ return new Date((invitation.created?.getTime() ?? Date.now()) + invitation.lifetime * 1e3);
4723
+ };
4738
4724
  var tryAcquireBeforeContextDisposed = async (ctx, mutex) => {
4739
4725
  let guard;
4740
4726
  return cancelWithContext3(ctx, (async () => {
@@ -5750,18 +5736,19 @@ var InvitationsHandler = class {
5750
5736
  });
5751
5737
  return extension;
5752
5738
  };
5753
- if (invitation.lifetime && invitation.created) {
5754
- if (invitation.created.getTime() + invitation.lifetime * 1e3 < Date.now()) {
5739
+ const expiresOn = getExpirationTime(invitation);
5740
+ if (expiresOn) {
5741
+ if (expiresOn.getTime() < Date.now()) {
5755
5742
  log18.warn("invitation has already expired", void 0, {
5756
5743
  F: __dxlog_file22,
5757
- L: 193,
5744
+ L: 194,
5758
5745
  S: this,
5759
5746
  C: (f, a) => f(...a)
5760
5747
  });
5761
5748
  guardedState.set(null, Invitation7.State.EXPIRED);
5762
5749
  void ctx.dispose().catch((err) => log18.catch(err, void 0, {
5763
5750
  F: __dxlog_file22,
5764
- L: 195,
5751
+ L: 196,
5765
5752
  S: this,
5766
5753
  C: (f, a) => f(...a)
5767
5754
  }));
@@ -5772,7 +5759,7 @@ var InvitationsHandler = class {
5772
5759
  guardedState.set(null, Invitation7.State.EXPIRED);
5773
5760
  metrics.increment("dxos.invitation.expired");
5774
5761
  await ctx.dispose();
5775
- }, invitation.created.getTime() + invitation.lifetime * 1e3 - Date.now());
5762
+ }, expiresOn.getTime() - Date.now());
5776
5763
  }
5777
5764
  let swarmConnection;
5778
5765
  scheduleTask7(ctx, async () => {
@@ -5788,7 +5775,7 @@ var InvitationsHandler = class {
5788
5775
  type: invitation.type
5789
5776
  }, {
5790
5777
  F: __dxlog_file22,
5791
- L: 226,
5778
+ L: 227,
5792
5779
  S: this,
5793
5780
  C: (f, a) => f(...a)
5794
5781
  });
@@ -5796,7 +5783,7 @@ var InvitationsHandler = class {
5796
5783
  if (deviceProfile) {
5797
5784
  invariant15(invitation.kind === Invitation7.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
5798
5785
  F: __dxlog_file22,
5799
- L: 235,
5786
+ L: 236,
5800
5787
  S: this,
5801
5788
  A: [
5802
5789
  "invitation.kind === Invitation.Kind.DEVICE",
@@ -5814,7 +5801,7 @@ var InvitationsHandler = class {
5814
5801
  triedPeers: triedPeersIds.size
5815
5802
  }, {
5816
5803
  F: __dxlog_file22,
5817
- L: 243,
5804
+ L: 244,
5818
5805
  S: this,
5819
5806
  C: (f, a) => f(...a)
5820
5807
  });
@@ -5841,7 +5828,7 @@ var InvitationsHandler = class {
5841
5828
  currentState: guardedState.current.state
5842
5829
  }, {
5843
5830
  F: __dxlog_file22,
5844
- L: 271,
5831
+ L: 272,
5845
5832
  S: this,
5846
5833
  C: (f, a) => f(...a)
5847
5834
  });
@@ -5859,7 +5846,7 @@ var InvitationsHandler = class {
5859
5846
  id: traceId
5860
5847
  }), {
5861
5848
  F: __dxlog_file22,
5862
- L: 283,
5849
+ L: 284,
5863
5850
  S: this,
5864
5851
  C: (f, a) => f(...a)
5865
5852
  });
@@ -5871,7 +5858,7 @@ var InvitationsHandler = class {
5871
5858
  ...protocol.toJSON()
5872
5859
  }, {
5873
5860
  F: __dxlog_file22,
5874
- L: 294,
5861
+ L: 295,
5875
5862
  S: this,
5876
5863
  C: (f, a) => f(...a)
5877
5864
  });
@@ -5881,7 +5868,7 @@ var InvitationsHandler = class {
5881
5868
  ...protocol.toJSON()
5882
5869
  }, {
5883
5870
  F: __dxlog_file22,
5884
- L: 298,
5871
+ L: 299,
5885
5872
  S: this,
5886
5873
  C: (f, a) => f(...a)
5887
5874
  });
@@ -5895,7 +5882,7 @@ var InvitationsHandler = class {
5895
5882
  authMethod: introductionResponse.authMethod
5896
5883
  }, {
5897
5884
  F: __dxlog_file22,
5898
- L: 306,
5885
+ L: 307,
5899
5886
  S: this,
5900
5887
  C: (f, a) => f(...a)
5901
5888
  });
@@ -5917,7 +5904,7 @@ var InvitationsHandler = class {
5917
5904
  ...protocol.toJSON()
5918
5905
  }, {
5919
5906
  F: __dxlog_file22,
5920
- L: 336,
5907
+ L: 337,
5921
5908
  S: this,
5922
5909
  C: (f, a) => f(...a)
5923
5910
  });
@@ -5930,7 +5917,7 @@ var InvitationsHandler = class {
5930
5917
  ...protocol.toJSON()
5931
5918
  }, {
5932
5919
  F: __dxlog_file22,
5933
- L: 350,
5920
+ L: 351,
5934
5921
  S: this,
5935
5922
  C: (f, a) => f(...a)
5936
5923
  });
@@ -5943,7 +5930,7 @@ var InvitationsHandler = class {
5943
5930
  id: traceId
5944
5931
  }), {
5945
5932
  F: __dxlog_file22,
5946
- L: 359,
5933
+ L: 360,
5947
5934
  S: this,
5948
5935
  C: (f, a) => f(...a)
5949
5936
  });
@@ -5953,7 +5940,7 @@ var InvitationsHandler = class {
5953
5940
  ...protocol.toJSON()
5954
5941
  }, {
5955
5942
  F: __dxlog_file22,
5956
- L: 362,
5943
+ L: 363,
5957
5944
  S: this,
5958
5945
  C: (f, a) => f(...a)
5959
5946
  });
@@ -5961,7 +5948,7 @@ var InvitationsHandler = class {
5961
5948
  } else {
5962
5949
  log18.verbose("auth failed", err, {
5963
5950
  F: __dxlog_file22,
5964
- L: 365,
5951
+ L: 366,
5965
5952
  S: this,
5966
5953
  C: (f, a) => f(...a)
5967
5954
  });
@@ -5973,7 +5960,7 @@ var InvitationsHandler = class {
5973
5960
  error: err
5974
5961
  }), {
5975
5962
  F: __dxlog_file22,
5976
- L: 369,
5963
+ L: 370,
5977
5964
  S: this,
5978
5965
  C: (f, a) => f(...a)
5979
5966
  });
@@ -5989,7 +5976,7 @@ var InvitationsHandler = class {
5989
5976
  ...protocol.toJSON()
5990
5977
  }, {
5991
5978
  F: __dxlog_file22,
5992
- L: 378,
5979
+ L: 379,
5993
5980
  S: this,
5994
5981
  C: (f, a) => f(...a)
5995
5982
  });
@@ -5997,7 +5984,7 @@ var InvitationsHandler = class {
5997
5984
  } else {
5998
5985
  log18.verbose("auth failed", err, {
5999
5986
  F: __dxlog_file22,
6000
- L: 381,
5987
+ L: 382,
6001
5988
  S: this,
6002
5989
  C: (f, a) => f(...a)
6003
5990
  });
@@ -6014,7 +6001,7 @@ var InvitationsHandler = class {
6014
6001
  ...protocol.toJSON()
6015
6002
  }, {
6016
6003
  F: __dxlog_file22,
6017
- L: 393,
6004
+ L: 394,
6018
6005
  S: this,
6019
6006
  C: (f, a) => f(...a)
6020
6007
  });
@@ -6027,14 +6014,14 @@ var InvitationsHandler = class {
6027
6014
  });
6028
6015
  edgeInvitationHandler.handle(ctx, guardedState, protocol, deviceProfile);
6029
6016
  scheduleTask7(ctx, async () => {
6030
- const error = protocol.checkInvitation(invitation);
6017
+ const error = checkInvitation(protocol, invitation);
6031
6018
  if (error) {
6032
6019
  stream.error(error);
6033
6020
  await ctx.dispose();
6034
6021
  } else {
6035
6022
  invariant15(invitation.swarmKey, void 0, {
6036
6023
  F: __dxlog_file22,
6037
- L: 405,
6024
+ L: 406,
6038
6025
  S: this,
6039
6026
  A: [
6040
6027
  "invitation.swarmKey",
@@ -6078,7 +6065,7 @@ var InvitationsHandler = class {
6078
6065
  for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
6079
6066
  log18("guest waiting for authentication code...", void 0, {
6080
6067
  F: __dxlog_file22,
6081
- L: 457,
6068
+ L: 458,
6082
6069
  S: this,
6083
6070
  C: (f, a) => f(...a)
6084
6071
  });
@@ -6086,7 +6073,7 @@ var InvitationsHandler = class {
6086
6073
  const authCode = await authenticated.wait(options);
6087
6074
  log18("sending authentication request", void 0, {
6088
6075
  F: __dxlog_file22,
6089
- L: 461,
6076
+ L: 462,
6090
6077
  S: this,
6091
6078
  C: (f, a) => f(...a)
6092
6079
  });
@@ -6105,7 +6092,7 @@ var InvitationsHandler = class {
6105
6092
  attempt
6106
6093
  }, {
6107
6094
  F: __dxlog_file22,
6108
- L: 472,
6095
+ L: 473,
6109
6096
  S: this,
6110
6097
  C: (f, a) => f(...a)
6111
6098
  });
@@ -6123,7 +6110,7 @@ var InvitationsHandler = class {
6123
6110
  }
6124
6111
  log18("sending authentication request", void 0, {
6125
6112
  F: __dxlog_file22,
6126
- L: 491,
6113
+ L: 492,
6127
6114
  S: this,
6128
6115
  C: (f, a) => f(...a)
6129
6116
  });
@@ -6136,6 +6123,13 @@ var InvitationsHandler = class {
6136
6123
  }
6137
6124
  }
6138
6125
  };
6126
+ var checkInvitation = (protocol, invitation) => {
6127
+ const expiresOn = getExpirationTime(invitation);
6128
+ if (expiresOn && expiresOn.getTime() < Date.now()) {
6129
+ return new InvalidInvitationError("Invitation already expired.");
6130
+ }
6131
+ return protocol.checkInvitation(invitation);
6132
+ };
6139
6133
  var createAdmissionKeypair = () => {
6140
6134
  const keypair = createKeyPair();
6141
6135
  return {
@@ -6145,7 +6139,7 @@ var createAdmissionKeypair = () => {
6145
6139
  };
6146
6140
 
6147
6141
  // packages/sdk/client-services/src/packlets/invitations/invitations-service.ts
6148
- import { Stream as Stream9 } from "@dxos/codec-protobuf";
6142
+ import { Stream as Stream9 } from "@dxos/codec-protobuf/stream";
6149
6143
  import { QueryInvitationsResponse } from "@dxos/protocols/proto/dxos/client/services";
6150
6144
  import { trace as trace8 } from "@dxos/tracing";
6151
6145
  var InvitationsServiceImpl = class {
@@ -6250,7 +6244,7 @@ import { createCancelDelegatedSpaceInvitationCredential, createDelegatedSpaceInv
6250
6244
  import { writeMessages as writeMessages4 } from "@dxos/feed-store";
6251
6245
  import { invariant as invariant16 } from "@dxos/invariant";
6252
6246
  import { log as log19 } from "@dxos/log";
6253
- import { AlreadyJoinedError as AlreadyJoinedError3, AuthorizationError as AuthorizationError2, InvalidInvitationError, SpaceNotFoundError as SpaceNotFoundError2 } from "@dxos/protocols";
6247
+ import { AlreadyJoinedError as AlreadyJoinedError3, AuthorizationError as AuthorizationError2, InvalidInvitationError as InvalidInvitationError2, SpaceNotFoundError as SpaceNotFoundError2 } from "@dxos/protocols";
6254
6248
  import { Invitation as Invitation8 } from "@dxos/protocols/proto/dxos/client/services";
6255
6249
  import { SpaceMember as SpaceMember6 } from "@dxos/protocols/proto/dxos/halo/credentials";
6256
6250
  var __dxlog_file23 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
@@ -6270,7 +6264,7 @@ var SpaceInvitationProtocol = class {
6270
6264
  }
6271
6265
  checkCanInviteNewMembers() {
6272
6266
  if (this._spaceKey == null) {
6273
- return new InvalidInvitationError("No spaceKey was provided for a space invitation.");
6267
+ return new InvalidInvitationError2("No spaceKey was provided for a space invitation.");
6274
6268
  }
6275
6269
  const space = this._spaceManager.spaces.get(this._spaceKey);
6276
6270
  if (space == null) {
@@ -6284,7 +6278,7 @@ var SpaceInvitationProtocol = class {
6284
6278
  getInvitationContext() {
6285
6279
  invariant16(this._spaceKey, void 0, {
6286
6280
  F: __dxlog_file23,
6287
- L: 64,
6281
+ L: 65,
6288
6282
  S: this,
6289
6283
  A: [
6290
6284
  "this._spaceKey",
@@ -6294,7 +6288,7 @@ var SpaceInvitationProtocol = class {
6294
6288
  const space = this._spaceManager.spaces.get(this._spaceKey);
6295
6289
  invariant16(space, void 0, {
6296
6290
  F: __dxlog_file23,
6297
- L: 66,
6291
+ L: 67,
6298
6292
  S: this,
6299
6293
  A: [
6300
6294
  "space",
@@ -6310,7 +6304,7 @@ var SpaceInvitationProtocol = class {
6310
6304
  async admit(invitation, request, guestProfile) {
6311
6305
  invariant16(this._spaceKey && request.space, void 0, {
6312
6306
  F: __dxlog_file23,
6313
- L: 79,
6307
+ L: 80,
6314
6308
  S: this,
6315
6309
  A: [
6316
6310
  "this._spaceKey && request.space",
@@ -6322,7 +6316,7 @@ var SpaceInvitationProtocol = class {
6322
6316
  guest: request.space.deviceKey
6323
6317
  }, {
6324
6318
  F: __dxlog_file23,
6325
- L: 80,
6319
+ L: 81,
6326
6320
  S: this,
6327
6321
  C: (f, a) => f(...a)
6328
6322
  });
@@ -6344,7 +6338,7 @@ var SpaceInvitationProtocol = class {
6344
6338
  async delegate(invitation) {
6345
6339
  invariant16(this._spaceKey, void 0, {
6346
6340
  F: __dxlog_file23,
6347
- L: 100,
6341
+ L: 101,
6348
6342
  S: this,
6349
6343
  A: [
6350
6344
  "this._spaceKey",
@@ -6354,7 +6348,7 @@ var SpaceInvitationProtocol = class {
6354
6348
  const space = this._spaceManager.spaces.get(this._spaceKey);
6355
6349
  invariant16(space, void 0, {
6356
6350
  F: __dxlog_file23,
6357
- L: 102,
6351
+ L: 103,
6358
6352
  S: this,
6359
6353
  A: [
6360
6354
  "space",
@@ -6364,7 +6358,7 @@ var SpaceInvitationProtocol = class {
6364
6358
  if (invitation.authMethod === Invitation8.AuthMethod.KNOWN_PUBLIC_KEY) {
6365
6359
  invariant16(invitation.guestKeypair?.publicKey, void 0, {
6366
6360
  F: __dxlog_file23,
6367
- L: 104,
6361
+ L: 105,
6368
6362
  S: this,
6369
6363
  A: [
6370
6364
  "invitation.guestKeypair?.publicKey",
@@ -6377,7 +6371,7 @@ var SpaceInvitationProtocol = class {
6377
6371
  id: invitation.invitationId
6378
6372
  }, {
6379
6373
  F: __dxlog_file23,
6380
- L: 107,
6374
+ L: 108,
6381
6375
  S: this,
6382
6376
  C: (f, a) => f(...a)
6383
6377
  });
@@ -6386,13 +6380,13 @@ var SpaceInvitationProtocol = class {
6386
6380
  authMethod: invitation.authMethod,
6387
6381
  swarmKey: invitation.swarmKey,
6388
6382
  role: invitation.role ?? SpaceMember6.Role.ADMIN,
6389
- expiresOn: invitation.lifetime ? new Date((invitation.created?.getTime() ?? Date.now()) + invitation.lifetime) : void 0,
6383
+ expiresOn: computeExpirationTime(invitation),
6390
6384
  multiUse: invitation.multiUse ?? false,
6391
6385
  guestKey: invitation.authMethod === Invitation8.AuthMethod.KNOWN_PUBLIC_KEY ? invitation.guestKeypair.publicKey : void 0
6392
6386
  });
6393
6387
  invariant16(credential.credential, void 0, {
6394
6388
  F: __dxlog_file23,
6395
- L: 127,
6389
+ L: 126,
6396
6390
  S: this,
6397
6391
  A: [
6398
6392
  "credential.credential",
@@ -6407,7 +6401,7 @@ var SpaceInvitationProtocol = class {
6407
6401
  async cancelDelegation(invitation) {
6408
6402
  invariant16(this._spaceKey, void 0, {
6409
6403
  F: __dxlog_file23,
6410
- L: 133,
6404
+ L: 132,
6411
6405
  S: this,
6412
6406
  A: [
6413
6407
  "this._spaceKey",
@@ -6416,7 +6410,7 @@ var SpaceInvitationProtocol = class {
6416
6410
  });
6417
6411
  invariant16(invitation.type === Invitation8.Type.DELEGATED && invitation.delegationCredentialId, void 0, {
6418
6412
  F: __dxlog_file23,
6419
- L: 134,
6413
+ L: 133,
6420
6414
  S: this,
6421
6415
  A: [
6422
6416
  "invitation.type === Invitation.Type.DELEGATED && invitation.delegationCredentialId",
@@ -6426,7 +6420,7 @@ var SpaceInvitationProtocol = class {
6426
6420
  const space = this._spaceManager.spaces.get(this._spaceKey);
6427
6421
  invariant16(space, void 0, {
6428
6422
  F: __dxlog_file23,
6429
- L: 136,
6423
+ L: 135,
6430
6424
  S: this,
6431
6425
  A: [
6432
6426
  "space",
@@ -6438,14 +6432,14 @@ var SpaceInvitationProtocol = class {
6438
6432
  id: invitation.invitationId
6439
6433
  }, {
6440
6434
  F: __dxlog_file23,
6441
- L: 138,
6435
+ L: 137,
6442
6436
  S: this,
6443
6437
  C: (f, a) => f(...a)
6444
6438
  });
6445
6439
  const credential = await createCancelDelegatedSpaceInvitationCredential(this._signingContext.credentialSigner, space.key, invitation.delegationCredentialId);
6446
6440
  invariant16(credential.credential, void 0, {
6447
6441
  F: __dxlog_file23,
6448
- L: 145,
6442
+ L: 144,
6449
6443
  S: this,
6450
6444
  A: [
6451
6445
  "credential.credential",
@@ -6458,7 +6452,7 @@ var SpaceInvitationProtocol = class {
6458
6452
  }
6459
6453
  checkInvitation(invitation) {
6460
6454
  if (invitation.spaceKey == null) {
6461
- return new InvalidInvitationError("No spaceKey was provided for a space invitation.");
6455
+ return new InvalidInvitationError2("No spaceKey was provided for a space invitation.");
6462
6456
  }
6463
6457
  if (this._spaceManager.spaces.has(invitation.spaceKey)) {
6464
6458
  return new AlreadyJoinedError3("Already joined space.");
@@ -6484,7 +6478,7 @@ var SpaceInvitationProtocol = class {
6484
6478
  async accept(response) {
6485
6479
  invariant16(response.space, void 0, {
6486
6480
  F: __dxlog_file23,
6487
- L: 180,
6481
+ L: 179,
6488
6482
  S: this,
6489
6483
  A: [
6490
6484
  "response.space",
@@ -6495,7 +6489,7 @@ var SpaceInvitationProtocol = class {
6495
6489
  const assertion = getCredentialAssertion5(credential);
6496
6490
  invariant16(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
6497
6491
  F: __dxlog_file23,
6498
- L: 183,
6492
+ L: 182,
6499
6493
  S: this,
6500
6494
  A: [
6501
6495
  "assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -6504,7 +6498,7 @@ var SpaceInvitationProtocol = class {
6504
6498
  });
6505
6499
  invariant16(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
6506
6500
  F: __dxlog_file23,
6507
- L: 184,
6501
+ L: 183,
6508
6502
  S: this,
6509
6503
  A: [
6510
6504
  "credential.subject.id.equals(this._signingContext.identityKey)",
@@ -6740,7 +6734,7 @@ var InvitationsManager = class {
6740
6734
  }
6741
6735
  }
6742
6736
  _createInvitation(protocol, _options) {
6743
- 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 ?? {};
6737
+ 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 ?? {};
6744
6738
  const authCode = options?.authCode ?? (authMethod === Invitation9.AuthMethod.SHARED_SECRET ? generatePasscode(AUTHENTICATION_CODE_LENGTH) : void 0);
6745
6739
  return {
6746
6740
  invitationId,
@@ -7165,6 +7159,18 @@ var EdgeAgentManager = class extends Resource6 {
7165
7159
  haloSpaceKey: this._identity.haloSpaceKey.toHex()
7166
7160
  });
7167
7161
  const deviceKey = PublicKey13.fromHex(response.deviceKey);
7162
+ if (await this._identity.authorizedDeviceKeys.has(deviceKey)) {
7163
+ log22.info("agent was already added to HALO, ignoring response", {
7164
+ response
7165
+ }, {
7166
+ F: __dxlog_file26,
7167
+ L: 67,
7168
+ S: this,
7169
+ C: (f, a) => f(...a)
7170
+ });
7171
+ this._updateStatus(EdgeAgentStatus.ACTIVE, deviceKey);
7172
+ return;
7173
+ }
7168
7174
  await this._identity.admitDevice({
7169
7175
  deviceKey,
7170
7176
  controlFeedKey: PublicKey13.fromHex(response.feedKey),
@@ -7173,7 +7179,7 @@ var EdgeAgentManager = class extends Resource6 {
7173
7179
  });
7174
7180
  log22("agent created", response, {
7175
7181
  F: __dxlog_file26,
7176
- L: 73,
7182
+ L: 79,
7177
7183
  S: this,
7178
7184
  C: (f, a) => f(...a)
7179
7185
  });
@@ -7185,7 +7191,7 @@ var EdgeAgentManager = class extends Resource6 {
7185
7191
  isEnabled
7186
7192
  }, {
7187
7193
  F: __dxlog_file26,
7188
- L: 81,
7194
+ L: 87,
7189
7195
  S: this,
7190
7196
  C: (f, a) => f(...a)
7191
7197
  });
@@ -7218,7 +7224,7 @@ var EdgeAgentManager = class extends Resource6 {
7218
7224
  async _fetchAgentStatus() {
7219
7225
  invariant18(this._edgeHttpClient, void 0, {
7220
7226
  F: __dxlog_file26,
7221
- L: 115,
7227
+ L: 121,
7222
7228
  S: this,
7223
7229
  A: [
7224
7230
  "this._edgeHttpClient",
@@ -7228,7 +7234,7 @@ var EdgeAgentManager = class extends Resource6 {
7228
7234
  try {
7229
7235
  log22("fetching agent status", void 0, {
7230
7236
  F: __dxlog_file26,
7231
- L: 117,
7237
+ L: 123,
7232
7238
  S: this,
7233
7239
  C: (f, a) => f(...a)
7234
7240
  });
@@ -7247,7 +7253,7 @@ var EdgeAgentManager = class extends Resource6 {
7247
7253
  err
7248
7254
  }, {
7249
7255
  F: __dxlog_file26,
7250
- L: 127,
7256
+ L: 133,
7251
7257
  S: this,
7252
7258
  C: (f, a) => f(...a)
7253
7259
  });
@@ -7260,7 +7266,7 @@ var EdgeAgentManager = class extends Resource6 {
7260
7266
  retryAfterMs
7261
7267
  }, {
7262
7268
  F: __dxlog_file26,
7263
- L: 132,
7269
+ L: 138,
7264
7270
  S: this,
7265
7271
  C: (f, a) => f(...a)
7266
7272
  });
@@ -7296,7 +7302,7 @@ var EdgeAgentManager = class extends Resource6 {
7296
7302
  spaceId: space.id
7297
7303
  }, {
7298
7304
  F: __dxlog_file26,
7299
- L: 159,
7305
+ L: 165,
7300
7306
  S: this,
7301
7307
  C: (f, a) => f(...a)
7302
7308
  });
@@ -7316,7 +7322,7 @@ var EdgeAgentManager = class extends Resource6 {
7316
7322
  status
7317
7323
  }, {
7318
7324
  F: __dxlog_file26,
7319
- L: 175,
7325
+ L: 181,
7320
7326
  S: this,
7321
7327
  C: (f, a) => f(...a)
7322
7328
  });
@@ -7327,7 +7333,7 @@ _ts_decorate9([
7327
7333
  ], EdgeAgentManager.prototype, "createAgent", null);
7328
7334
 
7329
7335
  // packages/sdk/client-services/src/packlets/agents/edge-agent-service.ts
7330
- import { Stream as Stream11 } from "@dxos/codec-protobuf";
7336
+ import { Stream as Stream11 } from "@dxos/codec-protobuf/stream";
7331
7337
  import { EdgeAgentStatus as EdgeAgentStatus2 } from "@dxos/protocols";
7332
7338
  import { QueryAgentStatusResponse, QueryEdgeStatusResponse } from "@dxos/protocols/proto/dxos/client/services";
7333
7339
  var EdgeAgentServiceImpl = class {
@@ -7406,7 +7412,7 @@ import { trace as Trace3 } from "@dxos/tracing";
7406
7412
  import { safeInstanceof } from "@dxos/util";
7407
7413
 
7408
7414
  // packages/sdk/client-services/src/packlets/identity/identity-recovery-manager.ts
7409
- import { generateSeedPhrase as generateSeedPhrase2, keyPairFromSeedPhrase as keyPairFromSeedPhrase2 } from "@dxos/credentials";
7415
+ import { generateSeedPhrase, keyPairFromSeedPhrase } from "@dxos/credentials";
7410
7416
  import { sign as sign3 } from "@dxos/crypto";
7411
7417
  import { invariant as invariant19 } from "@dxos/invariant";
7412
7418
  import { PublicKey as PublicKey14 } from "@dxos/keys";
@@ -7422,27 +7428,41 @@ var EdgeIdentityRecoveryManager = class {
7422
7428
  this._identityProvider = _identityProvider;
7423
7429
  this._acceptRecoveredIdentity = _acceptRecoveredIdentity;
7424
7430
  }
7425
- async createRecoveryPhrase() {
7431
+ async createRecoveryCredential({ recoveryKey, algorithm }) {
7426
7432
  const identity = this._identityProvider();
7427
7433
  invariant19(identity, void 0, {
7428
7434
  F: __dxlog_file27,
7429
- L: 29,
7435
+ L: 37,
7430
7436
  S: this,
7431
7437
  A: [
7432
7438
  "identity",
7433
7439
  ""
7434
7440
  ]
7435
7441
  });
7436
- const seedphrase = generateSeedPhrase2();
7437
- const keypair = keyPairFromSeedPhrase2(seedphrase);
7438
- const recoveryKey = PublicKey14.from(keypair.publicKey);
7442
+ let recoveryCode;
7443
+ if (!recoveryKey) {
7444
+ recoveryCode = generateSeedPhrase();
7445
+ const keypair = keyPairFromSeedPhrase(recoveryCode);
7446
+ recoveryKey = PublicKey14.from(keypair.publicKey);
7447
+ algorithm = "ED25519";
7448
+ }
7449
+ invariant19(algorithm, "Algorithm is required.", {
7450
+ F: __dxlog_file27,
7451
+ L: 47,
7452
+ S: this,
7453
+ A: [
7454
+ "algorithm",
7455
+ "'Algorithm is required.'"
7456
+ ]
7457
+ });
7439
7458
  const identityKey = identity.identityKey;
7440
7459
  const credential = await identity.getIdentityCredentialSigner().createCredential({
7441
7460
  subject: identityKey,
7442
7461
  assertion: {
7443
7462
  "@type": "dxos.halo.credentials.IdentityRecovery",
7444
7463
  recoveryKey,
7445
- identityKey
7464
+ identityKey,
7465
+ algorithm
7446
7466
  }
7447
7467
  });
7448
7468
  const receipt = await identity.controlPipeline.writer.write({
@@ -7457,20 +7477,81 @@ var EdgeIdentityRecoveryManager = class {
7457
7477
  ]
7458
7478
  ]));
7459
7479
  return {
7460
- seedphrase
7480
+ recoveryCode
7461
7481
  };
7462
7482
  }
7463
- async recoverIdentity(args) {
7483
+ async requestRecoveryChallenge() {
7464
7484
  invariant19(this._edgeClient, "Not connected to EDGE.", {
7465
7485
  F: __dxlog_file27,
7466
- L: 51,
7486
+ L: 66,
7467
7487
  S: this,
7468
7488
  A: [
7469
7489
  "this._edgeClient",
7470
7490
  "'Not connected to EDGE.'"
7471
7491
  ]
7472
7492
  });
7473
- const recoveryKeypair = keyPairFromSeedPhrase2(args.seedphrase);
7493
+ const deviceKey = await this._keyring.createKey();
7494
+ const controlFeedKey = await this._keyring.createKey();
7495
+ const request = {
7496
+ deviceKey: deviceKey.toHex(),
7497
+ controlFeedKey: controlFeedKey.toHex()
7498
+ };
7499
+ try {
7500
+ await this._edgeClient.recoverIdentity(request);
7501
+ throw new Error("No challenge received.");
7502
+ } catch (error) {
7503
+ if (!(error instanceof EdgeAuthChallengeError2)) {
7504
+ throw error;
7505
+ }
7506
+ return {
7507
+ deviceKey,
7508
+ controlFeedKey,
7509
+ challenge: error.challenge
7510
+ };
7511
+ }
7512
+ }
7513
+ async recoverIdentityWithExternalSignature({ identityDid, deviceKey, controlFeedKey, signature, clientDataJson, authenticatorData }) {
7514
+ invariant19(this._edgeClient, "Not connected to EDGE.", {
7515
+ F: __dxlog_file27,
7516
+ L: 98,
7517
+ S: this,
7518
+ A: [
7519
+ "this._edgeClient",
7520
+ "'Not connected to EDGE.'"
7521
+ ]
7522
+ });
7523
+ const request = {
7524
+ identityDid,
7525
+ deviceKey: deviceKey.toHex(),
7526
+ controlFeedKey: controlFeedKey.toHex(),
7527
+ signature: clientDataJson && authenticatorData ? {
7528
+ signature: Buffer.from(signature).toString("base64"),
7529
+ clientDataJson: Buffer.from(clientDataJson).toString("base64"),
7530
+ authenticatorData: Buffer.from(authenticatorData).toString("base64")
7531
+ } : Buffer.from(signature).toString("base64")
7532
+ };
7533
+ const response = await this._edgeClient.recoverIdentity(request);
7534
+ await this._acceptRecoveredIdentity({
7535
+ authorizedDeviceCredential: decodeCredential(response.deviceAuthCredential),
7536
+ haloGenesisFeedKey: PublicKey14.fromHex(response.genesisFeedKey),
7537
+ haloSpaceKey: PublicKey14.fromHex(response.haloSpaceKey),
7538
+ identityKey: PublicKey14.fromHex(response.identityKey),
7539
+ deviceKey,
7540
+ controlFeedKey,
7541
+ dataFeedKey: await this._keyring.createKey()
7542
+ });
7543
+ }
7544
+ async recoverIdentity({ recoveryCode }) {
7545
+ invariant19(this._edgeClient, "Not connected to EDGE.", {
7546
+ F: __dxlog_file27,
7547
+ L: 128,
7548
+ S: this,
7549
+ A: [
7550
+ "this._edgeClient",
7551
+ "'Not connected to EDGE.'"
7552
+ ]
7553
+ });
7554
+ const recoveryKeypair = keyPairFromSeedPhrase(recoveryCode);
7474
7555
  const recoveryKey = PublicKey14.from(recoveryKeypair.publicKey);
7475
7556
  const deviceKey = await this._keyring.createKey();
7476
7557
  const controlFeedKey = await this._keyring.createKey();
@@ -7494,7 +7575,7 @@ var EdgeIdentityRecoveryManager = class {
7494
7575
  }
7495
7576
  log23.info("recovering identity", response, {
7496
7577
  F: __dxlog_file27,
7497
- L: 77,
7578
+ L: 154,
7498
7579
  S: this,
7499
7580
  C: (f, a) => f(...a)
7500
7581
  });
@@ -8234,7 +8315,7 @@ import { WebsocketRpcClient } from "@dxos/websocket-rpc";
8234
8315
 
8235
8316
  // packages/sdk/client-services/src/packlets/devices/devices-service.ts
8236
8317
  import { EventSubscriptions as EventSubscriptions3 } from "@dxos/async";
8237
- import { Stream as Stream12 } from "@dxos/codec-protobuf";
8318
+ import { Stream as Stream12 } from "@dxos/codec-protobuf/stream";
8238
8319
  import { invariant as invariant22 } from "@dxos/invariant";
8239
8320
  import { Device as Device2, DeviceKind as DeviceKind2 } from "@dxos/protocols/proto/dxos/client/services";
8240
8321
  var __dxlog_file30 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
@@ -8324,7 +8405,7 @@ var DevicesServiceImpl = class {
8324
8405
 
8325
8406
  // packages/sdk/client-services/src/packlets/identity/contacts-service.ts
8326
8407
  import { EventSubscriptions as EventSubscriptions4, scheduleTask as scheduleTask9, UpdateScheduler as UpdateScheduler2 } from "@dxos/async";
8327
- import { Stream as Stream13 } from "@dxos/codec-protobuf";
8408
+ import { Stream as Stream13 } from "@dxos/codec-protobuf/stream";
8328
8409
  import { PublicKey as PublicKey17 } from "@dxos/keys";
8329
8410
  import { ComplexMap as ComplexMap5, ComplexSet as ComplexSet6 } from "@dxos/util";
8330
8411
  var ContactsServiceImpl = class {
@@ -8407,7 +8488,7 @@ var ContactsServiceImpl = class {
8407
8488
 
8408
8489
  // packages/sdk/client-services/src/packlets/logging/logging-service.ts
8409
8490
  import { Event as Event10 } from "@dxos/async";
8410
- import { Stream as Stream14 } from "@dxos/codec-protobuf";
8491
+ import { Stream as Stream14 } from "@dxos/codec-protobuf/stream";
8411
8492
  import { PublicKey as PublicKey18 } from "@dxos/keys";
8412
8493
  import { getContextFromEntry, log as log26 } from "@dxos/log";
8413
8494
  import { QueryLogsRequest } from "@dxos/protocols/proto/dxos/client/services";
@@ -8530,7 +8611,7 @@ var shouldLog = (entry2, request) => {
8530
8611
  var LOG_PROCESSING = 0;
8531
8612
 
8532
8613
  // packages/sdk/client-services/src/packlets/network/network-service.ts
8533
- import { Stream as Stream15 } from "@dxos/codec-protobuf";
8614
+ import { Stream as Stream15 } from "@dxos/codec-protobuf/stream";
8534
8615
  var NetworkServiceImpl = class {
8535
8616
  constructor(networkManager, signalManager) {
8536
8617
  this.networkManager = networkManager;
@@ -8592,7 +8673,7 @@ var NetworkServiceImpl = class {
8592
8673
  };
8593
8674
 
8594
8675
  // packages/sdk/client-services/src/packlets/system/system-service.ts
8595
- import { Stream as Stream16 } from "@dxos/codec-protobuf";
8676
+ import { Stream as Stream16 } from "@dxos/codec-protobuf/stream";
8596
8677
  import { GetDiagnosticsRequest as GetDiagnosticsRequest2 } from "@dxos/protocols/proto/dxos/client/services";
8597
8678
  import { jsonKeyReplacer as jsonKeyReplacer2 } from "@dxos/util";
8598
8679
  var SystemServiceImpl = class {
@@ -9096,4 +9177,4 @@ export {
9096
9177
  importProfileData,
9097
9178
  ClientServicesHost
9098
9179
  };
9099
- //# sourceMappingURL=chunk-443F7E4C.mjs.map
9180
+ //# sourceMappingURL=chunk-C6HAFZX6.mjs.map