# Mnemonic

Utility functions for generating and working with [BIP-39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) mnemonics.

:::info
The `Mnemonic` module is a friendly wrapper over [`@scure/bip39`](https://github.com/paulmillr/scure-bip39), an **audited** implementation of [BIP-39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki)
:::

## Examples

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

* [Generating a Random Mnemonic](#generating-a-random-mnemonic)

* [Converting to Private Key](#converting-to-private-key)

* [Converting to HD Key](#converting-to-hd-key)

* [Converting to Seed](#converting-to-seed)

### Generating a Random Mnemonic

Random mnemonics can be generated using [`Mnemonic.random`](/api/Mnemonic/random):

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

const mnemonic = Mnemonic.random(Mnemonic.english)
// @log: 'buyer zoo end danger ice capable shrug naive twist relief mass bonus'
```

### Converting to Private Key

Mnemonics can be converted to a private key using [`Mnemonic.toPrivateKey`](/api/Mnemonic/toPrivateKey):

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

const privateKey = Mnemonic.toPrivateKey(
  'buyer zoo end danger ice capable shrug naive twist relief mass bonus'
)
// @log: '0x...'
```

### Converting to HD Key

Mnemonics can be converted to a HD Key using [`Mnemonic.toHdKey`](/api/Mnemonic/toHdKey):

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

const hdKey = Mnemonic.toHdKey(
  'buyer zoo end danger ice capable shrug naive twist relief mass bonus'
)
```

### Converting to Seed

Mnemonics can be converted to a master seed using [`Mnemonic.toSeed`](/api/Mnemonic/toSeed):

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

const mnemonic =
  'buyer zoo end danger ice capable shrug naive twist relief mass bonus'
const seed = Mnemonic.toSeed(mnemonic)
// @log: Uint8Array [...64 bytes]
```

## Functions

| Name                | Description                         |
| ------------------- | ----------------------------------- |
| [`Mnemonic.path`](/api/Mnemonic/path) | Creates an Ethereum-based BIP-44 HD path. |
| [`Mnemonic.random`](/api/Mnemonic/random) | Generates a random mnemonic. |
| [`Mnemonic.toHdKey`](/api/Mnemonic/toHdKey) | Converts a mnemonic to a HD Key. |
| [`Mnemonic.toPrivateKey`](/api/Mnemonic/toPrivateKey) | Converts a mnemonic to a private key. |
| [`Mnemonic.toSeed`](/api/Mnemonic/toSeed) | Converts a mnemonic to a master seed. |
| [`Mnemonic.validate`](/api/Mnemonic/validate) | Checks if a mnemonic is valid, given a wordlist. |
