@dxos/echo-db 2.33.1-dev.83d113fe → 2.33.1-dev.d6c55789
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/invitations/greeting-initiator.d.ts +1 -4
- package/dist/src/invitations/greeting-initiator.d.ts.map +1 -1
- package/dist/src/invitations/greeting-initiator.js +1 -7
- package/dist/src/invitations/greeting-initiator.js.map +1 -1
- package/dist/src/invitations/halo-recovery-initiator.d.ts.map +1 -1
- package/dist/src/invitations/halo-recovery-initiator.js +2 -2
- package/dist/src/invitations/halo-recovery-initiator.js.map +1 -1
- 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/authenticator.d.ts +5 -0
- package/dist/src/parties/authenticator.d.ts.map +1 -0
- package/dist/src/parties/authenticator.js +27 -0
- package/dist/src/parties/authenticator.js.map +1 -0
- package/dist/src/parties/party-factory.d.ts.map +1 -1
- package/dist/src/parties/party-factory.js +1 -5
- package/dist/src/parties/party-factory.js.map +1 -1
- package/dist/src/parties/party-internal.d.ts.map +1 -1
- package/dist/src/parties/party-internal.js +5 -3
- package/dist/src/parties/party-internal.js.map +1 -1
- package/dist/src/pipeline/party-processor.d.ts +2 -3
- package/dist/src/pipeline/party-processor.d.ts.map +1 -1
- package/dist/src/pipeline/party-processor.js +5 -11
- package/dist/src/pipeline/party-processor.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +17 -17
- package/src/invitations/greeting-initiator.ts +1 -26
- package/src/invitations/halo-recovery-initiator.ts +4 -4
- package/src/invitations/offline-invitation-claimer.ts +4 -4
- package/src/parties/authenticator.ts +31 -0
- package/src/parties/party-factory.ts +1 -6
- package/src/parties/party-internal.ts +14 -5
- package/src/pipeline/party-processor.ts +5 -15
|
@@ -7,7 +7,6 @@ import debug from 'debug';
|
|
|
7
7
|
|
|
8
8
|
import { waitForEvent } from '@dxos/async';
|
|
9
9
|
import {
|
|
10
|
-
Authenticator,
|
|
11
10
|
ClaimResponse,
|
|
12
11
|
Keyring,
|
|
13
12
|
KeyType,
|
|
@@ -17,7 +16,8 @@ import {
|
|
|
17
16
|
createGreetingClaimMessage,
|
|
18
17
|
SecretProvider,
|
|
19
18
|
SecretValidator,
|
|
20
|
-
SignedMessage
|
|
19
|
+
SignedMessage,
|
|
20
|
+
codec
|
|
21
21
|
} from '@dxos/credentials';
|
|
22
22
|
import { keyToBuffer, keyToString, PublicKey, randomBytes, verify } from '@dxos/crypto';
|
|
23
23
|
import { raise } from '@dxos/debug';
|
|
@@ -144,7 +144,7 @@ export class HaloRecoveryInitiator {
|
|
|
144
144
|
|
|
145
145
|
// The secretProvider should provide an `Auth` message signed directly by the Identity key.
|
|
146
146
|
createSecretProvider (): SecretProvider {
|
|
147
|
-
return async (info: any) => Buffer.from(
|
|
147
|
+
return async (info: any) => Buffer.from(codec.encode(
|
|
148
148
|
/* The signed portion of the Auth message includes the ID and authNonce provided
|
|
149
149
|
* by "info". These values will be validated on the other end.
|
|
150
150
|
*/
|
|
@@ -182,7 +182,7 @@ export class HaloRecoveryInitiator {
|
|
|
182
182
|
});
|
|
183
183
|
|
|
184
184
|
const secretValidator: SecretValidator = async (invitation, secret) => {
|
|
185
|
-
const { payload: authMessage } =
|
|
185
|
+
const { payload: authMessage } = codec.decode(secret);
|
|
186
186
|
|
|
187
187
|
return keyring.verify(<unknown>authMessage as SignedMessage) &&
|
|
188
188
|
authMessage.signed.payload.partyKey.equals(invitation.id) &&
|
|
@@ -7,7 +7,6 @@ import debug from 'debug';
|
|
|
7
7
|
|
|
8
8
|
import { waitForEvent } from '@dxos/async';
|
|
9
9
|
import {
|
|
10
|
-
Authenticator,
|
|
11
10
|
ClaimResponse,
|
|
12
11
|
Keyring,
|
|
13
12
|
KeyType,
|
|
@@ -18,7 +17,8 @@ import {
|
|
|
18
17
|
SecretInfo,
|
|
19
18
|
SecretProvider,
|
|
20
19
|
SecretValidator,
|
|
21
|
-
SignedMessage
|
|
20
|
+
SignedMessage,
|
|
21
|
+
codec
|
|
22
22
|
} from '@dxos/credentials';
|
|
23
23
|
import { keyToBuffer, keyToString, PublicKey, randomBytes } from '@dxos/crypto';
|
|
24
24
|
import { raise } from '@dxos/debug';
|
|
@@ -156,7 +156,7 @@ export class OfflineInvitationClaimer {
|
|
|
156
156
|
});
|
|
157
157
|
|
|
158
158
|
const secretValidator: SecretValidator = async (invitation, secret) => {
|
|
159
|
-
const { payload: authMessage } =
|
|
159
|
+
const { payload: authMessage } = codec.decode(secret);
|
|
160
160
|
|
|
161
161
|
return keyring.verify(<unknown>authMessage as SignedMessage) &&
|
|
162
162
|
authMessage.signed.payload.partyKey.equals(invitation.id) &&
|
|
@@ -172,7 +172,7 @@ export class OfflineInvitationClaimer {
|
|
|
172
172
|
// The secretProvider should provide an `Auth` message signed directly by the Identity key.
|
|
173
173
|
static createSecretProvider (identity: Identity): SecretProvider {
|
|
174
174
|
return async (info?: SecretInfo) => {
|
|
175
|
-
return Buffer.from(
|
|
175
|
+
return Buffer.from(codec.encode(
|
|
176
176
|
/* The signed portion of the Auth message includes the ID and authNonce provided
|
|
177
177
|
* by the `info` object. These values will be validated on the other end.
|
|
178
178
|
*/
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2022 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import debug from 'debug';
|
|
6
|
+
|
|
7
|
+
import { Authenticator, createEnvelopeMessage, PartyAuthenticator } from '@dxos/credentials';
|
|
8
|
+
|
|
9
|
+
import { IdentityProvider } from '../halo';
|
|
10
|
+
import { PartyProcessor } from '../pipeline';
|
|
11
|
+
|
|
12
|
+
const log = debug('dxos:echo-db:authenticator');
|
|
13
|
+
|
|
14
|
+
export function createAuthenticator (partyProcessor: PartyProcessor, identityProvider: IdentityProvider): Authenticator {
|
|
15
|
+
return new PartyAuthenticator(partyProcessor.state, async auth => {
|
|
16
|
+
if (auth.feedAdmit && auth.feedKey && !partyProcessor.isFeedAdmitted(auth.feedKey)) {
|
|
17
|
+
const deviceKeyChain = identityProvider().deviceKeyChain ?? identityProvider().deviceKey;
|
|
18
|
+
if (!deviceKeyChain) {
|
|
19
|
+
log('Not device key chain available to admit new member feed');
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
await partyProcessor.writeHaloMessage(createEnvelopeMessage(
|
|
24
|
+
identityProvider().keyring,
|
|
25
|
+
partyProcessor.partyKey,
|
|
26
|
+
auth.feedAdmit,
|
|
27
|
+
[deviceKeyChain]
|
|
28
|
+
));
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
@@ -205,12 +205,7 @@ export class PartyFactory {
|
|
|
205
205
|
const initiator = new GreetingInitiator(
|
|
206
206
|
this._networkManager,
|
|
207
207
|
identity,
|
|
208
|
-
invitationDescriptor
|
|
209
|
-
async partyKey => {
|
|
210
|
-
const feedProvider = this._createFeedProvider(partyKey);
|
|
211
|
-
const feed = await feedProvider.createOrOpenWritableFeed();
|
|
212
|
-
return feed.key;
|
|
213
|
-
}
|
|
208
|
+
invitationDescriptor
|
|
214
209
|
);
|
|
215
210
|
|
|
216
211
|
await initiator.connect();
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import assert from 'assert';
|
|
6
6
|
|
|
7
7
|
import { synchronized, Event } from '@dxos/async';
|
|
8
|
-
import { KeyHint, createAuthMessage,
|
|
8
|
+
import { KeyHint, createAuthMessage, createFeedAdmitMessage, codec } from '@dxos/credentials';
|
|
9
9
|
import { PublicKey } from '@dxos/crypto';
|
|
10
10
|
import { failUndefined, raise, timed } from '@dxos/debug';
|
|
11
11
|
import { PartyKey, PartySnapshot, Timeframe, FeedKey } from '@dxos/echo-protocol';
|
|
@@ -19,6 +19,7 @@ import { ActivationOptions, PartyPreferences, IdentityProvider } from '../halo';
|
|
|
19
19
|
import { InvitationManager } from '../invitations';
|
|
20
20
|
import { CredentialsProvider, PartyFeedProvider, PartyProtocolFactory } from '../pipeline';
|
|
21
21
|
import { SnapshotStore } from '../snapshots';
|
|
22
|
+
import { createAuthenticator } from './authenticator';
|
|
22
23
|
import { PartyCore, PartyOptions } from './party-core';
|
|
23
24
|
import { CONTACT_DEBOUNCE_INTERVAL } from './party-manager';
|
|
24
25
|
|
|
@@ -178,7 +179,7 @@ export class PartyInternal {
|
|
|
178
179
|
this._identityProvider,
|
|
179
180
|
this._createCredentialsProvider(this._partyCore.key, writeFeed.key),
|
|
180
181
|
this._invitationManager,
|
|
181
|
-
this._partyCore.processor.
|
|
182
|
+
createAuthenticator(this._partyCore.processor, this._identityProvider),
|
|
182
183
|
this._partyCore.processor.getActiveFeedSet()
|
|
183
184
|
);
|
|
184
185
|
|
|
@@ -274,12 +275,20 @@ export class PartyInternal {
|
|
|
274
275
|
return {
|
|
275
276
|
get: () => {
|
|
276
277
|
const identity = this._identityProvider();
|
|
277
|
-
|
|
278
|
+
const signingKey = identity.deviceKeyChain ?? identity.deviceKey ?? raise(new IdentityNotInitializedError());
|
|
279
|
+
return Buffer.from(codec.encode(createAuthMessage(
|
|
278
280
|
identity.signer,
|
|
279
281
|
partyKey,
|
|
280
282
|
identity.identityKey ?? raise(new IdentityNotInitializedError()),
|
|
281
|
-
|
|
282
|
-
identity.keyring.getKey(feedKey)
|
|
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
|
+
)
|
|
283
292
|
)));
|
|
284
293
|
}
|
|
285
294
|
};
|
|
@@ -7,11 +7,9 @@ import debug from 'debug';
|
|
|
7
7
|
|
|
8
8
|
import { Event } from '@dxos/async';
|
|
9
9
|
import {
|
|
10
|
-
Authenticator,
|
|
11
10
|
KeyHint,
|
|
12
11
|
KeyRecord,
|
|
13
12
|
PartyState,
|
|
14
|
-
PartyAuthenticator,
|
|
15
13
|
Message as HaloMessage,
|
|
16
14
|
IdentityEventType,
|
|
17
15
|
PartyEventType
|
|
@@ -32,7 +30,6 @@ export interface FeedSetProvider {
|
|
|
32
30
|
*/
|
|
33
31
|
export class PartyProcessor {
|
|
34
32
|
private readonly _state: PartyState;
|
|
35
|
-
private readonly _authenticator: Authenticator;
|
|
36
33
|
|
|
37
34
|
private _outboundHaloStream: FeedWriter<HaloMessage> | undefined;
|
|
38
35
|
|
|
@@ -49,21 +46,14 @@ export class PartyProcessor {
|
|
|
49
46
|
private readonly _partyKey: PartyKey
|
|
50
47
|
) {
|
|
51
48
|
this._state = new PartyState(this._partyKey);
|
|
52
|
-
this._authenticator = new PartyAuthenticator(this._state);
|
|
53
|
-
|
|
54
|
-
/* TODO(telackey): `@dxos/credentials` was only half converted to TS. In its current state, the KeyRecord type
|
|
55
|
-
* is not exported, and the PartyStateMachine being used is not properly understood as an EventEmitter by TS.
|
|
56
|
-
* Casting to 'any' is a workaround for the compiler, but the fix is fully to convert @dxos/credentials to TS.
|
|
57
|
-
*/
|
|
58
|
-
const state = this._state as any;
|
|
59
49
|
|
|
60
50
|
// TODO(marik-d): Use `Event.wrap` here.
|
|
61
|
-
|
|
51
|
+
this._state.on(PartyEventType.ADMIT_FEED, (keyRecord: any) => {
|
|
62
52
|
log(`Feed key admitted ${keyRecord.publicKey.toHex()}`);
|
|
63
53
|
this._feedAdded.emit(keyRecord.publicKey);
|
|
64
54
|
});
|
|
65
|
-
|
|
66
|
-
|
|
55
|
+
this._state.on(PartyEventType.ADMIT_KEY, (keyRecord: KeyRecord) => this.keyOrInfoAdded.emit(keyRecord.publicKey));
|
|
56
|
+
this._state.on(IdentityEventType.UPDATE_IDENTITY, (publicKey: PublicKey) => this.keyOrInfoAdded.emit(publicKey));
|
|
67
57
|
}
|
|
68
58
|
|
|
69
59
|
get partyKey () {
|
|
@@ -90,8 +80,8 @@ export class PartyProcessor {
|
|
|
90
80
|
return this._state.credentialMessages.size === 0;
|
|
91
81
|
}
|
|
92
82
|
|
|
93
|
-
get
|
|
94
|
-
return this.
|
|
83
|
+
get state () {
|
|
84
|
+
return this._state;
|
|
95
85
|
}
|
|
96
86
|
|
|
97
87
|
isFeedAdmitted (feedKey: FeedKey) {
|