@dxos/echo-db 2.33.1 → 2.33.2-dev.18eaaced
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.
- package/dist/src/echo.d.ts +8 -8
- package/dist/src/echo.d.ts.map +1 -1
- package/dist/src/echo.js +15 -16
- package/dist/src/echo.js.map +1 -1
- package/dist/src/echo.test.js +7 -13
- package/dist/src/echo.test.js.map +1 -1
- package/dist/src/halo/contact-manager.d.ts +4 -4
- package/dist/src/halo/contact-manager.d.ts.map +1 -1
- package/dist/src/halo/contact-manager.js +10 -4
- package/dist/src/halo/contact-manager.js.map +1 -1
- package/dist/src/halo/halo-factory.d.ts +14 -9
- package/dist/src/halo/halo-factory.d.ts.map +1 -1
- package/dist/src/halo/halo-factory.js +47 -14
- package/dist/src/halo/halo-factory.js.map +1 -1
- package/dist/src/halo/halo-party.d.ts +35 -7
- package/dist/src/halo/halo-party.d.ts.map +1 -1
- package/dist/src/halo/halo-party.js +97 -18
- package/dist/src/halo/halo-party.js.map +1 -1
- package/dist/src/halo/halo.d.ts +14 -12
- package/dist/src/halo/halo.d.ts.map +1 -1
- package/dist/src/halo/halo.js +31 -29
- package/dist/src/halo/halo.js.map +1 -1
- package/dist/src/halo/halo.test.d.ts +2 -0
- package/dist/src/halo/halo.test.d.ts.map +1 -0
- package/dist/src/halo/halo.test.js +162 -0
- package/dist/src/halo/halo.test.js.map +1 -0
- package/dist/src/halo/identity-manager.d.ts +10 -8
- package/dist/src/halo/identity-manager.d.ts.map +1 -1
- package/dist/src/halo/identity-manager.js +24 -20
- package/dist/src/halo/identity-manager.js.map +1 -1
- package/dist/src/halo/identity.d.ts +12 -6
- package/dist/src/halo/identity.d.ts.map +1 -1
- package/dist/src/halo/identity.js +11 -15
- package/dist/src/halo/identity.js.map +1 -1
- package/dist/src/halo/index.d.ts +1 -1
- package/dist/src/halo/index.d.ts.map +1 -1
- package/dist/src/halo/index.js +1 -1
- package/dist/src/halo/index.js.map +1 -1
- package/dist/src/halo/party-opener.js +1 -1
- package/dist/src/halo/party-opener.js.map +1 -1
- package/dist/src/halo/preferences.d.ts +9 -9
- package/dist/src/halo/preferences.d.ts.map +1 -1
- package/dist/src/halo/preferences.js +25 -15
- package/dist/src/halo/preferences.js.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/invitations/greeting-initiator.d.ts +14 -4
- package/dist/src/invitations/greeting-initiator.d.ts.map +1 -1
- package/dist/src/invitations/greeting-initiator.js +15 -16
- package/dist/src/invitations/greeting-initiator.js.map +1 -1
- package/dist/src/invitations/greeting-responder.d.ts +3 -3
- package/dist/src/invitations/greeting-responder.d.ts.map +1 -1
- package/dist/src/invitations/greeting-responder.js +3 -4
- package/dist/src/invitations/greeting-responder.js.map +1 -1
- package/dist/src/invitations/halo-recovery-initiator.d.ts +6 -4
- package/dist/src/invitations/halo-recovery-initiator.d.ts.map +1 -1
- package/dist/src/invitations/halo-recovery-initiator.js +15 -26
- package/dist/src/invitations/halo-recovery-initiator.js.map +1 -1
- package/dist/src/invitations/index.d.ts +1 -1
- package/dist/src/invitations/index.js +1 -1
- package/dist/src/invitations/{invitation-manager.d.ts → invitation-factory.d.ts} +5 -6
- package/dist/src/invitations/invitation-factory.d.ts.map +1 -0
- package/dist/src/invitations/{invitation-manager.js → invitation-factory.js} +9 -15
- package/dist/src/invitations/invitation-factory.js.map +1 -0
- package/dist/src/invitations/offline-invitation-claimer.d.ts +3 -3
- package/dist/src/invitations/offline-invitation-claimer.js +1 -1
- package/dist/src/parties/{party-internal.d.ts → data-party.d.ts} +13 -11
- package/dist/src/parties/data-party.d.ts.map +1 -0
- package/dist/src/parties/{party-internal.js → data-party.js} +27 -37
- package/dist/src/parties/data-party.js.map +1 -0
- package/dist/src/parties/index.d.ts +1 -2
- package/dist/src/parties/index.d.ts.map +1 -1
- package/dist/src/parties/index.js +1 -2
- package/dist/src/parties/index.js.map +1 -1
- package/dist/src/parties/party-factory.d.ts +10 -11
- package/dist/src/parties/party-factory.d.ts.map +1 -1
- package/dist/src/parties/party-factory.js +25 -16
- package/dist/src/parties/party-factory.js.map +1 -1
- package/dist/src/parties/party-manager.d.ts +9 -9
- package/dist/src/parties/party-manager.d.ts.map +1 -1
- package/dist/src/parties/party-manager.js +13 -13
- package/dist/src/parties/party-manager.js.map +1 -1
- package/dist/src/parties/party-manager.test.js +69 -68
- package/dist/src/parties/party-manager.test.js.map +1 -1
- package/dist/src/{halo → parties}/party-preferences.d.ts +3 -3
- package/dist/src/parties/party-preferences.d.ts.map +1 -0
- package/dist/src/{halo → parties}/party-preferences.js +3 -3
- package/dist/src/parties/party-preferences.js.map +1 -0
- package/dist/src/pipeline/index.d.ts +3 -1
- package/dist/src/pipeline/index.d.ts.map +1 -1
- package/dist/src/pipeline/index.js +3 -1
- package/dist/src/pipeline/index.js.map +1 -1
- package/dist/src/{metadata → pipeline}/metadata-store.d.ts +0 -0
- package/dist/src/{metadata → pipeline}/metadata-store.d.ts.map +1 -1
- package/dist/src/{metadata → pipeline}/metadata-store.js +0 -0
- package/dist/src/{metadata → pipeline}/metadata-store.js.map +1 -1
- package/dist/src/{metadata → pipeline}/metadata-store.test.d.ts +0 -0
- package/dist/src/pipeline/metadata-store.test.d.ts.map +1 -0
- package/dist/src/{metadata → pipeline}/metadata-store.test.js +0 -0
- package/dist/src/{metadata → pipeline}/metadata-store.test.js.map +1 -1
- package/dist/src/{parties → pipeline}/party-core.d.ts +0 -0
- package/dist/src/pipeline/party-core.d.ts.map +1 -0
- package/dist/src/{parties → pipeline}/party-core.js +8 -4
- package/dist/src/pipeline/party-core.js.map +1 -0
- package/dist/src/{parties → pipeline}/party-core.test.d.ts +0 -0
- package/dist/src/pipeline/party-core.test.d.ts.map +1 -0
- package/dist/src/{parties → pipeline}/party-core.test.js +3 -4
- package/dist/src/pipeline/party-core.test.js.map +1 -0
- package/dist/src/pipeline/party-feed-provider.d.ts +3 -2
- package/dist/src/pipeline/party-feed-provider.d.ts.map +1 -1
- package/dist/src/pipeline/party-feed-provider.js +40 -19
- package/dist/src/pipeline/party-feed-provider.js.map +1 -1
- package/dist/src/protocol/auth-plugin.d.ts +7 -0
- package/dist/src/protocol/auth-plugin.d.ts.map +1 -0
- package/dist/src/protocol/auth-plugin.js +16 -0
- package/dist/src/protocol/auth-plugin.js.map +1 -0
- package/dist/src/protocol/authenticator.d.ts +14 -0
- package/dist/src/protocol/authenticator.d.ts.map +1 -0
- package/dist/src/protocol/authenticator.js +31 -0
- package/dist/src/protocol/authenticator.js.map +1 -0
- package/dist/src/protocol/authenticator.test.d.ts +2 -0
- package/dist/src/protocol/authenticator.test.d.ts.map +1 -0
- package/dist/src/protocol/authenticator.test.js +45 -0
- package/dist/src/protocol/authenticator.test.js.map +1 -0
- package/dist/src/protocol/credentials-signer.d.ts +31 -0
- package/dist/src/protocol/credentials-signer.d.ts.map +1 -0
- package/dist/src/protocol/credentials-signer.js +53 -0
- package/dist/src/protocol/credentials-signer.js.map +1 -0
- package/dist/src/protocol/halo-recovery-plugin.d.ts +10 -0
- package/dist/src/protocol/halo-recovery-plugin.d.ts.map +1 -0
- package/dist/src/protocol/halo-recovery-plugin.js +18 -0
- package/dist/src/protocol/halo-recovery-plugin.js.map +1 -0
- package/dist/src/protocol/index.d.ts +7 -0
- package/dist/src/protocol/index.d.ts.map +1 -0
- package/dist/src/{metadata → protocol}/index.js +7 -2
- package/dist/src/protocol/index.js.map +1 -0
- package/dist/src/protocol/offline-invitation-plugin.d.ts +9 -0
- package/dist/src/protocol/offline-invitation-plugin.d.ts.map +1 -0
- package/dist/src/protocol/offline-invitation-plugin.js +17 -0
- package/dist/src/protocol/offline-invitation-plugin.js.map +1 -0
- package/dist/src/{pipeline → protocol}/party-protocol-factory.d.ts +7 -17
- package/dist/src/protocol/party-protocol-factory.d.ts.map +1 -0
- package/dist/src/{pipeline → protocol}/party-protocol-factory.js +7 -47
- package/dist/src/protocol/party-protocol-factory.js.map +1 -0
- package/dist/src/snapshots/snapshot-generator.d.ts +1 -1
- package/dist/src/snapshots/snapshot-generator.d.ts.map +1 -1
- package/dist/src/testing/testing-factories.js.map +1 -1
- package/dist/src/testing/testing.d.ts +2 -2
- package/dist/src/testing/testing.d.ts.map +1 -1
- package/dist/src/testing/testing.js +1 -7
- package/dist/src/testing/testing.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +17 -17
- package/src/echo.test.ts +8 -14
- package/src/echo.ts +107 -109
- package/src/halo/contact-manager.ts +9 -5
- package/src/halo/halo-factory.ts +82 -19
- package/src/halo/halo-party.ts +137 -21
- package/src/halo/halo.test.ts +198 -0
- package/src/halo/halo.ts +40 -38
- package/src/halo/identity-manager.ts +33 -28
- package/src/halo/identity.ts +19 -23
- package/src/halo/index.ts +1 -1
- package/src/halo/party-opener.ts +1 -1
- package/src/halo/preferences.ts +29 -18
- package/src/index.ts +1 -1
- package/src/invitations/greeting-initiator.ts +37 -32
- package/src/invitations/greeting-responder.ts +4 -5
- package/src/invitations/halo-recovery-initiator.ts +16 -24
- package/src/invitations/index.ts +1 -1
- package/src/invitations/{invitation-manager.ts → invitation-factory.ts} +8 -15
- package/src/invitations/offline-invitation-claimer.ts +3 -3
- package/src/parties/{party-internal.ts → data-party.ts} +30 -55
- package/src/parties/index.ts +1 -2
- package/src/parties/party-factory.ts +31 -21
- package/src/parties/party-manager.test.ts +99 -73
- package/src/parties/party-manager.ts +17 -17
- package/src/{halo → parties}/party-preferences.ts +3 -3
- package/src/pipeline/index.ts +3 -1
- package/src/{metadata → pipeline}/metadata-store.test.ts +0 -0
- package/src/{metadata → pipeline}/metadata-store.ts +0 -0
- package/src/{parties → pipeline}/party-core.test.ts +1 -2
- package/src/{parties → pipeline}/party-core.ts +12 -7
- package/src/pipeline/party-feed-provider.ts +32 -21
- package/src/protocol/auth-plugin.ts +14 -0
- package/src/protocol/authenticator.test.ts +66 -0
- package/src/protocol/authenticator.ts +56 -0
- package/src/protocol/credentials-signer.ts +60 -0
- package/src/protocol/halo-recovery-plugin.ts +20 -0
- package/src/protocol/index.ts +10 -0
- package/src/protocol/offline-invitation-plugin.ts +19 -0
- package/src/{pipeline → protocol}/party-protocol-factory.ts +10 -82
- package/src/snapshots/snapshot-generator.ts +1 -1
- package/src/testing/testing-factories.ts +2 -2
- package/src/testing/testing.ts +3 -9
- package/dist/src/halo/party-preferences.d.ts.map +0 -1
- package/dist/src/halo/party-preferences.js.map +0 -1
- package/dist/src/invitations/invitation-manager.d.ts.map +0 -1
- package/dist/src/invitations/invitation-manager.js.map +0 -1
- package/dist/src/metadata/index.d.ts +0 -2
- package/dist/src/metadata/index.d.ts.map +0 -1
- package/dist/src/metadata/index.js.map +0 -1
- package/dist/src/metadata/metadata-store.test.d.ts.map +0 -1
- package/dist/src/parties/authenticator.d.ts +0 -5
- package/dist/src/parties/authenticator.d.ts.map +0 -1
- package/dist/src/parties/authenticator.js +0 -27
- package/dist/src/parties/authenticator.js.map +0 -1
- package/dist/src/parties/party-core.d.ts.map +0 -1
- package/dist/src/parties/party-core.js.map +0 -1
- package/dist/src/parties/party-core.test.d.ts.map +0 -1
- package/dist/src/parties/party-core.test.js.map +0 -1
- package/dist/src/parties/party-internal.d.ts.map +0 -1
- package/dist/src/parties/party-internal.js.map +0 -1
- package/dist/src/pipeline/party-protocol-factory.d.ts.map +0 -1
- package/dist/src/pipeline/party-protocol-factory.js.map +0 -1
- package/src/metadata/index.ts +0 -5
- 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
|
|
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
|
|
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
|
-
|
|
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.
|
|
38
|
+
this._credentialsSigner.signer,
|
|
46
39
|
this._partyProcessor.partyKey,
|
|
47
40
|
publicKey,
|
|
48
|
-
this.
|
|
49
|
-
this.
|
|
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.
|
|
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 {
|
|
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 {
|
|
135
|
+
* @param {InvitationFactory} invitationManager
|
|
136
136
|
*/
|
|
137
|
-
static createOfflineInvitationClaimHandler (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
|
|
8
|
+
import { KeyHint } from '@dxos/credentials';
|
|
9
9
|
import { PublicKey } from '@dxos/crypto';
|
|
10
|
-
import {
|
|
11
|
-
import { PartyKey, PartySnapshot, Timeframe
|
|
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 {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
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
|
-
*
|
|
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
|
|
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?:
|
|
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
|
-
|
|
53
|
-
//
|
|
54
|
-
private readonly
|
|
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
|
-
|
|
66
|
+
this._credentialsSigner.getIdentityKey().publicKey,
|
|
68
67
|
_initialTimeframe,
|
|
69
68
|
_options
|
|
70
69
|
);
|
|
71
70
|
|
|
72
|
-
|
|
73
|
-
|
|
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
|
|
160
|
+
this._invitationManager = new InvitationFactory(
|
|
164
161
|
this._partyCore.processor,
|
|
165
|
-
this.
|
|
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
|
-
|
|
180
|
-
this.
|
|
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
|
-
|
|
187
|
-
|
|
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
|
*/
|
package/src/parties/index.ts
CHANGED
|
@@ -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 {
|
|
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
|
|
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<
|
|
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.
|
|
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
|
|
127
|
+
const party = new DataParty(
|
|
127
128
|
partyKey,
|
|
128
129
|
this._modelFactory,
|
|
129
130
|
this._snapshotStore,
|
|
130
131
|
feedProvider,
|
|
131
|
-
|
|
132
|
+
identity.createCredentialsSigner(),
|
|
133
|
+
identity.preferences,
|
|
132
134
|
this._networkManager,
|
|
133
|
-
|
|
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.
|
|
164
|
+
const feedProvider = this._feedProviderFactory(partyKey);
|
|
161
165
|
|
|
162
166
|
//
|
|
163
167
|
// Create the party.
|
|
164
168
|
//
|
|
165
|
-
const party = new
|
|
169
|
+
const party = new DataParty(
|
|
166
170
|
partyKey,
|
|
167
171
|
this._modelFactory,
|
|
168
172
|
this._snapshotStore,
|
|
169
173
|
feedProvider,
|
|
170
|
-
|
|
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<
|
|
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
|
-
|
|
208
|
-
|
|
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<
|
|
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');
|