@dxos/credentials 2.33.8-dev.8609bc45 → 2.33.9-dev.0628f3ab
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/.rush/temp/package-deps_build.json +62 -0
- package/.rush/temp/package-deps_build_test.json +21 -21
- package/.rush/temp/shrinkwrap-deps.json +23 -12
- package/credentials.build.log +10 -9
- package/dist/src/auth/auth-message.js +2 -2
- package/dist/src/auth/auth-message.js.map +1 -1
- package/dist/src/auth/auth-plugin.d.ts.map +1 -1
- package/dist/src/auth/auth-plugin.js +4 -4
- package/dist/src/auth/auth-plugin.js.map +1 -1
- package/dist/src/auth/auth-plugin.test.js +7 -7
- package/dist/src/auth/auth-plugin.test.js.map +1 -1
- package/dist/src/greet/greeter-plugin.test.js +11 -16
- package/dist/src/greet/greeter-plugin.test.js.map +1 -1
- package/dist/src/greet/greeter.d.ts +3 -5
- package/dist/src/greet/greeter.d.ts.map +1 -1
- package/dist/src/greet/greeter.js +14 -18
- package/dist/src/greet/greeter.js.map +1 -1
- package/dist/src/greet/greeter.test.js +4 -10
- package/dist/src/greet/greeter.test.js.map +1 -1
- package/dist/src/greet/greeting-command-plugin.d.ts.map +1 -1
- package/dist/src/greet/greeting-command-plugin.js +14 -14
- package/dist/src/greet/greeting-command-plugin.js.map +1 -1
- package/dist/src/greet/greeting-message.js +9 -9
- package/dist/src/greet/greeting-message.js.map +1 -1
- package/dist/src/greet/party-invitation-claim-handler.js +5 -5
- package/dist/src/greet/party-invitation-claim-handler.js.map +1 -1
- package/dist/src/identity/identity-message-processor.d.ts.map +1 -1
- package/dist/src/identity/identity-message-processor.js +6 -6
- package/dist/src/identity/identity-message-processor.js.map +1 -1
- package/dist/src/identity/identity-message.js +7 -7
- package/dist/src/identity/identity-message.js.map +1 -1
- package/dist/src/identity/seedphrase.js +2 -2
- package/dist/src/identity/seedphrase.js.map +1 -1
- package/dist/src/keys/keyring-helpers.d.ts.map +1 -1
- package/dist/src/keys/keyring-helpers.js +12 -12
- package/dist/src/keys/keyring-helpers.js.map +1 -1
- package/dist/src/keys/keyring.js +19 -19
- package/dist/src/keys/keyring.js.map +1 -1
- package/dist/src/keys/keyring.test.js +10 -10
- package/dist/src/keys/keyring.test.js.map +1 -1
- package/dist/src/keys/keystore.js +5 -5
- package/dist/src/keys/keystore.js.map +1 -1
- package/dist/src/party/party-credential.js +9 -9
- package/dist/src/party/party-credential.js.map +1 -1
- package/dist/src/party/party-invitation-manager.js +5 -5
- package/dist/src/party/party-invitation-manager.js.map +1 -1
- package/dist/src/party/party-state.d.ts.map +1 -1
- package/dist/src/party/party-state.js +21 -21
- package/dist/src/party/party-state.js.map +1 -1
- package/dist/src/proto/gen/dxos/credentials/greet.d.ts +1 -1
- package/dist/src/proto/gen/dxos/credentials/greet.d.ts.map +1 -1
- package/dist/src/proto/gen/index.d.ts.map +1 -1
- package/dist/src/proto/gen/index.js +1 -1
- package/dist/src/proto/gen/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +17 -13
- package/src/auth/auth-message.ts +1 -1
- package/src/auth/auth-plugin.test.ts +6 -6
- package/src/auth/auth-plugin.ts +1 -1
- package/src/greet/greeter-plugin.test.ts +13 -19
- package/src/greet/greeter.test.js +6 -15
- package/src/greet/greeter.ts +10 -14
- package/src/greet/greeting-command-plugin.ts +4 -4
- package/src/greet/greeting-message.ts +1 -1
- package/src/greet/party-invitation-claim-handler.ts +1 -1
- package/src/identity/identity-message-processor.ts +1 -1
- package/src/identity/identity-message.ts +1 -1
- package/src/identity/seedphrase.ts +1 -1
- package/src/keys/keyring-helpers.ts +3 -3
- package/src/keys/keyring.test.ts +5 -5
- package/src/keys/keyring.ts +3 -3
- package/src/keys/keystore.ts +1 -1
- package/src/party/party-credential.ts +1 -1
- package/src/party/party-invitation-manager.ts +1 -1
- package/src/party/party-state.ts +1 -1
- package/src/proto/gen/dxos/credentials/greet.ts +1 -1
- package/src/proto/gen/index.ts +1 -1
|
@@ -4,15 +4,15 @@
|
|
|
4
4
|
|
|
5
5
|
// DXOS testing browser.
|
|
6
6
|
|
|
7
|
-
import assert from 'assert';
|
|
8
7
|
import debug from 'debug';
|
|
9
8
|
import eos from 'end-of-stream';
|
|
10
9
|
import expect from 'expect';
|
|
10
|
+
import assert from 'node:assert';
|
|
11
11
|
import pify from 'pify';
|
|
12
12
|
import pump from 'pump';
|
|
13
13
|
import waitForExpect from 'wait-for-expect';
|
|
14
14
|
|
|
15
|
-
import {
|
|
15
|
+
import { randomBytes, createKeyPair } from '@dxos/crypto';
|
|
16
16
|
import { FeedStore, createBatchStream, HypercoreFeed } from '@dxos/feed-store';
|
|
17
17
|
import { Protocol, ProtocolOptions } from '@dxos/mesh-protocol';
|
|
18
18
|
import { Replicator } from '@dxos/protocol-plugin-replicator';
|
|
@@ -83,7 +83,7 @@ const createProtocol = async (partyKey: PublicKey, authenticator: Authenticator,
|
|
|
83
83
|
const auth = new AuthPlugin(peerId, authenticator, [Replicator.extension]);
|
|
84
84
|
const authPromise = new Promise((resolve) => {
|
|
85
85
|
auth.on('authenticated', (incomingPeerId) => {
|
|
86
|
-
log(`Authenticated ${
|
|
86
|
+
log(`Authenticated ${PublicKey.stringify(incomingPeerId)} on ${PublicKey.stringify(peerId)}`);
|
|
87
87
|
resolve(true);
|
|
88
88
|
});
|
|
89
89
|
});
|
|
@@ -112,7 +112,7 @@ const createProtocol = async (partyKey: PublicKey, authenticator: Authenticator,
|
|
|
112
112
|
const proto = new Protocol({
|
|
113
113
|
streamOptions: { live: true },
|
|
114
114
|
discoveryKey: partyKey.asBuffer(),
|
|
115
|
-
userSession: { peerId:
|
|
115
|
+
userSession: { peerId: PublicKey.stringify(peerId), credentials },
|
|
116
116
|
initiator: !!protocolOptions?.initiator
|
|
117
117
|
})
|
|
118
118
|
.setExtension(auth.createExtension())
|
|
@@ -184,7 +184,7 @@ it('Auth & Repl (GOOD)', async () => {
|
|
|
184
184
|
await waitForExpect(async () => {
|
|
185
185
|
const msgs = await getMessages(node1, node2);
|
|
186
186
|
expect(msgs).toContain(message1);
|
|
187
|
-
log(`${message1} on ${
|
|
187
|
+
log(`${message1} on ${PublicKey.stringify(node2.id)}.`);
|
|
188
188
|
});
|
|
189
189
|
|
|
190
190
|
const message2 = randomBytes(32).toString('hex');
|
|
@@ -192,7 +192,7 @@ it('Auth & Repl (GOOD)', async () => {
|
|
|
192
192
|
await waitForExpect(async () => {
|
|
193
193
|
const msgs = await getMessages(node2, node1);
|
|
194
194
|
expect(msgs).toContain(message2);
|
|
195
|
-
log(`${message2} on ${
|
|
195
|
+
log(`${message2} on ${PublicKey.stringify(node1.id)}.`);
|
|
196
196
|
});
|
|
197
197
|
|
|
198
198
|
connection.destroy();
|
package/src/auth/auth-plugin.ts
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// Copyright 2019 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import assert from 'assert';
|
|
6
5
|
import debug from 'debug';
|
|
7
6
|
import { EventEmitter } from 'events';
|
|
7
|
+
import assert from 'node:assert';
|
|
8
8
|
|
|
9
9
|
import { Extension, ERR_EXTENSION_RESPONSE_FAILED, Protocol } from '@dxos/mesh-protocol';
|
|
10
10
|
|
|
@@ -7,7 +7,7 @@ import expect from 'expect';
|
|
|
7
7
|
import pump from 'pump';
|
|
8
8
|
|
|
9
9
|
import { trigger } from '@dxos/async';
|
|
10
|
-
import {
|
|
10
|
+
import { randomBytes } from '@dxos/crypto';
|
|
11
11
|
import { Protocol } from '@dxos/mesh-protocol';
|
|
12
12
|
import { PublicKey, PublicKeyLike } from '@dxos/protocols';
|
|
13
13
|
import { arraysEqual } from '@dxos/util';
|
|
@@ -24,23 +24,16 @@ const log = debug('dxos:halo:greet');
|
|
|
24
24
|
/**
|
|
25
25
|
* Create the Greeter with Plugin and Protocol.
|
|
26
26
|
*/
|
|
27
|
-
const createGreeter = async (targetPartyKey: PublicKeyLike) => {
|
|
27
|
+
const createGreeter = async (targetPartyKey: PublicKeyLike, genesisFeedKey: PublicKey) => {
|
|
28
28
|
const [writePromise, outerResolve] = trigger<Message[]>();
|
|
29
29
|
|
|
30
|
-
const hints = [
|
|
31
|
-
{ publicKey: PublicKey.from(randomBytes(32)), type: KeyType.IDENTITY },
|
|
32
|
-
{ publicKey: PublicKey.from(randomBytes(32)), type: KeyType.DEVICE },
|
|
33
|
-
{ publicKey: PublicKey.from(randomBytes(32)), type: KeyType.FEED },
|
|
34
|
-
{ publicKey: PublicKey.from(randomBytes(32)), type: KeyType.FEED }
|
|
35
|
-
];
|
|
36
|
-
|
|
37
30
|
const greeter = new Greeter(
|
|
38
31
|
targetPartyKey,
|
|
32
|
+
genesisFeedKey,
|
|
39
33
|
async messages => {
|
|
40
34
|
outerResolve(messages);
|
|
41
35
|
return messages;
|
|
42
|
-
}
|
|
43
|
-
async () => hints
|
|
36
|
+
}
|
|
44
37
|
);
|
|
45
38
|
|
|
46
39
|
const peerId = randomBytes(32);
|
|
@@ -51,13 +44,13 @@ const createGreeter = async (targetPartyKey: PublicKeyLike) => {
|
|
|
51
44
|
live: true
|
|
52
45
|
},
|
|
53
46
|
discoveryKey: peerId,
|
|
54
|
-
userSession: { peerId:
|
|
47
|
+
userSession: { peerId: PublicKey.stringify(peerId) },
|
|
55
48
|
initiator: true
|
|
56
49
|
})
|
|
57
50
|
.setExtension(plugin.createExtension())
|
|
58
51
|
.init();
|
|
59
52
|
|
|
60
|
-
return { greeter, rendezvousKey: peerId, plugin, protocol, writePromise: writePromise()
|
|
53
|
+
return { greeter, rendezvousKey: peerId, plugin, protocol, writePromise: writePromise() };
|
|
61
54
|
};
|
|
62
55
|
|
|
63
56
|
/**
|
|
@@ -71,8 +64,8 @@ const createInvitee = async (rendezvousKey: Buffer, invitationId: Buffer) => {
|
|
|
71
64
|
|
|
72
65
|
const connectionPromise = new Promise<void>(resolve => {
|
|
73
66
|
plugin.on('peer:joined', (peerId) => {
|
|
74
|
-
if (peerId &&
|
|
75
|
-
log(`${
|
|
67
|
+
if (peerId && PublicKey.stringify(peerId) === PublicKey.stringify(rendezvousKey)) {
|
|
68
|
+
log(`${PublicKey.stringify(peerId)} connected.`);
|
|
76
69
|
resolve();
|
|
77
70
|
}
|
|
78
71
|
});
|
|
@@ -83,7 +76,7 @@ const createInvitee = async (rendezvousKey: Buffer, invitationId: Buffer) => {
|
|
|
83
76
|
live: true
|
|
84
77
|
},
|
|
85
78
|
discoveryKey: rendezvousKey,
|
|
86
|
-
userSession: { peerId:
|
|
79
|
+
userSession: { peerId: PublicKey.stringify(peerId) },
|
|
87
80
|
initiator: false
|
|
88
81
|
})
|
|
89
82
|
.setExtension(plugin.createExtension())
|
|
@@ -100,14 +93,15 @@ const connect = (source: Protocol, target: Protocol) => pump(source.stream, targ
|
|
|
100
93
|
|
|
101
94
|
it('Greeting Flow using GreetingCommandPlugin', async () => {
|
|
102
95
|
const targetPartyKey = PublicKey.from(randomBytes(32));
|
|
96
|
+
const genesisFeedKey = PublicKey.from(randomBytes(32));
|
|
103
97
|
const secret = '0000';
|
|
104
98
|
|
|
105
99
|
const secretProvider: SecretProvider = async () => Buffer.from(secret);
|
|
106
100
|
const secretValidator: SecretValidator = async (invitation, secret) => !!secret && !!invitation.secret && arraysEqual(secret, invitation.secret);
|
|
107
101
|
|
|
108
102
|
const {
|
|
109
|
-
protocol: greeterProtocol, greeter, rendezvousKey,
|
|
110
|
-
} = await createGreeter(targetPartyKey);
|
|
103
|
+
protocol: greeterProtocol, greeter, rendezvousKey, writePromise
|
|
104
|
+
} = await createGreeter(targetPartyKey, genesisFeedKey);
|
|
111
105
|
|
|
112
106
|
const invitation = await greeter.createInvitation(targetPartyKey, secretValidator, secretProvider);
|
|
113
107
|
|
|
@@ -162,7 +156,7 @@ it('Greeting Flow using GreetingCommandPlugin', async () => {
|
|
|
162
156
|
|
|
163
157
|
// Send them to the greeter.
|
|
164
158
|
const notarizeResponse = await plugin.send(rendezvousKey, command);
|
|
165
|
-
expect(notarizeResponse.
|
|
159
|
+
expect(notarizeResponse.genesisFeed).toEqual(genesisFeedKey);
|
|
166
160
|
|
|
167
161
|
// In the real world, the response would be signed in an envelope by the Greeter, but in this test it is not altered.
|
|
168
162
|
const written = await writePromise;
|
|
@@ -21,27 +21,20 @@ const createKeyring = async () => {
|
|
|
21
21
|
await keyring.createKeyRecord({ type: KeyType.PARTY });
|
|
22
22
|
await keyring.createKeyRecord({ type: KeyType.IDENTITY });
|
|
23
23
|
await keyring.createKeyRecord({ type: KeyType.DEVICE });
|
|
24
|
+
await keyring.createKeyRecord({ type: KeyType.FEED });
|
|
24
25
|
return keyring;
|
|
25
26
|
};
|
|
26
27
|
|
|
27
|
-
const createGreeter = (keyring
|
|
28
|
+
const createGreeter = (keyring) => new Greeter(
|
|
28
29
|
keyring.findKey(Filter.matches({ type: KeyType.PARTY })).publicKey,
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
keyring.findKey(Filter.matches({ type: KeyType.FEED })).publicKey,
|
|
31
|
+
messages => messages
|
|
31
32
|
);
|
|
32
33
|
|
|
33
34
|
it('Good invitation', async () => {
|
|
34
35
|
const keyring = await createKeyring();
|
|
35
36
|
const secret = '0000';
|
|
36
|
-
|
|
37
|
-
const hints = [
|
|
38
|
-
{ publicKey: randomBytes(32), type: KeyType.IDENTITY },
|
|
39
|
-
{ publicKey: randomBytes(32), type: KeyType.DEVICE },
|
|
40
|
-
{ publicKey: randomBytes(32), type: KeyType.FEED },
|
|
41
|
-
{ publicKey: randomBytes(32), type: KeyType.FEED }
|
|
42
|
-
];
|
|
43
|
-
|
|
44
|
-
const greeter = createGreeter(keyring, hints);
|
|
37
|
+
const greeter = createGreeter(keyring);
|
|
45
38
|
|
|
46
39
|
const secretProvider = async () => Buffer.from(secret);
|
|
47
40
|
const secretValidator = async (invitation, secret) => secret && arraysEqual(secret, invitation.secret);
|
|
@@ -105,9 +98,7 @@ it('Good invitation', async () => {
|
|
|
105
98
|
}
|
|
106
99
|
};
|
|
107
100
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
expect(response.feedHints).toEqual(hints.filter(hint => hint.type === KeyType.FEED).map(hint => hint.publicKey));
|
|
101
|
+
await greeter.handleMessage(message.payload, invitation.id, randomBytes());
|
|
111
102
|
|
|
112
103
|
// The `FINISH` command informs the Greeter the Invitee is done.
|
|
113
104
|
{
|
package/src/greet/greeter.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
// Copyright 2019 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import assert from 'assert';
|
|
6
5
|
import debug from 'debug';
|
|
6
|
+
import assert from 'node:assert';
|
|
7
7
|
|
|
8
8
|
import { ERR_EXTENSION_RESPONSE_FAILED } from '@dxos/mesh-protocol';
|
|
9
9
|
import { PublicKeyLike, PublicKey } from '@dxos/protocols';
|
|
@@ -11,7 +11,7 @@ import { arraysEqual } from '@dxos/util';
|
|
|
11
11
|
|
|
12
12
|
import { Keyring } from '../keys';
|
|
13
13
|
import { getPartyCredentialMessageType } from '../party';
|
|
14
|
-
import { PartyCredential, Message,
|
|
14
|
+
import { PartyCredential, Message, Command, NotarizeResponse, WithTypeUrl } from '../proto';
|
|
15
15
|
import { PeerId } from '../typedefs';
|
|
16
16
|
import {
|
|
17
17
|
ERR_GREET_INVALID_COMMAND,
|
|
@@ -28,7 +28,6 @@ import { Invitation, InvitationOnFinish, SecretProvider, SecretValidator } from
|
|
|
28
28
|
const log = debug('dxos:halo:greet');
|
|
29
29
|
|
|
30
30
|
export type PartyWriter = (params: Message[]) => Promise<Message[]>;
|
|
31
|
-
export type HintProvider = (params: Message[]) => Promise<KeyHint[]>;
|
|
32
31
|
|
|
33
32
|
/**
|
|
34
33
|
* Reference Greeter that uses useable, single-use "invitations" to authenticate the invitee.
|
|
@@ -36,7 +35,6 @@ export type HintProvider = (params: Message[]) => Promise<KeyHint[]>;
|
|
|
36
35
|
export class Greeter {
|
|
37
36
|
_partyKey?: PublicKey;
|
|
38
37
|
_partyWriter?: PartyWriter;
|
|
39
|
-
_hintProvider?: HintProvider;
|
|
40
38
|
_invitations = new Map<string, Invitation>();
|
|
41
39
|
|
|
42
40
|
/**
|
|
@@ -44,18 +42,19 @@ export class Greeter {
|
|
|
44
42
|
* TODO(telackey): Does it make sense to separate out the Invitee functionality?
|
|
45
43
|
* @param {PublicKeyLike} [partyKey] The publicKey of the target Party.
|
|
46
44
|
* @param {function} [partyWriter] Callback function to write messages to the Party.
|
|
47
|
-
* @param {function} [hintProvider] Callback function to gather feed and key hints to give to the invitee.
|
|
48
45
|
*/
|
|
49
|
-
constructor (
|
|
50
|
-
|
|
46
|
+
constructor (
|
|
47
|
+
partyKey?: PublicKeyLike,
|
|
48
|
+
private readonly _genesisFeedKey?: PublicKey,
|
|
49
|
+
partyWriter?: PartyWriter
|
|
50
|
+
) {
|
|
51
|
+
if (partyKey || partyWriter) {
|
|
51
52
|
assert(partyKey);
|
|
52
53
|
assert(partyWriter);
|
|
53
|
-
assert(hintProvider);
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
this._partyKey = partyKey ? PublicKey.from(partyKey) : undefined;
|
|
57
57
|
this._partyWriter = partyWriter;
|
|
58
|
-
this._hintProvider = hintProvider;
|
|
59
58
|
}
|
|
60
59
|
|
|
61
60
|
/**
|
|
@@ -250,19 +249,16 @@ export class Greeter {
|
|
|
250
249
|
log('Admitting new node after successful greeting.');
|
|
251
250
|
|
|
252
251
|
assert(this._partyWriter);
|
|
253
|
-
assert(this._hintProvider);
|
|
254
252
|
|
|
255
253
|
// Write the supplied messages to the target Party.
|
|
256
254
|
const copies = await this._partyWriter(params);
|
|
257
255
|
|
|
258
|
-
// Retrieve the hinted feed and key info for the invitee.
|
|
259
|
-
const hints = await this._hintProvider(params);
|
|
260
|
-
|
|
261
256
|
await invitation.notarize();
|
|
257
|
+
assert(this._genesisFeedKey);
|
|
262
258
|
return {
|
|
263
259
|
'@type': 'dxos.credentials.greet.NotarizeResponse',
|
|
264
260
|
copies,
|
|
265
|
-
|
|
261
|
+
genesisFeed: this._genesisFeedKey
|
|
266
262
|
};
|
|
267
263
|
}
|
|
268
264
|
}
|
|
@@ -7,13 +7,13 @@
|
|
|
7
7
|
* and moved somewhere more abstract (RpcProtocolPlugin?).
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import assert from 'assert';
|
|
11
10
|
import debug from 'debug';
|
|
12
11
|
import { EventEmitter } from 'events';
|
|
12
|
+
import assert from 'node:assert';
|
|
13
13
|
|
|
14
14
|
import { WithTypeUrl } from '@dxos/codec-protobuf';
|
|
15
|
-
import { keyToBuffer, keyToString } from '@dxos/crypto';
|
|
16
15
|
import { Extension, ERR_EXTENSION_RESPONSE_FAILED, Protocol } from '@dxos/mesh-protocol';
|
|
16
|
+
import { PublicKey } from '@dxos/protocols';
|
|
17
17
|
|
|
18
18
|
import { wrapMessage } from '../party';
|
|
19
19
|
import { codec, Command } from '../proto';
|
|
@@ -28,7 +28,7 @@ export type GreetingCommandMessageHandler = (message: any, remotePeerId: Buffer,
|
|
|
28
28
|
|
|
29
29
|
const getPeerId = (protocol: Protocol) => {
|
|
30
30
|
const { peerId } = protocol.getSession() ?? {};
|
|
31
|
-
return
|
|
31
|
+
return PublicKey.bufferize(peerId);
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
/**
|
|
@@ -113,7 +113,7 @@ export class GreetingCommandPlugin extends EventEmitter {
|
|
|
113
113
|
async _send (peerId: PeerId, message: Command, oneway: boolean) {
|
|
114
114
|
assert(Buffer.isBuffer(peerId));
|
|
115
115
|
// `peerId` is a Buffer, but here we only need its string form.
|
|
116
|
-
const peerIdStr =
|
|
116
|
+
const peerIdStr = PublicKey.stringify(peerId);
|
|
117
117
|
const peer = this._peers.get(peerIdStr);
|
|
118
118
|
assert(peer, `Peer not connected: ${peerIdStr}`);
|
|
119
119
|
const extension = peer.getExtension(GreetingCommandPlugin.EXTENSION_NAME);
|
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
// TODO(burdon): Factor out helpers.
|
|
7
7
|
//
|
|
8
8
|
|
|
9
|
-
import assert from 'assert';
|
|
10
9
|
import stableStringify from 'json-stable-stringify';
|
|
10
|
+
import assert from 'node:assert';
|
|
11
11
|
|
|
12
|
-
import { createKeyPair, KeyPair
|
|
13
|
-
import { PublicKey, PublicKeyLike } from '@dxos/protocols';
|
|
12
|
+
import { createKeyPair, KeyPair } from '@dxos/crypto';
|
|
13
|
+
import { PublicKey, PublicKeyLike, PUBLIC_KEY_LENGTH, SECRET_KEY_LENGTH } from '@dxos/protocols';
|
|
14
14
|
|
|
15
15
|
import { KeyChain, KeyRecord, KeyType, createDateTimeString } from '../proto';
|
|
16
16
|
import { MakeOptional } from '../typedefs';
|
package/src/keys/keyring.test.ts
CHANGED
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
|
|
5
5
|
// DXOS testing browser.
|
|
6
6
|
|
|
7
|
-
import assert from 'assert';
|
|
8
7
|
import expect from 'expect';
|
|
8
|
+
import assert from 'node:assert';
|
|
9
9
|
|
|
10
|
-
import { createKeyPair,
|
|
10
|
+
import { createKeyPair, randomBytes, verify } from '@dxos/crypto';
|
|
11
11
|
import { PublicKey } from '@dxos/protocols';
|
|
12
12
|
|
|
13
13
|
import { KeyType, schema } from '../proto';
|
|
@@ -90,7 +90,7 @@ it('Add/retrieve a publicKey from an external source (without secret present)',
|
|
|
90
90
|
|
|
91
91
|
it('Retrieve a non-existent key', async () => {
|
|
92
92
|
const keyring = new Keyring();
|
|
93
|
-
const internal = keyring.findKey(Filter.matches({ key:
|
|
93
|
+
const internal = keyring.findKey(Filter.matches({ key: PublicKey.stringify(randomBytes(32)) }));
|
|
94
94
|
expect(internal).toBeUndefined();
|
|
95
95
|
});
|
|
96
96
|
|
|
@@ -194,8 +194,8 @@ it('Attempt to add a badly formatted key', async () => {
|
|
|
194
194
|
const keyring = new Keyring();
|
|
195
195
|
const good = createKeyPair();
|
|
196
196
|
const bad = {
|
|
197
|
-
publicKey:
|
|
198
|
-
secretKey:
|
|
197
|
+
publicKey: PublicKey.stringify(good.publicKey),
|
|
198
|
+
secretKey: PublicKey.stringify(good.secretKey),
|
|
199
199
|
type: KeyType.IDENTITY
|
|
200
200
|
};
|
|
201
201
|
|
package/src/keys/keyring.ts
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
// Copyright 2019 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import assert from 'assert';
|
|
6
5
|
import memdown from 'memdown';
|
|
6
|
+
import assert from 'node:assert';
|
|
7
7
|
|
|
8
8
|
import { Event } from '@dxos/async';
|
|
9
9
|
import {
|
|
10
|
-
KeyPair,
|
|
10
|
+
KeyPair, randomBytes, sign as cryptoSign, verify as cryptoVerify
|
|
11
11
|
} from '@dxos/crypto';
|
|
12
12
|
import { PublicKey, PublicKeyLike } from '@dxos/protocols';
|
|
13
13
|
import { arraysEqual } from '@dxos/util';
|
|
@@ -583,7 +583,7 @@ export class Keyring implements Signer {
|
|
|
583
583
|
item.publicKey = PublicKey.from(item.publicKey);
|
|
584
584
|
}
|
|
585
585
|
if (item.secretKey) {
|
|
586
|
-
item.secretKey =
|
|
586
|
+
item.secretKey = PublicKey.bufferize(item.secretKey);
|
|
587
587
|
}
|
|
588
588
|
|
|
589
589
|
if (item.secretKey) {
|
package/src/keys/keystore.ts
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
// Copyright 2019 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import assert from 'assert';
|
|
6
5
|
import bufferJson from 'buffer-json-encoding';
|
|
7
6
|
import debug from 'debug';
|
|
8
7
|
import encode from 'encoding-down';
|
|
9
8
|
import levelup, { LevelUp } from 'levelup';
|
|
10
9
|
import memdown from 'memdown';
|
|
10
|
+
import assert from 'node:assert';
|
|
11
11
|
import toArray from 'stream-to-array';
|
|
12
12
|
|
|
13
13
|
import { PublicKey } from '@dxos/protocols';
|
package/src/party/party-state.ts
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// Copyright 2019 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import assert from 'assert';
|
|
6
5
|
import debug from 'debug';
|
|
7
6
|
import { EventEmitter } from 'events';
|
|
7
|
+
import assert from 'node:assert';
|
|
8
8
|
|
|
9
9
|
import { discoveryKey } from '@dxos/crypto';
|
|
10
10
|
import { PublicKey, PublicKeyLike } from '@dxos/protocols';
|
|
@@ -32,7 +32,7 @@ export interface HandshakeResponse {
|
|
|
32
32
|
}
|
|
33
33
|
export interface NotarizeResponse {
|
|
34
34
|
copies?: ReturnType<(typeof substitutions)["google.protobuf.Any"]["decode"]>[];
|
|
35
|
-
|
|
35
|
+
genesisFeed?: ReturnType<(typeof substitutions)["dxos.halo.keys.PubKey"]["decode"]>;
|
|
36
36
|
}
|
|
37
37
|
export interface KeyHint {
|
|
38
38
|
publicKey?: ReturnType<(typeof substitutions)["dxos.halo.keys.PubKey"]["decode"]>;
|
package/src/proto/gen/index.ts
CHANGED
|
@@ -49,5 +49,5 @@ export interface TYPES {
|
|
|
49
49
|
}
|
|
50
50
|
export interface SERVICES {
|
|
51
51
|
}
|
|
52
|
-
export const schemaJson = JSON.parse("{\"nested\":{\"dxos\":{\"nested\":{\"credentials\":{\"nested\":{\"auth\":{\"nested\":{\"Auth\":{\"fields\":{\"partyKey\":{\"type\":\"PubKey\",\"id\":1,\"comment\":\"The publicKey of the target Party for these credentials.\"},\"deviceKey\":{\"type\":\"PubKey\",\"id\":2,\"comment\":\"The publicKey of the authenticating Device.\"},\"identityKey\":{\"type\":\"PubKey\",\"id\":3,\"comment\":\"The publicKey of the authenticating Identity.\"},\"feedKey\":{\"type\":\"PubKey\",\"id\":4,\"comment\":\"The publicKey of the authenticating Identity.\"},\"feedAdmit\":{\"type\":\"google.protobuf.Any\",\"id\":5,\"comment\":\"FeedAdmit message to the should be written to a control feed in case the `feedKey` is not admitted to the party.\"}},\"comment\":\"The payload for a SignedMessage sent during handshake for replication authentication.\"}}},\"greet\":{\"nested\":{\"BeginResponse\":{\"fields\":{\"info\":{\"keyType\":\"string\",\"type\":\"google.protobuf.Any\",\"id\":1,\"comment\":null}},\"comment\":null},\"ClaimResponse\":{\"fields\":{\"id\":{\"type\":\"bytes\",\"id\":1,\"comment\":null},\"rendezvousKey\":{\"type\":\"bytes\",\"id\":2,\"comment\":null}},\"comment\":null},\"Command\":{\"fields\":{\"command\":{\"type\":\"Type\",\"id\":1,\"comment\":null},\"secret\":{\"type\":\"bytes\",\"id\":2,\"comment\":null},\"params\":{\"rule\":\"repeated\",\"type\":\"google.protobuf.Any\",\"id\":10,\"comment\":null}},\"nested\":{\"Type\":{\"values\":{\"BEGIN\":0,\"HANDSHAKE\":1,\"NOTARIZE\":2,\"FINISH\":3,\"CLAIM\":10},\"comment\":null,\"comments\":{\"BEGIN\":null,\"HANDSHAKE\":null,\"NOTARIZE\":null,\"FINISH\":null,\"CLAIM\":null}}},\"comment\":\"A Greeter command.\"},\"HandshakeResponse\":{\"fields\":{\"nonce\":{\"type\":\"bytes\",\"id\":1,\"comment\":null},\"partyKey\":{\"type\":\"PubKey\",\"id\":2,\"comment\":null}},\"comment\":null},\"KeyHint\":{\"fields\":{\"publicKey\":{\"type\":\"PubKey\",\"id\":1,\"comment\":null},\"type\":{\"type\":\"KeyType\",\"id\":2,\"comment\":null}},\"comment\":null},\"NotarizeResponse\":{\"fields\":{\"copies\":{\"rule\":\"repeated\",\"type\":\"google.protobuf.Any\",\"id\":1,\"comment\":null},\"
|
|
52
|
+
export const schemaJson = JSON.parse("{\"nested\":{\"dxos\":{\"nested\":{\"credentials\":{\"nested\":{\"auth\":{\"nested\":{\"Auth\":{\"fields\":{\"partyKey\":{\"type\":\"PubKey\",\"id\":1,\"comment\":\"The publicKey of the target Party for these credentials.\"},\"deviceKey\":{\"type\":\"PubKey\",\"id\":2,\"comment\":\"The publicKey of the authenticating Device.\"},\"identityKey\":{\"type\":\"PubKey\",\"id\":3,\"comment\":\"The publicKey of the authenticating Identity.\"},\"feedKey\":{\"type\":\"PubKey\",\"id\":4,\"comment\":\"The publicKey of the authenticating Identity.\"},\"feedAdmit\":{\"type\":\"google.protobuf.Any\",\"id\":5,\"comment\":\"FeedAdmit message to the should be written to a control feed in case the `feedKey` is not admitted to the party.\"}},\"comment\":\"The payload for a SignedMessage sent during handshake for replication authentication.\"}}},\"greet\":{\"nested\":{\"BeginResponse\":{\"fields\":{\"info\":{\"keyType\":\"string\",\"type\":\"google.protobuf.Any\",\"id\":1,\"comment\":null}},\"comment\":null},\"ClaimResponse\":{\"fields\":{\"id\":{\"type\":\"bytes\",\"id\":1,\"comment\":null},\"rendezvousKey\":{\"type\":\"bytes\",\"id\":2,\"comment\":null}},\"comment\":null},\"Command\":{\"fields\":{\"command\":{\"type\":\"Type\",\"id\":1,\"comment\":null},\"secret\":{\"type\":\"bytes\",\"id\":2,\"comment\":null},\"params\":{\"rule\":\"repeated\",\"type\":\"google.protobuf.Any\",\"id\":10,\"comment\":null}},\"nested\":{\"Type\":{\"values\":{\"BEGIN\":0,\"HANDSHAKE\":1,\"NOTARIZE\":2,\"FINISH\":3,\"CLAIM\":10},\"comment\":null,\"comments\":{\"BEGIN\":null,\"HANDSHAKE\":null,\"NOTARIZE\":null,\"FINISH\":null,\"CLAIM\":null}}},\"comment\":\"A Greeter command.\"},\"HandshakeResponse\":{\"fields\":{\"nonce\":{\"type\":\"bytes\",\"id\":1,\"comment\":null},\"partyKey\":{\"type\":\"PubKey\",\"id\":2,\"comment\":null}},\"comment\":null},\"KeyHint\":{\"fields\":{\"publicKey\":{\"type\":\"PubKey\",\"id\":1,\"comment\":null},\"type\":{\"type\":\"KeyType\",\"id\":2,\"comment\":null}},\"comment\":null},\"NotarizeResponse\":{\"fields\":{\"copies\":{\"rule\":\"repeated\",\"type\":\"google.protobuf.Any\",\"id\":1,\"comment\":null},\"genesisFeed\":{\"type\":\"PubKey\",\"id\":3,\"comment\":null}},\"comment\":null}}},\"identity\":{\"nested\":{\"DeviceInfo\":{\"fields\":{\"publicKey\":{\"type\":\"PubKey\",\"id\":1,\"comment\":null},\"displayName\":{\"type\":\"string\",\"id\":2,\"comment\":null}},\"comment\":null},\"IdentityInfo\":{\"fields\":{\"publicKey\":{\"type\":\"PubKey\",\"id\":1,\"comment\":null},\"displayName\":{\"type\":\"string\",\"id\":2,\"comment\":null}},\"comment\":null}}},\"Message\":{\"fields\":{\"payload\":{\"rule\":\"required\",\"type\":\"google.protobuf.Any\",\"id\":1,\"comment\":null}},\"comment\":null},\"party\":{\"nested\":{\"Envelope\":{\"fields\":{\"partyKey\":{\"type\":\"PubKey\",\"id\":1,\"comment\":null},\"message\":{\"type\":\"Message\",\"id\":2,\"comment\":null}},\"comment\":null},\"FeedAdmit\":{\"fields\":{\"partyKey\":{\"type\":\"PubKey\",\"id\":1,\"comment\":null},\"feedKey\":{\"type\":\"PubKey\",\"id\":2,\"comment\":null}},\"comment\":null},\"FeedGenesis\":{\"fields\":{\"feedKey\":{\"type\":\"PubKey\",\"id\":1,\"comment\":null},\"ownerKey\":{\"type\":\"PubKey\",\"id\":2,\"comment\":null}},\"comment\":null},\"KeyAdmit\":{\"fields\":{\"partyKey\":{\"type\":\"PubKey\",\"id\":1,\"comment\":null},\"admitKey\":{\"type\":\"PubKey\",\"id\":2,\"comment\":null},\"admitKeyType\":{\"type\":\"KeyType\",\"id\":3,\"comment\":null}},\"comment\":null},\"PartyCredential\":{\"oneofs\":{\"contents\":{\"oneof\":[\"envelope\",\"partyGenesis\",\"keyAdmit\",\"feedAdmit\",\"feedGenesis\"],\"comment\":null}},\"fields\":{\"type\":{\"type\":\"Type\",\"id\":1,\"comment\":null},\"envelope\":{\"type\":\"Envelope\",\"id\":10,\"comment\":null},\"partyGenesis\":{\"type\":\"PartyGenesis\",\"id\":11,\"comment\":null},\"keyAdmit\":{\"type\":\"KeyAdmit\",\"id\":12,\"comment\":null},\"feedAdmit\":{\"type\":\"FeedAdmit\",\"id\":13,\"comment\":null},\"feedGenesis\":{\"type\":\"FeedGenesis\",\"id\":14,\"comment\":null}},\"nested\":{\"Type\":{\"values\":{\"ENVELOPE\":0,\"PARTY_GENESIS\":1,\"FEED_GENESIS\":2,\"KEY_ADMIT\":3,\"FEED_ADMIT\":4},\"comment\":null,\"comments\":{\"ENVELOPE\":null,\"PARTY_GENESIS\":null,\"FEED_GENESIS\":null,\"KEY_ADMIT\":null,\"FEED_ADMIT\":null}}},\"comment\":null},\"PartyGenesis\":{\"fields\":{\"partyKey\":{\"type\":\"PubKey\",\"id\":1,\"comment\":null},\"feedKey\":{\"type\":\"PubKey\",\"id\":2,\"comment\":null},\"admitKey\":{\"type\":\"PubKey\",\"id\":3,\"comment\":null},\"admitKeyType\":{\"type\":\"KeyType\",\"id\":4,\"comment\":null}},\"comment\":null},\"PartyInvitation\":{\"fields\":{\"id\":{\"type\":\"bytes\",\"id\":1,\"comment\":null},\"partyKey\":{\"type\":\"PubKey\",\"id\":2,\"comment\":null},\"issuerKey\":{\"type\":\"PubKey\",\"id\":3,\"comment\":null},\"inviteeKey\":{\"type\":\"PubKey\",\"id\":4,\"comment\":null}},\"comment\":null}}},\"SignedMessage\":{\"fields\":{\"signed\":{\"rule\":\"required\",\"type\":\"Signed\",\"id\":1,\"comment\":null},\"signatures\":{\"rule\":\"repeated\",\"type\":\"Signature\",\"id\":2,\"comment\":null}},\"nested\":{\"Signature\":{\"fields\":{\"key\":{\"rule\":\"required\",\"type\":\"PubKey\",\"id\":1,\"comment\":null},\"signature\":{\"rule\":\"required\",\"type\":\"bytes\",\"id\":2,\"comment\":null},\"keyChain\":{\"type\":\"KeyChain\",\"id\":3,\"comment\":null}},\"comment\":null},\"Signed\":{\"fields\":{\"created\":{\"rule\":\"required\",\"type\":\"string\",\"id\":1,\"comment\":null},\"nonce\":{\"rule\":\"required\",\"type\":\"bytes\",\"id\":2,\"comment\":null},\"payload\":{\"rule\":\"required\",\"type\":\"google.protobuf.Any\",\"id\":10,\"comment\":null}},\"comment\":null}},\"comment\":\"A generic container message used whenever messages are signed (e.g. PartyCredential)\"}}},\"halo\":{\"nested\":{\"keys\":{\"nested\":{\"KeyChain\":{\"fields\":{\"publicKey\":{\"rule\":\"required\",\"type\":\"PubKey\",\"id\":1,\"comment\":null},\"message\":{\"rule\":\"required\",\"type\":\"SignedMessage\",\"id\":2,\"comment\":null},\"parents\":{\"rule\":\"repeated\",\"type\":\"KeyChain\",\"id\":3,\"comment\":null}},\"comment\":null},\"KeyRecord\":{\"fields\":{\"type\":{\"rule\":\"required\",\"type\":\"KeyType\",\"id\":1,\"comment\":\"The `KeyType` type of the key. This is often unknown for keys from other sources.\"},\"publicKey\":{\"rule\":\"required\",\"type\":\"PubKey\",\"id\":2,\"comment\":\"The public key as a Buffer (required).\"},\"secretKey\":{\"type\":\"PrivKey\",\"id\":3,\"comment\":\"The secret key as a Buffer (this will never be visible outside the Keyring).\"},\"hint\":{\"type\":\"bool\",\"id\":4,\"comment\":\"Is this key from a Greeting \\\"hint\\\"?\"},\"own\":{\"type\":\"bool\",\"id\":5,\"comment\":\"Determines if this is our key?\\nUsually true if `secretKey` is present; may be false for \\\"inception keys\\\" such as the Party key.\"},\"trusted\":{\"type\":\"bool\",\"id\":6,\"comment\":\"Is this key to be trusted?\"},\"added\":{\"type\":\"string\",\"id\":7,\"comment\":\"An RFC-3339 date/time string for when the key was added to the Keyring.\"},\"created\":{\"type\":\"string\",\"id\":8,\"comment\":\"An RFC-3339 date/time string for when the key was created.\"}},\"comment\":null},\"KeyRecordList\":{\"fields\":{\"keys\":{\"rule\":\"repeated\",\"type\":\"KeyRecord\",\"id\":1,\"comment\":null}},\"comment\":null},\"KeyType\":{\"values\":{\"UNKNOWN\":0,\"IDENTITY\":1,\"DEVICE\":2,\"PARTY\":3,\"FEED\":4,\"DXNS_ADDRESS\":5},\"comment\":null,\"comments\":{\"UNKNOWN\":null,\"IDENTITY\":null,\"DEVICE\":null,\"PARTY\":null,\"FEED\":null,\"DXNS_ADDRESS\":null}},\"PrivKey\":{\"fields\":{\"data\":{\"type\":\"bytes\",\"id\":1,\"comment\":null}},\"comment\":null},\"PubKey\":{\"fields\":{\"data\":{\"type\":\"bytes\",\"id\":1,\"comment\":null}},\"comment\":null}}}}}}},\"google\":{\"nested\":{\"protobuf\":{\"nested\":{\"Any\":{\"fields\":{\"type_url\":{\"type\":\"string\",\"id\":1},\"value\":{\"type\":\"bytes\",\"id\":2}},\"comment\":null},\"BoolValue\":{\"fields\":{\"value\":{\"type\":\"bool\",\"id\":1}},\"comment\":null},\"BytesValue\":{\"fields\":{\"value\":{\"type\":\"bytes\",\"id\":1}},\"comment\":null},\"DoubleValue\":{\"fields\":{\"value\":{\"type\":\"double\",\"id\":1}},\"comment\":null},\"FloatValue\":{\"fields\":{\"value\":{\"type\":\"float\",\"id\":1}},\"comment\":null},\"Int32Value\":{\"fields\":{\"value\":{\"type\":\"int32\",\"id\":1}},\"comment\":null},\"Int64Value\":{\"fields\":{\"value\":{\"type\":\"int64\",\"id\":1}},\"comment\":null},\"StringValue\":{\"fields\":{\"value\":{\"type\":\"string\",\"id\":1}},\"comment\":null},\"UInt32Value\":{\"fields\":{\"value\":{\"type\":\"uint32\",\"id\":1}},\"comment\":null},\"UInt64Value\":{\"fields\":{\"value\":{\"type\":\"uint64\",\"id\":1}},\"comment\":null}}}}}}}");
|
|
53
53
|
export const schema = Schema.fromJson<TYPES, SERVICES>(schemaJson, substitutions);
|