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;
11pub mod types;
12pub mod verifier;
13
14pub use log::{LoggingConfig, LoggingLevel};
15
16use wasm_bindgen::prelude::*;
17use wasm_bindgen_futures::JsFuture;
18
19/// Initializes the module.
20#[wasm_bindgen]
21pub async fn initialize(
22    logging_config: Option<LoggingConfig>,
23    thread_count: usize,
24) -> Result<(), JsValue> {
25    log::init_logging(logging_config);
26
27    JsFuture::from(web_spawn::start_spawner()).await?;
28
29    // Initialize rayon global thread pool.
30    rayon::ThreadPoolBuilder::new()
31        .num_threads(thread_count)
32        .spawn_handler(|thread| {
33            // Drop join handle.
34            let _ = web_spawn::spawn(move || thread.run());
35            Ok(())
36        })
37        .build_global()
38        .unwrap_throw();
39
40    Ok(())
41}