@staticmethod
def decode(cid: Union[(str, BytesLike)]) -> 'CID':
    '\n            Decodes a CID from a bytestring or a hex string (which will be converted to :obj:`bytes`\n            using :obj:`bytes.fromhex`). Note: the hex string is not multibase encoded.\n\n            Example usage for CIDv1 multibase-encoded string:\n\n            >>> s = "zb2rhe5P4gXftAwvA4eXQ5HJwsER2owDyS9sKaQRRVQPn93bA"\n            >>> CID.decode(s)\n            CID(\'base58btc\', 1, \'raw\',\n            \'12206e6ff7950a36187a801613426e858dce686cd7d7e3c0fc42ee0330072d245c95\')\n\n            Example usage for CIDv1 bytestring (multibase always set to \'base58btc\'):\n\n            >>> b = bytes.fromhex(\n            ... "015512206e6ff7950a36187a801613426e85"\n            ... "8dce686cd7d7e3c0fc42ee0330072d245c95")\n            >>> CID.decode(b)\n            CID(\'base58btc\', 1, \'raw\',\n            \'12206e6ff7950a36187a801613426e858dce686cd7d7e3c0fc42ee0330072d245c95\')\n\n            Example usage for CIDv0 base58-encoded string:\n\n            >>> s = "QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR"\n            >>> CID.decode(s)\n            CID(\'base58btc\', 0, \'dag-pb\',\n            \'1220c3c4733ec8affd06cf9e9ff50ffc6bcd2ec85a6170004bb709669c31de94391a\')\n\n            Example usage for CIDv0 bytestring (multibase always set to \'base58btc\'):\n\n            >>> b = bytes.fromhex(\n            ... "1220c3c4733ec8affd06cf9e9ff50ffc6b"\n            ... "cd2ec85a6170004bb709669c31de94391a")\n            >>> CID.decode(b)\n            CID(\'base58btc\', 0, \'dag-pb\',\n            \'1220c3c4733ec8affd06cf9e9ff50ffc6bcd2ec85a6170004bb709669c31de94391a\')\n\n            :param cid: the CID bytes or multibase-encoded string\n            :type cid: :obj:`str` or :obj:`~multiformats.varint.BytesLike`\n\n            :raises ValueError: if the CID is malformed or the CID version is unsupported\n            :raises KeyError: if the multibase, multicodec or multihash are unknown\n\n        '
    if isinstance(cid, str):
        (cid, mb) = _binary_cid_from_str(cid)
    else:
        mb = multibase.get('base58btc')
    validate(cid, BytesLike)
    cid = memoryview(cid)
    if ((len(cid) == 34) and (cid[0] == 18) and (cid[1] == 32)):
        v = 0
        mc_code = 112
        digest = cid
    else:
        (v, _, cid) = varint.decode_raw(cid)
        if (v == 0):
            raise ValueError('CIDv0 is malformed.')
        if (v in (2, 3)):
            raise ValueError('CID versions 2 and 3 are reserved for future use.')
        if (v != 1):
            raise ValueError(f'CIDv{v} is currently not supported.')
        (mc_code, _, cid) = multicodec.unwrap_raw(cid)
        digest = cid
    mc = multicodec.get(code=mc_code)
    (mh_code, _) = multihash.unwrap_raw(digest)
    mh = multihash.get(code=mh_code)
    return CID._new_instance(CID, mb, v, mc, mh, digest)
Decodes a CID from a bytestring or a hex string (which will be converted to :obj:`bytes`
using :obj:`bytes.fromhex`). Note: the hex string is not multibase encoded.

Example usage for CIDv1 multibase-encoded string:

>>> s = "zb2rhe5P4gXftAwvA4eXQ5HJwsER2owDyS9sKaQRRVQPn93bA"
>>> CID.decode(s)
CID('base58btc', 1, 'raw',
'12206e6ff7950a36187a801613426e858dce686cd7d7e3c0fc42ee0330072d245c95')

Example usage for CIDv1 bytestring (multibase always set to 'base58btc'):

>>> b = bytes.fromhex(
... "015512206e6ff7950a36187a801613426e85"
... "8dce686cd7d7e3c0fc42ee0330072d245c95")
>>> CID.decode(b)
CID('base58btc', 1, 'raw',
'12206e6ff7950a36187a801613426e858dce686cd7d7e3c0fc42ee0330072d245c95')

Example usage for CIDv0 base58-encoded string:

>>> s = "QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR"
>>> CID.decode(s)
CID('base58btc', 0, 'dag-pb',
'1220c3c4733ec8affd06cf9e9ff50ffc6bcd2ec85a6170004bb709669c31de94391a')

Example usage for CIDv0 bytestring (multibase always set to 'base58btc'):

>>> b = bytes.fromhex(
... "1220c3c4733ec8affd06cf9e9ff50ffc6b"
... "cd2ec85a6170004bb709669c31de94391a")
>>> CID.decode(b)
CID('base58btc', 0, 'dag-pb',
'1220c3c4733ec8affd06cf9e9ff50ffc6bcd2ec85a6170004bb709669c31de94391a')

:param cid: the CID bytes or multibase-encoded string
:type cid: :obj:`str` or :obj:`~multiformats.varint.BytesLike`

:raises ValueError: if the CID is malformed or the CID version is unsupported
:raises KeyError: if the multibase, multicodec or multihash are unknown
@staticmethod
def decode(cid: Union[(str, BytesLike)]) -> 'CID':
    '\n            Decodes a CID from a bytestring or a hex string (which will be converted to :obj:`bytes`\n            using :obj:`bytes.fromhex`). Note: the hex string is not multibase encoded.\n\n            Example usage for CIDv1 multibase-encoded string:\n\n            >>> s = "zb2rhe5P4gXftAwvA4eXQ5HJwsER2owDyS9sKaQRRVQPn93bA"\n            >>> CID.decode(s)\n            CID(\'base58btc\', 1, \'raw\',\n            \'12206e6ff7950a36187a801613426e858dce686cd7d7e3c0fc42ee0330072d245c95\')\n\n            Example usage for CIDv1 bytestring (multibase always set to \'base58btc\'):\n\n            >>> b = bytes.fromhex(\n            ... "015512206e6ff7950a36187a801613426e85"\n            ... "8dce686cd7d7e3c0fc42ee0330072d245c95")\n            >>> CID.decode(b)\n            CID(\'base58btc\', 1, \'raw\',\n            \'12206e6ff7950a36187a801613426e858dce686cd7d7e3c0fc42ee0330072d245c95\')\n\n            Example usage for CIDv0 base58-encoded string:\n\n            >>> s = "QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR"\n            >>> CID.decode(s)\n            CID(\'base58btc\', 0, \'dag-pb\',\n            \'1220c3c4733ec8affd06cf9e9ff50ffc6bcd2ec85a6170004bb709669c31de94391a\')\n\n            Example usage for CIDv0 bytestring (multibase always set to \'base58btc\'):\n\n            >>> b = bytes.fromhex(\n            ... "1220c3c4733ec8affd06cf9e9ff50ffc6b"\n            ... "cd2ec85a6170004bb709669c31de94391a")\n            >>> CID.decode(b)\n            CID(\'base58btc\', 0, \'dag-pb\',\n            \'1220c3c4733ec8affd06cf9e9ff50ffc6bcd2ec85a6170004bb709669c31de94391a\')\n\n            :param cid: the CID bytes or multibase-encoded string\n            :type cid: :obj:`str` or :obj:`~multiformats.varint.BytesLike`\n\n            :raises ValueError: if the CID is malformed or the CID version is unsupported\n            :raises KeyError: if the multibase, multicodec or multihash are unknown\n\n        '
    if isinstance(cid, str):
        (cid, mb) = _binary_cid_from_str(cid)
    else:
        mb = multibase.get('base58btc')
    validate(cid, BytesLike)
    cid = memoryview(cid)
    if ((len(cid) == 34) and (cid[0] == 18) and (cid[1] == 32)):
        v = 0
        mc_code = 112
        digest = cid
    else:
        (v, _, cid) = varint.decode_raw(cid)
        if (v == 0):
            raise ValueError('CIDv0 is malformed.')
        if (v in (2, 3)):
            raise ValueError('CID versions 2 and 3 are reserved for future use.')
        if (v != 1):
            raise ValueError(f'CIDv{v} is currently not supported.')
        (mc_code, _, cid) = multicodec.unwrap_raw(cid)
        digest = cid
    mc = multicodec.get(code=mc_code)
    (mh_code, _) = multihash.unwrap_raw(digest)
    mh = multihash.get(code=mh_code)
    return CID._new_instance(CID, mb, v, mc, mh, digest)