multihash-cryptonite-0.1.0.0: Self-identifying hashes, implementation of <https://github.com/multiformats/multihash>

Copyright2018 Monadic GmbH
LicenseBSD3
Maintainerkim@monadic.xyz, team@monadic.xyz
Stabilityprovisional
Portabilitynon-portable (GHC extensions)
Safe HaskellNone
LanguageHaskell2010

Data.Multihash

Contents

Description

multihash encoding of Digests.

Example:

>>> :set -XOverloadedStrings
>>> import qualified Crypto.Hash as C
>>> import Data.ByteArray.Encoding (Base(..), convertToBase)
>>> import Data.ByteString (ByteString)
>>> import qualified Data.ByteString.Char8 as C8
>>> import System.IO (stdout)
>>> :{
    let
        input :: ByteString
        input = "multihash"
        atBase :: Base -> Multihash -> ByteString
        atBase base = convertToBase base . encodedBytes
     in
        C8.hPutStr stdout $ C8.unlines
            [ atBase Base16 $ multihash C.SHA1   input
            , atBase Base32 $ multihash C.SHA1   input
            , atBase Base16 $ multihash C.SHA256 input
            , atBase Base32 $ multihash C.SHA256 input
            ]
:}
111488c2f11fb2ce392acb5b2986e640211c4690073e
CEKIRQXRD6ZM4OJKZNNSTBXGIAQRYRUQA47A====
12209cbc07c3f991725836a3aa2a581ca2029198aa420b9d99bc0e131d9f3e2cbe47
CIQJZPAHYP4ZC4SYG2R2UKSYDSRAFEMYVJBAXHMZXQHBGHM7HYWL4RY=
Synopsis

Documentation

data Multihash Source #

A multihash-encoded strict ByteString.

Instances
Eq Multihash Source # 
Instance details

Defined in Data.Multihash

Ord Multihash Source # 
Instance details

Defined in Data.Multihash

NFData Multihash Source # 
Instance details

Defined in Data.Multihash

Methods

rnf :: Multihash -> () #

Hashable Multihash Source # 
Instance details

Defined in Data.Multihash

fromDigest :: forall a. Multihashable a => Digest a -> Multihash Source #

Encode a Digest as a Multihash.

encodedBytes :: Multihash -> ByteString Source #

Extract the raw, multihash-encoded bytes of a Multihash.

multihash :: (ByteArrayAccess ba, Multihashable a) => a -> ba -> Multihash Source #

Hash a value to a Multihash

decodeDigest :: forall a. Multihashable a => ByteString -> Either String (Digest a) Source #

Decode a Digest from a multihash-encoded ByteString.

Compact representation

data CompactMultihash Source #

A Multihash backed by a ShortByteString.

This is useful when holding many Multihashes in memory, due to lower memory overhead and less heap fragmentation. See the documentation for ShortByteString for details.

compact :: Multihash -> CompactMultihash Source #

Convert a Multihash to a compact representation.

expand :: CompactMultihash -> Multihash Source #

Convert a CompactMultihash to the regular representation.

Re-exports

type Multihashable a = (HashAlgorithm a, FromCryptonite a) Source #

fromCryptonite :: FromCryptonite a => proxy a -> HashAlgorithm Source #