@wireapp/core-crypto 0.6.0-rc.6 → 0.6.0-rc.8

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wireapp/core-crypto",
3
- "version": "0.6.0-rc.6",
3
+ "version": "0.6.0-rc.8",
4
4
  "description": "CoreCrypto bindings for the Web",
5
5
  "type": "module",
6
6
  "module": "platforms/web/corecrypto.js",
@@ -1,124 +1,3 @@
1
- declare class FfiWireE2EIdentity {
2
- free(): void;
3
- /**
4
- * See [core_crypto::e2e_identity::WireE2eIdentity::directory_response]
5
- * @param {Uint8Array} directory
6
- * @returns {any}
7
- */
8
- directory_response(directory: Uint8Array): any;
9
- /**
10
- * See [core_crypto::e2e_identity::WireE2eIdentity::new_account_request]
11
- * @param {any} directory
12
- * @param {string} previous_nonce
13
- * @returns {Uint8Array}
14
- */
15
- new_account_request(directory: any, previous_nonce: string): Uint8Array;
16
- /**
17
- * See [core_crypto::e2e_identity::WireE2eIdentity::new_account_response]
18
- * @param {Uint8Array} account
19
- * @returns {Uint8Array}
20
- */
21
- new_account_response(account: Uint8Array): Uint8Array;
22
- /**
23
- * See [core_crypto::e2e_identity::WireE2eIdentity::new_order_request]
24
- * @param {string} handle
25
- * @param {string} client_id
26
- * @param {number} expiry_days
27
- * @param {any} directory
28
- * @param {Uint8Array} account
29
- * @param {string} previous_nonce
30
- * @returns {Uint8Array}
31
- */
32
- new_order_request(handle: string, client_id: string, expiry_days: number, directory: any, account: Uint8Array, previous_nonce: string): Uint8Array;
33
- /**
34
- * See [core_crypto::e2e_identity::WireE2eIdentity::new_order_response]
35
- * @param {Uint8Array} order
36
- * @returns {any}
37
- */
38
- new_order_response(order: Uint8Array): any;
39
- /**
40
- * See [core_crypto::e2e_identity::WireE2eIdentity::new_authz_request]
41
- * @param {string} url
42
- * @param {Uint8Array} account
43
- * @param {string} previous_nonce
44
- * @returns {Uint8Array}
45
- */
46
- new_authz_request(url: string, account: Uint8Array, previous_nonce: string): Uint8Array;
47
- /**
48
- * See [core_crypto::e2e_identity::WireE2eIdentity::new_authz_response]
49
- * @param {Uint8Array} authz
50
- * @returns {any}
51
- */
52
- new_authz_response(authz: Uint8Array): any;
53
- /**
54
- * See [core_crypto::e2e_identity::WireE2eIdentity::create_dpop_token]
55
- * @param {string} access_token_url
56
- * @param {string} user_id
57
- * @param {bigint} client_id
58
- * @param {string} domain
59
- * @param {any} client_id_challenge
60
- * @param {string} backend_nonce
61
- * @param {number} expiry_days
62
- * @returns {string}
63
- */
64
- create_dpop_token(access_token_url: string, user_id: string, client_id: bigint, domain: string, client_id_challenge: any, backend_nonce: string, expiry_days: number): string;
65
- /**
66
- * See [core_crypto::e2e_identity::WireE2eIdentity::new_challenge_request]
67
- * @param {any} handle_challenge
68
- * @param {Uint8Array} account
69
- * @param {string} previous_nonce
70
- * @returns {Uint8Array}
71
- */
72
- new_challenge_request(handle_challenge: any, account: Uint8Array, previous_nonce: string): Uint8Array;
73
- /**
74
- * See [core_crypto::e2e_identity::WireE2eIdentity::new_challenge_response]
75
- * @param {Uint8Array} challenge
76
- */
77
- new_challenge_response(challenge: Uint8Array): void;
78
- /**
79
- * See [core_crypto::e2e_identity::WireE2eIdentity::check_order_request]
80
- * @param {string} order_url
81
- * @param {Uint8Array} account
82
- * @param {string} previous_nonce
83
- * @returns {Uint8Array}
84
- */
85
- check_order_request(order_url: string, account: Uint8Array, previous_nonce: string): Uint8Array;
86
- /**
87
- * See [core_crypto::e2e_identity::WireE2eIdentity::check_order_response]
88
- * @param {Uint8Array} order
89
- * @returns {Uint8Array}
90
- */
91
- check_order_response(order: Uint8Array): Uint8Array;
92
- /**
93
- * See [core_crypto::e2e_identity::WireE2eIdentity::finalize_request]
94
- * @param {(Uint8Array)[]} domains
95
- * @param {Uint8Array} order
96
- * @param {Uint8Array} account
97
- * @param {string} previous_nonce
98
- * @returns {Uint8Array}
99
- */
100
- finalize_request(domains: (Uint8Array)[], order: Uint8Array, account: Uint8Array, previous_nonce: string): Uint8Array;
101
- /**
102
- * See [core_crypto::e2e_identity::WireE2eIdentity::finalize_response]
103
- * @param {Uint8Array} finalize
104
- * @returns {any}
105
- */
106
- finalize_response(finalize: Uint8Array): any;
107
- /**
108
- * See [core_crypto::e2e_identity::WireE2eIdentity::certificate_request]
109
- * @param {any} finalize
110
- * @param {Uint8Array} account
111
- * @param {string} previous_nonce
112
- * @returns {Uint8Array}
113
- */
114
- certificate_request(finalize: any, account: Uint8Array, previous_nonce: string): Uint8Array;
115
- /**
116
- * See [core_crypto::e2e_identity::WireE2eIdentity::certificate_response]
117
- * @param {string} certificate_chain
118
- * @returns {(Uint8Array)[]}
119
- */
120
- certificate_response(certificate_chain: string): (Uint8Array)[];
121
- }
122
1
  /**
123
2
  * Error wrapper that takes care of extracting rich error details across the FFI (through JSON parsing)
124
3
  *
@@ -529,7 +408,7 @@ export interface CoreCryptoCallbacks {
529
408
  * @param clientId - id of the client performing an operation requiring authorization
530
409
  * @returns whether the user is authorized by the logic layer to perform the operation
531
410
  */
532
- authorize: (conversationId: Uint8Array, clientId: Uint8Array) => boolean;
411
+ authorize: (conversationId: Uint8Array, clientId: Uint8Array) => Promise<boolean>;
533
412
  /**
534
413
  * A mix between {@link authorize} and {@link clientIsExistingGroupUser}. We currently use this callback to verify
535
414
  * external commits to join a group ; in such case, the client has to:
@@ -541,7 +420,7 @@ export interface CoreCryptoCallbacks {
541
420
  * @param existingClients - all the clients currently within the MLS group
542
421
  * @returns true if the external client is authorized to write to the conversation
543
422
  */
544
- userAuthorize: (conversationId: Uint8Array, externalClientId: Uint8Array, existingClients: Uint8Array[]) => boolean;
423
+ userAuthorize: (conversationId: Uint8Array, externalClientId: Uint8Array, existingClients: Uint8Array[]) => Promise<boolean>;
545
424
  /**
546
425
  * Callback to ensure that the given `clientId` belongs to one of the provided `existingClients`
547
426
  * This basically allows to defer the client ID parsing logic to the caller - because CoreCrypto is oblivious to such things
@@ -550,7 +429,7 @@ export interface CoreCryptoCallbacks {
550
429
  * @param clientId - id of a client
551
430
  * @param existingClients - all the clients currently within the MLS group
552
431
  */
553
- clientIsExistingGroupUser: (conversationId: Uint8Array, clientId: Uint8Array, existingClients: Uint8Array[]) => boolean;
432
+ clientIsExistingGroupUser: (conversationId: Uint8Array, clientId: Uint8Array, existingClients: Uint8Array[]) => Promise<boolean>;
554
433
  }
555
434
  /**
556
435
  * Wrapper for the WASM-compiled version of CoreCrypto
@@ -605,6 +484,22 @@ export declare class CoreCrypto {
605
484
  * @param clientId - {@link CoreCryptoParams#clientId} but required
606
485
  */
607
486
  mlsInit(clientId: ClientId): Promise<void>;
487
+ /**
488
+ * Generates a MLS KeyPair/CredentialBundle with a temporary, random client ID.
489
+ * This method is designed to be used in conjunction with {@link CoreCrypto.mlsInitWithClientID} and represents the first step in this process
490
+ *
491
+ * @returns This returns the TLS-serialized identity key (i.e. the signature keypair's public key)
492
+ */
493
+ mlsGenerateKeypair(): Promise<Uint8Array>;
494
+ /**
495
+ * Updates the current temporary Client ID with the newly provided one. This is the second step in the externally-generated clients process
496
+ *
497
+ * Important: This is designed to be called after {@link CoreCrypto.mlsGenerateKeyPair}
498
+ *
499
+ * @param clientId - The newly-allocated client ID by the MLS Authentication Service
500
+ * @param signaturePublicKey - The public key you were given at the first step; This is for authentication purposes
501
+ */
502
+ mlsInitWithClientId(clientId: ClientId, signaturePublicKey: Uint8Array): Promise<void>;
608
503
  /** @hidden */
609
504
  private constructor();
610
505
  /**
@@ -624,7 +519,7 @@ export declare class CoreCrypto {
624
519
  *
625
520
  * @param callbacks - Any interface following the {@link CoreCryptoCallbacks} interface
626
521
  */
627
- registerCallbacks(callbacks: CoreCryptoCallbacks): void;
522
+ registerCallbacks(callbacks: CoreCryptoCallbacks, ctx?: any): Promise<void>;
628
523
  /**
629
524
  * Checks if the Client is member of a given conversation and if the MLS Group is loaded up
630
525
  *
@@ -952,9 +847,19 @@ export declare class CoreCrypto {
952
847
  /**
953
848
  * Creates a new prekey with an automatically generated ID..
954
849
  *
955
- * @returns: A CBOR-serialized version of the PreKeyBundle corresponding to the newly generated and stored PreKey
850
+ * @returns A CBOR-serialized version of the PreKeyBundle corresponding to the newly generated and stored PreKey
956
851
  */
957
852
  proteusNewPrekeyAuto(): Promise<Uint8Array>;
853
+ /**
854
+ * Proteus last resort prekey stuff
855
+ *
856
+ * @returns A CBOR-serialize version of the PreKeyBundle associated with the last resort PreKey (holding the last resort prekey id)
857
+ */
858
+ proteusLastResortPrekey(): Promise<Uint8Array>;
859
+ /**
860
+ * @returns The last resort PreKey id
861
+ */
862
+ static proteusLastResortPrekeyId(): number;
958
863
  /**
959
864
  * Proteus public key fingerprint
960
865
  * It's basically the public key encoded as an hex string
@@ -997,12 +902,12 @@ export declare class CoreCrypto {
997
902
  /**
998
903
  * Creates an enrollment instance with private key material you can use in order to fetch
999
904
  * a new x509 certificate from the acme server.
1000
- * Make sure to call [WireE2eIdentity::free] (not yet available) to dispose this instance and its associated
905
+ * Make sure to call {@link WireE2eIdentity.free} to dispose this instance and its associated
1001
906
  * keying material.
1002
907
  *
1003
908
  * @param ciphersuite - For generating signing key material. Only {@link Ciphersuite.MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519} is supported currently
1004
909
  */
1005
- newAcmeEnrollment(): Promise<WireE2eIdentity>;
910
+ newAcmeEnrollment(ciphersuite?: Ciphersuite): Promise<WireE2eIdentity>;
1006
911
  /**
1007
912
  * Returns the current version of {@link CoreCrypto}
1008
913
  *
@@ -1016,7 +921,8 @@ type AcmeOrder = Uint8Array;
1016
921
  export declare class WireE2eIdentity {
1017
922
  #private;
1018
923
  /** @hidden */
1019
- constructor(e2ei: CoreCryptoFfiTypes.FfiWireE2EIdentity);
924
+ constructor(e2ei: unknown);
925
+ free(): void;
1020
926
  /**
1021
927
  * Parses the response from `GET /acme/{provisioner-name}/directory`.
1022
928
  * Use this {@link AcmeDirectory} in the next step to fetch the first nonce from the acme server. Use
@@ -1133,13 +1039,13 @@ export declare class WireE2eIdentity {
1133
1039
  /**
1134
1040
  * Final step before fetching the certificate.
1135
1041
  *
1136
- * @param domains you want to generate a certificate for e.g. `["wire.com"]`
1137
- * @param order you got from {@link checkOrderResponse}
1138
- * @param account you found after {@link newAccountResponse}
1139
- * @param previousNonce `replay-nonce` response header from `POST /acme/{provisioner-name}/order/{order-id}`
1042
+ * @param domains - domains you want to generate a certificate for e.g. `["wire.com"]`
1043
+ * @param order - order you got from {@link checkOrderResponse}
1044
+ * @param account - account you found after {@link newAccountResponse}
1045
+ * @param previousNonce - `replay-nonce` response header from `POST /acme/{provisioner-name}/order/{order-id}`
1140
1046
  * @see https://www.rfc-editor.org/rfc/rfc8555.html#section-7.4
1141
1047
  */
1142
- finalizeRequest(domains: Uint8Array[], order: AcmeOrder, account: AcmeAccount, previousNonce: string): JsonRawData;
1048
+ finalizeRequest(domains: string[], order: AcmeOrder, account: AcmeAccount, previousNonce: string): JsonRawData;
1143
1049
  /**
1144
1050
  * Parses the response from `POST /acme/{provisioner-name}/order/{order-id}/finalize`.
1145
1051
  *
@@ -228,7 +228,7 @@ function makeMutClosure(arg0, arg1, dtor, f) {
228
228
  function __wbg_adapter_52(arg0, arg1, arg2) {
229
229
  try {
230
230
  const retptr = wasm$1.__wbindgen_add_to_stack_pointer(-16);
231
- wasm$1._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h017e8b5914b4ce6e(retptr, arg0, arg1, addHeapObject(arg2));
231
+ wasm$1._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h0b669391a1ca469a(retptr, arg0, arg1, addHeapObject(arg2));
232
232
  var r0 = getInt32Memory0()[retptr / 4 + 0];
233
233
  var r1 = getInt32Memory0()[retptr / 4 + 1];
234
234
  if (r1) {
@@ -240,7 +240,7 @@ function __wbg_adapter_52(arg0, arg1, arg2) {
240
240
  }
241
241
  }
242
242
  function __wbg_adapter_55(arg0, arg1, arg2) {
243
- wasm$1._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h2cd85c49913904d9(arg0, arg1, addHeapObject(arg2));
243
+ wasm$1._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__ha3d8e2730fb8635e(arg0, arg1, addHeapObject(arg2));
244
244
  }
245
245
  function _assertClass(instance, klass) {
246
246
  if (!(instance instanceof klass)) {
@@ -279,23 +279,6 @@ function getArrayJsValueFromWasm0(ptr, len) {
279
279
  }
280
280
  return result;
281
281
  }
282
- /**
283
- * Returns the current version of CoreCrypto
284
- * @returns {string}
285
- */
286
- function version() {
287
- try {
288
- const retptr = wasm$1.__wbindgen_add_to_stack_pointer(-16);
289
- wasm$1.version(retptr);
290
- var r0 = getInt32Memory0()[retptr / 4 + 0];
291
- var r1 = getInt32Memory0()[retptr / 4 + 1];
292
- return getStringFromWasm0(r0, r1);
293
- }
294
- finally {
295
- wasm$1.__wbindgen_add_to_stack_pointer(16);
296
- wasm$1.__wbindgen_free(r0, r1);
297
- }
298
- }
299
282
  function handleError(f, args) {
300
283
  try {
301
284
  return f.apply(this, args);
@@ -307,8 +290,8 @@ function handleError(f, args) {
307
290
  function getArrayU8FromWasm0(ptr, len) {
308
291
  return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len);
309
292
  }
310
- function __wbg_adapter_263(arg0, arg1, arg2, arg3) {
311
- wasm$1.wasm_bindgen__convert__closures__invoke2_mut__h8cd39efe380c2d83(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
293
+ function __wbg_adapter_271(arg0, arg1, arg2, arg3) {
294
+ wasm$1.wasm_bindgen__convert__closures__invoke2_mut__h191981cd1d6b08cc(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
312
295
  }
313
296
  /**
314
297
  * see [core_crypto::prelude::MlsWirePolicy]
@@ -659,6 +642,23 @@ let CoreCrypto$1 = class CoreCrypto {
659
642
  wasm$1.__wbg_corecrypto_free(ptr);
660
643
  }
661
644
  /**
645
+ * Returns the current version of CoreCrypto
646
+ * @returns {string}
647
+ */
648
+ static version() {
649
+ try {
650
+ const retptr = wasm$1.__wbindgen_add_to_stack_pointer(-16);
651
+ wasm$1.corecrypto_version(retptr);
652
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
653
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
654
+ return getStringFromWasm0(r0, r1);
655
+ }
656
+ finally {
657
+ wasm$1.__wbindgen_add_to_stack_pointer(16);
658
+ wasm$1.__wbindgen_free(r0, r1);
659
+ }
660
+ }
661
+ /**
662
662
  * see [core_crypto::MlsCentral::try_new]
663
663
  * @param {string} path
664
664
  * @param {string} key
@@ -707,6 +707,32 @@ let CoreCrypto$1 = class CoreCrypto {
707
707
  return takeObject(ret);
708
708
  }
709
709
  /**
710
+ * Returns [`WasmCryptoResult<Vec<u8>>`]
711
+ *
712
+ * See [core_crypto::MlsCentral::mls_generate_keypair]
713
+ * @returns {Promise<any>}
714
+ */
715
+ mls_generate_keypair() {
716
+ const ret = wasm$1.corecrypto_mls_generate_keypair(this.ptr);
717
+ return takeObject(ret);
718
+ }
719
+ /**
720
+ * Returns [`WasmCryptoResult<()>`]
721
+ *
722
+ * See [core_crypto::MlsCentral::mls_init_with_client_id]
723
+ * @param {Uint8Array} client_id
724
+ * @param {Uint8Array} signature_public_key
725
+ * @returns {Promise<any>}
726
+ */
727
+ mls_init_with_client_id(client_id, signature_public_key) {
728
+ const ptr0 = passArray8ToWasm0(client_id, wasm$1.__wbindgen_malloc);
729
+ const len0 = WASM_VECTOR_LEN;
730
+ const ptr1 = passArray8ToWasm0(signature_public_key, wasm$1.__wbindgen_malloc);
731
+ const len1 = WASM_VECTOR_LEN;
732
+ const ret = wasm$1.corecrypto_mls_init_with_client_id(this.ptr, ptr0, len0, ptr1, len1);
733
+ return takeObject(ret);
734
+ }
735
+ /**
710
736
  * Returns: [`WasmCryptoResult<()>`]
711
737
  *
712
738
  * see [core_crypto::MlsCentral::close]
@@ -1227,7 +1253,7 @@ let CoreCrypto$1 = class CoreCrypto {
1227
1253
  * see [core_crypto::proteus::ProteusCentral::encrypt]
1228
1254
  * @param {string} session_id
1229
1255
  * @param {Uint8Array} plaintext
1230
- * @returns {Promise<Uint8Array>}
1256
+ * @returns {Promise<Promise<any>>}
1231
1257
  */
1232
1258
  proteus_encrypt(session_id, plaintext) {
1233
1259
  const ptr0 = passStringToWasm0(session_id, wasm$1.__wbindgen_malloc, wasm$1.__wbindgen_realloc);
@@ -1243,7 +1269,7 @@ let CoreCrypto$1 = class CoreCrypto {
1243
1269
  * see [core_crypto::proteus::ProteusCentral::encrypt_batched]
1244
1270
  * @param {(string)[]} sessions
1245
1271
  * @param {Uint8Array} plaintext
1246
- * @returns {Promise<Map<any, any>>}
1272
+ * @returns {Promise<any>}
1247
1273
  */
1248
1274
  proteus_encrypt_batched(sessions, plaintext) {
1249
1275
  const ptr0 = passArrayJsValueToWasm0(sessions, wasm$1.__wbindgen_malloc);
@@ -1258,7 +1284,7 @@ let CoreCrypto$1 = class CoreCrypto {
1258
1284
  *
1259
1285
  * see [core_crypto::proteus::ProteusCentral::new_prekey]
1260
1286
  * @param {number} prekey_id
1261
- * @returns {Promise<Uint8Array>}
1287
+ * @returns {Promise<Promise<any>>}
1262
1288
  */
1263
1289
  proteus_new_prekey(prekey_id) {
1264
1290
  const ret = wasm$1.corecrypto_proteus_new_prekey(this.ptr, prekey_id);
@@ -1268,13 +1294,45 @@ let CoreCrypto$1 = class CoreCrypto {
1268
1294
  * Returns: [`WasmCryptoResult<Uint8Array>`]
1269
1295
  *
1270
1296
  * see [core_crypto::proteus::ProteusCentral::new_prekey]
1271
- * @returns {Promise<Uint8Array>}
1297
+ * @returns {Promise<Promise<any>>}
1272
1298
  */
1273
1299
  proteus_new_prekey_auto() {
1274
1300
  const ret = wasm$1.corecrypto_proteus_new_prekey_auto(this.ptr);
1275
1301
  return takeObject(ret);
1276
1302
  }
1277
1303
  /**
1304
+ * Returns [`WasmCryptoResult<Uint8Array>`]
1305
+ *
1306
+ * see [core_crypto::proteus::ProteusCentral::last_resort_prekey]
1307
+ * @returns {Promise<any>}
1308
+ */
1309
+ proteus_last_resort_prekey() {
1310
+ const ret = wasm$1.corecrypto_proteus_last_resort_prekey(this.ptr);
1311
+ return takeObject(ret);
1312
+ }
1313
+ /**
1314
+ * Returns: [`WasmCryptoResult<u16>`]
1315
+ *
1316
+ * see [core_crypto::proteus::ProteusCentral::last_resort_prekey_id]
1317
+ * @returns {number}
1318
+ */
1319
+ static proteus_last_resort_prekey_id() {
1320
+ try {
1321
+ const retptr = wasm$1.__wbindgen_add_to_stack_pointer(-16);
1322
+ wasm$1.corecrypto_proteus_last_resort_prekey_id(retptr);
1323
+ var r0 = getInt32Memory0()[retptr / 4 + 0];
1324
+ var r1 = getInt32Memory0()[retptr / 4 + 1];
1325
+ var r2 = getInt32Memory0()[retptr / 4 + 2];
1326
+ if (r2) {
1327
+ throw takeObject(r1);
1328
+ }
1329
+ return r0;
1330
+ }
1331
+ finally {
1332
+ wasm$1.__wbindgen_add_to_stack_pointer(16);
1333
+ }
1334
+ }
1335
+ /**
1278
1336
  * Returns: [`WasmCryptoResult<String>`]
1279
1337
  *
1280
1338
  * see [core_crypto::proteus::ProteusCentral::fingerprint]
@@ -1421,9 +1479,10 @@ class CoreCryptoWasmCallbacks {
1421
1479
  * @param {Function} authorize
1422
1480
  * @param {Function} user_authorize
1423
1481
  * @param {Function} client_is_existing_group_user
1482
+ * @param {any} ctx
1424
1483
  */
1425
- constructor(authorize, user_authorize, client_is_existing_group_user) {
1426
- const ret = wasm$1.corecryptowasmcallbacks_new(addHeapObject(authorize), addHeapObject(user_authorize), addHeapObject(client_is_existing_group_user));
1484
+ constructor(authorize, user_authorize, client_is_existing_group_user, ctx) {
1485
+ const ret = wasm$1.corecryptowasmcallbacks_new(addHeapObject(authorize), addHeapObject(user_authorize), addHeapObject(client_is_existing_group_user), addHeapObject(ctx));
1427
1486
  return CoreCryptoWasmCallbacks.__wrap(ret);
1428
1487
  }
1429
1488
  }
@@ -1838,7 +1897,7 @@ class FfiWireE2EIdentity {
1838
1897
  }
1839
1898
  /**
1840
1899
  * See [core_crypto::e2e_identity::WireE2eIdentity::finalize_request]
1841
- * @param {(Uint8Array)[]} domains
1900
+ * @param {(string)[]} domains
1842
1901
  * @param {Uint8Array} order
1843
1902
  * @param {Uint8Array} account
1844
1903
  * @param {string} previous_nonce
@@ -2244,9 +2303,27 @@ async function load(module, imports) {
2244
2303
  function getImports() {
2245
2304
  const imports = {};
2246
2305
  imports.wbg = {};
2306
+ imports.wbg.__wbg_new_f9876326328f45ed = function () {
2307
+ const ret = new Object();
2308
+ return addHeapObject(ret);
2309
+ };
2310
+ imports.wbg.__wbg_new_b525de17f44a8943 = function () {
2311
+ const ret = new Array();
2312
+ return addHeapObject(ret);
2313
+ };
2314
+ imports.wbg.__wbg_set_17224bc548dd1d7b = function (arg0, arg1, arg2) {
2315
+ getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
2316
+ };
2317
+ imports.wbg.__wbg_set_20cbc34131e76824 = function (arg0, arg1, arg2) {
2318
+ getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
2319
+ };
2247
2320
  imports.wbg.__wbindgen_object_drop_ref = function (arg0) {
2248
2321
  takeObject(arg0);
2249
2322
  };
2323
+ imports.wbg.__wbindgen_number_new = function (arg0) {
2324
+ const ret = arg0;
2325
+ return addHeapObject(ret);
2326
+ };
2250
2327
  imports.wbg.__wbindgen_object_clone_ref = function (arg0) {
2251
2328
  const ret = getObject(arg0);
2252
2329
  return addHeapObject(ret);
@@ -2296,20 +2373,20 @@ function getImports() {
2296
2373
  const ret = getObject(arg0).length;
2297
2374
  return ret;
2298
2375
  };
2299
- imports.wbg.__wbg_new_537b7341ce90bb31 = function (arg0) {
2300
- const ret = new Uint8Array(getObject(arg0));
2301
- return addHeapObject(ret);
2302
- };
2303
2376
  imports.wbg.__wbg_call_9495de66fdbe016b = function () {
2304
2377
  return handleError(function (arg0, arg1, arg2) {
2305
2378
  const ret = getObject(arg0).call(getObject(arg1), getObject(arg2));
2306
2379
  return addHeapObject(ret);
2307
2380
  }, arguments);
2308
2381
  };
2309
- imports.wbg.__wbg_new_f9876326328f45ed = function () {
2310
- const ret = new Object();
2382
+ imports.wbg.__wbg_new_537b7341ce90bb31 = function (arg0) {
2383
+ const ret = new Uint8Array(getObject(arg0));
2311
2384
  return addHeapObject(ret);
2312
2385
  };
2386
+ imports.wbg.__wbg_push_49c286f04dd3bf59 = function (arg0, arg1) {
2387
+ const ret = getObject(arg0).push(getObject(arg1));
2388
+ return ret;
2389
+ };
2313
2390
  imports.wbg.__wbg_new_f841cc6f2098f4b5 = function () {
2314
2391
  const ret = new Map();
2315
2392
  return addHeapObject(ret);
@@ -2322,28 +2399,6 @@ function getImports() {
2322
2399
  const ret = BigInt.asUintN(64, arg0);
2323
2400
  return addHeapObject(ret);
2324
2401
  };
2325
- imports.wbg.__wbg_ffiwiree2eidentity_new = function (arg0) {
2326
- const ret = FfiWireE2EIdentity.__wrap(arg0);
2327
- return addHeapObject(ret);
2328
- };
2329
- imports.wbg.__wbg_new_b525de17f44a8943 = function () {
2330
- const ret = new Array();
2331
- return addHeapObject(ret);
2332
- };
2333
- imports.wbg.__wbg_set_17224bc548dd1d7b = function (arg0, arg1, arg2) {
2334
- getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
2335
- };
2336
- imports.wbg.__wbg_set_20cbc34131e76824 = function (arg0, arg1, arg2) {
2337
- getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
2338
- };
2339
- imports.wbg.__wbindgen_number_new = function (arg0) {
2340
- const ret = arg0;
2341
- return addHeapObject(ret);
2342
- };
2343
- imports.wbg.__wbg_push_49c286f04dd3bf59 = function (arg0, arg1) {
2344
- const ret = getObject(arg0).push(getObject(arg1));
2345
- return ret;
2346
- };
2347
2402
  imports.wbg.__wbg_new_9d3a9ce4282a18a8 = function (arg0, arg1) {
2348
2403
  try {
2349
2404
  var state0 = { a: arg0, b: arg1 };
@@ -2351,7 +2406,7 @@ function getImports() {
2351
2406
  const a = state0.a;
2352
2407
  state0.a = 0;
2353
2408
  try {
2354
- return __wbg_adapter_263(a, state0.b, arg0, arg1);
2409
+ return __wbg_adapter_271(a, state0.b, arg0, arg1);
2355
2410
  }
2356
2411
  finally {
2357
2412
  state0.a = a;
@@ -2364,6 +2419,10 @@ function getImports() {
2364
2419
  state0.a = state0.b = 0;
2365
2420
  }
2366
2421
  };
2422
+ imports.wbg.__wbg_ffiwiree2eidentity_new = function (arg0) {
2423
+ const ret = FfiWireE2EIdentity.__wrap(arg0);
2424
+ return addHeapObject(ret);
2425
+ };
2367
2426
  imports.wbg.__wbg_setonsuccess_925a7718d3f62bc1 = function (arg0, arg1) {
2368
2427
  getObject(arg0).onsuccess = getObject(arg1);
2369
2428
  };
@@ -2448,6 +2507,10 @@ function getImports() {
2448
2507
  return addHeapObject(ret);
2449
2508
  }, arguments);
2450
2509
  };
2510
+ imports.wbg.__wbg_length_ea0846e494e3b16e = function (arg0) {
2511
+ const ret = getObject(arg0).length;
2512
+ return ret;
2513
+ };
2451
2514
  imports.wbg.__wbg_reject_57029f54148d79c3 = function (arg0) {
2452
2515
  const ret = Promise.reject(getObject(arg0));
2453
2516
  return addHeapObject(ret);
@@ -2638,6 +2701,10 @@ function getImports() {
2638
2701
  const ret = new Uint8Array(arg0 >>> 0);
2639
2702
  return addHeapObject(ret);
2640
2703
  };
2704
+ imports.wbg.__wbg_charCodeAt_d78a90aced59e02f = function (arg0, arg1) {
2705
+ const ret = getObject(arg0).charCodeAt(arg1 >>> 0);
2706
+ return ret;
2707
+ };
2641
2708
  imports.wbg.__wbg_next_88560ec06a094dea = function () {
2642
2709
  return handleError(function (arg0) {
2643
2710
  const ret = getObject(arg0).next();
@@ -2719,6 +2786,12 @@ function getImports() {
2719
2786
  const ret = getObject(arg0).target;
2720
2787
  return isLikeNone(ret) ? 0 : addHeapObject(ret);
2721
2788
  };
2789
+ imports.wbg.__wbg_error_f64b8d41ed4d2fdc = function () {
2790
+ return handleError(function (arg0) {
2791
+ const ret = getObject(arg0).error;
2792
+ return isLikeNone(ret) ? 0 : addHeapObject(ret);
2793
+ }, arguments);
2794
+ };
2722
2795
  imports.wbg.__wbg_result_3a1fef332bc47038 = function () {
2723
2796
  return handleError(function (arg0) {
2724
2797
  const ret = getObject(arg0).result;
@@ -2759,12 +2832,6 @@ function getImports() {
2759
2832
  getObject(arg0).deleteObjectStore(getStringFromWasm0(arg1, arg2));
2760
2833
  }, arguments);
2761
2834
  };
2762
- imports.wbg.__wbg_error_f64b8d41ed4d2fdc = function () {
2763
- return handleError(function (arg0) {
2764
- const ret = getObject(arg0).error;
2765
- return isLikeNone(ret) ? 0 : addHeapObject(ret);
2766
- }, arguments);
2767
- };
2768
2835
  imports.wbg.__wbindgen_is_falsy = function (arg0) {
2769
2836
  const ret = !getObject(arg0);
2770
2837
  return ret;
@@ -2880,6 +2947,10 @@ function getImports() {
2880
2947
  const ret = getObject(arg0).then(getObject(arg1));
2881
2948
  return addHeapObject(ret);
2882
2949
  };
2950
+ imports.wbg.__wbg_then_f753623316e2873a = function (arg0, arg1, arg2) {
2951
+ const ret = getObject(arg0).then(getObject(arg1), getObject(arg2));
2952
+ return addHeapObject(ret);
2953
+ };
2883
2954
  imports.wbg.__wbg_resolve_fd40f858d9db1a04 = function (arg0) {
2884
2955
  const ret = Promise.resolve(getObject(arg0));
2885
2956
  return addHeapObject(ret);
@@ -2944,12 +3015,12 @@ function getImports() {
2944
3015
  return addHeapObject(ret);
2945
3016
  }, arguments);
2946
3017
  };
2947
- imports.wbg.__wbindgen_closure_wrapper4326 = function (arg0, arg1, arg2) {
2948
- const ret = makeMutClosure(arg0, arg1, 146, __wbg_adapter_52);
3018
+ imports.wbg.__wbindgen_closure_wrapper4402 = function (arg0, arg1, arg2) {
3019
+ const ret = makeMutClosure(arg0, arg1, 145, __wbg_adapter_52);
2949
3020
  return addHeapObject(ret);
2950
3021
  };
2951
- imports.wbg.__wbindgen_closure_wrapper4766 = function (arg0, arg1, arg2) {
2952
- const ret = makeMutClosure(arg0, arg1, 146, __wbg_adapter_55);
3022
+ imports.wbg.__wbindgen_closure_wrapper4858 = function (arg0, arg1, arg2) {
3023
+ const ret = makeMutClosure(arg0, arg1, 145, __wbg_adapter_55);
2953
3024
  return addHeapObject(ret);
2954
3025
  };
2955
3026
  return imports;
@@ -3003,14 +3074,13 @@ var exports = /*#__PURE__*/Object.freeze({
3003
3074
  PublicGroupStateBundle: PublicGroupStateBundle,
3004
3075
  WirePolicy: WirePolicy$1,
3005
3076
  default: init,
3006
- initSync: initSync,
3007
- version: version
3077
+ initSync: initSync
3008
3078
  });
3009
3079
 
3010
3080
  var wasm = async (opt = {}) => {
3011
3081
  let {importHook, serverPath} = opt;
3012
3082
 
3013
- let path = "assets/core_crypto_ffi-fb64c1f7.wasm";
3083
+ let path = "assets/core_crypto_ffi-d7dac5b2.wasm";
3014
3084
 
3015
3085
  if (serverPath != null) {
3016
3086
  path = serverPath + /[^\/\\]*$/.exec(path)[0];
@@ -3026,7 +3096,7 @@ var wasm = async (opt = {}) => {
3026
3096
 
3027
3097
  // Wire
3028
3098
  // Copyright (C) 2022 Wire Swiss GmbH
3029
- var _a, _CoreCrypto_module, _CoreCrypto_cc, _WireE2eIdentity_e2ei;
3099
+ var _a, _CoreCrypto_module, _CoreCrypto_cc, _CoreCrypto_assertModuleLoaded, _WireE2eIdentity_e2ei;
3030
3100
  /**
3031
3101
  * Error wrapper that takes care of extracting rich error details across the FFI (through JSON parsing)
3032
3102
  *
@@ -3046,7 +3116,7 @@ class CoreCryptoError extends Error {
3046
3116
  this.proteusErrorCode = richError.proteusErrorCode;
3047
3117
  }
3048
3118
  static fallback(msg, ...params) {
3049
- console.warn("Cannot build CoreCryptoError, falling back to standard Error");
3119
+ console.warn(`Cannot build CoreCryptoError, falling back to standard Error! ctx: ${msg}`);
3050
3120
  // @ts-ignore
3051
3121
  return new Error(msg, ...params);
3052
3122
  }
@@ -3269,6 +3339,26 @@ class CoreCrypto {
3269
3339
  async mlsInit(clientId) {
3270
3340
  return await CoreCryptoError.asyncMapErr(__classPrivateFieldGet(this, _CoreCrypto_cc, "f").mls_init(clientId));
3271
3341
  }
3342
+ /**
3343
+ * Generates a MLS KeyPair/CredentialBundle with a temporary, random client ID.
3344
+ * This method is designed to be used in conjunction with {@link CoreCrypto.mlsInitWithClientID} and represents the first step in this process
3345
+ *
3346
+ * @returns This returns the TLS-serialized identity key (i.e. the signature keypair's public key)
3347
+ */
3348
+ async mlsGenerateKeypair() {
3349
+ return await CoreCryptoError.asyncMapErr(__classPrivateFieldGet(this, _CoreCrypto_cc, "f").mls_generate_keypair());
3350
+ }
3351
+ /**
3352
+ * Updates the current temporary Client ID with the newly provided one. This is the second step in the externally-generated clients process
3353
+ *
3354
+ * Important: This is designed to be called after {@link CoreCrypto.mlsGenerateKeyPair}
3355
+ *
3356
+ * @param clientId - The newly-allocated client ID by the MLS Authentication Service
3357
+ * @param signaturePublicKey - The public key you were given at the first step; This is for authentication purposes
3358
+ */
3359
+ async mlsInitWithClientId(clientId, signaturePublicKey) {
3360
+ return await CoreCryptoError.asyncMapErr(__classPrivateFieldGet(this, _CoreCrypto_cc, "f").mls_init_with_client_id(clientId, signaturePublicKey));
3361
+ }
3272
3362
  /** @hidden */
3273
3363
  constructor(cc) {
3274
3364
  /** @hidden */
@@ -3296,10 +3386,10 @@ class CoreCrypto {
3296
3386
  *
3297
3387
  * @param callbacks - Any interface following the {@link CoreCryptoCallbacks} interface
3298
3388
  */
3299
- registerCallbacks(callbacks) {
3389
+ async registerCallbacks(callbacks, ctx = null) {
3300
3390
  try {
3301
- const wasmCallbacks = new (__classPrivateFieldGet(CoreCrypto, _a, "f", _CoreCrypto_module).CoreCryptoWasmCallbacks)(callbacks.authorize, callbacks.userAuthorize, callbacks.clientIsExistingGroupUser);
3302
- __classPrivateFieldGet(this, _CoreCrypto_cc, "f").set_callbacks(wasmCallbacks);
3391
+ const wasmCallbacks = new (__classPrivateFieldGet(CoreCrypto, _a, "f", _CoreCrypto_module).CoreCryptoWasmCallbacks)(callbacks.authorize, callbacks.userAuthorize, callbacks.clientIsExistingGroupUser, ctx);
3392
+ await __classPrivateFieldGet(this, _CoreCrypto_cc, "f").set_callbacks(wasmCallbacks);
3303
3393
  }
3304
3394
  catch (e) {
3305
3395
  throw CoreCryptoError.fromStdError(e);
@@ -3377,6 +3467,9 @@ class CoreCrypto {
3377
3467
  * @returns a {@link DecryptedMessage}. Note that {@link DecryptedMessage#message} is `undefined` when the encrypted payload contains a system message such a proposal or commit
3378
3468
  */
3379
3469
  async decryptMessage(conversationId, payload) {
3470
+ if (!payload?.length) {
3471
+ throw new Error("decryptMessage payload is empty or null");
3472
+ }
3380
3473
  try {
3381
3474
  const ffiDecryptedMessage = await CoreCryptoError.asyncMapErr(__classPrivateFieldGet(this, _CoreCrypto_cc, "f").decrypt_message(conversationId, payload));
3382
3475
  const commitDelay = ffiDecryptedMessage.commit_delay ?
@@ -3857,11 +3950,26 @@ class CoreCrypto {
3857
3950
  /**
3858
3951
  * Creates a new prekey with an automatically generated ID..
3859
3952
  *
3860
- * @returns: A CBOR-serialized version of the PreKeyBundle corresponding to the newly generated and stored PreKey
3953
+ * @returns A CBOR-serialized version of the PreKeyBundle corresponding to the newly generated and stored PreKey
3861
3954
  */
3862
3955
  async proteusNewPrekeyAuto() {
3863
3956
  return await CoreCryptoError.asyncMapErr(__classPrivateFieldGet(this, _CoreCrypto_cc, "f").proteus_new_prekey_auto());
3864
3957
  }
3958
+ /**
3959
+ * Proteus last resort prekey stuff
3960
+ *
3961
+ * @returns A CBOR-serialize version of the PreKeyBundle associated with the last resort PreKey (holding the last resort prekey id)
3962
+ */
3963
+ async proteusLastResortPrekey() {
3964
+ return await CoreCryptoError.asyncMapErr(__classPrivateFieldGet(this, _CoreCrypto_cc, "f").proteus_last_resort_prekey());
3965
+ }
3966
+ /**
3967
+ * @returns The last resort PreKey id
3968
+ */
3969
+ static proteusLastResortPrekeyId() {
3970
+ __classPrivateFieldGet(this, _a, "m", _CoreCrypto_assertModuleLoaded).call(this);
3971
+ return __classPrivateFieldGet(this, _a, "f", _CoreCrypto_module).CoreCrypto.proteus_last_resort_prekey_id();
3972
+ }
3865
3973
  /**
3866
3974
  * Proteus public key fingerprint
3867
3975
  * It's basically the public key encoded as an hex string
@@ -3921,13 +4029,16 @@ class CoreCrypto {
3921
4029
  /**
3922
4030
  * Creates an enrollment instance with private key material you can use in order to fetch
3923
4031
  * a new x509 certificate from the acme server.
3924
- * Make sure to call [WireE2eIdentity::free] (not yet available) to dispose this instance and its associated
4032
+ * Make sure to call {@link WireE2eIdentity.free} to dispose this instance and its associated
3925
4033
  * keying material.
3926
4034
  *
3927
4035
  * @param ciphersuite - For generating signing key material. Only {@link Ciphersuite.MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519} is supported currently
3928
4036
  */
3929
- async newAcmeEnrollment() {
3930
- const e2ei = await CoreCryptoError.asyncMapErr(__classPrivateFieldGet(this, _CoreCrypto_cc, "f").new_acme_enrollment(Ciphersuite.MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519));
4037
+ async newAcmeEnrollment(ciphersuite = Ciphersuite.MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519) {
4038
+ if (ciphersuite !== Ciphersuite.MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519) {
4039
+ throw new Error("This ACME ciphersuite isn't supported. Only `Ciphersuite.MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519` is as of now");
4040
+ }
4041
+ const e2ei = await CoreCryptoError.asyncMapErr(__classPrivateFieldGet(this, _CoreCrypto_cc, "f").new_acme_enrollment(ciphersuite));
3931
4042
  return new WireE2eIdentity(e2ei);
3932
4043
  }
3933
4044
  /**
@@ -3936,13 +4047,15 @@ class CoreCrypto {
3936
4047
  * @returns The `core-crypto-ffi` version as defined in its `Cargo.toml` file
3937
4048
  */
3938
4049
  static version() {
3939
- if (!__classPrivateFieldGet(this, _a, "f", _CoreCrypto_module)) {
3940
- throw new Error("Internal module hasn't been initialized. Please use `await CoreCrypto.init(params)`!");
3941
- }
3942
- return __classPrivateFieldGet(this, _a, "f", _CoreCrypto_module).version();
4050
+ __classPrivateFieldGet(this, _a, "m", _CoreCrypto_assertModuleLoaded).call(this);
4051
+ return __classPrivateFieldGet(this, _a, "f", _CoreCrypto_module).CoreCrypto.version();
3943
4052
  }
3944
4053
  }
3945
- _a = CoreCrypto, _CoreCrypto_cc = new WeakMap();
4054
+ _a = CoreCrypto, _CoreCrypto_cc = new WeakMap(), _CoreCrypto_assertModuleLoaded = function _CoreCrypto_assertModuleLoaded() {
4055
+ if (!__classPrivateFieldGet(this, _a, "f", _CoreCrypto_module)) {
4056
+ throw new Error("Internal module hasn't been initialized. Please use `await CoreCrypto.init(params)` or `await CoreCrypto.deferredInit(params)` !");
4057
+ }
4058
+ };
3946
4059
  /** @hidden */
3947
4060
  _CoreCrypto_module = { value: void 0 };
3948
4061
  class WireE2eIdentity {
@@ -3952,6 +4065,9 @@ class WireE2eIdentity {
3952
4065
  _WireE2eIdentity_e2ei.set(this, void 0);
3953
4066
  __classPrivateFieldSet(this, _WireE2eIdentity_e2ei, e2ei, "f");
3954
4067
  }
4068
+ free() {
4069
+ __classPrivateFieldGet(this, _WireE2eIdentity_e2ei, "f").free();
4070
+ }
3955
4071
  /**
3956
4072
  * Parses the response from `GET /acme/{provisioner-name}/directory`.
3957
4073
  * Use this {@link AcmeDirectory} in the next step to fetch the first nonce from the acme server. Use
@@ -4152,10 +4268,10 @@ class WireE2eIdentity {
4152
4268
  /**
4153
4269
  * Final step before fetching the certificate.
4154
4270
  *
4155
- * @param domains you want to generate a certificate for e.g. `["wire.com"]`
4156
- * @param order you got from {@link checkOrderResponse}
4157
- * @param account you found after {@link newAccountResponse}
4158
- * @param previousNonce `replay-nonce` response header from `POST /acme/{provisioner-name}/order/{order-id}`
4271
+ * @param domains - domains you want to generate a certificate for e.g. `["wire.com"]`
4272
+ * @param order - order you got from {@link checkOrderResponse}
4273
+ * @param account - account you found after {@link newAccountResponse}
4274
+ * @param previousNonce - `replay-nonce` response header from `POST /acme/{provisioner-name}/order/{order-id}`
4159
4275
  * @see https://www.rfc-editor.org/rfc/rfc8555.html#section-7.4
4160
4276
  */
4161
4277
  finalizeRequest(domains, order, account, previousNonce) {