HORIZON HASKELLDocslts/ghc-9.14.xd82dee82026-10-12Search names, modules, packages, or :: a typeCtrl K

GHC 9.14.1 · lts/ghc-9.14.x · d82dee8 · 2026-10-12

Modulecardano-addresses-4.0.2Haskell2010

Cardano.Mnemonic

  • 14 types
  • 2 classes
  • 12 values

Introduction

0 declarations

We call Entropy an arbitrary sequence of bytes that has been generated through high quality randomness methods. The allowed size of an Entropy is 96-256 bits and is necessarily a multiple of 32 bits (4 bytes).

Mnemonic is an Entropy with an appended checksum calculated by taking the first ent / 32 bits of the SHA256 hash of it, where ent designates the Entropy size in bits.

The concatenated result is split into groups of 11 bits, each encoding a number from 0 to 2047 serving as an index into a known dictionary:

https://github.com/cardano-foundation/cardano-wallet/tree/master/specifications/mnemonic/english.txt

This makes for a human-readable sentence of English words.

Entropy Size

Checksum Size

Sentence Length

Example

96 bits (12 bytes)

3 bits

9 words

test child burst immense armed parrot company walk dog

128 bits (16 bytes)

4 bits

12 words

test walk nut penalty hip pave soap entry language right filter choice

160 bits (20 bytes)

5 bits

15 words

art forum devote street sure rather head chuckle guard poverty release quote oak craft enemy

192 bits (24 bytes)

6 bits

18 words

churn shaft spoon second erode useless thrive burst group seed element sign scrub buffalo jelly grace neck useless

224 bits (28 bytes)

7 bits

21 words

draft ability female child jump maid roof hurt below live topple paper exclude ordinary coach churn sunset emerge blame ketchup much

256 bits (32 bytes)

8 bits

24 words

excess behave track soul table wear ocean cash stay nature item turtle palm soccer lunch horror start stumble month panic right must lock dress

SomeMnemonic

5 declarations
datadata SomeMnemonic where
#

Ease the manipulation of Mnemonic by encapsulating the type constraints inside a constructor. This is particularly useful for functions which do not require anything but a valid Mnemonic without any particular pre-condition on the size of the Mnemonic itself.

Constructors

Instances3Eq, Show, NFData
classclass MkSomeMnemonic (sz :: [Nat]) where
#

This class enables caller to parse text list of variable length into mnemonic sentences.

Note that the given Nats have to be valid mnemonic sizes, otherwise the underlying code won't even compile, with not-so-friendly error messages.

Methods

  • mkSomeMnemonic :: [Text] -> Either (MkSomeMnemonicError sz) SomeMnemonic

    Construct a mnemonic from a list of words. This function is particularly useful when the number of words is not necessarily known at runtime. The function is however ambiguous and requires thereby a type application.

    Examples:

    Example1 expression
    mkSomeMnemonic @'[ 12 ] [ "test", "child", "burst", "immense", "armed", "parrot", "company", "walk", "dog" ]Left "Invalid number of words: 12 words are expected."
    Example1 expression
    mkSomeMnemonic @'[ 9, 12, 15 ] [ "test", "child", "burst", "immense", "armed", "parrot", "company", "walk", "dog" ]Right (SomeMnemonic ...)
Instances2MkSomeMnemonic
classclass NatVals (ns :: [Nat]) where
#

Small helper to collect Nat values from a type-level list

Methods

Instances2NatVals
  • NatVals '[]Defined in cardano-addresses-4.0.2 · Cardano.Mnemonic
  • (KnownNat n, NatVals rest) => NatVals (n ': rest)Defined in cardano-addresses-4.0.2 · Cardano.Mnemonic

Mnemonic

7 declarations
datadata Mnemonic (mw :: Nat)
#

A opaque Mnemonic type.

Instances3Eq, Show, NFData
  • Eq (Mnemonic mw)Defined in cardano-addresses-4.0.2 · Cardano.Mnemonic
  • Show (Mnemonic mw)Defined in cardano-addresses-4.0.2 · Cardano.Mnemonic
  • NFData (Mnemonic mw)Defined in cardano-addresses-4.0.2 · Cardano.Mnemonic

    NFData instances

datadata MkMnemonicError (csz :: Nat)
#

This wraps errors from Cardano.Encoding.BIP39

Constructors

Instances3Eq, Show, NFData

Entropy

5 declarations
datadata Entropy (n :: Nat)
#

BIP39's entropy is a byte array of a given size (in bits, see ValidEntropySize for the valid size).

To it is associated

Instances9Eq, Show, NormalForm, Arbitrary, …
  • Eq (Entropy n)Defined in cardano-crypto-1.3.0 · Crypto.Encoding.BIP39
  • Show (Entropy n)Defined in cardano-crypto-1.3.0 · Crypto.Encoding.BIP39
  • NormalForm (Entropy n)Defined in cardano-crypto-1.3.0 · Crypto.Encoding.BIP39
  • Arbitrary (Entropy 128)Defined in cardano-crypto-1.3.0 · Crypto.Encoding.BIP39
  • Arbitrary (Entropy 160)Defined in cardano-crypto-1.3.0 · Crypto.Encoding.BIP39
  • Arbitrary (Entropy 192)Defined in cardano-crypto-1.3.0 · Crypto.Encoding.BIP39
  • Arbitrary (Entropy 224)Defined in cardano-crypto-1.3.0 · Crypto.Encoding.BIP39
  • Arbitrary (Entropy 256)Defined in cardano-crypto-1.3.0 · Crypto.Encoding.BIP39
  • Arbitrary (Entropy 96)Defined in cardano-crypto-1.3.0 · Crypto.Encoding.BIP39

Dictionary

3 declarations
datadata Dictionary
#

this discribe the property of the Dictionary and will alllow to convert from a mnemonic phrase to MnemonicSentence

This is especially needed to build the BIP39 Seed

Internals & Re-export from Crypto.Encoding.BIP39

11 declarations
typetype ConsistentEntropy (ent :: Nat) (mw :: Nat) (csz :: Nat) = (ValidEntropySize ent, ValidChecksumSize ent csz, ValidMnemonicSentence mw, MnemonicWords ent ~ mw)
#

Type Constraint Alias to check the entropy size, the number of mnemonic words and the checksum size is consistent. i.e. that the following is true:

| entropysize | checksumsize | entropysize + checksumsize | mnemonicsize | +---------------+--------------+----------------------------+--------------+ | 96 | 3 | 99 | 9 | | 128 | 4 | 132 | 12 | | 160 | 5 | 165 | 15 | | 192 | 6 | 198 | 18 | | 224 | 7 | 231 | 21 | | 256 | 8 | 264 | 24 |

This type constraint alias also perform all the GHC's cumbersome type level literal handling.

Troubleshooting

0 declarations
  • Natural XX is out of bounds for Int: This usually occurs when ones is trying to specify an invalid size for an Entropy or Mnemonic. For example:

Example1 expression
genEntropy @42error:  • Natural CheckSumBits 42 is out of bounds for Int
  • This could be the case as well when forgetting to use an adequate type application:

Example1 expression
mkEntropy memptyerror:  • Natural ent is out of bounds for Int

Orphan instances

6 instances