Skip to content

aea.helpers.cid

Utils to support multiple CID versions.

Original implementation: https://github.com/ipld/py-cid/

BaseCID Objects

class BaseCID()

Base CID object.

__init__

def __init__(version: int, codec: str, multihash: bytes)

Creates a new CID object.

version

@property
def version() -> int

CID version

codec

@property
def codec() -> str

CID codec

multihash

@property
def multihash() -> bytes

CID multihash

buffer

@property
@abstractmethod
def buffer() -> bytes

Multihash buffer.

encode

@abstractmethod
def encode(encoding: str = DEFAULT_ENCODING) -> bytes

Encode multihash.

__repr__

def __repr__() -> str

Object representation.

__str__

def __str__() -> str

String representation.

__eq__

def __eq__(other: object) -> bool

Dunder to check object equivalence.

CIDv0 Objects

class CIDv0(BaseCID)

CID version 0 object

__init__

def __init__(multihash: bytes) -> None

Initialize object.

buffer

@property
def buffer() -> bytes

The raw representation that will be encoded.

encode

def encode(encoding: str = DEFAULT_ENCODING) -> bytes

base58-encoded buffer

to_v1

def to_v1() -> "CIDv1"

Get an equivalent CIDv1 object.

CIDv1 Objects

class CIDv1(BaseCID)

CID version 1 object

__init__

def __init__(codec: str, multihash: bytes) -> None

Initialize object.

buffer

@property
def buffer() -> bytes

The raw representation of the CID

encode

def encode(encoding: str = DEFAULT_ENCODING) -> bytes

Encoded version of the raw representation

to_v0

def to_v0() -> CIDv0

Get an equivalent CIDv0 object.

CID Objects

class CID()

CID class.

make

@classmethod
def make(cls, version: int, codec: str, multihash: bytes) -> CIDObject

Make CID from given arguments.

is_cid

@classmethod
def is_cid(cls, cid: str) -> bool

Checks if a given input string is valid encoded CID or not.

from_string

@classmethod
def from_string(cls, cid: str) -> CIDObject

Creates a CID object from a encoded form

from_bytes

@classmethod
def from_bytes(cls, cid: bytes) -> CIDObject

Creates a CID object from a encoded form

to_v0

def to_v0(hash_string: str) -> str

Convert CID v1 hash to CID v0

to_v1

def to_v1(hash_string: str, encoding: str = DEFAULT_ENCODING) -> str

Convert CID v0 hash to CID v1