client.keys.ecdsa module

class factom_did.client.keys.ecdsa.ECDSASecp256k1Key(public_key=None, private_key=None)

Bases: object

Representation of an ECDSASecp256k1 key. Instances of this class allow signing of messages and signature verification, as well as key creation and derivation of a public key from a private key.

ON_CHAIN_PUB_KEY_NAME = 'publicKeyBase58'
get_public_key_on_chain_repr()
private_key
public_key
sign(message, hash_f=<built-in function openssl_sha256>)

Signs a message with the existing private key and signature type.

The message is hashed before being signed, with the provided hash function. The default hash function used is SHA-256.

Parameters:
  • message (bytes) – The message to sign.
  • hash_f (function, optional) – The hash function used to compute the digest of the message before signing it.
Returns:

The bytes of the signatures.

Return type:

bytes

Raises:

AssertionError – If the supplied message is not bytes, or if a private key has not been specified.

verify(message, signature, hash_f=<built-in function openssl_sha256>)

Verifies the signature of the given message

Parameters:
  • message (bytes) – The (allegedly) signed message.
  • signature (bytes) – The signature to verify.
  • hash_f (function, optional) – The hash function used to compute the digest of the message.
Returns:

True if the signature is successfully verified, False otherwise.

Return type:

bool