Skip to content

bovine.crypto.multibase

MultiCodec

Bases: Enum

The used Multicodec prefixes

Source code in bovine/bovine/crypto/multibase.py
class MultiCodec(Enum):
    """The used Multicodec prefixes"""

    Ed25519Public = b"\xed\x01"
    EcP256Public = b"\x80$"
    EcP384Public = b"\x81\x24"
    RsaPublic = b"\x85$"

    Ed25519Private = b"\x80\x26"
    EcP256Private = b"\x86\x26"

multibase_58btc_encode(data)

Encodes data in base 58 using the bitcoin alphabet and adds the prefix z

Source code in bovine/bovine/crypto/multibase.py
def multibase_58btc_encode(data: bytes) -> str:
    """Encodes `data` in base 58 using the bitcoin alphabet
    and adds the prefix `z`"""
    return "z" + based58.b58encode(data).decode("utf-8")

multibase_decode(data)

Decodes the string data using the multibase algorithm

Parameters:

Name Type Description Default
data str

The string to decode

required

Returns:

Type Description
bytes

The bytes

Source code in bovine/bovine/crypto/multibase.py
def multibase_decode(data: str) -> bytes:
    """Decodes the string data using the multibase algorithm

    :param data: The string to decode
    :return: The bytes"""
    if data[0] == "z":
        return based58.b58decode(data[1:].encode("utf-8"))

    raise ValueError(f"{data} encoded in unknown format")