@dxos/client-services 0.7.5-main.ff8607b → 0.7.5-staging.2ff1350

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 (45) hide show
  1. package/dist/lib/browser/{chunk-TS26F5QD.mjs → chunk-VWRYD6LV.mjs} +194 -127
  2. package/dist/lib/browser/chunk-VWRYD6LV.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-25BSUDM4.cjs → chunk-K6H3KWWB.cjs} +192 -125
  7. package/dist/lib/node/chunk-K6H3KWWB.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-XLOQTBJB.mjs → chunk-6OZO2NH7.mjs} +194 -127
  12. package/dist/lib/node-esm/chunk-6OZO2NH7.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/diagnostics/diagnostics-collector.d.ts.map +1 -1
  18. package/dist/types/src/packlets/diagnostics/diagnostics.d.ts.map +1 -1
  19. package/dist/types/src/packlets/identity/identity-manager.d.ts +0 -3
  20. package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
  21. package/dist/types/src/packlets/identity/identity-recovery-manager.d.ts +12 -4
  22. package/dist/types/src/packlets/identity/identity-recovery-manager.d.ts.map +1 -1
  23. package/dist/types/src/packlets/identity/identity-service.d.ts +8 -3
  24. package/dist/types/src/packlets/identity/identity-service.d.ts.map +1 -1
  25. package/dist/types/src/packlets/identity/identity.d.ts +3 -1
  26. package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
  27. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  28. package/dist/types/src/version.d.ts +1 -1
  29. package/dist/types/src/version.d.ts.map +1 -1
  30. package/package.json +39 -38
  31. package/src/packlets/agents/edge-agent-manager.ts +6 -0
  32. package/src/packlets/diagnostics/diagnostics-collector.ts +2 -2
  33. package/src/packlets/diagnostics/diagnostics.ts +17 -13
  34. package/src/packlets/identity/identity-manager.ts +3 -29
  35. package/src/packlets/identity/identity-recovery-manager.ts +86 -9
  36. package/src/packlets/identity/identity-service.ts +16 -3
  37. package/src/packlets/identity/identity.test.ts +2 -1
  38. package/src/packlets/identity/identity.ts +4 -1
  39. package/src/packlets/spaces/data-space-manager.ts +2 -2
  40. package/src/packlets/spaces/edge-feed-replicator.ts +8 -8
  41. package/src/packlets/spaces/spaces-service.ts +30 -20
  42. package/src/version.ts +1 -1
  43. package/dist/lib/browser/chunk-TS26F5QD.mjs.map +0 -7
  44. package/dist/lib/node/chunk-25BSUDM4.cjs.map +0 -7
  45. package/dist/lib/node-esm/chunk-XLOQTBJB.mjs.map +0 -7
@@ -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.ff8607b";
400
+ var DXOS_VERSION = "0.7.5-staging.2ff1350";
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,
@@ -569,7 +571,7 @@ import { ClientServicesProviderResource } from "@dxos/client-protocol";
569
571
  import { ConfigResource } from "@dxos/config";
570
572
  import { GetDiagnosticsRequest } from "@dxos/protocols/proto/dxos/client/services";
571
573
  import { TRACE_PROCESSOR as TRACE_PROCESSOR2 } from "@dxos/tracing";
572
- import { jsonKeyReplacer, nonNullable } from "@dxos/util";
574
+ import { jsonKeyReplacer, isNonNullable } from "@dxos/util";
573
575
  var GET_DIAGNOSTICS_RPC_TIMEOUT = 1e4;
574
576
  var DiagnosticsCollector = class {
575
577
  static {
@@ -602,7 +604,7 @@ var findSystemServiceProvider = () => {
602
604
  };
603
605
  var findConfigs = () => {
604
606
  const configs = TRACE_PROCESSOR2.findResourcesByAnnotation(ConfigResource);
605
- return configs.map((r) => r.instance.deref()).filter(nonNullable);
607
+ return configs.map((r) => r.instance.deref()).filter(isNonNullable);
606
608
  };
607
609
 
608
610
  // packages/sdk/client-services/src/packlets/identity/authenticator.ts
@@ -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,
@@ -959,7 +961,7 @@ var EdgeFeedReplicator = class extends Resource {
959
961
  return;
960
962
  }
961
963
  if (message.type === "data") {
962
- log3.info("sending blocks", {
964
+ log3("sending blocks", {
963
965
  feedKey: message.feedKey,
964
966
  blocks: message.blocks.map((b) => b.index)
965
967
  }, {
@@ -1034,7 +1036,7 @@ var EdgeFeedReplicator = class extends Resource {
1034
1036
  feedKey
1035
1037
  };
1036
1038
  if (message.length > feed.length) {
1037
- log3.info("requesting missing blocks", logMeta, {
1039
+ log3("requesting missing blocks", logMeta, {
1038
1040
  F: __dxlog_file5,
1039
1041
  L: 194,
1040
1042
  S: this,
@@ -1049,7 +1051,7 @@ var EdgeFeedReplicator = class extends Resource {
1049
1051
  }
1050
1052
  });
1051
1053
  } else if (message.length < feed.length) {
1052
- log3.info("pushing blocks to remote", logMeta, {
1054
+ log3("pushing blocks to remote", logMeta, {
1053
1055
  F: __dxlog_file5,
1054
1056
  L: 202,
1055
1057
  S: this,
@@ -1065,7 +1067,7 @@ var EdgeFeedReplicator = class extends Resource {
1065
1067
  }
1066
1068
  }
1067
1069
  case "data": {
1068
- log3.info("received data", {
1070
+ log3("received data", {
1069
1071
  feed: message.feedKey,
1070
1072
  blocks: message.blocks.map((b) => b.index)
1071
1073
  }, {
@@ -1104,7 +1106,7 @@ var EdgeFeedReplicator = class extends Resource {
1104
1106
  });
1105
1107
  }
1106
1108
  async _pushBlocks(feed, from, to) {
1107
- log3.info("pushing blocks", {
1109
+ log3("pushing blocks", {
1108
1110
  feed: feed.key.toHex(),
1109
1111
  from,
1110
1112
  to
@@ -1143,7 +1145,7 @@ var EdgeFeedReplicator = class extends Resource {
1143
1145
  this._remoteLength.set(feed.key, to);
1144
1146
  }
1145
1147
  async _integrateBlocks(feed, blocks) {
1146
- log3.info("integrating blocks", {
1148
+ log3("integrating blocks", {
1147
1149
  feed: feed.key.toHex(),
1148
1150
  blocks: blocks.length
1149
1151
  }, {
@@ -2450,7 +2452,7 @@ var DataSpaceManager = class extends Resource4 {
2450
2452
  });
2451
2453
  dataSpace.postOpen.append(async () => {
2452
2454
  const setting = dataSpace.getEdgeReplicationSetting();
2453
- if (setting === EdgeReplicationSetting.ENABLED) {
2455
+ if (!setting || setting === EdgeReplicationSetting.ENABLED) {
2454
2456
  await this._echoEdgeReplicator?.connectToSpace(dataSpace.id);
2455
2457
  } else if (this._echoEdgeReplicator) {
2456
2458
  log6("not connecting EchoEdgeReplicator because of EdgeReplicationSetting", {
@@ -2465,7 +2467,7 @@ var DataSpaceManager = class extends Resource4 {
2465
2467
  });
2466
2468
  dataSpace.preClose.append(async () => {
2467
2469
  const setting = dataSpace.getEdgeReplicationSetting();
2468
- if (setting === EdgeReplicationSetting.ENABLED) {
2470
+ if (!setting || setting === EdgeReplicationSetting.ENABLED) {
2469
2471
  await this._echoEdgeReplicator?.disconnectFromSpace(dataSpace.id);
2470
2472
  }
2471
2473
  });
@@ -2598,7 +2600,7 @@ DataSpaceManager = _ts_decorate3([
2598
2600
  // packages/sdk/client-services/src/packlets/spaces/spaces-service.ts
2599
2601
  import { EventSubscriptions as EventSubscriptions2, UpdateScheduler, scheduleTask as scheduleTask3 } from "@dxos/async";
2600
2602
  import { Stream as Stream7 } from "@dxos/codec-protobuf/stream";
2601
- import { createAdmissionCredentials as createAdmissionCredentials2, getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
2603
+ import { createAdmissionCredentials as createAdmissionCredentials2, createDidFromIdentityKey as createDidFromIdentityKey2, getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
2602
2604
  import { raise } from "@dxos/debug";
2603
2605
  import { writeMessages as writeMessages2 } from "@dxos/feed-store";
2604
2606
  import { invariant as invariant6 } from "@dxos/invariant";
@@ -2654,7 +2656,7 @@ var SpacesServiceImpl = class {
2654
2656
  const credentials = await createAdmissionCredentials2(identity.getIdentityCredentialSigner(), request.memberKey, space.key, space.genesisFeedKey, request.newRole, space.spaceState.membershipChainHeads);
2655
2657
  invariant6(credentials[0].credential, void 0, {
2656
2658
  F: __dxlog_file10,
2657
- L: 106,
2659
+ L: 111,
2658
2660
  S: this,
2659
2661
  A: [
2660
2662
  "credentials[0].credential",
@@ -2664,7 +2666,7 @@ var SpacesServiceImpl = class {
2664
2666
  const spaceMemberCredential = credentials[0].credential.credential;
2665
2667
  invariant6(getCredentialAssertion3(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2666
2668
  F: __dxlog_file10,
2667
- L: 108,
2669
+ L: 113,
2668
2670
  S: this,
2669
2671
  A: [
2670
2672
  "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2677,12 +2679,12 @@ var SpacesServiceImpl = class {
2677
2679
  return new Stream7(({ next, ctx }) => {
2678
2680
  const scheduler = new UpdateScheduler(ctx, async () => {
2679
2681
  const dataSpaceManager = await this._getDataSpaceManager();
2680
- 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)));
2681
2683
  log7("update", () => ({
2682
2684
  ids: spaces.map((space) => space.id)
2683
2685
  }), {
2684
2686
  F: __dxlog_file10,
2685
- L: 119,
2687
+ L: 126,
2686
2688
  S: this,
2687
2689
  C: (f, a) => f(...a)
2688
2690
  });
@@ -2774,7 +2776,7 @@ var SpacesServiceImpl = class {
2774
2776
  } else {
2775
2777
  invariant6(!credential.id, "Id on unsigned credentials is not allowed", {
2776
2778
  F: __dxlog_file10,
2777
- L: 217,
2779
+ L: 224,
2778
2780
  S: this,
2779
2781
  A: [
2780
2782
  "!credential.id",
@@ -2783,7 +2785,7 @@ var SpacesServiceImpl = class {
2783
2785
  });
2784
2786
  invariant6(this._identityManager.identity, "Identity is not available", {
2785
2787
  F: __dxlog_file10,
2786
- L: 218,
2788
+ L: 225,
2787
2789
  S: this,
2788
2790
  A: [
2789
2791
  "this._identityManager.identity",
@@ -2793,7 +2795,7 @@ var SpacesServiceImpl = class {
2793
2795
  const signer = this._identityManager.identity.getIdentityCredentialSigner();
2794
2796
  invariant6(credential.issuer.equals(signer.getIssuer()), void 0, {
2795
2797
  F: __dxlog_file10,
2796
- L: 220,
2798
+ L: 227,
2797
2799
  S: this,
2798
2800
  A: [
2799
2801
  "credential.issuer.equals(signer.getIssuer())",
@@ -2843,7 +2845,7 @@ var SpacesServiceImpl = class {
2843
2845
  const assertion = getCredentialAssertion3(credential);
2844
2846
  invariant6(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
2845
2847
  F: __dxlog_file10,
2846
- L: 254,
2848
+ L: 261,
2847
2849
  S: this,
2848
2850
  A: [
2849
2851
  "assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2853,7 +2855,7 @@ var SpacesServiceImpl = class {
2853
2855
  const myIdentity = this._identityManager.identity;
2854
2856
  invariant6(myIdentity && credential.subject.id.equals(myIdentity.identityKey), void 0, {
2855
2857
  F: __dxlog_file10,
2856
- L: 256,
2858
+ L: 263,
2857
2859
  S: this,
2858
2860
  A: [
2859
2861
  "myIdentity && credential.subject.id.equals(myIdentity.identityKey)",
@@ -2874,10 +2876,10 @@ var SpacesServiceImpl = class {
2874
2876
  });
2875
2877
  }
2876
2878
  return {
2877
- space: this._serializeSpace(dataSpace)
2879
+ space: await this._serializeSpace(dataSpace)
2878
2880
  };
2879
2881
  }
2880
- _serializeSpace(space) {
2882
+ async _serializeSpace(space) {
2881
2883
  return {
2882
2884
  id: space.id,
2883
2885
  spaceKey: space.key,
@@ -2897,7 +2899,7 @@ var SpacesServiceImpl = class {
2897
2899
  totalDataTimeframe: void 0,
2898
2900
  spaceRootUrl: space.databaseRoot?.url
2899
2901
  },
2900
- 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) => {
2901
2903
  const peers = space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key));
2902
2904
  const isMe = this._identityManager.identity?.identityKey.equals(member.key);
2903
2905
  if (isMe) {
@@ -2905,6 +2907,7 @@ var SpacesServiceImpl = class {
2905
2907
  }
2906
2908
  return {
2907
2909
  identity: {
2910
+ did: await createDidFromIdentityKey2(member.key),
2908
2911
  identityKey: member.key,
2909
2912
  profile: member.profile ?? {}
2910
2913
  },
@@ -2912,7 +2915,7 @@ var SpacesServiceImpl = class {
2912
2915
  presence: peers.length > 0 ? SpaceMember4.PresenceState.ONLINE : SpaceMember4.PresenceState.OFFLINE,
2913
2916
  peerStates: peers
2914
2917
  };
2915
- }),
2918
+ })),
2916
2919
  creator: space.inner.spaceState.creator?.key,
2917
2920
  cache: space.cache,
2918
2921
  metrics: space.metrics,
@@ -2957,13 +2960,14 @@ var Identity = class {
2957
2960
  this.space = params.space;
2958
2961
  this._signer = params.signer;
2959
2962
  this._presence = params.presence;
2963
+ this.did = params.did;
2960
2964
  this.identityKey = params.identityKey;
2961
2965
  this.deviceKey = params.deviceKey;
2962
2966
  log8.trace("dxos.halo.device", {
2963
2967
  deviceKey: params.deviceKey
2964
2968
  }, {
2965
2969
  F: __dxlog_file11,
2966
- L: 79,
2970
+ L: 82,
2967
2971
  S: this,
2968
2972
  C: (f, a) => f(...a)
2969
2973
  });
@@ -3065,7 +3069,7 @@ var Identity = class {
3065
3069
  getIdentityCredentialSigner() {
3066
3070
  invariant7(this._deviceStateMachine.deviceCredentialChain, "Device credential chain is not ready.", {
3067
3071
  F: __dxlog_file11,
3068
- L: 195,
3072
+ L: 198,
3069
3073
  S: this,
3070
3074
  A: [
3071
3075
  "this._deviceStateMachine.deviceCredentialChain",
@@ -3109,7 +3113,7 @@ var Identity = class {
3109
3113
  dataFeedKey
3110
3114
  }, {
3111
3115
  F: __dxlog_file11,
3112
- L: 220,
3116
+ L: 223,
3113
3117
  S: this,
3114
3118
  C: (f, a) => f(...a)
3115
3119
  });
@@ -3166,7 +3170,7 @@ Identity = _ts_decorate4([
3166
3170
  import platform from "platform";
3167
3171
  import { Event as Event6 } from "@dxos/async";
3168
3172
  import { Context as Context4 } from "@dxos/context";
3169
- import { createCredentialSignerWithKey as createCredentialSignerWithKey2, CredentialGenerator, generateSeedPhrase, keyPairFromSeedPhrase } from "@dxos/credentials";
3173
+ import { createCredentialSignerWithKey as createCredentialSignerWithKey2, createDidFromIdentityKey as createDidFromIdentityKey3, CredentialGenerator } from "@dxos/credentials";
3170
3174
  import { invariant as invariant8 } from "@dxos/invariant";
3171
3175
  import { PublicKey as PublicKey7 } from "@dxos/keys";
3172
3176
  import { log as log9 } from "@dxos/log";
@@ -3208,7 +3212,7 @@ var IdentityManager = class {
3208
3212
  id: traceId
3209
3213
  }), {
3210
3214
  F: __dxlog_file12,
3211
- L: 121,
3215
+ L: 116,
3212
3216
  S: this,
3213
3217
  C: (f, a) => f(...a)
3214
3218
  });
@@ -3217,7 +3221,7 @@ var IdentityManager = class {
3217
3221
  identityRecord
3218
3222
  }, {
3219
3223
  F: __dxlog_file12,
3220
- L: 124,
3224
+ L: 119,
3221
3225
  S: this,
3222
3226
  C: (f, a) => f(...a)
3223
3227
  });
@@ -3230,7 +3234,7 @@ var IdentityManager = class {
3230
3234
  displayName: this._identity.profileDocument?.displayName
3231
3235
  }, {
3232
3236
  F: __dxlog_file12,
3233
- L: 129,
3237
+ L: 124,
3234
3238
  S: this,
3235
3239
  C: (f, a) => f(...a)
3236
3240
  });
@@ -3240,7 +3244,7 @@ var IdentityManager = class {
3240
3244
  id: traceId
3241
3245
  }), {
3242
3246
  F: __dxlog_file12,
3243
- L: 136,
3247
+ L: 131,
3244
3248
  S: this,
3245
3249
  C: (f, a) => f(...a)
3246
3250
  });
@@ -3248,13 +3252,13 @@ var IdentityManager = class {
3248
3252
  async close() {
3249
3253
  await this._identity?.close(new Context4(void 0, {
3250
3254
  F: __dxlog_file12,
3251
- L: 140
3255
+ L: 135
3252
3256
  }));
3253
3257
  }
3254
3258
  async createIdentity({ displayName, deviceProfile } = {}) {
3255
3259
  invariant8(!this._identity, "Identity already exists.", {
3256
3260
  F: __dxlog_file12,
3257
- L: 145,
3261
+ L: 140,
3258
3262
  S: this,
3259
3263
  A: [
3260
3264
  "!this._identity",
@@ -3263,7 +3267,7 @@ var IdentityManager = class {
3263
3267
  });
3264
3268
  log9("creating identity...", void 0, {
3265
3269
  F: __dxlog_file12,
3266
- L: 146,
3270
+ L: 141,
3267
3271
  S: this,
3268
3272
  C: (f, a) => f(...a)
3269
3273
  });
@@ -3281,13 +3285,13 @@ var IdentityManager = class {
3281
3285
  const identity = await this._constructIdentity(identityRecord);
3282
3286
  await identity.open(new Context4(void 0, {
3283
3287
  F: __dxlog_file12,
3284
- L: 161
3288
+ L: 156
3285
3289
  }));
3286
3290
  {
3287
3291
  const generator = new CredentialGenerator(this._keyring, identityRecord.identityKey, identityRecord.deviceKey);
3288
3292
  invariant8(identityRecord.haloSpace.genesisFeedKey, "Genesis feed key is required.", {
3289
3293
  F: __dxlog_file12,
3290
- L: 165,
3294
+ L: 160,
3291
3295
  S: this,
3292
3296
  A: [
3293
3297
  "identityRecord.haloSpace.genesisFeedKey",
@@ -3296,7 +3300,7 @@ var IdentityManager = class {
3296
3300
  });
3297
3301
  invariant8(identityRecord.haloSpace.dataFeedKey, "Data feed key is required.", {
3298
3302
  F: __dxlog_file12,
3299
- L: 166,
3303
+ L: 161,
3300
3304
  S: this,
3301
3305
  A: [
3302
3306
  "identityRecord.haloSpace.dataFeedKey",
@@ -3335,7 +3339,7 @@ var IdentityManager = class {
3335
3339
  displayName: this._identity.profileDocument?.displayName
3336
3340
  }, {
3337
3341
  F: __dxlog_file12,
3338
- L: 204,
3342
+ L: 199,
3339
3343
  S: this,
3340
3344
  C: (f, a) => f(...a)
3341
3345
  });
@@ -3346,7 +3350,7 @@ var IdentityManager = class {
3346
3350
  profile: identity.profileDocument
3347
3351
  }, {
3348
3352
  F: __dxlog_file12,
3349
- L: 210,
3353
+ L: 205,
3350
3354
  S: this,
3351
3355
  C: (f, a) => f(...a)
3352
3356
  });
@@ -3383,13 +3387,13 @@ var IdentityManager = class {
3383
3387
  params
3384
3388
  }, {
3385
3389
  F: __dxlog_file12,
3386
- L: 249,
3390
+ L: 244,
3387
3391
  S: this,
3388
3392
  C: (f, a) => f(...a)
3389
3393
  });
3390
3394
  invariant8(!this._identity, "Identity already exists.", {
3391
3395
  F: __dxlog_file12,
3392
- L: 250,
3396
+ L: 245,
3393
3397
  S: this,
3394
3398
  A: [
3395
3399
  "!this._identity",
@@ -3410,7 +3414,7 @@ var IdentityManager = class {
3410
3414
  const identity = await this._constructIdentity(identityRecord);
3411
3415
  await identity.open(new Context4(void 0, {
3412
3416
  F: __dxlog_file12,
3413
- L: 264
3417
+ L: 259
3414
3418
  }));
3415
3419
  return {
3416
3420
  identity,
@@ -3429,7 +3433,7 @@ var IdentityManager = class {
3429
3433
  displayName: this._identity.profileDocument?.displayName
3430
3434
  }, {
3431
3435
  F: __dxlog_file12,
3432
- L: 278,
3436
+ L: 273,
3433
3437
  S: this,
3434
3438
  C: (f, a) => f(...a)
3435
3439
  });
@@ -3443,7 +3447,7 @@ var IdentityManager = class {
3443
3447
  deviceKey: identity.deviceKey
3444
3448
  }, {
3445
3449
  F: __dxlog_file12,
3446
- L: 289,
3450
+ L: 284,
3447
3451
  S: this,
3448
3452
  C: (f, a) => f(...a)
3449
3453
  });
@@ -3454,7 +3458,7 @@ var IdentityManager = class {
3454
3458
  async updateProfile(profile) {
3455
3459
  invariant8(this._identity, "Identity not initialized.", {
3456
3460
  F: __dxlog_file12,
3457
- L: 296,
3461
+ L: 291,
3458
3462
  S: this,
3459
3463
  A: [
3460
3464
  "this._identity",
@@ -3485,7 +3489,7 @@ var IdentityManager = class {
3485
3489
  async updateDeviceProfile(profile) {
3486
3490
  invariant8(this._identity, "Identity not initialized.", {
3487
3491
  F: __dxlog_file12,
3488
- L: 313,
3492
+ L: 308,
3489
3493
  S: this,
3490
3494
  A: [
3491
3495
  "this._identity",
@@ -3518,48 +3522,10 @@ var IdentityManager = class {
3518
3522
  profile
3519
3523
  };
3520
3524
  }
3521
- async createRecoveryPhrase() {
3522
- const identity = this._identity;
3523
- invariant8(identity, void 0, {
3524
- F: __dxlog_file12,
3525
- L: 340,
3526
- S: this,
3527
- A: [
3528
- "identity",
3529
- ""
3530
- ]
3531
- });
3532
- const seedphrase = generateSeedPhrase();
3533
- const keypair = keyPairFromSeedPhrase(seedphrase);
3534
- const recoveryKey = PublicKey7.from(keypair.publicKey);
3535
- const identityKey = identity.identityKey;
3536
- const credential = await identity.getIdentityCredentialSigner().createCredential({
3537
- subject: identityKey,
3538
- assertion: {
3539
- "@type": "dxos.halo.credentials.IdentityRecovery",
3540
- recoveryKey,
3541
- identityKey
3542
- }
3543
- });
3544
- const receipt = await identity.controlPipeline.writer.write({
3545
- credential: {
3546
- credential
3547
- }
3548
- });
3549
- await identity.controlPipeline.state.waitUntilTimeframe(new Timeframe3([
3550
- [
3551
- receipt.feedKey,
3552
- receipt.seq
3553
- ]
3554
- ]));
3555
- return {
3556
- seedphrase
3557
- };
3558
- }
3559
3525
  async _constructIdentity(identityRecord) {
3560
3526
  invariant8(!this._identity, void 0, {
3561
3527
  F: __dxlog_file12,
3562
- L: 362,
3528
+ L: 334,
3563
3529
  S: this,
3564
3530
  A: [
3565
3531
  "!this._identity",
@@ -3570,7 +3536,7 @@ var IdentityManager = class {
3570
3536
  identityRecord
3571
3537
  }, {
3572
3538
  F: __dxlog_file12,
3573
- L: 363,
3539
+ L: 335,
3574
3540
  S: this,
3575
3541
  C: (f, a) => f(...a)
3576
3542
  });
@@ -3585,7 +3551,7 @@ var IdentityManager = class {
3585
3551
  });
3586
3552
  invariant8(identityRecord.haloSpace.controlFeedKey, void 0, {
3587
3553
  F: __dxlog_file12,
3588
- L: 376,
3554
+ L: 348,
3589
3555
  S: this,
3590
3556
  A: [
3591
3557
  "identityRecord.haloSpace.controlFeedKey",
@@ -3597,7 +3563,7 @@ var IdentityManager = class {
3597
3563
  });
3598
3564
  invariant8(identityRecord.haloSpace.dataFeedKey, void 0, {
3599
3565
  F: __dxlog_file12,
3600
- L: 380,
3566
+ L: 352,
3601
3567
  S: this,
3602
3568
  A: [
3603
3569
  "identityRecord.haloSpace.dataFeedKey",
@@ -3621,10 +3587,12 @@ var IdentityManager = class {
3621
3587
  });
3622
3588
  await space.setControlFeed(controlFeed);
3623
3589
  await space.setDataFeed(dataFeed);
3590
+ const did = await createDidFromIdentityKey3(identityRecord.identityKey);
3624
3591
  const identity = new Identity({
3625
3592
  space,
3626
3593
  presence,
3627
3594
  signer: this._keyring,
3595
+ did,
3628
3596
  identityKey: identityRecord.identityKey,
3629
3597
  deviceKey: identityRecord.deviceKey,
3630
3598
  edgeConnection: this._edgeConnection,
@@ -3634,7 +3602,7 @@ var IdentityManager = class {
3634
3602
  identityKey: identityRecord.identityKey
3635
3603
  }, {
3636
3604
  F: __dxlog_file12,
3637
- L: 409,
3605
+ L: 383,
3638
3606
  S: this,
3639
3607
  C: (f, a) => f(...a)
3640
3608
  });
@@ -3659,7 +3627,7 @@ var IdentityManager = class {
3659
3627
  onAuthFailure: () => {
3660
3628
  log9.warn("auth failure", void 0, {
3661
3629
  F: __dxlog_file12,
3662
- L: 434,
3630
+ L: 408,
3663
3631
  S: this,
3664
3632
  C: (f, a) => f(...a)
3665
3633
  });
@@ -3722,7 +3690,7 @@ var IdentityServiceImpl = class extends Resource5 {
3722
3690
  const identity = this._identityManager.identity;
3723
3691
  invariant9(identity, void 0, {
3724
3692
  F: __dxlog_file13,
3725
- L: 60,
3693
+ L: 61,
3726
3694
  S: this,
3727
3695
  A: [
3728
3696
  "identity",
@@ -3745,6 +3713,7 @@ var IdentityServiceImpl = class extends Resource5 {
3745
3713
  return void 0;
3746
3714
  }
3747
3715
  return {
3716
+ did: this._identityManager.identity.did,
3748
3717
  identityKey: this._identityManager.identity.identityKey,
3749
3718
  spaceKey: this._identityManager.identity.space.key,
3750
3719
  profile: this._identityManager.identity.profileDocument
@@ -3753,7 +3722,7 @@ var IdentityServiceImpl = class extends Resource5 {
3753
3722
  async updateProfile(profile) {
3754
3723
  invariant9(this._identityManager.identity, "Identity not initialized.", {
3755
3724
  F: __dxlog_file13,
3756
- L: 86,
3725
+ L: 88,
3757
3726
  S: this,
3758
3727
  A: [
3759
3728
  "this._identityManager.identity",
@@ -3764,18 +3733,29 @@ var IdentityServiceImpl = class extends Resource5 {
3764
3733
  await this._onProfileUpdate?.(this._identityManager.identity.profileDocument);
3765
3734
  return this._getIdentity();
3766
3735
  }
3767
- async createRecoveryPhrase() {
3768
- return this._recoveryManager.createRecoveryPhrase();
3736
+ async createRecoveryCredential(request) {
3737
+ return this._recoveryManager.createRecoveryCredential(request);
3738
+ }
3739
+ async requestRecoveryChallenge() {
3740
+ return this._recoveryManager.requestRecoveryChallenge();
3769
3741
  }
3770
3742
  async recoverIdentity(request) {
3771
- 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
+ }
3772
3752
  return this._getIdentity();
3773
3753
  }
3774
3754
  // TODO(burdon): Rename createPresentation?
3775
3755
  async signPresentation({ presentation, nonce }) {
3776
3756
  invariant9(this._identityManager.identity, "Identity not initialized.", {
3777
3757
  F: __dxlog_file13,
3778
- L: 103,
3758
+ L: 116,
3779
3759
  S: this,
3780
3760
  A: [
3781
3761
  "this._identityManager.identity",
@@ -3794,7 +3774,7 @@ var IdentityServiceImpl = class extends Resource5 {
3794
3774
  const identity = this._identityManager.identity;
3795
3775
  invariant9(identity, "Identity not initialized.", {
3796
3776
  F: __dxlog_file13,
3797
- L: 117,
3777
+ L: 130,
3798
3778
  S: this,
3799
3779
  A: [
3800
3780
  "identity",
@@ -3832,7 +3812,7 @@ var IdentityServiceImpl = class extends Resource5 {
3832
3812
  duplicate: space.id
3833
3813
  }, {
3834
3814
  F: __dxlog_file13,
3835
- L: 151,
3815
+ L: 164,
3836
3816
  S: this,
3837
3817
  C: (f, a) => f(...a)
3838
3818
  });
@@ -3846,7 +3826,7 @@ var IdentityServiceImpl = class extends Resource5 {
3846
3826
  }, (err) => {
3847
3827
  log10.catch(err, void 0, {
3848
3828
  F: __dxlog_file13,
3849
- L: 162,
3829
+ L: 175,
3850
3830
  S: this,
3851
3831
  C: (f, a) => f(...a)
3852
3832
  });
@@ -7036,6 +7016,18 @@ var EdgeAgentManager = class extends Resource6 {
7036
7016
  haloSpaceKey: this._identity.haloSpaceKey.toHex()
7037
7017
  });
7038
7018
  const deviceKey = PublicKey13.fromHex(response.deviceKey);
7019
+ if (await this._identity.authorizedDeviceKeys.has(deviceKey)) {
7020
+ log21.info("agent was already added to HALO, ignoring response", {
7021
+ response
7022
+ }, {
7023
+ F: __dxlog_file25,
7024
+ L: 67,
7025
+ S: this,
7026
+ C: (f, a) => f(...a)
7027
+ });
7028
+ this._updateStatus(EdgeAgentStatus.ACTIVE, deviceKey);
7029
+ return;
7030
+ }
7039
7031
  await this._identity.admitDevice({
7040
7032
  deviceKey,
7041
7033
  controlFeedKey: PublicKey13.fromHex(response.feedKey),
@@ -7044,7 +7036,7 @@ var EdgeAgentManager = class extends Resource6 {
7044
7036
  });
7045
7037
  log21("agent created", response, {
7046
7038
  F: __dxlog_file25,
7047
- L: 73,
7039
+ L: 79,
7048
7040
  S: this,
7049
7041
  C: (f, a) => f(...a)
7050
7042
  });
@@ -7056,7 +7048,7 @@ var EdgeAgentManager = class extends Resource6 {
7056
7048
  isEnabled
7057
7049
  }, {
7058
7050
  F: __dxlog_file25,
7059
- L: 81,
7051
+ L: 87,
7060
7052
  S: this,
7061
7053
  C: (f, a) => f(...a)
7062
7054
  });
@@ -7089,7 +7081,7 @@ var EdgeAgentManager = class extends Resource6 {
7089
7081
  async _fetchAgentStatus() {
7090
7082
  invariant19(this._edgeHttpClient, void 0, {
7091
7083
  F: __dxlog_file25,
7092
- L: 115,
7084
+ L: 121,
7093
7085
  S: this,
7094
7086
  A: [
7095
7087
  "this._edgeHttpClient",
@@ -7099,7 +7091,7 @@ var EdgeAgentManager = class extends Resource6 {
7099
7091
  try {
7100
7092
  log21("fetching agent status", void 0, {
7101
7093
  F: __dxlog_file25,
7102
- L: 117,
7094
+ L: 123,
7103
7095
  S: this,
7104
7096
  C: (f, a) => f(...a)
7105
7097
  });
@@ -7118,7 +7110,7 @@ var EdgeAgentManager = class extends Resource6 {
7118
7110
  err
7119
7111
  }, {
7120
7112
  F: __dxlog_file25,
7121
- L: 127,
7113
+ L: 133,
7122
7114
  S: this,
7123
7115
  C: (f, a) => f(...a)
7124
7116
  });
@@ -7131,7 +7123,7 @@ var EdgeAgentManager = class extends Resource6 {
7131
7123
  retryAfterMs
7132
7124
  }, {
7133
7125
  F: __dxlog_file25,
7134
- L: 132,
7126
+ L: 138,
7135
7127
  S: this,
7136
7128
  C: (f, a) => f(...a)
7137
7129
  });
@@ -7167,7 +7159,7 @@ var EdgeAgentManager = class extends Resource6 {
7167
7159
  spaceId: space.id
7168
7160
  }, {
7169
7161
  F: __dxlog_file25,
7170
- L: 159,
7162
+ L: 165,
7171
7163
  S: this,
7172
7164
  C: (f, a) => f(...a)
7173
7165
  });
@@ -7187,7 +7179,7 @@ var EdgeAgentManager = class extends Resource6 {
7187
7179
  status
7188
7180
  }, {
7189
7181
  F: __dxlog_file25,
7190
- L: 175,
7182
+ L: 181,
7191
7183
  S: this,
7192
7184
  C: (f, a) => f(...a)
7193
7185
  });
@@ -7277,7 +7269,7 @@ import { trace as Trace3 } from "@dxos/tracing";
7277
7269
  import { safeInstanceof } from "@dxos/util";
7278
7270
 
7279
7271
  // packages/sdk/client-services/src/packlets/identity/identity-recovery-manager.ts
7280
- import { generateSeedPhrase as generateSeedPhrase2, keyPairFromSeedPhrase as keyPairFromSeedPhrase2 } from "@dxos/credentials";
7272
+ import { generateSeedPhrase, keyPairFromSeedPhrase } from "@dxos/credentials";
7281
7273
  import { sign as sign3 } from "@dxos/crypto";
7282
7274
  import { invariant as invariant20 } from "@dxos/invariant";
7283
7275
  import { PublicKey as PublicKey14 } from "@dxos/keys";
@@ -7293,27 +7285,41 @@ var EdgeIdentityRecoveryManager = class {
7293
7285
  this._identityProvider = _identityProvider;
7294
7286
  this._acceptRecoveredIdentity = _acceptRecoveredIdentity;
7295
7287
  }
7296
- async createRecoveryPhrase() {
7288
+ async createRecoveryCredential({ recoveryKey, algorithm }) {
7297
7289
  const identity = this._identityProvider();
7298
7290
  invariant20(identity, void 0, {
7299
7291
  F: __dxlog_file26,
7300
- L: 29,
7292
+ L: 37,
7301
7293
  S: this,
7302
7294
  A: [
7303
7295
  "identity",
7304
7296
  ""
7305
7297
  ]
7306
7298
  });
7307
- const seedphrase = generateSeedPhrase2();
7308
- const keypair = keyPairFromSeedPhrase2(seedphrase);
7309
- const recoveryKey = PublicKey14.from(keypair.publicKey);
7299
+ let recoveryCode;
7300
+ if (!recoveryKey) {
7301
+ recoveryCode = generateSeedPhrase();
7302
+ const keypair = keyPairFromSeedPhrase(recoveryCode);
7303
+ recoveryKey = PublicKey14.from(keypair.publicKey);
7304
+ algorithm = "ED25519";
7305
+ }
7306
+ invariant20(algorithm, "Algorithm is required.", {
7307
+ F: __dxlog_file26,
7308
+ L: 47,
7309
+ S: this,
7310
+ A: [
7311
+ "algorithm",
7312
+ "'Algorithm is required.'"
7313
+ ]
7314
+ });
7310
7315
  const identityKey = identity.identityKey;
7311
7316
  const credential = await identity.getIdentityCredentialSigner().createCredential({
7312
7317
  subject: identityKey,
7313
7318
  assertion: {
7314
7319
  "@type": "dxos.halo.credentials.IdentityRecovery",
7315
7320
  recoveryKey,
7316
- identityKey
7321
+ identityKey,
7322
+ algorithm
7317
7323
  }
7318
7324
  });
7319
7325
  const receipt = await identity.controlPipeline.writer.write({
@@ -7328,20 +7334,81 @@ var EdgeIdentityRecoveryManager = class {
7328
7334
  ]
7329
7335
  ]));
7330
7336
  return {
7331
- seedphrase
7337
+ recoveryCode
7338
+ };
7339
+ }
7340
+ async requestRecoveryChallenge() {
7341
+ invariant20(this._edgeClient, "Not connected to EDGE.", {
7342
+ F: __dxlog_file26,
7343
+ L: 66,
7344
+ S: this,
7345
+ A: [
7346
+ "this._edgeClient",
7347
+ "'Not connected to EDGE.'"
7348
+ ]
7349
+ });
7350
+ const deviceKey = await this._keyring.createKey();
7351
+ const controlFeedKey = await this._keyring.createKey();
7352
+ const request = {
7353
+ deviceKey: deviceKey.toHex(),
7354
+ controlFeedKey: controlFeedKey.toHex()
7355
+ };
7356
+ try {
7357
+ await this._edgeClient.recoverIdentity(request);
7358
+ throw new Error("No challenge received.");
7359
+ } catch (error) {
7360
+ if (!(error instanceof EdgeAuthChallengeError2)) {
7361
+ throw error;
7362
+ }
7363
+ return {
7364
+ deviceKey,
7365
+ controlFeedKey,
7366
+ challenge: error.challenge
7367
+ };
7368
+ }
7369
+ }
7370
+ async recoverIdentityWithExternalSignature({ identityDid, deviceKey, controlFeedKey, signature, clientDataJson, authenticatorData }) {
7371
+ invariant20(this._edgeClient, "Not connected to EDGE.", {
7372
+ F: __dxlog_file26,
7373
+ L: 98,
7374
+ S: this,
7375
+ A: [
7376
+ "this._edgeClient",
7377
+ "'Not connected to EDGE.'"
7378
+ ]
7379
+ });
7380
+ const request = {
7381
+ identityDid,
7382
+ deviceKey: deviceKey.toHex(),
7383
+ controlFeedKey: controlFeedKey.toHex(),
7384
+ signature: clientDataJson && authenticatorData ? {
7385
+ signature: Buffer.from(signature).toString("base64"),
7386
+ clientDataJson: Buffer.from(clientDataJson).toString("base64"),
7387
+ authenticatorData: Buffer.from(authenticatorData).toString("base64")
7388
+ } : Buffer.from(signature).toString("base64")
7332
7389
  };
7390
+ const response = await this._edgeClient.recoverIdentity(request);
7391
+ await this._acceptRecoveredIdentity({
7392
+ authorizedDeviceCredential: decodeCredential(response.deviceAuthCredential),
7393
+ haloGenesisFeedKey: PublicKey14.fromHex(response.genesisFeedKey),
7394
+ haloSpaceKey: PublicKey14.fromHex(response.haloSpaceKey),
7395
+ identityKey: PublicKey14.fromHex(response.identityKey),
7396
+ deviceKey,
7397
+ controlFeedKey,
7398
+ dataFeedKey: await this._keyring.createKey()
7399
+ });
7333
7400
  }
7334
- async recoverIdentity(args) {
7401
+ async recoverIdentity({ recoveryCode }) {
7335
7402
  invariant20(this._edgeClient, "Not connected to EDGE.", {
7336
7403
  F: __dxlog_file26,
7337
- L: 51,
7404
+ L: 128,
7338
7405
  S: this,
7339
7406
  A: [
7340
7407
  "this._edgeClient",
7341
7408
  "'Not connected to EDGE.'"
7342
7409
  ]
7343
7410
  });
7344
- const recoveryKeypair = keyPairFromSeedPhrase2(args.seedphrase);
7411
+ const recoveryKeypair = keyPairFromSeedPhrase(recoveryCode);
7345
7412
  const recoveryKey = PublicKey14.from(recoveryKeypair.publicKey);
7346
7413
  const deviceKey = await this._keyring.createKey();
7347
7414
  const controlFeedKey = await this._keyring.createKey();
@@ -7365,7 +7432,7 @@ var EdgeIdentityRecoveryManager = class {
7365
7432
  }
7366
7433
  log22.info("recovering identity", response, {
7367
7434
  F: __dxlog_file26,
7368
- L: 77,
7435
+ L: 154,
7369
7436
  S: this,
7370
7437
  C: (f, a) => f(...a)
7371
7438
  });
@@ -8967,4 +9034,4 @@ export {
8967
9034
  importProfileData,
8968
9035
  ClientServicesHost
8969
9036
  };
8970
- //# sourceMappingURL=chunk-XLOQTBJB.mjs.map
9037
+ //# sourceMappingURL=chunk-6OZO2NH7.mjs.map