| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Cardano.Crypto.WalletHD.Encrypted
Description
Keys are stored as CBOR-encoded v2 envelopes: a random 32-byte salt and 24-byte nonce, Argon2id-derived 32-byte wrapping key, and the 64-byte extended secret key encrypted with XChaCha20-Poly1305. The public key and chain code are bound as AEAD additional data so they cannot be silently swapped without detection.
The plaintext secret key is held exclusively in sodium_malloc'd memory
(MLockedSizedBytes) which is locked against swapping and is never moved
by the GC. All public operations are in IO; callers must mlsbFinalize
any MLockedSizedBytes they receive when done with it.
Synopsis
- data EncryptedKey
- data XPrvFormat
- data XPrvError
- = XPrvDecodeError
- | XPrvUnsupportedVersion
- | XPrvUnsupportedKdf
- | XPrvUnsupportedCipher
- | XPrvInvalidKdfParams
- | XPrvInvalidSaltLength
- | XPrvInvalidNonceLength
- | XPrvInvalidTagLength
- | XPrvInvalidCiphertextLength
- | XPrvAuthenticationFailed
- | XPrvInvalidSecretKey
- | XPrvInvalidPublicKey
- | XPrvInvalidChainCode
- | XPrvPublicKeyMismatch
- | XPrvInternalError
- newtype Signature = Signature ByteString
- data DerivationScheme
- type DerivationIndex = Word32
- encryptedCreate ∷ (ByteArrayAccess passphrase, ByteArrayAccess secret, ByteArrayAccess cc) ⇒ secret → passphrase → cc → IO (Either XPrvError EncryptedKey)
- encryptedCreateDirectWithTweak ∷ (ByteArrayAccess passphrase, ByteArrayAccess secret) ⇒ secret → passphrase → IO (Either XPrvError EncryptedKey)
- encryptedKey ∷ ByteString → Either XPrvError EncryptedKey
- unEncryptedKey ∷ EncryptedKey → ByteString
- encryptedKeyFormat ∷ EncryptedKey → XPrvFormat
- encryptedValidatePassphrase ∷ ByteArrayAccess passphrase ⇒ EncryptedKey → passphrase → IO (Either XPrvError ())
- encryptedChangePass ∷ (ByteArrayAccess oldPassPhrase, ByteArrayAccess newPassPhrase) ⇒ oldPassPhrase → newPassPhrase → EncryptedKey → IO (Either XPrvError EncryptedKey)
- encryptedSign ∷ (ByteArrayAccess passphrase, ByteArrayAccess msg) ⇒ EncryptedKey → passphrase → msg → IO (Either XPrvError Signature)
- encryptedDerivePrivate ∷ ByteArrayAccess passphrase ⇒ DerivationScheme → EncryptedKey → passphrase → DerivationIndex → IO (Either XPrvError EncryptedKey)
- encryptedDerivePublic ∷ DerivationScheme → (PublicKey, ChainCode) → DerivationIndex → (PublicKey, ChainCode)
- encryptedPublic ∷ EncryptedKey → ByteString
- encryptedChainCode ∷ EncryptedKey → ByteString
- encryptedKeyMaterial ∷ ByteArrayAccess passphrase ⇒ EncryptedKey → passphrase → IO (Either XPrvError (MLockedSizedBytes 64))
- withFastKdfForTesting ∷ IO a → IO a
- withDeterministicRandomnessForTesting ∷ IO a → IO a
Types
data EncryptedKey Source #
Instances
| Show EncryptedKey Source # | |
Defined in Cardano.Crypto.WalletHD.Encrypted Methods showsPrec ∷ Int → EncryptedKey → ShowS # show ∷ EncryptedKey → String # showList ∷ [EncryptedKey] → ShowS # | |
| NFData EncryptedKey Source # | |
Defined in Cardano.Crypto.WalletHD.Encrypted Methods rnf ∷ EncryptedKey → () # | |
| Eq EncryptedKey Source # | |
Defined in Cardano.Crypto.WalletHD.Encrypted | |
| ByteArrayAccess EncryptedKey Source # | |
Defined in Cardano.Crypto.WalletHD.Encrypted Methods length ∷ EncryptedKey → Int Source # withByteArray ∷ EncryptedKey → (Ptr p → IO a) → IO a Source # copyByteArrayToPtr ∷ EncryptedKey → Ptr p → IO () Source # | |
data XPrvFormat Source #
Constructors
| LegacyV1 | |
| EnvelopeV2 |
Instances
| Show XPrvFormat Source # | |
Defined in Cardano.Crypto.WalletHD.Encrypted Methods showsPrec ∷ Int → XPrvFormat → ShowS # show ∷ XPrvFormat → String # showList ∷ [XPrvFormat] → ShowS # | |
| Eq XPrvFormat Source # | |
Defined in Cardano.Crypto.WalletHD.Encrypted | |
Constructors
Constructors
| Signature ByteString |
data DerivationScheme Source #
Constructors
| DerivationScheme1 | |
| DerivationScheme2 |
Instances
type DerivationIndex = Word32 Source #
Construction & validation
encryptedCreate ∷ (ByteArrayAccess passphrase, ByteArrayAccess secret, ByteArrayAccess cc) ⇒ secret → passphrase → cc → IO (Either XPrvError EncryptedKey) Source #
encryptedCreateDirectWithTweak ∷ (ByteArrayAccess passphrase, ByteArrayAccess secret) ⇒ secret → passphrase → IO (Either XPrvError EncryptedKey) Source #
Passphrase operations
encryptedValidatePassphrase ∷ ByteArrayAccess passphrase ⇒ EncryptedKey → passphrase → IO (Either XPrvError ()) Source #
encryptedChangePass ∷ (ByteArrayAccess oldPassPhrase, ByteArrayAccess newPassPhrase) ⇒ oldPassPhrase → newPassPhrase → EncryptedKey → IO (Either XPrvError EncryptedKey) Source #
Signing & derivation
encryptedSign ∷ (ByteArrayAccess passphrase, ByteArrayAccess msg) ⇒ EncryptedKey → passphrase → msg → IO (Either XPrvError Signature) Source #
encryptedDerivePrivate ∷ ByteArrayAccess passphrase ⇒ DerivationScheme → EncryptedKey → passphrase → DerivationIndex → IO (Either XPrvError EncryptedKey) Source #
encryptedDerivePublic ∷ DerivationScheme → (PublicKey, ChainCode) → DerivationIndex → (PublicKey, ChainCode) Source #
Accessors
encryptedKeyMaterial ∷ ByteArrayAccess passphrase ⇒ EncryptedKey → passphrase → IO (Either XPrvError (MLockedSizedBytes 64)) Source #
Decrypt a v2 EncryptedKey and return the 64-byte extended ed25519
scalar in locked memory. The caller must mlsbFinalize the result when
done with it.
Test helpers
withFastKdfForTesting ∷ IO a → IO a Source #
Reduce Argon2id cost for fast tests while keeping all v2 envelope structure intact.
withDeterministicRandomnessForTesting ∷ IO a → IO a Source #
Replace system randomness with a deterministic counter for reproducible test output.