@freesignal/protocol 0.7.9 → 0.7.11

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
@@ -24,27 +24,29 @@ import EventEmitter, { EventCallback } from "easyemitter.ts";
24
24
  export declare class BootstrapRequest extends EventEmitter<'change', BootstrapRequest> {
25
25
  #private;
26
26
  readonly senderId: UserId | string;
27
- private readonly keyExchangeData;
28
- constructor(senderId: UserId | string, keyExchangeData: KeyExchangeData);
27
+ readonly data: KeyExchangeData;
28
+ constructor(senderId: UserId | string, data: KeyExchangeData);
29
29
  onChange: EventCallback<BootstrapRequest, this>;
30
30
  get status(): "pending" | "accepted" | "denied";
31
- get data(): KeyExchangeData | undefined;
32
31
  accept(): void;
33
32
  deny(): void;
34
33
  }
35
- type NodeEventData = {
34
+ export type NodeEventData = {
36
35
  session?: KeySession;
37
36
  payload?: Uint8Array;
38
37
  datagram?: Datagram;
39
38
  request?: BootstrapRequest;
40
39
  userId?: UserId;
41
40
  };
42
- type SendEventData = {
41
+ export type HandshakeEventData = {
42
+ session: KeySession;
43
+ };
44
+ export type SendEventData = {
43
45
  session?: KeySession;
44
46
  datagram: Datagram;
45
47
  userId: UserId;
46
48
  };
47
- type MessageEventData = {
49
+ export type MessageEventData = {
48
50
  session: KeySession;
49
51
  payload: Uint8Array;
50
52
  };
package/dist/node.js CHANGED
@@ -51,10 +51,10 @@ const utils_1 = require("@freesignal/utils");
51
51
  const crypto_1 = __importDefault(require("@freesignal/crypto"));
52
52
  const easyemitter_ts_1 = __importDefault(require("easyemitter.ts"));
53
53
  class BootstrapRequest extends easyemitter_ts_1.default {
54
- constructor(senderId, keyExchangeData) {
54
+ constructor(senderId, data) {
55
55
  super();
56
56
  this.senderId = senderId;
57
- this.keyExchangeData = keyExchangeData;
57
+ this.data = data;
58
58
  _BootstrapRequest_status.set(this, 'pending');
59
59
  this.onChange = () => { };
60
60
  this.on('change', (data, emitter) => this.onChange(data, emitter));
@@ -62,18 +62,17 @@ class BootstrapRequest extends easyemitter_ts_1.default {
62
62
  get status() {
63
63
  return __classPrivateFieldGet(this, _BootstrapRequest_status, "f");
64
64
  }
65
- get data() {
66
- return __classPrivateFieldGet(this, _BootstrapRequest_status, "f") === 'accepted' ? this.keyExchangeData : undefined;
67
- }
68
65
  accept() {
69
- if (this.status === 'pending')
66
+ if (this.status === 'pending') {
70
67
  __classPrivateFieldSet(this, _BootstrapRequest_status, 'accepted', "f");
71
- this.emit('change', this);
68
+ this.emit('change', this);
69
+ }
72
70
  }
73
71
  deny() {
74
- if (this.status === 'pending')
72
+ if (this.status === 'pending') {
75
73
  __classPrivateFieldSet(this, _BootstrapRequest_status, 'denied', "f");
76
- this.emit('change', this);
74
+ this.emit('change', this);
75
+ }
77
76
  }
78
77
  }
79
78
  exports.BootstrapRequest = BootstrapRequest;
@@ -198,7 +197,7 @@ class FreeSignalNode {
198
197
  sendBootstrap(receiverId) {
199
198
  return __awaiter(this, void 0, void 0, function* () {
200
199
  //console.debug("Sending Bootstrap");
201
- if (receiverId && (yield this.sessions.has(receiverId.toString())))
200
+ if (yield this.sessions.has(receiverId.toString()))
202
201
  throw new Error("Session exists");
203
202
  const datagram = yield this.packBootstrap();
204
203
  this.emitter.emit('send', { datagram, userId: types_1.UserId.from(receiverId) });
@@ -326,10 +325,12 @@ class FreeSignalNode {
326
325
  const keyExchangeData = (0, utils_1.decodeData)(datagram.payload);
327
326
  const userId = types_1.UserId.fromKey(keyExchangeData.identityKey);
328
327
  const request = new BootstrapRequest(userId, keyExchangeData);
328
+ let sended = false;
329
329
  request.onChange = (request) => {
330
- if (!request.data)
331
- throw new Error("Error sending handshake");
332
- this.sendHandshake(request.data);
330
+ if (request.status === 'accepted' && !sended) {
331
+ sended = true;
332
+ this.sendHandshake(request.data);
333
+ }
333
334
  };
334
335
  yield this.bootstraps.set(userId.toString(), request);
335
336
  this.emitter.emit('bootstrap', { request });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@freesignal/protocol",
3
- "version": "0.7.9",
3
+ "version": "0.7.11",
4
4
  "description": "Signal Protocol implementation in javascript",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "author": "Christian Braghette",