@dxos/echo-db 2.33.5-dev.97a81dd0 → 2.33.5-dev.bbe0c471
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 +1 -0
- package/dist/src/echo.d.ts.map +1 -1
- package/dist/src/echo.js +7 -18
- package/dist/src/echo.js.map +1 -1
- package/dist/src/halo/halo-factory.js +4 -4
- 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 +5 -5
- package/dist/src/halo/halo-party.js.map +1 -1
- package/dist/src/halo/halo.test.js +4 -3
- package/dist/src/halo/halo.test.js.map +1 -1
- package/dist/src/invitations/greeting-responder.d.ts +6 -4
- package/dist/src/invitations/greeting-responder.d.ts.map +1 -1
- package/dist/src/invitations/greeting-responder.js +3 -2
- package/dist/src/invitations/greeting-responder.js.map +1 -1
- package/dist/src/invitations/invitation-factory.d.ts +5 -2
- package/dist/src/invitations/invitation-factory.d.ts.map +1 -1
- package/dist/src/invitations/invitation-factory.js +4 -3
- package/dist/src/invitations/invitation-factory.js.map +1 -1
- package/dist/src/parties/data-party.d.ts +3 -3
- package/dist/src/parties/data-party.d.ts.map +1 -1
- package/dist/src/parties/data-party.js +5 -5
- package/dist/src/parties/data-party.js.map +1 -1
- package/dist/src/parties/data-party.test.js +13 -12
- package/dist/src/parties/data-party.test.js.map +1 -1
- package/dist/src/parties/party-factory.js +9 -9
- package/dist/src/parties/party-factory.js.map +1 -1
- package/dist/src/parties/party-manager.test.js +7 -6
- package/dist/src/parties/party-manager.test.js.map +1 -1
- package/dist/src/pipeline/metadata-store.d.ts +3 -3
- package/dist/src/pipeline/metadata-store.d.ts.map +1 -1
- package/dist/src/pipeline/metadata-store.js +5 -5
- package/dist/src/pipeline/metadata-store.js.map +1 -1
- package/dist/src/pipeline/metadata-store.test.js +8 -4
- package/dist/src/pipeline/metadata-store.test.js.map +1 -1
- package/dist/src/pipeline/party-core.d.ts +2 -2
- package/dist/src/pipeline/party-core.d.ts.map +1 -1
- package/dist/src/pipeline/party-core.js +5 -9
- package/dist/src/pipeline/party-core.js.map +1 -1
- package/dist/src/pipeline/party-core.test.js +15 -15
- package/dist/src/pipeline/party-core.test.js.map +1 -1
- package/dist/src/pipeline/party-processor.d.ts +3 -9
- package/dist/src/pipeline/party-processor.d.ts.map +1 -1
- package/dist/src/pipeline/party-processor.js +0 -8
- package/dist/src/pipeline/party-processor.js.map +1 -1
- package/dist/src/pipeline/pipeline.test.js +2 -2
- package/dist/src/pipeline/pipeline.test.js.map +1 -1
- package/dist/src/protocol/authenticator.d.ts +3 -3
- package/dist/src/protocol/authenticator.d.ts.map +1 -1
- package/dist/src/protocol/authenticator.js +2 -2
- package/dist/src/protocol/authenticator.js.map +1 -1
- package/dist/src/protocol/authenticator.test.js +1 -4
- package/dist/src/protocol/authenticator.test.js.map +1 -1
- package/dist/src/snapshots/snapshot-store.d.ts +3 -3
- package/dist/src/snapshots/snapshot-store.d.ts.map +1 -1
- package/dist/src/snapshots/snapshot-store.js +5 -5
- package/dist/src/snapshots/snapshot-store.js.map +1 -1
- package/dist/src/snapshots/snapshot-store.test.js +1 -1
- package/dist/src/snapshots/snapshot-store.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +17 -17
- package/src/echo.ts +8 -18
- package/src/halo/halo-factory.ts +4 -4
- package/src/halo/halo-party.ts +12 -7
- package/src/halo/halo.test.ts +4 -3
- package/src/invitations/greeting-responder.ts +7 -5
- package/src/invitations/invitation-factory.ts +8 -5
- package/src/parties/data-party.test.ts +14 -12
- package/src/parties/data-party.ts +8 -7
- package/src/parties/party-factory.ts +9 -9
- package/src/parties/party-manager.test.ts +9 -6
- package/src/pipeline/metadata-store.test.ts +8 -4
- package/src/pipeline/metadata-store.ts +5 -5
- package/src/pipeline/party-core.test.ts +15 -15
- package/src/pipeline/party-core.ts +6 -11
- package/src/pipeline/party-processor.ts +2 -18
- package/src/pipeline/pipeline.test.ts +2 -2
- package/src/protocol/authenticator.test.ts +1 -4
- package/src/protocol/authenticator.ts +8 -4
- package/src/snapshots/snapshot-store.test.ts +1 -1
- package/src/snapshots/snapshot-store.ts +5 -6
package/src/halo/halo-factory.ts
CHANGED
|
@@ -93,21 +93,21 @@ export class HaloFactory {
|
|
|
93
93
|
* B. Device key (the first "member" of the Identity's HALO).
|
|
94
94
|
* C. Feed key (the feed owned by the Device).
|
|
95
95
|
*/
|
|
96
|
-
await halo.
|
|
96
|
+
await halo.credentialsWriter.write(createPartyGenesisMessage(this._keyring, identityKey, feedKeyPair.publicKey, deviceKey));
|
|
97
97
|
|
|
98
98
|
/* 3. Make a special self-signed KeyAdmit message which will serve as an "IdentityGenesis" message. This
|
|
99
99
|
* message will be copied into other Parties which we create or join.
|
|
100
100
|
*/
|
|
101
|
-
await halo.
|
|
101
|
+
await halo.credentialsWriter.write(createKeyAdmitMessage(this._keyring, identityKey.publicKey, identityKey));
|
|
102
102
|
|
|
103
103
|
if (options.identityDisplayName) {
|
|
104
104
|
// 4. Write the IdentityInfo message with descriptive details (eg, display name).
|
|
105
|
-
await halo.
|
|
105
|
+
await halo.credentialsWriter.write(createIdentityInfoMessage(this._keyring, options.identityDisplayName, identityKey));
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
if (options.deviceDisplayName) {
|
|
109
109
|
// 5. Write the DeviceInfo message with descriptive details (eg, display name).
|
|
110
|
-
await halo.
|
|
110
|
+
await halo.credentialsWriter.write(createDeviceInfoMessage(this._keyring, options.deviceDisplayName, deviceKey));
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
// Create special properties item.
|
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
|
|
8
|
+
import { KeyHint } from '@dxos/credentials';
|
|
9
9
|
import { PublicKey } from '@dxos/crypto';
|
|
10
10
|
import { timed } from '@dxos/debug';
|
|
11
|
-
import { Timeframe
|
|
11
|
+
import { Timeframe } from '@dxos/echo-protocol';
|
|
12
12
|
import { ModelFactory } from '@dxos/model-factory';
|
|
13
13
|
import { NetworkManager } from '@dxos/network-manager';
|
|
14
14
|
|
|
@@ -122,6 +122,10 @@ export class HaloParty {
|
|
|
122
122
|
return this._partyCore.processor.feedKeys;
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
+
get credentialsWriter () {
|
|
126
|
+
return this._partyCore.credentialsWriter;
|
|
127
|
+
}
|
|
128
|
+
|
|
125
129
|
async getWriteFeedKey () {
|
|
126
130
|
const feed = await this._feedProvider.createOrOpenWritableFeed();
|
|
127
131
|
return feed.key;
|
|
@@ -146,6 +150,7 @@ export class HaloParty {
|
|
|
146
150
|
this._invitationManager = new InvitationFactory(
|
|
147
151
|
this._partyCore.processor,
|
|
148
152
|
this._credentialsSigner,
|
|
153
|
+
this._partyCore.credentialsWriter,
|
|
149
154
|
this._networkManager
|
|
150
155
|
);
|
|
151
156
|
|
|
@@ -165,7 +170,11 @@ export class HaloParty {
|
|
|
165
170
|
// Replication.
|
|
166
171
|
await this._protocol.start([
|
|
167
172
|
createReplicatorPlugin(this._feedProvider),
|
|
168
|
-
createAuthPlugin(createAuthenticator(
|
|
173
|
+
createAuthPlugin(createAuthenticator(
|
|
174
|
+
this._partyCore.processor,
|
|
175
|
+
this._credentialsSigner,
|
|
176
|
+
this._partyCore.credentialsWriter
|
|
177
|
+
), peerId),
|
|
169
178
|
createHaloRecoveryPlugin(this._credentialsSigner.getIdentityKey().publicKey, this._invitationManager, peerId)
|
|
170
179
|
]);
|
|
171
180
|
|
|
@@ -196,10 +205,6 @@ export class HaloParty {
|
|
|
196
205
|
return this;
|
|
197
206
|
}
|
|
198
207
|
|
|
199
|
-
writeCredentialsMessage (message: HaloMessage): Promise<WriteReceipt> {
|
|
200
|
-
return this._partyCore.writeCredentialsMessage(message);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
208
|
async createInvitation (authenticationDetails: InvitationAuthenticator, options?: InvitationOptions): Promise<InvitationDescriptor> {
|
|
204
209
|
assert(this._invitationManager, 'HALO party not open.');
|
|
205
210
|
return this._invitationManager.createInvitation(authenticationDetails, options);
|
package/src/halo/halo.test.ts
CHANGED
|
@@ -26,10 +26,11 @@ describe('HALO', () => {
|
|
|
26
26
|
.registerModel(ObjectModel);
|
|
27
27
|
|
|
28
28
|
const networkManager = new NetworkManager();
|
|
29
|
-
const
|
|
30
|
-
const
|
|
29
|
+
const storage = createStorage('', StorageType.RAM);
|
|
30
|
+
const snapshotStore = new SnapshotStore(storage.directory('snapshots'));
|
|
31
|
+
const metadataStore = new MetadataStore(storage.directory('metadata'));
|
|
31
32
|
const keyring = new Keyring();
|
|
32
|
-
const feedStore = new FeedStore(
|
|
33
|
+
const feedStore = new FeedStore(storage.directory('feed'), { valueEncoding: codec });
|
|
33
34
|
|
|
34
35
|
const feedProviderFactory = (partyKey: PublicKey) => new PartyFeedProvider(
|
|
35
36
|
metadataStore,
|
|
@@ -14,12 +14,13 @@ import {
|
|
|
14
14
|
KeyType,
|
|
15
15
|
SecretProvider,
|
|
16
16
|
SecretValidator
|
|
17
|
+
, Message as HaloMessage
|
|
17
18
|
} from '@dxos/credentials';
|
|
18
19
|
import { keyToString, randomBytes, PublicKey } from '@dxos/crypto';
|
|
19
|
-
import { SwarmKey } from '@dxos/echo-protocol';
|
|
20
|
+
import { FeedWriter, SwarmKey } from '@dxos/echo-protocol';
|
|
20
21
|
import { FullyConnectedTopology, NetworkManager } from '@dxos/network-manager';
|
|
21
22
|
|
|
22
|
-
import {
|
|
23
|
+
import { PartyStateProvider } from '../pipeline';
|
|
23
24
|
import { CredentialsSigner } from '../protocol/credentials-signer';
|
|
24
25
|
import { InvitationOptions } from './common';
|
|
25
26
|
import { greetingProtocolProvider } from './greeting-protocol-provider';
|
|
@@ -57,8 +58,9 @@ export class GreetingResponder {
|
|
|
57
58
|
|
|
58
59
|
constructor (
|
|
59
60
|
private readonly _networkManager: NetworkManager,
|
|
60
|
-
private readonly _partyProcessor:
|
|
61
|
-
private readonly _credentialsSigner: CredentialsSigner
|
|
61
|
+
private readonly _partyProcessor: PartyStateProvider,
|
|
62
|
+
private readonly _credentialsSigner: CredentialsSigner,
|
|
63
|
+
private readonly _credentialsWriter: FeedWriter<HaloMessage>
|
|
62
64
|
) {
|
|
63
65
|
this._greeter = new Greeter(
|
|
64
66
|
this._partyProcessor.partyKey,
|
|
@@ -222,7 +224,7 @@ export class GreetingResponder {
|
|
|
222
224
|
[this._credentialsSigner.getDeviceSigningKeys()]
|
|
223
225
|
);
|
|
224
226
|
|
|
225
|
-
await this.
|
|
227
|
+
await this._credentialsWriter.write(envelope);
|
|
226
228
|
|
|
227
229
|
// Wait for keys to be admitted.
|
|
228
230
|
await waitForCondition(() => admittedKeys.every(hasKey));
|
|
@@ -4,11 +4,12 @@
|
|
|
4
4
|
|
|
5
5
|
import assert from 'assert';
|
|
6
6
|
|
|
7
|
-
import { createPartyInvitationMessage } from '@dxos/credentials';
|
|
7
|
+
import { createPartyInvitationMessage, Message as HaloMessage } from '@dxos/credentials';
|
|
8
8
|
import { PublicKey } from '@dxos/crypto';
|
|
9
|
+
import { FeedWriter } from '@dxos/echo-protocol';
|
|
9
10
|
import { NetworkManager } from '@dxos/network-manager';
|
|
10
11
|
|
|
11
|
-
import {
|
|
12
|
+
import { PartyStateProvider } from '../pipeline';
|
|
12
13
|
import { CredentialsSigner } from '../protocol/credentials-signer';
|
|
13
14
|
import { defaultInvitationAuthenticator, InvitationAuthenticator, InvitationOptions } from './common';
|
|
14
15
|
import { GreetingResponder } from './greeting-responder';
|
|
@@ -19,10 +20,11 @@ import { InvitationDescriptor, InvitationDescriptorType } from './invitation-des
|
|
|
19
20
|
*/
|
|
20
21
|
export class InvitationFactory {
|
|
21
22
|
constructor (
|
|
22
|
-
private readonly _partyProcessor:
|
|
23
|
+
private readonly _partyProcessor: PartyStateProvider,
|
|
23
24
|
// This needs to be a provider in case this is a backend for the HALO party.
|
|
24
25
|
// Then the identity would be changed after this is instantiated.
|
|
25
26
|
private readonly _credentialsSigner: CredentialsSigner,
|
|
27
|
+
private readonly _credentialsWriter: FeedWriter<HaloMessage>,
|
|
26
28
|
private readonly _networkManager: NetworkManager
|
|
27
29
|
) {}
|
|
28
30
|
|
|
@@ -42,7 +44,7 @@ export class InvitationFactory {
|
|
|
42
44
|
this._credentialsSigner.getDeviceSigningKeys()
|
|
43
45
|
);
|
|
44
46
|
|
|
45
|
-
await this.
|
|
47
|
+
await this._credentialsWriter.write(invitationMessage);
|
|
46
48
|
|
|
47
49
|
return new InvitationDescriptor(
|
|
48
50
|
InvitationDescriptorType.OFFLINE,
|
|
@@ -60,7 +62,8 @@ export class InvitationFactory {
|
|
|
60
62
|
const responder = new GreetingResponder(
|
|
61
63
|
this._networkManager,
|
|
62
64
|
this._partyProcessor,
|
|
63
|
-
this._credentialsSigner
|
|
65
|
+
this._credentialsSigner,
|
|
66
|
+
this._credentialsWriter
|
|
64
67
|
);
|
|
65
68
|
|
|
66
69
|
const { secretValidator, secretProvider } = authenticationDetails;
|
|
@@ -23,9 +23,11 @@ import { DataParty } from './data-party';
|
|
|
23
23
|
|
|
24
24
|
describe('DataParty', () => {
|
|
25
25
|
const createParty = async (identity: IdentityCredentials, partyKey: PublicKey, hints: KeyHint[]) => {
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
const snapshotStore = new SnapshotStore(
|
|
26
|
+
|
|
27
|
+
const storage = createStorage('', StorageType.RAM);
|
|
28
|
+
const snapshotStore = new SnapshotStore(storage.directory('snapshots'));
|
|
29
|
+
const metadataStore = new MetadataStore(storage.directory('metadata'));
|
|
30
|
+
const feedStore = new FeedStore(storage.directory('feed'), { valueEncoding: codec });
|
|
29
31
|
const modelFactory = new ModelFactory().registerModel(ObjectModel);
|
|
30
32
|
const networkManager = new NetworkManager();
|
|
31
33
|
const partyFeedProvider = new PartyFeedProvider(metadataStore, identity.keyring, feedStore, partyKey);
|
|
@@ -60,7 +62,7 @@ describe('DataParty', () => {
|
|
|
60
62
|
await party.open();
|
|
61
63
|
|
|
62
64
|
const feed = await party.getWriteFeed();
|
|
63
|
-
await party.
|
|
65
|
+
await party.credentialsWriter.write(createPartyGenesisMessage(
|
|
64
66
|
keyring,
|
|
65
67
|
partyKey,
|
|
66
68
|
feed.key,
|
|
@@ -80,14 +82,14 @@ describe('DataParty', () => {
|
|
|
80
82
|
const party = await createParty(identity, partyKey.publicKey, []);
|
|
81
83
|
await party.open();
|
|
82
84
|
const feed = await party.getWriteFeed();
|
|
83
|
-
await party.
|
|
85
|
+
await party.credentialsWriter.write(createPartyGenesisMessage(
|
|
84
86
|
keyring,
|
|
85
87
|
partyKey,
|
|
86
88
|
feed.key,
|
|
87
89
|
partyKey
|
|
88
90
|
));
|
|
89
91
|
|
|
90
|
-
const authenticator = createAuthenticator(party.processor, identity.createCredentialsSigner());
|
|
92
|
+
const authenticator = createAuthenticator(party.processor, identity.createCredentialsSigner(), party.credentialsWriter);
|
|
91
93
|
const credentialsProvider = createCredentialsProvider(identity.createCredentialsSigner(), party.key, feed.key);
|
|
92
94
|
|
|
93
95
|
const wrappedCredentials = haloCodec.decode(credentialsProvider.get());
|
|
@@ -104,13 +106,13 @@ describe('DataParty', () => {
|
|
|
104
106
|
const party = await createParty(identityA, partyKey.publicKey, []);
|
|
105
107
|
await party.open();
|
|
106
108
|
const feed = await party.getWriteFeed();
|
|
107
|
-
await party.
|
|
109
|
+
await party.credentialsWriter.write(createPartyGenesisMessage(
|
|
108
110
|
keyring,
|
|
109
111
|
partyKey,
|
|
110
112
|
feed.key,
|
|
111
113
|
partyKey
|
|
112
114
|
));
|
|
113
|
-
const authenticator = createAuthenticator(party.processor, identityA.createCredentialsSigner());
|
|
115
|
+
const authenticator = createAuthenticator(party.processor, identityA.createCredentialsSigner(), party.credentialsWriter);
|
|
114
116
|
|
|
115
117
|
const identityB = await deriveTestDeviceCredentials(identityA);
|
|
116
118
|
const credentialsProvider = createCredentialsProvider(identityB.createCredentialsSigner(), party.key, feed.key);
|
|
@@ -129,13 +131,13 @@ describe('DataParty', () => {
|
|
|
129
131
|
const partyA = await createParty(identityA, partyKey.publicKey, []);
|
|
130
132
|
await partyA.open();
|
|
131
133
|
const feedA = await partyA.getWriteFeed();
|
|
132
|
-
await partyA.
|
|
134
|
+
await partyA.credentialsWriter.write(createPartyGenesisMessage(
|
|
133
135
|
keyring,
|
|
134
136
|
partyKey,
|
|
135
137
|
feedA.key,
|
|
136
138
|
partyKey
|
|
137
139
|
));
|
|
138
|
-
await partyA.
|
|
140
|
+
await partyA.credentialsWriter.write(createKeyAdmitMessage(
|
|
139
141
|
keyring,
|
|
140
142
|
partyKey.publicKey,
|
|
141
143
|
identityA.identityKey,
|
|
@@ -165,13 +167,13 @@ describe('DataParty', () => {
|
|
|
165
167
|
const partyA = await createParty(identityA, partyKeyA.publicKey, []);
|
|
166
168
|
await partyA.open();
|
|
167
169
|
const feedA = await partyA.getWriteFeed();
|
|
168
|
-
await partyA.
|
|
170
|
+
await partyA.credentialsWriter.write(createPartyGenesisMessage(
|
|
169
171
|
identityA.keyring,
|
|
170
172
|
partyKeyA,
|
|
171
173
|
feedA.key,
|
|
172
174
|
partyKeyA
|
|
173
175
|
));
|
|
174
|
-
await partyA.
|
|
176
|
+
await partyA.credentialsWriter.write(createKeyAdmitMessage(
|
|
175
177
|
identityA.keyring,
|
|
176
178
|
partyKeyA.publicKey,
|
|
177
179
|
identityA.identityKey,
|
|
@@ -5,10 +5,10 @@
|
|
|
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
10
|
import { timed } from '@dxos/debug';
|
|
11
|
-
import { PartyKey, PartySnapshot, Timeframe
|
|
11
|
+
import { PartyKey, PartySnapshot, Timeframe } from '@dxos/echo-protocol';
|
|
12
12
|
import { FeedDescriptor } from '@dxos/feed-store';
|
|
13
13
|
import { ModelFactory } from '@dxos/model-factory';
|
|
14
14
|
import { NetworkManager } from '@dxos/network-manager';
|
|
@@ -127,6 +127,10 @@ export class DataParty {
|
|
|
127
127
|
return this._invitationManager;
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
+
get credentialsWriter () {
|
|
131
|
+
return this._partyCore.credentialsWriter;
|
|
132
|
+
}
|
|
133
|
+
|
|
130
134
|
get title () {
|
|
131
135
|
return this._preferences?.getLastKnownTitle();
|
|
132
136
|
}
|
|
@@ -152,6 +156,7 @@ export class DataParty {
|
|
|
152
156
|
this._invitationManager = new InvitationFactory(
|
|
153
157
|
this._partyCore.processor,
|
|
154
158
|
this._credentialsSigner,
|
|
159
|
+
this._partyCore.credentialsWriter,
|
|
155
160
|
this._networkManager
|
|
156
161
|
);
|
|
157
162
|
|
|
@@ -171,7 +176,7 @@ export class DataParty {
|
|
|
171
176
|
|
|
172
177
|
await this._protocol.start([
|
|
173
178
|
createReplicatorPlugin(this._feedProvider),
|
|
174
|
-
createAuthPlugin(createAuthenticator(this._partyCore.processor, this._credentialsSigner), deviceKey.publicKey),
|
|
179
|
+
createAuthPlugin(createAuthenticator(this._partyCore.processor, this._credentialsSigner, this.credentialsWriter), deviceKey.publicKey),
|
|
175
180
|
createOfflineInvitationPlugin(this._invitationManager, deviceKey.publicKey)
|
|
176
181
|
]);
|
|
177
182
|
|
|
@@ -210,10 +215,6 @@ export class DataParty {
|
|
|
210
215
|
return this._feedProvider.getFeeds();
|
|
211
216
|
}
|
|
212
217
|
|
|
213
|
-
writeCredentialsMessage (message: HaloMessage): Promise<WriteReceipt> {
|
|
214
|
-
return this._partyCore.writeCredentialsMessage(message);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
218
|
get isActive (): boolean {
|
|
218
219
|
assert(this._preferences, 'PartyActivator required');
|
|
219
220
|
return this._preferences.isActive;
|
|
@@ -63,7 +63,7 @@ export class PartyFactory {
|
|
|
63
63
|
const writableFeed = await party.getWriteFeed();
|
|
64
64
|
|
|
65
65
|
// PartyGenesis (self-signed by Party).
|
|
66
|
-
await party.
|
|
66
|
+
await party.credentialsWriter.write(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.credentialsWriter.write(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.credentialsWriter.write(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.credentialsWriter.write(createEnvelopeMessage(
|
|
93
93
|
identity.keyring,
|
|
94
94
|
partyKey.publicKey,
|
|
95
95
|
wrapMessage(identity.identityInfo),
|
|
@@ -179,7 +179,7 @@ export class PartyFactory {
|
|
|
179
179
|
|
|
180
180
|
// Copy our signed IdentityInfo into the new Party.
|
|
181
181
|
if (identity.identityInfo) {
|
|
182
|
-
await party.
|
|
182
|
+
await party.credentialsWriter.write(createEnvelopeMessage(
|
|
183
183
|
identity.keyring,
|
|
184
184
|
partyKey,
|
|
185
185
|
wrapMessage(identity.identityInfo),
|
|
@@ -204,7 +204,7 @@ export class PartyFactory {
|
|
|
204
204
|
const writableFeed = await party.getWriteFeed();
|
|
205
205
|
|
|
206
206
|
// PartyGenesis (self-signed by Party).
|
|
207
|
-
await party.
|
|
207
|
+
await party.credentialsWriter.write(createPartyGenesisMessage(
|
|
208
208
|
identity.keyring,
|
|
209
209
|
partyKey,
|
|
210
210
|
writableFeed.key,
|
|
@@ -212,7 +212,7 @@ export class PartyFactory {
|
|
|
212
212
|
);
|
|
213
213
|
|
|
214
214
|
// KeyAdmit (IdentityGenesis in an Envelope signed by Party).
|
|
215
|
-
await party.
|
|
215
|
+
await party.credentialsWriter.write(createEnvelopeMessage(
|
|
216
216
|
identity.keyring,
|
|
217
217
|
partyKey.publicKey,
|
|
218
218
|
wrapMessage(identity.identityGenesis),
|
|
@@ -220,7 +220,7 @@ export class PartyFactory {
|
|
|
220
220
|
));
|
|
221
221
|
|
|
222
222
|
// FeedAdmit (signed by the Device KeyChain).
|
|
223
|
-
await party.
|
|
223
|
+
await party.credentialsWriter.write(createFeedAdmitMessage(
|
|
224
224
|
identity.keyring,
|
|
225
225
|
partyKey.publicKey,
|
|
226
226
|
writableFeed.key,
|
|
@@ -229,7 +229,7 @@ export class PartyFactory {
|
|
|
229
229
|
|
|
230
230
|
// IdentityInfo in an Envelope signed by the Device KeyChain.
|
|
231
231
|
if (identity.identityInfo) {
|
|
232
|
-
await party.
|
|
232
|
+
await party.credentialsWriter.write(createEnvelopeMessage(
|
|
233
233
|
identity.keyring,
|
|
234
234
|
partyKey.publicKey,
|
|
235
235
|
wrapMessage(identity.identityInfo),
|
|
@@ -55,9 +55,11 @@ const log = debug('dxos:echo:parties:party-manager:test');
|
|
|
55
55
|
*/
|
|
56
56
|
const setup = async () => {
|
|
57
57
|
const keyring = new Keyring();
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
const snapshotStore = new SnapshotStore(
|
|
58
|
+
|
|
59
|
+
const storage = createStorage('', StorageType.RAM);
|
|
60
|
+
const snapshotStore = new SnapshotStore(storage.directory('snapshots'));
|
|
61
|
+
const metadataStore = new MetadataStore(storage.directory('metadata'));
|
|
62
|
+
const feedStore = new FeedStore(storage.directory('feed'), { valueEncoding: codec });
|
|
61
63
|
const modelFactory = new ModelFactory().registerModel(ObjectModel);
|
|
62
64
|
const networkManager = new NetworkManager();
|
|
63
65
|
const feedProviderFactory = (partyKey: PublicKey) => new PartyFeedProvider(metadataStore, keyring, feedStore, partyKey);
|
|
@@ -147,12 +149,13 @@ describe('Party manager', () => {
|
|
|
147
149
|
});
|
|
148
150
|
|
|
149
151
|
test('Create from cold start', async () => {
|
|
152
|
+
|
|
150
153
|
const storage = createStorage('', StorageType.RAM);
|
|
151
|
-
const feedStore = new FeedStore(storage, { valueEncoding: codec });
|
|
154
|
+
const feedStore = new FeedStore(storage.directory('feed'), { valueEncoding: codec });
|
|
152
155
|
const keyring = new Keyring();
|
|
153
|
-
const
|
|
156
|
+
const snapshotStore = new SnapshotStore(storage.directory('snapshots'));
|
|
157
|
+
const metadataStore = new MetadataStore(storage.directory('metadata'));
|
|
154
158
|
const modelFactory = new ModelFactory().registerModel(ObjectModel);
|
|
155
|
-
const snapshotStore = new SnapshotStore(createStorage('snapshots', StorageType.RAM));
|
|
156
159
|
const networkManager = new NetworkManager();
|
|
157
160
|
const feedProviderFactory = (partyKey: PublicKey) => new PartyFeedProvider(metadataStore, keyring, feedStore, partyKey);
|
|
158
161
|
|
|
@@ -11,7 +11,8 @@ import { MetadataStore } from './metadata-store';
|
|
|
11
11
|
|
|
12
12
|
describe('MetadataStore in-memory', () => {
|
|
13
13
|
it('Creates party and adds feeds to it', async () => {
|
|
14
|
-
const
|
|
14
|
+
const storage = createStorage('', StorageType.RAM);
|
|
15
|
+
const store = new MetadataStore(storage.directory('metadata'));
|
|
15
16
|
await store.load();
|
|
16
17
|
expect(store.parties?.length).toBe(0);
|
|
17
18
|
|
|
@@ -33,7 +34,8 @@ describe('MetadataStore in-memory', () => {
|
|
|
33
34
|
});
|
|
34
35
|
|
|
35
36
|
it('Creates party when adding feed', async () => {
|
|
36
|
-
const
|
|
37
|
+
const storage = createStorage('', StorageType.RAM);
|
|
38
|
+
const store = new MetadataStore(storage.directory('metadata'));
|
|
37
39
|
await store.load();
|
|
38
40
|
|
|
39
41
|
const partyKey = PublicKey.random();
|
|
@@ -45,7 +47,8 @@ describe('MetadataStore in-memory', () => {
|
|
|
45
47
|
});
|
|
46
48
|
|
|
47
49
|
it('Doesn\'t add same feed twice', async () => {
|
|
48
|
-
const
|
|
50
|
+
const storage = createStorage('', StorageType.RAM);
|
|
51
|
+
const store = new MetadataStore(storage.directory('metadata'));
|
|
49
52
|
await store.load();
|
|
50
53
|
|
|
51
54
|
const partyKey = PublicKey.random();
|
|
@@ -60,7 +63,8 @@ describe('MetadataStore in-memory', () => {
|
|
|
60
63
|
|
|
61
64
|
// TODO(yivlad): Doesn't work for now.
|
|
62
65
|
it.skip('Resets storage', async () => {
|
|
63
|
-
const
|
|
66
|
+
const storage = createStorage('snapshots', StorageType.RAM);
|
|
67
|
+
const store = new MetadataStore(storage.directory(''));
|
|
64
68
|
|
|
65
69
|
const partyKey = PublicKey.random();
|
|
66
70
|
const feedKey = PublicKey.random();
|
|
@@ -8,7 +8,7 @@ import debug from 'debug';
|
|
|
8
8
|
import { PublicKey } from '@dxos/crypto';
|
|
9
9
|
import { failUndefined } from '@dxos/debug';
|
|
10
10
|
import { EchoMetadata, PartyMetadata, schema } from '@dxos/echo-protocol';
|
|
11
|
-
import {
|
|
11
|
+
import { Directory } from '@dxos/random-access-multi-storage';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Version for the schema of the stored data as defined in dxos.echo.metadata.EchoMetadata.
|
|
@@ -28,7 +28,7 @@ export class MetadataStore {
|
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
constructor (
|
|
31
|
-
private readonly
|
|
31
|
+
private readonly _directory: Directory
|
|
32
32
|
) {}
|
|
33
33
|
|
|
34
34
|
get version (): number {
|
|
@@ -47,7 +47,7 @@ export class MetadataStore {
|
|
|
47
47
|
* Loads metadata from persistent storage.
|
|
48
48
|
*/
|
|
49
49
|
async load (): Promise<void> {
|
|
50
|
-
const file = this.
|
|
50
|
+
const file = this._directory.createOrOpen('EchoMetadata');
|
|
51
51
|
try {
|
|
52
52
|
const { size } = await file.stat();
|
|
53
53
|
if (size === 0) {
|
|
@@ -75,7 +75,7 @@ export class MetadataStore {
|
|
|
75
75
|
updated: new Date()
|
|
76
76
|
};
|
|
77
77
|
|
|
78
|
-
const file = this.
|
|
78
|
+
const file = this._directory.createOrOpen('EchoMetadata');
|
|
79
79
|
|
|
80
80
|
try {
|
|
81
81
|
const encoded = Buffer.from(schema.getCodecForType('dxos.echo.metadata.EchoMetadata').encode(data));
|
|
@@ -90,7 +90,7 @@ export class MetadataStore {
|
|
|
90
90
|
*/
|
|
91
91
|
async clear (): Promise<void> {
|
|
92
92
|
log('Clearing all echo metadata...');
|
|
93
|
-
await this.
|
|
93
|
+
await this._directory.destroy();
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
/**
|
|
@@ -24,15 +24,15 @@ import { PartyCore } from './party-core';
|
|
|
24
24
|
describe('PartyCore', () => {
|
|
25
25
|
const setup = async () => {
|
|
26
26
|
const storage = createStorage('', StorageType.RAM);
|
|
27
|
-
const feedStore = new FeedStore(storage, { valueEncoding: codec });
|
|
27
|
+
const feedStore = new FeedStore(storage.directory('feed'), { valueEncoding: codec });
|
|
28
28
|
afterTest(async () => feedStore.close());
|
|
29
29
|
|
|
30
30
|
const keyring = new Keyring();
|
|
31
31
|
|
|
32
|
-
const metadataStore = new MetadataStore(
|
|
32
|
+
const metadataStore = new MetadataStore(storage.directory('metadata'));
|
|
33
33
|
|
|
34
34
|
const modelFactory = new ModelFactory().registerModel(ObjectModel);
|
|
35
|
-
const snapshotStore = new SnapshotStore(
|
|
35
|
+
const snapshotStore = new SnapshotStore(storage.directory('snapshots'));
|
|
36
36
|
|
|
37
37
|
const partyKey = await keyring.createKeyRecord({ type: KeyType.PARTY });
|
|
38
38
|
|
|
@@ -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.credentialsWriter.write(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.credentialsWriter.write(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.credentialsWriter.write(createFeedAdmitMessage(
|
|
124
124
|
keyring,
|
|
125
125
|
party.key,
|
|
126
126
|
feedKey.publicKey,
|
|
@@ -132,15 +132,15 @@ describe('PartyCore', () => {
|
|
|
132
132
|
|
|
133
133
|
test('opens feed from hints', async () => {
|
|
134
134
|
const storage = createStorage('', StorageType.RAM);
|
|
135
|
-
const feedStore = new FeedStore(storage, { valueEncoding: codec });
|
|
135
|
+
const feedStore = new FeedStore(storage.directory('feed'), { valueEncoding: codec });
|
|
136
136
|
afterTest(async () => feedStore.close());
|
|
137
137
|
|
|
138
138
|
const keyring = new Keyring();
|
|
139
139
|
|
|
140
|
-
const metadataStore = new MetadataStore(
|
|
140
|
+
const metadataStore = new MetadataStore(storage.directory('metadata'));
|
|
141
141
|
|
|
142
142
|
const modelFactory = new ModelFactory().registerModel(ObjectModel);
|
|
143
|
-
const snapshotStore = new SnapshotStore(
|
|
143
|
+
const snapshotStore = new SnapshotStore(storage.directory('snapshots'));
|
|
144
144
|
|
|
145
145
|
const partyKey = await keyring.createKeyRecord({ type: KeyType.PARTY });
|
|
146
146
|
|
|
@@ -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.credentialsWriter.write(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.credentialsWriter.write(createFeedAdmitMessage(
|
|
230
230
|
keyring,
|
|
231
231
|
party.key,
|
|
232
232
|
feedKey.publicKey,
|
|
@@ -253,13 +253,13 @@ describe('PartyCore', () => {
|
|
|
253
253
|
const peer1 = await setup();
|
|
254
254
|
|
|
255
255
|
const storage = createStorage('', StorageType.RAM);
|
|
256
|
-
const feedStore = new FeedStore(storage, { valueEncoding: codec });
|
|
256
|
+
const feedStore = new FeedStore(storage.directory('feed'), { valueEncoding: codec });
|
|
257
257
|
afterTest(async () => feedStore.close());
|
|
258
258
|
|
|
259
|
-
const metadataStore = new MetadataStore(
|
|
259
|
+
const metadataStore = new MetadataStore(storage.directory('metadata'));
|
|
260
260
|
|
|
261
261
|
const modelFactory = new ModelFactory().registerModel(ObjectModel);
|
|
262
|
-
const snapshotStore = new SnapshotStore(
|
|
262
|
+
const snapshotStore = new SnapshotStore(storage.directory('snapshots'));
|
|
263
263
|
|
|
264
264
|
const partyFeedProvider = new PartyFeedProvider(metadataStore, peer1.keyring, feedStore, peer1.party.key);
|
|
265
265
|
|
|
@@ -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.credentialsWriter.write(createFeedAdmitMessage(
|
|
277
277
|
peer1.keyring,
|
|
278
278
|
peer1.party.key,
|
|
279
279
|
feed2.key,
|