Credential
- class cometa.common.credential.Credential(ptr)[source]
Bases:
objectRepresents a credential used in Cardano addresses.
- A credential identifies the owner of funds or staking rights. It can be either:
A key hash (hash of a public verification key)
A script hash (hash of a Plutus or native script)
- Credentials are used in:
Payment credentials (who can spend funds)
Staking credentials (who controls staking rights)
- classmethod from_hash(hash_value, credential_type)[source]
Creates a credential from a hash and credential type.
- Parameters:
hash_value (Blake2bHash) – The Blake2b hash (key hash or script hash).
credential_type (CredentialType) – The credential type (KEY_HASH or SCRIPT_HASH).
- Returns:
A new Credential instance.
- Raises:
CardanoError – If credential creation fails.
- Return type:
Example
>>> h = Blake2bHash.from_hex("00" * 28) >>> cred = Credential.from_hash(h, CredentialType.KEY_HASH)
- classmethod from_key_hash(hash_value)[source]
Creates a key hash credential.
- Parameters:
hash_value (Blake2bHash | str | bytes) – The key hash as a Blake2bHash, hex string, or bytes.
- Returns:
A new Credential with type KEY_HASH.
- Raises:
CardanoError – If credential creation fails.
- Return type:
Example
>>> cred = Credential.from_key_hash("00" * 28)
- classmethod from_script_hash(hash_value)[source]
Creates a script hash credential.
- Parameters:
hash_value (Blake2bHash | str | bytes) – The script hash as a Blake2bHash, hex string, or bytes.
- Returns:
A new Credential with type SCRIPT_HASH.
- Raises:
CardanoError – If credential creation fails.
- Return type:
Example
>>> cred = Credential.from_script_hash("00" * 28)
- classmethod from_hex(hex_string, credential_type)[source]
Creates a credential from a hexadecimal hash string.
- Parameters:
hex_string (str) – The hexadecimal representation of the hash.
credential_type (CredentialType) – The credential type.
- Returns:
A new Credential instance.
- Raises:
CardanoError – If the hex string is invalid.
- Return type:
Example
>>> cred = Credential.from_hex("00" * 28, CredentialType.KEY_HASH)
- classmethod from_bytes(data, credential_type)[source]
Creates a credential from raw hash bytes.
- Parameters:
data (bytes | bytearray) – The raw hash bytes.
credential_type (CredentialType) – The credential type.
- Returns:
A new Credential instance.
- Raises:
CardanoError – If credential creation fails.
- Return type:
Example
>>> cred = Credential.from_bytes(bytes(28), CredentialType.KEY_HASH)
- classmethod from_cbor(reader)[source]
Deserializes a Credential from CBOR data.
- Parameters:
reader (CborReader) – A CborReader positioned at the credential data.
- Returns:
A new Credential deserialized from the CBOR data.
- Raises:
CardanoError – If deserialization fails.
- Return type:
- property type: CredentialType
Returns the credential type (KEY_HASH or SCRIPT_HASH).
- property hash: Blake2bHash
Returns the underlying hash as a Blake2bHash object.
- property hash_bytes: bytes
Returns the hash as raw bytes.
- property hash_hex: str
Returns the hash as a hexadecimal string.
- property is_key_hash: bool
Returns True if this is a key hash credential.
- property is_script_hash: bool
Returns True if this is a script hash credential.
- to_cbor(writer)[source]
Serializes the credential to CBOR format.
- Parameters:
writer (CborWriter) – A CborWriter to write the serialized data to.
- Raises:
CardanoError – If serialization fails.
- Return type:
None
- to_cip116_json(writer)[source]
Converts this object to CIP-116 compliant JSON representation.
CIP-116 defines a standard JSON format for Cardano data structures.
- Parameters:
writer (JsonWriter) – A JsonWriter to write the serialized data to.
- Raises:
CardanoError – If conversion fails.
- Return type:
None
- compare(other)[source]
Compares this credential with another credential.
- Parameters:
other (Credential) – The credential to compare with.
- Returns:
A negative value if this credential is less than other, zero if they are equal, a positive value if this credential is greater than other.
- Return type:
int
- __eq__(other)[source]
Checks equality with another Credential.
- Parameters:
other (object)
- Return type:
bool
- __lt__(other)[source]
Less than comparison.
- Parameters:
other (Credential)
- Return type:
bool
- __le__(other)[source]
Less than or equal comparison.
- Parameters:
other (Credential)
- Return type:
bool
- __gt__(other)[source]
Greater than comparison.
- Parameters:
other (Credential)
- Return type:
bool
- __ge__(other)[source]
Greater than or equal comparison.
- Parameters:
other (Credential)
- Return type:
bool