Hash

Assets are identified by their base58 encoded hash. Momotor uses the multihash format for these hashes to support multiple hashing algorithms.

The multihash format allows to easily upgrade the hashing function in the future and only uses hashing algorithms both client and server can support.

For short content (less than MAX_IDENTITY_LENGTH bytes), the content itself is encoded as a identity hash.

Functions

momotor.rpc.hash.funcs.get_algorithm_by_code(code)

Get a PEP 452 compatible hashing object by its multihash code or name

Parameters

code (Union[str, int]) – multihash code or name

Return type

object

Returns

PEP 452 compatible hashing object

momotor.rpc.hash.funcs.get_code_by_hash_obj(hash_obj)

Get the multihash code for a PEP 452 compatible hashing object

Parameters

hash_objPEP 452 compatible hashing object

Return type

int

Returns

multihash code

Identity hash

A PEP 452 compatible implementation of an identity hashing object.

The identity hash stores the literal content as a hash:

>>> IdentityHash(b'any random data').digest() == b'any random data'
True
class momotor.rpc.hash.identity.IdentityHash(data=None)
name = 'identity'

identifier for the hashing function

update(data)

Extend the hash with data

Parameters

data (bytes) – data to concatenate to the existing data

digest()

Get the current data

Return type

bytes

Returns

the current data

hexdigest()

Get the current data as hex-encoded digest

Return type

bytes

Returns

the hex-encoded current data

copy()

Create a copy of this hash object

Return type

IdentityHash

Returns

Copy of the object

property digest_size
property block_size
momotor.rpc.hash.identity.new(data=None)

Create a identity hash object

Parameters

data (Union[bytes, memoryview, None]) – initial data for the hash

Return type

IdentityHash

Returns

the identity hash object

momotor.rpc.hash.identity.digest_size = None

Digest size is variable