@wireapp/core-crypto 1.1.2 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -36,6 +36,13 @@ brew install gnu-sed
36
36
  ```
37
37
  and add an alias to your shell configuration file: `alias sed=gsed` (e.g. to `~/.zshenv` if you're using zsh).
38
38
 
39
+ ### Development Requirements
40
+
41
+ #### Pre-commit
42
+
43
+ - Install the [`pre-commit` framework](https://pre-commit.com/)
44
+ - Run `pre-commit install` to initialize the pre-commit hooks
45
+
39
46
  ### Android
40
47
 
41
48
  Install Android SDK and Build-Tools for API level 30+
@@ -48,7 +55,7 @@ Install Android SDK and Build-Tools for API level 30+
48
55
 
49
56
  Install android rust targets:
50
57
  ```ignore
51
- rustup target add x86_64-linux-android aarch64-linux-android armv7-linux-androideabi i686-linux-android
58
+ rustup target add x86_64-linux-android aarch64-linux-android armv7-linux-androideabi
52
59
  ```
53
60
  Build:
54
61
  ```ignore
@@ -137,11 +144,11 @@ cargo install cargo-nextest
137
144
  cargo nextest run
138
145
  ```
139
146
 
140
- #### Run core crypto tests on WASM target
147
+ ### Run core crypto internal tests on WASM target
141
148
 
142
149
  If you haven't already, install the target and wasm-pack:
143
150
 
144
- ```ignore
151
+ ```sh
145
152
  rustup target add wasm32-unknown-unknown
146
153
  cargo install wasm-pack
147
154
  ```
@@ -164,28 +171,63 @@ wasm-pack test --headless --chrome ./<crate-folder-to-test>
164
171
  cargo nextest run --features test-all-cipher
165
172
  ```
166
173
 
167
- ### Platform-specific testing
174
+ ### Platform-specific tests for Kotlin/JVM
168
175
 
169
- ### Kotlin/Android
176
+ Build the JVM target every timee the Rust code changes:
170
177
 
171
- * Take the steps to compile for Kotlin/Android
172
- * Then:
173
- ```ignore
174
- cd crypto-ffi/bindings
175
- ./gradlew test
178
+ ```sh
179
+ # substitute with `jvm-darwin` on OSX
180
+ core-crypto/crypto-ffi$ cargo make jvm-linux
181
+ ```
182
+
183
+ Then run the tests each time the wrapper or wrapper tests change
184
+
185
+ ```sh
186
+ core-crypto/crypto-ffi/bindings$ ./gradlew jvm:build -x lint -x lintRelease
187
+ ```
188
+
189
+ ### Platform-specific tests for Android
190
+
191
+ Build the Android target every timee the Rust code changes:
192
+
193
+ ```sh
194
+ core-crypto/crypto-ffi$ cargo make android
195
+ ```
196
+
197
+ Then run the tests each time the wrapper or wrapper tests change
198
+
199
+ ```sh
200
+ core-crypto/crypto-ffi/bindings$ ./gradlew android:build -x lint -x lintRelease
176
201
  ```
177
202
 
178
203
  ### Swift/iOS
179
204
 
180
205
  *No E2E testing is available as of now on Swift.*
181
206
 
182
- ### WASM/Web
207
+ ### Platform-spcecific tests for WASM/Web
183
208
 
184
- * Take the steps to compile for WASM/Web
185
- * Then:
186
- ```ignore
187
- cd crypto-ffi
188
- bun test
209
+ Install TS dependencies on first go, and each time they change:
210
+
211
+ ```sh
212
+ bun install
213
+ ```
214
+
215
+ Build the WASM target every timee the Rust code changes:
216
+
217
+ ```sh
218
+ core-crypto/crypto-ffi$ cargo make wasm
219
+ ```
220
+
221
+ Then run the tests each time the wrapper or wrapper tests change
222
+
223
+ ```sh
224
+ core-crypto/crypto-ffi$ bun run test
225
+ ```
226
+
227
+ Note that CI will fail if it doesn't like your formatting. This can typically be automtically adjusted with
228
+
229
+ ```sh
230
+ core-crypto/crypto-ffi$ bun eslinst bindings/js --max-warnings=0 --fix
189
231
  ```
190
232
 
191
233
  ## Benchmarks
@@ -276,4 +318,4 @@ cd crypto-ffi/bindings/android
276
318
  Publishing JS / WASM bindings happens automatically by a github workflow when a release tag is pushed.
277
319
 
278
320
  If you would like to publish to `@wireapp/core-crypto` manually, log into NPM and
279
- just run `npm publish`.
321
+ just run `bun publish`.
package/package.json CHANGED
@@ -1,12 +1,14 @@
1
1
  {
2
2
  "name": "@wireapp/core-crypto",
3
- "version": "1.1.2",
3
+ "version": "3.0.0",
4
4
  "description": "CoreCrypto bindings for the Web",
5
5
  "type": "module",
6
6
  "module": "platforms/web/corecrypto.js",
7
7
  "types": "platforms/web/corecrypto.d.ts",
8
8
  "scripts": {
9
- "clean": "rm -f ./platforms/web/*.{js,ts,wasm,html} && rm -rf ./platforms/web/assets"
9
+ "clean": "rm -f ./platforms/web/*.{js,ts,wasm,html} && rm -rf ./platforms/web/assets",
10
+ "test": "[ \"$(basename $PWD)\" != \"crypto-ffi\" ] && echo \"Error: Not in crypto-ffi directory, do:\" && echo cd crypto-ffi && exit 1 || bun run build_ts.ts && wdio run bindings/js/wdio.conf.ts --spec bindings/js/test/**/*.test.ts",
11
+ "bench": "[ \"$(basename $PWD)\" != \"crypto-ffi\" ] && echo \"Error: Not in crypto-ffi directory, do:\" && echo cd crypto-ffi && exit 1 ||bun run build_ts.ts && wdio run bindings/js/wdio.conf.ts --spec bindings/js/benches/**/*.bench.ts --log-level warn"
10
12
  },
11
13
  "publishConfig": {
12
14
  "access": "public"
@@ -32,14 +34,22 @@
32
34
  "url": "https://github.com/wireapp/core-crypto/issues"
33
35
  },
34
36
  "devDependencies": {
37
+ "@types/bun": "^1.1.13",
38
+ "@types/mocha": "^10.0.9",
35
39
  "@typescript-eslint/eslint-plugin": "^7.0.2",
36
40
  "@typescript-eslint/parser": "^7.0.2",
41
+ "@wdio/browser-runner": "^9.2.12",
42
+ "@wdio/cli": "^9.2.12",
43
+ "@wdio/logger": "^9.1.3",
44
+ "@wdio/mocha-framework": "^9.2.8",
45
+ "@wdio/spec-reporter": "^9.2.14",
46
+ "@wdio/static-server-service": "^9.2.2",
37
47
  "bun-plugin-dts": "^0.2.1",
38
48
  "eslint": "^8.56.0",
39
49
  "eslint-config-prettier": "^9.1.0",
40
50
  "eslint-plugin-prettier": "^5.1.3",
51
+ "eslint-plugin-wdio": "^9.2.11",
41
52
  "prettier": "^3.2.5",
42
- "puppeteer": "^22.2.0",
43
53
  "ts-loader": "^9.5.1",
44
54
  "typescript": "^5.3.3"
45
55
  }
@@ -8,6 +8,16 @@ declare enum WirePolicy {
8
8
  */
9
9
  Ciphertext = 2
10
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
+ }
11
21
  declare enum Ciphersuite {
12
22
  /**
13
23
  * DH KEM x25519 | AES-GCM 128 | SHA2-256 | Ed25519
@@ -38,16 +48,6 @@ declare enum Ciphersuite {
38
48
  */
39
49
  MLS_256_DHKEMP384_AES256GCM_SHA384_P384 = 7
40
50
  }
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
@@ -68,6 +68,53 @@ export class AcmeChallenge {
68
68
  */
69
69
  readonly url: string;
70
70
  }
71
+ declare class BuildMetadata {
72
+ /**
73
+ ** Return copy of self without private attributes.
74
+ */
75
+ toJSON(): Object;
76
+ /**
77
+ * Return stringified version of self.
78
+ */
79
+ toString(): string;
80
+ free(): void;
81
+ /**
82
+ * Whether this build was in Debug mode (true) or Release mode (false)
83
+ */
84
+ readonly cargoDebug: string;
85
+ /**
86
+ * Features enabled for this build
87
+ */
88
+ readonly cargoFeatures: string;
89
+ /**
90
+ * Git branch
91
+ */
92
+ readonly gitBranch: string;
93
+ /**
94
+ * Output of `git describe`
95
+ */
96
+ readonly gitDescribe: string;
97
+ /**
98
+ * `true` when the source code differed from the commit at the most recent git hash
99
+ */
100
+ readonly gitDirty: string;
101
+ /**
102
+ * Hash of current git commit
103
+ */
104
+ readonly gitSha: string;
105
+ /**
106
+ * Optimization level
107
+ */
108
+ readonly optLevel: string;
109
+ /**
110
+ * Build target triple
111
+ */
112
+ readonly targetTriple: string;
113
+ /**
114
+ * Build Timestamp
115
+ */
116
+ readonly timestamp: string;
117
+ }
71
118
  /**
72
119
  * see [core_crypto::prelude::MlsConversationConfiguration]
73
120
  */
@@ -390,6 +437,13 @@ declare class CoreCryptoContext {
390
437
  /**
391
438
  * Returns: [`WasmCryptoResult<()>`]
392
439
  *
440
+ * see [core_crypto::proteus::ProteusCentral::try_new]
441
+ * @returns {Promise<any>}
442
+ */
443
+ proteus_init(): Promise<any>;
444
+ /**
445
+ * Returns: [`WasmCryptoResult<()>`]
446
+ *
393
447
  * See [core_crypto::context::CentralContext::proteus_session_from_prekey]
394
448
  * @param {string} session_id
395
449
  * @param {Uint8Array} prekey
@@ -609,6 +663,7 @@ declare class CoreCryptoContext {
609
663
  e2ei_mls_init_only(enrollment: FfiWireE2EIdentity, certificate_chain: string, nb_key_package?: number): Promise<any>;
610
664
  /**
611
665
  * Returns: [`WasmCryptoResult<CommitBundle>`]
666
+ *
612
667
  * see [core_crypto::context::CentralContext::e2ei_rotate]
613
668
  * @param {Uint8Array} conversation_id
614
669
  * @returns {Promise<any>}
@@ -1233,6 +1288,10 @@ declare class CoreCryptoContext$1 {
1233
1288
  * @returns A `Uint8Array` buffer that contains `length` cryptographically-secure random bytes
1234
1289
  */
1235
1290
  randomBytes(length: number): Promise<Uint8Array>;
1291
+ /**
1292
+ * Initializes the proteus client
1293
+ */
1294
+ proteusInit(): Promise<void>;
1236
1295
  /**
1237
1296
  * Create a Proteus session using a prekey
1238
1297
  *
@@ -1533,6 +1592,12 @@ declare class CoreCryptoContext$1 {
1533
1592
  */
1534
1593
  getCredentialInUse(groupInfo: Uint8Array, credentialType?: CredentialType$1): Promise<E2eiConversationState>;
1535
1594
  }
1595
+ export interface CoreCryptoRichError {
1596
+ message: string;
1597
+ error_name?: string;
1598
+ error_stack?: string[];
1599
+ proteus_error_code?: number;
1600
+ }
1536
1601
  /**
1537
1602
  * Error wrapper that takes care of extracting rich error details across the FFI (through JSON parsing)
1538
1603
  *
@@ -1543,8 +1608,8 @@ declare class CoreCryptoContext$1 {
1543
1608
  * Please note that in this case the extra properties will not be available.
1544
1609
  */
1545
1610
  export declare class CoreCryptoError extends Error {
1546
- rustStackTrace: string;
1547
- proteusErrorCode: number;
1611
+ errorStack: string[];
1612
+ proteusErrorCode: number | null;
1548
1613
  private constructor();
1549
1614
  private static fallback;
1550
1615
  static build(msg: string, ...params: unknown[]): CoreCryptoError | Error;
@@ -2218,9 +2283,10 @@ export interface CoreCryptoLogger {
2218
2283
  /**
2219
2284
  * This method will be called by Core Crypto to log messages. It is up to the implementer to decide how to handle the message and where to actually log it.
2220
2285
  * @param level - the level of the logged message. it will also be present in the json message
2221
- * @param json_msg - message to log in json format
2286
+ * @param message - log message
2287
+ * @param context - additional context captured when the log was made.
2222
2288
  **/
2223
- log: (level: CoreCryptoLogLevel, json_msg: string) => void;
2289
+ log: (level: CoreCryptoLogLevel, message: string, context: string) => void;
2224
2290
  }
2225
2291
  /**
2226
2292
  * Defines the maximum log level for the logs from Core Crypto
@@ -2234,13 +2300,30 @@ export declare enum CoreCryptoLogLevel {
2234
2300
  Error = 6
2235
2301
  }
2236
2302
  /**
2237
- * Initializes the global logger for Core Crypto and registers the callback. Can be called only once
2303
+ * Initializes the global logger for Core Crypto and registers the callback.
2304
+ *
2305
+ * **NOTE:** you must call this after `await CoreCrypto.init(params)` or `await CoreCrypto.deferredInit(params)`.
2306
+ *
2307
+ * @deprecated use {@link CoreCrypto.setLogger} instead.
2308
+ *
2238
2309
  * @param logger - the interface to be called when something is going to be logged
2239
2310
  * @param level - the max level that should be logged
2240
- *
2241
- * NOTE: you must call this after `await CoreCrypto.init(params)` or `await CoreCrypto.deferredInit(params)`.
2242
2311
  **/
2243
2312
  export declare function initLogger(logger: CoreCryptoLogger, level: CoreCryptoLogLevel, ctx?: unknown): void;
2313
+ /**
2314
+ * Initializes the global logger for Core Crypto and registers the callback.
2315
+ *
2316
+ * **NOTE:** you must call this after `await CoreCrypto.init(params)` or `await CoreCrypto.deferredInit(params)`.
2317
+ *
2318
+ * @param logger - the interface to be called when something is going to be logged
2319
+ **/
2320
+ export declare function setLogger(logger: CoreCryptoLogger, ctx?: unknown): void;
2321
+ /**
2322
+ * Sets maximum log level for logs forwarded to the logger, defaults to `Warn`.
2323
+ *
2324
+ * @param level - the max level that should be logged
2325
+ */
2326
+ export declare function setMaxLogLevel(level: CoreCryptoLogLevel): void;
2244
2327
  /**
2245
2328
  * Wrapper for the WASM-compiled version of CoreCrypto
2246
2329
  */
@@ -2250,7 +2333,8 @@ export declare class CoreCrypto {
2250
2333
  * Should only be used internally
2251
2334
  */
2252
2335
  inner(): unknown;
2253
- static setLogger(logger: CoreCryptoWasmLogger, level: CoreCryptoLogLevel): void;
2336
+ static setLogger(logger: CoreCryptoWasmLogger): void;
2337
+ static setMaxLogLevel(level: CoreCryptoLogLevel): void;
2254
2338
  /**
2255
2339
  * This is your entrypoint to initialize {@link CoreCrypto}!
2256
2340
  *
@@ -2588,6 +2672,9 @@ export declare class CoreCrypto {
2588
2672
  reseedRng(seed: Uint8Array): Promise<void>;
2589
2673
  /**
2590
2674
  * Initializes the proteus client
2675
+ *
2676
+ * @deprecated Create a transaction with {@link CoreCrypto.transaction}
2677
+ * and use {@link CoreCryptoContext.proteusInit} instead.
2591
2678
  */
2592
2679
  proteusInit(): Promise<void>;
2593
2680
  /**
@@ -2873,6 +2960,12 @@ export declare class CoreCrypto {
2873
2960
  * @returns The `core-crypto-ffi` version as defined in its `Cargo.toml` file
2874
2961
  */
2875
2962
  static version(): string;
2963
+ /**
2964
+ * Returns build metadata for the {@link CoreCrypto} libary.
2965
+ *
2966
+ * @returns varous build metadata for `core-crypto`.
2967
+ */
2968
+ static buildMetadata(): BuildMetadata;
2876
2969
  }
2877
2970
  type JsonRawData = Uint8Array;
2878
2971
  export declare class E2eiEnrollment {
@@ -184,13 +184,13 @@ function makeMutClosure(arg0, arg1, dtor, f) {
184
184
  return real;
185
185
  }
186
186
  function __wbg_adapter_54(arg0, arg1, arg2) {
187
- wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h04c8e12eab94d8e7(arg0, arg1, addHeapObject(arg2));
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__h07cca67d94fc484f(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
- wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hec7f3798e268a664(arg0, arg1, addHeapObject(arg2));
193
+ wasm._dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h2e1bdf8eee89b946(arg0, arg1, addHeapObject(arg2));
194
194
  }
195
195
  function getArrayJsValueFromWasm0(ptr, len) {
196
196
  ptr = ptr >>> 0;
@@ -242,15 +242,10 @@ function handleError(f, args) {
242
242
  wasm.__wbindgen_exn_store(addHeapObject(e));
243
243
  }
244
244
  }
245
- function __wbg_adapter_497(arg0, arg1, arg2, arg3) {
246
- wasm.wasm_bindgen__convert__closures__invoke2_mut__h5053bb07030a5de3(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
245
+ function __wbg_adapter_512(arg0, arg1, arg2, arg3) {
246
+ wasm.wasm_bindgen__convert__closures__invoke2_mut__h5d1db9fa3036c038(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
247
247
  }
248
- var WirePolicy = Object.freeze({
249
- Plaintext: 1,
250
- "1": "Plaintext",
251
- Ciphertext: 2,
252
- "2": "Ciphertext"
253
- });
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" });
254
249
  var DeviceStatus = Object.freeze({
255
250
  Valid: 1,
256
251
  "1": "Valid",
@@ -259,6 +254,18 @@ var DeviceStatus = Object.freeze({
259
254
  Revoked: 3,
260
255
  "3": "Revoked"
261
256
  });
257
+ var WirePolicy = Object.freeze({
258
+ Plaintext: 1,
259
+ "1": "Plaintext",
260
+ Ciphertext: 2,
261
+ "2": "Ciphertext"
262
+ });
263
+ var CredentialType = Object.freeze({
264
+ Basic: 1,
265
+ "1": "Basic",
266
+ X509: 2,
267
+ "2": "X509"
268
+ });
262
269
  var Ciphersuite = Object.freeze({
263
270
  MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519: 1,
264
271
  "1": "MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519",
@@ -275,13 +282,6 @@ var Ciphersuite = Object.freeze({
275
282
  MLS_256_DHKEMP384_AES256GCM_SHA384_P384: 7,
276
283
  "7": "MLS_256_DHKEMP384_AES256GCM_SHA384_P384"
277
284
  });
278
- 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" });
279
- var CredentialType = Object.freeze({
280
- Basic: 1,
281
- "1": "Basic",
282
- X509: 2,
283
- "2": "X509"
284
- });
285
285
  var AcmeChallengeFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
286
286
  }, unregister: () => {
287
287
  } } : new FinalizationRegistry((ptr) => wasm.__wbg_acmechallenge_free(ptr >>> 0, 1));
@@ -499,6 +499,144 @@ class BufferedDecryptedMessage {
499
499
  return takeObject(ret);
500
500
  }
501
501
  }
502
+ var BuildMetadataFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
503
+ }, unregister: () => {
504
+ } } : new FinalizationRegistry((ptr) => wasm.__wbg_buildmetadata_free(ptr >>> 0, 1));
505
+
506
+ class BuildMetadata {
507
+ static __wrap(ptr) {
508
+ ptr = ptr >>> 0;
509
+ const obj = Object.create(BuildMetadata.prototype);
510
+ obj.__wbg_ptr = ptr;
511
+ BuildMetadataFinalization.register(obj, obj.__wbg_ptr, obj);
512
+ return obj;
513
+ }
514
+ toJSON() {
515
+ return {
516
+ timestamp: this.timestamp,
517
+ cargoDebug: this.cargoDebug,
518
+ cargoFeatures: this.cargoFeatures,
519
+ optLevel: this.optLevel,
520
+ targetTriple: this.targetTriple,
521
+ gitBranch: this.gitBranch,
522
+ gitDescribe: this.gitDescribe,
523
+ gitSha: this.gitSha,
524
+ gitDirty: this.gitDirty
525
+ };
526
+ }
527
+ toString() {
528
+ return JSON.stringify(this);
529
+ }
530
+ __destroy_into_raw() {
531
+ const ptr = this.__wbg_ptr;
532
+ this.__wbg_ptr = 0;
533
+ BuildMetadataFinalization.unregister(this);
534
+ return ptr;
535
+ }
536
+ free() {
537
+ const ptr = this.__destroy_into_raw();
538
+ wasm.__wbg_buildmetadata_free(ptr, 0);
539
+ }
540
+ get timestamp() {
541
+ try {
542
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
543
+ wasm.__wbg_get_buildmetadata_timestamp(retptr, this.__wbg_ptr);
544
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
545
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
546
+ return getStringFromWasm0(r0, r1);
547
+ } finally {
548
+ wasm.__wbindgen_add_to_stack_pointer(16);
549
+ }
550
+ }
551
+ get cargoDebug() {
552
+ try {
553
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
554
+ wasm.__wbg_get_buildmetadata_cargoDebug(retptr, this.__wbg_ptr);
555
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
556
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
557
+ return getStringFromWasm0(r0, r1);
558
+ } finally {
559
+ wasm.__wbindgen_add_to_stack_pointer(16);
560
+ }
561
+ }
562
+ get cargoFeatures() {
563
+ try {
564
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
565
+ wasm.__wbg_get_buildmetadata_cargoFeatures(retptr, this.__wbg_ptr);
566
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
567
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
568
+ return getStringFromWasm0(r0, r1);
569
+ } finally {
570
+ wasm.__wbindgen_add_to_stack_pointer(16);
571
+ }
572
+ }
573
+ get optLevel() {
574
+ try {
575
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
576
+ wasm.__wbg_get_buildmetadata_optLevel(retptr, this.__wbg_ptr);
577
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
578
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
579
+ return getStringFromWasm0(r0, r1);
580
+ } finally {
581
+ wasm.__wbindgen_add_to_stack_pointer(16);
582
+ }
583
+ }
584
+ get targetTriple() {
585
+ try {
586
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
587
+ wasm.__wbg_get_buildmetadata_targetTriple(retptr, this.__wbg_ptr);
588
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
589
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
590
+ return getStringFromWasm0(r0, r1);
591
+ } finally {
592
+ wasm.__wbindgen_add_to_stack_pointer(16);
593
+ }
594
+ }
595
+ get gitBranch() {
596
+ try {
597
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
598
+ wasm.__wbg_get_buildmetadata_gitBranch(retptr, this.__wbg_ptr);
599
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
600
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
601
+ return getStringFromWasm0(r0, r1);
602
+ } finally {
603
+ wasm.__wbindgen_add_to_stack_pointer(16);
604
+ }
605
+ }
606
+ get gitDescribe() {
607
+ try {
608
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
609
+ wasm.__wbg_get_buildmetadata_gitDescribe(retptr, this.__wbg_ptr);
610
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
611
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
612
+ return getStringFromWasm0(r0, r1);
613
+ } finally {
614
+ wasm.__wbindgen_add_to_stack_pointer(16);
615
+ }
616
+ }
617
+ get gitSha() {
618
+ try {
619
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
620
+ wasm.__wbg_get_buildmetadata_gitSha(retptr, this.__wbg_ptr);
621
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
622
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
623
+ return getStringFromWasm0(r0, r1);
624
+ } finally {
625
+ wasm.__wbindgen_add_to_stack_pointer(16);
626
+ }
627
+ }
628
+ get gitDirty() {
629
+ try {
630
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
631
+ wasm.__wbg_get_buildmetadata_gitDirty(retptr, this.__wbg_ptr);
632
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
633
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
634
+ return getStringFromWasm0(r0, r1);
635
+ } finally {
636
+ wasm.__wbindgen_add_to_stack_pointer(16);
637
+ }
638
+ }
639
+ }
502
640
  var CommitBundleFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
503
641
  }, unregister: () => {
504
642
  } } : new FinalizationRegistry((ptr) => wasm.__wbg_commitbundle_free(ptr >>> 0, 1));
@@ -644,6 +782,10 @@ class CoreCrypto {
644
782
  wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
645
783
  }
646
784
  }
785
+ static build_metadata() {
786
+ const ret = wasm.corecrypto_build_metadata();
787
+ return BuildMetadata.__wrap(ret);
788
+ }
647
789
  static _internal_new(path, key, client_id, ciphersuites, entropy_seed, nb_key_package) {
648
790
  const ptr0 = passStringToWasm0(path, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
649
791
  const len0 = WASM_VECTOR_LEN;
@@ -682,10 +824,13 @@ class CoreCrypto {
682
824
  const ret = wasm.corecrypto_wipe(ptr);
683
825
  return takeObject(ret);
684
826
  }
685
- static set_logger(logger, level) {
827
+ static set_logger(logger) {
686
828
  _assertClass(logger, CoreCryptoWasmLogger);
687
829
  var ptr0 = logger.__destroy_into_raw();
688
- wasm.corecrypto_set_logger(ptr0, level);
830
+ wasm.corecrypto_set_logger(ptr0);
831
+ }
832
+ static set_max_log_level(level) {
833
+ wasm.corecrypto_set_max_log_level(level);
689
834
  }
690
835
  set_callbacks(callbacks) {
691
836
  _assertClass(callbacks, CoreCryptoWasmCallbacks);
@@ -725,10 +870,6 @@ class CoreCrypto {
725
870
  const ret = wasm.corecrypto_reseed_rng(this.__wbg_ptr, ptr0, len0);
726
871
  return takeObject(ret);
727
872
  }
728
- proteus_init() {
729
- const ret = wasm.corecrypto_proteus_init(this.__wbg_ptr);
730
- return takeObject(ret);
731
- }
732
873
  proteus_session_exists(session_id) {
733
874
  const ptr0 = passStringToWasm0(session_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
734
875
  const len0 = WASM_VECTOR_LEN;
@@ -1076,6 +1217,10 @@ class CoreCryptoContext {
1076
1217
  const ret = wasm.corecryptocontext_get_client_ids(this.__wbg_ptr, ptr0, len0);
1077
1218
  return takeObject(ret);
1078
1219
  }
1220
+ proteus_init() {
1221
+ const ret = wasm.corecryptocontext_proteus_init(this.__wbg_ptr);
1222
+ return takeObject(ret);
1223
+ }
1079
1224
  proteus_session_from_prekey(session_id, prekey) {
1080
1225
  const ptr0 = passStringToWasm0(session_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1081
1226
  const len0 = WASM_VECTOR_LEN;
@@ -2033,58 +2178,58 @@ function __wbg_get_imports() {
2033
2178
  imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
2034
2179
  takeObject(arg0);
2035
2180
  };
2036
- imports.wbg.__wbindgen_bigint_from_u64 = function(arg0) {
2037
- const ret = BigInt.asUintN(64, arg0);
2181
+ imports.wbg.__wbg_ffiwiree2eidentity_new = function(arg0) {
2182
+ const ret = FfiWireE2EIdentity.__wrap(arg0);
2038
2183
  return addHeapObject(ret);
2039
2184
  };
2040
2185
  imports.wbg.__wbindgen_number_new = function(arg0) {
2041
2186
  const ret = arg0;
2042
2187
  return addHeapObject(ret);
2043
2188
  };
2044
- imports.wbg.__wbg_ffiwiree2eidentity_new = function(arg0) {
2045
- const ret = FfiWireE2EIdentity.__wrap(arg0);
2046
- return addHeapObject(ret);
2047
- };
2048
- imports.wbg.__wbg_execute_1168d8ced41f5786 = function() {
2189
+ imports.wbg.__wbg_execute_a85f95e9599e213e = function() {
2049
2190
  return handleError(function(arg0, arg1) {
2050
2191
  const ret = getObject(arg0).execute(CoreCryptoContext.__wrap(arg1));
2051
2192
  return addHeapObject(ret);
2052
2193
  }, arguments);
2053
2194
  };
2054
- imports.wbg.__wbg_newacmeorder_new = function(arg0) {
2055
- const ret = NewAcmeOrder.__wrap(arg0);
2056
- return addHeapObject(ret);
2057
- };
2058
- imports.wbg.__wbg_newacmeauthz_new = function(arg0) {
2059
- const ret = NewAcmeAuthz.__wrap(arg0);
2060
- return addHeapObject(ret);
2061
- };
2062
2195
  imports.wbg.__wbg_proteusautoprekeybundle_new = function(arg0) {
2063
2196
  const ret = ProteusAutoPrekeyBundle.__wrap(arg0);
2064
2197
  return addHeapObject(ret);
2065
2198
  };
2199
+ imports.wbg.__wbg_newacmeorder_new = function(arg0) {
2200
+ const ret = NewAcmeOrder.__wrap(arg0);
2201
+ return addHeapObject(ret);
2202
+ };
2066
2203
  imports.wbg.__wbg_acmedirectory_new = function(arg0) {
2067
2204
  const ret = AcmeDirectory.__wrap(arg0);
2068
2205
  return addHeapObject(ret);
2069
2206
  };
2207
+ imports.wbg.__wbg_newacmeauthz_new = function(arg0) {
2208
+ const ret = NewAcmeAuthz.__wrap(arg0);
2209
+ return addHeapObject(ret);
2210
+ };
2070
2211
  imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
2071
2212
  const ret = getStringFromWasm0(arg0, arg1);
2072
2213
  return addHeapObject(ret);
2073
2214
  };
2215
+ imports.wbg.__wbindgen_bigint_from_u64 = function(arg0) {
2216
+ const ret = BigInt.asUintN(64, arg0);
2217
+ return addHeapObject(ret);
2218
+ };
2074
2219
  imports.wbg.__wbg_buffereddecryptedmessage_new = function(arg0) {
2075
2220
  const ret = BufferedDecryptedMessage.__wrap(arg0);
2076
2221
  return addHeapObject(ret);
2077
2222
  };
2078
- imports.wbg.__wbg_corecrypto_new = function(arg0) {
2079
- const ret = CoreCrypto.__wrap(arg0);
2223
+ imports.wbg.__wbg_commitbundle_new = function(arg0) {
2224
+ const ret = CommitBundle.__wrap(arg0);
2080
2225
  return addHeapObject(ret);
2081
2226
  };
2082
2227
  imports.wbg.__wbg_proposalbundle_new = function(arg0) {
2083
2228
  const ret = ProposalBundle.__wrap(arg0);
2084
2229
  return addHeapObject(ret);
2085
2230
  };
2086
- imports.wbg.__wbg_commitbundle_new = function(arg0) {
2087
- const ret = CommitBundle.__wrap(arg0);
2231
+ imports.wbg.__wbg_corecrypto_new = function(arg0) {
2232
+ const ret = CoreCrypto.__wrap(arg0);
2088
2233
  return addHeapObject(ret);
2089
2234
  };
2090
2235
  imports.wbg.__wbindgen_object_clone_ref = function(arg0) {
@@ -2099,6 +2244,14 @@ function __wbg_get_imports() {
2099
2244
  getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
2100
2245
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
2101
2246
  };
2247
+ imports.wbg.__wbindgen_is_undefined = function(arg0) {
2248
+ const ret = getObject(arg0) === undefined;
2249
+ return ret;
2250
+ };
2251
+ imports.wbg.__wbindgen_in = function(arg0, arg1) {
2252
+ const ret = getObject(arg0) in getObject(arg1);
2253
+ return ret;
2254
+ };
2102
2255
  imports.wbg.__wbindgen_boolean_get = function(arg0) {
2103
2256
  const v = getObject(arg0);
2104
2257
  const ret = typeof v === "boolean" ? v ? 1 : 0 : 2;
@@ -2127,10 +2280,6 @@ function __wbg_get_imports() {
2127
2280
  const ret = typeof val === "object" && val !== null;
2128
2281
  return ret;
2129
2282
  };
2130
- imports.wbg.__wbindgen_in = function(arg0, arg1) {
2131
- const ret = getObject(arg0) in getObject(arg1);
2132
- return ret;
2133
- };
2134
2283
  imports.wbg.__wbg_queueMicrotask_48421b3cc9052b68 = function(arg0) {
2135
2284
  const ret = getObject(arg0).queueMicrotask;
2136
2285
  return addHeapObject(ret);
@@ -2163,10 +2312,6 @@ function __wbg_get_imports() {
2163
2312
  const ret = getObject(arg0) === null;
2164
2313
  return ret;
2165
2314
  };
2166
- imports.wbg.__wbindgen_is_undefined = function(arg0) {
2167
- const ret = getObject(arg0) === undefined;
2168
- return ret;
2169
- };
2170
2315
  imports.wbg.__wbindgen_jsval_loose_eq = function(arg0, arg1) {
2171
2316
  const ret = getObject(arg0) == getObject(arg1);
2172
2317
  return ret;
@@ -2665,6 +2810,12 @@ function __wbg_get_imports() {
2665
2810
  const ret = new Error(getStringFromWasm0(arg0, arg1));
2666
2811
  return addHeapObject(ret);
2667
2812
  };
2813
+ imports.wbg.__wbg_setcause_95acfe0bd827ffdb = function(arg0, arg1) {
2814
+ getObject(arg0).cause = getObject(arg1);
2815
+ };
2816
+ imports.wbg.__wbg_setname_ef058a4c6ff7e6d4 = function(arg0, arg1, arg2) {
2817
+ getObject(arg0).name = getStringFromWasm0(arg1, arg2);
2818
+ };
2668
2819
  imports.wbg.__wbg_apply_353f4c9ca391d52b = function() {
2669
2820
  return handleError(function(arg0, arg1, arg2) {
2670
2821
  const ret = getObject(arg0).apply(getObject(arg1), getObject(arg2));
@@ -2748,7 +2899,7 @@ function __wbg_get_imports() {
2748
2899
  const a = state0.a;
2749
2900
  state0.a = 0;
2750
2901
  try {
2751
- return __wbg_adapter_497(a, state0.b, arg02, arg12);
2902
+ return __wbg_adapter_512(a, state0.b, arg02, arg12);
2752
2903
  } finally {
2753
2904
  state0.a = a;
2754
2905
  }
@@ -2834,16 +2985,16 @@ function __wbg_get_imports() {
2834
2985
  const ret = v0;
2835
2986
  return addHeapObject(ret);
2836
2987
  };
2837
- imports.wbg.__wbindgen_closure_wrapper3447 = function(arg0, arg1, arg2) {
2838
- const ret = makeMutClosure(arg0, arg1, 751, __wbg_adapter_54);
2988
+ imports.wbg.__wbindgen_closure_wrapper3710 = function(arg0, arg1, arg2) {
2989
+ const ret = makeMutClosure(arg0, arg1, 899, __wbg_adapter_54);
2839
2990
  return addHeapObject(ret);
2840
2991
  };
2841
- imports.wbg.__wbindgen_closure_wrapper13040 = function(arg0, arg1, arg2) {
2842
- const ret = makeMutClosure(arg0, arg1, 2019, __wbg_adapter_57);
2992
+ imports.wbg.__wbindgen_closure_wrapper13415 = function(arg0, arg1, arg2) {
2993
+ const ret = makeMutClosure(arg0, arg1, 2169, __wbg_adapter_57);
2843
2994
  return addHeapObject(ret);
2844
2995
  };
2845
- imports.wbg.__wbindgen_closure_wrapper15217 = function(arg0, arg1, arg2) {
2846
- const ret = makeMutClosure(arg0, arg1, 2263, __wbg_adapter_60);
2996
+ imports.wbg.__wbindgen_closure_wrapper15391 = function(arg0, arg1, arg2) {
2997
+ const ret = makeMutClosure(arg0, arg1, 2396, __wbg_adapter_60);
2847
2998
  return addHeapObject(ret);
2848
2999
  };
2849
3000
  return imports;
@@ -3147,6 +3298,9 @@ class CoreCryptoContext2 {
3147
3298
  async randomBytes(length) {
3148
3299
  return await CoreCryptoError.asyncMapErr(this.#ctx.random_bytes(length));
3149
3300
  }
3301
+ async proteusInit() {
3302
+ return await CoreCryptoError.asyncMapErr(this.#ctx.proteus_init());
3303
+ }
3150
3304
  async proteusSessionFromPrekey(sessionId, prekey) {
3151
3305
  return await CoreCryptoError.asyncMapErr(this.#ctx.proteus_session_from_prekey(sessionId, prekey));
3152
3306
  }
@@ -3298,33 +3452,35 @@ class CoreCryptoContext2 {
3298
3452
 
3299
3453
  // bindings/js/CoreCrypto.ts
3300
3454
  class CoreCryptoError extends Error {
3301
- rustStackTrace;
3455
+ errorStack;
3302
3456
  proteusErrorCode;
3303
- constructor(msg, richError, ...params) {
3304
- super(msg, ...params);
3457
+ constructor(richError, ...params) {
3458
+ super(richError.message, ...params);
3305
3459
  Object.setPrototypeOf(this, new.target.prototype);
3306
- this.name = richError.errorName;
3307
- this.rustStackTrace = richError.rustStackTrace;
3308
- this.proteusErrorCode = richError.proteusErrorCode;
3460
+ if (richError.error_name) {
3461
+ this.name = richError.error_name;
3462
+ }
3463
+ if (richError.error_stack) {
3464
+ this.errorStack = richError.error_stack;
3465
+ } else {
3466
+ this.errorStack = [];
3467
+ }
3468
+ if (richError.proteus_error_code) {
3469
+ this.proteusErrorCode = richError.proteus_error_code;
3470
+ } else {
3471
+ this.proteusErrorCode = null;
3472
+ }
3309
3473
  }
3310
3474
  static fallback(msg, ...params) {
3311
3475
  console.warn(`Cannot build CoreCryptoError, falling back to standard Error! ctx: ${msg}`);
3312
3476
  return new Error(msg, ...params);
3313
3477
  }
3314
3478
  static build(msg, ...params) {
3315
- const parts = msg.split(`
3316
-
3317
- `);
3318
- if (parts.length < 2) {
3319
- const cause = new Error("CoreCrypto WASM FFI Error doesn't have enough elements to build a rich error");
3320
- return this.fallback(msg, { cause }, ...params);
3321
- }
3322
- const [errMsg, richErrorJSON] = parts;
3323
3479
  try {
3324
- const richError = JSON.parse(richErrorJSON);
3325
- return new this(errMsg, richError, ...params);
3480
+ const richError = JSON.parse(msg);
3481
+ return new this(richError, ...params);
3326
3482
  } catch (cause) {
3327
- return this.fallback(msg, { cause }, ...params);
3483
+ return this.fallback(msg, ...params);
3328
3484
  }
3329
3485
  }
3330
3486
  static fromStdError(e) {
@@ -3434,7 +3590,15 @@ var CoreCryptoLogLevel2;
3434
3590
  })(CoreCryptoLogLevel2 ||= {});
3435
3591
  function initLogger(logger, level, ctx = null) {
3436
3592
  const wasmLogger = new CoreCryptoWasmLogger(logger.log, ctx);
3437
- CoreCrypto2.setLogger(wasmLogger, level);
3593
+ CoreCrypto2.setLogger(wasmLogger);
3594
+ CoreCrypto2.setMaxLogLevel(level);
3595
+ }
3596
+ function setLogger(logger, ctx = null) {
3597
+ const wasmLogger = new CoreCryptoWasmLogger(logger.log, ctx);
3598
+ CoreCrypto2.setLogger(wasmLogger);
3599
+ }
3600
+ function setMaxLogLevel(level) {
3601
+ CoreCrypto2.setMaxLogLevel(level);
3438
3602
  }
3439
3603
 
3440
3604
  class CoreCrypto2 {
@@ -3453,9 +3617,13 @@ class CoreCrypto2 {
3453
3617
  this.#module = await core_crypto_ffi_default(wasmFilePath);
3454
3618
  }
3455
3619
  }
3456
- static setLogger(logger, level) {
3620
+ static setLogger(logger) {
3621
+ this.#assertModuleLoaded();
3622
+ CoreCrypto.set_logger(logger);
3623
+ }
3624
+ static setMaxLogLevel(level) {
3457
3625
  this.#assertModuleLoaded();
3458
- CoreCrypto.set_logger(logger, level);
3626
+ CoreCrypto.set_max_log_level(level);
3459
3627
  }
3460
3628
  static async init({
3461
3629
  databaseName,
@@ -3485,21 +3653,20 @@ class CoreCrypto2 {
3485
3653
  let result;
3486
3654
  let error = null;
3487
3655
  try {
3488
- await this.#cc.transaction({
3656
+ await CoreCryptoError.asyncMapErr(this.#cc.transaction({
3489
3657
  execute: async (ctx) => {
3490
3658
  try {
3491
- result = await callback(CoreCryptoContext2.fromFfiContext(ctx));
3659
+ result = await CoreCryptoError.asyncMapErr(callback(CoreCryptoContext2.fromFfiContext(ctx)));
3492
3660
  } catch (e) {
3493
- if (e instanceof CoreCryptoError) {
3494
- error = e;
3495
- } else {
3496
- error = CoreCryptoError.fromStdError(e);
3497
- }
3661
+ error = e;
3498
3662
  throw error;
3499
3663
  }
3500
3664
  }
3501
- });
3502
- } catch (_) {
3665
+ }));
3666
+ } catch (e) {
3667
+ if (error === null) {
3668
+ error = e;
3669
+ }
3503
3670
  }
3504
3671
  if (error !== null) {
3505
3672
  throw error;
@@ -3632,7 +3799,7 @@ class CoreCrypto2 {
3632
3799
  return await CoreCryptoError.asyncMapErr(this.#cc.reseed_rng(seed));
3633
3800
  }
3634
3801
  async proteusInit() {
3635
- return await CoreCryptoError.asyncMapErr(this.#cc.proteus_init());
3802
+ return await this.transaction(async (ctx) => await ctx.proteusInit());
3636
3803
  }
3637
3804
  async proteusSessionFromPrekey(sessionId, prekey) {
3638
3805
  return await this.transaction(async (ctx) => await ctx.proteusSessionFromPrekey(sessionId, prekey));
@@ -3758,6 +3925,10 @@ class CoreCrypto2 {
3758
3925
  this.#assertModuleLoaded();
3759
3926
  return CoreCrypto.version();
3760
3927
  }
3928
+ static buildMetadata() {
3929
+ this.#assertModuleLoaded();
3930
+ return CoreCrypto.build_metadata();
3931
+ }
3761
3932
  }
3762
3933
 
3763
3934
  class E2eiEnrollment {
@@ -3836,6 +4007,8 @@ var E2eiConversationState;
3836
4007
  E2eiConversationState2[E2eiConversationState2["NotEnabled"] = 3] = "NotEnabled";
3837
4008
  })(E2eiConversationState ||= {});
3838
4009
  export {
4010
+ setMaxLogLevel,
4011
+ setLogger,
3839
4012
  normalizeEnum,
3840
4013
  mapWireIdentity,
3841
4014
  initLogger,