Skip to content

Mnemonic

Utility functions for generating and working with BIP-39 mnemonics.

Examples

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

Generating a Random Mnemonic

Random mnemonics can be generated using Mnemonic.random:

import { Mnemonic } from 'ox'
 
const mnemonic = Mnemonic.random(Mnemonic.english)
'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:

import { Mnemonic } from 'ox'
 
const privateKey = Mnemonic.toPrivateKey('buyer zoo end danger ice capable shrug naive twist relief mass bonus')
'0x...'

Converting to HD Key

Mnemonics can be converted to a HD Key using Mnemonic.toHdKey:

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:

import { Mnemonic } from 'ox'
 
const mnemonic = 'buyer zoo end danger ice capable shrug naive twist relief mass bonus'
const seed = Mnemonic.toSeed(mnemonic)
Uint8Array [...64 bytes]

Functions

NameDescription
Mnemonic.pathCreates an Ethereum-based BIP-44 HD path.
Mnemonic.randomGenerates a random mnemonic.
Mnemonic.toHdKeyConverts a mnemonic to a HD Key.
Mnemonic.toPrivateKeyConverts a mnemonic to a private key.
Mnemonic.toSeedConverts a mnemonic to a master seed.
Mnemonic.validateChecks if a mnemonic is valid, given a wordlist.