cosmpy.crypto package — cosmpy documentation

# cosmpy.crypto package

## Submodules

## cosmpy.crypto.address module

Address of the Crypto package.

class cosmpy.crypto.address.Address(value: Union[str, bytes, cosmpy.crypto.keypairs.PublicKey, cosmpy.crypto.address.Address], prefix: Optional[str] = None)

  Bases: `object`

  Address class.

## cosmpy.crypto.hashfuncs module

Hash functions of Crypto package.

cosmpy.crypto.hashfuncs.ripemd160(contents: bytes) → bytes

  Get ripemd160 hash.

  Parameters

    contents – bytes contents.

  Returns

    bytes ripemd160 hash.

cosmpy.crypto.hashfuncs.sha256(contents: bytes) → bytes

  Get sha256 hash.

  Parameters

    contents – bytes contents.

  Returns

    bytes sha256 hash.

## cosmpy.crypto.interface module

Interface for a Signer.

class cosmpy.crypto.interface.Signer

  Bases: `abc.ABC`

  Signer abstract class.

  abstract sign(message: bytes, deterministic=False, canonicalise: bool = True) → bytes

    Perform signing.

  abstract sign_digest(digest: bytes, deterministic=False, canonicalise: bool = True) → bytes

    Perform digest signing.

## cosmpy.crypto.keypairs module

Crypto KeyPairs (Public Key and Private Key).

class cosmpy.crypto.keypairs.PrivateKey(private_key: Optional[bytes] = None)

  Bases: `cosmpy.crypto.keypairs.PublicKey`, `cosmpy.crypto.interface.Signer`

  Private key class.

  property private_key: str

    Get private key.

    Returns

      str private key.

  property private_key_bytes: bytes

    Get bytes private key.

    Returns

      bytes private key.

  property private_key_hex: str

    Get private key hex.

    Returns

      str private key hex.

  sign(message: bytes, deterministic: bool = True, canonicalise: bool = True) → bytes

    Sign message.

    Parameters

      - message – bytes message content.

      - deterministic – bool is deterministic.

      - canonicalise – bool is canonicalise.

    Returns

      bytes signed message.

  sign_digest(digest: bytes, deterministic=True, canonicalise: bool = True) → bytes

    Sign digest.

    Parameters

      - digest – bytes digest content.

      - deterministic – bool is deterministic.

      - canonicalise – bool is canonicalise.

    Returns

      bytes signed digest.

class cosmpy.crypto.keypairs.PublicKey(public_key: Union[bytes, cosmpy.crypto.keypairs.PublicKey, ecdsa.keys.VerifyingKey])

  Bases: `object`

  Public key class.

  curve: ecdsa.curves.Curve = SECP256k1
  hash_function(*, usedforsecurity=True)

    Returns a sha256 hash object; optionally initialized with a string

  property public_key: str

    Get public key.

    Returns

      str public key.

  property public_key_bytes: bytes

    Get bytes public key.

    Returns

      bytes public key.

  property public_key_hex: str

    Get public key hex.

    Returns

      str public key hex.

  verify(message: bytes, signature: bytes) → bool

    Verify message and signature.

    Parameters

      - message – bytes message content.

      - signature – bytes signature.

    Returns

      bool is message and signature valid.

  verify_digest(digest: bytes, signature: bytes) → bool

    Verify digest.

    Parameters

      - digest – bytes digest.

      - signature – bytes signature.

    Returns

      bool is digest valid.

## Module contents

This package contains the Crypto modules.