Rust -> Wasm bindings
Overview
Adding a New Binding
Example Implementation
use wasm_bindgen::prelude::*;
use num_bigint::BigUint;
#[wasm_bindgen]
pub fn your_function(
input_hex: &str, // Hex string input
input_array: Vec<JsValue>, // Array of values
) -> Result<JsValue, JsError> {
// Parse hex string to BigUint
let value = jsvalue_to_biguint(&JsValue::from_str(input_hex))?;
// Process array elements
let values: Vec<BigUint> = input_array
.iter()
.map(|v| jsvalue_to_biguint(v))
.collect::<Result<Vec<_>, _>>()?;
// Perform computation
let result = compute_something(&value, &values)
.map_err(|e| JsError::new(&e.to_string()))?;
// Return result as BigInt string
Ok(biguint_to_jsvalue(&result))
}Type Conversions
Error Handling
Available Functions
Function
Description
TypeScript Wrapper
Development notes
How wasm-pack is used to achieve interoperability
wasm-pack is used to achieve interoperabilityLast updated
Was this helpful?