@dxos/client-services 0.8.4-main.b97322e → 0.8.4-main.bcb3aa67d6

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 (222) hide show
  1. package/dist/lib/browser/{chunk-WKKP35EC.mjs → chunk-5A3KX2RY.mjs} +4406 -3958
  2. package/dist/lib/browser/chunk-5A3KX2RY.mjs.map +7 -0
  3. package/dist/lib/browser/chunk-NQSC7HOE.mjs +22 -0
  4. package/dist/lib/browser/chunk-NQSC7HOE.mjs.map +7 -0
  5. package/dist/lib/browser/chunk-QCWEHHJW.mjs +24 -0
  6. package/dist/lib/browser/chunk-QCWEHHJW.mjs.map +7 -0
  7. package/dist/lib/browser/index.mjs +481 -78
  8. package/dist/lib/browser/index.mjs.map +4 -4
  9. package/dist/lib/browser/meta.json +1 -1
  10. package/dist/lib/browser/packlets/diagnostics/browser-diagnostics-broadcast.mjs +93 -0
  11. package/dist/lib/browser/packlets/diagnostics/browser-diagnostics-broadcast.mjs.map +7 -0
  12. package/dist/lib/browser/packlets/diagnostics/diagnostics-broadcast.mjs +11 -0
  13. package/dist/lib/browser/packlets/diagnostics/diagnostics-broadcast.mjs.map +7 -0
  14. package/dist/lib/browser/packlets/locks/browser.mjs +126 -0
  15. package/dist/lib/browser/packlets/locks/browser.mjs.map +7 -0
  16. package/dist/lib/browser/packlets/locks/node.mjs +66 -0
  17. package/dist/lib/browser/packlets/locks/node.mjs.map +7 -0
  18. package/dist/lib/browser/testing/index.mjs +45 -26
  19. package/dist/lib/browser/testing/index.mjs.map +3 -3
  20. package/dist/lib/node-esm/chunk-2SZHAWBN.mjs +24 -0
  21. package/dist/lib/node-esm/chunk-2SZHAWBN.mjs.map +7 -0
  22. package/dist/lib/node-esm/{chunk-ZE2HYS56.mjs → chunk-FNPO5UMU.mjs} +4302 -3722
  23. package/dist/lib/node-esm/chunk-FNPO5UMU.mjs.map +7 -0
  24. package/dist/lib/node-esm/chunk-PKEGMOQ4.mjs +22 -0
  25. package/dist/lib/node-esm/chunk-PKEGMOQ4.mjs.map +7 -0
  26. package/dist/lib/node-esm/index.mjs +481 -78
  27. package/dist/lib/node-esm/index.mjs.map +4 -4
  28. package/dist/lib/node-esm/meta.json +1 -1
  29. package/dist/lib/node-esm/packlets/diagnostics/browser-diagnostics-broadcast.mjs +93 -0
  30. package/dist/lib/node-esm/packlets/diagnostics/browser-diagnostics-broadcast.mjs.map +7 -0
  31. package/dist/lib/node-esm/packlets/diagnostics/diagnostics-broadcast.mjs +11 -0
  32. package/dist/lib/node-esm/packlets/diagnostics/diagnostics-broadcast.mjs.map +7 -0
  33. package/dist/lib/node-esm/packlets/locks/browser.mjs +126 -0
  34. package/dist/lib/node-esm/packlets/locks/browser.mjs.map +7 -0
  35. package/dist/lib/node-esm/packlets/locks/node.mjs +66 -0
  36. package/dist/lib/node-esm/packlets/locks/node.mjs.map +7 -0
  37. package/dist/lib/node-esm/testing/index.mjs +45 -26
  38. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  39. package/dist/types/src/index.d.ts +1 -0
  40. package/dist/types/src/index.d.ts.map +1 -1
  41. package/dist/types/src/packlets/agents/edge-agent-manager.d.ts +3 -2
  42. package/dist/types/src/packlets/agents/edge-agent-manager.d.ts.map +1 -1
  43. package/dist/types/src/packlets/agents/edge-agent-service.d.ts +1 -1
  44. package/dist/types/src/packlets/agents/edge-agent-service.d.ts.map +1 -1
  45. package/dist/types/src/packlets/devices/devices-service.d.ts.map +1 -1
  46. package/dist/types/src/packlets/devtools/devtools.d.ts +20 -20
  47. package/dist/types/src/packlets/devtools/devtools.d.ts.map +1 -1
  48. package/dist/types/src/packlets/devtools/feeds.d.ts +1 -1
  49. package/dist/types/src/packlets/devtools/feeds.d.ts.map +1 -1
  50. package/dist/types/src/packlets/devtools/network.d.ts +1 -1
  51. package/dist/types/src/packlets/devtools/network.d.ts.map +1 -1
  52. package/dist/types/src/packlets/diagnostics/browser-diagnostics-broadcast.d.ts +1 -1
  53. package/dist/types/src/packlets/diagnostics/browser-diagnostics-broadcast.d.ts.map +1 -1
  54. package/dist/types/src/packlets/diagnostics/diagnostics-broadcast.d.ts +1 -1
  55. package/dist/types/src/packlets/diagnostics/diagnostics-broadcast.d.ts.map +1 -1
  56. package/dist/types/src/packlets/diagnostics/diagnostics.d.ts +1 -1
  57. package/dist/types/src/packlets/diagnostics/diagnostics.d.ts.map +1 -1
  58. package/dist/types/src/packlets/diagnostics/index.d.ts +1 -1
  59. package/dist/types/src/packlets/diagnostics/index.d.ts.map +1 -1
  60. package/dist/types/src/packlets/identity/authenticator.d.ts +2 -2
  61. package/dist/types/src/packlets/identity/authenticator.d.ts.map +1 -1
  62. package/dist/types/src/packlets/identity/contacts-service.d.ts +1 -1
  63. package/dist/types/src/packlets/identity/contacts-service.d.ts.map +1 -1
  64. package/dist/types/src/packlets/identity/identity-manager.d.ts +7 -7
  65. package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
  66. package/dist/types/src/packlets/identity/identity-recovery-manager.d.ts +7 -6
  67. package/dist/types/src/packlets/identity/identity-recovery-manager.d.ts.map +1 -1
  68. package/dist/types/src/packlets/identity/identity-service.d.ts +1 -6
  69. package/dist/types/src/packlets/identity/identity-service.d.ts.map +1 -1
  70. package/dist/types/src/packlets/identity/identity.d.ts +9 -12
  71. package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
  72. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts +4 -4
  73. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts.map +1 -1
  74. package/dist/types/src/packlets/invitations/edge-invitation-handler.d.ts +1 -1
  75. package/dist/types/src/packlets/invitations/edge-invitation-handler.d.ts.map +1 -1
  76. package/dist/types/src/packlets/invitations/invitation-guest-extenstion.d.ts.map +1 -1
  77. package/dist/types/src/packlets/invitations/invitation-host-extension.d.ts.map +1 -1
  78. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts +3 -4
  79. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts.map +1 -1
  80. package/dist/types/src/packlets/invitations/invitations-handler.d.ts +4 -4
  81. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  82. package/dist/types/src/packlets/invitations/invitations-manager.d.ts +3 -3
  83. package/dist/types/src/packlets/invitations/invitations-manager.d.ts.map +1 -1
  84. package/dist/types/src/packlets/invitations/invitations-service.d.ts +1 -1
  85. package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
  86. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts +3 -3
  87. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
  88. package/dist/types/src/packlets/invitations/utils.d.ts.map +1 -1
  89. package/dist/types/src/packlets/locks/index.d.ts +1 -1
  90. package/dist/types/src/packlets/locks/index.d.ts.map +1 -1
  91. package/dist/types/src/packlets/logging/logging-service.d.ts +5 -1
  92. package/dist/types/src/packlets/logging/logging-service.d.ts.map +1 -1
  93. package/dist/types/src/packlets/network/network-service.d.ts +2 -2
  94. package/dist/types/src/packlets/network/network-service.d.ts.map +1 -1
  95. package/dist/types/src/packlets/services/client-rpc-server.d.ts +2 -2
  96. package/dist/types/src/packlets/services/client-rpc-server.d.ts.map +1 -1
  97. package/dist/types/src/packlets/services/feed-syncer.d.ts +59 -0
  98. package/dist/types/src/packlets/services/feed-syncer.d.ts.map +1 -0
  99. package/dist/types/src/packlets/services/feed-syncer.test.d.ts +2 -0
  100. package/dist/types/src/packlets/services/feed-syncer.test.d.ts.map +1 -0
  101. package/dist/types/src/packlets/services/platform.d.ts.map +1 -1
  102. package/dist/types/src/packlets/services/service-context.d.ts +14 -9
  103. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  104. package/dist/types/src/packlets/services/service-host.d.ts +20 -6
  105. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  106. package/dist/types/src/packlets/space-export/space-archive-reader.d.ts +9 -1
  107. package/dist/types/src/packlets/space-export/space-archive-reader.d.ts.map +1 -1
  108. package/dist/types/src/packlets/space-export/space-archive-writer.d.ts +7 -1
  109. package/dist/types/src/packlets/space-export/space-archive-writer.d.ts.map +1 -1
  110. package/dist/types/src/packlets/space-export/space-archive.test.d.ts +2 -0
  111. package/dist/types/src/packlets/space-export/space-archive.test.d.ts.map +1 -0
  112. package/dist/types/src/packlets/spaces/automerge-space-state.d.ts +1 -1
  113. package/dist/types/src/packlets/spaces/automerge-space-state.d.ts.map +1 -1
  114. package/dist/types/src/packlets/spaces/data-space-manager.d.ts +28 -16
  115. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  116. package/dist/types/src/packlets/spaces/data-space.d.ts +28 -12
  117. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  118. package/dist/types/src/packlets/spaces/edge-feed-replicator.d.ts +2 -2
  119. package/dist/types/src/packlets/spaces/edge-feed-replicator.d.ts.map +1 -1
  120. package/dist/types/src/packlets/spaces/genesis.d.ts +2 -1
  121. package/dist/types/src/packlets/spaces/genesis.d.ts.map +1 -1
  122. package/dist/types/src/packlets/spaces/notarization-plugin.d.ts +6 -6
  123. package/dist/types/src/packlets/spaces/notarization-plugin.d.ts.map +1 -1
  124. package/dist/types/src/packlets/spaces/spaces-service.d.ts +3 -3
  125. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  126. package/dist/types/src/packlets/storage/profile-archive.d.ts.map +1 -1
  127. package/dist/types/src/packlets/storage/storage.d.ts.map +1 -1
  128. package/dist/types/src/packlets/system/system-service.d.ts +1 -1
  129. package/dist/types/src/packlets/system/system-service.d.ts.map +1 -1
  130. package/dist/types/src/packlets/testing/invitation-utils.d.ts +6 -3
  131. package/dist/types/src/packlets/testing/invitation-utils.d.ts.map +1 -1
  132. package/dist/types/src/packlets/testing/test-builder.d.ts +8 -7
  133. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  134. package/dist/types/src/packlets/worker/worker-runtime.d.ts +31 -4
  135. package/dist/types/src/packlets/worker/worker-runtime.d.ts.map +1 -1
  136. package/dist/types/src/packlets/worker/worker-session.d.ts +2 -2
  137. package/dist/types/src/packlets/worker/worker-session.d.ts.map +1 -1
  138. package/dist/types/src/version.d.ts +1 -1
  139. package/dist/types/src/version.d.ts.map +1 -1
  140. package/dist/types/tsconfig.tsbuildinfo +1 -1
  141. package/package.json +72 -48
  142. package/src/index.ts +1 -0
  143. package/src/packlets/agents/edge-agent-manager.ts +10 -7
  144. package/src/packlets/agents/edge-agent-service.ts +15 -5
  145. package/src/packlets/devices/devices-service.test.ts +4 -3
  146. package/src/packlets/devices/devices-service.ts +2 -2
  147. package/src/packlets/devtools/devtools.ts +30 -29
  148. package/src/packlets/devtools/feeds.ts +2 -2
  149. package/src/packlets/devtools/network.ts +1 -1
  150. package/src/packlets/diagnostics/browser-diagnostics-broadcast.ts +1 -1
  151. package/src/packlets/diagnostics/diagnostics-broadcast.ts +1 -1
  152. package/src/packlets/diagnostics/diagnostics-collector.ts +1 -1
  153. package/src/packlets/diagnostics/diagnostics.ts +1 -1
  154. package/src/packlets/diagnostics/index.ts +1 -1
  155. package/src/packlets/identity/authenticator.node.test.ts +1 -1
  156. package/src/packlets/identity/authenticator.ts +3 -3
  157. package/src/packlets/identity/contacts-service.ts +3 -2
  158. package/src/packlets/identity/identity-manager.test.ts +8 -8
  159. package/src/packlets/identity/identity-manager.ts +23 -20
  160. package/src/packlets/identity/identity-recovery-manager.ts +22 -18
  161. package/src/packlets/identity/identity-service.test.ts +9 -28
  162. package/src/packlets/identity/identity-service.ts +5 -75
  163. package/src/packlets/identity/identity.test.ts +11 -11
  164. package/src/packlets/identity/identity.ts +16 -37
  165. package/src/packlets/invitations/device-invitation-protocol.test.ts +1 -1
  166. package/src/packlets/invitations/device-invitation-protocol.ts +6 -5
  167. package/src/packlets/invitations/edge-invitation-handler.ts +5 -4
  168. package/src/packlets/invitations/invitation-guest-extenstion.ts +7 -5
  169. package/src/packlets/invitations/invitation-host-extension.ts +8 -6
  170. package/src/packlets/invitations/invitation-protocol.ts +3 -4
  171. package/src/packlets/invitations/invitations-handler.test.ts +8 -7
  172. package/src/packlets/invitations/invitations-handler.ts +13 -13
  173. package/src/packlets/invitations/invitations-manager.ts +40 -17
  174. package/src/packlets/invitations/invitations-service.ts +5 -5
  175. package/src/packlets/invitations/space-invitation-protocol.test.ts +19 -18
  176. package/src/packlets/invitations/space-invitation-protocol.ts +13 -16
  177. package/src/packlets/invitations/utils.ts +1 -1
  178. package/src/packlets/locks/browser.ts +1 -1
  179. package/src/packlets/locks/index.ts +1 -1
  180. package/src/packlets/logging/logging-service.ts +7 -3
  181. package/src/packlets/logging/logging.test.ts +1 -1
  182. package/src/packlets/network/network-service.test.ts +4 -3
  183. package/src/packlets/network/network-service.ts +7 -6
  184. package/src/packlets/services/client-rpc-server.ts +5 -5
  185. package/src/packlets/services/feed-syncer.test.ts +340 -0
  186. package/src/packlets/services/feed-syncer.ts +337 -0
  187. package/src/packlets/services/platform.ts +7 -1
  188. package/src/packlets/services/service-context.test.ts +4 -3
  189. package/src/packlets/services/service-context.ts +139 -52
  190. package/src/packlets/services/service-host.test.ts +11 -9
  191. package/src/packlets/services/service-host.ts +78 -28
  192. package/src/packlets/services/service-registry.test.ts +2 -1
  193. package/src/packlets/space-export/space-archive-reader.ts +65 -4
  194. package/src/packlets/space-export/space-archive-writer.ts +42 -5
  195. package/src/packlets/space-export/space-archive.test.ts +287 -0
  196. package/src/packlets/space-export/tar.test.ts +1 -1
  197. package/src/packlets/spaces/automerge-space-state.ts +1 -1
  198. package/src/packlets/spaces/data-space-manager.test.ts +79 -13
  199. package/src/packlets/spaces/data-space-manager.ts +124 -116
  200. package/src/packlets/spaces/data-space.ts +60 -35
  201. package/src/packlets/spaces/edge-feed-replicator.test.ts +4 -4
  202. package/src/packlets/spaces/edge-feed-replicator.ts +12 -11
  203. package/src/packlets/spaces/epoch-migrations.ts +5 -5
  204. package/src/packlets/spaces/genesis.ts +6 -1
  205. package/src/packlets/spaces/notarization-plugin.test.ts +3 -3
  206. package/src/packlets/spaces/notarization-plugin.ts +13 -12
  207. package/src/packlets/spaces/spaces-service.test.ts +12 -8
  208. package/src/packlets/spaces/spaces-service.ts +57 -31
  209. package/src/packlets/storage/profile-archive.ts +1 -1
  210. package/src/packlets/storage/storage.ts +7 -8
  211. package/src/packlets/system/system-service.test.ts +1 -1
  212. package/src/packlets/system/system-service.ts +4 -4
  213. package/src/packlets/testing/invitation-utils.ts +11 -7
  214. package/src/packlets/testing/test-builder.ts +39 -13
  215. package/src/packlets/worker/worker-runtime.ts +152 -13
  216. package/src/packlets/worker/worker-session.ts +11 -11
  217. package/src/version.ts +1 -1
  218. package/dist/lib/browser/chunk-WKKP35EC.mjs.map +0 -7
  219. package/dist/lib/node-esm/chunk-ZE2HYS56.mjs.map +0 -7
  220. package/dist/types/src/packlets/identity/default-space-state-machine.d.ts +0 -19
  221. package/dist/types/src/packlets/identity/default-space-state-machine.d.ts.map +0 -1
  222. package/src/packlets/identity/default-space-state-machine.ts +0 -44
@@ -4,40 +4,39 @@
4
4
 
5
5
  import { Event } from '@dxos/async';
6
6
  import { AUTH_TIMEOUT, LOAD_CONTROL_FEEDS_TIMEOUT } from '@dxos/client-protocol';
7
- import { type Context } from '@dxos/context';
7
+ import { type Context as DxosContext } from '@dxos/context';
8
8
  import {
9
- DeviceStateMachine,
10
9
  type CredentialSigner,
11
- createCredentialSignerWithKey,
12
- createCredentialSignerWithChain,
10
+ DeviceStateMachine,
13
11
  ProfileStateMachine,
12
+ createCredentialSignerWithChain,
13
+ createCredentialSignerWithKey,
14
14
  } from '@dxos/credentials';
15
15
  import { type Signer } from '@dxos/crypto';
16
16
  import { type Space } from '@dxos/echo-pipeline';
17
17
  import { type EdgeConnection } from '@dxos/edge-client';
18
- import { writeMessages, type FeedWrapper } from '@dxos/feed-store';
18
+ import { type FeedWrapper, writeMessages } from '@dxos/feed-store';
19
19
  import { invariant } from '@dxos/invariant';
20
- import { type IdentityDid, PublicKey, type SpaceId } from '@dxos/keys';
20
+ import { type IdentityDid, PublicKey } from '@dxos/keys';
21
21
  import { log } from '@dxos/log';
22
22
  import { type Runtime } from '@dxos/protocols/proto/dxos/config';
23
23
  import { type FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';
24
24
  import {
25
25
  AdmittedFeed,
26
+ type Credential,
26
27
  type DeviceProfileDocument,
27
28
  type ProfileDocument,
28
- type Credential,
29
29
  } from '@dxos/protocols/proto/dxos/halo/credentials';
30
30
  import { type DeviceAdmissionRequest } from '@dxos/protocols/proto/dxos/halo/invitations';
31
31
  import { type Presence } from '@dxos/teleport-extension-gossip';
32
- import { Timeframe } from '@dxos/timeframe';
33
32
  import { trace } from '@dxos/tracing';
34
33
  import { type ComplexMap, ComplexSet } from '@dxos/util';
35
34
 
36
- import { TrustedKeySetAuthVerifier } from './authenticator';
37
- import { DefaultSpaceStateMachine } from './default-space-state-machine';
38
35
  import { EdgeFeedReplicator } from '../spaces';
39
36
 
40
- export type IdentityParams = {
37
+ import { TrustedKeySetAuthVerifier } from './authenticator';
38
+
39
+ export type IdentityProps = {
41
40
  did: IdentityDid;
42
41
  identityKey: PublicKey;
43
42
  deviceKey: PublicKey;
@@ -59,7 +58,6 @@ export class Identity {
59
58
  private readonly _presence?: Presence;
60
59
  private readonly _deviceStateMachine: DeviceStateMachine;
61
60
  private readonly _profileStateMachine: ProfileStateMachine;
62
- private readonly _defaultSpaceStateMachine: DefaultSpaceStateMachine;
63
61
  private readonly _edgeFeedReplicator?: EdgeFeedReplicator = undefined;
64
62
 
65
63
  public readonly authVerifier: TrustedKeySetAuthVerifier;
@@ -70,7 +68,7 @@ export class Identity {
70
68
 
71
69
  public readonly stateUpdate = new Event();
72
70
 
73
- constructor(params: IdentityParams) {
71
+ constructor(params: IdentityProps) {
74
72
  this.space = params.space;
75
73
  this._signer = params.signer;
76
74
  this._presence = params.presence;
@@ -90,10 +88,6 @@ export class Identity {
90
88
  identityKey: this.identityKey,
91
89
  onUpdate: () => this.stateUpdate.emit(),
92
90
  });
93
- this._defaultSpaceStateMachine = new DefaultSpaceStateMachine({
94
- identityKey: this.identityKey,
95
- onUpdate: () => this.stateUpdate.emit(),
96
- });
97
91
 
98
92
  this.authVerifier = new TrustedKeySetAuthVerifier({
99
93
  trustedKeysProvider: () => new ComplexSet(PublicKey.hash, this.authorizedDeviceKeys.keys()),
@@ -111,32 +105,26 @@ export class Identity {
111
105
  return this._deviceStateMachine.authorizedDeviceKeys;
112
106
  }
113
107
 
114
- get defaultSpaceId(): SpaceId | undefined {
115
- return this._defaultSpaceStateMachine.spaceId;
116
- }
117
-
118
108
  @trace.span()
119
- async open(ctx: Context): Promise<void> {
109
+ async open(ctx: DxosContext): Promise<void> {
120
110
  await this._presence?.open();
121
111
  await this.space.spaceState.addCredentialProcessor(this._deviceStateMachine);
122
112
  await this.space.spaceState.addCredentialProcessor(this._profileStateMachine);
123
- await this.space.spaceState.addCredentialProcessor(this._defaultSpaceStateMachine);
124
113
  if (this._edgeFeedReplicator) {
125
114
  this.space.protocol.feedAdded.append(this._onFeedAdded);
126
115
  }
127
116
  await this.space.open(ctx);
128
117
  }
129
118
 
130
- public async joinNetwork(): Promise<void> {
131
- await this.space.startProtocol();
119
+ public async joinNetwork(ctx: DxosContext): Promise<void> {
120
+ await this.space.startProtocol(ctx);
132
121
  await this._edgeFeedReplicator?.open();
133
122
  }
134
123
 
135
124
  @trace.span()
136
- async close(ctx: Context): Promise<void> {
125
+ async close(ctx: DxosContext): Promise<void> {
137
126
  await this._presence?.close();
138
127
  await this.authVerifier.close();
139
- await this.space.spaceState.removeCredentialProcessor(this._defaultSpaceStateMachine);
140
128
  await this.space.spaceState.removeCredentialProcessor(this._profileStateMachine);
141
129
  await this.space.spaceState.removeCredentialProcessor(this._deviceStateMachine);
142
130
 
@@ -146,7 +134,7 @@ export class Identity {
146
134
 
147
135
  await this._edgeFeedReplicator?.close();
148
136
 
149
- await this.space.close();
137
+ await this.space.close(ctx);
150
138
  }
151
139
 
152
140
  async ready(): Promise<void> {
@@ -210,15 +198,6 @@ export class Identity {
210
198
  return createCredentialSignerWithKey(this._signer, this.deviceKey);
211
199
  }
212
200
 
213
- async updateDefaultSpace(spaceId: SpaceId): Promise<void> {
214
- const credential = await this.getDeviceCredentialSigner().createCredential({
215
- subject: this.identityKey,
216
- assertion: { '@type': 'dxos.halo.credentials.DefaultSpace', spaceId },
217
- });
218
- const receipt = await this.controlPipeline.writer.write({ credential: { credential } });
219
- await this.controlPipeline.state.waitUntilTimeframe(new Timeframe([[receipt.feedKey, receipt.seq]]));
220
- }
221
-
222
201
  async admitDevice({ deviceKey, controlFeedKey, dataFeedKey }: DeviceAdmissionRequest): Promise<Credential> {
223
202
  log('Admitting device:', {
224
203
  identityKey: this.identityKey,
@@ -2,7 +2,7 @@
2
2
  // Copyright 2022 DXOS.org
3
3
  //
4
4
 
5
- import { describe, expect, test, onTestFinished } from 'vitest';
5
+ import { describe, expect, onTestFinished, test } from 'vitest';
6
6
 
7
7
  import { chain } from '@dxos/async';
8
8
  import { Context } from '@dxos/context';
@@ -6,7 +6,7 @@ import { getCredentialAssertion } from '@dxos/credentials';
6
6
  import { invariant } from '@dxos/invariant';
7
7
  import { type Keyring } from '@dxos/keyring';
8
8
  import { type PublicKey } from '@dxos/keys';
9
- import { AlreadyJoinedError, type ApiError } from '@dxos/protocols';
9
+ import { AlreadyJoinedError } from '@dxos/protocols';
10
10
  import { Invitation } from '@dxos/protocols/proto/dxos/client/services';
11
11
  import type { DeviceProfileDocument } from '@dxos/protocols/proto/dxos/halo/credentials';
12
12
  import {
@@ -15,14 +15,15 @@ import {
15
15
  type IntroductionRequest,
16
16
  } from '@dxos/protocols/proto/dxos/halo/invitations';
17
17
 
18
+ import { type Identity, type JoinIdentityProps } from '../identity';
19
+
18
20
  import { type InvitationProtocol } from './invitation-protocol';
19
- import { type Identity, type JoinIdentityParams } from '../identity';
20
21
 
21
22
  export class DeviceInvitationProtocol implements InvitationProtocol {
22
23
  constructor(
23
24
  private readonly _keyring: Keyring,
24
25
  private readonly _getIdentity: () => Identity,
25
- private readonly _acceptIdentity: (identity: JoinIdentityParams) => Promise<Identity>,
26
+ private readonly _acceptIdentity: (identity: JoinIdentityProps) => Promise<Identity>,
26
27
  ) {}
27
28
 
28
29
  toJSON(): object {
@@ -31,7 +32,7 @@ export class DeviceInvitationProtocol implements InvitationProtocol {
31
32
  };
32
33
  }
33
34
 
34
- checkCanInviteNewMembers(): ApiError | undefined {
35
+ checkCanInviteNewMembers(): Error | undefined {
35
36
  return undefined;
36
37
  }
37
38
 
@@ -70,7 +71,7 @@ export class DeviceInvitationProtocol implements InvitationProtocol {
70
71
  try {
71
72
  const identity = this._getIdentity();
72
73
  if (identity) {
73
- return new AlreadyJoinedError('Currently only one identity per client is supported.');
74
+ return new AlreadyJoinedError({ message: 'Currently only one identity per client is supported.' });
74
75
  }
75
76
  } catch {
76
77
  // No identity.
@@ -19,8 +19,8 @@ import { schema } from '@dxos/protocols/proto';
19
19
  import { Invitation } from '@dxos/protocols/proto/dxos/client/services';
20
20
  import { type DeviceProfileDocument } from '@dxos/protocols/proto/dxos/halo/credentials';
21
21
  import {
22
- type AdmissionResponse,
23
22
  type AdmissionRequest,
23
+ type AdmissionResponse,
24
24
  type SpaceAdmissionRequest,
25
25
  } from '@dxos/protocols/proto/dxos/halo/invitations';
26
26
 
@@ -126,7 +126,7 @@ export class EdgeInvitationHandler implements FlowLockHolder {
126
126
 
127
127
  guardedState.set(this, Invitation.State.CONNECTING);
128
128
 
129
- const response = await this._joinSpaceByInvitation(guardedState, spaceId, {
129
+ const response = await this._joinSpaceByInvitation(ctx, guardedState, spaceId, {
130
130
  identityKey: admissionRequest.identityKey.toHex(),
131
131
  invitationId: guardedState.current.invitationId,
132
132
  });
@@ -153,13 +153,14 @@ export class EdgeInvitationHandler implements FlowLockHolder {
153
153
  }
154
154
 
155
155
  private async _joinSpaceByInvitation(
156
+ ctx: Context,
156
157
  guardedState: GuardedInvitationState,
157
158
  spaceId: SpaceId,
158
159
  request: JoinSpaceRequest,
159
160
  ): Promise<JoinSpaceResponseBody> {
160
161
  invariant(this._client);
161
162
  try {
162
- return await this._client.joinSpaceByInvitation(spaceId, request);
163
+ return await this._client.joinSpaceByInvitation(ctx, spaceId, request);
163
164
  } catch (error: any) {
164
165
  if (error instanceof EdgeAuthChallengeError) {
165
166
  const publicKey = guardedState.current.guestKeypair?.publicKey;
@@ -168,7 +169,7 @@ export class EdgeInvitationHandler implements FlowLockHolder {
168
169
  throw error;
169
170
  }
170
171
  const signature = sign(Buffer.from(error.challenge, 'base64'), privateKey);
171
- return this._client.joinSpaceByInvitation(spaceId, {
172
+ return this._client.joinSpaceByInvitation(ctx, spaceId, {
172
173
  ...request,
173
174
  signature: Buffer.from(signature).toString('base64'),
174
175
  });
@@ -3,7 +3,7 @@
3
3
  //
4
4
 
5
5
  import { type Mutex, type MutexGuard, Trigger } from '@dxos/async';
6
- import { cancelWithContext, Context } from '@dxos/context';
6
+ import { Context, cancelWithContext } from '@dxos/context';
7
7
  import { invariant } from '@dxos/invariant';
8
8
  import { log } from '@dxos/log';
9
9
  import { InvalidInvitationExtensionRoleError } from '@dxos/protocols';
@@ -97,10 +97,12 @@ export class InvitationGuestExtension
97
97
  await cancelWithContext(this._ctx, this._remoteOptionsTrigger.wait({ timeout: OPTIONS_TIMEOUT }));
98
98
  log.verbose('options received');
99
99
  if (this._remoteOptions?.role !== InvitationOptions.Role.HOST) {
100
- throw new InvalidInvitationExtensionRoleError(undefined, {
101
- expected: InvitationOptions.Role.HOST,
102
- remoteOptions: this._remoteOptions,
103
- remotePeerId: context.remotePeerId,
100
+ throw new InvalidInvitationExtensionRoleError({
101
+ context: {
102
+ expected: InvitationOptions.Role.HOST,
103
+ remoteOptions: this._remoteOptions,
104
+ remotePeerId: context.remotePeerId,
105
+ },
104
106
  });
105
107
  }
106
108
 
@@ -3,9 +3,9 @@
3
3
  //
4
4
 
5
5
  import { type Mutex, type MutexGuard, Trigger, scheduleTask } from '@dxos/async';
6
- import { cancelWithContext, Context } from '@dxos/context';
6
+ import { Context, cancelWithContext } from '@dxos/context';
7
7
  import { randomBytes, verify } from '@dxos/crypto';
8
- import { invariant, InvariantViolation } from '@dxos/invariant';
8
+ import { InvariantViolation, invariant } from '@dxos/invariant';
9
9
  import { PublicKey } from '@dxos/keys';
10
10
  import { log } from '@dxos/log';
11
11
  import { InvalidInvitationExtensionRoleError, trace } from '@dxos/protocols';
@@ -245,10 +245,12 @@ export class InvitationHostExtension
245
245
  await cancelWithContext(this._ctx, this._remoteOptionsTrigger.wait({ timeout: OPTIONS_TIMEOUT }));
246
246
  log.verbose('options received');
247
247
  if (this._remoteOptions?.role !== InvitationOptions.Role.GUEST) {
248
- throw new InvalidInvitationExtensionRoleError(undefined, {
249
- expected: InvitationOptions.Role.GUEST,
250
- remoteOptions: this._remoteOptions,
251
- remotePeerId: context.remotePeerId,
248
+ throw new InvalidInvitationExtensionRoleError({
249
+ context: {
250
+ expected: InvitationOptions.Role.GUEST,
251
+ remoteOptions: this._remoteOptions,
252
+ remotePeerId: context.remotePeerId,
253
+ },
252
254
  });
253
255
  }
254
256
  this._callbacks.onStateUpdate(Invitation.State.CONNECTED);
@@ -3,9 +3,8 @@
3
3
  //
4
4
 
5
5
  import { type PublicKey } from '@dxos/keys';
6
- import type { ApiError } from '@dxos/protocols';
7
6
  import type { Invitation } from '@dxos/protocols/proto/dxos/client/services';
8
- import type { ProfileDocument, DeviceProfileDocument } from '@dxos/protocols/proto/dxos/halo/credentials';
7
+ import type { DeviceProfileDocument, ProfileDocument } from '@dxos/protocols/proto/dxos/halo/credentials';
9
8
  import type {
10
9
  AdmissionRequest,
11
10
  AdmissionResponse,
@@ -26,7 +25,7 @@ export interface InvitationProtocol {
26
25
  // Host
27
26
  //
28
27
 
29
- checkCanInviteNewMembers(): ApiError | undefined;
28
+ checkCanInviteNewMembers(): Error | undefined;
30
29
 
31
30
  /**
32
31
  * Protocol-specific information to include in the invitation.
@@ -58,7 +57,7 @@ export interface InvitationProtocol {
58
57
  *
59
58
  * For example, the guest may already be a member of the space.
60
59
  */
61
- checkInvitation(invitation: Partial<Invitation>): ApiError | undefined;
60
+ checkInvitation(invitation: Partial<Invitation>): Error | undefined;
62
61
 
63
62
  /**
64
63
  * Get profile information to send to the host to identify the guest.
@@ -2,19 +2,20 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import { beforeEach, onTestFinished, describe, expect, test } from 'vitest';
5
+ import { beforeEach, describe, expect, onTestFinished, test } from 'vitest';
6
6
 
7
- import { type PushStream, sleep, Trigger, waitForCondition } from '@dxos/async';
7
+ import { type PushStream, Trigger, sleep, waitForCondition } from '@dxos/async';
8
8
  import { Context } from '@dxos/context';
9
9
  import { PublicKey } from '@dxos/keys';
10
10
  import { Invitation } from '@dxos/protocols/proto/dxos/client/services';
11
11
  import { openAndClose } from '@dxos/test-utils';
12
12
  import { range } from '@dxos/util';
13
13
 
14
+ import { TestBuilder, type TestPeer } from '../testing';
15
+
14
16
  import { type InvitationProtocol } from './invitation-protocol';
15
17
  import { InvitationsHandler } from './invitations-handler';
16
18
  import { SpaceInvitationProtocol } from './space-invitation-protocol';
17
- import { TestBuilder, type TestPeer } from '../testing';
18
19
 
19
20
  interface PeerSetup {
20
21
  ctx: Context;
@@ -94,7 +95,7 @@ describe.skipIf(process.env.CI && !process.env.RUN_FLAKY_TESTS)(
94
95
  await acceptInvitation(guest, invitation);
95
96
 
96
97
  await guest.sink.waitFor(Invitation.State.READY_FOR_AUTHENTICATION);
97
- await guest.peer.networkManager.close();
98
+ await guest.peer.networkManager.close(Context.default());
98
99
  await host.sink.waitFor(Invitation.State.CONNECTING);
99
100
 
100
101
  await sleep(10);
@@ -253,9 +254,9 @@ describe.skipIf(process.env.CI && !process.env.RUN_FLAKY_TESTS)(
253
254
  const peer = testBuilder.createPeer();
254
255
  await peer.createIdentity();
255
256
  await openAndClose(peer.echoHost, peer.dataSpaceManager);
256
- await peer.echoHost.addReplicator(peer.meshEchoReplicator);
257
+ await peer.echoHost.addReplicator(Context.default(), peer.meshEchoReplicator);
257
258
  if (spaceKey == null) {
258
- const space = await peer.dataSpaceManager.createSpace();
259
+ const space = await peer.dataSpaceManager.createSpace(new Context());
259
260
  spaceKey = space.key;
260
261
  }
261
262
  const invitationHandler = new InvitationsHandler(peer.networkManager, undefined, {
@@ -358,7 +359,7 @@ describe.skipIf(process.env.CI && !process.env.RUN_FLAKY_TESTS)(
358
359
  };
359
360
 
360
361
  const createInvitation = async (setup: PeerSetup, options?: Partial<Invitation>): Promise<Invitation> => {
361
- const observable = await setup.peer.invitationsManager.createInvitation({
362
+ const observable = await setup.peer.invitationsManager.createInvitation(setup.ctx, {
362
363
  type: Invitation.Type.DELEGATED,
363
364
  kind: Invitation.Kind.SPACE,
364
365
  authMethod: Invitation.AuthMethod.SHARED_SECRET,
@@ -2,7 +2,7 @@
2
2
  // Copyright 2022 DXOS.org
3
3
  //
4
4
 
5
- import { type PushStream, scheduleTask, TimeoutError, type Trigger } from '@dxos/async';
5
+ import { type PushStream, TimeoutError, type Trigger, scheduleTask } from '@dxos/async';
6
6
  import { INVITATION_TIMEOUT, getExpirationTime } from '@dxos/client-protocol';
7
7
  import { type Context, ContextDisposedError } from '@dxos/context';
8
8
  import { createKeyPair, sign } from '@dxos/crypto';
@@ -10,19 +10,19 @@ import { type EdgeHttpClient } from '@dxos/edge-client';
10
10
  import { invariant } from '@dxos/invariant';
11
11
  import { PublicKey } from '@dxos/keys';
12
12
  import { log } from '@dxos/log';
13
- import { createTeleportProtocolFactory, type SwarmNetworkManager, type SwarmConnection } from '@dxos/network-manager';
13
+ import { type SwarmConnection, type SwarmNetworkManager, createTeleportProtocolFactory } from '@dxos/network-manager';
14
14
  import { InvalidInvitationError, InvalidInvitationExtensionRoleError, trace } from '@dxos/protocols';
15
15
  import { type AdmissionKeypair, Invitation } from '@dxos/protocols/proto/dxos/client/services';
16
16
  import { type DeviceProfileDocument } from '@dxos/protocols/proto/dxos/halo/credentials';
17
17
  import { AuthenticationResponse, type IntroductionResponse } from '@dxos/protocols/proto/dxos/halo/invitations';
18
18
  import { InvitationOptions } from '@dxos/protocols/proto/dxos/halo/invitations';
19
- import { type ExtensionContext, type TeleportExtension, type TeleportParams } from '@dxos/teleport';
19
+ import { type ExtensionContext, type TeleportExtension, type TeleportProps } from '@dxos/teleport';
20
20
  import { trace as _trace } from '@dxos/tracing';
21
21
  import { ComplexSet } from '@dxos/util';
22
22
 
23
23
  import { type EdgeInvitationConfig, EdgeInvitationHandler } from './edge-invitation-handler';
24
24
  import { InvitationGuestExtension } from './invitation-guest-extenstion';
25
- import { InvitationHostExtension, isAuthenticationRequired, MAX_OTP_ATTEMPTS } from './invitation-host-extension';
25
+ import { InvitationHostExtension, MAX_OTP_ATTEMPTS, isAuthenticationRequired } from './invitation-host-extension';
26
26
  import { type InvitationProtocol } from './invitation-protocol';
27
27
  import { createGuardedInvitationState } from './invitation-state';
28
28
  import { InvitationTopology } from './invitation-topology';
@@ -31,8 +31,8 @@ const metrics = _trace.metrics;
31
31
 
32
32
  const MAX_DELEGATED_INVITATION_HOST_TRIES = 3;
33
33
 
34
- export type InvitationConnectionParams = {
35
- teleport: Partial<TeleportParams>;
34
+ export type InvitationConnectionProps = {
35
+ teleport: Partial<TeleportProps>;
36
36
  edgeInvitations?: EdgeInvitationConfig;
37
37
  };
38
38
 
@@ -71,7 +71,7 @@ export class InvitationsHandler {
71
71
  constructor(
72
72
  private readonly _networkManager: SwarmNetworkManager,
73
73
  private readonly _edgeClient?: EdgeHttpClient,
74
- private readonly _connectionParams?: InvitationConnectionParams,
74
+ private readonly _connectionProps?: InvitationConnectionProps,
75
75
  ) {}
76
76
 
77
77
  handleInvitationFlow(
@@ -200,7 +200,7 @@ export class InvitationsHandler {
200
200
  ctx,
201
201
  async () => {
202
202
  // ensure the swarm is closed before changing state and closing the stream.
203
- await swarmConnection.close();
203
+ await swarmConnection.close(ctx);
204
204
  guardedState.set(null, Invitation.State.EXPIRED);
205
205
  metrics.increment('dxos.invitation.expired');
206
206
  await ctx.dispose();
@@ -388,7 +388,7 @@ export class InvitationsHandler {
388
388
  return extension;
389
389
  };
390
390
 
391
- const edgeInvitationHandler = new EdgeInvitationHandler(this._connectionParams?.edgeInvitations, this._edgeClient, {
391
+ const edgeInvitationHandler = new EdgeInvitationHandler(this._connectionProps?.edgeInvitations, this._edgeClient, {
392
392
  onInvitationSuccess: async (admissionResponse, admissionRequest) => {
393
393
  const result = await protocol.accept(admissionResponse, admissionRequest);
394
394
  log.info('admitted by edge', { ...protocol.toJSON() });
@@ -436,15 +436,15 @@ export class InvitationsHandler {
436
436
  } else {
437
437
  label = `invitation host for space ${invitation.spaceKey?.truncate()}`;
438
438
  }
439
- const swarmConnection = await this._networkManager.joinSwarm({
439
+ const swarmConnection = await this._networkManager.joinSwarm(ctx, {
440
440
  topic: invitation.swarmKey,
441
441
  protocolProvider: createTeleportProtocolFactory(async (teleport) => {
442
442
  teleport.addExtension('dxos.halo.invitations', extensionFactory());
443
- }, this._connectionParams?.teleport),
443
+ }, this._connectionProps?.teleport),
444
444
  topology: new InvitationTopology(role),
445
445
  label,
446
446
  });
447
- ctx.onDispose(() => swarmConnection.close());
447
+ ctx.onDispose(() => swarmConnection.close(ctx));
448
448
  return swarmConnection;
449
449
  }
450
450
 
@@ -503,7 +503,7 @@ export class InvitationsHandler {
503
503
  const checkInvitation = (protocol: InvitationProtocol, invitation: Partial<Invitation>) => {
504
504
  const expiresOn = getExpirationTime(invitation);
505
505
  if (expiresOn && expiresOn.getTime() < Date.now()) {
506
- return new InvalidInvitationError('Invitation already expired.');
506
+ return new InvalidInvitationError({ message: 'Invitation already expired.' });
507
507
  }
508
508
  return protocol.checkInvitation(invitation);
509
509
  };
@@ -4,14 +4,14 @@
4
4
 
5
5
  import { Event, PushStream, TimeoutError, Trigger } from '@dxos/async';
6
6
  import {
7
- AuthenticatingInvitation,
8
7
  AUTHENTICATION_CODE_LENGTH,
8
+ AuthenticatingInvitation,
9
9
  CancellableInvitation,
10
10
  INVITATION_TIMEOUT,
11
11
  } from '@dxos/client-protocol';
12
12
  import { Context } from '@dxos/context';
13
13
  import { generatePasscode } from '@dxos/credentials';
14
- import { hasInvitationExpired, type MetadataStore } from '@dxos/echo-pipeline';
14
+ import { type MetadataStore, hasInvitationExpired } from '@dxos/echo-pipeline';
15
15
  import { invariant } from '@dxos/invariant';
16
16
  import { PublicKey } from '@dxos/keys';
17
17
  import { log } from '@dxos/log';
@@ -21,14 +21,16 @@ import {
21
21
  Invitation,
22
22
  } from '@dxos/protocols/proto/dxos/client/services';
23
23
  import { SpaceMember } from '@dxos/protocols/proto/dxos/halo/credentials';
24
+ import { trace } from '@dxos/tracing';
24
25
 
25
26
  import type { InvitationProtocol } from './invitation-protocol';
26
- import { createAdmissionKeypair, type InvitationsHandler } from './invitations-handler';
27
+ import { type InvitationsHandler, createAdmissionKeypair } from './invitations-handler';
27
28
 
28
29
  /**
29
30
  * Entry point for creating and accepting invitations, keeps track of existing invitation set and
30
31
  * emits events when the set changes.
31
32
  */
33
+ @trace.resource()
32
34
  export class InvitationsManager {
33
35
  private readonly _createInvitations = new Map<string, CancellableInvitation>();
34
36
  private readonly _acceptInvitations = new Map<string, AuthenticatingInvitation>();
@@ -48,7 +50,11 @@ export class InvitationsManager {
48
50
  private readonly _metadataStore: MetadataStore,
49
51
  ) {}
50
52
 
51
- async createInvitation(options: Partial<Invitation> & Pick<Invitation, 'kind'>): Promise<CancellableInvitation> {
53
+ @trace.span({ showInBrowserTimeline: true })
54
+ async createInvitation(
55
+ ctx: Context,
56
+ options: Partial<Invitation> & Pick<Invitation, 'kind'>,
57
+ ): Promise<CancellableInvitation> {
52
58
  if (options.invitationId) {
53
59
  const existingInvitation = this._createInvitations.get(options.invitationId);
54
60
  if (existingInvitation) {
@@ -63,7 +69,11 @@ export class InvitationsManager {
63
69
  }
64
70
  const invitation = this._createInvitation(handler, options);
65
71
 
66
- const { ctx, stream, observableInvitation } = this._createObservableInvitation(handler, invitation);
72
+ const {
73
+ ctx: invitationCtx,
74
+ stream,
75
+ observableInvitation,
76
+ } = this._createObservableInvitation(ctx, handler, invitation);
67
77
 
68
78
  this._createInvitations.set(invitation.invitationId, observableInvitation);
69
79
  this.invitationCreated.emit(invitation);
@@ -84,12 +94,12 @@ export class InvitationsManager {
84
94
  return observableInvitation;
85
95
  }
86
96
 
87
- this._invitationsHandler.handleInvitationFlow(ctx, stream, handler, observableInvitation.get());
97
+ this._invitationsHandler.handleInvitationFlow(invitationCtx, stream, handler, observableInvitation.get());
88
98
 
89
99
  return observableInvitation;
90
100
  }
91
101
 
92
- async loadPersistentInvitations(): Promise<{ invitations: Invitation[] }> {
102
+ async loadPersistentInvitations(ctx: Context): Promise<{ invitations: Invitation[] }> {
93
103
  if (this._persistentInvitationsLoaded) {
94
104
  const invitations = this.getCreatedInvitations().filter((i) => i.persistent);
95
105
  return { invitations };
@@ -101,7 +111,7 @@ export class InvitationsManager {
101
111
 
102
112
  const loadTasks = freshInvitations.map((persistentInvitation) => {
103
113
  invariant(!this._createInvitations.get(persistentInvitation.invitationId), 'invitation already exists');
104
- return this.createInvitation({ ...persistentInvitation, persistent: false });
114
+ return this.createInvitation(ctx, { ...persistentInvitation, persistent: false });
105
115
  });
106
116
  const cInvitations = await Promise.all(loadTasks);
107
117
 
@@ -115,7 +125,7 @@ export class InvitationsManager {
115
125
  }
116
126
  }
117
127
 
118
- acceptInvitation(request: AcceptInvitationRequest): AuthenticatingInvitation {
128
+ acceptInvitation(_ctx: Context, request: AcceptInvitationRequest): AuthenticatingInvitation {
119
129
  const options = request.invitation;
120
130
  const existingInvitation = this._acceptInvitations.get(options.invitationId);
121
131
  if (existingInvitation) {
@@ -123,8 +133,20 @@ export class InvitationsManager {
123
133
  }
124
134
 
125
135
  const handler = this._getHandler(options);
126
- const { ctx, invitation, stream, otpEnteredTrigger } = this._createObservableAcceptingInvitation(handler, options);
127
- this._invitationsHandler.acceptInvitation(ctx, stream, handler, options, otpEnteredTrigger, request.deviceProfile);
136
+ const {
137
+ ctx: invitationCtx,
138
+ invitation,
139
+ stream,
140
+ otpEnteredTrigger,
141
+ } = this._createObservableAcceptingInvitation(handler, options);
142
+ this._invitationsHandler.acceptInvitation(
143
+ invitationCtx,
144
+ stream,
145
+ handler,
146
+ options,
147
+ otpEnteredTrigger,
148
+ request.deviceProfile,
149
+ );
128
150
  this._acceptInvitations.set(invitation.get().invitationId, invitation);
129
151
  this.invitationAccepted.emit(invitation.get());
130
152
 
@@ -198,7 +220,7 @@ export class InvitationsManager {
198
220
  state = Invitation.State.INIT,
199
221
  timeout = INVITATION_TIMEOUT,
200
222
  swarmKey = PublicKey.random(),
201
- persistent = _options?.authMethod !== Invitation.AuthMethod.KNOWN_PUBLIC_KEY, // default no not storing keypairs
223
+ persistent = _options?.authMethod !== Invitation.AuthMethod.KNOWN_PUBLIC_KEY,
202
224
  created = new Date(),
203
225
  guestKeypair = undefined,
204
226
  role = SpaceMember.Role.ADMIN,
@@ -232,17 +254,18 @@ export class InvitationsManager {
232
254
  }
233
255
 
234
256
  private _createObservableInvitation(
257
+ ctx: Context,
235
258
  handler: InvitationProtocol,
236
259
  invitation: Invitation,
237
260
  ): { ctx: Context; stream: PushStream<Invitation>; observableInvitation: CancellableInvitation } {
238
261
  const stream = new PushStream<Invitation>();
239
- const ctx = new Context({
262
+ const invitationCtx = ctx.derive({
240
263
  onError: (err) => {
241
264
  stream.error(err);
242
- void ctx.dispose();
265
+ void invitationCtx.dispose();
243
266
  },
244
267
  });
245
- ctx.onDispose(() => {
268
+ invitationCtx.onDispose(() => {
246
269
  log('complete', { ...handler.toJSON() });
247
270
  stream.complete();
248
271
  });
@@ -251,10 +274,10 @@ export class InvitationsManager {
251
274
  subscriber: stream.observable,
252
275
  onCancel: async () => {
253
276
  stream.next({ ...invitation, state: Invitation.State.CANCELLED });
254
- await ctx.dispose();
277
+ await invitationCtx.dispose();
255
278
  },
256
279
  });
257
- return { ctx, stream, observableInvitation };
280
+ return { ctx: invitationCtx, stream, observableInvitation };
258
281
  }
259
282
 
260
283
  private _createObservableAcceptingInvitation(
@@ -4,8 +4,8 @@
4
4
 
5
5
  import { Stream } from '@dxos/codec-protobuf/stream';
6
6
  import {
7
- type AuthenticationRequest,
8
7
  type AcceptInvitationRequest,
8
+ type AuthenticationRequest,
9
9
  type Invitation,
10
10
  type InvitationsService,
11
11
  QueryInvitationsResponse,
@@ -28,9 +28,9 @@ export class InvitationsServiceImpl implements InvitationsService {
28
28
  }
29
29
 
30
30
  createInvitation(options: Invitation): Stream<Invitation> {
31
- return new Stream<Invitation>(({ next, close }) => {
31
+ return new Stream<Invitation>(({ ctx, next, close }) => {
32
32
  void this._invitationsManager
33
- .createInvitation(options)
33
+ .createInvitation(ctx, options)
34
34
  .then((invitation) => {
35
35
  trace.metrics.increment('dxos.invitation.created');
36
36
  invitation.subscribe(next, close, close);
@@ -40,8 +40,8 @@ export class InvitationsServiceImpl implements InvitationsService {
40
40
  }
41
41
 
42
42
  acceptInvitation(request: AcceptInvitationRequest): Stream<Invitation> {
43
- const invitation = this._invitationsManager.acceptInvitation(request);
44
- return new Stream<Invitation>(({ next, close }) => {
43
+ return new Stream<Invitation>(({ ctx, next, close }) => {
44
+ const invitation = this._invitationsManager.acceptInvitation(ctx, request);
45
45
  invitation.subscribe(next, close, close);
46
46
  });
47
47
  }