@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
@@ -26,8 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var chunk_25BSUDM4_exports = {};
30
- __export(chunk_25BSUDM4_exports, {
29
+ var chunk_K6H3KWWB_exports = {};
30
+ __export(chunk_K6H3KWWB_exports, {
31
31
  ClientRpcServer: () => ClientRpcServer,
32
32
  ClientServicesHost: () => ClientServicesHost,
33
33
  DataSpace: () => DataSpace,
@@ -72,7 +72,7 @@ __export(chunk_25BSUDM4_exports, {
72
72
  subscribeToSpaces: () => subscribeToSpaces,
73
73
  subscribeToSwarmInfo: () => subscribeToSwarmInfo
74
74
  });
75
- module.exports = __toCommonJS(chunk_25BSUDM4_exports);
75
+ module.exports = __toCommonJS(chunk_K6H3KWWB_exports);
76
76
  var import_async = require("@dxos/async");
77
77
  var import_stream = require("@dxos/codec-protobuf/stream");
78
78
  var import_feed_store = require("@dxos/feed-store");
@@ -735,7 +735,7 @@ var DevtoolsServiceImpl = class {
735
735
  });
736
736
  }
737
737
  };
738
- var DXOS_VERSION = "0.7.5-main.ff8607b";
738
+ var DXOS_VERSION = "0.7.5-staging.2ff1350";
739
739
  var getPlatform = () => {
740
740
  if (process.browser) {
741
741
  if (typeof window !== "undefined") {
@@ -799,6 +799,7 @@ var createDiagnostics = async (clientServices, serviceContext, config) => {
799
799
  const identity = serviceContext.identityManager.identity;
800
800
  if (identity) {
801
801
  diagnostics.identity = {
802
+ did: identity.did,
802
803
  identityKey: identity.identityKey,
803
804
  spaceKey: identity.space.key,
804
805
  profile: identity.profileDocument
@@ -837,16 +838,17 @@ var getSpaceStats = async (space) => {
837
838
  ...credential.subject.assertion,
838
839
  id: credential.id
839
840
  })),
840
- members: Array.from(space.inner.spaceState.members.values()).map((member) => ({
841
+ members: await Promise.all(Array.from(space.inner.spaceState.members.values()).map(async (member) => ({
841
842
  role: member.role,
842
843
  identity: {
844
+ did: await (0, import_credentials.createDidFromIdentityKey)(member.key),
843
845
  identityKey: member.key,
844
846
  profile: {
845
847
  displayName: member.assertion.profile?.displayName
846
848
  }
847
849
  },
848
850
  presence: space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key)).length > 0 ? import_services.SpaceMember.PresenceState.ONLINE : import_services.SpaceMember.PresenceState.OFFLINE
849
- })),
851
+ }))),
850
852
  pipeline: {
851
853
  // TODO(burdon): Pick properties from credentials if needed.
852
854
  currentEpoch: space.automergeSpaceState.lastEpoch,
@@ -926,7 +928,7 @@ var findSystemServiceProvider = () => {
926
928
  };
927
929
  var findConfigs = () => {
928
930
  const configs = import_tracing2.TRACE_PROCESSOR.findResourcesByAnnotation(import_config.ConfigResource);
929
- return configs.map((r) => r.instance.deref()).filter(import_util2.nonNullable);
931
+ return configs.map((r) => r.instance.deref()).filter(import_util2.isNonNullable);
930
932
  };
931
933
  var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/authenticator.ts";
932
934
  var Credential = import_proto.schema.getCodecForType("dxos.halo.credentials.Credential");
@@ -1211,7 +1213,7 @@ var EdgeFeedReplicator = class extends import_context3.Resource {
1211
1213
  this._remoteLength.clear();
1212
1214
  }
1213
1215
  async addFeed(feed) {
1214
- import_log3.log.info("addFeed", {
1216
+ (0, import_log3.log)("addFeed", {
1215
1217
  key: feed.key,
1216
1218
  connected: this._connected,
1217
1219
  hasConnectionCtx: !!this._connectionCtx
@@ -1248,7 +1250,7 @@ var EdgeFeedReplicator = class extends import_context3.Resource {
1248
1250
  }
1249
1251
  async _sendMessage(message) {
1250
1252
  if (!this._connectionCtx) {
1251
- import_log3.log.info("message dropped because connection was disposed", void 0, {
1253
+ (0, import_log3.log)("message dropped because connection was disposed", void 0, {
1252
1254
  F: __dxlog_file5,
1253
1255
  L: 146,
1254
1256
  S: this,
@@ -1257,7 +1259,7 @@ var EdgeFeedReplicator = class extends import_context3.Resource {
1257
1259
  return;
1258
1260
  }
1259
1261
  if (message.type === "data") {
1260
- import_log3.log.info("sending blocks", {
1262
+ (0, import_log3.log)("sending blocks", {
1261
1263
  feedKey: message.feedKey,
1262
1264
  blocks: message.blocks.map((b) => b.index)
1263
1265
  }, {
@@ -1332,7 +1334,7 @@ var EdgeFeedReplicator = class extends import_context3.Resource {
1332
1334
  feedKey
1333
1335
  };
1334
1336
  if (message.length > feed.length) {
1335
- import_log3.log.info("requesting missing blocks", logMeta, {
1337
+ (0, import_log3.log)("requesting missing blocks", logMeta, {
1336
1338
  F: __dxlog_file5,
1337
1339
  L: 194,
1338
1340
  S: this,
@@ -1347,7 +1349,7 @@ var EdgeFeedReplicator = class extends import_context3.Resource {
1347
1349
  }
1348
1350
  });
1349
1351
  } else if (message.length < feed.length) {
1350
- import_log3.log.info("pushing blocks to remote", logMeta, {
1352
+ (0, import_log3.log)("pushing blocks to remote", logMeta, {
1351
1353
  F: __dxlog_file5,
1352
1354
  L: 202,
1353
1355
  S: this,
@@ -1363,7 +1365,7 @@ var EdgeFeedReplicator = class extends import_context3.Resource {
1363
1365
  }
1364
1366
  }
1365
1367
  case "data": {
1366
- import_log3.log.info("received data", {
1368
+ (0, import_log3.log)("received data", {
1367
1369
  feed: message.feedKey,
1368
1370
  blocks: message.blocks.map((b) => b.index)
1369
1371
  }, {
@@ -1402,7 +1404,7 @@ var EdgeFeedReplicator = class extends import_context3.Resource {
1402
1404
  });
1403
1405
  }
1404
1406
  async _pushBlocks(feed, from, to) {
1405
- import_log3.log.info("pushing blocks", {
1407
+ (0, import_log3.log)("pushing blocks", {
1406
1408
  feed: feed.key.toHex(),
1407
1409
  from,
1408
1410
  to
@@ -1441,7 +1443,7 @@ var EdgeFeedReplicator = class extends import_context3.Resource {
1441
1443
  this._remoteLength.set(feed.key, to);
1442
1444
  }
1443
1445
  async _integrateBlocks(feed, blocks) {
1444
- import_log3.log.info("integrating blocks", {
1446
+ (0, import_log3.log)("integrating blocks", {
1445
1447
  feed: feed.key.toHex(),
1446
1448
  blocks: blocks.length
1447
1449
  }, {
@@ -2664,7 +2666,7 @@ var DataSpaceManager = class extends import_context7.Resource {
2664
2666
  });
2665
2667
  dataSpace.postOpen.append(async () => {
2666
2668
  const setting = dataSpace.getEdgeReplicationSetting();
2667
- if (setting === import_metadata.EdgeReplicationSetting.ENABLED) {
2669
+ if (!setting || setting === import_metadata.EdgeReplicationSetting.ENABLED) {
2668
2670
  await this._echoEdgeReplicator?.connectToSpace(dataSpace.id);
2669
2671
  } else if (this._echoEdgeReplicator) {
2670
2672
  (0, import_log8.log)("not connecting EchoEdgeReplicator because of EdgeReplicationSetting", {
@@ -2679,7 +2681,7 @@ var DataSpaceManager = class extends import_context7.Resource {
2679
2681
  });
2680
2682
  dataSpace.preClose.append(async () => {
2681
2683
  const setting = dataSpace.getEdgeReplicationSetting();
2682
- if (setting === import_metadata.EdgeReplicationSetting.ENABLED) {
2684
+ if (!setting || setting === import_metadata.EdgeReplicationSetting.ENABLED) {
2683
2685
  await this._echoEdgeReplicator?.disconnectFromSpace(dataSpace.id);
2684
2686
  }
2685
2687
  });
@@ -2856,7 +2858,7 @@ var SpacesServiceImpl = class {
2856
2858
  const credentials = await (0, import_credentials13.createAdmissionCredentials)(identity.getIdentityCredentialSigner(), request.memberKey, space.key, space.genesisFeedKey, request.newRole, space.spaceState.membershipChainHeads);
2857
2859
  (0, import_invariant8.invariant)(credentials[0].credential, void 0, {
2858
2860
  F: __dxlog_file10,
2859
- L: 106,
2861
+ L: 111,
2860
2862
  S: this,
2861
2863
  A: [
2862
2864
  "credentials[0].credential",
@@ -2866,7 +2868,7 @@ var SpacesServiceImpl = class {
2866
2868
  const spaceMemberCredential = credentials[0].credential.credential;
2867
2869
  (0, import_invariant8.invariant)((0, import_credentials13.getCredentialAssertion)(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
2868
2870
  F: __dxlog_file10,
2869
- L: 108,
2871
+ L: 113,
2870
2872
  S: this,
2871
2873
  A: [
2872
2874
  "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -2879,12 +2881,12 @@ var SpacesServiceImpl = class {
2879
2881
  return new import_stream7.Stream(({ next, ctx }) => {
2880
2882
  const scheduler = new import_async12.UpdateScheduler(ctx, async () => {
2881
2883
  const dataSpaceManager = await this._getDataSpaceManager();
2882
- const spaces = Array.from(dataSpaceManager.spaces.values()).map((space) => this._serializeSpace(space));
2884
+ const spaces = await Promise.all(Array.from(dataSpaceManager.spaces.values()).map((space) => this._serializeSpace(space)));
2883
2885
  (0, import_log9.log)("update", () => ({
2884
2886
  ids: spaces.map((space) => space.id)
2885
2887
  }), {
2886
2888
  F: __dxlog_file10,
2887
- L: 119,
2889
+ L: 126,
2888
2890
  S: this,
2889
2891
  C: (f, a) => f(...a)
2890
2892
  });
@@ -2976,7 +2978,7 @@ var SpacesServiceImpl = class {
2976
2978
  } else {
2977
2979
  (0, import_invariant8.invariant)(!credential.id, "Id on unsigned credentials is not allowed", {
2978
2980
  F: __dxlog_file10,
2979
- L: 217,
2981
+ L: 224,
2980
2982
  S: this,
2981
2983
  A: [
2982
2984
  "!credential.id",
@@ -2985,7 +2987,7 @@ var SpacesServiceImpl = class {
2985
2987
  });
2986
2988
  (0, import_invariant8.invariant)(this._identityManager.identity, "Identity is not available", {
2987
2989
  F: __dxlog_file10,
2988
- L: 218,
2990
+ L: 225,
2989
2991
  S: this,
2990
2992
  A: [
2991
2993
  "this._identityManager.identity",
@@ -2995,7 +2997,7 @@ var SpacesServiceImpl = class {
2995
2997
  const signer = this._identityManager.identity.getIdentityCredentialSigner();
2996
2998
  (0, import_invariant8.invariant)(credential.issuer.equals(signer.getIssuer()), void 0, {
2997
2999
  F: __dxlog_file10,
2998
- L: 220,
3000
+ L: 227,
2999
3001
  S: this,
3000
3002
  A: [
3001
3003
  "credential.issuer.equals(signer.getIssuer())",
@@ -3045,7 +3047,7 @@ var SpacesServiceImpl = class {
3045
3047
  const assertion = (0, import_credentials13.getCredentialAssertion)(credential);
3046
3048
  (0, import_invariant8.invariant)(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
3047
3049
  F: __dxlog_file10,
3048
- L: 254,
3050
+ L: 261,
3049
3051
  S: this,
3050
3052
  A: [
3051
3053
  "assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -3055,7 +3057,7 @@ var SpacesServiceImpl = class {
3055
3057
  const myIdentity = this._identityManager.identity;
3056
3058
  (0, import_invariant8.invariant)(myIdentity && credential.subject.id.equals(myIdentity.identityKey), void 0, {
3057
3059
  F: __dxlog_file10,
3058
- L: 256,
3060
+ L: 263,
3059
3061
  S: this,
3060
3062
  A: [
3061
3063
  "myIdentity && credential.subject.id.equals(myIdentity.identityKey)",
@@ -3076,10 +3078,10 @@ var SpacesServiceImpl = class {
3076
3078
  });
3077
3079
  }
3078
3080
  return {
3079
- space: this._serializeSpace(dataSpace)
3081
+ space: await this._serializeSpace(dataSpace)
3080
3082
  };
3081
3083
  }
3082
- _serializeSpace(space) {
3084
+ async _serializeSpace(space) {
3083
3085
  return {
3084
3086
  id: space.id,
3085
3087
  spaceKey: space.key,
@@ -3099,7 +3101,7 @@ var SpacesServiceImpl = class {
3099
3101
  totalDataTimeframe: void 0,
3100
3102
  spaceRootUrl: space.databaseRoot?.url
3101
3103
  },
3102
- members: Array.from(space.inner.spaceState.members.values()).map((member) => {
3104
+ members: await Promise.all(Array.from(space.inner.spaceState.members.values()).map(async (member) => {
3103
3105
  const peers = space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key));
3104
3106
  const isMe = this._identityManager.identity?.identityKey.equals(member.key);
3105
3107
  if (isMe) {
@@ -3107,6 +3109,7 @@ var SpacesServiceImpl = class {
3107
3109
  }
3108
3110
  return {
3109
3111
  identity: {
3112
+ did: await (0, import_credentials13.createDidFromIdentityKey)(member.key),
3110
3113
  identityKey: member.key,
3111
3114
  profile: member.profile ?? {}
3112
3115
  },
@@ -3114,7 +3117,7 @@ var SpacesServiceImpl = class {
3114
3117
  presence: peers.length > 0 ? import_services7.SpaceMember.PresenceState.ONLINE : import_services7.SpaceMember.PresenceState.OFFLINE,
3115
3118
  peerStates: peers
3116
3119
  };
3117
- }),
3120
+ })),
3118
3121
  creator: space.inner.spaceState.creator?.key,
3119
3122
  cache: space.cache,
3120
3123
  metrics: space.metrics,
@@ -3157,13 +3160,14 @@ var Identity = class {
3157
3160
  this.space = params.space;
3158
3161
  this._signer = params.signer;
3159
3162
  this._presence = params.presence;
3163
+ this.did = params.did;
3160
3164
  this.identityKey = params.identityKey;
3161
3165
  this.deviceKey = params.deviceKey;
3162
3166
  import_log6.log.trace("dxos.halo.device", {
3163
3167
  deviceKey: params.deviceKey
3164
3168
  }, {
3165
3169
  F: __dxlog_file11,
3166
- L: 79,
3170
+ L: 82,
3167
3171
  S: this,
3168
3172
  C: (f, a) => f(...a)
3169
3173
  });
@@ -3265,7 +3269,7 @@ var Identity = class {
3265
3269
  getIdentityCredentialSigner() {
3266
3270
  (0, import_invariant6.invariant)(this._deviceStateMachine.deviceCredentialChain, "Device credential chain is not ready.", {
3267
3271
  F: __dxlog_file11,
3268
- L: 195,
3272
+ L: 198,
3269
3273
  S: this,
3270
3274
  A: [
3271
3275
  "this._deviceStateMachine.deviceCredentialChain",
@@ -3309,7 +3313,7 @@ var Identity = class {
3309
3313
  dataFeedKey
3310
3314
  }, {
3311
3315
  F: __dxlog_file11,
3312
- L: 220,
3316
+ L: 223,
3313
3317
  S: this,
3314
3318
  C: (f, a) => f(...a)
3315
3319
  });
@@ -3392,7 +3396,7 @@ var IdentityManager = class {
3392
3396
  id: traceId
3393
3397
  }), {
3394
3398
  F: __dxlog_file12,
3395
- L: 121,
3399
+ L: 116,
3396
3400
  S: this,
3397
3401
  C: (f, a) => f(...a)
3398
3402
  });
@@ -3401,7 +3405,7 @@ var IdentityManager = class {
3401
3405
  identityRecord
3402
3406
  }, {
3403
3407
  F: __dxlog_file12,
3404
- L: 124,
3408
+ L: 119,
3405
3409
  S: this,
3406
3410
  C: (f, a) => f(...a)
3407
3411
  });
@@ -3414,7 +3418,7 @@ var IdentityManager = class {
3414
3418
  displayName: this._identity.profileDocument?.displayName
3415
3419
  }, {
3416
3420
  F: __dxlog_file12,
3417
- L: 129,
3421
+ L: 124,
3418
3422
  S: this,
3419
3423
  C: (f, a) => f(...a)
3420
3424
  });
@@ -3424,7 +3428,7 @@ var IdentityManager = class {
3424
3428
  id: traceId
3425
3429
  }), {
3426
3430
  F: __dxlog_file12,
3427
- L: 136,
3431
+ L: 131,
3428
3432
  S: this,
3429
3433
  C: (f, a) => f(...a)
3430
3434
  });
@@ -3432,13 +3436,13 @@ var IdentityManager = class {
3432
3436
  async close() {
3433
3437
  await this._identity?.close(new import_context8.Context(void 0, {
3434
3438
  F: __dxlog_file12,
3435
- L: 140
3439
+ L: 135
3436
3440
  }));
3437
3441
  }
3438
3442
  async createIdentity({ displayName, deviceProfile } = {}) {
3439
3443
  (0, import_invariant9.invariant)(!this._identity, "Identity already exists.", {
3440
3444
  F: __dxlog_file12,
3441
- L: 145,
3445
+ L: 140,
3442
3446
  S: this,
3443
3447
  A: [
3444
3448
  "!this._identity",
@@ -3447,7 +3451,7 @@ var IdentityManager = class {
3447
3451
  });
3448
3452
  (0, import_log10.log)("creating identity...", void 0, {
3449
3453
  F: __dxlog_file12,
3450
- L: 146,
3454
+ L: 141,
3451
3455
  S: this,
3452
3456
  C: (f, a) => f(...a)
3453
3457
  });
@@ -3465,13 +3469,13 @@ var IdentityManager = class {
3465
3469
  const identity = await this._constructIdentity(identityRecord);
3466
3470
  await identity.open(new import_context8.Context(void 0, {
3467
3471
  F: __dxlog_file12,
3468
- L: 161
3472
+ L: 156
3469
3473
  }));
3470
3474
  {
3471
3475
  const generator = new import_credentials14.CredentialGenerator(this._keyring, identityRecord.identityKey, identityRecord.deviceKey);
3472
3476
  (0, import_invariant9.invariant)(identityRecord.haloSpace.genesisFeedKey, "Genesis feed key is required.", {
3473
3477
  F: __dxlog_file12,
3474
- L: 165,
3478
+ L: 160,
3475
3479
  S: this,
3476
3480
  A: [
3477
3481
  "identityRecord.haloSpace.genesisFeedKey",
@@ -3480,7 +3484,7 @@ var IdentityManager = class {
3480
3484
  });
3481
3485
  (0, import_invariant9.invariant)(identityRecord.haloSpace.dataFeedKey, "Data feed key is required.", {
3482
3486
  F: __dxlog_file12,
3483
- L: 166,
3487
+ L: 161,
3484
3488
  S: this,
3485
3489
  A: [
3486
3490
  "identityRecord.haloSpace.dataFeedKey",
@@ -3519,7 +3523,7 @@ var IdentityManager = class {
3519
3523
  displayName: this._identity.profileDocument?.displayName
3520
3524
  }, {
3521
3525
  F: __dxlog_file12,
3522
- L: 204,
3526
+ L: 199,
3523
3527
  S: this,
3524
3528
  C: (f, a) => f(...a)
3525
3529
  });
@@ -3530,7 +3534,7 @@ var IdentityManager = class {
3530
3534
  profile: identity.profileDocument
3531
3535
  }, {
3532
3536
  F: __dxlog_file12,
3533
- L: 210,
3537
+ L: 205,
3534
3538
  S: this,
3535
3539
  C: (f, a) => f(...a)
3536
3540
  });
@@ -3567,13 +3571,13 @@ var IdentityManager = class {
3567
3571
  params
3568
3572
  }, {
3569
3573
  F: __dxlog_file12,
3570
- L: 249,
3574
+ L: 244,
3571
3575
  S: this,
3572
3576
  C: (f, a) => f(...a)
3573
3577
  });
3574
3578
  (0, import_invariant9.invariant)(!this._identity, "Identity already exists.", {
3575
3579
  F: __dxlog_file12,
3576
- L: 250,
3580
+ L: 245,
3577
3581
  S: this,
3578
3582
  A: [
3579
3583
  "!this._identity",
@@ -3594,7 +3598,7 @@ var IdentityManager = class {
3594
3598
  const identity = await this._constructIdentity(identityRecord);
3595
3599
  await identity.open(new import_context8.Context(void 0, {
3596
3600
  F: __dxlog_file12,
3597
- L: 264
3601
+ L: 259
3598
3602
  }));
3599
3603
  return {
3600
3604
  identity,
@@ -3613,7 +3617,7 @@ var IdentityManager = class {
3613
3617
  displayName: this._identity.profileDocument?.displayName
3614
3618
  }, {
3615
3619
  F: __dxlog_file12,
3616
- L: 278,
3620
+ L: 273,
3617
3621
  S: this,
3618
3622
  C: (f, a) => f(...a)
3619
3623
  });
@@ -3627,7 +3631,7 @@ var IdentityManager = class {
3627
3631
  deviceKey: identity.deviceKey
3628
3632
  }, {
3629
3633
  F: __dxlog_file12,
3630
- L: 289,
3634
+ L: 284,
3631
3635
  S: this,
3632
3636
  C: (f, a) => f(...a)
3633
3637
  });
@@ -3638,7 +3642,7 @@ var IdentityManager = class {
3638
3642
  async updateProfile(profile) {
3639
3643
  (0, import_invariant9.invariant)(this._identity, "Identity not initialized.", {
3640
3644
  F: __dxlog_file12,
3641
- L: 296,
3645
+ L: 291,
3642
3646
  S: this,
3643
3647
  A: [
3644
3648
  "this._identity",
@@ -3669,7 +3673,7 @@ var IdentityManager = class {
3669
3673
  async updateDeviceProfile(profile) {
3670
3674
  (0, import_invariant9.invariant)(this._identity, "Identity not initialized.", {
3671
3675
  F: __dxlog_file12,
3672
- L: 313,
3676
+ L: 308,
3673
3677
  S: this,
3674
3678
  A: [
3675
3679
  "this._identity",
@@ -3702,48 +3706,10 @@ var IdentityManager = class {
3702
3706
  profile
3703
3707
  };
3704
3708
  }
3705
- async createRecoveryPhrase() {
3706
- const identity = this._identity;
3707
- (0, import_invariant9.invariant)(identity, void 0, {
3708
- F: __dxlog_file12,
3709
- L: 340,
3710
- S: this,
3711
- A: [
3712
- "identity",
3713
- ""
3714
- ]
3715
- });
3716
- const seedphrase = (0, import_credentials14.generateSeedPhrase)();
3717
- const keypair = (0, import_credentials14.keyPairFromSeedPhrase)(seedphrase);
3718
- const recoveryKey = import_keys9.PublicKey.from(keypair.publicKey);
3719
- const identityKey = identity.identityKey;
3720
- const credential = await identity.getIdentityCredentialSigner().createCredential({
3721
- subject: identityKey,
3722
- assertion: {
3723
- "@type": "dxos.halo.credentials.IdentityRecovery",
3724
- recoveryKey,
3725
- identityKey
3726
- }
3727
- });
3728
- const receipt = await identity.controlPipeline.writer.write({
3729
- credential: {
3730
- credential
3731
- }
3732
- });
3733
- await identity.controlPipeline.state.waitUntilTimeframe(new import_timeframe4.Timeframe([
3734
- [
3735
- receipt.feedKey,
3736
- receipt.seq
3737
- ]
3738
- ]));
3739
- return {
3740
- seedphrase
3741
- };
3742
- }
3743
3709
  async _constructIdentity(identityRecord) {
3744
3710
  (0, import_invariant9.invariant)(!this._identity, void 0, {
3745
3711
  F: __dxlog_file12,
3746
- L: 362,
3712
+ L: 334,
3747
3713
  S: this,
3748
3714
  A: [
3749
3715
  "!this._identity",
@@ -3754,7 +3720,7 @@ var IdentityManager = class {
3754
3720
  identityRecord
3755
3721
  }, {
3756
3722
  F: __dxlog_file12,
3757
- L: 363,
3723
+ L: 335,
3758
3724
  S: this,
3759
3725
  C: (f, a) => f(...a)
3760
3726
  });
@@ -3769,7 +3735,7 @@ var IdentityManager = class {
3769
3735
  });
3770
3736
  (0, import_invariant9.invariant)(identityRecord.haloSpace.controlFeedKey, void 0, {
3771
3737
  F: __dxlog_file12,
3772
- L: 376,
3738
+ L: 348,
3773
3739
  S: this,
3774
3740
  A: [
3775
3741
  "identityRecord.haloSpace.controlFeedKey",
@@ -3781,7 +3747,7 @@ var IdentityManager = class {
3781
3747
  });
3782
3748
  (0, import_invariant9.invariant)(identityRecord.haloSpace.dataFeedKey, void 0, {
3783
3749
  F: __dxlog_file12,
3784
- L: 380,
3750
+ L: 352,
3785
3751
  S: this,
3786
3752
  A: [
3787
3753
  "identityRecord.haloSpace.dataFeedKey",
@@ -3805,10 +3771,12 @@ var IdentityManager = class {
3805
3771
  });
3806
3772
  await space.setControlFeed(controlFeed);
3807
3773
  await space.setDataFeed(dataFeed);
3774
+ const did = await (0, import_credentials14.createDidFromIdentityKey)(identityRecord.identityKey);
3808
3775
  const identity = new Identity({
3809
3776
  space,
3810
3777
  presence,
3811
3778
  signer: this._keyring,
3779
+ did,
3812
3780
  identityKey: identityRecord.identityKey,
3813
3781
  deviceKey: identityRecord.deviceKey,
3814
3782
  edgeConnection: this._edgeConnection,
@@ -3818,7 +3786,7 @@ var IdentityManager = class {
3818
3786
  identityKey: identityRecord.identityKey
3819
3787
  }, {
3820
3788
  F: __dxlog_file12,
3821
- L: 409,
3789
+ L: 383,
3822
3790
  S: this,
3823
3791
  C: (f, a) => f(...a)
3824
3792
  });
@@ -3843,7 +3811,7 @@ var IdentityManager = class {
3843
3811
  onAuthFailure: () => {
3844
3812
  import_log10.log.warn("auth failure", void 0, {
3845
3813
  F: __dxlog_file12,
3846
- L: 434,
3814
+ L: 408,
3847
3815
  S: this,
3848
3816
  C: (f, a) => f(...a)
3849
3817
  });
@@ -3896,7 +3864,7 @@ var IdentityServiceImpl = class extends import_context9.Resource {
3896
3864
  const identity = this._identityManager.identity;
3897
3865
  (0, import_invariant10.invariant)(identity, void 0, {
3898
3866
  F: __dxlog_file13,
3899
- L: 60,
3867
+ L: 61,
3900
3868
  S: this,
3901
3869
  A: [
3902
3870
  "identity",
@@ -3919,6 +3887,7 @@ var IdentityServiceImpl = class extends import_context9.Resource {
3919
3887
  return void 0;
3920
3888
  }
3921
3889
  return {
3890
+ did: this._identityManager.identity.did,
3922
3891
  identityKey: this._identityManager.identity.identityKey,
3923
3892
  spaceKey: this._identityManager.identity.space.key,
3924
3893
  profile: this._identityManager.identity.profileDocument
@@ -3927,7 +3896,7 @@ var IdentityServiceImpl = class extends import_context9.Resource {
3927
3896
  async updateProfile(profile) {
3928
3897
  (0, import_invariant10.invariant)(this._identityManager.identity, "Identity not initialized.", {
3929
3898
  F: __dxlog_file13,
3930
- L: 86,
3899
+ L: 88,
3931
3900
  S: this,
3932
3901
  A: [
3933
3902
  "this._identityManager.identity",
@@ -3938,18 +3907,29 @@ var IdentityServiceImpl = class extends import_context9.Resource {
3938
3907
  await this._onProfileUpdate?.(this._identityManager.identity.profileDocument);
3939
3908
  return this._getIdentity();
3940
3909
  }
3941
- async createRecoveryPhrase() {
3942
- return this._recoveryManager.createRecoveryPhrase();
3910
+ async createRecoveryCredential(request) {
3911
+ return this._recoveryManager.createRecoveryCredential(request);
3912
+ }
3913
+ async requestRecoveryChallenge() {
3914
+ return this._recoveryManager.requestRecoveryChallenge();
3943
3915
  }
3944
3916
  async recoverIdentity(request) {
3945
- await this._recoveryManager.recoverIdentity(request);
3917
+ if (request.recoveryCode) {
3918
+ await this._recoveryManager.recoverIdentity({
3919
+ recoveryCode: request.recoveryCode
3920
+ });
3921
+ } else if (request.external) {
3922
+ await this._recoveryManager.recoverIdentityWithExternalSignature(request.external);
3923
+ } else {
3924
+ throw new Error("Invalid request.");
3925
+ }
3946
3926
  return this._getIdentity();
3947
3927
  }
3948
3928
  // TODO(burdon): Rename createPresentation?
3949
3929
  async signPresentation({ presentation, nonce }) {
3950
3930
  (0, import_invariant10.invariant)(this._identityManager.identity, "Identity not initialized.", {
3951
3931
  F: __dxlog_file13,
3952
- L: 103,
3932
+ L: 116,
3953
3933
  S: this,
3954
3934
  A: [
3955
3935
  "this._identityManager.identity",
@@ -3968,7 +3948,7 @@ var IdentityServiceImpl = class extends import_context9.Resource {
3968
3948
  const identity = this._identityManager.identity;
3969
3949
  (0, import_invariant10.invariant)(identity, "Identity not initialized.", {
3970
3950
  F: __dxlog_file13,
3971
- L: 117,
3951
+ L: 130,
3972
3952
  S: this,
3973
3953
  A: [
3974
3954
  "identity",
@@ -4006,7 +3986,7 @@ var IdentityServiceImpl = class extends import_context9.Resource {
4006
3986
  duplicate: space.id
4007
3987
  }, {
4008
3988
  F: __dxlog_file13,
4009
- L: 151,
3989
+ L: 164,
4010
3990
  S: this,
4011
3991
  C: (f, a) => f(...a)
4012
3992
  });
@@ -4020,7 +4000,7 @@ var IdentityServiceImpl = class extends import_context9.Resource {
4020
4000
  }, (err) => {
4021
4001
  import_log11.log.catch(err, void 0, {
4022
4002
  F: __dxlog_file13,
4023
- L: 162,
4003
+ L: 175,
4024
4004
  S: this,
4025
4005
  C: (f, a) => f(...a)
4026
4006
  });
@@ -7082,6 +7062,18 @@ var EdgeAgentManager = class extends import_context15.Resource {
7082
7062
  haloSpaceKey: this._identity.haloSpaceKey.toHex()
7083
7063
  });
7084
7064
  const deviceKey = import_keys15.PublicKey.fromHex(response.deviceKey);
7065
+ if (await this._identity.authorizedDeviceKeys.has(deviceKey)) {
7066
+ import_log21.log.info("agent was already added to HALO, ignoring response", {
7067
+ response
7068
+ }, {
7069
+ F: __dxlog_file25,
7070
+ L: 67,
7071
+ S: this,
7072
+ C: (f, a) => f(...a)
7073
+ });
7074
+ this._updateStatus(import_protocols14.EdgeAgentStatus.ACTIVE, deviceKey);
7075
+ return;
7076
+ }
7085
7077
  await this._identity.admitDevice({
7086
7078
  deviceKey,
7087
7079
  controlFeedKey: import_keys15.PublicKey.fromHex(response.feedKey),
@@ -7090,7 +7082,7 @@ var EdgeAgentManager = class extends import_context15.Resource {
7090
7082
  });
7091
7083
  (0, import_log21.log)("agent created", response, {
7092
7084
  F: __dxlog_file25,
7093
- L: 73,
7085
+ L: 79,
7094
7086
  S: this,
7095
7087
  C: (f, a) => f(...a)
7096
7088
  });
@@ -7102,7 +7094,7 @@ var EdgeAgentManager = class extends import_context15.Resource {
7102
7094
  isEnabled
7103
7095
  }, {
7104
7096
  F: __dxlog_file25,
7105
- L: 81,
7097
+ L: 87,
7106
7098
  S: this,
7107
7099
  C: (f, a) => f(...a)
7108
7100
  });
@@ -7135,7 +7127,7 @@ var EdgeAgentManager = class extends import_context15.Resource {
7135
7127
  async _fetchAgentStatus() {
7136
7128
  (0, import_invariant20.invariant)(this._edgeHttpClient, void 0, {
7137
7129
  F: __dxlog_file25,
7138
- L: 115,
7130
+ L: 121,
7139
7131
  S: this,
7140
7132
  A: [
7141
7133
  "this._edgeHttpClient",
@@ -7145,7 +7137,7 @@ var EdgeAgentManager = class extends import_context15.Resource {
7145
7137
  try {
7146
7138
  (0, import_log21.log)("fetching agent status", void 0, {
7147
7139
  F: __dxlog_file25,
7148
- L: 117,
7140
+ L: 123,
7149
7141
  S: this,
7150
7142
  C: (f, a) => f(...a)
7151
7143
  });
@@ -7164,7 +7156,7 @@ var EdgeAgentManager = class extends import_context15.Resource {
7164
7156
  err
7165
7157
  }, {
7166
7158
  F: __dxlog_file25,
7167
- L: 127,
7159
+ L: 133,
7168
7160
  S: this,
7169
7161
  C: (f, a) => f(...a)
7170
7162
  });
@@ -7177,7 +7169,7 @@ var EdgeAgentManager = class extends import_context15.Resource {
7177
7169
  retryAfterMs
7178
7170
  }, {
7179
7171
  F: __dxlog_file25,
7180
- L: 132,
7172
+ L: 138,
7181
7173
  S: this,
7182
7174
  C: (f, a) => f(...a)
7183
7175
  });
@@ -7213,7 +7205,7 @@ var EdgeAgentManager = class extends import_context15.Resource {
7213
7205
  spaceId: space.id
7214
7206
  }, {
7215
7207
  F: __dxlog_file25,
7216
- L: 159,
7208
+ L: 165,
7217
7209
  S: this,
7218
7210
  C: (f, a) => f(...a)
7219
7211
  });
@@ -7233,7 +7225,7 @@ var EdgeAgentManager = class extends import_context15.Resource {
7233
7225
  status
7234
7226
  }, {
7235
7227
  F: __dxlog_file25,
7236
- L: 175,
7228
+ L: 181,
7237
7229
  S: this,
7238
7230
  C: (f, a) => f(...a)
7239
7231
  });
@@ -7306,27 +7298,41 @@ var EdgeIdentityRecoveryManager = class {
7306
7298
  this._identityProvider = _identityProvider;
7307
7299
  this._acceptRecoveredIdentity = _acceptRecoveredIdentity;
7308
7300
  }
7309
- async createRecoveryPhrase() {
7301
+ async createRecoveryCredential({ recoveryKey, algorithm }) {
7310
7302
  const identity = this._identityProvider();
7311
7303
  (0, import_invariant22.invariant)(identity, void 0, {
7312
7304
  F: __dxlog_file26,
7313
- L: 29,
7305
+ L: 37,
7314
7306
  S: this,
7315
7307
  A: [
7316
7308
  "identity",
7317
7309
  ""
7318
7310
  ]
7319
7311
  });
7320
- const seedphrase = (0, import_credentials23.generateSeedPhrase)();
7321
- const keypair = (0, import_credentials23.keyPairFromSeedPhrase)(seedphrase);
7322
- const recoveryKey = import_keys17.PublicKey.from(keypair.publicKey);
7312
+ let recoveryCode;
7313
+ if (!recoveryKey) {
7314
+ recoveryCode = (0, import_credentials23.generateSeedPhrase)();
7315
+ const keypair = (0, import_credentials23.keyPairFromSeedPhrase)(recoveryCode);
7316
+ recoveryKey = import_keys17.PublicKey.from(keypair.publicKey);
7317
+ algorithm = "ED25519";
7318
+ }
7319
+ (0, import_invariant22.invariant)(algorithm, "Algorithm is required.", {
7320
+ F: __dxlog_file26,
7321
+ L: 47,
7322
+ S: this,
7323
+ A: [
7324
+ "algorithm",
7325
+ "'Algorithm is required.'"
7326
+ ]
7327
+ });
7323
7328
  const identityKey = identity.identityKey;
7324
7329
  const credential = await identity.getIdentityCredentialSigner().createCredential({
7325
7330
  subject: identityKey,
7326
7331
  assertion: {
7327
7332
  "@type": "dxos.halo.credentials.IdentityRecovery",
7328
7333
  recoveryKey,
7329
- identityKey
7334
+ identityKey,
7335
+ algorithm
7330
7336
  }
7331
7337
  });
7332
7338
  const receipt = await identity.controlPipeline.writer.write({
@@ -7341,20 +7347,81 @@ var EdgeIdentityRecoveryManager = class {
7341
7347
  ]
7342
7348
  ]));
7343
7349
  return {
7344
- seedphrase
7350
+ recoveryCode
7351
+ };
7352
+ }
7353
+ async requestRecoveryChallenge() {
7354
+ (0, import_invariant22.invariant)(this._edgeClient, "Not connected to EDGE.", {
7355
+ F: __dxlog_file26,
7356
+ L: 66,
7357
+ S: this,
7358
+ A: [
7359
+ "this._edgeClient",
7360
+ "'Not connected to EDGE.'"
7361
+ ]
7362
+ });
7363
+ const deviceKey = await this._keyring.createKey();
7364
+ const controlFeedKey = await this._keyring.createKey();
7365
+ const request = {
7366
+ deviceKey: deviceKey.toHex(),
7367
+ controlFeedKey: controlFeedKey.toHex()
7368
+ };
7369
+ try {
7370
+ await this._edgeClient.recoverIdentity(request);
7371
+ throw new Error("No challenge received.");
7372
+ } catch (error) {
7373
+ if (!(error instanceof import_protocols17.EdgeAuthChallengeError)) {
7374
+ throw error;
7375
+ }
7376
+ return {
7377
+ deviceKey,
7378
+ controlFeedKey,
7379
+ challenge: error.challenge
7380
+ };
7381
+ }
7382
+ }
7383
+ async recoverIdentityWithExternalSignature({ identityDid, deviceKey, controlFeedKey, signature, clientDataJson, authenticatorData }) {
7384
+ (0, import_invariant22.invariant)(this._edgeClient, "Not connected to EDGE.", {
7385
+ F: __dxlog_file26,
7386
+ L: 98,
7387
+ S: this,
7388
+ A: [
7389
+ "this._edgeClient",
7390
+ "'Not connected to EDGE.'"
7391
+ ]
7392
+ });
7393
+ const request = {
7394
+ identityDid,
7395
+ deviceKey: deviceKey.toHex(),
7396
+ controlFeedKey: controlFeedKey.toHex(),
7397
+ signature: clientDataJson && authenticatorData ? {
7398
+ signature: Buffer.from(signature).toString("base64"),
7399
+ clientDataJson: Buffer.from(clientDataJson).toString("base64"),
7400
+ authenticatorData: Buffer.from(authenticatorData).toString("base64")
7401
+ } : Buffer.from(signature).toString("base64")
7345
7402
  };
7403
+ const response = await this._edgeClient.recoverIdentity(request);
7404
+ await this._acceptRecoveredIdentity({
7405
+ authorizedDeviceCredential: decodeCredential(response.deviceAuthCredential),
7406
+ haloGenesisFeedKey: import_keys17.PublicKey.fromHex(response.genesisFeedKey),
7407
+ haloSpaceKey: import_keys17.PublicKey.fromHex(response.haloSpaceKey),
7408
+ identityKey: import_keys17.PublicKey.fromHex(response.identityKey),
7409
+ deviceKey,
7410
+ controlFeedKey,
7411
+ dataFeedKey: await this._keyring.createKey()
7412
+ });
7346
7413
  }
7347
- async recoverIdentity(args) {
7414
+ async recoverIdentity({ recoveryCode }) {
7348
7415
  (0, import_invariant22.invariant)(this._edgeClient, "Not connected to EDGE.", {
7349
7416
  F: __dxlog_file26,
7350
- L: 51,
7417
+ L: 128,
7351
7418
  S: this,
7352
7419
  A: [
7353
7420
  "this._edgeClient",
7354
7421
  "'Not connected to EDGE.'"
7355
7422
  ]
7356
7423
  });
7357
- const recoveryKeypair = (0, import_credentials23.keyPairFromSeedPhrase)(args.seedphrase);
7424
+ const recoveryKeypair = (0, import_credentials23.keyPairFromSeedPhrase)(recoveryCode);
7358
7425
  const recoveryKey = import_keys17.PublicKey.from(recoveryKeypair.publicKey);
7359
7426
  const deviceKey = await this._keyring.createKey();
7360
7427
  const controlFeedKey = await this._keyring.createKey();
@@ -7378,7 +7445,7 @@ var EdgeIdentityRecoveryManager = class {
7378
7445
  }
7379
7446
  import_log23.log.info("recovering identity", response, {
7380
7447
  F: __dxlog_file26,
7381
- L: 77,
7448
+ L: 154,
7382
7449
  S: this,
7383
7450
  C: (f, a) => f(...a)
7384
7451
  });
@@ -8907,4 +8974,4 @@ ClientServicesHost = _ts_decorate11([
8907
8974
  subscribeToSpaces,
8908
8975
  subscribeToSwarmInfo
8909
8976
  });
8910
- //# sourceMappingURL=chunk-25BSUDM4.cjs.map
8977
+ //# sourceMappingURL=chunk-K6H3KWWB.cjs.map