Copyright | (c) 2025 Jared Tobin |
---|---|
License | MIT |
Maintainer | Jared Tobin <jared@ppad.tech> |
Safe Haskell | None |
Language | Haskell2010 |
Crypto.KDF.BIP39
Description
BIP39 mnemonic codes for deterministic key generation, supporting wordlists in multiple languages.
Synopsis
- mnemonic :: ByteString -> Text
- _mnemonic :: Wordlist -> ByteString -> Text
- valid :: Text -> Bool
- _valid :: Wordlist -> Text -> Bool
- seed :: Text -> Text -> ByteString
- _seed :: Wordlist -> Text -> Text -> ByteString
- seed_unsafe :: Text -> Text -> ByteString
- newtype Wordlist = Wordlist (Array Text)
- english :: Wordlist
- chinese_traditional :: Wordlist
- chinese_simplified :: Wordlist
- czech :: Wordlist
- french :: Wordlist
- korean :: Wordlist
- italian :: Wordlist
- japanese :: Wordlist
- portuguese :: Wordlist
- spanish :: Wordlist
Mnemonic construction and validation
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"
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"
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
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
Arguments
:: Text | mnemonic |
-> Text | passphrase (use e.g. "" or |
-> 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>
Arguments
:: Wordlist | wordlist |
-> Text | mnemonic |
-> Text | passphrase (use e.g. "" or |
-> 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>
Arguments
:: Text | mnemonic |
-> Text | passphrase (use e.g. "" or |
-> 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"
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
持 楼 粗 杀 承 图 涌 整 拿 路 式 棋
The default Czech wordlist.
>>>
TIO.putStrLn $ _mnemonic czech trop
hadr omladina oslepit metr krajina deflace varovat flirt lovec dechovka cudnost svitek
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
The default Korean wordlist.
>>>
TIO.putStrLn $ _mnemonic korean trop
대문 어쩐지 여덟 설거지 볶음 그늘 태권도 단맛 상반기 균형 국왕 진출
The default Italian wordlist.
>>>
TIO.putStrLn $ _mnemonic italian trop
conferma nevrotico obbligo indole florido benigno svista cigno grotta belva barbaro sfocato
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