libp2p-hs-0.1.0.0: Haskell implementation of the libp2p networking stack
Safe HaskellNone
LanguageGHC2021

Network.LibP2P.Core.Multihash

Description

Multihash encoding/decoding.

Multihash is a self-describing hash format: hash-function-codedigest-sizedigest Used for Peer ID derivation and content addressing.

Synopsis

Documentation

data HashFunction Source #

Supported hash functions for multihash encoding.

Constructors

Identity

Code 0x00: raw bytes, no hashing

SHA256

Code 0x12: SHA-256 (32-byte digest)

Instances

Instances details
Show HashFunction Source # 
Instance details

Defined in Network.LibP2P.Core.Multihash

Eq HashFunction Source # 
Instance details

Defined in Network.LibP2P.Core.Multihash

encodeMultihash :: HashFunction -> ByteString -> ByteString Source #

Encode data as a multihash. For Identity: stores raw bytes. For SHA256: hashes first, stores digest.

decodeMultihash :: ByteString -> Either String (HashFunction, ByteString) Source #

Decode a multihash into its hash function and digest/data. Note: does not reject trailing bytes after the digest.

validateMultihash :: ByteString -> Either String (HashFunction, ByteString) Source #

Validate a multihash strictly: decode, check digest length constraints, and reject trailing bytes.