Skip to main content

terra_sdk.key.key

Key Objects​


_1
class Key()

Abstract Key interface, representing an agent with transaction-signing capabilities.

Arguments:

  • public_key Optional[bytes] - compressed public key bytes,

public_key​

Compressed public key bytes, used to derive :data:raw_address and :data:raw_pubkey.

raw_address​

Raw Bech32 words of address, used to derive associated account and validator operator addresses.

raw_pubkey​

Raw Bech32 words of pubkey, used to derive associated account and validator pubkeys.

sign​


_2
@abc.abstractmethod
_2
def sign(payload: bytes) -> bytes

Signs the data payload. An implementation of Key is expected to override this method.

Arguments:

  • payload bytes - arbitrary data payload

Raises:

  • NotImplementedError - if not implemented

Returns:

  • bytes - signed payload

acc_address​


_2
@property
_2
def acc_address() -> AccAddress

Fluid Bech32 account address. Default derivation via :data:public_key is provided.

Raises:

  • ValueError - if Key was not initialized with proper public key

Returns:

  • AccAddress - account address

val_address​


_2
@property
_2
def val_address() -> ValAddress

Fluid Bech32 validator operator address. Default derivation via :data:public_key is provided.

Raises:

  • ValueError - if Key was not initialized with proper public key

Returns:

  • ValAddress - validator operator address

acc_pubkey​


_2
@property
_2
def acc_pubkey() -> AccPubKey

Fluid Bech32 account pubkey. Default derivation via :data:public_key is provided.

Raises:

  • ValueError - if Key was not initialized with proper public key

Returns:

  • AccPubKey - account pubkey

val_pubkey​


_2
@property
_2
def val_pubkey() -> ValPubKey

Fluid Bech32 validator pubkey. Default derivation via public_key is provided.

Raises:

  • ValueError - if Key was not initialized with proper public key

Returns:

  • ValPubKey - validator pubkey

create_signature​


_1
def create_signature(sign_doc: SignDoc) -> SignatureV2

Signs the transaction with the signing algorithm provided by this Key implementation, and outputs the signature. The signature is only returned, and must be manually added to the signatures field of an :class:Tx.

Arguments:

  • sign_doc SignDoc - unsigned transaction

Raises:

  • ValueError - if missing public_key

Returns:

  • SignatureV2 - signature object

sign_tx​


_1
def sign_tx(tx: Tx, options: SignOptions) -> Tx

Signs the transaction with the signing algorithm provided by this Key implementation, and creates a ready-to-broadcast :class:Tx object with the signature applied.

Arguments:

  • tx Tx - unsigned transaction
  • options SignOptions - options for signing

Returns:

  • Tx - ready-to-broadcast transaction object