@wireapp/core 34.0.1 → 34.1.0

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/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "./src/main/cryptography/AssetCryptography/crypto.node": "./src/main/cryptography/AssetCryptography/crypto.browser.js"
4
4
  },
5
5
  "dependencies": {
6
- "@wireapp/api-client": "^21.0.1",
6
+ "@wireapp/api-client": "^21.0.2",
7
7
  "@wireapp/commons": "^4.4.10",
8
8
  "@wireapp/core-crypto": "0.5.2",
9
9
  "@wireapp/cryptobox": "12.8.0",
@@ -64,6 +64,6 @@
64
64
  "test": "jest",
65
65
  "watch": "tsc ---watch"
66
66
  },
67
- "version": "34.0.1",
68
- "gitHead": "f9c46253d2c2f82cac2dda5cabc511d3c2d4a689"
67
+ "version": "34.1.0",
68
+ "gitHead": "d1769e7914896e9a730f264b8c4f90004d9986d9"
69
69
  }
@@ -1,5 +1,5 @@
1
1
  import { APIClient } from '@wireapp/api-client';
2
- import { PreKey as SerializedPreKey } from '@wireapp/api-client/src/auth/';
2
+ import { PreKey } from '@wireapp/api-client/src/auth/';
3
3
  import { RegisteredClient } from '@wireapp/api-client/src/client/';
4
4
  import { OTRRecipients, QualifiedOTRRecipients, QualifiedUserClients, UserClients } from '@wireapp/api-client/src/conversation/';
5
5
  import { ConversationOtrMessageAddEvent } from '@wireapp/api-client/src/event';
@@ -49,7 +49,7 @@ export declare class CryptographyService {
49
49
  onNewSession?: (sessionId: SessionId) => void;
50
50
  }): void;
51
51
  static convertBase64RecipientsToArray(recipients: OTRRecipients<string>): OTRRecipients<Uint8Array>;
52
- createCryptobox(entropyData?: Uint8Array): Promise<SerializedPreKey[]>;
52
+ createCryptobox(entropyData?: Uint8Array): Promise<PreKey[]>;
53
53
  decrypt(sessionId: string, encodedCiphertext: string): Promise<Uint8Array>;
54
54
  encryptQualified(plainText: Uint8Array, preKeyBundles: QualifiedUserPreKeyBundleMap | QualifiedUserClients): Promise<{
55
55
  missing: QualifiedUserClients;
@@ -61,6 +61,20 @@ export declare class CryptographyService {
61
61
  }>;
62
62
  private encryptPayloadForSession;
63
63
  initCryptobox(): Promise<void>;
64
+ /**
65
+ * Get the fingerprint of the local client.
66
+ */
67
+ getLocalFingerprint(): string;
68
+ /**
69
+ * Get the fingerprint of a remote client
70
+ * @param userId ID of user
71
+ * @param clientId ID of client
72
+ * @param prekey A prekey can be given to create a session if it doesn't already exist.
73
+ * If not provided and the session doesn't exists it will fetch a new prekey from the backend
74
+ */
75
+ getRemoteFingerprint(userId: QualifiedId, clientId: string, prekey?: PreKey): Promise<string>;
76
+ private getOrCreateSession;
77
+ private getUserPrekey;
64
78
  deleteCryptographyStores(): Promise<boolean[]>;
65
79
  resetSession(sessionId: string): Promise<void>;
66
80
  decryptMessage(otrMessage: ConversationOtrMessageAddEvent): Promise<GenericMessage>;
@@ -74,7 +74,7 @@ class CryptographyService {
74
74
  setCryptoboxHooks({ onNewPrekeys, onNewSession, }) {
75
75
  if (onNewPrekeys) {
76
76
  this.cryptobox.on(cryptobox_1.Cryptobox.TOPIC.NEW_PREKEYS, prekeys => {
77
- const serializedPreKeys = prekeys.map(this.cryptobox.serialize_prekey);
77
+ const serializedPreKeys = prekeys.map(prekey => this.cryptobox.serialize_prekey(prekey));
78
78
  onNewPrekeys(serializedPreKeys);
79
79
  });
80
80
  }
@@ -170,6 +170,37 @@ class CryptographyService {
170
170
  async initCryptobox() {
171
171
  await this.cryptobox.load();
172
172
  }
173
+ /**
174
+ * Get the fingerprint of the local client.
175
+ */
176
+ getLocalFingerprint() {
177
+ return this.cryptobox.getIdentity().public_key.fingerprint();
178
+ }
179
+ /**
180
+ * Get the fingerprint of a remote client
181
+ * @param userId ID of user
182
+ * @param clientId ID of client
183
+ * @param prekey A prekey can be given to create a session if it doesn't already exist.
184
+ * If not provided and the session doesn't exists it will fetch a new prekey from the backend
185
+ */
186
+ async getRemoteFingerprint(userId, clientId, prekey) {
187
+ const session = await this.getOrCreateSession(userId, clientId, prekey);
188
+ return session.fingerprint_remote();
189
+ }
190
+ async getOrCreateSession(userId, clientId, initialPrekey) {
191
+ const sessionId = this.constructSessionId(userId, clientId);
192
+ try {
193
+ return await this.cryptobox.session_load(sessionId);
194
+ }
195
+ catch (error) {
196
+ const prekey = initialPrekey !== null && initialPrekey !== void 0 ? initialPrekey : (await this.getUserPrekey(userId, clientId)).prekey;
197
+ const prekeyBuffer = bazinga64_1.Decoder.fromBase64(prekey.key).asBytes;
198
+ return this.cryptobox.session_from_prekey(sessionId, prekeyBuffer.buffer);
199
+ }
200
+ }
201
+ getUserPrekey(userId, clientId) {
202
+ return this.apiClient.api.user.getClientPreKey(userId, clientId);
203
+ }
173
204
  deleteCryptographyStores() {
174
205
  return this.database.deleteStores();
175
206
  }