AuxiliaryData

class cometa.auxiliary_data.auxiliary_data.AuxiliaryData(ptr=None)[source]

Bases: object

Represents auxiliary data that can be attached to a Cardano transaction.

Auxiliary data encapsulates optional information such as transaction metadata and scripts. The auxiliary data is hashed and referenced in the transaction body.

Example

>>> aux_data = AuxiliaryData()
>>> metadata = TransactionMetadata()
>>> metadata.insert(721, nft_metadatum)
>>> aux_data.set_metadata(metadata)
__init__(ptr=None)[source]
Return type:

None

__enter__()[source]
Return type:

AuxiliaryData

__exit__(exc_type, exc_val, exc_tb)[source]
Return type:

None

__repr__()[source]

Return repr(self).

Return type:

str

classmethod from_cbor(reader)[source]

Deserializes AuxiliaryData from CBOR data.

Parameters:

reader (CborReader) – A CborReader positioned at the auxiliary data.

Returns:

A new AuxiliaryData deserialized from the CBOR data.

Raises:

CardanoError – If deserialization fails.

Return type:

AuxiliaryData

Note

The original CBOR encoding is cached internally to ensure that re-serialization produces identical bytes, preserving the hash and any existing signatures.

property metadata: TransactionMetadata | None

Retrieves the transaction metadata from this auxiliary data.

Returns:

The TransactionMetadata, or None if no metadata is present.

set_metadata(metadata)[source]

Sets or removes the transaction metadata.

Parameters:

metadata (TransactionMetadata | None) – The TransactionMetadata to set, or None to remove existing metadata.

Raises:

CardanoError – If the operation fails.

Return type:

None

Example

>>> aux_data.set_metadata(TransactionMetadata())
to_hash()[source]

Computes the hash of this auxiliary data.

The hash is used in the transaction body to reference the auxiliary data.

Returns:

The Blake2b-256 hash of the auxiliary data.

Raises:

CardanoError – If hashing fails.

Return type:

Blake2bHash

to_cbor(writer)[source]

Serializes the auxiliary data to CBOR format.

If this object was created via from_cbor(), the original CBOR encoding is reused to preserve the hash.

Parameters:

writer (CborWriter) – A CborWriter to write the serialized data to.

Raises:

CardanoError – If serialization fails.

Return type:

None

clear_cbor_cache()[source]

Clears the cached CBOR encoding.

After calling this, to_cbor() will generate a new encoding based on the current state rather than reusing the original bytes.

Return type:

None

to_cip116_json(writer)[source]

Serializes this auxiliary data to CIP-116 compliant JSON.

Parameters:

writer (JsonWriter) – The JsonWriter to write the JSON to.

Raises:

CardanoError – If serialization fails.

Return type:

None