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 an 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 (
str
|int
) – multihash code or name- Return type:
- 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_obj – PEP 452 compatible hashing object
- Return type:
- Returns:
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)#
- copy()#
Create a copy of this hash object
- Return type:
- Returns:
Copy of the object
- hexdigest()#
Get the current data as hex-encoded digest
- Return type:
- Returns:
the hex-encoded current data
- update(data)#
Extend the hash with data
- Parameters:
data (
bytes
) – data to concatenate to the existing data
- property block_size#
- property digest_size#
- name = 'identity'#
identifier for the hashing function
- momotor.rpc.hash.identity.new(data=None)#
Create a identity hash object
- Parameters:
data (
bytes
|memoryview
|None
) – initial data for the hash- Return type:
- Returns:
the identity hash object
- momotor.rpc.hash.identity.digest_size = None#
Digest size is variable