View Source Slip39 (slip39 v0.1.0)

Elixir implementation of the SLIP-0039 : Shamir's Secret-Sharing for Mnemonic Codes.

This implementation is largely inspired by the reference implementation.

This work is very in progress. Any contribution is welcome.

DISCLAIMER

This module is supplied as is. Since it has not been audited and can contains bugs, it should not be used to manipulate valuable secrets. If you decide to ignore this warning, use basic OPSEC common sense and, at the very least, use a computer booted on a USB key, then taken offline during calls to the functions of this module. In addition, each mnemonic generated must never be stored in an electronic format and must be carefully re-read. In any case, its/their authors cannot be held responsible for any loss of data or its financial consequences resulting from the direct or indirect use of this module.

Summary

Functions

Combine mnemonic shares to obtain the master secret which was previously split using Shamir's secret sharing scheme.

Split a master secret into mnemonic shares using Shamir's secret sharing scheme using a single threshold/count group and no passphrase encryption.

Split a master secret into mnemonic shares using Shamir's secret sharing scheme.

Functions

Link to this function

combine_mnemonics(mnemonics, passphrase \\ "")

View Source
@spec combine_mnemonics([String.t()], String.t()) :: binary()

Combine mnemonic shares to obtain the master secret which was previously split using Shamir's secret sharing scheme.

This is the user-friendly method to recover a backed-up secret optionally protected by a passphrase.

Examples

  iex(1)> ["pajamas lungs academic acid thank snapshot scramble should mason vintage lilac infant rocky dismiss blue spider recover step alcohol that early pregnant guilt","pajamas lungs academic agency firefly order hearing describe forbid welfare emphasis true ting pregnant solution genre source graduate idea alcohol squeeze luxury elegant","pajamas lungs academic always minister evening lunch prospect duke license realize evening armed laser oven warmth helpful slap trial home sunlight trend standard"]
  iex(2)> |> Slip39.combine_mnemonics
  "Long life to Elixir!"
Link to this function

generate_mnemonics!(threshold, share_count, master_secret)

View Source

Split a master secret into mnemonic shares using Shamir's secret sharing scheme using a single threshold/count group and no passphrase encryption.

Examples

Since random data is inserted into mnemonics when they are generated you won't have the same output when running this example.

iex(1)>  Slip39.generate_mnemonics!(3,5,"Long life to Elixir!")
[
  ["formal discuss academic acne rebound violence class ultimate float envelope smear costume fumes medical license practice eclipse language auction check coding lamp lecture",
  "formal discuss academic agree debut bucket both salt cage home improve purchase burden amuse paces distance acid destroy plan piece alive upstairs being",
  "formal discuss academic amazing database devote software peasant either profile junction object disaster velvet aspect regret adapt axle excuse advocate flip eyebrow friar",
  "formal discuss academic arcade pitch subject thunder math airport maiden season acquire ladle infant being criminal edge forward trouble loan jacket system smirk",
  "formal discuss academic axle overall phrase treat thank branch transfer wireless faint award skin jerky paid twice fake exact echo saver steady ruler"]
]
Link to this function

generate_mnemonics!(group_threshold, groups, master_secret, passphrase, iteration_exponent)

View Source

Split a master secret into mnemonic shares using Shamir's secret sharing scheme.

The supplied Master Secret is encrypted by the passphrase (empty passphrase is used if none is provided) and split into a set of mnemonic shares.

This function allows a two level group definition (see example).

Examples

Alice want to backup her secret. She will keep two share for herself, in separate vault, but in case she lost one of them, she want to be able to recover her secret, by recovering any three share she had given to five of her best friends.

Note that since random data is inserted into mnemonics when they are generated you won't have the same output when running this example.

iex(1)> groups = Slip39.generate_mnemonics!(2, [{1,1}, {1,1}, {3,5}], "Long life to Elixir!", "")
[
  ["window provide acrobat leader include tidy estate promise holiday earth trip solution cubic math teammate auction bracelet fishing walnut faint minister material endless"],
  ["window provide beard leader fumes scholar primary elder flavor theory papa insect holiday survive beam cards laundry flexible lunch presence rebuild emerald exhaust"],
  ["window provide ceramic learn charity industry aviation sack package priority umbrella forbid triumph webcam starting firefly problem vocal improve task sympathy spray herd",
  "window provide ceramic lips lecture airport hobo legal declare describe says source quiet golden pitch society genius raisin ceiling admit luxury empty license",
  "window provide ceramic luxury diet diploma bumpy cowboy usher building drove leaves rapids trust squeeze salt mule presence pupal disease public rainbow afraid",
  "window provide ceramic march mule ending jerky hanger frozen lift beyond antenna unknown intend platform employer focus unknown taught tidy tidy clinic typical",
  "window provide ceramic method clay carve stadium laden tenant rhythm river much security isolate fumes axis calcium expect pulse petition miracle senior else"]
]

...(2)> to_be_store_in_alice_vault1 = groups |> Enum.at(0)
["window provide acrobat leader include tidy estate promise holiday earth trip solution cubic math teammate auction bracelet fishing walnut faint minister material endless"]

...(3)> to_be_store_in_alice_vault2 = groups |> Enum.at(1)
["window provide beard leader fumes scholar primary elder flavor theory papa insect holiday survive beam cards laundry flexible lunch presence rebuild emerald exhaust"]

...(4)> to_be_given_to_five_friends = groups |> Enum.at(2)
["window provide ceramic learn charity industry aviation sack package priority umbrella forbid triumph webcam starting firefly problem vocal improve task sympathy spray herd",
"window provide ceramic lips lecture airport hobo legal declare describe says source quiet golden pitch society genius raisin ceiling admit luxury empty license",
"window provide ceramic luxury diet diploma bumpy cowboy usher building drove leaves rapids trust squeeze salt mule presence pupal disease public rainbow afraid",
"window provide ceramic march mule ending jerky hanger frozen lift beyond antenna unknown intend platform employer focus unknown taught tidy tidy clinic typical",
"window provide ceramic method clay carve stadium laden tenant rhythm river much security isolate fumes axis calcium expect pulse petition miracle senior else"]