This folder defines the main necessary Rust dependencies (in Cargo.toml
) with the rust-verkle dependendy in its center.
For building the WASM code and managing the interactions between JavaScript/TypeScript and WASM wasm-pack is being used and will need a separate initial installation.
Additionally wasm-bindgen-cli and (optional, for optimization) wasm-opt need to be installed.
The WASM build process follows the "Compiling from Rust to WASM" Mozilla web docs tutorial which can be used for an introduction to the topic.
The low level API for the interaction with the WASM code is written in Rust and located in the ./src subfolder and looks like the following:
#[wasm_bindgen]
pub fn element_sub(lhs: ElementWrapper, rhs: ElementWrapper) -> ElementWrapper {
ElementWrapper {
inner: lhs.inner - rhs.inner,
}
}
These API elements are compiled during the wasm-pack
build process (see below) and exposed in JavaScript/TypeScript as the final low level API.
For an ESM build run:
wasm-pack build
You should see a pkg
folder appear.
To build a Node.js compatible module run:
wasm-pack build --target nodejs