@freesignal/protocol 0.4.6 → 0.4.7
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 +7 -12
- package/dist/test.js +7 -5
- package/dist/types.js +4 -4
- package/package.json +1 -1
package/dist/node.d.ts
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* along with this program. If not, see <https://www.gnu.org/licenses/>
|
|
18
18
|
*/
|
|
19
19
|
import { Database, LocalStorage, Crypto, KeyExchangeDataBundle, KeyExchangeData } from "@freesignal/interfaces";
|
|
20
|
-
import { Datagram, DatagramHeader,
|
|
20
|
+
import { Datagram, DatagramHeader, IdentityKey, PrivateIdentityKey, Protocols, UserId } from "./types";
|
|
21
21
|
import { KeyExchange } from "./x3dh";
|
|
22
22
|
import { ExportedKeySession, KeySession } from "./double-ratchet";
|
|
23
23
|
export declare class BootstrapRequest {
|
|
@@ -65,7 +65,7 @@ export declare class FreeSignalNode {
|
|
|
65
65
|
open(datagram: Datagram | Uint8Array): Promise<{
|
|
66
66
|
header: DatagramHeader;
|
|
67
67
|
payload?: Uint8Array;
|
|
68
|
-
|
|
68
|
+
datagram?: Datagram;
|
|
69
69
|
}>;
|
|
70
70
|
}
|
|
71
71
|
declare class SessionMap implements LocalStorage<string, KeySession> {
|
package/dist/node.js
CHANGED
|
@@ -168,6 +168,7 @@ class FreeSignalNode {
|
|
|
168
168
|
*/
|
|
169
169
|
open(datagram) {
|
|
170
170
|
return __awaiter(this, void 0, void 0, function* () {
|
|
171
|
+
var _a;
|
|
171
172
|
if (datagram instanceof Uint8Array)
|
|
172
173
|
datagram = types_1.Datagram.from(datagram);
|
|
173
174
|
let out = {
|
|
@@ -218,15 +219,12 @@ class FreeSignalNode {
|
|
|
218
219
|
};
|
|
219
220
|
}
|
|
220
221
|
const response = { type: types_1.DiscoverType.RESPONSE, discoverId: message.discoverId, data };
|
|
221
|
-
out.
|
|
222
|
-
out.discoverType = types_1.DiscoverType.REQUEST;
|
|
222
|
+
out.datagram = yield this.encrypt(datagram.sender, types_1.Protocols.DISCOVER, (0, utils_1.encodeData)(response));
|
|
223
223
|
}
|
|
224
224
|
else if (message.type === types_1.DiscoverType.RESPONSE && this.discovers.has(message.discoverId)) {
|
|
225
225
|
this.discovers.delete(message.discoverId);
|
|
226
|
-
if (message.data)
|
|
227
|
-
out.
|
|
228
|
-
out.discoverType = types_1.DiscoverType.RESPONSE;
|
|
229
|
-
}
|
|
226
|
+
if (message.data)
|
|
227
|
+
out.datagram = yield this.packHandshake(message.data);
|
|
230
228
|
}
|
|
231
229
|
return out;
|
|
232
230
|
case types_1.Protocols.BOOTSTRAP:
|
|
@@ -239,12 +237,9 @@ class FreeSignalNode {
|
|
|
239
237
|
this.onRequest(request);
|
|
240
238
|
}
|
|
241
239
|
;
|
|
242
|
-
const
|
|
243
|
-
if (
|
|
244
|
-
|
|
245
|
-
if (data)
|
|
246
|
-
out.payload = (0, utils_1.encodeData)(data);
|
|
247
|
-
}
|
|
240
|
+
const bootstrap = yield ((_a = (yield this.bootstraps.get(datagram.sender))) === null || _a === void 0 ? void 0 : _a.get());
|
|
241
|
+
if (bootstrap)
|
|
242
|
+
out.datagram = yield this.packHandshake(bootstrap);
|
|
248
243
|
return out;
|
|
249
244
|
default:
|
|
250
245
|
throw new Error("Invalid protocol");
|
package/dist/test.js
CHANGED
|
@@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const utils_1 = require("@freesignal/utils");
|
|
12
13
|
const _1 = require(".");
|
|
13
14
|
console.log("FreeSignal protocol test");
|
|
14
15
|
const bob = (0, _1.createNode)({ keyExchange: new _1.AsyncMap(), sessions: new _1.AsyncMap(), users: new _1.AsyncMap(), bundles: new _1.AsyncMap(), bootstraps: new _1.AsyncMap() });
|
|
@@ -16,22 +17,23 @@ const alice = (0, _1.createNode)({ keyExchange: new _1.AsyncMap(), sessions: new
|
|
|
16
17
|
setImmediate(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
18
|
const bobBootstrap = yield bob.packBootstrap(alice.userId);
|
|
18
19
|
alice.onRequest = (request) => { request.accept(); };
|
|
19
|
-
yield alice.open(bobBootstrap);
|
|
20
|
+
const test = (yield alice.open(bobBootstrap)).datagram;
|
|
21
|
+
console.log(_1.Datagram.from(test).toJSON());
|
|
20
22
|
const bobRequest = yield alice.getRequest(bob.userId.toString());
|
|
21
23
|
if (!bobRequest)
|
|
22
24
|
throw new Error("Bootstrap Failed");
|
|
23
25
|
const aliceHandshake = yield alice.packHandshake(bobRequest);
|
|
24
26
|
yield bob.open(aliceHandshake);
|
|
25
27
|
const first = (yield bob.packData(alice.userId, "Hi Alice!")).toBytes();
|
|
26
|
-
console.log("Bob: ", (yield alice.open(first)).payload);
|
|
28
|
+
console.log("Bob: ", (0, utils_1.decodeData)((yield alice.open(first)).payload));
|
|
27
29
|
const second = yield alice.packData(bob.userId, "Hi Bob!");
|
|
28
|
-
console.log("Alice: ", (yield bob.open(second)).payload);
|
|
30
|
+
console.log("Alice: ", (0, utils_1.decodeData)((yield bob.open(second)).payload));
|
|
29
31
|
const third = yield Promise.all(["How are you?", "How are this days?", "For me it's a good time"].map(msg => bob.packData(alice.userId, msg)));
|
|
30
32
|
third.forEach((data) => __awaiter(void 0, void 0, void 0, function* () {
|
|
31
|
-
console.log("Bob: ", (yield alice.open(data)).payload);
|
|
33
|
+
console.log("Bob: ", (0, utils_1.decodeData)((yield alice.open(data)).payload));
|
|
32
34
|
}));
|
|
33
35
|
const fourth = yield alice.packData(bob.userId, "Not so bad my man");
|
|
34
|
-
console.log("Alice: ", (yield bob.open(fourth)).payload);
|
|
36
|
+
console.log("Alice: ", (0, utils_1.decodeData)((yield bob.open(fourth)).payload));
|
|
35
37
|
//const testone = await Promise.all(Array(400).fill(0).map(() => alice.packData(bob.userId, decodeBase64(crypto.randomBytes(64)))));
|
|
36
38
|
//console.log(((await bob.open(testone[350])).payload));
|
|
37
39
|
}));
|
package/dist/types.js
CHANGED
|
@@ -330,10 +330,10 @@ class Datagram {
|
|
|
330
330
|
}
|
|
331
331
|
else if (data instanceof Datagram) {
|
|
332
332
|
const datagram = new Datagram(data.sender, data.receiver, data.protocol, data.payload);
|
|
333
|
-
datagram._id =
|
|
334
|
-
datagram._version =
|
|
335
|
-
datagram._createdAt =
|
|
336
|
-
datagram._signature =
|
|
333
|
+
datagram._id = data.id;
|
|
334
|
+
datagram._version = data.version;
|
|
335
|
+
datagram._createdAt = data._createdAt;
|
|
336
|
+
datagram._signature = data._signature;
|
|
337
337
|
return datagram;
|
|
338
338
|
}
|
|
339
339
|
else
|