BSV-ex v0.2.2 BSV.Mnemonic View Source

Module for generating and restoring mnemonic phrases, for the generation of deterministic keys. Implements BIP-39.

A mnemonic phrase is a group of easy to remember words. The phrase can be converted to a binary seed, which in turn is used to generate deterministic keys.

Link to this section Summary

Types

t()

Mnemonic phrase

Functions

Returns a list of the allowed mnemonic entropy lengths.

Returns a mnemonic phrase derived from the given binary.

Generates a new mnemonic phrase from the given entropy length (defaults to 256 bits / 24 words).

Returns a binary derived from the given mnemonic phrase.

Returns a wallet seed derived from the given mnemonic phrase and optionally a passphrase.

Returns the mnemonic word list.

Link to this section Types

Mnemonic phrase

Link to this section Functions

Link to this function

allowed_lengths()

View Source
allowed_lengths() :: list()

Returns a list of the allowed mnemonic entropy lengths.

Link to this function

from_entropy(entropy)

View Source
from_entropy(binary()) :: BSV.Mnemonic.t()

Returns a mnemonic phrase derived from the given binary.

Examples

iex> BSV.Test.mnemonic_entropy
...> |> BSV.Mnemonic.from_entropy
"organ boring cushion feature wheat juice quality replace concert baby topic scrub"
Link to this function

generate(entropy_length \\ List.last([128, 160, 192, 224, 256]))

View Source
generate(integer()) :: BSV.Mnemonic.t()

Generates a new mnemonic phrase from the given entropy length (defaults to 256 bits / 24 words).

Examples

iex> BSV.Mnemonic.generate
...> |> String.split
...> |> length
24

iex> BSV.Mnemonic.generate(128)
...> |> String.split
...> |> length
12
Link to this function

to_entropy(mnemonic)

View Source
to_entropy(BSV.Mnemonic.t()) :: binary()

Returns a binary derived from the given mnemonic phrase.

Examples

iex> "organ boring cushion feature wheat juice quality replace concert baby topic scrub"
...> |> BSV.Mnemonic.to_entropy
<<156, 99, 60, 217, 170, 31, 158, 241, 171, 205, 182, 46, 162, 35, 148, 96>>
Link to this function

to_seed(mnemonic, options \\ [])

View Source
to_seed(BSV.Mnemonic.t(), keyword()) :: binary()

Returns a wallet seed derived from the given mnemonic phrase and optionally a passphrase.

Options

The accepted options are:

  • `:passphrase` - Optionally protect the seed with an additional passphrase
  • `:encoding` - Optionally encode the seed with either the `:base64` or `:hex` encoding scheme.

Examples

iex> BSV.Mnemonic.from_entropy(BSV.Test.mnemonic_entropy)
...> |> BSV.Mnemonic.to_seed(encoding: :hex)
"380823f725beb7846806d0b88590a0823ea81c0b88cd151f7295772bbe48bbffa9b0f131dce77c4a7168925d466270c12bc0073db917da9f2bb1f4ac59e9fa3b"

iex> BSV.Mnemonic.from_entropy(BSV.Test.mnemonic_entropy)
...> |> BSV.Mnemonic.to_seed(passphrase: "my wallet")
...> |> byte_size
64

Returns the mnemonic word list.