@freesignal/protocol 0.7.4 → 0.7.6

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
@@ -20,13 +20,13 @@ import { Database, LocalStorage, Crypto, KeyExchangeDataBundle, KeyExchangeData
20
20
  import { Datagram, EncryptedDatagram, IdentityKey, PrivateIdentityKey, Protocols, UserId } from "./types";
21
21
  import { KeyExchange } from "./x3dh";
22
22
  import { ExportedKeySession, KeySession } from "./double-ratchet";
23
- import EventEmitter, { EventCall } from "easyemitter.ts";
23
+ 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
27
  private readonly keyExchangeData;
28
28
  constructor(senderId: UserId | string, keyExchangeData: KeyExchangeData);
29
- onChange: EventCall<'change', BootstrapRequest>;
29
+ onChange: EventCallback<BootstrapRequest, this>;
30
30
  get status(): "pending" | "accepted" | "denied";
31
31
  get data(): KeyExchangeData | undefined;
32
32
  accept(): void;
@@ -64,10 +64,10 @@ export declare class FreeSignalNode {
64
64
  bundles: LocalStorage<string, KeyExchangeDataBundle>;
65
65
  bootstraps: LocalStorage<string, BootstrapRequest>;
66
66
  }>, privateIdentityKey?: PrivateIdentityKey);
67
- protected messageHandler: EventCall<"message", NodeEventData>;
68
- protected sendHandler: EventCall<"send", NodeEventData>;
69
- protected handshakeHandler: EventCall<"handshake", NodeEventData>;
70
- protected bootstrapHandler: EventCall<"bootstrap", NodeEventData>;
67
+ protected messageHandler: EventCallback<NodeEventData, typeof this.emitter>;
68
+ protected sendHandler: EventCallback<NodeEventData, typeof this.emitter>;
69
+ protected handshakeHandler: EventCallback<NodeEventData, typeof this.emitter>;
70
+ protected bootstrapHandler: EventCallback<NodeEventData, typeof this.emitter>;
71
71
  onMessage: (data: MessageEventData) => void;
72
72
  onSend: (data: Uint8Array) => void;
73
73
  onHandshake: (userId: UserId) => void;
package/dist/node.js CHANGED
@@ -57,7 +57,7 @@ class BootstrapRequest extends easyemitter_ts_1.default {
57
57
  this.keyExchangeData = keyExchangeData;
58
58
  _BootstrapRequest_status.set(this, 'pending');
59
59
  this.onChange = () => { };
60
- this.on('change', (data) => this.onChange(data));
60
+ this.on('change', (data, emitter) => this.onChange(data, emitter));
61
61
  }
62
62
  get status() {
63
63
  return __classPrivateFieldGet(this, _BootstrapRequest_status, "f");
@@ -82,10 +82,10 @@ class FreeSignalNode {
82
82
  constructor(storage, privateIdentityKey) {
83
83
  this.discovers = new Set();
84
84
  this.emitter = new easyemitter_ts_1.default();
85
- this.messageHandler = (data) => { var _a, _b; return this.onMessage({ session: (_a = data.data) === null || _a === void 0 ? void 0 : _a.session, payload: (_b = data.data) === null || _b === void 0 ? void 0 : _b.payload }); };
86
- this.sendHandler = (data) => this.onSend(data.data.datagram.toBytes());
87
- this.handshakeHandler = (data) => { var _a, _b; return this.onHandshake(types_1.UserId.from((_b = (_a = data.data) === null || _a === void 0 ? void 0 : _a.session) === null || _b === void 0 ? void 0 : _b.userId)); };
88
- this.bootstrapHandler = (data) => { var _a; return this.onRequest((_a = data.data) === null || _a === void 0 ? void 0 : _a.request); };
85
+ this.messageHandler = (data) => this.onMessage({ session: data.session, payload: data.payload });
86
+ this.sendHandler = (data) => this.onSend(data.datagram.toBytes());
87
+ this.handshakeHandler = (data) => { var _a; return this.onHandshake(types_1.UserId.from((_a = data.session) === null || _a === void 0 ? void 0 : _a.userId)); };
88
+ this.bootstrapHandler = (data) => this.onRequest(data.request);
89
89
  this.onMessage = () => { };
90
90
  this.onSend = () => { };
91
91
  this.onHandshake = () => { };
@@ -138,7 +138,7 @@ class FreeSignalNode {
138
138
  //console.debug("Sending Handshake Ack");
139
139
  const session = yield this.sessions.get(data.sessionTag);
140
140
  if (!session)
141
- throw new Error("Session not found for user: " + data);
141
+ throw new Error("Session not found for sessionTag: " + data.sessionTag);
142
142
  this.emitter.emit('send', yield this.encrypt(session.userId, types_1.Protocols.HANDSHAKE, crypto_1.default.ECDH.scalarMult(this.privateIdentityKey.exchangeKey, session.identityKey.exchangeKey)));
143
143
  return;
144
144
  }
@@ -262,7 +262,7 @@ class FreeSignalNode {
262
262
  const session = yield this.sessions.get(sessionTag);
263
263
  if (!session)
264
264
  throw new Error("Session not found for sessionTag: " + datagram.sessionTag);
265
- this.emitter.emit('send', { session, payload: opened.payload.slice(types_1.UserId.keyLength), userId: session.userId });
265
+ this.emitter.emit('send', { session, datagram: types_1.Datagram.from(opened.payload.slice(types_1.UserId.keyLength)), userId: session.userId });
266
266
  return;
267
267
  }
268
268
  case types_1.Protocols.DISCOVER: {
@@ -309,11 +309,10 @@ class FreeSignalNode {
309
309
  const keyExchangeData = (0, utils_1.decodeData)(datagram.payload);
310
310
  const userId = types_1.UserId.fromKey(keyExchangeData.identityKey);
311
311
  const request = new BootstrapRequest(userId, keyExchangeData);
312
- request.onChange = (event) => {
313
- var _a;
312
+ request.onChange = (request) => {
314
313
  if (!request.data)
315
314
  throw new Error("Error sending handshake");
316
- this.sendHandshake((_a = event.data) === null || _a === void 0 ? void 0 : _a.data);
315
+ this.sendHandshake(request.data);
317
316
  };
318
317
  yield this.bootstraps.set(userId.toString(), request);
319
318
  this.emitter.emit('bootstrap', { request });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@freesignal/protocol",
3
- "version": "0.7.4",
3
+ "version": "0.7.6",
4
4
  "description": "Signal Protocol implementation in javascript",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "author": "Christian Braghette",