@freesignal/protocol 0.7.5 → 0.7.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
@@ -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;
@@ -83,6 +83,7 @@ export declare class FreeSignalNode {
83
83
  sendRelay(relayId: string | UserId, receiverId: string | UserId, data: Datagram): Promise<void>;
84
84
  sendPing(receiverId: string | UserId): Promise<void>;
85
85
  sendDiscover(receiverId: string | UserId, discoverId: string | UserId): Promise<void>;
86
+ packBootstrap(): Promise<Datagram>;
86
87
  sendBootstrap(receiverId: string | UserId): Promise<void>;
87
88
  protected decrypt(datagram: EncryptedDatagram | Datagram | Uint8Array): Promise<MessageEventData>;
88
89
  protected open(datagram: Datagram | EncryptedDatagram | Uint8Array): Promise<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 = () => { };
@@ -190,12 +190,17 @@ class FreeSignalNode {
190
190
  this.emitter.emit('send', yield this.encrypt(receiverId, types_1.Protocols.DISCOVER, (0, utils_1.encodeData)(message)));
191
191
  });
192
192
  }
193
+ packBootstrap() {
194
+ return __awaiter(this, void 0, void 0, function* () {
195
+ return new types_1.Datagram(types_1.Protocols.BOOTSTRAP, (0, utils_1.encodeData)(yield this.keyExchange.generateData()));
196
+ });
197
+ }
193
198
  sendBootstrap(receiverId) {
194
199
  return __awaiter(this, void 0, void 0, function* () {
195
200
  //console.debug("Sending Bootstrap");
196
- if (yield this.sessions.has(receiverId.toString()))
201
+ if (receiverId && (yield this.sessions.has(receiverId.toString())))
197
202
  throw new Error("Session exists");
198
- const datagram = new types_1.Datagram(types_1.Protocols.BOOTSTRAP, (0, utils_1.encodeData)(yield this.keyExchange.generateData()));
203
+ const datagram = yield this.packBootstrap();
199
204
  this.emitter.emit('send', { datagram, userId: types_1.UserId.from(receiverId) });
200
205
  });
201
206
  }
@@ -309,11 +314,10 @@ class FreeSignalNode {
309
314
  const keyExchangeData = (0, utils_1.decodeData)(datagram.payload);
310
315
  const userId = types_1.UserId.fromKey(keyExchangeData.identityKey);
311
316
  const request = new BootstrapRequest(userId, keyExchangeData);
312
- request.onChange = (event) => {
313
- var _a;
317
+ request.onChange = (request) => {
314
318
  if (!request.data)
315
319
  throw new Error("Error sending handshake");
316
- this.sendHandshake((_a = event.data) === null || _a === void 0 ? void 0 : _a.data);
320
+ this.sendHandshake(request.data);
317
321
  };
318
322
  yield this.bootstraps.set(userId.toString(), request);
319
323
  this.emitter.emit('bootstrap', { request });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@freesignal/protocol",
3
- "version": "0.7.5",
3
+ "version": "0.7.7",
4
4
  "description": "Signal Protocol implementation in javascript",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "author": "Christian Braghette",