# Keystore.toKeyAsync

Extracts a Key asynchronously from a JSON Keystore to use for decryption.

## Imports

:::code-group
```ts [Named]
import { Keystore } from 'ox'
```

```ts [Entrypoint]
import * as Keystore from 'ox/Keystore'
```
:::

## Examples

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

// JSON keystore.
const keystore = { crypto: { ... }, id: '...', version: 3 }

const key = await Keystore.toKeyAsync(keystore, { password: 'hunter2' }) // [!code focus]

const decrypted = Keystore.decrypt(keystore, key)
```

## Definition

```ts
function toKeyAsync(
  keystore: Keystore.Keystore,
  options: toKeyAsync.Options,
): Promise<Key>
```

**Source:** [src/core/Keystore.ts](https://github.com/wevm/ox/blob/main/src/core/Keystore.ts#L580)

## Parameters

### keystore

* **Type:** [`Keystore.Keystore`](/api/Keystore/types#keystorekeystore)

JSON Keystore

#### keystore.cipher

* **Type:** `"aes-128-ctr"`

#### keystore.cipherparams

* **Type:** `{ iv: string; }`

#### keystore.ciphertext

* **Type:** `string`

#### keystore.crypto

* **Type:** `{ cipher: "aes-128-ctr"; ciphertext: string; cipherparams: { iv: string; }; mac: string; } & Pick`

#### keystore.id

* **Type:** `string`

#### keystore.iv

* **Type:** `string`

#### keystore.mac

* **Type:** `string`

#### keystore.version

* **Type:** `3`

### options

* **Type:** `toKeyAsync.Options`

Options

#### options.password

* **Type:** `string`

Password to derive key from.

## Return Type

Key

[`Promise<Key>`](/api/Keystore/types#keystorekey)
