@dxos/echo-db 2.33.5-dev.61c93034 → 2.33.5-dev.97a81dd0
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/halo/halo-factory.d.ts.map +1 -1
- package/dist/src/halo/halo-factory.js +5 -11
- package/dist/src/halo/halo-factory.js.map +1 -1
- package/dist/src/halo/halo-party.d.ts +3 -3
- package/dist/src/halo/halo-party.d.ts.map +1 -1
- package/dist/src/halo/halo-party.js +3 -3
- package/dist/src/halo/halo-party.js.map +1 -1
- package/dist/src/invitations/greeting-responder.d.ts +2 -2
- package/dist/src/invitations/greeting-responder.d.ts.map +1 -1
- package/dist/src/invitations/greeting-responder.js.map +1 -1
- package/dist/src/invitations/invitation-factory.d.ts +2 -2
- package/dist/src/invitations/invitation-factory.d.ts.map +1 -1
- package/dist/src/invitations/invitation-factory.js.map +1 -1
- package/dist/src/parties/data-party.d.ts +7 -5
- package/dist/src/parties/data-party.d.ts.map +1 -1
- package/dist/src/parties/data-party.js +9 -8
- package/dist/src/parties/data-party.js.map +1 -1
- package/dist/src/parties/data-party.test.js +12 -12
- package/dist/src/parties/data-party.test.js.map +1 -1
- package/dist/src/parties/party-factory.d.ts +0 -6
- package/dist/src/parties/party-factory.d.ts.map +1 -1
- package/dist/src/parties/party-factory.js +17 -45
- package/dist/src/parties/party-factory.js.map +1 -1
- package/dist/src/parties/party-manager.d.ts.map +1 -1
- package/dist/src/parties/party-manager.js +2 -1
- package/dist/src/parties/party-manager.js.map +1 -1
- package/dist/src/pipeline/message-selector.d.ts +2 -2
- package/dist/src/pipeline/message-selector.d.ts.map +1 -1
- package/dist/src/pipeline/message-selector.js +6 -3
- package/dist/src/pipeline/message-selector.js.map +1 -1
- package/dist/src/pipeline/party-core.d.ts +3 -2
- package/dist/src/pipeline/party-core.d.ts.map +1 -1
- package/dist/src/pipeline/party-core.js +5 -0
- package/dist/src/pipeline/party-core.js.map +1 -1
- package/dist/src/pipeline/party-core.test.js +6 -6
- package/dist/src/pipeline/party-core.test.js.map +1 -1
- package/dist/src/pipeline/party-processor.d.ts +23 -5
- package/dist/src/pipeline/party-processor.d.ts.map +1 -1
- package/dist/src/pipeline/party-processor.js.map +1 -1
- package/dist/src/pipeline/pipeline.d.ts +2 -4
- package/dist/src/pipeline/pipeline.d.ts.map +1 -1
- package/dist/src/pipeline/pipeline.js +0 -3
- package/dist/src/pipeline/pipeline.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +17 -17
- package/src/halo/halo-factory.ts +6 -18
- package/src/halo/halo-party.ts +6 -6
- package/src/invitations/greeting-responder.ts +2 -2
- package/src/invitations/invitation-factory.ts +2 -2
- package/src/parties/data-party.test.ts +12 -12
- package/src/parties/data-party.ts +15 -12
- package/src/parties/party-factory.ts +23 -69
- package/src/parties/party-manager.ts +2 -1
- package/src/pipeline/message-selector.ts +8 -6
- package/src/pipeline/party-core.test.ts +6 -6
- package/src/pipeline/party-core.ts +7 -2
- package/src/pipeline/party-processor.ts +26 -2
- package/src/pipeline/pipeline.ts +2 -6
package/src/halo/halo-party.ts
CHANGED
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
import assert from 'assert';
|
|
6
6
|
|
|
7
7
|
import { Event, synchronized } from '@dxos/async';
|
|
8
|
-
import { KeyHint } from '@dxos/credentials';
|
|
8
|
+
import { KeyHint, Message as HaloMessage } from '@dxos/credentials';
|
|
9
9
|
import { PublicKey } from '@dxos/crypto';
|
|
10
10
|
import { timed } from '@dxos/debug';
|
|
11
|
-
import { Timeframe } from '@dxos/echo-protocol';
|
|
11
|
+
import { Timeframe, WriteReceipt } from '@dxos/echo-protocol';
|
|
12
12
|
import { ModelFactory } from '@dxos/model-factory';
|
|
13
13
|
import { NetworkManager } from '@dxos/network-manager';
|
|
14
14
|
|
|
@@ -114,10 +114,6 @@ export class HaloParty {
|
|
|
114
114
|
return this._partyCore.processor.credentialMessages.get(this._credentialsSigner.getIdentityKey().publicKey.toHex());
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
get memberKeys () {
|
|
118
|
-
return this._partyCore.processor.memberKeys;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
117
|
get credentialMessages () {
|
|
122
118
|
return this._partyCore.processor.credentialMessages;
|
|
123
119
|
}
|
|
@@ -200,6 +196,10 @@ export class HaloParty {
|
|
|
200
196
|
return this;
|
|
201
197
|
}
|
|
202
198
|
|
|
199
|
+
writeCredentialsMessage (message: HaloMessage): Promise<WriteReceipt> {
|
|
200
|
+
return this._partyCore.writeCredentialsMessage(message);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
203
|
async createInvitation (authenticationDetails: InvitationAuthenticator, options?: InvitationOptions): Promise<InvitationDescriptor> {
|
|
204
204
|
assert(this._invitationManager, 'HALO party not open.');
|
|
205
205
|
return this._invitationManager.createInvitation(authenticationDetails, options);
|
|
@@ -19,7 +19,7 @@ import { keyToString, randomBytes, PublicKey } from '@dxos/crypto';
|
|
|
19
19
|
import { SwarmKey } from '@dxos/echo-protocol';
|
|
20
20
|
import { FullyConnectedTopology, NetworkManager } from '@dxos/network-manager';
|
|
21
21
|
|
|
22
|
-
import {
|
|
22
|
+
import { CredentialWriter, PartyStateProvider } from '../pipeline';
|
|
23
23
|
import { CredentialsSigner } from '../protocol/credentials-signer';
|
|
24
24
|
import { InvitationOptions } from './common';
|
|
25
25
|
import { greetingProtocolProvider } from './greeting-protocol-provider';
|
|
@@ -57,7 +57,7 @@ export class GreetingResponder {
|
|
|
57
57
|
|
|
58
58
|
constructor (
|
|
59
59
|
private readonly _networkManager: NetworkManager,
|
|
60
|
-
private readonly _partyProcessor:
|
|
60
|
+
private readonly _partyProcessor: CredentialWriter & PartyStateProvider,
|
|
61
61
|
private readonly _credentialsSigner: CredentialsSigner
|
|
62
62
|
) {
|
|
63
63
|
this._greeter = new Greeter(
|
|
@@ -8,7 +8,7 @@ import { createPartyInvitationMessage } from '@dxos/credentials';
|
|
|
8
8
|
import { PublicKey } from '@dxos/crypto';
|
|
9
9
|
import { NetworkManager } from '@dxos/network-manager';
|
|
10
10
|
|
|
11
|
-
import {
|
|
11
|
+
import { CredentialWriter, PartyStateProvider } from '../pipeline';
|
|
12
12
|
import { CredentialsSigner } from '../protocol/credentials-signer';
|
|
13
13
|
import { defaultInvitationAuthenticator, InvitationAuthenticator, InvitationOptions } from './common';
|
|
14
14
|
import { GreetingResponder } from './greeting-responder';
|
|
@@ -19,7 +19,7 @@ import { InvitationDescriptor, InvitationDescriptorType } from './invitation-des
|
|
|
19
19
|
*/
|
|
20
20
|
export class InvitationFactory {
|
|
21
21
|
constructor (
|
|
22
|
-
private readonly _partyProcessor:
|
|
22
|
+
private readonly _partyProcessor: CredentialWriter & PartyStateProvider,
|
|
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
25
|
private readonly _credentialsSigner: CredentialsSigner,
|
|
@@ -59,8 +59,8 @@ describe('DataParty', () => {
|
|
|
59
59
|
const party = await createParty(identity, partyKey.publicKey, []);
|
|
60
60
|
await party.open();
|
|
61
61
|
|
|
62
|
-
const feed = await party.
|
|
63
|
-
await party.
|
|
62
|
+
const feed = await party.getWriteFeed();
|
|
63
|
+
await party.writeCredentialsMessage(createPartyGenesisMessage(
|
|
64
64
|
keyring,
|
|
65
65
|
partyKey,
|
|
66
66
|
feed.key,
|
|
@@ -79,8 +79,8 @@ describe('DataParty', () => {
|
|
|
79
79
|
|
|
80
80
|
const party = await createParty(identity, partyKey.publicKey, []);
|
|
81
81
|
await party.open();
|
|
82
|
-
const feed = await party.
|
|
83
|
-
await party.
|
|
82
|
+
const feed = await party.getWriteFeed();
|
|
83
|
+
await party.writeCredentialsMessage(createPartyGenesisMessage(
|
|
84
84
|
keyring,
|
|
85
85
|
partyKey,
|
|
86
86
|
feed.key,
|
|
@@ -103,8 +103,8 @@ describe('DataParty', () => {
|
|
|
103
103
|
|
|
104
104
|
const party = await createParty(identityA, partyKey.publicKey, []);
|
|
105
105
|
await party.open();
|
|
106
|
-
const feed = await party.
|
|
107
|
-
await party.
|
|
106
|
+
const feed = await party.getWriteFeed();
|
|
107
|
+
await party.writeCredentialsMessage(createPartyGenesisMessage(
|
|
108
108
|
keyring,
|
|
109
109
|
partyKey,
|
|
110
110
|
feed.key,
|
|
@@ -128,14 +128,14 @@ describe('DataParty', () => {
|
|
|
128
128
|
|
|
129
129
|
const partyA = await createParty(identityA, partyKey.publicKey, []);
|
|
130
130
|
await partyA.open();
|
|
131
|
-
const feedA = await partyA.
|
|
132
|
-
await partyA.
|
|
131
|
+
const feedA = await partyA.getWriteFeed();
|
|
132
|
+
await partyA.writeCredentialsMessage(createPartyGenesisMessage(
|
|
133
133
|
keyring,
|
|
134
134
|
partyKey,
|
|
135
135
|
feedA.key,
|
|
136
136
|
partyKey
|
|
137
137
|
));
|
|
138
|
-
await partyA.
|
|
138
|
+
await partyA.writeCredentialsMessage(createKeyAdmitMessage(
|
|
139
139
|
keyring,
|
|
140
140
|
partyKey.publicKey,
|
|
141
141
|
identityA.identityKey,
|
|
@@ -164,14 +164,14 @@ describe('DataParty', () => {
|
|
|
164
164
|
|
|
165
165
|
const partyA = await createParty(identityA, partyKeyA.publicKey, []);
|
|
166
166
|
await partyA.open();
|
|
167
|
-
const feedA = await partyA.
|
|
168
|
-
await partyA.
|
|
167
|
+
const feedA = await partyA.getWriteFeed();
|
|
168
|
+
await partyA.writeCredentialsMessage(createPartyGenesisMessage(
|
|
169
169
|
identityA.keyring,
|
|
170
170
|
partyKeyA,
|
|
171
171
|
feedA.key,
|
|
172
172
|
partyKeyA
|
|
173
173
|
));
|
|
174
|
-
await partyA.
|
|
174
|
+
await partyA.writeCredentialsMessage(createKeyAdmitMessage(
|
|
175
175
|
identityA.keyring,
|
|
176
176
|
partyKeyA.publicKey,
|
|
177
177
|
identityA.identityKey,
|
|
@@ -5,10 +5,11 @@
|
|
|
5
5
|
import assert from 'assert';
|
|
6
6
|
|
|
7
7
|
import { synchronized, Event } from '@dxos/async';
|
|
8
|
-
import { KeyHint } from '@dxos/credentials';
|
|
8
|
+
import { KeyHint, Message as HaloMessage } from '@dxos/credentials';
|
|
9
9
|
import { PublicKey } from '@dxos/crypto';
|
|
10
10
|
import { timed } from '@dxos/debug';
|
|
11
|
-
import { PartyKey, PartySnapshot, Timeframe } from '@dxos/echo-protocol';
|
|
11
|
+
import { PartyKey, PartySnapshot, Timeframe, WriteReceipt } from '@dxos/echo-protocol';
|
|
12
|
+
import { FeedDescriptor } from '@dxos/feed-store';
|
|
12
13
|
import { ModelFactory } from '@dxos/model-factory';
|
|
13
14
|
import { NetworkManager } from '@dxos/network-manager';
|
|
14
15
|
import { ObjectModel } from '@dxos/object-model';
|
|
@@ -126,16 +127,6 @@ export class DataParty {
|
|
|
126
127
|
return this._invitationManager;
|
|
127
128
|
}
|
|
128
129
|
|
|
129
|
-
// TODO(burdon): Remove?
|
|
130
|
-
get feedProvider (): PartyFeedProvider {
|
|
131
|
-
return this._feedProvider;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
get preferences (): PartyPreferences {
|
|
135
|
-
assert(this._preferences, 'Preferences not available.');
|
|
136
|
-
return this._preferences;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
130
|
get title () {
|
|
140
131
|
return this._preferences?.getLastKnownTitle();
|
|
141
132
|
}
|
|
@@ -211,6 +202,18 @@ export class DataParty {
|
|
|
211
202
|
return this;
|
|
212
203
|
}
|
|
213
204
|
|
|
205
|
+
async getWriteFeed (): Promise<FeedDescriptor> {
|
|
206
|
+
return this._feedProvider.createOrOpenWritableFeed();
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
getFeeds (): FeedDescriptor[] {
|
|
210
|
+
return this._feedProvider.getFeeds();
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
writeCredentialsMessage (message: HaloMessage): Promise<WriteReceipt> {
|
|
214
|
+
return this._partyCore.writeCredentialsMessage(message);
|
|
215
|
+
}
|
|
216
|
+
|
|
214
217
|
get isActive (): boolean {
|
|
215
218
|
assert(this._preferences, 'PartyActivator required');
|
|
216
219
|
return this._preferences.isActive;
|
|
@@ -60,10 +60,10 @@ export class PartyFactory {
|
|
|
60
60
|
// Connect the pipeline.
|
|
61
61
|
await party.open();
|
|
62
62
|
|
|
63
|
-
const writableFeed = await party.
|
|
63
|
+
const writableFeed = await party.getWriteFeed();
|
|
64
64
|
|
|
65
65
|
// PartyGenesis (self-signed by Party).
|
|
66
|
-
await party.
|
|
66
|
+
await party.writeCredentialsMessage(createPartyGenesisMessage(
|
|
67
67
|
identity.keyring,
|
|
68
68
|
partyKey,
|
|
69
69
|
writableFeed.key,
|
|
@@ -71,7 +71,7 @@ export class PartyFactory {
|
|
|
71
71
|
);
|
|
72
72
|
|
|
73
73
|
// KeyAdmit (IdentityGenesis in an Envelope signed by Party).
|
|
74
|
-
await party.
|
|
74
|
+
await party.writeCredentialsMessage(createEnvelopeMessage(
|
|
75
75
|
identity.keyring,
|
|
76
76
|
partyKey.publicKey,
|
|
77
77
|
wrapMessage(identity.identityGenesis),
|
|
@@ -80,7 +80,7 @@ export class PartyFactory {
|
|
|
80
80
|
|
|
81
81
|
// FeedAdmit (signed by the Device KeyChain).
|
|
82
82
|
// TODO(dmaretskyi): Is this really needed since a feed is already admitted by party genesis message.
|
|
83
|
-
await party.
|
|
83
|
+
await party.writeCredentialsMessage(createFeedAdmitMessage(
|
|
84
84
|
identity.keyring,
|
|
85
85
|
partyKey.publicKey,
|
|
86
86
|
writableFeed.key,
|
|
@@ -89,7 +89,7 @@ export class PartyFactory {
|
|
|
89
89
|
|
|
90
90
|
// IdentityInfo in an Envelope signed by the Device KeyChain.
|
|
91
91
|
if (identity.identityInfo) {
|
|
92
|
-
await party.
|
|
92
|
+
await party.writeCredentialsMessage(createEnvelopeMessage(
|
|
93
93
|
identity.keyring,
|
|
94
94
|
partyKey.publicKey,
|
|
95
95
|
wrapMessage(identity.identityInfo),
|
|
@@ -106,50 +106,6 @@ export class PartyFactory {
|
|
|
106
106
|
return party;
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
/**
|
|
110
|
-
* Constructs a party object and creates a local write feed for it.
|
|
111
|
-
* @param partyKey
|
|
112
|
-
* @param hints
|
|
113
|
-
*/
|
|
114
|
-
async addParty (partyKey: PartyKey, hints: KeyHint[] = []) {
|
|
115
|
-
const identity = this._identityProvider() ?? raise(new IdentityNotInitializedError());
|
|
116
|
-
|
|
117
|
-
/*
|
|
118
|
-
* TODO(telackey): We shouldn't have to add our key here, it should be in the hints, but our hint
|
|
119
|
-
* mechanism is broken by not waiting on the messages to be processed before returning.
|
|
120
|
-
*/
|
|
121
|
-
|
|
122
|
-
const feedProvider = this._feedProviderFactory(partyKey);
|
|
123
|
-
const { feed } = await feedProvider.createOrOpenWritableFeed();
|
|
124
|
-
const feedKeyPair = identity.keyring.getKey(feed.key);
|
|
125
|
-
assert(feedKeyPair, 'Keypair for writable feed not found.');
|
|
126
|
-
const party = new DataParty(
|
|
127
|
-
partyKey,
|
|
128
|
-
this._modelFactory,
|
|
129
|
-
this._snapshotStore,
|
|
130
|
-
feedProvider,
|
|
131
|
-
identity.createCredentialsSigner(),
|
|
132
|
-
identity.preferences,
|
|
133
|
-
this._networkManager,
|
|
134
|
-
hints,
|
|
135
|
-
undefined,
|
|
136
|
-
this._options
|
|
137
|
-
);
|
|
138
|
-
|
|
139
|
-
await party.open();
|
|
140
|
-
const isHalo = identity.identityKey.publicKey.equals(partyKey);
|
|
141
|
-
const signingKey = isHalo ? identity.deviceKey : identity.deviceKeyChain;
|
|
142
|
-
assert(signingKey, 'No device key or keychain.');
|
|
143
|
-
// Write the Feed genesis message.
|
|
144
|
-
await party.processor.writeHaloMessage(createFeedAdmitMessage(
|
|
145
|
-
identity.keyring,
|
|
146
|
-
partyKey,
|
|
147
|
-
feedKeyPair.publicKey,
|
|
148
|
-
[signingKey]
|
|
149
|
-
));
|
|
150
|
-
return party;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
109
|
/**
|
|
154
110
|
* Constructs a party object from an existing set of feeds.
|
|
155
111
|
* @param partyKey
|
|
@@ -190,7 +146,6 @@ export class PartyFactory {
|
|
|
190
146
|
}
|
|
191
147
|
|
|
192
148
|
async joinParty (invitationDescriptor: InvitationDescriptor, secretProvider: SecretProvider): Promise<DataParty> {
|
|
193
|
-
const haloInvitation = !!invitationDescriptor.identityKey;
|
|
194
149
|
const originalInvitation = invitationDescriptor;
|
|
195
150
|
|
|
196
151
|
const identity = this._identityProvider() ?? raise(new IdentityNotInitializedError());
|
|
@@ -218,19 +173,18 @@ export class PartyFactory {
|
|
|
218
173
|
|
|
219
174
|
await initiator.connect();
|
|
220
175
|
const { partyKey, hints } = await initiator.redeemInvitation(secretProvider);
|
|
221
|
-
const party = await this.
|
|
176
|
+
const party = await this.constructParty(partyKey, hints);
|
|
177
|
+
await party.open();
|
|
222
178
|
await initiator.destroy();
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
));
|
|
233
|
-
}
|
|
179
|
+
|
|
180
|
+
// Copy our signed IdentityInfo into the new Party.
|
|
181
|
+
if (identity.identityInfo) {
|
|
182
|
+
await party.writeCredentialsMessage(createEnvelopeMessage(
|
|
183
|
+
identity.keyring,
|
|
184
|
+
partyKey,
|
|
185
|
+
wrapMessage(identity.identityInfo),
|
|
186
|
+
[identity.deviceKeyChain]
|
|
187
|
+
));
|
|
234
188
|
}
|
|
235
189
|
|
|
236
190
|
return party;
|
|
@@ -247,10 +201,10 @@ export class PartyFactory {
|
|
|
247
201
|
// Connect the pipeline.
|
|
248
202
|
await party.open();
|
|
249
203
|
|
|
250
|
-
const writableFeed = await party.
|
|
204
|
+
const writableFeed = await party.getWriteFeed();
|
|
251
205
|
|
|
252
206
|
// PartyGenesis (self-signed by Party).
|
|
253
|
-
await party.
|
|
207
|
+
await party.writeCredentialsMessage(createPartyGenesisMessage(
|
|
254
208
|
identity.keyring,
|
|
255
209
|
partyKey,
|
|
256
210
|
writableFeed.key,
|
|
@@ -258,7 +212,7 @@ export class PartyFactory {
|
|
|
258
212
|
);
|
|
259
213
|
|
|
260
214
|
// KeyAdmit (IdentityGenesis in an Envelope signed by Party).
|
|
261
|
-
await party.
|
|
215
|
+
await party.writeCredentialsMessage(createEnvelopeMessage(
|
|
262
216
|
identity.keyring,
|
|
263
217
|
partyKey.publicKey,
|
|
264
218
|
wrapMessage(identity.identityGenesis),
|
|
@@ -266,7 +220,7 @@ export class PartyFactory {
|
|
|
266
220
|
));
|
|
267
221
|
|
|
268
222
|
// FeedAdmit (signed by the Device KeyChain).
|
|
269
|
-
await party.
|
|
223
|
+
await party.writeCredentialsMessage(createFeedAdmitMessage(
|
|
270
224
|
identity.keyring,
|
|
271
225
|
partyKey.publicKey,
|
|
272
226
|
writableFeed.key,
|
|
@@ -275,7 +229,7 @@ export class PartyFactory {
|
|
|
275
229
|
|
|
276
230
|
// IdentityInfo in an Envelope signed by the Device KeyChain.
|
|
277
231
|
if (identity.identityInfo) {
|
|
278
|
-
await party.
|
|
232
|
+
await party.writeCredentialsMessage(createEnvelopeMessage(
|
|
279
233
|
identity.keyring,
|
|
280
234
|
partyKey.publicKey,
|
|
281
235
|
wrapMessage(identity.identityInfo),
|
|
@@ -285,7 +239,7 @@ export class PartyFactory {
|
|
|
285
239
|
|
|
286
240
|
// const keyAdmitMessage = snapshot.halo?.messages?.[1];
|
|
287
241
|
// assert(keyAdmitMessage);
|
|
288
|
-
// await party.
|
|
242
|
+
// await party.writeCredentialsMessage(createEnvelopeMessage(
|
|
289
243
|
// identity.signer,
|
|
290
244
|
// partyKey.publicKey,
|
|
291
245
|
// keyAdmitMessage,
|
|
@@ -293,7 +247,7 @@ export class PartyFactory {
|
|
|
293
247
|
// ));
|
|
294
248
|
|
|
295
249
|
// for(const message of snapshot.halo?.messages?.slice(2) || []) {
|
|
296
|
-
// await party.
|
|
250
|
+
// await party.writeCredentialsMessage(message);
|
|
297
251
|
// }
|
|
298
252
|
|
|
299
253
|
// Write messages to create ECHO items.
|
|
@@ -175,7 +175,8 @@ export class PartyManager {
|
|
|
175
175
|
}
|
|
176
176
|
|
|
177
177
|
log(`Adding party partyKey=${partyKey.toHex()} hints=${hints.length}`);
|
|
178
|
-
const party = await this._partyFactory.
|
|
178
|
+
const party = await this._partyFactory.constructParty(partyKey, hints);
|
|
179
|
+
await party.open();
|
|
179
180
|
await this._metadataStore.addParty(party.key);
|
|
180
181
|
this._setParty(party);
|
|
181
182
|
return party;
|
|
@@ -10,7 +10,7 @@ import { PublicKey } from '@dxos/crypto';
|
|
|
10
10
|
import { MessageSelector } from '@dxos/echo-protocol';
|
|
11
11
|
|
|
12
12
|
import { TimeframeClock } from '../database';
|
|
13
|
-
import {
|
|
13
|
+
import { PartyStateProvider } from './party-processor';
|
|
14
14
|
|
|
15
15
|
const log = debug('dxos:echo-db:message-selector');
|
|
16
16
|
|
|
@@ -23,7 +23,7 @@ const log = debug('dxos:echo-db:message-selector');
|
|
|
23
23
|
* @param partyProcessor
|
|
24
24
|
* @param timeframeClock
|
|
25
25
|
*/
|
|
26
|
-
export const createMessageSelector = (partyProcessor:
|
|
26
|
+
export const createMessageSelector = (partyProcessor: PartyStateProvider, timeframeClock: TimeframeClock): MessageSelector => candidates => {
|
|
27
27
|
// Check ECHO message candidates first since they are less expensive than HALO cancidates.
|
|
28
28
|
for (let i = 0; i < candidates.length; i++) {
|
|
29
29
|
const { data: { echo } } = candidates[i];
|
|
@@ -51,10 +51,12 @@ export const createMessageSelector = (partyProcessor: PartyProcessor, timeframeC
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
if (partyProcessor.genesisRequired) {
|
|
54
|
-
// TODO(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
try { // TODO(dmaretskyi): Get getPartyCredentialMessageType crashes for some reason.
|
|
55
|
+
// TODO(telackey): Add check that this is for the right Party.
|
|
56
|
+
if (getPartyCredentialMessageType(halo) === PartyCredential.Type.PARTY_GENESIS) {
|
|
57
|
+
return i;
|
|
58
|
+
}
|
|
59
|
+
} catch { }
|
|
58
60
|
}
|
|
59
61
|
}
|
|
60
62
|
|
|
@@ -51,7 +51,7 @@ describe('PartyCore', () => {
|
|
|
51
51
|
afterTest(async () => party.close());
|
|
52
52
|
|
|
53
53
|
// PartyGenesis (self-signed by Party).
|
|
54
|
-
await party.
|
|
54
|
+
await party.writeCredentialsMessage(createPartyGenesisMessage(
|
|
55
55
|
keyring,
|
|
56
56
|
partyKey,
|
|
57
57
|
feed.key,
|
|
@@ -59,7 +59,7 @@ describe('PartyCore', () => {
|
|
|
59
59
|
);
|
|
60
60
|
|
|
61
61
|
// FeedAdmit (signed by the Device KeyChain).
|
|
62
|
-
await party.
|
|
62
|
+
await party.writeCredentialsMessage(createFeedAdmitMessage(
|
|
63
63
|
keyring,
|
|
64
64
|
partyKey.publicKey,
|
|
65
65
|
feed.key,
|
|
@@ -120,7 +120,7 @@ describe('PartyCore', () => {
|
|
|
120
120
|
const feedKey = await keyring.createKeyRecord({ type: KeyType.FEED });
|
|
121
121
|
|
|
122
122
|
const eventFired = feedStore.feedOpenedEvent.waitForCount(1);
|
|
123
|
-
await party.
|
|
123
|
+
await party.writeCredentialsMessage(createFeedAdmitMessage(
|
|
124
124
|
keyring,
|
|
125
125
|
party.key,
|
|
126
126
|
feedKey.publicKey,
|
|
@@ -197,7 +197,7 @@ describe('PartyCore', () => {
|
|
|
197
197
|
const fullKey = keyring.getFullKey(feedKey.publicKey);
|
|
198
198
|
const feed2 = await feedStore.openReadWriteFeed(fullKey!.publicKey, fullKey!.secretKey!);
|
|
199
199
|
|
|
200
|
-
await party.
|
|
200
|
+
await party.writeCredentialsMessage(createFeedAdmitMessage(
|
|
201
201
|
keyring,
|
|
202
202
|
party.key,
|
|
203
203
|
feed2.key,
|
|
@@ -226,7 +226,7 @@ describe('PartyCore', () => {
|
|
|
226
226
|
const feedKey = await keyring.createKeyRecord({ type: KeyType.FEED });
|
|
227
227
|
const fullKey = keyring.getFullKey(feedKey.publicKey);
|
|
228
228
|
|
|
229
|
-
await party.
|
|
229
|
+
await party.writeCredentialsMessage(createFeedAdmitMessage(
|
|
230
230
|
keyring,
|
|
231
231
|
party.key,
|
|
232
232
|
feedKey.publicKey,
|
|
@@ -273,7 +273,7 @@ describe('PartyCore', () => {
|
|
|
273
273
|
|
|
274
274
|
const feed2 = await partyFeedProvider.createOrOpenWritableFeed();
|
|
275
275
|
|
|
276
|
-
await peer1.party.
|
|
276
|
+
await peer1.party.writeCredentialsMessage(createFeedAdmitMessage(
|
|
277
277
|
peer1.keyring,
|
|
278
278
|
peer1.party.key,
|
|
279
279
|
feed2.key,
|
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
import assert from 'assert';
|
|
6
6
|
|
|
7
7
|
import { synchronized } from '@dxos/async';
|
|
8
|
-
import { KeyHint, KeyType } from '@dxos/credentials';
|
|
8
|
+
import { KeyHint, KeyType, Message as HaloMessage } from '@dxos/credentials';
|
|
9
9
|
import { PublicKey } from '@dxos/crypto';
|
|
10
10
|
import { timed } from '@dxos/debug';
|
|
11
|
-
import { createFeedWriter, DatabaseSnapshot, PartyKey, PartySnapshot, Timeframe } from '@dxos/echo-protocol';
|
|
11
|
+
import { createFeedWriter, DatabaseSnapshot, PartyKey, PartySnapshot, Timeframe, WriteReceipt } from '@dxos/echo-protocol';
|
|
12
12
|
import { ModelFactory } from '@dxos/model-factory';
|
|
13
13
|
import { SubscriptionGroup } from '@dxos/util';
|
|
14
14
|
|
|
@@ -202,6 +202,11 @@ export class PartyCore {
|
|
|
202
202
|
return this;
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
+
writeCredentialsMessage (message: HaloMessage): Promise<WriteReceipt> {
|
|
206
|
+
assert(this._partyProcessor, 'Party not open');
|
|
207
|
+
return this._partyProcessor?.writeHaloMessage(message);
|
|
208
|
+
}
|
|
209
|
+
|
|
205
210
|
/**
|
|
206
211
|
* Create a snapshot of the current state.
|
|
207
212
|
*/
|
|
@@ -12,7 +12,8 @@ import {
|
|
|
12
12
|
PartyState,
|
|
13
13
|
Message as HaloMessage,
|
|
14
14
|
IdentityEventType,
|
|
15
|
-
PartyEventType
|
|
15
|
+
PartyEventType,
|
|
16
|
+
SignedMessage
|
|
16
17
|
} from '@dxos/credentials';
|
|
17
18
|
import { PublicKey } from '@dxos/crypto';
|
|
18
19
|
import { FeedKey, FeedWriter, IHaloStream, PartyKey, HaloStateSnapshot, WriteReceipt } from '@dxos/echo-protocol';
|
|
@@ -20,10 +21,33 @@ import { jsonReplacer } from '@dxos/util';
|
|
|
20
21
|
|
|
21
22
|
const log = debug('dxos:echo-db:party-processor');
|
|
22
23
|
|
|
24
|
+
export interface CredentialWriter {
|
|
25
|
+
writeHaloMessage (message: HaloMessage): Promise<WriteReceipt>
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface CredentialProcessor {
|
|
29
|
+
processMessage (message: IHaloStream): Promise<void>
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface PartyStateProvider {
|
|
33
|
+
partyKey: PublicKey
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Whether PartyGenesis was already processed.
|
|
37
|
+
*/
|
|
38
|
+
genesisRequired: boolean
|
|
39
|
+
memberKeys: PublicKey[]
|
|
40
|
+
feedKeys: PublicKey[]
|
|
41
|
+
getFeedOwningMember (feedKey: FeedKey): PublicKey | undefined
|
|
42
|
+
isFeedAdmitted (feedKey: FeedKey): boolean
|
|
43
|
+
|
|
44
|
+
getOfflineInvitation (invitationID: Buffer): SignedMessage | undefined
|
|
45
|
+
}
|
|
46
|
+
|
|
23
47
|
/**
|
|
24
48
|
* TODO(burdon): Wrapper/Bridge between HALO APIs.
|
|
25
49
|
*/
|
|
26
|
-
export class PartyProcessor {
|
|
50
|
+
export class PartyProcessor implements CredentialWriter, CredentialProcessor, PartyStateProvider {
|
|
27
51
|
private readonly _state: PartyState;
|
|
28
52
|
|
|
29
53
|
private _outboundHaloStream: FeedWriter<HaloMessage> | undefined;
|
package/src/pipeline/pipeline.ts
CHANGED
|
@@ -17,7 +17,7 @@ import { createReadable } from '@dxos/feed-store';
|
|
|
17
17
|
import { jsonReplacer } from '@dxos/util';
|
|
18
18
|
|
|
19
19
|
import { TimeframeClock } from '../database';
|
|
20
|
-
import {
|
|
20
|
+
import { CredentialProcessor, PartyStateProvider } from './party-processor';
|
|
21
21
|
|
|
22
22
|
interface Options {
|
|
23
23
|
readLogger?: (msg: any) => void
|
|
@@ -55,17 +55,13 @@ export class Pipeline {
|
|
|
55
55
|
* @param _options
|
|
56
56
|
*/
|
|
57
57
|
constructor (
|
|
58
|
-
private readonly _partyProcessor:
|
|
58
|
+
private readonly _partyProcessor: CredentialProcessor & PartyStateProvider,
|
|
59
59
|
private readonly _feedStorIterator: FeedStoreIterator,
|
|
60
60
|
private readonly _timeframeClock: TimeframeClock,
|
|
61
61
|
private readonly _feedWriter?: FeedWriter<FeedMessage>,
|
|
62
62
|
private readonly _options: Options = {}
|
|
63
63
|
) {}
|
|
64
64
|
|
|
65
|
-
get partyKey () {
|
|
66
|
-
return this._partyProcessor.partyKey;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
65
|
get isOpen () {
|
|
70
66
|
return this._inboundEchoStream !== undefined;
|
|
71
67
|
}
|