@freesignal/protocol 0.7.8 → 0.7.10
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 +7 -4
- package/dist/node.js +21 -10
- package/package.json +1 -1
package/dist/node.d.ts
CHANGED
|
@@ -32,19 +32,22 @@ export declare class BootstrapRequest extends EventEmitter<'change', BootstrapRe
|
|
|
32
32
|
accept(): void;
|
|
33
33
|
deny(): void;
|
|
34
34
|
}
|
|
35
|
-
type NodeEventData = {
|
|
35
|
+
export type NodeEventData = {
|
|
36
36
|
session?: KeySession;
|
|
37
37
|
payload?: Uint8Array;
|
|
38
38
|
datagram?: Datagram;
|
|
39
39
|
request?: BootstrapRequest;
|
|
40
40
|
userId?: UserId;
|
|
41
41
|
};
|
|
42
|
-
type
|
|
42
|
+
export type HandshakeEventData = {
|
|
43
|
+
session: KeySession;
|
|
44
|
+
};
|
|
45
|
+
export type SendEventData = {
|
|
43
46
|
session?: KeySession;
|
|
44
47
|
datagram: Datagram;
|
|
45
48
|
userId: UserId;
|
|
46
49
|
};
|
|
47
|
-
type MessageEventData = {
|
|
50
|
+
export type MessageEventData = {
|
|
48
51
|
session: KeySession;
|
|
49
52
|
payload: Uint8Array;
|
|
50
53
|
};
|
|
@@ -86,7 +89,7 @@ export declare class FreeSignalNode {
|
|
|
86
89
|
packBootstrap(): Promise<Datagram>;
|
|
87
90
|
sendBootstrap(receiverId: string | UserId): Promise<void>;
|
|
88
91
|
protected decrypt(datagram: EncryptedDatagram | Datagram | Uint8Array): Promise<MessageEventData>;
|
|
89
|
-
protected openHandshake(datagram: Datagram | EncryptedDatagram | Uint8Array): Promise<
|
|
92
|
+
protected openHandshake(datagram: Datagram | EncryptedDatagram | Uint8Array): Promise<'syn' | 'ack'>;
|
|
90
93
|
protected open(datagram: Datagram | EncryptedDatagram | Uint8Array): Promise<void>;
|
|
91
94
|
}
|
|
92
95
|
declare class SessionMap implements LocalStorage<string, KeySession> {
|
package/dist/node.js
CHANGED
|
@@ -66,14 +66,16 @@ class BootstrapRequest extends easyemitter_ts_1.default {
|
|
|
66
66
|
return __classPrivateFieldGet(this, _BootstrapRequest_status, "f") === 'accepted' ? this.keyExchangeData : undefined;
|
|
67
67
|
}
|
|
68
68
|
accept() {
|
|
69
|
-
if (this.status === 'pending')
|
|
69
|
+
if (this.status === 'pending') {
|
|
70
70
|
__classPrivateFieldSet(this, _BootstrapRequest_status, 'accepted', "f");
|
|
71
|
-
|
|
71
|
+
this.emit('change', this);
|
|
72
|
+
}
|
|
72
73
|
}
|
|
73
74
|
deny() {
|
|
74
|
-
if (this.status === 'pending')
|
|
75
|
+
if (this.status === 'pending') {
|
|
75
76
|
__classPrivateFieldSet(this, _BootstrapRequest_status, 'denied', "f");
|
|
76
|
-
|
|
77
|
+
this.emit('change', this);
|
|
78
|
+
}
|
|
77
79
|
}
|
|
78
80
|
}
|
|
79
81
|
exports.BootstrapRequest = BootstrapRequest;
|
|
@@ -198,7 +200,7 @@ class FreeSignalNode {
|
|
|
198
200
|
sendBootstrap(receiverId) {
|
|
199
201
|
return __awaiter(this, void 0, void 0, function* () {
|
|
200
202
|
//console.debug("Sending Bootstrap");
|
|
201
|
-
if (
|
|
203
|
+
if (yield this.sessions.has(receiverId.toString()))
|
|
202
204
|
throw new Error("Session exists");
|
|
203
205
|
const datagram = yield this.packBootstrap();
|
|
204
206
|
this.emitter.emit('send', { datagram, userId: types_1.UserId.from(receiverId) });
|
|
@@ -234,7 +236,7 @@ class FreeSignalNode {
|
|
|
234
236
|
throw new Error("Session not found for sessionTag: " + encrypted.sessionTag);
|
|
235
237
|
if (!(0, utils_1.compareBytes)(payload, crypto_1.default.ECDH.scalarMult(this.privateIdentityKey.exchangeKey, session.identityKey.exchangeKey)))
|
|
236
238
|
throw new Error("Error validating handshake data");
|
|
237
|
-
return
|
|
239
|
+
return 'ack';
|
|
238
240
|
}
|
|
239
241
|
//console.debug("Opening Handshake Syn");
|
|
240
242
|
const data = (0, utils_1.decodeData)(encrypted.payload);
|
|
@@ -244,8 +246,7 @@ class FreeSignalNode {
|
|
|
244
246
|
yield this.sessions.set(session.sessionTag, session);
|
|
245
247
|
yield this.users.set(session.userId.toString(), session.sessionTag);
|
|
246
248
|
yield this.bundles.set(session.userId.toString(), (0, utils_1.decodeData)(associatedData));
|
|
247
|
-
|
|
248
|
-
return session;
|
|
249
|
+
return 'syn';
|
|
249
250
|
});
|
|
250
251
|
}
|
|
251
252
|
open(datagram) {
|
|
@@ -253,9 +254,19 @@ class FreeSignalNode {
|
|
|
253
254
|
if (datagram instanceof Uint8Array)
|
|
254
255
|
datagram = types_1.Datagram.from(datagram);
|
|
255
256
|
switch (datagram.protocol) {
|
|
256
|
-
case types_1.Protocols.HANDSHAKE:
|
|
257
|
-
|
|
257
|
+
case types_1.Protocols.HANDSHAKE: {
|
|
258
|
+
const encrypted = types_1.EncryptedDatagram.from(datagram);
|
|
259
|
+
if (!encrypted.payload)
|
|
260
|
+
throw new Error("Missing payload");
|
|
261
|
+
if ((yield this.openHandshake(datagram)) === 'ack')
|
|
262
|
+
return;
|
|
263
|
+
const session = yield this.sessions.get(encrypted.sessionTag);
|
|
264
|
+
if (!session)
|
|
265
|
+
throw new Error("Session not found for sessionTag: " + encrypted.sessionTag);
|
|
266
|
+
yield this.sendHandshake(session);
|
|
267
|
+
this.emitter.emit('handshake', { session });
|
|
258
268
|
return;
|
|
269
|
+
}
|
|
259
270
|
case types_1.Protocols.MESSAGE:
|
|
260
271
|
//console.debug("Opening Message");
|
|
261
272
|
this.emitter.emit('message', yield this.decrypt(datagram));
|