#crypto-api #cryptography #testing #crypto


Wasmtime implementation of the wasi-crypto API

64 releases (33 stable)

12.0.2 Sep 14, 2023
11.0.2 Sep 14, 2023
11.0.1 Jul 24, 2023
10.0.2 Sep 14, 2023
0.25.0 Mar 16, 2021

#1467 in WebAssembly

Download history 62/week @ 2024-02-26 6/week @ 2024-03-11 198/week @ 2024-04-01 561/week @ 2024-04-22

759 downloads per month

Apache-2.0 WITH LLVM-exception

26K SLoC


This crate enables support for the wasi-crypto APIs in Wasmtime.

The sole purpose of the implementation is to allow bindings and application developers to test the proposed APIs. This implementation is not meant to be used in production. Like the specification, it is currently experimental and its functionality can quickly change.

Since the wasi-crypto API is expected to be an optional feature of WASI, this crate is currently separate from the wasi-common crate.

Wasmtime integration

Use the Wasmtime APIs to instantiate a Wasm module and link the wasi-crypto modules as follows:

use wasmtime_wasi_crypto::{
    WasiCryptoAsymmetricCommon, WasiCryptoCommon, WasiCryptoCtx, WasiCryptoSignatures,

let cx_crypto = WasiCryptoCtx::new();
WasiCryptoCommon::new(linker.store(), cx_crypto.clone()).add_to_linker(linker)?;
WasiCryptoAsymmetricCommon::new(linker.store(), cx_crypto.clone()).add_to_linker(linker)?;
WasiCryptoSignatures::new(linker.store(), cx_crypto.clone()).add_to_linker(linker)?;
WasiCryptoSymmetric::new(linker.store(), cx_crypto.clone()).add_to_linker(linker)?;

let wasi = wasmtime_wasi::old::snapshot_0::Wasi::new(linker.store(), mk_cx()?);

Building Wasmtime

Wasmtime must be compiled with the wasi-crypto feature flag (disabled by default) in order to include the crypto APIs.


Example rust bindings and assemblyscript bindings are provided to demonstrate how these APIs can be used and exposed to applications in an idiomatic way.


~1.5M SLoC