@freesignal/protocol 0.8.0 → 0.8.2
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 +2 -2
- package/dist/node.js +24 -19
- package/dist/types.d.ts +2 -1
- package/dist/types.js +6 -2
- package/package.json +45 -45
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>;
|
|
@@ -81,9 +81,9 @@ export declare class FreeSignalNode {
|
|
|
81
81
|
protected encrypt(receiverId: string | UserId, protocol: Protocols, data: Uint8Array): Promise<SendEventData>;
|
|
82
82
|
sendHandshake(data: KeyExchangeData): Promise<void>;
|
|
83
83
|
sendHandshake(session: KeySession): Promise<void>;
|
|
84
|
+
sendHandshake(userId: UserId | string): Promise<void>;
|
|
84
85
|
sendData<T>(receiverId: string | UserId, data: T): Promise<void>;
|
|
85
86
|
sendRelay(relayId: string | UserId, receiverId: string | UserId, data: Datagram): Promise<void>;
|
|
86
|
-
sendPing(receiverId: string | UserId): Promise<void>;
|
|
87
87
|
sendDiscover(receiverId: string | UserId, discoverId: string | UserId): Promise<void>;
|
|
88
88
|
packBootstrap(): Promise<Datagram>;
|
|
89
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;
|
|
@@ -126,6 +127,12 @@ export class FreeSignalNode {
|
|
|
126
127
|
}
|
|
127
128
|
sendHandshake(data) {
|
|
128
129
|
return __awaiter(this, void 0, void 0, function* () {
|
|
130
|
+
if (data instanceof UserId || typeof data === 'string') {
|
|
131
|
+
const session = yield this.sessions.get(data.toString());
|
|
132
|
+
if (!session)
|
|
133
|
+
throw new Error("Session not found for userId: " + data.toString());
|
|
134
|
+
data = session;
|
|
135
|
+
}
|
|
129
136
|
if (data instanceof KeySession) {
|
|
130
137
|
//console.debug("Sending Handshake Ack");
|
|
131
138
|
const session = yield this.sessions.get(data.sessionTag);
|
|
@@ -154,19 +161,17 @@ export class FreeSignalNode {
|
|
|
154
161
|
this.emitter.emit('send', yield this.encrypt(relayId, Protocols.RELAY, concatBytes(UserId.from(receiverId).toBytes(), data.toBytes())));
|
|
155
162
|
});
|
|
156
163
|
}
|
|
157
|
-
sendPing(receiverId) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
});
|
|
169
|
-
}
|
|
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
|
+
}*/
|
|
170
175
|
sendDiscover(receiverId, discoverId) {
|
|
171
176
|
return __awaiter(this, void 0, void 0, function* () {
|
|
172
177
|
//console.debug("Sending Discover");
|
|
@@ -329,13 +334,13 @@ export class FreeSignalNode {
|
|
|
329
334
|
this.emitter.emit('bootstrap', { request });
|
|
330
335
|
return;
|
|
331
336
|
}
|
|
332
|
-
case Protocols.PING:
|
|
337
|
+
/*case Protocols.PING:
|
|
333
338
|
datagram = EncryptedDatagram.from(datagram);
|
|
334
|
-
const session =
|
|
339
|
+
const session = await this.sessions.get(datagram.sessionTag!);
|
|
335
340
|
if (!session)
|
|
336
341
|
throw new Error("Session not found for sessionTag: " + datagram.sessionTag);
|
|
337
342
|
this.emitter.emit('ping', { session });
|
|
338
|
-
return
|
|
343
|
+
return;*/
|
|
339
344
|
default:
|
|
340
345
|
throw new Error("Invalid protocol");
|
|
341
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";
|
package/package.json
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@freesignal/protocol",
|
|
3
|
-
"version": "0.8.
|
|
4
|
-
"description": "Signal Protocol implementation in javascript",
|
|
5
|
-
"license": "GPL-3.0-or-later",
|
|
6
|
-
"author": "Christian Braghette",
|
|
7
|
-
"type": "module",
|
|
8
|
-
"exports": {
|
|
9
|
-
".": {
|
|
10
|
-
"import": "./dist/index.js",
|
|
11
|
-
"require": "./dist/index.js",
|
|
12
|
-
"types": "./dist/index.d.ts"
|
|
13
|
-
},
|
|
14
|
-
"./double-ratchet": {
|
|
15
|
-
"import": "./dist/double-ratchet.js",
|
|
16
|
-
"require": "./dist/double-ratchet.js",
|
|
17
|
-
"types": "./dist/double-ratchet.d.ts"
|
|
18
|
-
},
|
|
19
|
-
"./node": {
|
|
20
|
-
"import": "./dist/node.js",
|
|
21
|
-
"require": "./dist/node.js",
|
|
22
|
-
"types": "./dist/node.d.ts"
|
|
23
|
-
},
|
|
24
|
-
"./x3dh": {
|
|
25
|
-
"import": "./dist/x3dh.js",
|
|
26
|
-
"require": "./dist/x3dh.js",
|
|
27
|
-
"types": "./dist/x3dh.d.ts"
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
"main": "./dist/index.js",
|
|
31
|
-
"scripts": {
|
|
32
|
-
"pretest": "tsc",
|
|
33
|
-
"test": "node ./dist/test.js",
|
|
34
|
-
"prepare": "tsc"
|
|
35
|
-
},
|
|
36
|
-
"dependencies": {
|
|
37
|
-
"@freesignal/crypto": "^0.4.2",
|
|
38
|
-
"@freesignal/interfaces": "^0.3.0",
|
|
39
|
-
"@freesignal/utils": "^1.5.1",
|
|
40
|
-
"easyemitter.ts": "^1.1.0"
|
|
41
|
-
},
|
|
42
|
-
"devDependencies": {
|
|
43
|
-
"@types/node": "^24.2.1"
|
|
44
|
-
}
|
|
45
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@freesignal/protocol",
|
|
3
|
+
"version": "0.8.2",
|
|
4
|
+
"description": "Signal Protocol implementation in javascript",
|
|
5
|
+
"license": "GPL-3.0-or-later",
|
|
6
|
+
"author": "Christian Braghette",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
},
|
|
14
|
+
"./double-ratchet": {
|
|
15
|
+
"import": "./dist/double-ratchet.js",
|
|
16
|
+
"require": "./dist/double-ratchet.js",
|
|
17
|
+
"types": "./dist/double-ratchet.d.ts"
|
|
18
|
+
},
|
|
19
|
+
"./node": {
|
|
20
|
+
"import": "./dist/node.js",
|
|
21
|
+
"require": "./dist/node.js",
|
|
22
|
+
"types": "./dist/node.d.ts"
|
|
23
|
+
},
|
|
24
|
+
"./x3dh": {
|
|
25
|
+
"import": "./dist/x3dh.js",
|
|
26
|
+
"require": "./dist/x3dh.js",
|
|
27
|
+
"types": "./dist/x3dh.d.ts"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"main": "./dist/index.js",
|
|
31
|
+
"scripts": {
|
|
32
|
+
"pretest": "tsc",
|
|
33
|
+
"test": "node ./dist/test.js",
|
|
34
|
+
"prepare": "tsc"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@freesignal/crypto": "^0.4.2",
|
|
38
|
+
"@freesignal/interfaces": "^0.3.0",
|
|
39
|
+
"@freesignal/utils": "^1.5.1",
|
|
40
|
+
"easyemitter.ts": "^1.1.0"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@types/node": "^24.2.1"
|
|
44
|
+
}
|
|
45
|
+
}
|