Skip to main content

tlsn_wasm/
lib.rs

1//! TLSNotary WASM bindings.
2
3#![cfg(target_arch = "wasm32")]
4#![deny(unreachable_pub, unused_must_use, clippy::all)]
5#![allow(non_snake_case)]
6
7pub mod handler;
8pub(crate) mod io;
9mod log;
10pub mod prover;
11#[cfg(feature = "test")]
12pub mod tests;
13pub mod types;
14pub mod verifier;
15
16pub use log::{LoggingConfig, LoggingLevel};
17
18use wasm_bindgen::prelude::*;
19use wasm_bindgen_futures::JsFuture;
20
21#[cfg(feature = "test")]
22pub use tests::*;
23
24/// Initializes the module.
25#[wasm_bindgen]
26pub async fn initialize(
27    logging_config: Option<LoggingConfig>,
28    thread_count: usize,
29) -> Result<(), JsValue> {
30    log::init_logging(logging_config);
31
32    JsFuture::from(web_spawn::start_spawner()).await?;
33
34    // Initialize rayon global thread pool.
35    rayon::ThreadPoolBuilder::new()
36        .num_threads(thread_count)
37        .spawn_handler(|thread| {
38            // Drop join handle.
39            let _ = web_spawn::spawn(move || thread.run());
40            Ok(())
41        })
42        .build_global()
43        .unwrap_throw();
44
45    Ok(())
46}