@freesignal/protocol 0.7.7 → 0.7.9
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/node.d.ts +1 -0
- package/dist/node.js +30 -18
- package/package.json +1 -1
package/dist/node.d.ts
CHANGED
|
@@ -86,6 +86,7 @@ export declare class FreeSignalNode {
|
|
|
86
86
|
packBootstrap(): Promise<Datagram>;
|
|
87
87
|
sendBootstrap(receiverId: string | UserId): Promise<void>;
|
|
88
88
|
protected decrypt(datagram: EncryptedDatagram | Datagram | Uint8Array): Promise<MessageEventData>;
|
|
89
|
+
protected openHandshake(datagram: Datagram | EncryptedDatagram | Uint8Array): Promise<'syn' | 'ack'>;
|
|
89
90
|
protected open(datagram: Datagram | EncryptedDatagram | Uint8Array): Promise<void>;
|
|
90
91
|
}
|
|
91
92
|
declare class SessionMap implements LocalStorage<string, KeySession> {
|
package/dist/node.js
CHANGED
|
@@ -221,6 +221,32 @@ class FreeSignalNode {
|
|
|
221
221
|
return { session, payload: decrypted };
|
|
222
222
|
});
|
|
223
223
|
}
|
|
224
|
+
openHandshake(datagram) {
|
|
225
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
226
|
+
const encrypted = types_1.EncryptedDatagram.from(datagram);
|
|
227
|
+
if (!encrypted.payload)
|
|
228
|
+
throw new Error("Missing payload");
|
|
229
|
+
if (yield this.sessions.has(encrypted.sessionTag)) {
|
|
230
|
+
//console.debug("Opening Handshake Ack");
|
|
231
|
+
const session = yield this.sessions.get(encrypted.sessionTag);
|
|
232
|
+
const { payload } = yield this.decrypt(encrypted);
|
|
233
|
+
if (!session)
|
|
234
|
+
throw new Error("Session not found for sessionTag: " + encrypted.sessionTag);
|
|
235
|
+
if (!(0, utils_1.compareBytes)(payload, crypto_1.default.ECDH.scalarMult(this.privateIdentityKey.exchangeKey, session.identityKey.exchangeKey)))
|
|
236
|
+
throw new Error("Error validating handshake data");
|
|
237
|
+
return 'ack';
|
|
238
|
+
}
|
|
239
|
+
//console.debug("Opening Handshake Syn");
|
|
240
|
+
const data = (0, utils_1.decodeData)(encrypted.payload);
|
|
241
|
+
if (!encrypted.verify(types_1.IdentityKey.from(data.identityKey).signatureKey))
|
|
242
|
+
throw new Error("Signature not verified");
|
|
243
|
+
const { session, associatedData } = yield this.keyExchange.digestMessage(data);
|
|
244
|
+
yield this.sessions.set(session.sessionTag, session);
|
|
245
|
+
yield this.users.set(session.userId.toString(), session.sessionTag);
|
|
246
|
+
yield this.bundles.set(session.userId.toString(), (0, utils_1.decodeData)(associatedData));
|
|
247
|
+
return 'syn';
|
|
248
|
+
});
|
|
249
|
+
}
|
|
224
250
|
open(datagram) {
|
|
225
251
|
return __awaiter(this, void 0, void 0, function* () {
|
|
226
252
|
if (datagram instanceof Uint8Array)
|
|
@@ -230,25 +256,11 @@ class FreeSignalNode {
|
|
|
230
256
|
const encrypted = types_1.EncryptedDatagram.from(datagram);
|
|
231
257
|
if (!encrypted.payload)
|
|
232
258
|
throw new Error("Missing payload");
|
|
233
|
-
if (yield this.
|
|
234
|
-
//console.debug("Opening Handshake Ack");
|
|
235
|
-
const session = yield this.sessions.get(encrypted.sessionTag);
|
|
236
|
-
const { payload } = yield this.decrypt(encrypted);
|
|
237
|
-
if (!session)
|
|
238
|
-
throw new Error("Session not found for sessionTag: " + datagram.sessionTag);
|
|
239
|
-
if (!(0, utils_1.compareBytes)(payload, crypto_1.default.ECDH.scalarMult(this.privateIdentityKey.exchangeKey, session.identityKey.exchangeKey)))
|
|
240
|
-
throw new Error("Error validating handshake data");
|
|
241
|
-
this.emitter.emit('handshake', { session });
|
|
259
|
+
if ((yield this.openHandshake(datagram)) === 'ack')
|
|
242
260
|
return;
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
if (!datagram.verify(types_1.IdentityKey.from(data.identityKey).signatureKey))
|
|
247
|
-
throw new Error("Signature not verified");
|
|
248
|
-
const { session, associatedData } = yield this.keyExchange.digestMessage(data);
|
|
249
|
-
yield this.sessions.set(session.sessionTag, session);
|
|
250
|
-
yield this.users.set(session.userId.toString(), session.sessionTag);
|
|
251
|
-
yield this.bundles.set(session.userId.toString(), (0, utils_1.decodeData)(associatedData));
|
|
261
|
+
const session = yield this.sessions.get(encrypted.sessionTag);
|
|
262
|
+
if (!session)
|
|
263
|
+
throw new Error("Session not found for sessionTag: " + encrypted.sessionTag);
|
|
252
264
|
yield this.sendHandshake(session);
|
|
253
265
|
this.emitter.emit('handshake', { session });
|
|
254
266
|
return;
|