@freesignal/protocol 0.4.5 → 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 CHANGED
@@ -65,6 +65,7 @@ export declare class FreeSignalNode {
65
65
  open(datagram: Datagram | Uint8Array): Promise<{
66
66
  header: DatagramHeader;
67
67
  payload?: Uint8Array;
68
+ datagram?: Datagram;
68
69
  }>;
69
70
  }
70
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,12 +219,12 @@ class FreeSignalNode {
218
219
  };
219
220
  }
220
221
  const response = { type: types_1.DiscoverType.RESPONSE, discoverId: message.discoverId, data };
221
- out.payload = (yield this.encrypt(datagram.sender, types_1.Protocols.DISCOVER, (0, utils_1.encodeData)(response))).toBytes();
222
+ out.datagram = yield this.encrypt(datagram.sender, types_1.Protocols.DISCOVER, (0, utils_1.encodeData)(response));
222
223
  }
223
224
  else if (message.type === types_1.DiscoverType.RESPONSE && this.discovers.has(message.discoverId)) {
224
225
  this.discovers.delete(message.discoverId);
225
226
  if (message.data)
226
- out.payload = (0, utils_1.encodeData)(message.data);
227
+ out.datagram = yield this.packHandshake(message.data);
227
228
  }
228
229
  return out;
229
230
  case types_1.Protocols.BOOTSTRAP:
@@ -236,12 +237,9 @@ class FreeSignalNode {
236
237
  this.onRequest(request);
237
238
  }
238
239
  ;
239
- const request = yield this.bootstraps.get(datagram.sender);
240
- if (request) {
241
- const data = yield request.get();
242
- if (data)
243
- out.payload = (0, utils_1.encodeData)(data);
244
- }
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);
245
243
  return out;
246
244
  default:
247
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 = datagram.id;
334
- datagram._version = datagram.version;
335
- datagram._createdAt = datagram._createdAt;
336
- datagram._signature = 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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@freesignal/protocol",
3
- "version": "0.4.5",
3
+ "version": "0.4.7",
4
4
  "description": "Signal Protocol implementation in javascript",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "author": "Christian Braghette",