# WASM Integration

The `quicproquo-core` crate supports compilation to `wasm32-unknown-unknown`
when the `native` feature is disabled. This exposes the pure-crypto subset of
the library for use in browsers or other WASM runtimes.

## Building for WASM

```bash
rustup target add wasm32-unknown-unknown

cargo build -p quicproquo-core \
    --target wasm32-unknown-unknown \
    --no-default-features
```

The `--no-default-features` flag disables the `native` feature, which gates
MLS (openmls), OPAQUE, Cap'n Proto, and tokio -- all of which have dependencies
that do not compile to WASM.

## What is available in WASM mode

The following modules compile to WASM and are fully functional:

| Module            | Description                                        |
|-------------------|----------------------------------------------------|
| `identity`        | Ed25519 identity keypair (generate, sign, verify)  |
| `hybrid_kem`      | X25519 + ML-KEM-768 hybrid key encapsulation       |
| `safety_numbers`  | Signal-style safety number computation             |
| `sealed_sender`   | Sender identity + Ed25519 signature envelope       |
| `app_message`     | Rich application message serialisation/parsing     |
| `padding`         | Message padding to hide plaintext lengths          |
| `transcript`      | Encrypted tamper-evident message transcript        |
| `error`           | `CoreError` type                                   |

## What is NOT available in WASM mode

The following require the `native` feature and will not compile to WASM:

- `group` -- MLS group state machine (openmls)
- `keypackage` -- MLS KeyPackage generation
- `hybrid_crypto` -- hybrid HPKE provider for OpenMLS
- `keystore` -- OpenMLS key store with disk persistence
- `opaque_auth` -- OPAQUE cipher suite configuration

Networking (`quicproquo-client`, `quicproquo-server`) is not available in WASM.

## Random number generation

On `wasm32`, the `getrandom` crate is configured with the `js` feature to
use the browser's `crypto.getRandomValues()` API. This is set automatically
in `quicproquo-core/Cargo.toml`:

```toml
[target.'cfg(target_arch = "wasm32")'.dependencies]
getrandom = { version = "0.2", features = ["js"] }
```

This means the WASM build works in browser environments out of the box.
For non-browser WASM runtimes (WASI, etc.), you may need to adjust the
`getrandom` backend.

## wasm-bindgen and the TypeScript SDK

The `wasm-bindgen` JS bindings are now implemented in
`sdks/typescript/wasm-crypto/`. This provides 13 JavaScript-callable functions
wrapping the WASM-compatible crypto modules:

```bash
cd sdks/typescript/wasm-crypto
wasm-pack build --target web --out-dir ../pkg
```

The resulting 175 KB WASM bundle is used by the `@quicproquo/client`
TypeScript SDK and the interactive browser demo.

See the [TypeScript SDK and Browser Demo](typescript-sdk.md) guide for
full details on building and running the browser demo.
