@dxos/echo-db 2.33.3-dev.5c4af82a → 2.33.3
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/api/schema.d.ts.map +1 -1
- package/dist/src/api/schema.js +2 -4
- package/dist/src/api/schema.js.map +1 -1
- package/dist/src/echo.js +2 -2
- package/dist/src/echo.js.map +1 -1
- package/dist/src/halo/halo-party.d.ts.map +1 -1
- package/dist/src/halo/halo-party.js +1 -1
- package/dist/src/halo/halo-party.js.map +1 -1
- package/dist/src/halo/identity.d.ts +5 -4
- package/dist/src/halo/identity.d.ts.map +1 -1
- package/dist/src/halo/identity.js +9 -9
- package/dist/src/halo/identity.js.map +1 -1
- package/dist/src/invitations/offline-invitation-claimer.d.ts +2 -2
- package/dist/src/invitations/offline-invitation-claimer.d.ts.map +1 -1
- package/dist/src/invitations/offline-invitation-claimer.js +2 -2
- package/dist/src/invitations/offline-invitation-claimer.js.map +1 -1
- package/dist/src/parties/data-party.d.ts.map +1 -1
- package/dist/src/parties/data-party.js +1 -1
- package/dist/src/parties/data-party.js.map +1 -1
- package/dist/src/parties/data-party.test.d.ts +2 -0
- package/dist/src/parties/data-party.test.d.ts.map +1 -0
- package/dist/src/parties/data-party.test.js +129 -0
- package/dist/src/parties/data-party.test.js.map +1 -0
- package/dist/src/parties/party-factory.d.ts +2 -2
- package/dist/src/parties/party-factory.d.ts.map +1 -1
- package/dist/src/parties/party-factory.js +11 -10
- package/dist/src/parties/party-factory.js.map +1 -1
- package/dist/src/parties/party-manager.d.ts +2 -2
- package/dist/src/parties/party-manager.d.ts.map +1 -1
- package/dist/src/parties/party-manager.js.map +1 -1
- package/dist/src/parties/party-manager.test.js +7 -22
- package/dist/src/parties/party-manager.test.js.map +1 -1
- package/dist/src/pipeline/metadata-store.d.ts.map +1 -1
- package/dist/src/pipeline/metadata-store.js +5 -6
- package/dist/src/pipeline/metadata-store.js.map +1 -1
- package/dist/src/pipeline/party-core.test.js +1 -1
- package/dist/src/pipeline/party-core.test.js.map +1 -1
- package/dist/src/pipeline/party-processor.d.ts +0 -5
- package/dist/src/pipeline/party-processor.d.ts.map +1 -1
- package/dist/src/pipeline/party-processor.js +0 -7
- package/dist/src/pipeline/party-processor.js.map +1 -1
- package/dist/src/protocol/identity-credentials.d.ts +22 -0
- package/dist/src/protocol/identity-credentials.d.ts.map +1 -0
- package/dist/src/protocol/identity-credentials.js +50 -0
- package/dist/src/protocol/identity-credentials.js.map +1 -0
- package/dist/src/protocol/party-protocol-factory.d.ts +3 -4
- package/dist/src/protocol/party-protocol-factory.d.ts.map +1 -1
- package/dist/src/protocol/party-protocol-factory.js +12 -15
- package/dist/src/protocol/party-protocol-factory.js.map +1 -1
- package/dist/src/snapshots/snapshot-store.d.ts.map +1 -1
- package/dist/src/snapshots/snapshot-store.js +5 -6
- package/dist/src/snapshots/snapshot-store.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +20 -20
- package/src/api/schema.ts +2 -4
- package/src/echo.ts +1 -1
- package/src/halo/halo-party.ts +1 -2
- package/src/halo/identity.ts +14 -13
- package/src/invitations/offline-invitation-claimer.ts +5 -5
- package/src/parties/data-party.test.ts +212 -0
- package/src/parties/data-party.ts +1 -2
- package/src/parties/party-factory.ts +13 -12
- package/src/parties/party-manager.test.ts +8 -42
- package/src/parties/party-manager.ts +2 -2
- package/src/pipeline/metadata-store.ts +5 -6
- package/src/pipeline/party-core.test.ts +2 -4
- package/src/pipeline/party-processor.ts +0 -13
- package/src/protocol/identity-credentials.ts +78 -0
- package/src/protocol/party-protocol-factory.ts +13 -17
- package/src/snapshots/snapshot-store.ts +5 -6
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2022 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { createIdentityInfoMessage, createKeyAdmitMessage, createPartyGenesisMessage, KeyChain, KeyRecord, Keyring, KeyType, SignedMessage } from '@dxos/credentials';
|
|
6
|
+
|
|
7
|
+
import { ContactManager, Preferences } from '../halo';
|
|
8
|
+
import { CredentialsSigner } from './credentials-signer';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Provides access to identity credentials without revealing the underlying mechanism (HALO party).
|
|
12
|
+
*/
|
|
13
|
+
export interface IdentityCredentials {
|
|
14
|
+
keyring: Keyring
|
|
15
|
+
identityKey: KeyRecord
|
|
16
|
+
deviceKey: KeyRecord
|
|
17
|
+
deviceKeyChain: KeyChain
|
|
18
|
+
identityGenesis: SignedMessage
|
|
19
|
+
identityInfo: SignedMessage | undefined
|
|
20
|
+
displayName: string | undefined
|
|
21
|
+
createCredentialsSigner(): CredentialsSigner
|
|
22
|
+
preferences: Preferences | undefined
|
|
23
|
+
contacts: ContactManager | undefined
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type IdentityCredentialsProvider = () => IdentityCredentials | undefined
|
|
27
|
+
|
|
28
|
+
export async function createTestIdentityCredentials (keyring: Keyring): Promise<IdentityCredentials> {
|
|
29
|
+
const identityKey = await keyring.createKeyRecord({ type: KeyType.IDENTITY });
|
|
30
|
+
const deviceKey = await keyring.createKeyRecord({ type: KeyType.DEVICE });
|
|
31
|
+
const feedKey = await keyring.createKeyRecord({ type: KeyType.FEED });
|
|
32
|
+
|
|
33
|
+
const partyGenesis = createPartyGenesisMessage(keyring, identityKey, feedKey.publicKey, deviceKey);
|
|
34
|
+
const keyAdmit = createKeyAdmitMessage(keyring, identityKey.publicKey, identityKey);
|
|
35
|
+
|
|
36
|
+
const messageMap = new Map();
|
|
37
|
+
messageMap.set(identityKey.publicKey.toHex(), keyAdmit);
|
|
38
|
+
messageMap.set(deviceKey.publicKey.toHex(), partyGenesis);
|
|
39
|
+
const deviceKeyChain = Keyring.buildKeyChain(deviceKey.publicKey, messageMap, [feedKey.publicKey]);
|
|
40
|
+
|
|
41
|
+
const displayName = identityKey.publicKey.humanize();
|
|
42
|
+
const identityInfo = createIdentityInfoMessage(keyring, displayName, identityKey);
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
keyring,
|
|
46
|
+
identityKey,
|
|
47
|
+
deviceKey,
|
|
48
|
+
deviceKeyChain,
|
|
49
|
+
identityGenesis: keyAdmit.payload as SignedMessage,
|
|
50
|
+
identityInfo: identityInfo.payload as SignedMessage,
|
|
51
|
+
displayName,
|
|
52
|
+
createCredentialsSigner: () => new CredentialsSigner(keyring, identityKey, deviceKey, deviceKeyChain),
|
|
53
|
+
preferences: undefined,
|
|
54
|
+
contacts: undefined
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export async function deriveTestDeviceCredentials (identity: IdentityCredentials): Promise<IdentityCredentials> {
|
|
59
|
+
const deviceKey = await identity.keyring.createKeyRecord({ type: KeyType.DEVICE });
|
|
60
|
+
const keyAdmit = createKeyAdmitMessage(identity.keyring, identity.identityKey.publicKey, deviceKey, [identity.identityKey]);
|
|
61
|
+
|
|
62
|
+
const messageMap = new Map();
|
|
63
|
+
messageMap.set(identity.identityKey.publicKey.toHex(), identity.identityGenesis);
|
|
64
|
+
messageMap.set(deviceKey.publicKey.toHex(), keyAdmit);
|
|
65
|
+
const deviceKeyChain = Keyring.buildKeyChain(deviceKey.publicKey, messageMap, []);
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
...identity,
|
|
69
|
+
deviceKey,
|
|
70
|
+
deviceKeyChain,
|
|
71
|
+
createCredentialsSigner: () => new CredentialsSigner(
|
|
72
|
+
identity.keyring,
|
|
73
|
+
identity.identityKey,
|
|
74
|
+
deviceKey,
|
|
75
|
+
deviceKeyChain
|
|
76
|
+
)
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -6,7 +6,7 @@ import debug from 'debug';
|
|
|
6
6
|
|
|
7
7
|
import { synchronized } from '@dxos/async';
|
|
8
8
|
import { discoveryKey, keyToString, PublicKey } from '@dxos/crypto';
|
|
9
|
-
import { FeedKey,
|
|
9
|
+
import { FeedKey, PartyKey } from '@dxos/echo-protocol';
|
|
10
10
|
import type { HypercoreFeed } from '@dxos/feed-store';
|
|
11
11
|
import { Protocol } from '@dxos/mesh-protocol';
|
|
12
12
|
import { MMSTTopology, NetworkManager, Plugin } from '@dxos/network-manager';
|
|
@@ -32,12 +32,11 @@ export class PartyProtocolFactory {
|
|
|
32
32
|
private readonly _networkManager: NetworkManager,
|
|
33
33
|
private readonly _feedProvider: PartyFeedProvider,
|
|
34
34
|
private readonly _peerId: PublicKey,
|
|
35
|
-
private readonly _credentials: CredentialsProvider
|
|
36
|
-
activeFeeds: FeedSetProvider
|
|
35
|
+
private readonly _credentials: CredentialsProvider
|
|
37
36
|
) {
|
|
38
37
|
// Replication.
|
|
39
38
|
this._replicatorProtocolPluginFactory =
|
|
40
|
-
new ReplicatorProtocolPluginFactory(this._feedProvider
|
|
39
|
+
new ReplicatorProtocolPluginFactory(this._feedProvider);
|
|
41
40
|
}
|
|
42
41
|
|
|
43
42
|
async start (plugins: Plugin[]) {
|
|
@@ -125,34 +124,31 @@ export class PartyProtocolFactory {
|
|
|
125
124
|
*/
|
|
126
125
|
export class ReplicatorProtocolPluginFactory {
|
|
127
126
|
constructor (
|
|
128
|
-
private readonly _feedProvider: PartyFeedProvider
|
|
129
|
-
private readonly _activeFeeds: FeedSetProvider
|
|
127
|
+
private readonly _feedProvider: PartyFeedProvider
|
|
130
128
|
) {}
|
|
131
129
|
|
|
132
130
|
createPlugins () {
|
|
133
131
|
return [
|
|
134
132
|
new Replicator({
|
|
135
133
|
load: async () => {
|
|
136
|
-
const
|
|
137
|
-
log(`Loading feeds: ${
|
|
138
|
-
return
|
|
139
|
-
return { discoveryKey: feed.discoveryKey };
|
|
140
|
-
});
|
|
134
|
+
const feeds = this._feedProvider.getFeeds();
|
|
135
|
+
log(`Loading feeds: ${feeds.map(feed => keyToString(feed.key))}`);
|
|
136
|
+
return feeds.map((feed) => ({ discoveryKey: feed.feed.discoveryKey }));
|
|
141
137
|
},
|
|
142
138
|
|
|
143
139
|
subscribe: (addFeedToReplicatedSet: (feed: any) => void) => {
|
|
144
|
-
return this.
|
|
145
|
-
log(`Adding feed: ${
|
|
146
|
-
|
|
147
|
-
addFeedToReplicatedSet({ discoveryKey: feed.discoveryKey });
|
|
140
|
+
return this._feedProvider.feedOpened.on(async (feed) => {
|
|
141
|
+
log(`Adding feed: ${feed.key.toHex()}`);
|
|
142
|
+
addFeedToReplicatedSet({ discoveryKey: feed.feed.discoveryKey });
|
|
148
143
|
});
|
|
149
144
|
},
|
|
150
145
|
|
|
151
146
|
replicate: async (remoteFeeds, info) => {
|
|
152
147
|
// We can ignore remoteFeeds entirely, since the set of feeds we want to replicate is dictated by the Party.
|
|
153
148
|
// TODO(telackey): Why are we opening feeds? Necessary or belt/braces thinking, or because open party does it?
|
|
154
|
-
|
|
155
|
-
|
|
149
|
+
const feeds = this._feedProvider.getFeeds();
|
|
150
|
+
log(`Replicating: peerId=${info.session}; feeds=${feeds.map(feed => feed.key.toHex())}`);
|
|
151
|
+
return feeds.map(feed => feed.feed);
|
|
156
152
|
}
|
|
157
153
|
})
|
|
158
154
|
];
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
|
|
5
5
|
import assert from 'assert';
|
|
6
6
|
import debug from 'debug';
|
|
7
|
-
import pify from 'pify';
|
|
8
7
|
|
|
9
8
|
import { keyToString } from '@dxos/crypto';
|
|
10
9
|
import { schema, PartyKey, PartySnapshot } from '@dxos/echo-protocol';
|
|
@@ -26,12 +25,12 @@ export class SnapshotStore {
|
|
|
26
25
|
const file = this._storage.createOrOpen(partyKey.toHex());
|
|
27
26
|
|
|
28
27
|
try {
|
|
29
|
-
const { size } = await
|
|
28
|
+
const { size } = await file.stat();
|
|
30
29
|
if (size === 0) {
|
|
31
30
|
return undefined;
|
|
32
31
|
}
|
|
33
32
|
|
|
34
|
-
const data = await
|
|
33
|
+
const data = await file.read(0, size);
|
|
35
34
|
return schema.getCodecForType('dxos.echo.snapshot.PartySnapshot').decode(data);
|
|
36
35
|
} catch (err: any) {
|
|
37
36
|
if (err.code === 'ENOENT') {
|
|
@@ -40,7 +39,7 @@ export class SnapshotStore {
|
|
|
40
39
|
throw err;
|
|
41
40
|
}
|
|
42
41
|
} finally {
|
|
43
|
-
await
|
|
42
|
+
await file.close();
|
|
44
43
|
}
|
|
45
44
|
}
|
|
46
45
|
|
|
@@ -50,9 +49,9 @@ export class SnapshotStore {
|
|
|
50
49
|
|
|
51
50
|
try {
|
|
52
51
|
const data = schema.getCodecForType('dxos.echo.snapshot.PartySnapshot').encode(snapshot);
|
|
53
|
-
await
|
|
52
|
+
await file.write(0, Buffer.from(data));
|
|
54
53
|
} finally {
|
|
55
|
-
await
|
|
54
|
+
await file.close();
|
|
56
55
|
}
|
|
57
56
|
}
|
|
58
57
|
|