@dxos/echo-db 2.33.1-dev.eb88db79 → 2.33.2-dev.0f8f9225

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 (217) hide show
  1. package/dist/src/echo.d.ts +8 -8
  2. package/dist/src/echo.d.ts.map +1 -1
  3. package/dist/src/echo.js +15 -16
  4. package/dist/src/echo.js.map +1 -1
  5. package/dist/src/echo.test.js +7 -13
  6. package/dist/src/echo.test.js.map +1 -1
  7. package/dist/src/halo/contact-manager.d.ts +4 -4
  8. package/dist/src/halo/contact-manager.d.ts.map +1 -1
  9. package/dist/src/halo/contact-manager.js +10 -4
  10. package/dist/src/halo/contact-manager.js.map +1 -1
  11. package/dist/src/halo/halo-factory.d.ts +14 -9
  12. package/dist/src/halo/halo-factory.d.ts.map +1 -1
  13. package/dist/src/halo/halo-factory.js +47 -14
  14. package/dist/src/halo/halo-factory.js.map +1 -1
  15. package/dist/src/halo/halo-party.d.ts +35 -7
  16. package/dist/src/halo/halo-party.d.ts.map +1 -1
  17. package/dist/src/halo/halo-party.js +97 -18
  18. package/dist/src/halo/halo-party.js.map +1 -1
  19. package/dist/src/halo/halo.d.ts +14 -12
  20. package/dist/src/halo/halo.d.ts.map +1 -1
  21. package/dist/src/halo/halo.js +31 -29
  22. package/dist/src/halo/halo.js.map +1 -1
  23. package/dist/src/halo/halo.test.d.ts +2 -0
  24. package/dist/src/halo/halo.test.d.ts.map +1 -0
  25. package/dist/src/halo/halo.test.js +162 -0
  26. package/dist/src/halo/halo.test.js.map +1 -0
  27. package/dist/src/halo/identity-manager.d.ts +10 -8
  28. package/dist/src/halo/identity-manager.d.ts.map +1 -1
  29. package/dist/src/halo/identity-manager.js +24 -20
  30. package/dist/src/halo/identity-manager.js.map +1 -1
  31. package/dist/src/halo/identity.d.ts +12 -6
  32. package/dist/src/halo/identity.d.ts.map +1 -1
  33. package/dist/src/halo/identity.js +11 -15
  34. package/dist/src/halo/identity.js.map +1 -1
  35. package/dist/src/halo/index.d.ts +1 -1
  36. package/dist/src/halo/index.d.ts.map +1 -1
  37. package/dist/src/halo/index.js +1 -1
  38. package/dist/src/halo/index.js.map +1 -1
  39. package/dist/src/halo/party-opener.js +1 -1
  40. package/dist/src/halo/party-opener.js.map +1 -1
  41. package/dist/src/halo/preferences.d.ts +9 -9
  42. package/dist/src/halo/preferences.d.ts.map +1 -1
  43. package/dist/src/halo/preferences.js +25 -15
  44. package/dist/src/halo/preferences.js.map +1 -1
  45. package/dist/src/index.d.ts +1 -1
  46. package/dist/src/index.js +1 -1
  47. package/dist/src/invitations/greeting-initiator.d.ts +14 -4
  48. package/dist/src/invitations/greeting-initiator.d.ts.map +1 -1
  49. package/dist/src/invitations/greeting-initiator.js +15 -16
  50. package/dist/src/invitations/greeting-initiator.js.map +1 -1
  51. package/dist/src/invitations/greeting-responder.d.ts +3 -3
  52. package/dist/src/invitations/greeting-responder.d.ts.map +1 -1
  53. package/dist/src/invitations/greeting-responder.js +3 -4
  54. package/dist/src/invitations/greeting-responder.js.map +1 -1
  55. package/dist/src/invitations/halo-recovery-initiator.d.ts +6 -4
  56. package/dist/src/invitations/halo-recovery-initiator.d.ts.map +1 -1
  57. package/dist/src/invitations/halo-recovery-initiator.js +15 -26
  58. package/dist/src/invitations/halo-recovery-initiator.js.map +1 -1
  59. package/dist/src/invitations/index.d.ts +1 -1
  60. package/dist/src/invitations/index.js +1 -1
  61. package/dist/src/invitations/{invitation-manager.d.ts → invitation-factory.d.ts} +5 -6
  62. package/dist/src/invitations/invitation-factory.d.ts.map +1 -0
  63. package/dist/src/invitations/{invitation-manager.js → invitation-factory.js} +9 -15
  64. package/dist/src/invitations/invitation-factory.js.map +1 -0
  65. package/dist/src/invitations/offline-invitation-claimer.d.ts +3 -3
  66. package/dist/src/invitations/offline-invitation-claimer.js +1 -1
  67. package/dist/src/parties/{party-internal.d.ts → data-party.d.ts} +13 -11
  68. package/dist/src/parties/data-party.d.ts.map +1 -0
  69. package/dist/src/parties/{party-internal.js → data-party.js} +27 -37
  70. package/dist/src/parties/data-party.js.map +1 -0
  71. package/dist/src/parties/index.d.ts +1 -2
  72. package/dist/src/parties/index.d.ts.map +1 -1
  73. package/dist/src/parties/index.js +1 -2
  74. package/dist/src/parties/index.js.map +1 -1
  75. package/dist/src/parties/party-factory.d.ts +10 -11
  76. package/dist/src/parties/party-factory.d.ts.map +1 -1
  77. package/dist/src/parties/party-factory.js +25 -16
  78. package/dist/src/parties/party-factory.js.map +1 -1
  79. package/dist/src/parties/party-manager.d.ts +9 -9
  80. package/dist/src/parties/party-manager.d.ts.map +1 -1
  81. package/dist/src/parties/party-manager.js +13 -13
  82. package/dist/src/parties/party-manager.js.map +1 -1
  83. package/dist/src/parties/party-manager.test.js +69 -68
  84. package/dist/src/parties/party-manager.test.js.map +1 -1
  85. package/dist/src/{halo → parties}/party-preferences.d.ts +3 -3
  86. package/dist/src/parties/party-preferences.d.ts.map +1 -0
  87. package/dist/src/{halo → parties}/party-preferences.js +3 -3
  88. package/dist/src/parties/party-preferences.js.map +1 -0
  89. package/dist/src/pipeline/index.d.ts +3 -1
  90. package/dist/src/pipeline/index.d.ts.map +1 -1
  91. package/dist/src/pipeline/index.js +3 -1
  92. package/dist/src/pipeline/index.js.map +1 -1
  93. package/dist/src/{metadata → pipeline}/metadata-store.d.ts +0 -0
  94. package/dist/src/{metadata → pipeline}/metadata-store.d.ts.map +1 -1
  95. package/dist/src/{metadata → pipeline}/metadata-store.js +0 -0
  96. package/dist/src/{metadata → pipeline}/metadata-store.js.map +1 -1
  97. package/dist/src/{metadata → pipeline}/metadata-store.test.d.ts +0 -0
  98. package/dist/src/pipeline/metadata-store.test.d.ts.map +1 -0
  99. package/dist/src/{metadata → pipeline}/metadata-store.test.js +0 -0
  100. package/dist/src/{metadata → pipeline}/metadata-store.test.js.map +1 -1
  101. package/dist/src/{parties → pipeline}/party-core.d.ts +0 -0
  102. package/dist/src/pipeline/party-core.d.ts.map +1 -0
  103. package/dist/src/{parties → pipeline}/party-core.js +8 -4
  104. package/dist/src/pipeline/party-core.js.map +1 -0
  105. package/dist/src/{parties → pipeline}/party-core.test.d.ts +0 -0
  106. package/dist/src/pipeline/party-core.test.d.ts.map +1 -0
  107. package/dist/src/{parties → pipeline}/party-core.test.js +3 -4
  108. package/dist/src/pipeline/party-core.test.js.map +1 -0
  109. package/dist/src/pipeline/party-feed-provider.d.ts +3 -2
  110. package/dist/src/pipeline/party-feed-provider.d.ts.map +1 -1
  111. package/dist/src/pipeline/party-feed-provider.js +40 -19
  112. package/dist/src/pipeline/party-feed-provider.js.map +1 -1
  113. package/dist/src/protocol/auth-plugin.d.ts +7 -0
  114. package/dist/src/protocol/auth-plugin.d.ts.map +1 -0
  115. package/dist/src/protocol/auth-plugin.js +16 -0
  116. package/dist/src/protocol/auth-plugin.js.map +1 -0
  117. package/dist/src/protocol/authenticator.d.ts +14 -0
  118. package/dist/src/protocol/authenticator.d.ts.map +1 -0
  119. package/dist/src/protocol/authenticator.js +31 -0
  120. package/dist/src/protocol/authenticator.js.map +1 -0
  121. package/dist/src/protocol/authenticator.test.d.ts +2 -0
  122. package/dist/src/protocol/authenticator.test.d.ts.map +1 -0
  123. package/dist/src/protocol/authenticator.test.js +45 -0
  124. package/dist/src/protocol/authenticator.test.js.map +1 -0
  125. package/dist/src/protocol/credentials-signer.d.ts +31 -0
  126. package/dist/src/protocol/credentials-signer.d.ts.map +1 -0
  127. package/dist/src/protocol/credentials-signer.js +53 -0
  128. package/dist/src/protocol/credentials-signer.js.map +1 -0
  129. package/dist/src/protocol/halo-recovery-plugin.d.ts +10 -0
  130. package/dist/src/protocol/halo-recovery-plugin.d.ts.map +1 -0
  131. package/dist/src/protocol/halo-recovery-plugin.js +18 -0
  132. package/dist/src/protocol/halo-recovery-plugin.js.map +1 -0
  133. package/dist/src/protocol/index.d.ts +7 -0
  134. package/dist/src/protocol/index.d.ts.map +1 -0
  135. package/dist/src/{metadata → protocol}/index.js +7 -2
  136. package/dist/src/protocol/index.js.map +1 -0
  137. package/dist/src/protocol/offline-invitation-plugin.d.ts +9 -0
  138. package/dist/src/protocol/offline-invitation-plugin.d.ts.map +1 -0
  139. package/dist/src/protocol/offline-invitation-plugin.js +17 -0
  140. package/dist/src/protocol/offline-invitation-plugin.js.map +1 -0
  141. package/dist/src/{pipeline → protocol}/party-protocol-factory.d.ts +7 -17
  142. package/dist/src/protocol/party-protocol-factory.d.ts.map +1 -0
  143. package/dist/src/{pipeline → protocol}/party-protocol-factory.js +7 -47
  144. package/dist/src/protocol/party-protocol-factory.js.map +1 -0
  145. package/dist/src/snapshots/snapshot-generator.d.ts +1 -1
  146. package/dist/src/snapshots/snapshot-generator.d.ts.map +1 -1
  147. package/dist/src/testing/testing-factories.js.map +1 -1
  148. package/dist/src/testing/testing.d.ts +2 -2
  149. package/dist/src/testing/testing.d.ts.map +1 -1
  150. package/dist/src/testing/testing.js +1 -7
  151. package/dist/src/testing/testing.js.map +1 -1
  152. package/dist/tsconfig.tsbuildinfo +1 -1
  153. package/package.json +20 -20
  154. package/src/echo.test.ts +8 -14
  155. package/src/echo.ts +107 -109
  156. package/src/halo/contact-manager.ts +9 -5
  157. package/src/halo/halo-factory.ts +82 -19
  158. package/src/halo/halo-party.ts +137 -21
  159. package/src/halo/halo.test.ts +198 -0
  160. package/src/halo/halo.ts +40 -38
  161. package/src/halo/identity-manager.ts +33 -28
  162. package/src/halo/identity.ts +19 -23
  163. package/src/halo/index.ts +1 -1
  164. package/src/halo/party-opener.ts +1 -1
  165. package/src/halo/preferences.ts +29 -18
  166. package/src/index.ts +1 -1
  167. package/src/invitations/greeting-initiator.ts +37 -32
  168. package/src/invitations/greeting-responder.ts +4 -5
  169. package/src/invitations/halo-recovery-initiator.ts +16 -24
  170. package/src/invitations/index.ts +1 -1
  171. package/src/invitations/{invitation-manager.ts → invitation-factory.ts} +8 -15
  172. package/src/invitations/offline-invitation-claimer.ts +3 -3
  173. package/src/parties/{party-internal.ts → data-party.ts} +30 -55
  174. package/src/parties/index.ts +1 -2
  175. package/src/parties/party-factory.ts +31 -21
  176. package/src/parties/party-manager.test.ts +99 -73
  177. package/src/parties/party-manager.ts +17 -17
  178. package/src/{halo → parties}/party-preferences.ts +3 -3
  179. package/src/pipeline/index.ts +3 -1
  180. package/src/{metadata → pipeline}/metadata-store.test.ts +0 -0
  181. package/src/{metadata → pipeline}/metadata-store.ts +0 -0
  182. package/src/{parties → pipeline}/party-core.test.ts +1 -2
  183. package/src/{parties → pipeline}/party-core.ts +12 -7
  184. package/src/pipeline/party-feed-provider.ts +32 -21
  185. package/src/protocol/auth-plugin.ts +14 -0
  186. package/src/protocol/authenticator.test.ts +66 -0
  187. package/src/protocol/authenticator.ts +56 -0
  188. package/src/protocol/credentials-signer.ts +60 -0
  189. package/src/protocol/halo-recovery-plugin.ts +20 -0
  190. package/src/protocol/index.ts +10 -0
  191. package/src/protocol/offline-invitation-plugin.ts +19 -0
  192. package/src/{pipeline → protocol}/party-protocol-factory.ts +10 -82
  193. package/src/snapshots/snapshot-generator.ts +1 -1
  194. package/src/testing/testing-factories.ts +2 -2
  195. package/src/testing/testing.ts +3 -9
  196. package/dist/src/halo/party-preferences.d.ts.map +0 -1
  197. package/dist/src/halo/party-preferences.js.map +0 -1
  198. package/dist/src/invitations/invitation-manager.d.ts.map +0 -1
  199. package/dist/src/invitations/invitation-manager.js.map +0 -1
  200. package/dist/src/metadata/index.d.ts +0 -2
  201. package/dist/src/metadata/index.d.ts.map +0 -1
  202. package/dist/src/metadata/index.js.map +0 -1
  203. package/dist/src/metadata/metadata-store.test.d.ts.map +0 -1
  204. package/dist/src/parties/authenticator.d.ts +0 -5
  205. package/dist/src/parties/authenticator.d.ts.map +0 -1
  206. package/dist/src/parties/authenticator.js +0 -27
  207. package/dist/src/parties/authenticator.js.map +0 -1
  208. package/dist/src/parties/party-core.d.ts.map +0 -1
  209. package/dist/src/parties/party-core.js.map +0 -1
  210. package/dist/src/parties/party-core.test.d.ts.map +0 -1
  211. package/dist/src/parties/party-core.test.js.map +0 -1
  212. package/dist/src/parties/party-internal.d.ts.map +0 -1
  213. package/dist/src/parties/party-internal.js.map +0 -1
  214. package/dist/src/pipeline/party-protocol-factory.d.ts.map +0 -1
  215. package/dist/src/pipeline/party-protocol-factory.js.map +0 -1
  216. package/src/metadata/index.ts +0 -5
  217. package/src/parties/authenticator.ts +0 -31
@@ -8,8 +8,8 @@ import { createPartyInvitationMessage } from '@dxos/credentials';
8
8
  import { PublicKey } from '@dxos/crypto';
9
9
  import { NetworkManager } from '@dxos/network-manager';
10
10
 
11
- import { IdentityProvider } from '../halo';
12
11
  import { PartyProcessor } from '../pipeline';
12
+ import { CredentialsSigner } from '../protocol/credentials-signer';
13
13
  import { defaultInvitationAuthenticator, InvitationAuthenticator, InvitationOptions } from './common';
14
14
  import { GreetingResponder } from './greeting-responder';
15
15
  import { InvitationDescriptor, InvitationDescriptorType } from './invitation-descriptor';
@@ -17,36 +17,29 @@ import { InvitationDescriptor, InvitationDescriptorType } from './invitation-des
17
17
  /**
18
18
  * Groups together all invitation-related functionality for a single party.
19
19
  */
20
- export class InvitationManager {
20
+ export class InvitationFactory {
21
21
  constructor (
22
22
  private readonly _partyProcessor: PartyProcessor,
23
23
  // This needs to be a provider in case this is a backend for the HALO party.
24
24
  // Then the identity would be changed after this is instantiated.
25
- private readonly _identityProvider: IdentityProvider,
25
+ private readonly _credentialsSigner: CredentialsSigner,
26
26
  private readonly _networkManager: NetworkManager
27
27
  ) {}
28
28
 
29
- private get _identity () {
30
- return this._identityProvider();
31
- }
32
-
33
29
  get isHalo () {
34
30
  // The PartyKey of the HALO is the Identity key.
35
- assert(this._identity.identityKey, 'No identity key.');
36
- return this._identity.identityKey.publicKey.equals(this._partyProcessor.partyKey);
31
+ return this._credentialsSigner.getIdentityKey().publicKey.equals(this._partyProcessor.partyKey);
37
32
  }
38
33
 
39
34
  async createOfflineInvitation (publicKey: PublicKey) {
40
35
  assert(!this.isHalo, 'Offline invitations to HALO are not allowed.');
41
- assert(this._identity.identityKey, 'Identity key is required.');
42
- assert(this._identity.deviceKeyChain, 'Device keychain is required.');
43
36
 
44
37
  const invitationMessage = createPartyInvitationMessage(
45
- this._identity.signer,
38
+ this._credentialsSigner.signer,
46
39
  this._partyProcessor.partyKey,
47
40
  publicKey,
48
- this._identity.identityKey,
49
- this._identity.deviceKeyChain
41
+ this._credentialsSigner.getIdentityKey(),
42
+ this._credentialsSigner.getDeviceSigningKeys()
50
43
  );
51
44
 
52
45
  await this._partyProcessor.writeHaloMessage(invitationMessage);
@@ -67,7 +60,7 @@ export class InvitationManager {
67
60
  const responder = new GreetingResponder(
68
61
  this._networkManager,
69
62
  this._partyProcessor,
70
- this._identity
63
+ this._credentialsSigner
71
64
  );
72
65
 
73
66
  const { secretValidator, secretProvider } = authenticationDetails;
@@ -29,7 +29,7 @@ import { Identity } from '../halo';
29
29
  import { greetingProtocolProvider } from './greeting-protocol-provider';
30
30
  import { GreetingState } from './greeting-responder';
31
31
  import { InvitationDescriptor, InvitationDescriptorType } from './invitation-descriptor';
32
- import { InvitationManager } from './invitation-manager';
32
+ import { InvitationFactory } from './invitation-factory';
33
33
 
34
34
  const log = debug('dxos:party-manager:party-invitation-claimer');
35
35
 
@@ -132,9 +132,9 @@ export class OfflineInvitationClaimer {
132
132
  /**
133
133
  * Create a function for handling PartyInvitation claims on the indicated Party. This is used by members
134
134
  * of the Party for responding to attempts to claim an Invitation which has been written to the Party.
135
- * @param {InvitationManager} invitationManager
135
+ * @param {InvitationFactory} invitationManager
136
136
  */
137
- static createOfflineInvitationClaimHandler (invitationManager: InvitationManager) {
137
+ static createOfflineInvitationClaimHandler (invitationManager: InvitationFactory) {
138
138
  const claimHandler = new PartyInvitationClaimHandler(async (invitationID: Buffer) => {
139
139
  const invitationMessage = invitationManager.getOfflineInvitation(invitationID);
140
140
  if (!invitationMessage) {
@@ -5,22 +5,21 @@
5
5
  import assert from 'assert';
6
6
 
7
7
  import { synchronized, Event } from '@dxos/async';
8
- import { KeyHint, createAuthMessage, createFeedAdmitMessage, codec } from '@dxos/credentials';
8
+ import { KeyHint } from '@dxos/credentials';
9
9
  import { PublicKey } from '@dxos/crypto';
10
- import { failUndefined, raise, timed } from '@dxos/debug';
11
- import { PartyKey, PartySnapshot, Timeframe, FeedKey } from '@dxos/echo-protocol';
10
+ import { timed } from '@dxos/debug';
11
+ import { PartyKey, PartySnapshot, Timeframe } from '@dxos/echo-protocol';
12
12
  import { ModelFactory } from '@dxos/model-factory';
13
13
  import { NetworkManager } from '@dxos/network-manager';
14
14
  import { ObjectModel } from '@dxos/object-model';
15
15
 
16
16
  import { Database, Item, ResultSet } from '../api';
17
- import { IdentityNotInitializedError } from '../errors';
18
- import { ActivationOptions, PartyPreferences, IdentityProvider } from '../halo';
19
- import { InvitationManager } from '../invitations';
20
- import { CredentialsProvider, PartyFeedProvider, PartyProtocolFactory } from '../pipeline';
17
+ import { ActivationOptions, PartyPreferences, Preferences } from '../halo';
18
+ import { InvitationFactory } from '../invitations';
19
+ import { PartyFeedProvider, PartyProtocolFactory, PartyCore, PartyOptions } from '../pipeline';
20
+ import { createAuthPlugin, createOfflineInvitationPlugin, createAuthenticator, createCredentialsProvider } from '../protocol';
21
+ import { CredentialsSigner } from '../protocol/credentials-signer';
21
22
  import { SnapshotStore } from '../snapshots';
22
- import { createAuthenticator } from './authenticator';
23
- import { PartyCore, PartyOptions } from './party-core';
24
23
  import { CONTACT_DEBOUNCE_INTERVAL } from './party-manager';
25
24
 
26
25
  export const PARTY_ITEM_TYPE = 'dxos:item/party';
@@ -34,14 +33,16 @@ export interface PartyMember {
34
33
  }
35
34
 
36
35
  /**
37
- * TODO(burdon): Comment.
36
+ * Generic parties that peers create that is capable of storing data in the database.
37
+ *
38
+ * This class handles data-storage, replication, snapshots, access-control, and invitations.
38
39
  */
39
- export class PartyInternal {
40
+ export class DataParty {
40
41
  public readonly update = new Event<void>();
41
42
 
42
43
  private readonly _partyCore: PartyCore;
43
44
  private readonly _preferences?: PartyPreferences;
44
- private _invitationManager?: InvitationManager;
45
+ private _invitationManager?: InvitationFactory;
45
46
  private _protocol?: PartyProtocolFactory;
46
47
 
47
48
  constructor (
@@ -49,28 +50,27 @@ export class PartyInternal {
49
50
  modelFactory: ModelFactory,
50
51
  snapshotStore: SnapshotStore,
51
52
  private readonly _feedProvider: PartyFeedProvider,
52
- // This needs to be a provider in case this is a backend for the HALO party.
53
- // Then the identity would be changed after this is instantiated.
54
- private readonly _identityProvider: IdentityProvider,
53
+ private readonly _credentialsSigner: CredentialsSigner,
54
+ // TODO(dmaretskyi): Pull this out to a higher level. Should preferences be part of client API instead?
55
+ private readonly _profilePreferences: Preferences | undefined,
55
56
  private readonly _networkManager: NetworkManager,
56
57
  private readonly _hints: KeyHint[] = [],
57
58
  _initialTimeframe?: Timeframe,
58
59
  _options: PartyOptions = {}
59
60
  ) {
60
- const identity = this._identityProvider();
61
-
62
61
  this._partyCore = new PartyCore(
63
62
  partyKey,
64
63
  _feedProvider,
65
64
  modelFactory,
66
65
  snapshotStore,
67
- identity.identityKey?.publicKey ?? failUndefined(),
66
+ this._credentialsSigner.getIdentityKey().publicKey,
68
67
  _initialTimeframe,
69
68
  _options
70
69
  );
71
70
 
72
- if (identity.preferences) {
73
- this._preferences = new PartyPreferences(identity.preferences, this);
71
+ // TODO(dmaretskyi): Pull this out to a higher level. Should preferences be part of client API instead?
72
+ if (this._profilePreferences) {
73
+ this._preferences = new PartyPreferences(this._profilePreferences, this);
74
74
  }
75
75
  }
76
76
 
@@ -155,36 +155,34 @@ export class PartyInternal {
155
155
  return this;
156
156
  }
157
157
 
158
- const identity = this._identityProvider();
159
- assert(identity.deviceKey, 'Missing device key.');
160
-
161
158
  await this._partyCore.open(this._hints);
162
159
 
163
- this._invitationManager = new InvitationManager(
160
+ this._invitationManager = new InvitationFactory(
164
161
  this._partyCore.processor,
165
- this._identityProvider,
162
+ this._credentialsSigner,
166
163
  this._networkManager
167
164
  );
168
165
 
169
166
  //
170
167
  // Network/swarm.
168
+ // Replication, invitations, and authentication functions.
171
169
  //
172
170
 
171
+ const deviceKey = this._credentialsSigner.getDeviceKey();
173
172
  const writeFeed = await this._partyCore.getWriteFeed();
174
-
175
173
  this._protocol = new PartyProtocolFactory(
176
174
  this._partyCore.key,
177
175
  this._networkManager,
178
176
  this._feedProvider,
179
- this._identityProvider,
180
- this._createCredentialsProvider(this._partyCore.key, writeFeed.key),
181
- this._invitationManager,
182
- createAuthenticator(this._partyCore.processor, this._identityProvider),
177
+ deviceKey.publicKey,
178
+ createCredentialsProvider(this._credentialsSigner, this._partyCore.key, writeFeed.key),
183
179
  this._partyCore.processor.getActiveFeedSet()
184
180
  );
185
181
 
186
- // Replication.
187
- await this._protocol.start();
182
+ await this._protocol.start([
183
+ createAuthPlugin(createAuthenticator(this._partyCore.processor, this._credentialsSigner), deviceKey.publicKey),
184
+ createOfflineInvitationPlugin(this._invitationManager, deviceKey.publicKey)
185
+ ]);
188
186
 
189
187
  // Issue an 'update' whenever the properties change.
190
188
  this.database.select({ type: PARTY_ITEM_TYPE }).exec().update.on(() => this.update.emit());
@@ -271,29 +269,6 @@ export class PartyInternal {
271
269
  await this._partyCore.restoreFromSnapshot(snapshot);
272
270
  }
273
271
 
274
- private _createCredentialsProvider (partyKey: PartyKey, feedKey: FeedKey): CredentialsProvider {
275
- return {
276
- get: () => {
277
- const identity = this._identityProvider();
278
- const signingKey = identity.deviceKeyChain ?? identity.deviceKey ?? raise(new IdentityNotInitializedError());
279
- return Buffer.from(codec.encode(createAuthMessage(
280
- identity.signer,
281
- partyKey,
282
- identity.identityKey ?? raise(new IdentityNotInitializedError()),
283
- signingKey,
284
- identity.keyring.getKey(feedKey),
285
- undefined,
286
- createFeedAdmitMessage(
287
- identity.signer,
288
- partyKey,
289
- feedKey,
290
- [identity.keyring.getKey(feedKey) ?? failUndefined(), signingKey]
291
- )
292
- )));
293
- }
294
- };
295
- }
296
-
297
272
  /**
298
273
  * Get all party members.
299
274
  */
@@ -2,7 +2,6 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
- export * from './party-core';
6
5
  export * from './party-factory';
7
- export * from './party-internal';
6
+ export * from './data-party';
8
7
  export * from './party-manager';
@@ -15,20 +15,21 @@ import {
15
15
  wrapMessage
16
16
  } from '@dxos/credentials';
17
17
  import { humanize, keyToString, PublicKey } from '@dxos/crypto';
18
- import { failUndefined, timed } from '@dxos/debug';
18
+ import { failUndefined, raise, timed } from '@dxos/debug';
19
19
  import { createFeedWriter, FeedMessage, PartyKey, PartySnapshot, Timeframe } from '@dxos/echo-protocol';
20
20
  import { ModelFactory } from '@dxos/model-factory';
21
21
  import { NetworkManager } from '@dxos/network-manager';
22
22
  import { ObjectModel } from '@dxos/object-model';
23
23
 
24
+ import { IdentityNotInitializedError } from '../errors';
24
25
  import { IdentityProvider } from '../halo';
25
26
  import {
27
+ createDataPartyAdmissionMessages,
26
28
  GreetingInitiator, InvitationDescriptor, InvitationDescriptorType, OfflineInvitationClaimer
27
29
  } from '../invitations';
28
- import { PartyFeedProvider } from '../pipeline';
30
+ import { PartyFeedProvider, PartyOptions } from '../pipeline';
29
31
  import { SnapshotStore } from '../snapshots';
30
- import { PartyOptions } from './party-core';
31
- import { PartyInternal, PARTY_ITEM_TYPE } from './party-internal';
32
+ import { DataParty, PARTY_ITEM_TYPE } from './data-party';
32
33
 
33
34
  const log = debug('dxos:echo-db:party-factory');
34
35
 
@@ -41,7 +42,7 @@ export class PartyFactory {
41
42
  private readonly _networkManager: NetworkManager,
42
43
  private readonly _modelFactory: ModelFactory,
43
44
  private readonly _snapshotStore: SnapshotStore,
44
- private readonly _createFeedProvider: (partyKey: PublicKey) => PartyFeedProvider,
45
+ private readonly _feedProviderFactory: (partyKey: PublicKey) => PartyFeedProvider,
45
46
  private readonly _options: PartyOptions = {}
46
47
  ) {}
47
48
 
@@ -49,8 +50,8 @@ export class PartyFactory {
49
50
  * Create a new party with a new feed for it. Writes a party genensis message to this feed.
50
51
  */
51
52
  @timed(5_000)
52
- async createParty (): Promise<PartyInternal> {
53
- const identity = this._identityProvider();
53
+ async createParty (): Promise<DataParty> {
54
+ const identity = this._identityProvider() ?? raise(new IdentityNotInitializedError());
54
55
  assert(identity.identityGenesis, 'HALO not initialized.');
55
56
  assert(identity.deviceKeyChain, 'Device KeyChain not initialized.');
56
57
  assert(!this._options.readOnly, 'PartyFactory is read-only.');
@@ -112,25 +113,26 @@ export class PartyFactory {
112
113
  * @param hints
113
114
  */
114
115
  async addParty (partyKey: PartyKey, hints: KeyHint[] = []) {
115
- const identity = this._identityProvider();
116
+ const identity = this._identityProvider() ?? raise(new IdentityNotInitializedError());
116
117
 
117
118
  /*
118
119
  * TODO(telackey): We shouldn't have to add our key here, it should be in the hints, but our hint
119
120
  * mechanism is broken by not waiting on the messages to be processed before returning.
120
121
  */
121
122
 
122
- const feedProvider = this._createFeedProvider(partyKey);
123
+ const feedProvider = this._feedProviderFactory(partyKey);
123
124
  const { feed } = await feedProvider.createOrOpenWritableFeed();
124
125
  const feedKeyPair = identity.keyring.getKey(feed.key);
125
126
  assert(feedKeyPair, 'Keypair for writable feed not found.');
126
- const party = new PartyInternal(
127
+ const party = new DataParty(
127
128
  partyKey,
128
129
  this._modelFactory,
129
130
  this._snapshotStore,
130
131
  feedProvider,
131
- this._identityProvider,
132
+ identity.createCredentialsSigner(),
133
+ identity.preferences,
132
134
  this._networkManager,
133
- [{ type: feedKeyPair.type, publicKey: feedKeyPair.publicKey }, ...hints],
135
+ hints,
134
136
  undefined,
135
137
  this._options
136
138
  );
@@ -156,18 +158,21 @@ export class PartyFactory {
156
158
  * @param hints
157
159
  */
158
160
  async constructParty (partyKey: PartyKey, hints: KeyHint[] = [], initialTimeframe?: Timeframe) {
161
+ const identity = this._identityProvider() ?? raise(new IdentityNotInitializedError());
162
+
159
163
  // TODO(marik-d): Support read-only parties if this feed doesn't exist?
160
- const feedProvider = this._createFeedProvider(partyKey);
164
+ const feedProvider = this._feedProviderFactory(partyKey);
161
165
 
162
166
  //
163
167
  // Create the party.
164
168
  //
165
- const party = new PartyInternal(
169
+ const party = new DataParty(
166
170
  partyKey,
167
171
  this._modelFactory,
168
172
  this._snapshotStore,
169
173
  feedProvider,
170
- this._identityProvider,
174
+ identity.createCredentialsSigner(),
175
+ identity.preferences,
171
176
  this._networkManager,
172
177
  hints,
173
178
  initialTimeframe,
@@ -186,11 +191,11 @@ export class PartyFactory {
186
191
  return party;
187
192
  }
188
193
 
189
- async joinParty (invitationDescriptor: InvitationDescriptor, secretProvider: SecretProvider): Promise<PartyInternal> {
194
+ async joinParty (invitationDescriptor: InvitationDescriptor, secretProvider: SecretProvider): Promise<DataParty> {
190
195
  const haloInvitation = !!invitationDescriptor.identityKey;
191
196
  const originalInvitation = invitationDescriptor;
192
197
 
193
- const identity = this._identityProvider();
198
+ const identity = this._identityProvider() ?? raise(new IdentityNotInitializedError());
194
199
  // Claim the offline invitation and convert it into an interactive invitation.
195
200
  if (InvitationDescriptorType.OFFLINE === invitationDescriptor.type) {
196
201
  const invitationClaimer = new OfflineInvitationClaimer(this._networkManager, invitationDescriptor);
@@ -204,8 +209,13 @@ export class PartyFactory {
204
209
  // TODO(burdon): Factor out.
205
210
  const initiator = new GreetingInitiator(
206
211
  this._networkManager,
207
- identity,
208
- invitationDescriptor
212
+ invitationDescriptor,
213
+ async (partyKey, nonce) => [createDataPartyAdmissionMessages(
214
+ identity.createCredentialsSigner(),
215
+ partyKey,
216
+ identity.identityGenesis ?? raise(new IdentityNotInitializedError()),
217
+ nonce
218
+ )]
209
219
  );
210
220
 
211
221
  await initiator.connect();
@@ -230,8 +240,8 @@ export class PartyFactory {
230
240
  return party;
231
241
  }
232
242
 
233
- async cloneParty (snapshot: PartySnapshot): Promise<PartyInternal> {
234
- const identity = this._identityProvider();
243
+ async cloneParty (snapshot: PartySnapshot): Promise<DataParty> {
244
+ const identity = this._identityProvider() ?? raise(new IdentityNotInitializedError());
235
245
 
236
246
  assert(!this._options.readOnly, 'PartyFactory is read-only');
237
247
  assert(identity.identityGenesis, 'IdentityGenesis must exist');