Janiczek/elm-secret-sharing/1.0.0

NOTE: the latest version is 2.0.1

Secret

An implementation of Shamir's Secret Sharing: your secret is encrypted into N keys, of which only K are needed to reconstruct the original secret.

Port of simbo1905/shamir.

Advanced usage:

It's possible to have a tiered sharing: let's say you want to have admin keys and user keys; allowing either two admin keys or one admin key and three users to recover the secret.

For more info check this link.

Encrypt

{ seed : Seed
, parts : Int
, minPartsNeeded : Int
}
-> Bytes
-> Result EncryptError (List Key)

Allows splitting the Bytes secret to a given number of keys.

{ seed : Seed
, parts : Int
, minPartsNeeded : Int
}
-> String
-> Result EncryptError (List Key)

Allows splitting the String secret to a given number of keys.

Compared to encryptBytes, adds one extra 32bit integer at the beginning, saying how many UTF-8 bytes the string has. This is required for correct reconstruction later with decryptString.

= TooFewPartsNeeded
| TooManyParts
| MorePartsNeededThanAvailable
| NoSecret

These validation rules are in effect:

  • 2-255 parts must be generated
  • 2+ parts must be needed
  • there cannot be more parts needed than available
  • secret must be non-empty Bytes (Strings can be empty)

Decrypt

decryptBytes : List Key -> Result DecryptError Bytes

Allows deconstructing the Bytes secret from the given keys.

decryptString : List Key -> Result DecryptError String

Allows deconstructing the String secret from the given keys.

Compared to decryptBytes, requires one extra 32bit integer at the beginning, saying how many UTF-8 bytes the string has. This is given automatically during encryption with encryptString.

= NoKeysProvided
| KeysNotSameLength
| NotAnUtf8String

The library will fail decrypting if:

  • the keys list is empty
  • keys are not of the same length
  • the secret wasn't an UTF-8 string and you attempted to decryptString