Mnemoniac (mnemoniac v0.1.1)
Mnemoniac is an implementation of BIP-39 which describes generation of mnemonic codes or mnemonic sentences - a group of easy to remember words - for the generation of deterministic wallets.
See https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki
Link to this section Summary
Functions
Create a random mnemonic with the provided number of words. By default, the number of words is 24. Allowed numbers of words are 3, 6, 12, 15, 18, 24
Similar to create_mnemonic/1
, but fails the number of words is not supported
Create a mnemonic from entropy. The supported byte sizes are 16, 20, 24, 32
Similar to create_mnemonic_from_entropy/1
, but fails the entropy has unsupported byte size
Return supported entopy bit sizes
Return supported numbers of words that can be used for mnemonic generation
Return a map of word numbers to entropy bits.
Return all 2048 words used for mnemonic generation
Link to this section Functions
create_mnemonic(word_number \\ Enum.max([3, 6, 12, 15, 18, 21, 24]))
@spec create_mnemonic(non_neg_integer()) :: {:ok, String.t()} | {:error, :invalid_number}
Create a random mnemonic with the provided number of words. By default, the number of words is 24. Allowed numbers of words are 3, 6, 12, 15, 18, 24
examples
Examples
iex> {:ok, mnemonic} = Mnemoniac.create_mnemonic()
iex> mnemonic |> String.split(" ") |> Enum.count()
24
iex> {:ok, mnemonic} = Mnemoniac.create_mnemonic(12)
iex> mnemonic |> String.split(" ") |> Enum.count()
12
iex> Mnemoniac.create_mnemonic(10)
{:error, :invalid_number}
create_mnemonic!(word_number \\ Enum.max([3, 6, 12, 15, 18, 21, 24]))
@spec create_mnemonic!(non_neg_integer()) :: String.t() | no_return()
Similar to create_mnemonic/1
, but fails the number of words is not supported
examples
Examples
iex> mnemonic = Mnemoniac.create_mnemonic!()
iex> mnemonic |> String.split(" ") |> Enum.count()
24
iex> mnemonic = Mnemoniac.create_mnemonic!(12)
iex> mnemonic |> String.split(" ") |> Enum.count()
12
iex> Mnemoniac.create_mnemonic!(10)
** (ArgumentError) Number of words 10 is not supported, please use one of the [3, 6, 12, 15, 18, 21, 24]
create_mnemonic_from_entropy(entropy)
Create a mnemonic from entropy. The supported byte sizes are 16, 20, 24, 32
examples
Examples
iex> Mnemoniac.create_mnemonic_from_entropy(<<6, 197, 169, 93, 98, 210, 82, 216, 148, 177, 1, 251, 142, 15, 154, 85, 140, 0, 13, 202,234, 160, 129, 218>>)
{:ok, "almost coil firm shield cement hobby fan cage wine idea track prison scale alone close favorite limb still"}
iex> Mnemoniac.create_mnemonic_from_entropy(<<6, 197, 169, 93, 98, 210, 82, 216, 148, 177, 1, 251, 142, 15, 154, 85, 140, 0, 13, 202,234, 160, 129, 218, 6, 197, 169, 93, 98, 210, 82, 216>>)
{:ok, "almost coil firm shield cement hobby fan cage wine idea track prison scale alone close favorite limb south ramp famous stomach hard enter author"}
iex> Mnemoniac.create_mnemonic_from_entropy(<<1>>)
{:error, :invalid_entropy}
create_mnemonic_from_entropy!(entropy)
Similar to create_mnemonic_from_entropy/1
, but fails the entropy has unsupported byte size
examples
Examples
iex> Mnemoniac.create_mnemonic_from_entropy!(<<6, 197, 169, 93, 98, 210, 82, 216, 148, 177, 1, 251, 142, 15, 154, 85, 140, 0, 13, 202,234, 160, 129, 218>>)
"almost coil firm shield cement hobby fan cage wine idea track prison scale alone close favorite limb still"
iex> Mnemoniac.create_mnemonic_from_entropy!(<<1>>)
** (ArgumentError) Entropy size is invalid
entropy_bit_sizes()
@spec entropy_bit_sizes() :: [non_neg_integer()]
Return supported entopy bit sizes
word_numbers()
@spec word_numbers() :: [non_neg_integer()]
Return supported numbers of words that can be used for mnemonic generation
word_numbers_to_entropy_bits()
@spec word_numbers_to_entropy_bits() :: %{ required(non_neg_integer()) => non_neg_integer() }
Return a map of word numbers to entropy bits.
words()
@spec words() :: [String.t()]
Return all 2048 words used for mnemonic generation