| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Cometa.Crypto.Bip39
Description
English BIP39 recovery phrases with validated word counts and checksums.
Mnemonics contain wallet secrets. They have no Show or equality instance.
Import and export create ordinary Haskell text/byte values whose lifetimes
are managed by the caller; this API does not guarantee their erasure. Never
log exported phrases or use deterministic examples for real wallets.
Pure evaluation may share secret values and extend their retention; it does
not promise the timing or number of conversions.
import qualified Cometa.Crypto.Bip39 as Bip39
import qualified Data.ByteString as ByteString
main :: IO ()
main =
case Bip39.fromEntropy (ByteString.replicate 16 0) of -- test only
Left err -> print err
Right mnemonic -> print (Bip39.wordCount mnemonic)
Documentation
A checksum-validated sequence of 12, 15, 18, 21 or 24 lowercase English BIP39 words. Constructors are hidden; secret export is explicit.
Construction
fromEntropy :: ByteString -> Either Error Mnemonic Source #
Convert supplied entropy into a phrase. Exactly 16, 20, 24, 28 or 32 bytes
are accepted; other sizes return InvalidBip39EntropyLength. This operation
does not generate randomness. The caller must supply securely generated
entropy for a real wallet. Native failures return NativeError; a violated
result invariant returns NativeContractViolation.
fromText :: Text -> Either Error Mnemonic Source #
Parse a phrase, splitting on Unicode whitespace and discarding leading and
trailing whitespace. Words are case sensitive: only lowercase ASCII English
BIP39 words are accepted, without spelling correction or normalization.
Returns InvalidBip39WordCount, InvalidBip39Word (one-based position),
UnknownBip39Word, or InvalidBip39Checksum. Error values never include the
supplied words. Unexpected native failures return NativeError; a violated
result invariant returns NativeContractViolation.
fromWords :: [Text] -> Either Error Mnemonic Source #
Validate individual words and their checksum. Each list element must be
one lowercase ASCII word; embedded whitespace, NUL, upper case and non-ASCII
characters return InvalidBip39Word. Failures match fromText.
Inspection
Explicit secret export
exportText :: Mnemonic -> Text Source #
Export the secret phrase as lowercase words separated by single ASCII spaces. The returned text is ordinary caller-managed secret material.
exportEntropy :: Mnemonic -> Either Error ByteString Source #
Export the secret entropy bytes (16, 20, 24, 28 or 32 bytes). This is the
entropy accepted by Cometa.Crypto.Bip32.PrivateKey.withEntropy,
not the 64-byte seed produced by BIP39's separate passphrase KDF.
The returned bytes are ordinary caller-managed secret material. Native
failures return NativeError; a violated result invariant returns
NativeContractViolation.