BIP-39 mnemonic phrase generation and seed derivation.
A mnemonic is a human-readable representation of entropy used to create deterministic wallets. Words are drawn from a standard 2048-word list and include a built-in checksum.
Note: The wordlist language is fixed at compile time and defaults to English. Non-English BIP-39 wordlists are not currently supported.
Examples
iex> mnemonic = BSV.Mnemonic.generate()
iex> is_binary(mnemonic) and length(String.split(mnemonic)) == 12
true
iex> seed = BSV.Mnemonic.to_seed("abandon " |> String.duplicate(11) |> Kernel.<>("about") |> String.trim())
iex> byte_size(seed) == 64
true
Summary
Functions
Create a mnemonic phrase from raw entropy bytes.
Generate a random mnemonic phrase.
Extract the raw entropy bytes from a mnemonic phrase.
Derive a 512-bit seed from a mnemonic phrase using PBKDF2-HMAC-SHA512.
Validate a mnemonic phrase (correct word count, valid words, valid checksum).
Types
@type entropy_bits() :: 128 | 160 | 192 | 224 | 256
Entropy bit length
@type seed() :: <<_::512>>
Binary seed derived from mnemonic
@type t() :: String.t()
Mnemonic phrase (space-separated words)
Functions
Create a mnemonic phrase from raw entropy bytes.
The entropy must be 16, 20, 24, 28, or 32 bytes (128–256 bits).
@spec generate(entropy_bits()) :: t()
Generate a random mnemonic phrase.
Options
entropy_bits— one of 128 (12 words), 160 (15), 192 (18), 224 (21), 256 (24). Defaults to 128.
Extract the raw entropy bytes from a mnemonic phrase.
Derive a 512-bit seed from a mnemonic phrase using PBKDF2-HMAC-SHA512.
Options
:passphrase— optional passphrase (BIP-39 "25th word"). Default"".:encoding—:hexor:base64to encode the result. Defaultnil(raw binary).
Validate a mnemonic phrase (correct word count, valid words, valid checksum).