cometa-0.1.0.0: Idiomatic Haskell bindings to cardano-c
Safe HaskellSafe-Inferred
LanguageHaskell2010

Cometa.Crypto.Blake2b

Description

BLAKE2b digests as immutable byte sequences. This general digest type does not distinguish payment, stake, or script hashes.

import qualified Cometa.Crypto.Blake2b as Blake2b
import qualified Data.ByteString.Char8 as ByteString

main :: IO ()
main = do
  result <- Blake2b.compute 32 (ByteString.pack "abc")
  print (Blake2b.toHex $ result)
Synopsis

Documentation

data Blake2bHash Source #

A nonempty digest byte sequence. Equality compares bytes; ordering is lexicographic byte ordering. Show is diagnostic; use toHex for a stable textual encoding.

Hashing

compute Source #

Arguments

:: Int

Digest length in bytes, from 16 through 64 inclusive.

-> ByteString

Nonempty message to hash.

-> IO (Either Error Blake2bHash)

Digest with the requested length, or a validation or operation failure.

Compute an unkeyed digest with an output length of 16 through 64 bytes. Invalid output lengths return InvalidHashLength. Empty messages are currently unsupported and return NativeError with code OutOfBoundsMemoryRead. Other cardano-c failures also return NativeError.

Importing digests

fromBytes :: ByteString -> Either Error Blake2bHash Source #

Import digest bytes without hashing them. Any nonempty length is accepted; this operation does not assert a particular digest role or algorithm variant. Empty input returns EmptyHash.

fromHex :: Text -> Either Error Blake2bHash Source #

Import nonempty, even-length ASCII hexadecimal text, accepting both cases. Malformed text returns InvalidHex. No whitespace or prefix is accepted.

Inspection

toBytes :: Blake2bHash -> ByteString Source #

Observe the immutable digest bytes.

toHex :: Blake2bHash -> Text Source #

Encode the digest as lowercase ASCII hex, without a prefix or whitespace.

CBOR

encodeCbor :: Blake2bHash -> ByteString Source #

Encode the digest as one definite-length CBOR byte string.

decodeCbor :: ByteString -> Either Error Blake2bHash Source #

Import exactly one nonempty CBOR byte string without hashing it. Definite and indefinite byte strings are accepted; invalid CBOR, other types and trailing data return InvalidHashCbor. Empty bytes return EmptyHash.