@freesignal/protocol 0.8.1 → 0.8.3
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 -2
- package/dist/node.js +21 -22
- package/dist/types.d.ts +2 -1
- package/dist/types.js +6 -2
- package/package.json +1 -1
package/dist/node.d.ts
CHANGED
|
@@ -58,7 +58,7 @@ export declare class FreeSignalNode {
|
|
|
58
58
|
protected readonly keyExchange: KeyExchange;
|
|
59
59
|
protected readonly discovers: Set<string>;
|
|
60
60
|
protected readonly bootstraps: LocalStorage<string, BootstrapRequest>;
|
|
61
|
-
protected readonly emitter: EventEmitter<"message" | "send" | "handshake" | "
|
|
61
|
+
protected readonly emitter: EventEmitter<"message" | "send" | "handshake" | "bootstrap", NodeEventData>;
|
|
62
62
|
constructor(storage: Database<{
|
|
63
63
|
sessions: LocalStorage<string, ExportedKeySession>;
|
|
64
64
|
users: LocalStorage<string, string>;
|
|
@@ -84,7 +84,6 @@ export declare class FreeSignalNode {
|
|
|
84
84
|
sendHandshake(userId: UserId | string): Promise<void>;
|
|
85
85
|
sendData<T>(receiverId: string | UserId, data: T): Promise<void>;
|
|
86
86
|
sendRelay(relayId: string | UserId, receiverId: string | UserId, data: Datagram): Promise<void>;
|
|
87
|
-
sendPing(receiverId: string | UserId): Promise<void>;
|
|
88
87
|
sendDiscover(receiverId: string | UserId, discoverId: string | UserId): Promise<void>;
|
|
89
88
|
packBootstrap(): Promise<Datagram>;
|
|
90
89
|
sendBootstrap(receiverId: string | UserId): Promise<void>;
|
package/dist/node.js
CHANGED
|
@@ -97,13 +97,14 @@ export class FreeSignalNode {
|
|
|
97
97
|
return this.bootstraps.get(userId);
|
|
98
98
|
}
|
|
99
99
|
waitHandshaked(userId, timeout) {
|
|
100
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
101
101
|
var _a, _b;
|
|
102
102
|
if (timeout)
|
|
103
|
-
setTimeout(() =>
|
|
103
|
+
setTimeout(() => reject(), timeout);
|
|
104
104
|
while (((_b = (_a = (yield this.emitter.wait('handshake', timeout))) === null || _a === void 0 ? void 0 : _a.session) === null || _b === void 0 ? void 0 : _b.userId.toString()) !== userId.toString())
|
|
105
105
|
;
|
|
106
|
-
|
|
106
|
+
resolve();
|
|
107
|
+
}));
|
|
107
108
|
}
|
|
108
109
|
get identityKey() {
|
|
109
110
|
return this.privateIdentityKey.identityKey;
|
|
@@ -160,19 +161,17 @@ export class FreeSignalNode {
|
|
|
160
161
|
this.emitter.emit('send', yield this.encrypt(relayId, Protocols.RELAY, concatBytes(UserId.from(receiverId).toBytes(), data.toBytes())));
|
|
161
162
|
});
|
|
162
163
|
}
|
|
163
|
-
sendPing(receiverId) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
});
|
|
175
|
-
}
|
|
164
|
+
/*public async sendPing(receiverId: string | UserId): Promise<void> {
|
|
165
|
+
//console.debug("Sending Ping");
|
|
166
|
+
const sessionTag = await this.users.get(receiverId.toString());
|
|
167
|
+
if (!sessionTag)
|
|
168
|
+
throw new Error("Session not found for user: " + receiverId);
|
|
169
|
+
const session = await this.sessions.get(sessionTag);
|
|
170
|
+
if (!session)
|
|
171
|
+
throw new Error("Session not found for sessionTag: " + sessionTag);
|
|
172
|
+
const datagram = new Datagram(Protocols.PING, undefined, session.sessionTag);
|
|
173
|
+
this.emitter.emit('send', { session, datagram, userId: session.userId });
|
|
174
|
+
}*/
|
|
176
175
|
sendDiscover(receiverId, discoverId) {
|
|
177
176
|
return __awaiter(this, void 0, void 0, function* () {
|
|
178
177
|
//console.debug("Sending Discover");
|
|
@@ -254,12 +253,12 @@ export class FreeSignalNode {
|
|
|
254
253
|
const encrypted = EncryptedDatagram.from(datagram);
|
|
255
254
|
if (!encrypted.payload)
|
|
256
255
|
throw new Error("Missing payload");
|
|
257
|
-
|
|
258
|
-
return;
|
|
256
|
+
const handshakeState = yield this.openHandshake(datagram);
|
|
259
257
|
const session = yield this.sessions.get(encrypted.sessionTag);
|
|
260
258
|
if (!session)
|
|
261
259
|
throw new Error("Session not found for sessionTag: " + encrypted.sessionTag);
|
|
262
|
-
|
|
260
|
+
if (handshakeState === 'syn')
|
|
261
|
+
yield this.sendHandshake(session);
|
|
263
262
|
this.emitter.emit('handshake', { session });
|
|
264
263
|
return;
|
|
265
264
|
}
|
|
@@ -335,13 +334,13 @@ export class FreeSignalNode {
|
|
|
335
334
|
this.emitter.emit('bootstrap', { request });
|
|
336
335
|
return;
|
|
337
336
|
}
|
|
338
|
-
case Protocols.PING:
|
|
337
|
+
/*case Protocols.PING:
|
|
339
338
|
datagram = EncryptedDatagram.from(datagram);
|
|
340
|
-
const session =
|
|
339
|
+
const session = await this.sessions.get(datagram.sessionTag!);
|
|
341
340
|
if (!session)
|
|
342
341
|
throw new Error("Session not found for sessionTag: " + datagram.sessionTag);
|
|
343
342
|
this.emitter.emit('ping', { session });
|
|
344
|
-
return
|
|
343
|
+
return;*/
|
|
345
344
|
default:
|
|
346
345
|
throw new Error("Invalid protocol");
|
|
347
346
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ export declare class UserId implements Encodable {
|
|
|
25
25
|
static readonly keyLength = 32;
|
|
26
26
|
private constructor();
|
|
27
27
|
toString(): string;
|
|
28
|
+
toUrl(): string;
|
|
28
29
|
toJSON(): string;
|
|
29
30
|
toBytes(): Uint8Array;
|
|
30
31
|
static fromKey(identityKey: string | Uint8Array | IdentityKey): UserId;
|
|
@@ -72,7 +73,7 @@ export interface DiscoverMessage {
|
|
|
72
73
|
data?: KeyExchangeData;
|
|
73
74
|
}
|
|
74
75
|
export declare enum Protocols {
|
|
75
|
-
|
|
76
|
+
NULL = "",
|
|
76
77
|
MESSAGE = "/freesignal/message",
|
|
77
78
|
RELAY = "/freesignal/relay",
|
|
78
79
|
HANDSHAKE = "/freesignal/handshake",
|
package/dist/types.js
CHANGED
|
@@ -25,7 +25,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
25
25
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
26
26
|
});
|
|
27
27
|
};
|
|
28
|
-
import { concatBytes, decodeBase64, encodeBase64, bytesToNumber, numberToBytes, compareBytes } from "@freesignal/utils";
|
|
28
|
+
import { concatBytes, decodeBase64, encodeBase64, bytesToNumber, numberToBytes, compareBytes, decodeBase64URL } from "@freesignal/utils";
|
|
29
29
|
import crypto from "@freesignal/crypto";
|
|
30
30
|
export function encryptData(session, data) {
|
|
31
31
|
const key = session.getSendingKey();
|
|
@@ -71,6 +71,9 @@ export class UserId {
|
|
|
71
71
|
toString() {
|
|
72
72
|
return decodeBase64(this.array);
|
|
73
73
|
}
|
|
74
|
+
toUrl() {
|
|
75
|
+
return decodeBase64URL(this.array);
|
|
76
|
+
}
|
|
74
77
|
toJSON() {
|
|
75
78
|
return this.toString();
|
|
76
79
|
}
|
|
@@ -191,7 +194,8 @@ export var DiscoverType;
|
|
|
191
194
|
})(DiscoverType || (DiscoverType = {}));
|
|
192
195
|
export var Protocols;
|
|
193
196
|
(function (Protocols) {
|
|
194
|
-
Protocols["
|
|
197
|
+
Protocols["NULL"] = "";
|
|
198
|
+
//PING = '/freesignal/ping',
|
|
195
199
|
Protocols["MESSAGE"] = "/freesignal/message";
|
|
196
200
|
Protocols["RELAY"] = "/freesignal/relay";
|
|
197
201
|
Protocols["HANDSHAKE"] = "/freesignal/handshake";
|