# Engine

WASM implementations of Ox's supported cryptographic primitives, compiled
from C.

Install it during startup. WASM must be compiled asynchronously, so the
`await` lives there. Every cryptographic call afterwards is synchronous.

:::note
Performance varies by primitive, input size, runtime, and processor. Run
`pnpm bench:engines` to compare the available implementations on your target
machine.
:::

## Examples

```ts twoslash
// @noErrors
import { Engine, Hash } from 'ox/wasm'

await Engine.install()

Hash.sha256('0xdeadbeef')
```

## Functions

| Name                | Description                         |
| ------------------- | ----------------------------------- |
| [`Engine.engine`](/wasm/crypto/Engine/engine) | Compiles every WASM implementation this entrypoint provides, without installing it. |
| [`Engine.get`](/wasm/crypto/Engine/get) | Returns the installed engine. |
| [`Engine.install`](/wasm/crypto/Engine/install) | Compiles and installs every WASM implementation this entrypoint provides. |
| [`Engine.reset`](/wasm/crypto/Engine/reset) | Restores ox's default implementations. |
| [`Engine.set`](/wasm/crypto/Engine/set) | Installs crypto implementations, replacing the `@noble/*` implementations ox uses by default. |
| [`Engine.with`](/wasm/crypto/Engine/with) | Runs a function with an engine installed, then restores the previous engine. |

## Errors

| Name                | Description                         |
| ------------------- | ----------------------------------- |
| [`Engine.AsyncScopeError`](/wasm/crypto/Engine/errors#engineasyncscopeerror) | Thrown when [`Engine.with`](/wasm/crypto/Engine/with) is given an asynchronous function. |
| [`Engine.InvalidSlotValueError`](/wasm/crypto/Engine/errors#engineinvalidslotvalueerror) | Thrown when an engine slot is not an object or `undefined`. |
| [`Engine.UnknownPrimitiveError`](/wasm/crypto/Engine/errors#engineunknownprimitiveerror) | Thrown when a slot is given an unrecognized primitive name. |
| [`Engine.UnknownSlotError`](/wasm/crypto/Engine/errors#engineunknownsloterror) | Thrown when an unrecognized engine slot is supplied. |
