Bip39 Functions

int bip39_get_languages(char **output)

Get the list of default supported languages.

Note

The string returned should be freed using wally_free_string.

Returns:

See Error Codes

int bip39_get_wordlist(const char *lang, struct words **output)

Get the default word list for a language.

Parameters:
  • lang – Language to use. Pass NULL to use the default English list.

  • output – Destination for the resulting word list.

Note

The returned structure should not be freed or modified.

Returns:

See Error Codes

int bip39_get_word(const struct words *w, size_t index, char **output)

Get the ‘index’th word from a word list.

Parameters:
  • w – Word list to use. Pass NULL to use the default English list.

  • index – The 0-based index of the word in w.

  • output – Destination for the resulting word.

The string returned should be freed using wally_free_string.

Returns:

See Error Codes

const char *bip39_get_word_by_index(const struct words *w, size_t index)

Get the ‘index’th word from a word list.

Parameters:
  • w – Word list to use. Pass NULL to use the default English list.

  • index – The 0-based index of the word in w.

Note

Returns NULL if any argument is invalid or index is out of

bounds. Unlike bip39_get_word, the resulting word must not be written to or freed.

int bip39_mnemonic_from_bytes(const struct words *w, const unsigned char *bytes, size_t bytes_len, char **output)

Generate a mnemonic sentence from the entropy in bytes.

Parameters:
  • w – Word list to use. Pass NULL to use the default English list.

  • bytes – Entropy to convert.

  • bytes_len – The length of bytes in bytes.

  • output – Destination for the resulting mnemonic sentence.

Note

The string returned should be freed using wally_free_string.

Returns:

See Error Codes

int bip39_mnemonic_to_bytes(const struct words *w, const char *mnemonic, unsigned char *bytes_out, size_t len, size_t *written)

Convert a mnemonic sentence into entropy at bytes_out.

Parameters:
  • w – Word list to use. Pass NULL to use the default English list.

  • mnemonic – Mnemonic to convert.

  • bytes_out – Where to store the resulting entropy.

  • len – Size of bytes_out. Passing BIP39_ENTROPY_MAX_LEN will ensure the buffer is large enough.

  • written – Destination for the number of bytes written to bytes_out.

Returns:

See Variable Length Output Buffers

int bip39_mnemonic_validate(const struct words *w, const char *mnemonic)

Validate the checksum embedded in a mnemonic sentence.

Parameters:
  • w – Word list to use. Pass NULL to use the default English list.

  • mnemonic – Mnemonic to validate.

Returns:

See Error Codes

int bip39_mnemonic_to_seed(const char *mnemonic, const char *passphrase, unsigned char *bytes_out, size_t len, size_t *written)

Convert a mnemonic into a binary seed.

Parameters:
  • mnemonic – Mnemonic to convert.

  • passphrase – Mnemonic passphrase or NULL if no passphrase is needed.

  • bytes_out – The destination for the binary seed.

  • len – Size of bytes_out. Must be BIP39_SEED_LEN_512.

  • written – Destination for the number of bytes written to bytes_out.

Returns:

See Variable Length Output Buffers

int bip39_mnemonic_to_seed512(const char *mnemonic, const char *passphrase, unsigned char *bytes_out, size_t len)

Convert a mnemonic into a binary seed of 512 bits.

Parameters:
  • mnemonic – Mnemonic to convert.

  • passphrase – Mnemonic passphrase or NULL if no passphrase is needed.

  • bytes_out – The destination for the binary seed.

  • len – Size of bytes_out. Must be BIP39_SEED_LEN_512.

Note

Identical to bip39_mnemonic_to_seed but returns a fixed size buffer.

Returns:

See Error Codes

Bip39 Constants

BIP39_ENTROPY_LEN_128

Valid entropy lengths

BIP39_ENTROPY_LEN_160
BIP39_ENTROPY_LEN_192
BIP39_ENTROPY_LEN_224
BIP39_ENTROPY_LEN_256
BIP39_ENTROPY_LEN_288
BIP39_ENTROPY_LEN_320
BIP39_SEED_LEN_512

The required size of the output buffer for bip39_mnemonic_to_seed

BIP39_ENTROPY_MAX_LEN

Maximum entropy size (including up to 2 bytes for checksum)

BIP39_WORDLIST_LEN

The number of words in a BIP39 compliant wordlist