cardano-crypto-class-2.2.0.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 #

HashAlgorithm Blake2b_256 Source # 
Instance details

Defined in Cardano.Crypto.Hash.Blake2b

Associated Types

type SizeHash Blake2b_256Nat Source #

HashAlgorithm Keccak256 Source # 
Instance details

Defined in Cardano.Crypto.Hash.Keccak256

Associated Types

type SizeHash Keccak256Nat Source #

HashAlgorithm NeverHash Source # 
Instance details

Defined in Cardano.Crypto.Hash.NeverUsed

Associated Types

type SizeHash NeverHashNat Source #

HashAlgorithm RIPEMD160 Source # 
Instance details

Defined in Cardano.Crypto.Hash.RIPEMD160

Associated Types

type SizeHash RIPEMD160Nat Source #

HashAlgorithm SHA256 Source # 
Instance details

Defined in Cardano.Crypto.Hash.SHA256

Associated Types

type SizeHash SHA256Nat Source #

HashAlgorithm SHA3_256 Source # 
Instance details

Defined in Cardano.Crypto.Hash.SHA3_256

Associated Types

type SizeHash SHA3_256Nat 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 #

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

The size in bytes of the output of digest

data ByteString Source #

A space-efficient representation of a Word8 vector, supporting many efficient operations.

A ByteString contains 8-bit bytes, or by using the operations from Data.ByteString.Char8 it can be interpreted as containing 8-bit characters.

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 Source #

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

toConstrByteStringConstr Source #

dataTypeOfByteStringDataType Source #

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

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

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

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

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

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

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

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

gmapMpMonadPlus m ⇒ (∀ d. Data d ⇒ d → m d) → ByteString → m ByteString Source #

gmapMoMonadPlus m ⇒ (∀ d. Data d ⇒ d → m d) → ByteString → m ByteString Source #

IsString ByteString

Beware: fromString truncates multi-byte characters to octets. e.g. "枯朶に烏のとまりけり秋の暮" becomes �6k�nh~�Q��n�

Instance details

Defined in Data.ByteString.Internal.Type

Monoid ByteString 
Instance details

Defined in Data.ByteString.Internal.Type

Semigroup ByteString 
Instance details

Defined in Data.ByteString.Internal.Type

IsList ByteString

Since: bytestring-0.10.12.0

Instance details

Defined in Data.ByteString.Internal.Type

Associated Types

type Item ByteString Source #

Read ByteString 
Instance details

Defined in Data.ByteString.Internal.Type

Show ByteString 
Instance details

Defined in Data.ByteString.Internal.Type

FromCBOR ByteString 
Instance details

Defined in Cardano.Binary.FromCBOR

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 → () Source #

Eq ByteString 
Instance details

Defined in Data.ByteString.Internal.Type

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

Since: bytestring-0.11.2.0

Instance details

Defined in Data.ByteString.Internal.Type

Methods

liftQuote m ⇒ ByteString → m Exp Source #

liftTyped ∷ ∀ (m ∷ TypeType). Quote m ⇒ ByteStringCode m ByteString Source #

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

fromStringStringQ (TExp (Hash h a)) Source #

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

fromStringStringHash h a Source #

Generic (Hash h a) Source # 
Instance details

Defined in Cardano.Crypto.Hash.Class

Associated Types

type Rep (Hash h a) ∷ TypeType Source #

Methods

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

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

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

Defined in Cardano.Crypto.Hash.Class

Show (Hash h a) Source # 
Instance details

Defined in Cardano.Crypto.Hash.Class

Methods

showsPrecIntHash h a → ShowS Source #

showHash h a → String Source #

showList ∷ [Hash h a] → ShowS Source #

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

Defined in Cardano.Crypto.Hash.Class

Methods

fromCBORDecoder s (Hash h a) Source #

labelProxy (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 → () Source #

Eq (Hash h a) Source # 
Instance details

Defined in Cardano.Crypto.Hash.Class

Methods

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

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

Ord (Hash h a) Source # 
Instance details

Defined in Cardano.Crypto.Hash.Class

Methods

compareHash h a → Hash h a → Ordering Source #

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

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

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

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

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

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

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

typeNameString 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

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

Defined in Cardano.Crypto.Hash.Class

Methods

fromStringStringCode Q (Hash h a) Source #

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.0.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 → () Source #

Eq (PackedBytes n) Source # 
Instance details

Defined in Cardano.Crypto.PackedBytes

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 ⇒ TextMaybe (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 ⇒ StringMaybe (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