Skip to content

Commit

Permalink
Add Error instance to MnemonicToSigningStakeKeyError
Browse files Browse the repository at this point in the history
  • Loading branch information
palas committed Nov 12, 2024
1 parent d7f6ec9 commit e87b879
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions cardano-api/internal/Cardano/Api/Keys/Mnemonics.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ module Cardano.Api.Keys.Mnemonics
)
where

import Cardano.Api.Error (Error (..))
import Cardano.Api.Keys.Class (Key (..))
import Cardano.Api.Keys.Shelley (AsType, PaymentExtendedKey,
SigningKey (PaymentExtendedSigningKey, StakeExtendedSigningKey),
StakeExtendedKey)
import Cardano.Api.SerialiseRaw (SerialiseAsRawBytesError)

import Cardano.Address.Derivation (Depth (..), DerivationType (..), HardDerivation (..),
Index, XPrv, genMasterKeyFromMnemonic, indexFromWord32)
Expand All @@ -30,6 +30,7 @@ import Data.ByteString (ByteString)
import Data.Either.Combinators (mapLeft, maybeToRight)
import Data.Text (Text)
import Data.Word (Word32)
import Prettyprinter (Doc, Pretty (..))

-- | The size of a mnemonic sentence.
-- The size is given in the number of words in the sentence.
Expand Down Expand Up @@ -64,9 +65,15 @@ data MnemonicToSigningStakeKeyError
| InvalidSecondFactorMnemonicError String
| InvalidAccountNumberError Word32
| InvalidPaymentKeyNoError Word32
| InternalErrorConvertingToByteString SerialiseAsRawBytesError
deriving (Eq, Show)

instance Error MnemonicToSigningStakeKeyError where
prettyError :: MnemonicToSigningStakeKeyError -> Doc ann
prettyError (InvalidMnemonicError str) = "Invalid mnemonic sentence: " <> pretty str
prettyError (InvalidSecondFactorMnemonicError str) = "Invalid second factor mnemonic sentence: " <> pretty str
prettyError (InvalidAccountNumberError accNo) = "Invalid account number: " <> pretty accNo
prettyError (InvalidPaymentKeyNoError keyNo) = "Invalid payment key number: " <> pretty keyNo

-- | The second factor for the key derivation.
data SecondFactor
= -- | Use a mnemonic sentence as the second factor.
Expand Down

0 comments on commit e87b879

Please sign in to comment.