ppad-bip39-0.2.1: BIP39 mnemonic codes.
Copyright(c) 2025 Jared Tobin
LicenseMIT
MaintainerJared Tobin <jared@ppad.tech>
Safe HaskellNone
LanguageHaskell2010

Crypto.KDF.BIP39

Description

BIP39 mnemonic codes for deterministic key generation, supporting wordlists in multiple languages.

Synopsis

Mnemonic construction and validation

mnemonic Source #

Arguments

:: ByteString

128-256 bits of entropy

-> Text 

Generate a BIP39 mnemonic from some entropy, using the default English wordlist.

The entropy must be at least 128 bits long and at most 256 bits long. Providing invalid entropy will result in an ErrorCall exception.

>>> import qualified System.Entropy as E
>>> trop <- E.getEntropy 16
>>> mnemonic trop
"coral maze mimic half fat breeze thought club give brass bone snake"

_mnemonic Source #

Arguments

:: Wordlist 
-> ByteString

128-256 bits of entropy

-> Text 

Generate a BIP39 mnemonic from some entropy, using the provided wordlist.

The entropy must be at least 128 bits long and at most 256 bits long. Providing invalid entropy will result in an ErrorCall exception.

>>> import qualified System.Entropy as E
>>> trop <- E.getEntropy 16
>>> _mnemonic czech trop
"naslepo lysina dikobraz slupka beseda rorejs ostraha kobliha napevno blahobyt kazivost jiskra"

valid Source #

Arguments

:: Text

mnemonic

-> Bool

True if valid

Validate a mnemonic against the default English wordlist.

Verifies that the mnemonic has a valid length, and that every word is contained in the wordlist.

>>> valid "coral maze mimic half fat breeze thought club give brass bone snake"
True
>>> valid "coral maze mimic half fat breeze thought club give brass bone"
False

_valid Source #

Arguments

:: Wordlist 
-> Text

mnemonic

-> Bool

True if valid

Validate a mnemonic against a wordlist.

Verifies that the mnemonic has a valid length, and that every word is contained in the provided wordlist.

>>> let mnem = "持 樓 粗 殺 承 圖 湧 整 拿 路 式 棋"
>>> _valid chinese_traditional mnem
True
>>> _valid chinese_simplified mnem
False

Seed derivation

seed Source #

Arguments

:: Text

mnemonic

-> Text

passphrase (use e.g. "" or mempty if not required)

-> ByteString

seed

Derive a master seed from a provided mnemonic and passphrase, where the mnemonic has been generated from the default English wordlist.

The mnemonic's length and words are validated. If you want to validate the mnemonic's words against a non-English wordlist, use _seed.

>>> let mnem = "coral maze mimic half fat breeze thought club give brass bone snake"
>>  let pass = "hunter2"
>>> seed mnem pass
<512-bit long seed>

_seed Source #

Arguments

:: Wordlist

wordlist

-> Text

mnemonic

-> Text

passphrase (use e.g. "" or mempty if not required)

-> ByteString

seed

Derive a master seed from a provided mnemonic and passphrase, where the mnemonic has been generated from an arbitrary wordlist.

The provided mnemonic is checked for validity using _valid. Providing an invalid mnemonic will result in an ErrorCall exception.

>>> let mnem = "coral maze mimic half fat breeze thought club give brass bone snake"
>>  let pass = "hunter2"
>>> _seed english mnem pass
<512-bit long seed>

seed_unsafe Source #

Arguments

:: Text

mnemonic

-> Text

passphrase (use e.g. "" or mempty if not required)

-> ByteString

seed

Derive a master seed from a provided mnemonic and passphrase.

The mnemonic's length is validated, but its individual words are not. This function thus works for every wordlist.

>>> let mnem = "coral maze mimic half fat breeze thought club give brass bone snake"
>>  let pass = "hunter2"
>>> seed_unsafe mnem pass
<512-bit long seed>

Wordlists

Wordlists for various languages.

For the following examples:

>>> import qualified Data.Text.IO as TIO
>>> let trop = "0123456789abcdef"

newtype Wordlist Source #

A BIP39 wordlist.

Constructors

Wordlist (Array Text) 

english :: Wordlist Source #

The default English wordlist.

>>> TIO.putStrLn $ _mnemonic english trop
coral maze mimic half fat breeze thought club give brass bone snake

chinese_traditional :: Wordlist Source #

The default Traditional Chinese wordlist.

>>> TIO.putStrLn $ _mnemonic chinese_traditional trop
持 樓 粗 殺 承 圖 湧 整 拿 路 式 棋

chinese_simplified :: Wordlist Source #

The default Simplified Chinese wordlist.

>>> TIO.putStrLn $ _mnemonic chinese_simplified trop
持 楼 粗 杀 承 图 涌 整 拿 路 式 棋

czech :: Wordlist Source #

The default Czech wordlist.

>>> TIO.putStrLn $ _mnemonic czech trop
hadr omladina oslepit metr krajina deflace varovat flirt lovec dechovka cudnost svitek

french :: Wordlist Source #

The default French wordlist.

>>> TIO.putStrLn $ _mnemonic french trop
chlorure kimono légume flamme endroit bénéfice soulever céleste falaise belette banlieue reprise

korean :: Wordlist Source #

The default Korean wordlist.

>>> TIO.putStrLn $ _mnemonic korean trop
대문 어쩐지 여덟 설거지 볶음 그늘 태권도 단맛 상반기 균형 국왕 진출

italian :: Wordlist Source #

The default Italian wordlist.

>>> TIO.putStrLn $ _mnemonic italian trop
conferma nevrotico obbligo indole florido benigno svista cigno grotta belva barbaro sfocato

japanese :: Wordlist Source #

The default Japanese wordlist.

>>> TIO.putStrLn $ _mnemonic japanese trop
きおん たさい たまご しゃおん こふん えきたい ますく がはく しかい えおり うろこ ひとごみ

portuguese :: Wordlist Source #

The default Portuguese wordlist.

>>> TIO.putStrLn $ _mnemonic portuguese trop
capacho juba lareira figurado ejetar avaliar sonhador cachorro exposto autismo aterro refinar

spanish :: Wordlist Source #

The default Spanish wordlist.

>>> TIO.putStrLn $ _mnemonic spanish trop
charla marido mente guía explicar banco tapa casco gemelo balcón ayuda ropa