mfmts-1.2.0.0: cid/MultiFormats/CID/Constants.hs
-- | Module : MultiFormats.CID.Constants
-- Description : Defines constants used in CIDs
-- Copyright : Zoey McBride (c) 2026
-- License : AGPL-3.0-or-later
-- Maintainer : zoeymcbride@mailbox.org
-- Stability : experimental
module MultiFormats.CID.Constants
( -- * Versioning magic numbers
v0EncodingPrefix,
v0FirstByte,
v0SecondByte,
v1FirstVarInt,
-- * Versioning metadata
v0EncodingLength,
v0TotalBytes,
v0HashBytes,
-- * CBOR tag number for IPLD's DAG-CBOR specification.
ipldTagCBOR,
)
where
import Data.Word (Word8)
import MultiFormats.VarInt (VarInt)
-- | This prefixes a CIDv0 instead of a multibase prefix.
v0EncodingPrefix :: String
v0EncodingPrefix = "Qm"
-- | The length of a CIDv0 string, base58 encoded.
v0EncodingLength :: Int
v0EncodingLength = 46
-- | Required length in bytes of all CIDv0 encodings.
v0TotalBytes :: Int
v0TotalBytes = 34
-- | Length of hash digest in CIDv0, ie the length without its versioning
-- information, since those are the only items in CIDv0.
v0HashBytes :: Int
v0HashBytes = v0TotalBytes - 2
-- | Required first byte of all CIDv0 encodings.
v0FirstByte :: Word8
v0FirstByte = 0x12
-- | Required second byte of all CIDv0 encodings.
v0SecondByte :: Word8
v0SecondByte = 0x20
-- | Required first VarInt of all CIDv1 encodings.
v1FirstVarInt :: VarInt
v1FirstVarInt = 1
-- | Used for CBOR tagged major-types to identify CID encoded bytestrings.
ipldTagCBOR :: Word8
ipldTagCBOR = 42