@wireapp/core-crypto 2.0.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wireapp/core-crypto",
3
- "version": "2.0.0",
3
+ "version": "3.0.0",
4
4
  "description": "CoreCrypto bindings for the Web",
5
5
  "type": "module",
6
6
  "module": "platforms/web/corecrypto.js",
@@ -1,3 +1,23 @@
1
+ declare enum WirePolicy {
2
+ /**
3
+ * Handshake messages are never encrypted
4
+ */
5
+ Plaintext = 1,
6
+ /**
7
+ * Handshake messages are always encrypted
8
+ */
9
+ Ciphertext = 2
10
+ }
11
+ declare enum CredentialType {
12
+ /**
13
+ * Just a KeyPair
14
+ */
15
+ Basic = 1,
16
+ /**
17
+ * A certificate obtained through e2e identity enrollment process
18
+ */
19
+ X509 = 2
20
+ }
1
21
  declare enum Ciphersuite {
2
22
  /**
3
23
  * DH KEM x25519 | AES-GCM 128 | SHA2-256 | Ed25519
@@ -28,26 +48,6 @@ declare enum Ciphersuite {
28
48
  */
29
49
  MLS_256_DHKEMP384_AES256GCM_SHA384_P384 = 7
30
50
  }
31
- declare enum WirePolicy {
32
- /**
33
- * Handshake messages are never encrypted
34
- */
35
- Plaintext = 1,
36
- /**
37
- * Handshake messages are always encrypted
38
- */
39
- Ciphertext = 2
40
- }
41
- declare enum CredentialType {
42
- /**
43
- * Just a KeyPair
44
- */
45
- Basic = 1,
46
- /**
47
- * A certificate obtained through e2e identity enrollment process
48
- */
49
- X509 = 2
50
- }
51
51
  /**
52
52
  * For creating a challenge.
53
53
  * @see https://www.rfc-editor.org/rfc/rfc8555.html#section-7.5.1
@@ -437,6 +437,13 @@ declare class CoreCryptoContext {
437
437
  /**
438
438
  * Returns: [`WasmCryptoResult<()>`]
439
439
  *
440
+ * see [core_crypto::proteus::ProteusCentral::try_new]
441
+ * @returns {Promise<any>}
442
+ */
443
+ proteus_init(): Promise<any>;
444
+ /**
445
+ * Returns: [`WasmCryptoResult<()>`]
446
+ *
440
447
  * See [core_crypto::context::CentralContext::proteus_session_from_prekey]
441
448
  * @param {string} session_id
442
449
  * @param {Uint8Array} prekey
@@ -1281,6 +1288,10 @@ declare class CoreCryptoContext$1 {
1281
1288
  * @returns A `Uint8Array` buffer that contains `length` cryptographically-secure random bytes
1282
1289
  */
1283
1290
  randomBytes(length: number): Promise<Uint8Array>;
1291
+ /**
1292
+ * Initializes the proteus client
1293
+ */
1294
+ proteusInit(): Promise<void>;
1284
1295
  /**
1285
1296
  * Create a Proteus session using a prekey
1286
1297
  *
@@ -2661,6 +2672,9 @@ export declare class CoreCrypto {
2661
2672
  reseedRng(seed: Uint8Array): Promise<void>;
2662
2673
  /**
2663
2674
  * Initializes the proteus client
2675
+ *
2676
+ * @deprecated Create a transaction with {@link CoreCrypto.transaction}
2677
+ * and use {@link CoreCryptoContext.proteusInit} instead.
2664
2678
  */
2665
2679
  proteusInit(): Promise<void>;
2666
2680
  /**
@@ -187,7 +187,7 @@ function __wbg_adapter_54(arg0, arg1, arg2) {
187
187
  wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h5286e98832f56995(arg0, arg1, addHeapObject(arg2));
188
188
  }
189
189
  function __wbg_adapter_57(arg0, arg1, arg2) {
190
- wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h4499f6ce9f25a86a(arg0, arg1, addHeapObject(arg2));
190
+ wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hc681a33fe1ead8b3(arg0, arg1, addHeapObject(arg2));
191
191
  }
192
192
  function __wbg_adapter_60(arg0, arg1, arg2) {
193
193
  wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h2e1bdf8eee89b946(arg0, arg1, addHeapObject(arg2));
@@ -245,22 +245,7 @@ function handleError(f, args) {
245
245
  function __wbg_adapter_512(arg0, arg1, arg2, arg3) {
246
246
  wasm.wasm_bindgen__convert__closures__invoke2_mut__h5d1db9fa3036c038(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
247
247
  }
248
- var Ciphersuite = Object.freeze({
249
- MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519: 1,
250
- "1": "MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519",
251
- MLS_128_DHKEMP256_AES128GCM_SHA256_P256: 2,
252
- "2": "MLS_128_DHKEMP256_AES128GCM_SHA256_P256",
253
- MLS_128_DHKEMX25519_CHACHA20POLY1305_SHA256_Ed25519: 3,
254
- "3": "MLS_128_DHKEMX25519_CHACHA20POLY1305_SHA256_Ed25519",
255
- MLS_256_DHKEMX448_AES256GCM_SHA512_Ed448: 4,
256
- "4": "MLS_256_DHKEMX448_AES256GCM_SHA512_Ed448",
257
- MLS_256_DHKEMP521_AES256GCM_SHA512_P521: 5,
258
- "5": "MLS_256_DHKEMP521_AES256GCM_SHA512_P521",
259
- MLS_256_DHKEMX448_CHACHA20POLY1305_SHA512_Ed448: 6,
260
- "6": "MLS_256_DHKEMX448_CHACHA20POLY1305_SHA512_Ed448",
261
- MLS_256_DHKEMP384_AES256GCM_SHA384_P384: 7,
262
- "7": "MLS_256_DHKEMP384_AES256GCM_SHA384_P384"
263
- });
248
+ var CoreCryptoLogLevel = Object.freeze({ Off: 1, "1": "Off", Trace: 2, "2": "Trace", Debug: 3, "3": "Debug", Info: 4, "4": "Info", Warn: 5, "5": "Warn", Error: 6, "6": "Error" });
264
249
  var DeviceStatus = Object.freeze({
265
250
  Valid: 1,
266
251
  "1": "Valid",
@@ -269,7 +254,6 @@ var DeviceStatus = Object.freeze({
269
254
  Revoked: 3,
270
255
  "3": "Revoked"
271
256
  });
272
- var CoreCryptoLogLevel = Object.freeze({ Off: 1, "1": "Off", Trace: 2, "2": "Trace", Debug: 3, "3": "Debug", Info: 4, "4": "Info", Warn: 5, "5": "Warn", Error: 6, "6": "Error" });
273
257
  var WirePolicy = Object.freeze({
274
258
  Plaintext: 1,
275
259
  "1": "Plaintext",
@@ -282,6 +266,22 @@ var CredentialType = Object.freeze({
282
266
  X509: 2,
283
267
  "2": "X509"
284
268
  });
269
+ var Ciphersuite = Object.freeze({
270
+ MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519: 1,
271
+ "1": "MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519",
272
+ MLS_128_DHKEMP256_AES128GCM_SHA256_P256: 2,
273
+ "2": "MLS_128_DHKEMP256_AES128GCM_SHA256_P256",
274
+ MLS_128_DHKEMX25519_CHACHA20POLY1305_SHA256_Ed25519: 3,
275
+ "3": "MLS_128_DHKEMX25519_CHACHA20POLY1305_SHA256_Ed25519",
276
+ MLS_256_DHKEMX448_AES256GCM_SHA512_Ed448: 4,
277
+ "4": "MLS_256_DHKEMX448_AES256GCM_SHA512_Ed448",
278
+ MLS_256_DHKEMP521_AES256GCM_SHA512_P521: 5,
279
+ "5": "MLS_256_DHKEMP521_AES256GCM_SHA512_P521",
280
+ MLS_256_DHKEMX448_CHACHA20POLY1305_SHA512_Ed448: 6,
281
+ "6": "MLS_256_DHKEMX448_CHACHA20POLY1305_SHA512_Ed448",
282
+ MLS_256_DHKEMP384_AES256GCM_SHA384_P384: 7,
283
+ "7": "MLS_256_DHKEMP384_AES256GCM_SHA384_P384"
284
+ });
285
285
  var AcmeChallengeFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
286
286
  }, unregister: () => {
287
287
  } } : new FinalizationRegistry((ptr) => wasm.__wbg_acmechallenge_free(ptr >>> 0, 1));
@@ -870,10 +870,6 @@ class CoreCrypto {
870
870
  const ret = wasm.corecrypto_reseed_rng(this.__wbg_ptr, ptr0, len0);
871
871
  return takeObject(ret);
872
872
  }
873
- proteus_init() {
874
- const ret = wasm.corecrypto_proteus_init(this.__wbg_ptr);
875
- return takeObject(ret);
876
- }
877
873
  proteus_session_exists(session_id) {
878
874
  const ptr0 = passStringToWasm0(session_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
879
875
  const len0 = WASM_VECTOR_LEN;
@@ -1221,6 +1217,10 @@ class CoreCryptoContext {
1221
1217
  const ret = wasm.corecryptocontext_get_client_ids(this.__wbg_ptr, ptr0, len0);
1222
1218
  return takeObject(ret);
1223
1219
  }
1220
+ proteus_init() {
1221
+ const ret = wasm.corecryptocontext_proteus_init(this.__wbg_ptr);
1222
+ return takeObject(ret);
1223
+ }
1224
1224
  proteus_session_from_prekey(session_id, prekey) {
1225
1225
  const ptr0 = passStringToWasm0(session_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1226
1226
  const len0 = WASM_VECTOR_LEN;
@@ -2178,10 +2178,6 @@ function __wbg_get_imports() {
2178
2178
  imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
2179
2179
  takeObject(arg0);
2180
2180
  };
2181
- imports.wbg.__wbg_newacmeauthz_new = function(arg0) {
2182
- const ret = NewAcmeAuthz.__wrap(arg0);
2183
- return addHeapObject(ret);
2184
- };
2185
2181
  imports.wbg.__wbg_ffiwiree2eidentity_new = function(arg0) {
2186
2182
  const ret = FfiWireE2EIdentity.__wrap(arg0);
2187
2183
  return addHeapObject(ret);
@@ -2190,15 +2186,7 @@ function __wbg_get_imports() {
2190
2186
  const ret = arg0;
2191
2187
  return addHeapObject(ret);
2192
2188
  };
2193
- imports.wbg.__wbg_newacmeorder_new = function(arg0) {
2194
- const ret = NewAcmeOrder.__wrap(arg0);
2195
- return addHeapObject(ret);
2196
- };
2197
- imports.wbg.__wbindgen_bigint_from_u64 = function(arg0) {
2198
- const ret = BigInt.asUintN(64, arg0);
2199
- return addHeapObject(ret);
2200
- };
2201
- imports.wbg.__wbg_execute_0b146cfd7fac1205 = function() {
2189
+ imports.wbg.__wbg_execute_a85f95e9599e213e = function() {
2202
2190
  return handleError(function(arg0, arg1) {
2203
2191
  const ret = getObject(arg0).execute(CoreCryptoContext.__wrap(arg1));
2204
2192
  return addHeapObject(ret);
@@ -2208,14 +2196,26 @@ function __wbg_get_imports() {
2208
2196
  const ret = ProteusAutoPrekeyBundle.__wrap(arg0);
2209
2197
  return addHeapObject(ret);
2210
2198
  };
2211
- imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
2212
- const ret = getStringFromWasm0(arg0, arg1);
2199
+ imports.wbg.__wbg_newacmeorder_new = function(arg0) {
2200
+ const ret = NewAcmeOrder.__wrap(arg0);
2213
2201
  return addHeapObject(ret);
2214
2202
  };
2215
2203
  imports.wbg.__wbg_acmedirectory_new = function(arg0) {
2216
2204
  const ret = AcmeDirectory.__wrap(arg0);
2217
2205
  return addHeapObject(ret);
2218
2206
  };
2207
+ imports.wbg.__wbg_newacmeauthz_new = function(arg0) {
2208
+ const ret = NewAcmeAuthz.__wrap(arg0);
2209
+ return addHeapObject(ret);
2210
+ };
2211
+ imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
2212
+ const ret = getStringFromWasm0(arg0, arg1);
2213
+ return addHeapObject(ret);
2214
+ };
2215
+ imports.wbg.__wbindgen_bigint_from_u64 = function(arg0) {
2216
+ const ret = BigInt.asUintN(64, arg0);
2217
+ return addHeapObject(ret);
2218
+ };
2219
2219
  imports.wbg.__wbg_buffereddecryptedmessage_new = function(arg0) {
2220
2220
  const ret = BufferedDecryptedMessage.__wrap(arg0);
2221
2221
  return addHeapObject(ret);
@@ -2224,14 +2224,14 @@ function __wbg_get_imports() {
2224
2224
  const ret = CommitBundle.__wrap(arg0);
2225
2225
  return addHeapObject(ret);
2226
2226
  };
2227
- imports.wbg.__wbg_corecrypto_new = function(arg0) {
2228
- const ret = CoreCrypto.__wrap(arg0);
2229
- return addHeapObject(ret);
2230
- };
2231
2227
  imports.wbg.__wbg_proposalbundle_new = function(arg0) {
2232
2228
  const ret = ProposalBundle.__wrap(arg0);
2233
2229
  return addHeapObject(ret);
2234
2230
  };
2231
+ imports.wbg.__wbg_corecrypto_new = function(arg0) {
2232
+ const ret = CoreCrypto.__wrap(arg0);
2233
+ return addHeapObject(ret);
2234
+ };
2235
2235
  imports.wbg.__wbindgen_object_clone_ref = function(arg0) {
2236
2236
  const ret = getObject(arg0);
2237
2237
  return addHeapObject(ret);
@@ -2985,15 +2985,15 @@ function __wbg_get_imports() {
2985
2985
  const ret = v0;
2986
2986
  return addHeapObject(ret);
2987
2987
  };
2988
- imports.wbg.__wbindgen_closure_wrapper3708 = function(arg0, arg1, arg2) {
2988
+ imports.wbg.__wbindgen_closure_wrapper3710 = function(arg0, arg1, arg2) {
2989
2989
  const ret = makeMutClosure(arg0, arg1, 899, __wbg_adapter_54);
2990
2990
  return addHeapObject(ret);
2991
2991
  };
2992
- imports.wbg.__wbindgen_closure_wrapper13412 = function(arg0, arg1, arg2) {
2992
+ imports.wbg.__wbindgen_closure_wrapper13415 = function(arg0, arg1, arg2) {
2993
2993
  const ret = makeMutClosure(arg0, arg1, 2169, __wbg_adapter_57);
2994
2994
  return addHeapObject(ret);
2995
2995
  };
2996
- imports.wbg.__wbindgen_closure_wrapper15388 = function(arg0, arg1, arg2) {
2996
+ imports.wbg.__wbindgen_closure_wrapper15391 = function(arg0, arg1, arg2) {
2997
2997
  const ret = makeMutClosure(arg0, arg1, 2396, __wbg_adapter_60);
2998
2998
  return addHeapObject(ret);
2999
2999
  };
@@ -3298,6 +3298,9 @@ class CoreCryptoContext2 {
3298
3298
  async randomBytes(length) {
3299
3299
  return await CoreCryptoError.asyncMapErr(this.#ctx.random_bytes(length));
3300
3300
  }
3301
+ async proteusInit() {
3302
+ return await CoreCryptoError.asyncMapErr(this.#ctx.proteus_init());
3303
+ }
3301
3304
  async proteusSessionFromPrekey(sessionId, prekey) {
3302
3305
  return await CoreCryptoError.asyncMapErr(this.#ctx.proteus_session_from_prekey(sessionId, prekey));
3303
3306
  }
@@ -3650,21 +3653,20 @@ class CoreCrypto2 {
3650
3653
  let result;
3651
3654
  let error = null;
3652
3655
  try {
3653
- await this.#cc.transaction({
3656
+ await CoreCryptoError.asyncMapErr(this.#cc.transaction({
3654
3657
  execute: async (ctx) => {
3655
3658
  try {
3656
- result = await callback(CoreCryptoContext2.fromFfiContext(ctx));
3659
+ result = await CoreCryptoError.asyncMapErr(callback(CoreCryptoContext2.fromFfiContext(ctx)));
3657
3660
  } catch (e) {
3658
- if (e instanceof CoreCryptoError) {
3659
- error = e;
3660
- } else {
3661
- error = CoreCryptoError.fromStdError(e);
3662
- }
3661
+ error = e;
3663
3662
  throw error;
3664
3663
  }
3665
3664
  }
3666
- });
3667
- } catch (_) {
3665
+ }));
3666
+ } catch (e) {
3667
+ if (error === null) {
3668
+ error = e;
3669
+ }
3668
3670
  }
3669
3671
  if (error !== null) {
3670
3672
  throw error;
@@ -3797,7 +3799,7 @@ class CoreCrypto2 {
3797
3799
  return await CoreCryptoError.asyncMapErr(this.#cc.reseed_rng(seed));
3798
3800
  }
3799
3801
  async proteusInit() {
3800
- return await CoreCryptoError.asyncMapErr(this.#cc.proteus_init());
3802
+ return await this.transaction(async (ctx) => await ctx.proteusInit());
3801
3803
  }
3802
3804
  async proteusSessionFromPrekey(sessionId, prekey) {
3803
3805
  return await this.transaction(async (ctx) => await ctx.proteusSessionFromPrekey(sessionId, prekey));