# Engine

Functions for delegating ox's cryptography to a different implementation.

Ox uses [`@noble`](https://github.com/paulmillr/noble-hashes) and
[`@scure`](https://github.com/paulmillr/scure-bip32) by default. An engine
replaces those implementations with your own — for example a WASM build of an
audited C library.

## Examples

Below are some examples demonstrating common usages of the `Engine` module:

* [Installing an Engine](#installing-an-engine)

* [Overriding a Single Primitive](#overriding-a-single-primitive)

### Installing an Engine

Engine slots are named after ox modules, and everything is optional: any slot
or function you leave out keeps using ox's default implementation.

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

await Engine.load()
```

### Overriding a Single Primitive

```ts twoslash
import { Engine } from 'ox'

Engine.set({
  Hash: { keccak256: () => new Uint8Array(32) }
})
```

## Functions

| Name                | Description                         |
| ------------------- | ----------------------------------- |
| [`Engine.get`](/api/Engine/get) | Returns the installed engine. |
| [`Engine.reset`](/api/Engine/reset) | Restores ox's default implementations. |
| [`Engine.set`](/api/Engine/set) | Installs crypto implementations, replacing the `@noble/*` implementations ox uses by default. |
| [`Engine.with`](/api/Engine/with) | Runs a function with an engine installed, then restores the previous engine. |

## Errors

| Name                | Description                         |
| ------------------- | ----------------------------------- |
| [`Engine.AsyncScopeError`](/api/Engine/errors#engineasyncscopeerror) | Thrown when [`Engine.with`](/api/Engine/with) is given an asynchronous function. |
| [`Engine.UnknownPrimitiveError`](/api/Engine/errors#engineunknownprimitiveerror) | Thrown when a slot is given an unrecognized primitive name. |
| [`Engine.UnknownSlotError`](/api/Engine/errors#engineunknownsloterror) | Thrown when an unrecognized engine slot is supplied. |
