cardano-crypto-class-2.2.3.0: Type classes abstracting over cryptography primitives for Cardano
Safe HaskellSafe-Inferred
LanguageHaskell2010

Cardano.Crypto.Hash.Class

Description

Abstract hashing functionality.

Synopsis

Documentation

class (KnownNat (SizeHash h), Typeable h) ⇒ HashAlgorithm h where Source #

Associated Types

type SizeHash h ∷ Nat Source #

Size of hash digest

Methods

hashAlgorithmName ∷ proxy h → String Source #

digest ∷ proxy h → ByteStringByteString Source #

Instances

Instances details
HashAlgorithm Blake2b_224 Source # 
Instance details

Defined in Cardano.Crypto.Hash.Blake2b

Associated Types

type SizeHash Blake2b_224Nat Source #

Methods

hashAlgorithmName ∷ proxy Blake2b_224 → String Source #

digest ∷ proxy Blake2b_224ByteStringByteString Source #

HashAlgorithm Blake2b_256 Source # 
Instance details

Defined in Cardano.Crypto.Hash.Blake2b

Associated Types

type SizeHash Blake2b_256Nat Source #

Methods

hashAlgorithmName ∷ proxy Blake2b_256 → String Source #

digest ∷ proxy Blake2b_256ByteStringByteString Source #

HashAlgorithm Keccak256 Source # 
Instance details

Defined in Cardano.Crypto.Hash.Keccak256

Associated Types

type SizeHash Keccak256Nat Source #

Methods

hashAlgorithmName ∷ proxy Keccak256 → String Source #

digest ∷ proxy Keccak256ByteStringByteString Source #

HashAlgorithm NeverHash Source # 
Instance details

Defined in Cardano.Crypto.Hash.NeverUsed

Associated Types

type SizeHash NeverHashNat Source #

Methods

hashAlgorithmName ∷ proxy NeverHash → String Source #

digest ∷ proxy NeverHashByteStringByteString Source #

HashAlgorithm RIPEMD160 Source # 
Instance details

Defined in Cardano.Crypto.Hash.RIPEMD160

Associated Types

type SizeHash RIPEMD160Nat Source #

Methods

hashAlgorithmName ∷ proxy RIPEMD160 → String Source #

digest ∷ proxy RIPEMD160ByteStringByteString Source #

HashAlgorithm SHA256 Source # 
Instance details

Defined in Cardano.Crypto.Hash.SHA256

Associated Types

type SizeHash SHA256Nat Source #

Methods

hashAlgorithmName ∷ proxy SHA256 → String Source #

digest ∷ proxy SHA256ByteStringByteString Source #

HashAlgorithm SHA3_256 Source # 
Instance details

Defined in Cardano.Crypto.Hash.SHA3_256

Associated Types

type SizeHash SHA3_256Nat Source #

Methods

hashAlgorithmName ∷ proxy SHA3_256 → String Source #

digest ∷ proxy SHA3_256ByteStringByteString Source #

HashAlgorithm SHA3_512 Source # 
Instance details

Defined in Cardano.Crypto.Hash.SHA3_512

Associated Types

type SizeHash SHA3_512Nat Source #

Methods

hashAlgorithmName ∷ proxy SHA3_512 → String Source #

digest ∷ proxy SHA3_512ByteStringByteString Source #

HashAlgorithm SHA512 Source # 
Instance details

Defined in Cardano.Crypto.Hash.SHA512

Associated Types

type SizeHash SHA512Nat Source #

Methods

hashAlgorithmName ∷ proxy SHA512 → String Source #

digest ∷ proxy SHA512ByteStringByteString Source #

(KnownNat n, CmpNat n 33 ~ 'LT) ⇒ HashAlgorithm (Blake2bPrefix n) Source # 
Instance details

Defined in Cardano.Crypto.Hash.Short

Associated Types

type SizeHash (Blake2bPrefix n) ∷ Nat Source #

Methods

hashAlgorithmName ∷ proxy (Blake2bPrefix n) → String Source #

digest ∷ proxy (Blake2bPrefix n) → ByteStringByteString Source #

sizeHash ∷ ∀ h proxy. HashAlgorithm h ⇒ proxy h → Word Source #

The size in bytes of the output of digest

data ByteString #

Instances

Instances details
Data ByteString 
Instance details

Defined in Data.ByteString.Internal.Type

Methods

gfoldl ∷ (∀ d b. Data d ⇒ c (d → b) → d → c b) → (∀ g. g → c g) → ByteString → c ByteString #

gunfold ∷ (∀ b r. Data b ⇒ c (b → r) → c r) → (∀ r. r → c r) → Constr → c ByteString #

toConstrByteString → Constr #

dataTypeOfByteStringDataType #

dataCast1Typeable t ⇒ (∀ d. Data d ⇒ c (t d)) → Maybe (c ByteString) #

dataCast2Typeable t ⇒ (∀ d e. (Data d, Data e) ⇒ c (t d e)) → Maybe (c ByteString) #

gmapT ∷ (∀ b. Data b ⇒ b → b) → ByteStringByteString #

gmapQl ∷ (r → r' → r) → r → (∀ d. Data d ⇒ d → r') → ByteString → r #

gmapQr ∷ ∀ r r'. (r' → r → r) → r → (∀ d. Data d ⇒ d → r') → ByteString → r #

gmapQ ∷ (∀ d. Data d ⇒ d → u) → ByteString → [u] #

gmapQiInt → (∀ d. Data d ⇒ d → u) → ByteString → u #

gmapMMonad m ⇒ (∀ d. Data d ⇒ d → m d) → ByteString → m ByteString #

gmapMp ∷ MonadPlus m ⇒ (∀ d. Data d ⇒ d → m d) → ByteString → m ByteString #

gmapMo ∷ MonadPlus m ⇒ (∀ d. Data d ⇒ d → m d) → ByteString → m ByteString #

IsString ByteString 
Instance details

Defined in Data.ByteString.Internal.Type

Methods

fromString ∷ String → ByteString #

Monoid ByteString 
Instance details

Defined in Data.ByteString.Internal.Type

Semigroup ByteString 
Instance details

Defined in Data.ByteString.Internal.Type

Methods

(<>)ByteStringByteStringByteString #

sconcat ∷ NonEmpty ByteStringByteString #

stimes ∷ Integral b ⇒ b → ByteStringByteString #

IsList ByteString 
Instance details

Defined in Data.ByteString.Internal.Type

Associated Types

type Item ByteString #

Read ByteString 
Instance details

Defined in Data.ByteString.Internal.Type

Methods

readsPrecInt → ReadS ByteString

readList ∷ ReadS [ByteString]

readPrec ∷ ReadPrec ByteString

readListPrec ∷ ReadPrec [ByteString]

Show ByteString 
Instance details

Defined in Data.ByteString.Internal.Type

Methods

showsPrecIntByteString → ShowS #

showByteString → String #

showList ∷ [ByteString] → ShowS #

FromCBOR ByteString 
Instance details

Defined in Cardano.Binary.FromCBOR

Methods

fromCBORDecoder s ByteString Source #

label ∷ Proxy ByteString → Text Source #

ToCBOR ByteString 
Instance details

Defined in Cardano.Binary.ToCBOR

Methods

toCBORByteStringEncoding Source #

encodedSizeExpr ∷ (∀ t. ToCBOR t ⇒ Proxy t → Size) → Proxy ByteStringSize Source #

encodedListSizeExpr ∷ (∀ t. ToCBOR t ⇒ Proxy t → Size) → Proxy [ByteString] → Size Source #

SignableRepresentation ByteString Source # 
Instance details

Defined in Cardano.Crypto.Util

NFData ByteString 
Instance details

Defined in Data.ByteString.Internal.Type

Methods

rnfByteString → ()

Eq ByteString 
Instance details

Defined in Data.ByteString.Internal.Type

Methods

(==)ByteStringByteStringBool #

(/=)ByteStringByteStringBool #

Ord ByteString 
Instance details

Defined in Data.ByteString.Internal.Type

Hashable ByteString 
Instance details

Defined in Data.Hashable.Class

HeapWords ByteString 
Instance details

Defined in Cardano.HeapWords

ByteArray ByteString 
Instance details

Defined in Data.ByteArray.Types

Methods

allocRetInt → (Ptr p → IO a) → IO (a, ByteString) Source #

ByteArrayAccess ByteString 
Instance details

Defined in Data.ByteArray.Types

Methods

lengthByteStringInt Source #

withByteArrayByteString → (Ptr p → IO a) → IO a Source #

copyByteArrayToPtrByteStringPtr p → IO () Source #

MemPack ByteString 
Instance details

Defined in Data.MemPack

Buffer ByteString 
Instance details

Defined in Data.MemPack.Buffer

Methods

bufferByteCountByteStringInt Source #

bufferByteString → (ByteArray# → a) → (Addr# → a) → a Source #

NoThunks ByteString

Instance for string bytestrings

Strict bytestrings shouldn't contain any thunks, but could, due to https://gitlab.haskell.org/ghc/ghc/issues/17290. However, such thunks can't retain any data that they shouldn't, and so it's safe to ignore such thunks.

Instance details

Defined in NoThunks.Class

Serialise ByteString

Since: serialise-0.2.0.0

Instance details

Defined in Codec.Serialise.Class

Lift ByteString 
Instance details

Defined in Data.ByteString.Internal.Type

Methods

liftQuote m ⇒ ByteString → m Exp

liftTyped ∷ ∀ (m ∷ Type → Type). Quote m ⇒ ByteStringCode m ByteString

type Item ByteString 
Instance details

Defined in Data.ByteString.Internal.Type

data Hash h a where Source #

Bundled Patterns

pattern UnsafeHash ∷ ∀ h a. HashAlgorithm h ⇒ ShortByteStringHash h a 

Instances

Instances details
HashAlgorithm h ⇒ IsString (Q (TExp (Hash h a))) Source #

This instance is meant to be used with TemplateHaskell

>>> import Cardano.Crypto.Hash.Class (Hash)
>>> import Cardano.Crypto.Hash.Short (ShortHash)
>>> :set -XTemplateHaskell
>>> :set -XOverloadedStrings
>>> let hash = $$("0xBADC0FFEE0DDF00D") :: Hash ShortHash ()
>>> print hash
"badc0ffee0ddf00d"
>>> let hash = $$("0123456789abcdef") :: Hash ShortHash ()
>>> print hash
"0123456789abcdef"
>>> let hash = $$("deadbeef") :: Hash ShortHash ()
<interactive>:5:15: error:
    • <Hash blake2b_prefix_8>: Expected in decoded form to be: 8 bytes, but got: 4
    • In the Template Haskell splice $$("deadbeef")
      In the expression: $$("deadbeef") :: Hash ShortHash ()
      In an equation for ‘hash’:
          hash = $$("deadbeef") :: Hash ShortHash ()
>>> let hash = $$("123") :: Hash ShortHash ()
<interactive>:6:15: error:
    • <Hash blake2b_prefix_8>: Malformed hex: invalid bytestring size
    • In the Template Haskell splice $$("123")
      In the expression: $$("123") :: Hash ShortHash ()
      In an equation for ‘hash’: hash = $$("123") :: Hash ShortHash ()
Instance details

Defined in Cardano.Crypto.Hash.Class

Methods

fromString ∷ String → Q (TExp (Hash h a)) #

HashAlgorithm h ⇒ FromJSON (Hash h a) Source # 
Instance details

Defined in Cardano.Crypto.Hash.Class

HashAlgorithm h ⇒ FromJSONKey (Hash h a) Source # 
Instance details

Defined in Cardano.Crypto.Hash.Class

HashAlgorithm h ⇒ ToJSON (Hash h a) Source # 
Instance details

Defined in Cardano.Crypto.Hash.Class

Methods

toJSONHash h a → Value Source #

toEncodingHash h a → Encoding Source #

toJSONList ∷ [Hash h a] → Value Source #

toEncodingList ∷ [Hash h a] → Encoding Source #

omitFieldHash h a → Bool Source #

HashAlgorithm h ⇒ ToJSONKey (Hash h a) Source # 
Instance details

Defined in Cardano.Crypto.Hash.Class

HashAlgorithm h ⇒ IsString (Hash h a) Source # 
Instance details

Defined in Cardano.Crypto.Hash.Class

Methods

fromString ∷ String → Hash h a #

Generic (Hash h a) Source # 
Instance details

Defined in Cardano.Crypto.Hash.Class

Associated Types

type Rep (Hash h a) ∷ Type → Type #

Methods

fromHash h a → Rep (Hash h a) x #

toRep (Hash h a) x → Hash h a #

HashAlgorithm h ⇒ Read (Hash h a) Source # 
Instance details

Defined in Cardano.Crypto.Hash.Class

Methods

readsPrecInt → ReadS (Hash h a)

readList ∷ ReadS [Hash h a]

readPrec ∷ ReadPrec (Hash h a)

readListPrec ∷ ReadPrec [Hash h a]

Show (Hash h a) Source # 
Instance details

Defined in Cardano.Crypto.Hash.Class

Methods

showsPrecIntHash h a → ShowS #

showHash h a → String #

showList ∷ [Hash h a] → ShowS #

(HashAlgorithm h, Typeable a) ⇒ FromCBOR (Hash h a) Source # 
Instance details

Defined in Cardano.Crypto.Hash.Class

Methods

fromCBORDecoder s (Hash h a) Source #

label ∷ Proxy (Hash h a) → Text Source #

(HashAlgorithm h, Typeable a) ⇒ ToCBOR (Hash h a) Source # 
Instance details

Defined in Cardano.Crypto.Hash.Class

Methods

toCBORHash h a → Encoding Source #

encodedSizeExpr ∷ (∀ t. ToCBOR t ⇒ Proxy t → Size) → Proxy (Hash h a) → Size Source #

encodedListSizeExpr ∷ (∀ t. ToCBOR t ⇒ Proxy t → Size) → Proxy [Hash h a] → Size Source #

NFData (Hash h a) Source # 
Instance details

Defined in Cardano.Crypto.Hash.Class

Methods

rnfHash h a → ()

Eq (Hash h a) Source # 
Instance details

Defined in Cardano.Crypto.Hash.Class

Methods

(==)Hash h a → Hash h a → Bool #

(/=)Hash h a → Hash h a → Bool #

Ord (Hash h a) Source # 
Instance details

Defined in Cardano.Crypto.Hash.Class

Methods

compareHash h a → Hash h a → Ordering #

(<)Hash h a → Hash h a → Bool #

(<=)Hash h a → Hash h a → Bool #

(>)Hash h a → Hash h a → Bool #

(>=)Hash h a → Hash h a → Bool #

maxHash h a → Hash h a → Hash h a #

minHash h a → Hash h a → Hash h a #

HeapWords (Hash h a) Source # 
Instance details

Defined in Cardano.Crypto.Hash.Class

Methods

heapWordsHash h a → Int Source #

HashAlgorithm h ⇒ MemPack (Hash h a) Source # 
Instance details

Defined in Cardano.Crypto.Hash.Class

Methods

typeName ∷ String Source #

packedByteCountHash h a → Int Source #

packMHash h a → Pack s () Source #

unpackMBuffer b ⇒ Unpack b (Hash h a) Source #

NoThunks (Hash h a) Source # 
Instance details

Defined in Cardano.Crypto.Hash.Class

Methods

noThunksContextHash h a → IO (Maybe ThunkInfo) Source #

wNoThunksContextHash h a → IO (Maybe ThunkInfo) Source #

showTypeOf ∷ Proxy (Hash h a) → String Source #

HashAlgorithm h ⇒ IsString (Code Q (Hash h a)) Source # 
Instance details

Defined in Cardano.Crypto.Hash.Class

Methods

fromString ∷ String → Code Q (Hash h a) #

type Rep (Hash h a) Source # 
Instance details

Defined in Cardano.Crypto.Hash.Class

type Rep (Hash h a) = D1 ('MetaData "Hash" "Cardano.Crypto.Hash.Class" "cardano-crypto-class-2.2.3.0-inplace" 'True) (C1 ('MetaCons "UnsafeHashRep" 'PrefixI 'False) (S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (PackedBytes (SizeHash h)))))

data PackedBytes (n ∷ Nat) where Source #

Constructors

PackedBytes8 ∷ !Word64PackedBytes 8 
PackedBytes28 ∷ !Word64 → !Word64 → !Word64 → !Word32PackedBytes 28 
PackedBytes32 ∷ !Word64 → !Word64 → !Word64 → !Word64PackedBytes 32 

Instances

Instances details
NFData (PackedBytes n) Source # 
Instance details

Defined in Cardano.Crypto.PackedBytes

Methods

rnfPackedBytes n → ()

Eq (PackedBytes n) Source # 
Instance details

Defined in Cardano.Crypto.PackedBytes

Methods

(==)PackedBytes n → PackedBytes n → Bool #

(/=)PackedBytes n → PackedBytes n → Bool #

Ord (PackedBytes n) Source # 
Instance details

Defined in Cardano.Crypto.PackedBytes

KnownNat n ⇒ MemPack (PackedBytes n) Source # 
Instance details

Defined in Cardano.Crypto.PackedBytes

NoThunks (PackedBytes n) Source # 
Instance details

Defined in Cardano.Crypto.PackedBytes

KnownNat n ⇒ Serialise (PackedBytes n) Source # 
Instance details

Defined in Cardano.Crypto.PackedBytes

Core operations

hashWith ∷ ∀ h a. HashAlgorithm h ⇒ (a → ByteString) → a → Hash h a Source #

Hash the given value, using a serialisation function to turn it into bytes.

hashWithSerialiser ∷ ∀ h a. HashAlgorithm h ⇒ (a → Encoding) → a → Hash h a Source #

A variation on hashWith, but specially for CBOR encodings.

Conversions

castHashHash h a → Hash h b Source #

Cast the type of the hashed data.

The Hash type has a phantom type parameter to indicate what type the hash is of. It is sometimes necessary to fake this and hash a value of one type and use it where as hash of a different type is expected.

hashToBytesHash h a → ByteString Source #

The representation of the hash as bytes.

hashFromBytes Source #

Arguments

∷ ∀ h a. HashAlgorithm h 
ByteString

It must have an exact length, as given by sizeHash.

Maybe (Hash h a) 

Make a hash from it bytes representation.

hashToBytesShortHash h a → ShortByteString Source #

The representation of the hash as bytes, as a ShortByteString.

hashFromBytesShort Source #

Arguments

∷ ∀ h a. HashAlgorithm h 
ShortByteString

It must be a buffer of exact length, as given by sizeHash.

Maybe (Hash h a) 

Make a hash from it bytes representation, as a ShortByteString.

hashFromOffsetBytesShort Source #

Arguments

∷ ∀ h a. HashAlgorithm h 
ShortByteString

It must be a buffer that contains at least sizeHash many bytes staring at an offset.

Int

Offset in number of bytes

Maybe (Hash h a) 

Just like hashFromBytesShort, but allows using a region of a ShortByteString.

hashToPackedBytesHash h a → PackedBytes (SizeHash h) Source #

O(1) - Get the underlying hash representation

hashFromPackedBytesPackedBytes (SizeHash h) → Hash h a Source #

O(1) - Construct hash from the underlying representation

Rendering and parsing

hashToBytesAsHexHash h a → ByteString Source #

Convert the hash to hex encoding, as ByteString.

hashFromBytesAsHexHashAlgorithm h ⇒ ByteStringMaybe (Hash h a) Source #

Make a hash from hex-encoded ByteString representation.

This can fail for the same reason as hashFromBytes, or because the input is invalid hex. The whole byte string must be valid hex, not just a prefix.

hashToTextAsHexHash h a → Text Source #

Convert the hash to hex encoding, as Text.

hashFromTextAsHexHashAlgorithm h ⇒ Text → Maybe (Hash h a) Source #

Make a hash from hex-encoded Text representation.

This can fail for the same reason as hashFromBytes, or because the input is invalid hex. The whole byte string must be valid hex, not just a prefix.

hashToStringAsHexHash h a → String Source #

Convert the hash to hex encoding, as String.

hashFromStringAsHexHashAlgorithm h ⇒ String → Maybe (Hash h a) Source #

Make a hash from hex-encoded String representation.

This can fail for the same reason as hashFromBytes, or because the input is invalid hex. The whole byte string must be valid hex, not just a prefix.

Other operations

xorHash h a → Hash h a → Hash h a Source #

XOR two hashes together

Deprecated

hash ∷ ∀ h a. (HashAlgorithm h, ToCBOR a) ⇒ a → Hash h a Source #

Deprecated: Use hashWith or hashWithSerialiser

fromHashHash h a → Natural Source #

Deprecated: Use bytesToNatural . hashToBytes

hashRaw ∷ ∀ h a. HashAlgorithm h ⇒ (a → ByteString) → a → Hash h a Source #

Deprecated: Use hashWith

getHashHash h a → ByteString Source #

Deprecated: Use hashToBytes

getHashBytesAsHexHash h a → ByteString Source #

Deprecated: Use hashToBytesAsHex