Key

Cryptographic keys that could be used in address generation and transaction signing.

class pycardano.key.Key(payload: bytes, key_type: Optional[str] = None, description: Optional[str] = None)

Bases: CBORSerializable

A class that holds a cryptographic key and some metadata. e.g. signing key, verification key.

KEY_TYPE = ''
DESCRIPTION = ''
property payload: bytes
property key_type: str
property description: str
to_primitive() bytes

Convert the instance and its elements to CBOR primitives recursively.

Returns:

A CBOR primitive.

Return type:

Primitive

Raises:

SerializeException – When the object or its elements could not be converted to CBOR primitive types.

classmethod from_primitive(value: bytes) Key

Turn a CBOR primitive to its original class type.

Parameters:
  • cls (CBORBase) – The original class type.

  • value (Primitive) – A CBOR primitive.

Returns:

A CBOR serializable object.

Return type:

CBORBase

Raises:

DeserializeException – When the object could not be restored from primitives.

to_json() str

Serialize the key to JSON.

The json output has three fields: “type”, “description”, and “cborHex”.

Returns:

JSON representation of the key.

Return type:

str

classmethod from_json(data: str, validate_type=False) Key

Restore a key from a JSON string.

Parameters:
  • data (str) – JSON string.

  • validate_type (bool) – Checks whether the type specified in json object is the same as the class’s default type.

Returns:

The key restored from JSON.

Return type:

Key

Raises:

InvalidKeyTypeException – When validate_type=True and the type in json is not equal to the default type of the Key class used.

save(path: str)
classmethod load(path: str)
class pycardano.key.ExtendedSigningKey(payload: bytes, key_type: Optional[str] = None, description: Optional[str] = None)

Bases: Key

sign(data: bytes) bytes
to_verification_key() ExtendedVerificationKey
classmethod from_hdwallet(hdwallet: HDWallet) ExtendedSigningKey
class pycardano.key.ExtendedVerificationKey(payload: bytes, key_type: Optional[str] = None, description: Optional[str] = None)

Bases: Key

hash() VerificationKeyHash

Compute a blake2b hash from the key, excluding chain code

Returns:

Hash output in bytes.

Return type:

VerificationKeyHash

classmethod from_signing_key(key: ExtendedSigningKey) ExtendedVerificationKey
to_non_extended() VerificationKey

Get the 32-byte verification with chain code trimmed off

Returns:

32-byte verification with chain code trimmed off

Return type:

VerificationKey

class pycardano.key.VerificationKey(payload: bytes, key_type: Optional[str] = None, description: Optional[str] = None)

Bases: Key

hash() VerificationKeyHash

Compute a blake2b hash from the key

Returns:

Hash output in bytes.

Return type:

VerificationKeyHash

classmethod from_signing_key(key: SigningKey) VerificationKey
class pycardano.key.SigningKey(payload: bytes, key_type: Optional[str] = None, description: Optional[str] = None)

Bases: Key

sign(data: bytes) bytes
to_verification_key() VerificationKey
classmethod generate() SigningKey
class pycardano.key.PaymentExtendedSigningKey(payload: bytes, key_type: Optional[str] = None, description: Optional[str] = None)

Bases: ExtendedSigningKey

KEY_TYPE = 'PaymentExtendedSigningKeyShelley_ed25519_bip32'
DESCRIPTION = 'Payment Signing Key'
class pycardano.key.PaymentExtendedVerificationKey(payload: bytes, key_type: Optional[str] = None, description: Optional[str] = None)

Bases: ExtendedVerificationKey

KEY_TYPE = 'PaymentExtendedVerificationKeyShelley_ed25519_bip32'
DESCRIPTION = 'Payment Verification Key'
class pycardano.key.PaymentSigningKey(payload: bytes, key_type: Optional[str] = None, description: Optional[str] = None)

Bases: SigningKey

KEY_TYPE = 'PaymentSigningKeyShelley_ed25519'
DESCRIPTION = 'Payment Signing Key'
class pycardano.key.PaymentVerificationKey(payload: bytes, key_type: Optional[str] = None, description: Optional[str] = None)

Bases: VerificationKey

KEY_TYPE = 'PaymentVerificationKeyShelley_ed25519'
DESCRIPTION = 'Payment Verification Key'
class pycardano.key.PaymentKeyPair(signing_key: SigningKey, verification_key: VerificationKey)

Bases: object

classmethod generate() PaymentKeyPair
classmethod from_signing_key(signing_key: SigningKey) PaymentKeyPair
class pycardano.key.StakeExtendedSigningKey(payload: bytes, key_type: Optional[str] = None, description: Optional[str] = None)

Bases: ExtendedSigningKey

KEY_TYPE = 'StakeExtendedSigningKeyShelley_ed25519_bip32'
DESCRIPTION = 'Stake Signing Key'
class pycardano.key.StakeExtendedVerificationKey(payload: bytes, key_type: Optional[str] = None, description: Optional[str] = None)

Bases: ExtendedVerificationKey

KEY_TYPE = 'StakeExtendedVerificationKeyShelley_ed25519_bip32'
DESCRIPTION = 'Stake Verification Key'
class pycardano.key.StakeSigningKey(payload: bytes, key_type: Optional[str] = None, description: Optional[str] = None)

Bases: SigningKey

KEY_TYPE = 'StakeSigningKeyShelley_ed25519'
DESCRIPTION = 'Stake Signing Key'
class pycardano.key.StakeVerificationKey(payload: bytes, key_type: Optional[str] = None, description: Optional[str] = None)

Bases: VerificationKey

KEY_TYPE = 'StakeVerificationKeyShelley_ed25519'
DESCRIPTION = 'Stake Verification Key'
class pycardano.key.StakeKeyPair(signing_key: SigningKey, verification_key: VerificationKey)

Bases: object

classmethod generate() StakeKeyPair
classmethod from_signing_key(signing_key: SigningKey) StakeKeyPair
class pycardano.key.StakePoolSigningKey(payload: bytes, key_type: Optional[str] = None, description: Optional[str] = None)

Bases: SigningKey

KEY_TYPE = 'StakePoolSigningKey_ed25519'
DESCRIPTION = 'Stake Pool Operator Signing Key'
class pycardano.key.StakePoolVerificationKey(payload: bytes, key_type: Optional[str] = None, description: Optional[str] = None)

Bases: VerificationKey

KEY_TYPE = 'StakePoolVerificationKey_ed25519'
DESCRIPTION = 'Stake Pool Operator Verification Key'
class pycardano.key.StakePoolKeyPair(signing_key: SigningKey, verification_key: VerificationKey)

Bases: object

classmethod generate() StakePoolKeyPair
classmethod from_signing_key(signing_key: SigningKey) StakePoolKeyPair