@dxos/client-services 0.7.5-labs.5f04cf6 → 0.7.5-labs.e27f9b9

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 (49) hide show
  1. package/dist/lib/browser/{chunk-EVMMT65L.mjs → chunk-OHBCYJRF.mjs} +164 -167
  2. package/dist/lib/browser/chunk-OHBCYJRF.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-LXXOZWCX.cjs → chunk-X3IYGB6Q.cjs} +158 -161
  7. package/dist/lib/node/chunk-X3IYGB6Q.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-74ZMFWJS.mjs → chunk-U5S4G236.mjs} +164 -167
  12. package/dist/lib/node-esm/chunk-U5S4G236.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/diagnostics/diagnostics.d.ts.map +1 -1
  17. package/dist/types/src/packlets/identity/identity-manager.d.ts +0 -3
  18. package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
  19. package/dist/types/src/packlets/identity/identity-recovery-manager.d.ts +4 -5
  20. package/dist/types/src/packlets/identity/identity-recovery-manager.d.ts.map +1 -1
  21. package/dist/types/src/packlets/identity/identity-service.d.ts +3 -3
  22. package/dist/types/src/packlets/identity/identity-service.d.ts.map +1 -1
  23. package/dist/types/src/packlets/identity/identity.d.ts +3 -1
  24. package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
  25. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  26. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
  27. package/dist/types/src/packlets/invitations/utils.d.ts +1 -0
  28. package/dist/types/src/packlets/invitations/utils.d.ts.map +1 -1
  29. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  30. package/dist/types/src/version.d.ts +1 -1
  31. package/dist/types/tsconfig.tsbuildinfo +1 -1
  32. package/package.json +38 -38
  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 +24 -9
  36. package/src/packlets/identity/identity-service.ts +4 -2
  37. package/src/packlets/identity/identity.test.ts +2 -1
  38. package/src/packlets/identity/identity.ts +4 -1
  39. package/src/packlets/invitations/invitations-handler.ts +15 -6
  40. package/src/packlets/invitations/invitations-manager.ts +1 -1
  41. package/src/packlets/invitations/space-invitation-protocol.ts +2 -3
  42. package/src/packlets/invitations/utils.ts +7 -0
  43. package/src/packlets/spaces/data-space-manager.ts +1 -1
  44. package/src/packlets/spaces/edge-feed-replicator.ts +8 -8
  45. package/src/packlets/spaces/spaces-service.ts +30 -20
  46. package/src/version.ts +1 -1
  47. package/dist/lib/browser/chunk-EVMMT65L.mjs.map +0 -7
  48. package/dist/lib/node/chunk-LXXOZWCX.cjs.map +0 -7
  49. package/dist/lib/node-esm/chunk-74ZMFWJS.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-labs.5f04cf6";
400
+ var DXOS_VERSION = "0.7.5-labs.e27f9b9";
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,
@@ -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
  }, {
@@ -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
@@ -2676,7 +2678,7 @@ DataSpaceManager = _ts_decorate3([
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
2680
  import { Stream as Stream7 } from "@dxos/codec-protobuf/stream";
2679
- import { createAdmissionCredentials as createAdmissionCredentials2, getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
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
  });
@@ -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,8 +3811,8 @@ 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);
3847
3816
  }
3848
3817
  async recoverIdentity(request) {
3849
3818
  await this._recoveryManager.recoverIdentity(request);
@@ -3853,7 +3822,7 @@ var IdentityServiceImpl = class extends Resource5 {
3853
3822
  async signPresentation({ presentation, nonce }) {
3854
3823
  invariant9(this._identityManager.identity, "Identity not initialized.", {
3855
3824
  F: __dxlog_file14,
3856
- L: 103,
3825
+ L: 105,
3857
3826
  S: this,
3858
3827
  A: [
3859
3828
  "this._identityManager.identity",
@@ -3872,7 +3841,7 @@ var IdentityServiceImpl = class extends Resource5 {
3872
3841
  const identity = this._identityManager.identity;
3873
3842
  invariant9(identity, "Identity not initialized.", {
3874
3843
  F: __dxlog_file14,
3875
- L: 117,
3844
+ L: 119,
3876
3845
  S: this,
3877
3846
  A: [
3878
3847
  "identity",
@@ -3910,7 +3879,7 @@ var IdentityServiceImpl = class extends Resource5 {
3910
3879
  duplicate: space.id
3911
3880
  }, {
3912
3881
  F: __dxlog_file14,
3913
- L: 151,
3882
+ L: 153,
3914
3883
  S: this,
3915
3884
  C: (f, a) => f(...a)
3916
3885
  });
@@ -3924,7 +3893,7 @@ var IdentityServiceImpl = class extends Resource5 {
3924
3893
  }, (err) => {
3925
3894
  log11.catch(err, void 0, {
3926
3895
  F: __dxlog_file14,
3927
- L: 162,
3896
+ L: 164,
3928
3897
  S: this,
3929
3898
  C: (f, a) => f(...a)
3930
3899
  });
@@ -4705,14 +4674,14 @@ var DeviceInvitationProtocol = class {
4705
4674
 
4706
4675
  // packages/sdk/client-services/src/packlets/invitations/invitations-handler.ts
4707
4676
  import { scheduleTask as scheduleTask7, TimeoutError as TimeoutError2 } from "@dxos/async";
4708
- import { INVITATION_TIMEOUT } from "@dxos/client-protocol";
4677
+ import { INVITATION_TIMEOUT, getExpirationTime } from "@dxos/client-protocol";
4709
4678
  import { ContextDisposedError as ContextDisposedError3 } from "@dxos/context";
4710
4679
  import { createKeyPair, sign as sign2 } from "@dxos/crypto";
4711
4680
  import { invariant as invariant15 } from "@dxos/invariant";
4712
4681
  import { PublicKey as PublicKey11 } from "@dxos/keys";
4713
4682
  import { log as log18 } from "@dxos/log";
4714
4683
  import { createTeleportProtocolFactory } from "@dxos/network-manager";
4715
- import { InvalidInvitationExtensionRoleError as InvalidInvitationExtensionRoleError3, trace as trace7 } from "@dxos/protocols";
4684
+ import { InvalidInvitationError, InvalidInvitationExtensionRoleError as InvalidInvitationExtensionRoleError3, trace as trace7 } from "@dxos/protocols";
4716
4685
  import { Invitation as Invitation7 } from "@dxos/protocols/proto/dxos/client/services";
4717
4686
  import { AuthenticationResponse as AuthenticationResponse2 } from "@dxos/protocols/proto/dxos/halo/invitations";
4718
4687
  import { InvitationOptions as InvitationOptions4 } from "@dxos/protocols/proto/dxos/halo/invitations";
@@ -4735,6 +4704,12 @@ import { Invitation as Invitation3 } from "@dxos/protocols/proto/dxos/client/ser
4735
4704
  var stateToString = (state) => {
4736
4705
  return Object.entries(Invitation3.State).find(([key, val]) => val === state)?.[0] ?? "unknown";
4737
4706
  };
4707
+ var computeExpirationTime = (invitation) => {
4708
+ if (!invitation.lifetime) {
4709
+ return;
4710
+ }
4711
+ return new Date((invitation.created?.getTime() ?? Date.now()) + invitation.lifetime * 1e3);
4712
+ };
4738
4713
  var tryAcquireBeforeContextDisposed = async (ctx, mutex) => {
4739
4714
  let guard;
4740
4715
  return cancelWithContext3(ctx, (async () => {
@@ -5750,18 +5725,19 @@ var InvitationsHandler = class {
5750
5725
  });
5751
5726
  return extension;
5752
5727
  };
5753
- if (invitation.lifetime && invitation.created) {
5754
- if (invitation.created.getTime() + invitation.lifetime * 1e3 < Date.now()) {
5728
+ const expiresOn = getExpirationTime(invitation);
5729
+ if (expiresOn) {
5730
+ if (expiresOn.getTime() < Date.now()) {
5755
5731
  log18.warn("invitation has already expired", void 0, {
5756
5732
  F: __dxlog_file22,
5757
- L: 193,
5733
+ L: 194,
5758
5734
  S: this,
5759
5735
  C: (f, a) => f(...a)
5760
5736
  });
5761
5737
  guardedState.set(null, Invitation7.State.EXPIRED);
5762
5738
  void ctx.dispose().catch((err) => log18.catch(err, void 0, {
5763
5739
  F: __dxlog_file22,
5764
- L: 195,
5740
+ L: 196,
5765
5741
  S: this,
5766
5742
  C: (f, a) => f(...a)
5767
5743
  }));
@@ -5772,7 +5748,7 @@ var InvitationsHandler = class {
5772
5748
  guardedState.set(null, Invitation7.State.EXPIRED);
5773
5749
  metrics.increment("dxos.invitation.expired");
5774
5750
  await ctx.dispose();
5775
- }, invitation.created.getTime() + invitation.lifetime * 1e3 - Date.now());
5751
+ }, expiresOn.getTime() - Date.now());
5776
5752
  }
5777
5753
  let swarmConnection;
5778
5754
  scheduleTask7(ctx, async () => {
@@ -5788,7 +5764,7 @@ var InvitationsHandler = class {
5788
5764
  type: invitation.type
5789
5765
  }, {
5790
5766
  F: __dxlog_file22,
5791
- L: 226,
5767
+ L: 227,
5792
5768
  S: this,
5793
5769
  C: (f, a) => f(...a)
5794
5770
  });
@@ -5796,7 +5772,7 @@ var InvitationsHandler = class {
5796
5772
  if (deviceProfile) {
5797
5773
  invariant15(invitation.kind === Invitation7.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
5798
5774
  F: __dxlog_file22,
5799
- L: 235,
5775
+ L: 236,
5800
5776
  S: this,
5801
5777
  A: [
5802
5778
  "invitation.kind === Invitation.Kind.DEVICE",
@@ -5814,7 +5790,7 @@ var InvitationsHandler = class {
5814
5790
  triedPeers: triedPeersIds.size
5815
5791
  }, {
5816
5792
  F: __dxlog_file22,
5817
- L: 243,
5793
+ L: 244,
5818
5794
  S: this,
5819
5795
  C: (f, a) => f(...a)
5820
5796
  });
@@ -5841,7 +5817,7 @@ var InvitationsHandler = class {
5841
5817
  currentState: guardedState.current.state
5842
5818
  }, {
5843
5819
  F: __dxlog_file22,
5844
- L: 271,
5820
+ L: 272,
5845
5821
  S: this,
5846
5822
  C: (f, a) => f(...a)
5847
5823
  });
@@ -5859,7 +5835,7 @@ var InvitationsHandler = class {
5859
5835
  id: traceId
5860
5836
  }), {
5861
5837
  F: __dxlog_file22,
5862
- L: 283,
5838
+ L: 284,
5863
5839
  S: this,
5864
5840
  C: (f, a) => f(...a)
5865
5841
  });
@@ -5871,7 +5847,7 @@ var InvitationsHandler = class {
5871
5847
  ...protocol.toJSON()
5872
5848
  }, {
5873
5849
  F: __dxlog_file22,
5874
- L: 294,
5850
+ L: 295,
5875
5851
  S: this,
5876
5852
  C: (f, a) => f(...a)
5877
5853
  });
@@ -5881,7 +5857,7 @@ var InvitationsHandler = class {
5881
5857
  ...protocol.toJSON()
5882
5858
  }, {
5883
5859
  F: __dxlog_file22,
5884
- L: 298,
5860
+ L: 299,
5885
5861
  S: this,
5886
5862
  C: (f, a) => f(...a)
5887
5863
  });
@@ -5895,7 +5871,7 @@ var InvitationsHandler = class {
5895
5871
  authMethod: introductionResponse.authMethod
5896
5872
  }, {
5897
5873
  F: __dxlog_file22,
5898
- L: 306,
5874
+ L: 307,
5899
5875
  S: this,
5900
5876
  C: (f, a) => f(...a)
5901
5877
  });
@@ -5917,7 +5893,7 @@ var InvitationsHandler = class {
5917
5893
  ...protocol.toJSON()
5918
5894
  }, {
5919
5895
  F: __dxlog_file22,
5920
- L: 336,
5896
+ L: 337,
5921
5897
  S: this,
5922
5898
  C: (f, a) => f(...a)
5923
5899
  });
@@ -5930,7 +5906,7 @@ var InvitationsHandler = class {
5930
5906
  ...protocol.toJSON()
5931
5907
  }, {
5932
5908
  F: __dxlog_file22,
5933
- L: 350,
5909
+ L: 351,
5934
5910
  S: this,
5935
5911
  C: (f, a) => f(...a)
5936
5912
  });
@@ -5943,7 +5919,7 @@ var InvitationsHandler = class {
5943
5919
  id: traceId
5944
5920
  }), {
5945
5921
  F: __dxlog_file22,
5946
- L: 359,
5922
+ L: 360,
5947
5923
  S: this,
5948
5924
  C: (f, a) => f(...a)
5949
5925
  });
@@ -5953,7 +5929,7 @@ var InvitationsHandler = class {
5953
5929
  ...protocol.toJSON()
5954
5930
  }, {
5955
5931
  F: __dxlog_file22,
5956
- L: 362,
5932
+ L: 363,
5957
5933
  S: this,
5958
5934
  C: (f, a) => f(...a)
5959
5935
  });
@@ -5961,7 +5937,7 @@ var InvitationsHandler = class {
5961
5937
  } else {
5962
5938
  log18.verbose("auth failed", err, {
5963
5939
  F: __dxlog_file22,
5964
- L: 365,
5940
+ L: 366,
5965
5941
  S: this,
5966
5942
  C: (f, a) => f(...a)
5967
5943
  });
@@ -5973,7 +5949,7 @@ var InvitationsHandler = class {
5973
5949
  error: err
5974
5950
  }), {
5975
5951
  F: __dxlog_file22,
5976
- L: 369,
5952
+ L: 370,
5977
5953
  S: this,
5978
5954
  C: (f, a) => f(...a)
5979
5955
  });
@@ -5989,7 +5965,7 @@ var InvitationsHandler = class {
5989
5965
  ...protocol.toJSON()
5990
5966
  }, {
5991
5967
  F: __dxlog_file22,
5992
- L: 378,
5968
+ L: 379,
5993
5969
  S: this,
5994
5970
  C: (f, a) => f(...a)
5995
5971
  });
@@ -5997,7 +5973,7 @@ var InvitationsHandler = class {
5997
5973
  } else {
5998
5974
  log18.verbose("auth failed", err, {
5999
5975
  F: __dxlog_file22,
6000
- L: 381,
5976
+ L: 382,
6001
5977
  S: this,
6002
5978
  C: (f, a) => f(...a)
6003
5979
  });
@@ -6014,7 +5990,7 @@ var InvitationsHandler = class {
6014
5990
  ...protocol.toJSON()
6015
5991
  }, {
6016
5992
  F: __dxlog_file22,
6017
- L: 393,
5993
+ L: 394,
6018
5994
  S: this,
6019
5995
  C: (f, a) => f(...a)
6020
5996
  });
@@ -6027,14 +6003,14 @@ var InvitationsHandler = class {
6027
6003
  });
6028
6004
  edgeInvitationHandler.handle(ctx, guardedState, protocol, deviceProfile);
6029
6005
  scheduleTask7(ctx, async () => {
6030
- const error = protocol.checkInvitation(invitation);
6006
+ const error = checkInvitation(protocol, invitation);
6031
6007
  if (error) {
6032
6008
  stream.error(error);
6033
6009
  await ctx.dispose();
6034
6010
  } else {
6035
6011
  invariant15(invitation.swarmKey, void 0, {
6036
6012
  F: __dxlog_file22,
6037
- L: 405,
6013
+ L: 406,
6038
6014
  S: this,
6039
6015
  A: [
6040
6016
  "invitation.swarmKey",
@@ -6078,7 +6054,7 @@ var InvitationsHandler = class {
6078
6054
  for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
6079
6055
  log18("guest waiting for authentication code...", void 0, {
6080
6056
  F: __dxlog_file22,
6081
- L: 457,
6057
+ L: 458,
6082
6058
  S: this,
6083
6059
  C: (f, a) => f(...a)
6084
6060
  });
@@ -6086,7 +6062,7 @@ var InvitationsHandler = class {
6086
6062
  const authCode = await authenticated.wait(options);
6087
6063
  log18("sending authentication request", void 0, {
6088
6064
  F: __dxlog_file22,
6089
- L: 461,
6065
+ L: 462,
6090
6066
  S: this,
6091
6067
  C: (f, a) => f(...a)
6092
6068
  });
@@ -6105,7 +6081,7 @@ var InvitationsHandler = class {
6105
6081
  attempt
6106
6082
  }, {
6107
6083
  F: __dxlog_file22,
6108
- L: 472,
6084
+ L: 473,
6109
6085
  S: this,
6110
6086
  C: (f, a) => f(...a)
6111
6087
  });
@@ -6123,7 +6099,7 @@ var InvitationsHandler = class {
6123
6099
  }
6124
6100
  log18("sending authentication request", void 0, {
6125
6101
  F: __dxlog_file22,
6126
- L: 491,
6102
+ L: 492,
6127
6103
  S: this,
6128
6104
  C: (f, a) => f(...a)
6129
6105
  });
@@ -6136,6 +6112,13 @@ var InvitationsHandler = class {
6136
6112
  }
6137
6113
  }
6138
6114
  };
6115
+ var checkInvitation = (protocol, invitation) => {
6116
+ const expiresOn = getExpirationTime(invitation);
6117
+ if (expiresOn && expiresOn.getTime() < Date.now()) {
6118
+ return new InvalidInvitationError("Invitation already expired.");
6119
+ }
6120
+ return protocol.checkInvitation(invitation);
6121
+ };
6139
6122
  var createAdmissionKeypair = () => {
6140
6123
  const keypair = createKeyPair();
6141
6124
  return {
@@ -6250,7 +6233,7 @@ import { createCancelDelegatedSpaceInvitationCredential, createDelegatedSpaceInv
6250
6233
  import { writeMessages as writeMessages4 } from "@dxos/feed-store";
6251
6234
  import { invariant as invariant16 } from "@dxos/invariant";
6252
6235
  import { log as log19 } from "@dxos/log";
6253
- import { AlreadyJoinedError as AlreadyJoinedError3, AuthorizationError as AuthorizationError2, InvalidInvitationError, SpaceNotFoundError as SpaceNotFoundError2 } from "@dxos/protocols";
6236
+ import { AlreadyJoinedError as AlreadyJoinedError3, AuthorizationError as AuthorizationError2, InvalidInvitationError as InvalidInvitationError2, SpaceNotFoundError as SpaceNotFoundError2 } from "@dxos/protocols";
6254
6237
  import { Invitation as Invitation8 } from "@dxos/protocols/proto/dxos/client/services";
6255
6238
  import { SpaceMember as SpaceMember6 } from "@dxos/protocols/proto/dxos/halo/credentials";
6256
6239
  var __dxlog_file23 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/space-invitation-protocol.ts";
@@ -6270,7 +6253,7 @@ var SpaceInvitationProtocol = class {
6270
6253
  }
6271
6254
  checkCanInviteNewMembers() {
6272
6255
  if (this._spaceKey == null) {
6273
- return new InvalidInvitationError("No spaceKey was provided for a space invitation.");
6256
+ return new InvalidInvitationError2("No spaceKey was provided for a space invitation.");
6274
6257
  }
6275
6258
  const space = this._spaceManager.spaces.get(this._spaceKey);
6276
6259
  if (space == null) {
@@ -6284,7 +6267,7 @@ var SpaceInvitationProtocol = class {
6284
6267
  getInvitationContext() {
6285
6268
  invariant16(this._spaceKey, void 0, {
6286
6269
  F: __dxlog_file23,
6287
- L: 64,
6270
+ L: 65,
6288
6271
  S: this,
6289
6272
  A: [
6290
6273
  "this._spaceKey",
@@ -6294,7 +6277,7 @@ var SpaceInvitationProtocol = class {
6294
6277
  const space = this._spaceManager.spaces.get(this._spaceKey);
6295
6278
  invariant16(space, void 0, {
6296
6279
  F: __dxlog_file23,
6297
- L: 66,
6280
+ L: 67,
6298
6281
  S: this,
6299
6282
  A: [
6300
6283
  "space",
@@ -6310,7 +6293,7 @@ var SpaceInvitationProtocol = class {
6310
6293
  async admit(invitation, request, guestProfile) {
6311
6294
  invariant16(this._spaceKey && request.space, void 0, {
6312
6295
  F: __dxlog_file23,
6313
- L: 79,
6296
+ L: 80,
6314
6297
  S: this,
6315
6298
  A: [
6316
6299
  "this._spaceKey && request.space",
@@ -6322,7 +6305,7 @@ var SpaceInvitationProtocol = class {
6322
6305
  guest: request.space.deviceKey
6323
6306
  }, {
6324
6307
  F: __dxlog_file23,
6325
- L: 80,
6308
+ L: 81,
6326
6309
  S: this,
6327
6310
  C: (f, a) => f(...a)
6328
6311
  });
@@ -6344,7 +6327,7 @@ var SpaceInvitationProtocol = class {
6344
6327
  async delegate(invitation) {
6345
6328
  invariant16(this._spaceKey, void 0, {
6346
6329
  F: __dxlog_file23,
6347
- L: 100,
6330
+ L: 101,
6348
6331
  S: this,
6349
6332
  A: [
6350
6333
  "this._spaceKey",
@@ -6354,7 +6337,7 @@ var SpaceInvitationProtocol = class {
6354
6337
  const space = this._spaceManager.spaces.get(this._spaceKey);
6355
6338
  invariant16(space, void 0, {
6356
6339
  F: __dxlog_file23,
6357
- L: 102,
6340
+ L: 103,
6358
6341
  S: this,
6359
6342
  A: [
6360
6343
  "space",
@@ -6364,7 +6347,7 @@ var SpaceInvitationProtocol = class {
6364
6347
  if (invitation.authMethod === Invitation8.AuthMethod.KNOWN_PUBLIC_KEY) {
6365
6348
  invariant16(invitation.guestKeypair?.publicKey, void 0, {
6366
6349
  F: __dxlog_file23,
6367
- L: 104,
6350
+ L: 105,
6368
6351
  S: this,
6369
6352
  A: [
6370
6353
  "invitation.guestKeypair?.publicKey",
@@ -6377,7 +6360,7 @@ var SpaceInvitationProtocol = class {
6377
6360
  id: invitation.invitationId
6378
6361
  }, {
6379
6362
  F: __dxlog_file23,
6380
- L: 107,
6363
+ L: 108,
6381
6364
  S: this,
6382
6365
  C: (f, a) => f(...a)
6383
6366
  });
@@ -6386,13 +6369,13 @@ var SpaceInvitationProtocol = class {
6386
6369
  authMethod: invitation.authMethod,
6387
6370
  swarmKey: invitation.swarmKey,
6388
6371
  role: invitation.role ?? SpaceMember6.Role.ADMIN,
6389
- expiresOn: invitation.lifetime ? new Date((invitation.created?.getTime() ?? Date.now()) + invitation.lifetime) : void 0,
6372
+ expiresOn: computeExpirationTime(invitation),
6390
6373
  multiUse: invitation.multiUse ?? false,
6391
6374
  guestKey: invitation.authMethod === Invitation8.AuthMethod.KNOWN_PUBLIC_KEY ? invitation.guestKeypair.publicKey : void 0
6392
6375
  });
6393
6376
  invariant16(credential.credential, void 0, {
6394
6377
  F: __dxlog_file23,
6395
- L: 127,
6378
+ L: 126,
6396
6379
  S: this,
6397
6380
  A: [
6398
6381
  "credential.credential",
@@ -6407,7 +6390,7 @@ var SpaceInvitationProtocol = class {
6407
6390
  async cancelDelegation(invitation) {
6408
6391
  invariant16(this._spaceKey, void 0, {
6409
6392
  F: __dxlog_file23,
6410
- L: 133,
6393
+ L: 132,
6411
6394
  S: this,
6412
6395
  A: [
6413
6396
  "this._spaceKey",
@@ -6416,7 +6399,7 @@ var SpaceInvitationProtocol = class {
6416
6399
  });
6417
6400
  invariant16(invitation.type === Invitation8.Type.DELEGATED && invitation.delegationCredentialId, void 0, {
6418
6401
  F: __dxlog_file23,
6419
- L: 134,
6402
+ L: 133,
6420
6403
  S: this,
6421
6404
  A: [
6422
6405
  "invitation.type === Invitation.Type.DELEGATED && invitation.delegationCredentialId",
@@ -6426,7 +6409,7 @@ var SpaceInvitationProtocol = class {
6426
6409
  const space = this._spaceManager.spaces.get(this._spaceKey);
6427
6410
  invariant16(space, void 0, {
6428
6411
  F: __dxlog_file23,
6429
- L: 136,
6412
+ L: 135,
6430
6413
  S: this,
6431
6414
  A: [
6432
6415
  "space",
@@ -6438,14 +6421,14 @@ var SpaceInvitationProtocol = class {
6438
6421
  id: invitation.invitationId
6439
6422
  }, {
6440
6423
  F: __dxlog_file23,
6441
- L: 138,
6424
+ L: 137,
6442
6425
  S: this,
6443
6426
  C: (f, a) => f(...a)
6444
6427
  });
6445
6428
  const credential = await createCancelDelegatedSpaceInvitationCredential(this._signingContext.credentialSigner, space.key, invitation.delegationCredentialId);
6446
6429
  invariant16(credential.credential, void 0, {
6447
6430
  F: __dxlog_file23,
6448
- L: 145,
6431
+ L: 144,
6449
6432
  S: this,
6450
6433
  A: [
6451
6434
  "credential.credential",
@@ -6458,7 +6441,7 @@ var SpaceInvitationProtocol = class {
6458
6441
  }
6459
6442
  checkInvitation(invitation) {
6460
6443
  if (invitation.spaceKey == null) {
6461
- return new InvalidInvitationError("No spaceKey was provided for a space invitation.");
6444
+ return new InvalidInvitationError2("No spaceKey was provided for a space invitation.");
6462
6445
  }
6463
6446
  if (this._spaceManager.spaces.has(invitation.spaceKey)) {
6464
6447
  return new AlreadyJoinedError3("Already joined space.");
@@ -6484,7 +6467,7 @@ var SpaceInvitationProtocol = class {
6484
6467
  async accept(response) {
6485
6468
  invariant16(response.space, void 0, {
6486
6469
  F: __dxlog_file23,
6487
- L: 180,
6470
+ L: 179,
6488
6471
  S: this,
6489
6472
  A: [
6490
6473
  "response.space",
@@ -6495,7 +6478,7 @@ var SpaceInvitationProtocol = class {
6495
6478
  const assertion = getCredentialAssertion5(credential);
6496
6479
  invariant16(assertion["@type"] === "dxos.halo.credentials.SpaceMember", "Invalid credential", {
6497
6480
  F: __dxlog_file23,
6498
- L: 183,
6481
+ L: 182,
6499
6482
  S: this,
6500
6483
  A: [
6501
6484
  "assertion['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -6504,7 +6487,7 @@ var SpaceInvitationProtocol = class {
6504
6487
  });
6505
6488
  invariant16(credential.subject.id.equals(this._signingContext.identityKey), void 0, {
6506
6489
  F: __dxlog_file23,
6507
- L: 184,
6490
+ L: 183,
6508
6491
  S: this,
6509
6492
  A: [
6510
6493
  "credential.subject.id.equals(this._signingContext.identityKey)",
@@ -6740,7 +6723,7 @@ var InvitationsManager = class {
6740
6723
  }
6741
6724
  }
6742
6725
  _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 ?? {};
6726
+ 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
6727
  const authCode = options?.authCode ?? (authMethod === Invitation9.AuthMethod.SHARED_SECRET ? generatePasscode(AUTHENTICATION_CODE_LENGTH) : void 0);
6745
6728
  return {
6746
6729
  invitationId,
@@ -7406,7 +7389,7 @@ import { trace as Trace3 } from "@dxos/tracing";
7406
7389
  import { safeInstanceof } from "@dxos/util";
7407
7390
 
7408
7391
  // packages/sdk/client-services/src/packlets/identity/identity-recovery-manager.ts
7409
- import { generateSeedPhrase as generateSeedPhrase2, keyPairFromSeedPhrase as keyPairFromSeedPhrase2 } from "@dxos/credentials";
7392
+ import { generateSeedPhrase, keyPairFromSeedPhrase } from "@dxos/credentials";
7410
7393
  import { sign as sign3 } from "@dxos/crypto";
7411
7394
  import { invariant as invariant19 } from "@dxos/invariant";
7412
7395
  import { PublicKey as PublicKey14 } from "@dxos/keys";
@@ -7422,27 +7405,41 @@ var EdgeIdentityRecoveryManager = class {
7422
7405
  this._identityProvider = _identityProvider;
7423
7406
  this._acceptRecoveredIdentity = _acceptRecoveredIdentity;
7424
7407
  }
7425
- async createRecoveryPhrase() {
7408
+ async createRecoveryCredential({ recoveryKey, algorithm }) {
7426
7409
  const identity = this._identityProvider();
7427
7410
  invariant19(identity, void 0, {
7428
7411
  F: __dxlog_file27,
7429
- L: 29,
7412
+ L: 37,
7430
7413
  S: this,
7431
7414
  A: [
7432
7415
  "identity",
7433
7416
  ""
7434
7417
  ]
7435
7418
  });
7436
- const seedphrase = generateSeedPhrase2();
7437
- const keypair = keyPairFromSeedPhrase2(seedphrase);
7438
- const recoveryKey = PublicKey14.from(keypair.publicKey);
7419
+ let recoveryCode;
7420
+ if (!recoveryKey) {
7421
+ recoveryCode = generateSeedPhrase();
7422
+ const keypair = keyPairFromSeedPhrase(recoveryCode);
7423
+ recoveryKey = PublicKey14.from(keypair.publicKey);
7424
+ algorithm = -8;
7425
+ }
7426
+ invariant19(algorithm, "Algorithm is required.", {
7427
+ F: __dxlog_file27,
7428
+ L: 47,
7429
+ S: this,
7430
+ A: [
7431
+ "algorithm",
7432
+ "'Algorithm is required.'"
7433
+ ]
7434
+ });
7439
7435
  const identityKey = identity.identityKey;
7440
7436
  const credential = await identity.getIdentityCredentialSigner().createCredential({
7441
7437
  subject: identityKey,
7442
7438
  assertion: {
7443
7439
  "@type": "dxos.halo.credentials.IdentityRecovery",
7444
7440
  recoveryKey,
7445
- identityKey
7441
+ identityKey,
7442
+ algorithm
7446
7443
  }
7447
7444
  });
7448
7445
  const receipt = await identity.controlPipeline.writer.write({
@@ -7457,20 +7454,20 @@ var EdgeIdentityRecoveryManager = class {
7457
7454
  ]
7458
7455
  ]));
7459
7456
  return {
7460
- seedphrase
7457
+ recoveryCode
7461
7458
  };
7462
7459
  }
7463
- async recoverIdentity(args) {
7460
+ async recoverIdentity({ recoveryCode }) {
7464
7461
  invariant19(this._edgeClient, "Not connected to EDGE.", {
7465
7462
  F: __dxlog_file27,
7466
- L: 51,
7463
+ L: 66,
7467
7464
  S: this,
7468
7465
  A: [
7469
7466
  "this._edgeClient",
7470
7467
  "'Not connected to EDGE.'"
7471
7468
  ]
7472
7469
  });
7473
- const recoveryKeypair = keyPairFromSeedPhrase2(args.seedphrase);
7470
+ const recoveryKeypair = keyPairFromSeedPhrase(recoveryCode);
7474
7471
  const recoveryKey = PublicKey14.from(recoveryKeypair.publicKey);
7475
7472
  const deviceKey = await this._keyring.createKey();
7476
7473
  const controlFeedKey = await this._keyring.createKey();
@@ -7494,7 +7491,7 @@ var EdgeIdentityRecoveryManager = class {
7494
7491
  }
7495
7492
  log23.info("recovering identity", response, {
7496
7493
  F: __dxlog_file27,
7497
- L: 77,
7494
+ L: 92,
7498
7495
  S: this,
7499
7496
  C: (f, a) => f(...a)
7500
7497
  });
@@ -9096,4 +9093,4 @@ export {
9096
9093
  importProfileData,
9097
9094
  ClientServicesHost
9098
9095
  };
9099
- //# sourceMappingURL=chunk-EVMMT65L.mjs.map
9096
+ //# sourceMappingURL=chunk-OHBCYJRF.mjs.map