cardano-wallet-core-2022.7.1: The Wallet Backend for a Cardano node.
Copyright © 2018-2021 IOHK
License Apache-2.0
Safe Haskell None
Language Haskell2010

Cardano.Wallet.Primitive.Passphrase

Description

Hashing of wallet passwords.

Synopsis

Passphrases from the user

newtype Passphrase (purpose :: Symbol ) Source #

An encapsulated passphrase. The inner format is free, but the wrapper helps readability in function signatures.

Some type parameters in use are:

  • "user" - a passphrase entered by the user through the API. The FromText instance enforces password length rules.
  • "lenient" - like "user" , except without a minimum length restriction in FromText .`
  • "encryption" - the user's passphrase, transformed so that it can be used as the key for encrypting wallet keys.
  • "salt" - the random salt part of a hashed passphrase.

Instances

Instances details
Eq ( Passphrase purpose) Source #
Instance details

Defined in Cardano.Wallet.Primitive.Passphrase.Types

Show ( Passphrase purpose) Source #
Instance details

Defined in Cardano.Wallet.Primitive.Passphrase.Types

Semigroup ( Passphrase purpose) Source #
Instance details

Defined in Cardano.Wallet.Primitive.Passphrase.Types

Monoid ( Passphrase purpose) Source #
Instance details

Defined in Cardano.Wallet.Primitive.Passphrase.Types

NFData ( Passphrase purpose) Source #
Instance details

Defined in Cardano.Wallet.Primitive.Passphrase.Types

Methods

rnf :: Passphrase purpose -> () Source #

ToJSON ( ApiT ( Passphrase purpose)) Source #
Instance details

Defined in Cardano.Wallet.Api.Types

( PassphraseMaxLength purpose, PassphraseMinLength purpose) => FromJSON ( ApiT ( Passphrase purpose)) Source #
Instance details

Defined in Cardano.Wallet.Api.Types

ByteArrayAccess ( Passphrase purpose) Source #
Instance details

Defined in Cardano.Wallet.Primitive.Passphrase.Types

ToText ( Passphrase purpose) Source #
Instance details

Defined in Cardano.Wallet.Primitive.Passphrase.Types

( PassphraseMaxLength purpose, PassphraseMinLength purpose) => FromText ( Passphrase purpose) Source #
Instance details

Defined in Cardano.Wallet.Primitive.Passphrase.Types

MonadRandom ((->) ( Passphrase "salt") :: Type -> Type ) Source #

Little trick to be able to provide our own "random" salt in order to deterministically re-compute a passphrase hash from a known salt. Note that, this boils down to giving an extra argument to the encryptPassphrase function which is the salt, in order to make it behave deterministically.

encryptPassphrase
  :: MonadRandom m
  => Passphrase purpose
  -> m (Hash purpose)

 ~

encryptPassphrase
  :: Passphrase purpose
  -> Passphrase "salt"
  -> m (Hash purpose)
>>> encryptPassphrase pwd (Passphrase @"salt" salt)
Hash "..."
Instance details

Defined in Cardano.Wallet.Primitive.Passphrase.Types

Methods

getRandomBytes :: ByteArray byteArray => Int -> Passphrase "salt" -> byteArray Source #

class PassphraseMinLength (purpose :: Symbol ) where Source #

Methods

passphraseMinLength :: Proxy purpose -> Int Source #

Minimal Length for a passphrase, for lack of better validations

Wallet passphrases stored as hashes

newtype PassphraseHash Source #

Instances

Instances details
Eq PassphraseHash Source #
Instance details

Defined in Cardano.Wallet.Primitive.Passphrase.Types

Ord PassphraseHash Source #
Instance details

Defined in Cardano.Wallet.Primitive.Passphrase.Types

Show PassphraseHash Source #
Instance details

Defined in Cardano.Wallet.Primitive.Passphrase.Types

Semigroup PassphraseHash Source #
Instance details

Defined in Cardano.Wallet.Primitive.Passphrase.Types

Monoid PassphraseHash Source #
Instance details

Defined in Cardano.Wallet.Primitive.Passphrase.Types

NFData PassphraseHash Source #
Instance details

Defined in Cardano.Wallet.Primitive.Passphrase.Types

ByteArray PassphraseHash Source #
Instance details

Defined in Cardano.Wallet.Primitive.Passphrase.Types

ByteArrayAccess PassphraseHash Source #
Instance details

Defined in Cardano.Wallet.Primitive.Passphrase.Types

ToText PassphraseHash Source #
Instance details

Defined in Cardano.Wallet.Primitive.Passphrase.Types

ToJSON ( ApiT PassphraseHash ) Source #
Instance details

Defined in Cardano.Wallet.Api.Types

FromJSON ( ApiT PassphraseHash ) Source #
Instance details

Defined in Cardano.Wallet.Api.Types

FromText ( ApiT PassphraseHash ) Source #
Instance details

Defined in Cardano.Wallet.Api.Types

data PassphraseScheme Source #

A type to capture which encryption scheme should be used

Constructors

EncryptWithScrypt

Legacy encryption scheme for passphrases

EncryptWithPBKDF2

Encryption scheme used since cardano-wallet

Instances

Instances details
Eq PassphraseScheme Source #
Instance details

Defined in Cardano.Wallet.Primitive.Passphrase.Types

Ord PassphraseScheme Source #
Instance details

Defined in Cardano.Wallet.Primitive.Passphrase.Types

Read PassphraseScheme Source #
Instance details

Defined in Cardano.Wallet.Primitive.Passphrase.Types

Show PassphraseScheme Source #
Instance details

Defined in Cardano.Wallet.Primitive.Passphrase.Types

Generic PassphraseScheme Source #
Instance details

Defined in Cardano.Wallet.Primitive.Passphrase.Types

NFData PassphraseScheme Source #
Instance details

Defined in Cardano.Wallet.Primitive.Passphrase.Types

PersistFieldSql PassphraseScheme Source #
Instance details

Defined in Cardano.Wallet.DB.Sqlite.Types

PersistField PassphraseScheme Source #
Instance details

Defined in Cardano.Wallet.DB.Sqlite.Types

ToText PassphraseScheme Source #
Instance details

Defined in Cardano.Wallet.Primitive.Passphrase.Types

SymbolToField "walPassphraseScheme" Wallet ( Maybe PassphraseScheme ) Source #
Instance details

Defined in Cardano.Wallet.DB.Sqlite.Schema

type Rep PassphraseScheme Source #
Instance details

Defined in Cardano.Wallet.Primitive.Passphrase.Types

type Rep PassphraseScheme = D1 (' MetaData "PassphraseScheme" "Cardano.Wallet.Primitive.Passphrase.Types" "cardano-wallet-core-2022.7.1-AGKhlyz9liLKN3QqZD1gj" ' False ) ( C1 (' MetaCons "EncryptWithScrypt" ' PrefixI ' False ) ( U1 :: Type -> Type ) :+: C1 (' MetaCons "EncryptWithPBKDF2" ' PrefixI ' False ) ( U1 :: Type -> Type ))

data WalletPassphraseInfo Source #

Instances

Instances details
Eq WalletPassphraseInfo Source #
Instance details

Defined in Cardano.Wallet.Primitive.Passphrase.Types

Ord WalletPassphraseInfo Source #
Instance details

Defined in Cardano.Wallet.Primitive.Passphrase.Types

Show WalletPassphraseInfo Source #
Instance details

Defined in Cardano.Wallet.Primitive.Passphrase.Types

Generic WalletPassphraseInfo Source #
Instance details

Defined in Cardano.Wallet.Primitive.Passphrase.Types

NFData WalletPassphraseInfo Source #
Instance details

Defined in Cardano.Wallet.Primitive.Passphrase.Types

type Rep WalletPassphraseInfo Source #
Instance details

Defined in Cardano.Wallet.Primitive.Passphrase.Types

type Rep WalletPassphraseInfo = D1 (' MetaData "WalletPassphraseInfo" "Cardano.Wallet.Primitive.Passphrase.Types" "cardano-wallet-core-2022.7.1-AGKhlyz9liLKN3QqZD1gj" ' False ) ( C1 (' MetaCons "WalletPassphraseInfo" ' PrefixI ' True ) ( S1 (' MetaSel (' Just "lastUpdatedAt") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 UTCTime ) :*: S1 (' MetaSel (' Just "passphraseScheme") ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 PassphraseScheme )))

Operations

encryptPassphrase :: MonadRandom m => Passphrase "user" -> m ( PassphraseScheme , PassphraseHash ) Source #

Hashes a Passphrase into a format that is suitable for storing on disk. It will always use the current scheme: pbkdf2-hmac-sha512.

preparePassphrase :: PassphraseScheme -> Passphrase "user" -> Passphrase "encryption" Source #

Manipulation done on legacy passphrases before used for encryption.

changePassphraseXPrv Source #

Arguments

:: ( PassphraseScheme , Passphrase "user")

Old passphrase

-> ( PassphraseScheme , Passphrase "user")

New passphrase

-> XPrv

Key to re-encrypt

-> XPrv

Re-encrypts a wallet private key with a new passphrase.

  • *Important**: This function doesn't check that the old passphrase is correct! Caller is expected to have already checked that. Using an incorrect passphrase here will lead to very bad thing.

checkAndChangePassphraseXPrv Source #

Arguments

:: MonadRandom m
=> (( PassphraseScheme , PassphraseHash ), Passphrase "user")

Old passphrase

-> Passphrase "user"

New passphrase

-> XPrv

Key to re-encrypt

-> m ( Either ErrWrongPassphrase (( PassphraseScheme , PassphraseHash ), XPrv ))

Re-encrypts a wallet private key with a new passphrase.

data ErrWrongPassphrase Source #

Indicate a failure when checking for a given Passphrase match

Instances

Instances details
Eq ErrWrongPassphrase Source #
Instance details

Defined in Cardano.Wallet.Primitive.Passphrase.Types

Show ErrWrongPassphrase Source #
Instance details

Defined in Cardano.Wallet.Primitive.Passphrase.Types

Generic ErrWrongPassphrase Source #
Instance details

Defined in Cardano.Wallet.Primitive.Passphrase.Types

NFData ErrWrongPassphrase Source #
Instance details

Defined in Cardano.Wallet.Primitive.Passphrase.Types

type Rep ErrWrongPassphrase Source #
Instance details

Defined in Cardano.Wallet.Primitive.Passphrase.Types

type Rep ErrWrongPassphrase = D1 (' MetaData "ErrWrongPassphrase" "Cardano.Wallet.Primitive.Passphrase.Types" "cardano-wallet-core-2022.7.1-AGKhlyz9liLKN3QqZD1gj" ' False ) ( C1 (' MetaCons "ErrWrongPassphrase" ' PrefixI ' False ) ( U1 :: Type -> Type ) :+: C1 (' MetaCons "ErrPassphraseSchemeUnsupported" ' PrefixI ' False ) ( S1 (' MetaSel (' Nothing :: Maybe Symbol ) ' NoSourceUnpackedness ' NoSourceStrictness ' DecidedLazy ) ( Rec0 PassphraseScheme )))