Skip to content

Commit

Permalink
Add support for DRep, CCCold, and CCHot
Browse files Browse the repository at this point in the history
  • Loading branch information
palas committed Nov 14, 2024
1 parent 477b125 commit 629122c
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions cardano-api/internal/Cardano/Api/Keys/Mnemonics.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ where
import Cardano.Api.Error (Error (..))
import Cardano.Api.Keys.Class (Key (..))
import Cardano.Api.Keys.Shelley (AsType, PaymentExtendedKey,
SigningKey (PaymentExtendedSigningKey, StakeExtendedSigningKey),
StakeExtendedKey)
SigningKey (..),
StakeExtendedKey, DRepExtendedKey, SigningKey(DRepExtendedSigningKey), CommitteeHotExtendedKey, CommitteeColdExtendedKey)

import Cardano.Address.Derivation (Depth (..), DerivationType (..), HardDerivation (..),
Index, XPrv, genMasterKeyFromMnemonic, indexFromWord32)
import Cardano.Address.Style.Shelley (Role (..), Shelley (..))
import Cardano.Address.Style.Shelley (Role (..), Shelley (..), deriveDRepPrivateKey, deriveCCHotPrivateKey, deriveCCColdPrivateKey)
import Cardano.Mnemonic (MkSomeMnemonic (mkSomeMnemonic), MkSomeMnemonicError (..),
SomeMnemonic, entropyToMnemonic, genEntropy, mnemonicToText)

Expand Down Expand Up @@ -101,6 +101,33 @@ instance ExtendedSigningKeyRole StakeExtendedKey Word32 where
payKeyIx <- maybeToEither idx $ indexFromWord32 @(Index 'Soft 'PaymentK) idx
return $ StakeExtendedSigningKey $ getKey $ deriveAddressPrivateKey accK Stake payKeyIx

instance ExtendedSigningKeyRole DRepExtendedKey () where
deriveSigningKeyFromAccount
:: AsType DRepExtendedKey
-> Shelley 'AccountK XPrv
-> ()
-> Either Word32 (SigningKey DRepExtendedKey)
deriveSigningKeyFromAccount _ accK _ =
return $ DRepExtendedSigningKey $ getKey $ deriveDRepPrivateKey accK

instance ExtendedSigningKeyRole CommitteeColdExtendedKey () where
deriveSigningKeyFromAccount
:: AsType CommitteeColdExtendedKey
-> Shelley 'AccountK XPrv
-> ()
-> Either Word32 (SigningKey CommitteeColdExtendedKey)
deriveSigningKeyFromAccount _ accK _ =
return $ CommitteeColdExtendedSigningKey $ getKey $ deriveCCColdPrivateKey accK

instance ExtendedSigningKeyRole CommitteeHotExtendedKey () where
deriveSigningKeyFromAccount
:: AsType CommitteeHotExtendedKey
-> Shelley 'AccountK XPrv
-> ()
-> Either Word32 (SigningKey CommitteeHotExtendedKey)
deriveSigningKeyFromAccount _ accK _ =
return $ CommitteeHotExtendedSigningKey $ getKey $ deriveCCHotPrivateKey accK

-- | Generate a signing key from a mnemonic sentence.
-- A derivation path is like a file path in a file system. It specifies the
-- location of a key in the key tree. The path is a list of indices, one for each
Expand Down

0 comments on commit 629122c

Please sign in to comment.