@dxos/echo-db 2.33.8-dev.c77ba621 → 2.33.9-dev.2637427f
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/result-set.js +4 -4
- package/dist/src/api/result-set.js.map +1 -1
- package/dist/src/echo.js +2 -2
- package/dist/src/echo.js.map +1 -1
- package/dist/src/echo.test.js +17 -17
- package/dist/src/echo.test.js.map +1 -1
- package/dist/src/halo/halo-factory.d.ts +1 -1
- package/dist/src/halo/halo-factory.d.ts.map +1 -1
- package/dist/src/halo/halo-factory.js +17 -17
- package/dist/src/halo/halo-factory.js.map +1 -1
- package/dist/src/halo/halo-party.d.ts +4 -6
- package/dist/src/halo/halo-party.d.ts.map +1 -1
- package/dist/src/halo/halo-party.js +12 -6
- package/dist/src/halo/halo-party.js.map +1 -1
- package/dist/src/halo/halo.d.ts.map +1 -1
- package/dist/src/halo/halo.js +11 -10
- package/dist/src/halo/halo.js.map +1 -1
- package/dist/src/halo/halo.test.js +2 -3
- package/dist/src/halo/halo.test.js.map +1 -1
- package/dist/src/halo/identity-manager.d.ts.map +1 -1
- package/dist/src/halo/identity-manager.js +13 -7
- package/dist/src/halo/identity-manager.js.map +1 -1
- package/dist/src/halo/identity.js +2 -2
- package/dist/src/halo/identity.js.map +1 -1
- package/dist/src/halo/party-opener.d.ts.map +1 -1
- package/dist/src/halo/party-opener.js +2 -4
- package/dist/src/halo/party-opener.js.map +1 -1
- package/dist/src/halo/preferences.d.ts.map +1 -1
- package/dist/src/halo/preferences.js +9 -12
- package/dist/src/halo/preferences.js.map +1 -1
- package/dist/src/halo/types.d.ts +1 -0
- package/dist/src/halo/types.d.ts.map +1 -1
- package/dist/src/invitations/greeting-initiator.d.ts +5 -4
- package/dist/src/invitations/greeting-initiator.d.ts.map +1 -1
- package/dist/src/invitations/greeting-initiator.js +9 -10
- package/dist/src/invitations/greeting-initiator.js.map +1 -1
- package/dist/src/invitations/greeting-protocol-provider.js +2 -2
- package/dist/src/invitations/greeting-protocol-provider.js.map +1 -1
- package/dist/src/invitations/greeting-responder.d.ts +4 -7
- package/dist/src/invitations/greeting-responder.d.ts.map +1 -1
- package/dist/src/invitations/greeting-responder.js +12 -26
- package/dist/src/invitations/greeting-responder.js.map +1 -1
- package/dist/src/invitations/halo-recovery-initiator.js +8 -8
- package/dist/src/invitations/halo-recovery-initiator.js.map +1 -1
- package/dist/src/invitations/invitation-descriptor.js +12 -12
- package/dist/src/invitations/invitation-descriptor.js.map +1 -1
- package/dist/src/invitations/invitation-factory.d.ts +2 -1
- package/dist/src/invitations/invitation-factory.d.ts.map +1 -1
- package/dist/src/invitations/invitation-factory.js +6 -8
- package/dist/src/invitations/invitation-factory.js.map +1 -1
- package/dist/src/invitations/offline-invitation-claimer.js +9 -9
- package/dist/src/invitations/offline-invitation-claimer.js.map +1 -1
- package/dist/src/packlets/database/data-mirror.js +8 -8
- package/dist/src/packlets/database/data-mirror.js.map +1 -1
- package/dist/src/packlets/database/data-mirror.test.js +1 -1
- package/dist/src/packlets/database/data-mirror.test.js.map +1 -1
- package/dist/src/packlets/database/data-service-host.js +3 -3
- package/dist/src/packlets/database/data-service-host.js.map +1 -1
- package/dist/src/packlets/database/data-service-router.js +5 -5
- package/dist/src/packlets/database/data-service-router.js.map +1 -1
- package/dist/src/packlets/database/database-backend.js +3 -3
- package/dist/src/packlets/database/database-backend.js.map +1 -1
- package/dist/src/packlets/database/database.js +2 -2
- package/dist/src/packlets/database/database.js.map +1 -1
- package/dist/src/packlets/database/item-demuxer.js +14 -14
- package/dist/src/packlets/database/item-demuxer.js.map +1 -1
- package/dist/src/packlets/database/item-demuxer.test.js +1 -1
- package/dist/src/packlets/database/item-demuxer.test.js.map +1 -1
- package/dist/src/packlets/database/item-manager.js +18 -18
- package/dist/src/packlets/database/item-manager.js.map +1 -1
- package/dist/src/packlets/database/link.js +3 -3
- package/dist/src/packlets/database/link.js.map +1 -1
- package/dist/src/packlets/database/selection/result.js +2 -2
- package/dist/src/packlets/database/selection/result.js.map +1 -1
- package/dist/src/packlets/database/testing.js +1 -1
- package/dist/src/packlets/database/testing.js.map +1 -1
- package/dist/src/packlets/database/timeframe-clock.d.ts +2 -1
- package/dist/src/packlets/database/timeframe-clock.d.ts.map +1 -1
- package/dist/src/packlets/database/timeframe-clock.js +15 -5
- package/dist/src/packlets/database/timeframe-clock.js.map +1 -1
- package/dist/src/parties/data-party.d.ts +4 -3
- package/dist/src/parties/data-party.d.ts.map +1 -1
- package/dist/src/parties/data-party.js +18 -14
- package/dist/src/parties/data-party.js.map +1 -1
- package/dist/src/parties/data-party.test.js +12 -12
- package/dist/src/parties/data-party.test.js.map +1 -1
- package/dist/src/parties/party-factory.d.ts +2 -4
- package/dist/src/parties/party-factory.d.ts.map +1 -1
- package/dist/src/parties/party-factory.js +18 -15
- package/dist/src/parties/party-factory.js.map +1 -1
- package/dist/src/parties/party-manager.d.ts +1 -1
- package/dist/src/parties/party-manager.d.ts.map +1 -1
- package/dist/src/parties/party-manager.js +19 -19
- package/dist/src/parties/party-manager.js.map +1 -1
- package/dist/src/parties/party-manager.test.js +22 -18
- package/dist/src/parties/party-manager.test.js.map +1 -1
- package/dist/src/parties/party-preferences.js +2 -2
- package/dist/src/parties/party-preferences.js.map +1 -1
- package/dist/src/pipeline/feed-muxer.d.ts.map +1 -1
- package/dist/src/pipeline/feed-muxer.js +5 -5
- package/dist/src/pipeline/feed-muxer.js.map +1 -1
- package/dist/src/pipeline/feed-muxer.test.js +2 -2
- package/dist/src/pipeline/feed-muxer.test.js.map +1 -1
- package/dist/src/pipeline/message-selector.d.ts +1 -2
- package/dist/src/pipeline/message-selector.d.ts.map +1 -1
- package/dist/src/pipeline/message-selector.js +6 -33
- package/dist/src/pipeline/message-selector.js.map +1 -1
- package/dist/src/pipeline/metadata-store.d.ts +7 -2
- package/dist/src/pipeline/metadata-store.d.ts.map +1 -1
- package/dist/src/pipeline/metadata-store.js +12 -3
- package/dist/src/pipeline/metadata-store.js.map +1 -1
- package/dist/src/pipeline/party-feed-provider.d.ts +2 -2
- package/dist/src/pipeline/party-feed-provider.d.ts.map +1 -1
- package/dist/src/pipeline/party-feed-provider.js +5 -4
- package/dist/src/pipeline/party-feed-provider.js.map +1 -1
- package/dist/src/pipeline/party-pipeline.d.ts +5 -5
- package/dist/src/pipeline/party-pipeline.d.ts.map +1 -1
- package/dist/src/pipeline/party-pipeline.js +19 -20
- package/dist/src/pipeline/party-pipeline.js.map +1 -1
- package/dist/src/pipeline/party-pipeline.test.js +13 -18
- package/dist/src/pipeline/party-pipeline.test.js.map +1 -1
- package/dist/src/pipeline/party-processor.js +3 -3
- package/dist/src/pipeline/party-processor.js.map +1 -1
- package/dist/src/protocol/authenticator.test.js +53 -12
- package/dist/src/protocol/authenticator.test.js.map +1 -1
- package/dist/src/protocol/identity-credentials.d.ts.map +1 -1
- package/dist/src/protocol/identity-credentials.js +2 -2
- package/dist/src/protocol/identity-credentials.js.map +1 -1
- package/dist/src/protocol/party-protocol-factory.js +1 -1
- package/dist/src/protocol/party-protocol-factory.js.map +1 -1
- package/dist/src/protocol/replicator-plugin.d.ts.map +1 -1
- package/dist/src/protocol/replicator-plugin.js +1 -2
- package/dist/src/protocol/replicator-plugin.js.map +1 -1
- package/dist/src/snapshots/snapshot-generator.js +2 -2
- package/dist/src/snapshots/snapshot-generator.js.map +1 -1
- package/dist/src/snapshots/snapshot-store.d.ts.map +1 -1
- package/dist/src/snapshots/snapshot-store.js +4 -4
- package/dist/src/snapshots/snapshot-store.js.map +1 -1
- package/dist/src/testing/testing-factories.js +2 -2
- package/dist/src/testing/testing-factories.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +24 -20
- package/src/api/result-set.ts +1 -1
- package/src/echo.test.ts +6 -4
- package/src/echo.ts +1 -1
- package/src/halo/halo-factory.ts +9 -9
- package/src/halo/halo-party.ts +15 -7
- package/src/halo/halo.test.ts +3 -2
- package/src/halo/halo.ts +4 -2
- package/src/halo/identity-manager.ts +12 -3
- package/src/halo/identity.ts +1 -1
- package/src/halo/party-opener.ts +2 -4
- package/src/halo/preferences.ts +5 -9
- package/src/halo/types.ts +1 -0
- package/src/invitations/greeting-initiator.ts +11 -6
- package/src/invitations/greeting-protocol-provider.ts +2 -2
- package/src/invitations/greeting-responder.ts +12 -31
- package/src/invitations/halo-recovery-initiator.ts +4 -4
- package/src/invitations/invitation-descriptor.ts +6 -6
- package/src/invitations/invitation-factory.ts +3 -3
- package/src/invitations/offline-invitation-claimer.ts +4 -4
- package/src/packlets/database/data-mirror.test.ts +2 -2
- package/src/packlets/database/data-mirror.ts +1 -1
- package/src/packlets/database/data-service-host.ts +1 -1
- package/src/packlets/database/data-service-router.ts +1 -1
- package/src/packlets/database/database-backend.ts +1 -1
- package/src/packlets/database/database.ts +1 -1
- package/src/packlets/database/item-demuxer.test.ts +2 -2
- package/src/packlets/database/item-demuxer.ts +1 -1
- package/src/packlets/database/item-manager.ts +1 -1
- package/src/packlets/database/link.ts +1 -1
- package/src/packlets/database/selection/result.ts +1 -1
- package/src/packlets/database/testing.ts +2 -2
- package/src/packlets/database/timeframe-clock.ts +4 -1
- package/src/parties/data-party.test.ts +12 -12
- package/src/parties/data-party.ts +15 -7
- package/src/parties/party-factory.ts +21 -13
- package/src/parties/party-manager.test.ts +13 -9
- package/src/parties/party-manager.ts +15 -13
- package/src/parties/party-preferences.ts +1 -1
- package/src/pipeline/feed-muxer.test.ts +2 -2
- package/src/pipeline/feed-muxer.ts +5 -5
- package/src/pipeline/message-selector.ts +5 -36
- package/src/pipeline/metadata-store.ts +16 -3
- package/src/pipeline/party-feed-provider.ts +3 -3
- package/src/pipeline/party-pipeline.test.ts +13 -19
- package/src/pipeline/party-pipeline.ts +14 -13
- package/src/pipeline/party-processor.ts +1 -1
- package/src/protocol/authenticator.test.ts +102 -17
- package/src/protocol/identity-credentials.ts +5 -2
- package/src/protocol/party-protocol-factory.ts +2 -2
- package/src/protocol/replicator-plugin.ts +1 -2
- package/src/snapshots/snapshot-generator.ts +1 -1
- package/src/snapshots/snapshot-store.ts +3 -3
- package/src/testing/testing-factories.ts +1 -1
|
@@ -7,11 +7,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
7
7
|
};
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.createDataPartyAdmissionMessages = exports.createHaloPartyAdmissionMessage = exports.GreetingInitiator = void 0;
|
|
10
|
-
const assert_1 = __importDefault(require("assert"));
|
|
11
10
|
const debug_1 = __importDefault(require("debug"));
|
|
11
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
12
12
|
const async_1 = require("@dxos/async");
|
|
13
13
|
const credentials_1 = require("@dxos/credentials");
|
|
14
|
-
const crypto_1 = require("@dxos/crypto");
|
|
15
14
|
const network_manager_1 = require("@dxos/network-manager");
|
|
16
15
|
const protocols_1 = require("@dxos/protocols");
|
|
17
16
|
const greeting_protocol_provider_1 = require("./greeting-protocol-provider");
|
|
@@ -36,7 +35,7 @@ class GreetingInitiator {
|
|
|
36
35
|
this._getMessagesToNotarize = _getMessagesToNotarize;
|
|
37
36
|
// TODO(dboreham): Can we use the same states as the responder?
|
|
38
37
|
this._state = greeting_responder_1.GreetingState.INITIALIZED;
|
|
39
|
-
(0,
|
|
38
|
+
(0, node_assert_1.default)(invitation_descriptor_1.InvitationDescriptorType.INTERACTIVE === this._invitationDescriptor.type);
|
|
40
39
|
}
|
|
41
40
|
get state() {
|
|
42
41
|
return this._state;
|
|
@@ -46,7 +45,7 @@ class GreetingInitiator {
|
|
|
46
45
|
* @param {number} timeout Connection timeout (ms).
|
|
47
46
|
*/
|
|
48
47
|
async connect(timeout = DEFAULT_TIMEOUT) {
|
|
49
|
-
(0,
|
|
48
|
+
(0, node_assert_1.default)(this._state === greeting_responder_1.GreetingState.INITIALIZED);
|
|
50
49
|
// TODO(telackey): Clarify what the following comment means.
|
|
51
50
|
// TODO(telackey): We don't have the descriptor yet, but it must include at least this.
|
|
52
51
|
const { swarmKey, invitation } = this._invitationDescriptor;
|
|
@@ -62,9 +61,9 @@ class GreetingInitiator {
|
|
|
62
61
|
// Therefore at present the greeter discovers the invitation id from session metadata, via the invitee's peer id.
|
|
63
62
|
// TODO(dboreham): Invitation is actually invitationID.
|
|
64
63
|
const localPeerId = invitation;
|
|
65
|
-
log('Local PeerId:',
|
|
64
|
+
log('Local PeerId:', protocols_1.PublicKey.stringify(localPeerId));
|
|
66
65
|
this._greeterPlugin = new credentials_1.GreetingCommandPlugin(Buffer.from(localPeerId), new credentials_1.Greeter().createMessageHandler());
|
|
67
|
-
log(
|
|
66
|
+
log(protocols_1.PublicKey.stringify(localPeerId), 'connecting to', protocols_1.PublicKey.stringify(swarmKey));
|
|
68
67
|
const peerJoinedWaiter = (0, async_1.waitForEvent)(this._greeterPlugin, 'peer:joined', (remotePeerId) => remotePeerId && Buffer.from(responderPeerId).equals(remotePeerId), timeout, credentials_1.ERR_GREET_CONNECTED_TO_SWARM_TIMEOUT);
|
|
69
68
|
await this._networkManager.joinProtocolSwarm({
|
|
70
69
|
topic: protocols_1.PublicKey.from(swarmKey),
|
|
@@ -81,15 +80,14 @@ class GreetingInitiator {
|
|
|
81
80
|
* Called after connecting to initiate greeting protocol exchange.
|
|
82
81
|
*/
|
|
83
82
|
async redeemInvitation(secretProvider) {
|
|
84
|
-
|
|
85
|
-
(0, assert_1.default)(this._state === greeting_responder_1.GreetingState.CONNECTED);
|
|
83
|
+
(0, node_assert_1.default)(this._state === greeting_responder_1.GreetingState.CONNECTED);
|
|
86
84
|
const { swarmKey } = this._invitationDescriptor;
|
|
87
85
|
const responderPeerId = Buffer.from(swarmKey);
|
|
88
86
|
/* The first step in redeeming the Invitation is the BEGIN command.
|
|
89
87
|
* On the Greeter end, this is when it takes action (eg, generating a passcode)
|
|
90
88
|
* starting the redemption of the Invitation.
|
|
91
89
|
*/
|
|
92
|
-
(0,
|
|
90
|
+
(0, node_assert_1.default)(this._greeterPlugin); // Needed because typechecker complains that `_greeterPlugin` can possibly be undefined.
|
|
93
91
|
const { info } = await this._greeterPlugin.send(responderPeerId, (0, credentials_1.createGreetingBeginMessage)());
|
|
94
92
|
/* The next step is the HANDSHAKE command, which allow us to exchange additional
|
|
95
93
|
* details with the Greeter. This step requires authentication, so we must obtain
|
|
@@ -124,9 +122,10 @@ class GreetingInitiator {
|
|
|
124
122
|
}
|
|
125
123
|
await this.disconnect();
|
|
126
124
|
this._state = greeting_responder_1.GreetingState.SUCCEEDED;
|
|
125
|
+
(0, node_assert_1.default)(notarizeResponse.genesisFeed);
|
|
127
126
|
return {
|
|
128
127
|
partyKey,
|
|
129
|
-
|
|
128
|
+
genesisFeedKey: notarizeResponse.genesisFeed
|
|
130
129
|
};
|
|
131
130
|
}
|
|
132
131
|
async disconnect() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"greeting-initiator.js","sourceRoot":"","sources":["../../../src/invitations/greeting-initiator.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;;AAEF,
|
|
1
|
+
{"version":3,"file":"greeting-initiator.js","sourceRoot":"","sources":["../../../src/invitations/greeting-initiator.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;;AAEF,kDAA0B;AAC1B,8DAAiC;AAEjC,uCAA2C;AAC3C,mDAgB2B;AAC3B,2DAA+E;AAC/E,+CAA4C;AAG5C,6EAAwE;AACxE,6DAAqD;AACrD,mEAAyF;AAEzF,MAAM,GAAG,GAAG,IAAA,eAAK,EAAC,iCAAiC,CAAC,CAAC;AAErD,MAAM,eAAe,GAAG,KAAM,CAAC;AAO/B;;;GAGG;AACH,MAAa,iBAAiB;IAM5B;;;;;OAKG;IACH,YACmB,eAA+B,EAC/B,qBAA2C,EAC3C,sBAAsF;QAFtF,oBAAe,GAAf,eAAe,CAAgB;QAC/B,0BAAqB,GAArB,qBAAqB,CAAsB;QAC3C,2BAAsB,GAAtB,sBAAsB,C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AC;IAC3C,CAAC;IAED,KAAK,CAAC,OAAO;QACX,MAAM,IAAI,CAAC,UAAU,EAAE,CAAC;QACxB,IAAI,CAAC,cAAc,GAAG,SAAS,CAAC;QAChC,IAAI,CAAC,MAAM,GAAG,kCAAa,CAAC,SAAS,CAAC;QACtC,GAAG,CAAC,WAAW,CAAC,CAAC;IACnB,CAAC;CACF;AAtJD,8CAsJC;AAED;;GAEG;AACI,MAAM,+BAA+B,GAAG,CAC7C,iBAAoC,EACpC,KAAiB,EACR,EAAE,CAAC,IAAA,mCAAqB,EACjC,iBAAiB,CAAC,MAAM,EACxB,iBAAiB,CAAC,cAAc,EAAE,CAAC,SAAS,EAC5C,iBAAiB,CAAC,YAAY,EAAE,EAChC,EAAE,EACF,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CACnB,CAAC;AATW,QAAA,+BAA+B,mCAS1C;AAEF;;GAEG;AACI,MAAM,gCAAgC,GAAG,CAC9C,iBAAoC,EACpC,QAAmB,EACnB,eAA8B,EAC9B,KAAiB,EACR,EAAE,CAAC,IAAA,mCAAqB,EACjC,iBAAiB,CAAC,MAAM,EACxB,QAAQ,EACR,IAAA,yBAAW,EAAC,eAAe,CAAC,EAC5B,CAAC,iBAAiB,CAAC,oBAAoB,EAAE,CAAC,EAC1C,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CACnB,CAAC;AAXW,QAAA,gCAAgC,oCAW3C"}
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
//
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.greetingProtocolProvider = void 0;
|
|
7
|
-
const crypto_1 = require("@dxos/crypto");
|
|
8
7
|
const network_manager_1 = require("@dxos/network-manager");
|
|
8
|
+
const protocols_1 = require("@dxos/protocols");
|
|
9
9
|
/**
|
|
10
10
|
* Creates a duplex connection with a single peer using a common rendezvous key as topic.
|
|
11
11
|
* @param peerId
|
|
@@ -17,7 +17,7 @@ const network_manager_1 = require("@dxos/network-manager");
|
|
|
17
17
|
// TODO(dboreham): Write a test to check resources are released (no resource leaks).
|
|
18
18
|
const greetingProtocolProvider = (rendezvousKey, peerId, protocolPlugins) => (0, network_manager_1.protocolFactory)({
|
|
19
19
|
getTopics: () => [rendezvousKey],
|
|
20
|
-
session: { peerId:
|
|
20
|
+
session: { peerId: protocols_1.PublicKey.stringify(peerId) },
|
|
21
21
|
plugins: protocolPlugins
|
|
22
22
|
});
|
|
23
23
|
exports.greetingProtocolProvider = greetingProtocolProvider;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"greeting-protocol-provider.js","sourceRoot":"","sources":["../../../src/invitations/greeting-protocol-provider.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;AAEF,
|
|
1
|
+
{"version":3,"file":"greeting-protocol-provider.js","sourceRoot":"","sources":["../../../src/invitations/greeting-protocol-provider.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;AAEF,2DAAwD;AACxD,+CAA4C;AAE5C;;;;;;GAMG;AACH,6BAA6B;AAC7B,oFAAoF;AAC7E,MAAM,wBAAwB,GAAG,CAAC,aAAkB,EAAE,MAA2B,EAAE,eAAsB,EAAE,EAAE,CAAC,IAAA,iCAAe,EAAC;IACnI,SAAS,EAAE,GAAG,EAAE,CAAC,CAAC,aAAa,CAAC;IAChC,OAAO,EAAE,EAAE,MAAM,EAAE,qBAAS,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE;IAChD,OAAO,EAAE,eAAe;CACzB,CAAC,CAAC;AAJU,QAAA,wBAAwB,4BAIlC"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Event } from '@dxos/async';
|
|
3
|
-
import {
|
|
3
|
+
import { SecretProvider, SecretValidator, Message as HaloMessage } from '@dxos/credentials';
|
|
4
4
|
import { FeedWriter } from '@dxos/echo-protocol';
|
|
5
5
|
import { NetworkManager } from '@dxos/network-manager';
|
|
6
|
+
import { PublicKey } from '@dxos/protocols';
|
|
6
7
|
import { PartyStateProvider } from '../pipeline';
|
|
7
8
|
import { CredentialsSigner } from '../protocol/credentials-signer';
|
|
8
9
|
import { InvitationOptions } from './common';
|
|
@@ -25,6 +26,7 @@ export declare enum GreetingState {
|
|
|
25
26
|
export declare class GreetingResponder {
|
|
26
27
|
private readonly _networkManager;
|
|
27
28
|
private readonly _partyProcessor;
|
|
29
|
+
private readonly _genesisFeedKey;
|
|
28
30
|
private readonly _credentialsSigner;
|
|
29
31
|
private readonly _credentialsWriter;
|
|
30
32
|
private readonly _greeterPlugin;
|
|
@@ -35,7 +37,7 @@ export declare class GreetingResponder {
|
|
|
35
37
|
* Param: Invitation id
|
|
36
38
|
*/
|
|
37
39
|
readonly connected: Event<any>;
|
|
38
|
-
constructor(_networkManager: NetworkManager, _partyProcessor: PartyStateProvider, _credentialsSigner: CredentialsSigner, _credentialsWriter: FeedWriter<HaloMessage>);
|
|
40
|
+
constructor(_networkManager: NetworkManager, _partyProcessor: PartyStateProvider, _genesisFeedKey: PublicKey, _credentialsSigner: CredentialsSigner, _credentialsWriter: FeedWriter<HaloMessage>);
|
|
39
41
|
/**
|
|
40
42
|
* Accessor for UI to display status to the user.
|
|
41
43
|
* Return the current state for this Greeting Responder (waiting, peer connected, successful auth, auth failed, etc.)
|
|
@@ -69,10 +71,5 @@ export declare class GreetingResponder {
|
|
|
69
71
|
* @private
|
|
70
72
|
*/
|
|
71
73
|
_writeCredentialsToParty(messages: any[]): Promise<HaloMessage[]>;
|
|
72
|
-
/**
|
|
73
|
-
* Callback to gather member key and feed "hints" for the Invitee.
|
|
74
|
-
* @private
|
|
75
|
-
*/
|
|
76
|
-
_gatherHints(): KeyHint[];
|
|
77
74
|
}
|
|
78
75
|
//# sourceMappingURL=greeting-responder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"greeting-responder.d.ts","sourceRoot":"","sources":["../../../src/invitations/greeting-responder.ts"],"names":[],"mappings":";AAOA,OAAO,EAAE,KAAK,EAAoB,MAAM,aAAa,CAAC;AACtD,OAAO,
|
|
1
|
+
{"version":3,"file":"greeting-responder.d.ts","sourceRoot":"","sources":["../../../src/invitations/greeting-responder.ts"],"names":[],"mappings":";AAOA,OAAO,EAAE,KAAK,EAAoB,MAAM,aAAa,CAAC;AACtD,OAAO,EAKL,cAAc,EACd,eAAe,EACf,OAAO,IAAI,WAAW,EACvB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,UAAU,EAAY,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAA0B,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC/E,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAK7C;;GAEG;AACH,oBAAY,aAAa;IACvB,WAAW,gBAAgB;IAC3B,SAAS,cAAc;IACvB,SAAS,cAAc;IACvB,SAAS,cAAc;IACvB,OAAO,YAAY;IACnB,SAAS,cAAc;IACvB,YAAY,iBAAiB;CAC9B;AAED;;;GAGG;AACH,qBAAa,iBAAiB;IAa1B,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,kBAAkB;IACnC,OAAO,CAAC,QAAQ,CAAC,kBAAkB;IAhBrC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAwB;IACvD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA2B;IACrD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAU;IAEnC,OAAO,CAAC,MAAM,CAA4C;IAE1D;;OAEG;IACH,QAAQ,CAAC,SAAS,aAAoB;gBAGnB,eAAe,EAAE,cAAc,EAC/B,eAAe,EAAE,kBAAkB,EACnC,eAAe,EAAE,SAAS,EAC1B,kBAAkB,EAAE,iBAAiB,EACrC,kBAAkB,EAAE,UAAU,CAAC,WAAW,CAAC;IAW9D;;;;OAIG;IACH,IAAI,KAAK,kBAER;IAED;;;;;;OAMG;IAEG,MAAM,CACV,eAAe,EAAE,eAAe,EAChC,cAAc,CAAC,EAAE,cAAc,EAC/B,QAAQ,CAAC,EAAE,iBAAiB,CAAC,UAAU,CAAC,EACxC,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,MAAM,CAAC;IA+ClB;;OAEG;IACG,KAAK;IAqBX;;OAEG;IACG,IAAI;IAUV;;OAEG;IACG,OAAO;IAOb;;;;;OAKG;IACG,wBAAwB,CAAE,QAAQ,EAAE,GAAG,EAAE;CA6ChD"}
|
|
@@ -7,8 +7,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
7
7
|
};
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.GreetingResponder = exports.GreetingState = void 0;
|
|
10
|
-
const assert_1 = __importDefault(require("assert"));
|
|
11
10
|
const debug_1 = __importDefault(require("debug"));
|
|
11
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
12
12
|
const async_1 = require("@dxos/async");
|
|
13
13
|
const credentials_1 = require("@dxos/credentials");
|
|
14
14
|
const crypto_1 = require("@dxos/crypto");
|
|
@@ -34,9 +34,10 @@ var GreetingState;
|
|
|
34
34
|
* Upon successful greeting, the peer is admitted into the Party specified in the invitation descriptor.
|
|
35
35
|
*/
|
|
36
36
|
class GreetingResponder {
|
|
37
|
-
constructor(_networkManager, _partyProcessor, _credentialsSigner, _credentialsWriter) {
|
|
37
|
+
constructor(_networkManager, _partyProcessor, _genesisFeedKey, _credentialsSigner, _credentialsWriter) {
|
|
38
38
|
this._networkManager = _networkManager;
|
|
39
39
|
this._partyProcessor = _partyProcessor;
|
|
40
|
+
this._genesisFeedKey = _genesisFeedKey;
|
|
40
41
|
this._credentialsSigner = _credentialsSigner;
|
|
41
42
|
this._credentialsWriter = _credentialsWriter;
|
|
42
43
|
this._swarmKey = (0, crypto_1.randomBytes)();
|
|
@@ -45,7 +46,7 @@ class GreetingResponder {
|
|
|
45
46
|
* Param: Invitation id
|
|
46
47
|
*/
|
|
47
48
|
this.connected = new async_1.Event();
|
|
48
|
-
this._greeter = new credentials_1.Greeter(this._partyProcessor.partyKey,
|
|
49
|
+
this._greeter = new credentials_1.Greeter(this._partyProcessor.partyKey, this._genesisFeedKey, async (messages) => this._writeCredentialsToParty(messages));
|
|
49
50
|
this._greeterPlugin = new credentials_1.GreetingCommandPlugin(Buffer.from(this._swarmKey), this._greeter.createMessageHandler());
|
|
50
51
|
}
|
|
51
52
|
/**
|
|
@@ -65,8 +66,8 @@ class GreetingResponder {
|
|
|
65
66
|
*/
|
|
66
67
|
// TODO(burdon): Rename listenForXXX?
|
|
67
68
|
async invite(secretValidator, secretProvider, onFinish, expiration) {
|
|
68
|
-
(0,
|
|
69
|
-
(0,
|
|
69
|
+
(0, node_assert_1.default)(secretValidator);
|
|
70
|
+
(0, node_assert_1.default)(this._state === GreetingState.LISTENING);
|
|
70
71
|
let timeout;
|
|
71
72
|
const cleanup = async (expired) => {
|
|
72
73
|
if (timeout) {
|
|
@@ -89,12 +90,12 @@ class GreetingResponder {
|
|
|
89
90
|
// TODO(dboreham): Add tests for idempotence and transactional integrity over the greet flow.
|
|
90
91
|
this._greeterPlugin.once('peer:joined', (joinedPeerId) => {
|
|
91
92
|
if (joinedPeerId.equals(invitation.id)) {
|
|
92
|
-
log(`Initiator connected: ${
|
|
93
|
+
log(`Initiator connected: ${protocols_1.PublicKey.stringify(joinedPeerId)}`);
|
|
93
94
|
this._state = GreetingState.CONNECTED;
|
|
94
95
|
this.connected.emit(invitation.id);
|
|
95
96
|
}
|
|
96
97
|
else {
|
|
97
|
-
log(`Unexpected initiator connected: ${
|
|
98
|
+
log(`Unexpected initiator connected: ${protocols_1.PublicKey.stringify(joinedPeerId)}`);
|
|
98
99
|
}
|
|
99
100
|
});
|
|
100
101
|
return invitation.id;
|
|
@@ -104,7 +105,7 @@ class GreetingResponder {
|
|
|
104
105
|
*/
|
|
105
106
|
async start() {
|
|
106
107
|
log('Starting...');
|
|
107
|
-
(0,
|
|
108
|
+
(0, node_assert_1.default)(this._state === GreetingState.INITIALIZED);
|
|
108
109
|
// As the Greeter, use the topic as our peerId.
|
|
109
110
|
// (For reasons why see detailed comment on greetClient).
|
|
110
111
|
await this._networkManager.joinProtocolSwarm({
|
|
@@ -114,7 +115,7 @@ class GreetingResponder {
|
|
|
114
115
|
topology: new network_manager_1.FullyConnectedTopology(),
|
|
115
116
|
label: 'Greeting responder'
|
|
116
117
|
});
|
|
117
|
-
log(`Greeting for: ${this._partyProcessor.partyKey.toHex()} on swarmKey ${
|
|
118
|
+
log(`Greeting for: ${this._partyProcessor.partyKey.toHex()} on swarmKey ${protocols_1.PublicKey.stringify(this._swarmKey)}`);
|
|
118
119
|
this._state = GreetingState.LISTENING;
|
|
119
120
|
log('Listening');
|
|
120
121
|
return this._swarmKey;
|
|
@@ -146,7 +147,7 @@ class GreetingResponder {
|
|
|
146
147
|
* @private
|
|
147
148
|
*/
|
|
148
149
|
async _writeCredentialsToParty(messages) {
|
|
149
|
-
(0,
|
|
150
|
+
(0, node_assert_1.default)(this._state === GreetingState.CONNECTED);
|
|
150
151
|
/* These messages will be self-signed by keys not yet admitted to the Party,, so we cannot check
|
|
151
152
|
* for a trusted key, only that the signatures are valid.
|
|
152
153
|
*/
|
|
@@ -159,6 +160,7 @@ class GreetingResponder {
|
|
|
159
160
|
// Place the self-signed messages inside an Envelope, sign then write the signed Envelope to the Party.
|
|
160
161
|
const envelopes = [];
|
|
161
162
|
for (const message of messages) {
|
|
163
|
+
// TODO(dmaretskyi): Refactor to pass in a callback: `await admitKeys(messages)`.
|
|
162
164
|
const admittedKeys = (0, credentials_1.admitsKeys)(message);
|
|
163
165
|
// TODO(telackey): Add hasKey/isMember to PartyProcessor?
|
|
164
166
|
const hasKey = (key) => {
|
|
@@ -176,22 +178,6 @@ class GreetingResponder {
|
|
|
176
178
|
// Return the signed messages to the caller because copies are sent back to the invitee.
|
|
177
179
|
return envelopes;
|
|
178
180
|
}
|
|
179
|
-
/**
|
|
180
|
-
* Callback to gather member key and feed "hints" for the Invitee.
|
|
181
|
-
* @private
|
|
182
|
-
*/
|
|
183
|
-
_gatherHints() {
|
|
184
|
-
(0, assert_1.default)(this._state === GreetingState.SUCCEEDED);
|
|
185
|
-
const memberKeys = this._partyProcessor.memberKeys.map((publicKey) => ({
|
|
186
|
-
publicKey,
|
|
187
|
-
type: credentials_1.KeyType.UNKNOWN
|
|
188
|
-
}));
|
|
189
|
-
const memberFeeds = this._partyProcessor.feedKeys.map((publicKey) => ({
|
|
190
|
-
publicKey,
|
|
191
|
-
type: credentials_1.KeyType.FEED
|
|
192
|
-
}));
|
|
193
|
-
return [...memberKeys, ...memberFeeds];
|
|
194
|
-
}
|
|
195
181
|
}
|
|
196
182
|
exports.GreetingResponder = GreetingResponder;
|
|
197
183
|
//# sourceMappingURL=greeting-responder.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"greeting-responder.js","sourceRoot":"","sources":["../../../src/invitations/greeting-responder.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;;AAEF,
|
|
1
|
+
{"version":3,"file":"greeting-responder.js","sourceRoot":"","sources":["../../../src/invitations/greeting-responder.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;;AAEF,kDAA0B;AAC1B,8DAAiC;AAEjC,uCAAsD;AACtD,mDAQ2B;AAC3B,yCAA2C;AAE3C,2DAA+E;AAC/E,+CAA4C;AAK5C,6EAAwE;AAExE,MAAM,GAAG,GAAG,IAAA,eAAK,EAAC,iCAAiC,CAAC,CAAC;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AC,kBAAkB,CAAC,MAAM,EAC9B,IAAI,CAAC,eAAe,CAAC,QAAQ,EAC7B,OAAO,EACP,CAAC,IAAI,CAAC,kBAAkB,CAAC,oBAAoB,EAAE,CAAC,CACjD,CAAC;YAEF,MAAM,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;YAE9C,gCAAgC;YAChC,MAAM,IAAA,wBAAgB,EAAC,GAAG,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;YAEzD,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;SAC1B;QACD,IAAI,CAAC,MAAM,GAAG,aAAa,CAAC,SAAS,CAAC;QAEtC,GAAG,CAAC,oCAAoC,CAAC,CAAC;QAC1C,wFAAwF;QACxF,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AAnMD,8CAmMC"}
|
|
@@ -7,8 +7,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
7
7
|
};
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.HaloRecoveryInitiator = void 0;
|
|
10
|
-
const assert_1 = __importDefault(require("assert"));
|
|
11
10
|
const debug_1 = __importDefault(require("debug"));
|
|
11
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
12
12
|
const async_1 = require("@dxos/async");
|
|
13
13
|
const credentials_1 = require("@dxos/credentials");
|
|
14
14
|
const crypto_1 = require("@dxos/crypto");
|
|
@@ -41,10 +41,10 @@ class HaloRecoveryInitiator {
|
|
|
41
41
|
* @param {number} timeout Connection timeout (ms).
|
|
42
42
|
*/
|
|
43
43
|
async connect(timeout = DEFAULT_TIMEOUT) {
|
|
44
|
-
(0,
|
|
44
|
+
(0, node_assert_1.default)(this._state === greeting_responder_1.GreetingState.INITIALIZED);
|
|
45
45
|
// This is a temporary connection, there is no need to any special or permanent ID.
|
|
46
46
|
this._peerId = (0, crypto_1.randomBytes)();
|
|
47
|
-
log('Local PeerId:',
|
|
47
|
+
log('Local PeerId:', protocols_1.PublicKey.stringify(this._peerId));
|
|
48
48
|
const swarmKey = this._credentialsSigner.getIdentityKey().publicKey.asBuffer();
|
|
49
49
|
this._greeterPlugin = new credentials_1.GreetingCommandPlugin(this._peerId, async () => false);
|
|
50
50
|
log('Connecting');
|
|
@@ -67,18 +67,18 @@ class HaloRecoveryInitiator {
|
|
|
67
67
|
* @return {InvitationDescriptor}
|
|
68
68
|
*/
|
|
69
69
|
async claim() {
|
|
70
|
-
(0,
|
|
71
|
-
(0,
|
|
72
|
-
(0,
|
|
70
|
+
(0, node_assert_1.default)(this._state === greeting_responder_1.GreetingState.CONNECTED);
|
|
71
|
+
(0, node_assert_1.default)(this._greeterPlugin);
|
|
72
|
+
(0, node_assert_1.default)(this._peerId);
|
|
73
73
|
// Send to the first peer (any peer will do).
|
|
74
74
|
const peer = this._greeterPlugin.peers[0];
|
|
75
|
-
const responderPeerId =
|
|
75
|
+
const responderPeerId = protocols_1.PublicKey.bufferize(peer.getSession().peerId);
|
|
76
76
|
// Synthesize an "invitationID" which is the signature of both peerIds signed by our Identity key.
|
|
77
77
|
const signature = this._credentialsSigner.signer.rawSign(Buffer.concat([this._peerId, responderPeerId]), this._credentialsSigner.getIdentityKey());
|
|
78
78
|
// We expect to receive a new swarm/rendezvousKey to use for the full Greeting process.
|
|
79
79
|
const claimResponse = await this._greeterPlugin.send(responderPeerId, (0, credentials_1.createGreetingClaimMessage)(signature));
|
|
80
80
|
const { id, rendezvousKey } = claimResponse;
|
|
81
|
-
(0,
|
|
81
|
+
(0, node_assert_1.default)(id && rendezvousKey);
|
|
82
82
|
await this.disconnect();
|
|
83
83
|
this._state = greeting_responder_1.GreetingState.SUCCEEDED;
|
|
84
84
|
return new invitation_descriptor_1.InvitationDescriptor(invitation_descriptor_1.InvitationDescriptorType.INTERACTIVE, Buffer.from(rendezvousKey), Buffer.from(id), this._credentialsSigner.getIdentityKey().publicKey);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"halo-recovery-initiator.js","sourceRoot":"","sources":["../../../src/invitations/halo-recovery-initiator.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;;AAEF,
|
|
1
|
+
{"version":3,"file":"halo-recovery-initiator.js","sourceRoot":"","sources":["../../../src/invitations/halo-recovery-initiator.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;;AAEF,kDAA0B;AAC1B,8DAAiC;AAEjC,uCAA2C;AAC3C,mDAY2B;AAC3B,yCAAmD;AACnD,2DAA+E;AAC/E,+CAA4C;AAE5C,+CAA4D;AAE5D,6EAAwE;AACxE,6DAAqD;AACrD,mEAAyF;AAGzF,MAAM,GAAG,GAAG,IAAA,eAAK,EAAC,sCAAsC,CAAC,CAAC;AAE1D,MAAM,eAAe,GAAG,KAAK,CAAC;AAE9B;;;;;;GAMG;AACH,MAAa,qBAAqB;IAKhC,YACmB,eAA+B,EAC/B,kBAAqC;QADrC,oBAAe,GAAf,eAAe,CAAgB;QAC/B,uBAAkB,GAAlB,kBAAkB,CAAmB;QAEtD,IAAI,CAAC,MAAM,GAAG,kCAAa,CAAC,WAAW,CAAC;IAC1C,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,OAAO,CAAE,OAAO,GAAG,eAAe;QACtC,IAAA,qBAAM,EAAC,IAAI,CAAC,MAAM,KAAK,kCAAa,CAAC,WAAW,CAAC,CAAC;QAElD,mFAAmF;QACnF,IAAI,CAAC,OAAO,GAAG,IAAA,oBAAW,GAAE,CAAC;QAC7B,GAAG,CAAC,eAAe,EAAE,qBAAS,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;QAExD,MAAM,QAAQ,GAAG,IAAI,CAAC,kBAAkB,CAAC,cAAc,EAAE,CAAC,SAAS,CAAC,QAAQ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AE,EAAE;gBACpE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,mBAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;gBAEtD,OAAO,OAAO,CAAC,MAAM,CAAU,WAA4B,CAAC;oBAC1D,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC;oBACzD,UAAU,CAAC,SAAS,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC1D,CAAC,CAAC;YAEF,wCAAwC;YACxC,OAAO,iBAAiB,CAAC,gBAAgB,CAAC,EAAE,eAAe,EAAE,EAAE,EAAE,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,KAAM,EAAE,CAAC,CAAC;QACtG,CAAC,CAAC,CAAC;QAEH,OAAO,YAAY,CAAC,oBAAoB,EAAE,CAAC;IAC7C,CAAC;CACF;AApJD,sDAoJC"}
|
|
@@ -30,9 +30,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
30
30
|
};
|
|
31
31
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
32
|
exports.InvitationDescriptor = exports.InvitationDescriptorType = void 0;
|
|
33
|
-
const assert_1 = __importDefault(require("assert"));
|
|
34
33
|
const base_x_1 = __importDefault(require("base-x"));
|
|
35
34
|
const json_stable_stringify_1 = __importDefault(require("json-stable-stringify"));
|
|
35
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
36
36
|
const crypto_1 = require("@dxos/crypto");
|
|
37
37
|
const proto = __importStar(require("@dxos/echo-protocol"));
|
|
38
38
|
const protocols_1 = require("@dxos/protocols");
|
|
@@ -60,28 +60,28 @@ class InvitationDescriptor {
|
|
|
60
60
|
this.invitation = invitation;
|
|
61
61
|
this.identityKey = identityKey;
|
|
62
62
|
this.secret = secret;
|
|
63
|
-
(0,
|
|
64
|
-
(0,
|
|
65
|
-
(0,
|
|
63
|
+
(0, node_assert_1.default)(type);
|
|
64
|
+
(0, node_assert_1.default)(swarmKey instanceof Uint8Array);
|
|
65
|
+
(0, node_assert_1.default)(invitation instanceof Uint8Array);
|
|
66
66
|
if (identityKey) {
|
|
67
67
|
protocols_1.PublicKey.assertValidPublicKey(identityKey);
|
|
68
68
|
}
|
|
69
69
|
if (secret) {
|
|
70
|
-
(0,
|
|
70
|
+
(0, node_assert_1.default)(secret instanceof Uint8Array);
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
static fromQueryParameters(queryParameters) {
|
|
74
74
|
const { hash, swarmKey, invitation, identityKey, type } = queryParameters;
|
|
75
|
-
const descriptor = new InvitationDescriptor(parseInvitationType(type),
|
|
75
|
+
const descriptor = new InvitationDescriptor(parseInvitationType(type), protocols_1.PublicKey.bufferize(swarmKey), protocols_1.PublicKey.bufferize(invitation), identityKey ? protocols_1.PublicKey.from(identityKey) : undefined);
|
|
76
76
|
if (hash !== descriptor.hash) {
|
|
77
77
|
throw new errors_1.InvalidInvitationError();
|
|
78
78
|
}
|
|
79
79
|
return descriptor;
|
|
80
80
|
}
|
|
81
81
|
static fromProto(protoInvitation) {
|
|
82
|
-
(0,
|
|
83
|
-
(0,
|
|
84
|
-
(0,
|
|
82
|
+
(0, node_assert_1.default)(protoInvitation.type, 'Invitation type not provided.');
|
|
83
|
+
(0, node_assert_1.default)(protoInvitation.swarmKey, 'Invitation swarm key not provided.');
|
|
84
|
+
(0, node_assert_1.default)(protoInvitation.invitation, 'Invitation not provided.');
|
|
85
85
|
return new InvitationDescriptor(protoInvitation.type, protoInvitation.swarmKey, Buffer.from(protoInvitation.invitation), protoInvitation.identityKey ? protocols_1.PublicKey.from(protoInvitation.identityKey) : undefined, protoInvitation.secret ? Buffer.from(protoInvitation.secret) : undefined);
|
|
86
86
|
}
|
|
87
87
|
static decode(code) {
|
|
@@ -97,8 +97,8 @@ class InvitationDescriptor {
|
|
|
97
97
|
*/
|
|
98
98
|
toQueryParameters() {
|
|
99
99
|
const query = {
|
|
100
|
-
swarmKey:
|
|
101
|
-
invitation:
|
|
100
|
+
swarmKey: protocols_1.PublicKey.stringify(this.swarmKey),
|
|
101
|
+
invitation: protocols_1.PublicKey.stringify(this.invitation),
|
|
102
102
|
type: stringifyInvitationType(this.type)
|
|
103
103
|
};
|
|
104
104
|
if (this.identityKey) {
|
|
@@ -125,7 +125,7 @@ class InvitationDescriptor {
|
|
|
125
125
|
exports.InvitationDescriptor = InvitationDescriptor;
|
|
126
126
|
const parseInvitationType = (str) => {
|
|
127
127
|
const type = parseInt(str);
|
|
128
|
-
(0,
|
|
128
|
+
(0, node_assert_1.default)(type === 1 || type === 2, 'Invalid invitation type');
|
|
129
129
|
return type;
|
|
130
130
|
};
|
|
131
131
|
const stringifyInvitationType = (type) => type.toString();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"invitation-descriptor.js","sourceRoot":"","sources":["../../../src/invitations/invitation-descriptor.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEF,
|
|
1
|
+
{"version":3,"file":"invitation-descriptor.js","sourceRoot":"","sources":["../../../src/invitations/invitation-descriptor.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEF,oDAA0B;AAC1B,kFAAoD;AACpD,8DAAiC;AAEjC,yCAAyC;AAEzC,2DAA6C;AAC7C,+CAA4C;AAE5C,+CAA4D;AAE5D,oDAAoD;AACtC,QAAA,wBAAwB,GAAG,KAAK,CAAC,oBAAoB,CAAC,IAAI,CAAC;AAEzE,6CAA6C;AAC7C,MAAM,MAAM,GAAG,IAAA,gBAAI,EAAC,gEAAgE,CAAC,CAAC;AAEtF,iEAAiE;AACjE,yDAAyD;AACzD,MAAM,aAAa,GAAG,KAAK,CAAC;AAa5B;;;;;;;GAOG;AACH,MAAa,oBAAoB;IAiC/B,4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,CAAC,IAAI,GAAG,IAAA,kBAAS,EAAC,IAAA,+BAAe,EAAC,KAAK,CAAC,CAAC,CAAC;QAE/C,OAAO,KAAkC,CAAC;IAC5C,CAAC;IAED,OAAO;;QACL,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,WAAW,EAAE,MAAA,IAAI,CAAC,WAAW,0CAAE,YAAY,EAAE;YAC7C,MAAM,EAAE,IAAI,CAAC,MAAM;SACpB,CAAC;IACJ,CAAC;IAED,MAAM;QACJ,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAAC;QACrE,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC/B,CAAC;CACF;AA1FD,oDA0FC;AAED,MAAM,mBAAmB,GAAG,CAAC,GAAW,EAA4B,EAAE;IACpE,MAAM,IAAI,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;IAC3B,IAAA,qBAAM,EAAC,IAAI,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,EAAE,yBAAyB,CAAC,CAAC;IAC5D,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF,MAAM,uBAAuB,GAAG,CAAC,IAA8B,EAAU,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC"}
|
|
@@ -12,10 +12,11 @@ import { InvitationDescriptor } from './invitation-descriptor';
|
|
|
12
12
|
*/
|
|
13
13
|
export declare class InvitationFactory {
|
|
14
14
|
private readonly _partyProcessor;
|
|
15
|
+
private readonly _genesisFeedKey;
|
|
15
16
|
private readonly _credentialsSigner;
|
|
16
17
|
private readonly _credentialsWriter;
|
|
17
18
|
private readonly _networkManager;
|
|
18
|
-
constructor(_partyProcessor: PartyStateProvider, _credentialsSigner: CredentialsSigner, _credentialsWriter: FeedWriter<HaloMessage>, _networkManager: NetworkManager);
|
|
19
|
+
constructor(_partyProcessor: PartyStateProvider, _genesisFeedKey: PublicKey, _credentialsSigner: CredentialsSigner, _credentialsWriter: FeedWriter<HaloMessage>, _networkManager: NetworkManager);
|
|
19
20
|
get isHalo(): boolean;
|
|
20
21
|
createOfflineInvitation(publicKey: PublicKey): Promise<InvitationDescriptor>;
|
|
21
22
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"invitation-factory.d.ts","sourceRoot":"","sources":["../../../src/invitations/invitation-factory.ts"],"names":[],"mappings":";AAMA,OAAO,EAAgC,OAAO,IAAI,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACzF,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAkC,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAEtG,OAAO,EAAE,oBAAoB,EAA4B,MAAM,yBAAyB,CAAC;AAEzF;;GAEG;AACH,qBAAa,iBAAiB;IAE1B,OAAO,CAAC,QAAQ,CAAC,eAAe;
|
|
1
|
+
{"version":3,"file":"invitation-factory.d.ts","sourceRoot":"","sources":["../../../src/invitations/invitation-factory.ts"],"names":[],"mappings":";AAMA,OAAO,EAAgC,OAAO,IAAI,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACzF,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAkC,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAEtG,OAAO,EAAE,oBAAoB,EAA4B,MAAM,yBAAyB,CAAC;AAEzF;;GAEG;AACH,qBAAa,iBAAiB;IAE1B,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,kBAAkB;IACnC,OAAO,CAAC,QAAQ,CAAC,kBAAkB;IACnC,OAAO,CAAC,QAAQ,CAAC,eAAe;gBAJf,eAAe,EAAE,kBAAkB,EACnC,eAAe,EAAE,SAAS,EAC1B,kBAAkB,EAAE,iBAAiB,EACrC,kBAAkB,EAAE,UAAU,CAAC,WAAW,CAAC,EAC3C,eAAe,EAAE,cAAc;IAGlD,IAAI,MAAM,YAGT;IAEK,uBAAuB,CAAE,SAAS,EAAE,SAAS;IAoBnD;;OAEG;IACG,gBAAgB,CACpB,qBAAqB,GAAE,uBAAwD,EAAE,OAAO,GAAE,iBAAsB;IAwBlH,oBAAoB,CAAE,YAAY,EAAE,MAAM;CAG3C"}
|
|
@@ -7,7 +7,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
7
7
|
};
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.InvitationFactory = void 0;
|
|
10
|
-
const
|
|
10
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
11
11
|
const credentials_1 = require("@dxos/credentials");
|
|
12
12
|
const common_1 = require("./common");
|
|
13
13
|
const greeting_responder_1 = require("./greeting-responder");
|
|
@@ -16,11 +16,9 @@ const invitation_descriptor_1 = require("./invitation-descriptor");
|
|
|
16
16
|
* Groups together all invitation-related functionality for a single party.
|
|
17
17
|
*/
|
|
18
18
|
class InvitationFactory {
|
|
19
|
-
constructor(_partyProcessor,
|
|
20
|
-
// This needs to be a provider in case this is a backend for the HALO party.
|
|
21
|
-
// Then the identity would be changed after this is instantiated.
|
|
22
|
-
_credentialsSigner, _credentialsWriter, _networkManager) {
|
|
19
|
+
constructor(_partyProcessor, _genesisFeedKey, _credentialsSigner, _credentialsWriter, _networkManager) {
|
|
23
20
|
this._partyProcessor = _partyProcessor;
|
|
21
|
+
this._genesisFeedKey = _genesisFeedKey;
|
|
24
22
|
this._credentialsSigner = _credentialsSigner;
|
|
25
23
|
this._credentialsWriter = _credentialsWriter;
|
|
26
24
|
this._networkManager = _networkManager;
|
|
@@ -30,7 +28,7 @@ class InvitationFactory {
|
|
|
30
28
|
return this._credentialsSigner.getIdentityKey().publicKey.equals(this._partyProcessor.partyKey);
|
|
31
29
|
}
|
|
32
30
|
async createOfflineInvitation(publicKey) {
|
|
33
|
-
(0,
|
|
31
|
+
(0, node_assert_1.default)(!this.isHalo, 'Offline invitations to HALO are not allowed.');
|
|
34
32
|
const invitationMessage = (0, credentials_1.createPartyInvitationMessage)(this._credentialsSigner.signer, this._partyProcessor.partyKey, publicKey, this._credentialsSigner.getIdentityKey(), this._credentialsSigner.getDeviceSigningKeys());
|
|
35
33
|
await this._credentialsWriter.write(invitationMessage);
|
|
36
34
|
return new invitation_descriptor_1.InvitationDescriptor(invitation_descriptor_1.InvitationDescriptorType.OFFLINE, this._partyProcessor.partyKey.asBuffer(), invitationMessage.payload.signed.payload.id);
|
|
@@ -39,8 +37,8 @@ class InvitationFactory {
|
|
|
39
37
|
* Creates an invitation for a remote peer.
|
|
40
38
|
*/
|
|
41
39
|
async createInvitation(authenticationDetails = common_1.defaultInvitationAuthenticator, options = {}) {
|
|
42
|
-
(0,
|
|
43
|
-
const responder = new greeting_responder_1.GreetingResponder(this._networkManager, this._partyProcessor, this._credentialsSigner, this._credentialsWriter);
|
|
40
|
+
(0, node_assert_1.default)(this._networkManager);
|
|
41
|
+
const responder = new greeting_responder_1.GreetingResponder(this._networkManager, this._partyProcessor, this._genesisFeedKey, this._credentialsSigner, this._credentialsWriter);
|
|
44
42
|
const { secretValidator, secretProvider } = authenticationDetails;
|
|
45
43
|
const { onFinish, expiration } = options;
|
|
46
44
|
const swarmKey = await responder.start();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"invitation-factory.js","sourceRoot":"","sources":["../../../src/invitations/invitation-factory.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;;AAEF,
|
|
1
|
+
{"version":3,"file":"invitation-factory.js","sourceRoot":"","sources":["../../../src/invitations/invitation-factory.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;;AAEF,8DAAiC;AAEjC,mDAAyF;AAOzF,qCAAsG;AACtG,6DAAyD;AACzD,mEAAyF;AAEzF;;GAEG;AACH,MAAa,iBAAiB;IAC5B,YACmB,eAAmC,EACnC,eAA0B,EAC1B,kBAAqC,EACrC,kBAA2C,EAC3C,eAA+B;QAJ/B,oBAAe,GAAf,eAAe,CAAoB;QACnC,oBAAe,GAAf,eAAe,CAAW;QAC1B,uBAAkB,GAAlB,kBAAkB,CAAmB;QACrC,uBAAkB,GAAlB,kBAAkB,CAAyB;QAC3C,oBAAe,GAAf,eAAe,CAAgB;IAC/C,CAAC;IAEJ,IAAI,MAAM;QACR,gDAAgD;QAChD,OAAO,IAAI,CAAC,kBAAkB,CAAC,cAAc,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;IAClG,CAAC;IAED,KAAK,CAAC,uBAAuB,CAAE,SAAoB;QACjD,IAAA,qBAAM,EAAC,CAAC,IAAI,CAAC,MAAM,EAAE,8CAA8C,CAAC,CAAC;QAErE,MAAM,iBAAiB,GAAG,IAAA,0CAA4B,EACpD,IAAI,CAAC,kBAAkB,CAAC,MAAM,EAC9B,IAAI,CAAC,eAAe,CAAC,QAAQ,EAC7B,SAAS,EACT,IAAI,CAAC,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oB,CAAC,YAAY,CAAC,CAAC;IACjE,CAAC;CACF;AAjED,8CAiEC"}
|
|
@@ -7,8 +7,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
7
7
|
};
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.OfflineInvitationClaimer = void 0;
|
|
10
|
-
const assert_1 = __importDefault(require("assert"));
|
|
11
10
|
const debug_1 = __importDefault(require("debug"));
|
|
11
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
12
12
|
const async_1 = require("@dxos/async");
|
|
13
13
|
const credentials_1 = require("@dxos/credentials");
|
|
14
14
|
const crypto_1 = require("@dxos/crypto");
|
|
@@ -29,7 +29,7 @@ class OfflineInvitationClaimer {
|
|
|
29
29
|
this._networkManager = _networkManager;
|
|
30
30
|
this._invitationDescriptor = _invitationDescriptor;
|
|
31
31
|
this._state = greeting_responder_1.GreetingState.INITIALIZED;
|
|
32
|
-
(0,
|
|
32
|
+
(0, node_assert_1.default)(invitation_descriptor_1.InvitationDescriptorType.OFFLINE === _invitationDescriptor.type);
|
|
33
33
|
}
|
|
34
34
|
get state() {
|
|
35
35
|
return this._state;
|
|
@@ -39,12 +39,12 @@ class OfflineInvitationClaimer {
|
|
|
39
39
|
* @param {number} timeout Connection timeout (ms).
|
|
40
40
|
*/
|
|
41
41
|
async connect(timeout = DEFAULT_TIMEOUT) {
|
|
42
|
-
(0,
|
|
42
|
+
(0, node_assert_1.default)(this._state === greeting_responder_1.GreetingState.INITIALIZED);
|
|
43
43
|
const { swarmKey } = this._invitationDescriptor;
|
|
44
|
-
(0,
|
|
44
|
+
(0, node_assert_1.default)(swarmKey, 'swarmKey is required');
|
|
45
45
|
// This is a temporary connection, there is no need to any special or permanent ID.
|
|
46
46
|
const localPeerId = (0, crypto_1.randomBytes)();
|
|
47
|
-
log('Local PeerId:',
|
|
47
|
+
log('Local PeerId:', protocols_1.PublicKey.stringify(localPeerId));
|
|
48
48
|
this._greeterPlugin = new credentials_1.GreetingCommandPlugin(localPeerId, async () => false);
|
|
49
49
|
log('Connecting');
|
|
50
50
|
const peerJoinedWaiter = (0, async_1.waitForEvent)(this._greeterPlugin, 'peer:joined', () => { var _a; return !!((_a = this._greeterPlugin) === null || _a === void 0 ? void 0 : _a.peers.length); }, timeout);
|
|
@@ -66,15 +66,15 @@ class OfflineInvitationClaimer {
|
|
|
66
66
|
* @return {InvitationDescriptor}
|
|
67
67
|
*/
|
|
68
68
|
async claim() {
|
|
69
|
-
(0,
|
|
70
|
-
(0,
|
|
69
|
+
(0, node_assert_1.default)(this._state === greeting_responder_1.GreetingState.CONNECTED);
|
|
70
|
+
(0, node_assert_1.default)(this._greeterPlugin);
|
|
71
71
|
const { invitation: invitationID } = this._invitationDescriptor;
|
|
72
72
|
// Send to the first peer (any peer will do).
|
|
73
|
-
const responderPeerId =
|
|
73
|
+
const responderPeerId = protocols_1.PublicKey.bufferize(this._greeterPlugin.peers[0].getSession().peerId);
|
|
74
74
|
// We expect to receive a new swarm/rendezvousKey to use for the full Greeting process.
|
|
75
75
|
const claimResponse = await this._greeterPlugin.send(responderPeerId, (0, credentials_1.createGreetingClaimMessage)(Buffer.from(invitationID)));
|
|
76
76
|
const { id, rendezvousKey } = claimResponse;
|
|
77
|
-
(0,
|
|
77
|
+
(0, node_assert_1.default)(id && rendezvousKey);
|
|
78
78
|
await this.disconnect();
|
|
79
79
|
this._state = greeting_responder_1.GreetingState.SUCCEEDED;
|
|
80
80
|
return new invitation_descriptor_1.InvitationDescriptor(invitation_descriptor_1.InvitationDescriptorType.INTERACTIVE, Buffer.from(rendezvousKey), Buffer.from(id));
|