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: pycardano.serialization.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) pycardano.key.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) pycardano.key.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: pycardano.key.Key

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

Bases: pycardano.key.Key

hash() pycardano.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: pycardano.key.ExtendedSigningKey) pycardano.key.ExtendedVerificationKey
to_non_extended() pycardano.key.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: pycardano.key.Key

hash() pycardano.hash.VerificationKeyHash

Compute a blake2b hash from the key

Returns

Hash output in bytes.

Return type

VerificationKeyHash

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

Bases: pycardano.key.Key

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

Bases: pycardano.key.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: pycardano.key.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: pycardano.key.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: pycardano.key.VerificationKey

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

Bases: object

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

Bases: pycardano.key.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: pycardano.key.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: pycardano.key.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: pycardano.key.VerificationKey

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

Bases: object

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

Bases: pycardano.key.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: pycardano.key.VerificationKey

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

Bases: object

classmethod generate() pycardano.key.StakePoolKeyPair
classmethod from_signing_key(signing_key: pycardano.key.SigningKey) pycardano.key.StakePoolKeyPair