sawtooth_signing package

Submodules

sawtooth_signing.core module

exception sawtooth_signing.core.NoSuchAlgorithmError[source]

Bases: Exception

Thrown when trying to create an algorithm which does not exist.

exception sawtooth_signing.core.SigningError[source]

Bases: Exception

Thrown when an error occurs during the signing process.

exception sawtooth_signing.core.ParseError[source]

Bases: Exception

Thrown when an error occurs during deserialization of a Private or Public key from various formats.

class sawtooth_signing.core.PrivateKey[source]

Bases: object

A private key instance.

The underlying content is dependent on implementation.

get_algorithm_name()[source]

Returns the algorithm name used for this private key.

as_hex()[source]

Return the private key encoded as a hex string.

as_bytes()[source]

Return the private key bytes.

class sawtooth_signing.core.PublicKey[source]

Bases: object

A public key instance.

The underlying content is dependent on implementation.

get_algorithm_name()[source]

Returns the algorithm name used for this public key.

as_hex()[source]

Return the public key encoded as a hex string.

as_bytes()[source]

Return the public key bytes.

class sawtooth_signing.core.Context[source]

Bases: object

A context for a cryptographic signing algorithm.

get_algorithm_name()[source]

Returns the algorithm name.

sign(message, private_key)[source]

Sign a message

Given a private key for this algorithm, sign the given message bytes and return a hex-encoded string of the resulting signature.

Parameters:
  • message (bytes) – the message bytes
  • private_key (PrivateKey) – the private key
Returns:

The signature in a hex-encoded string

Raises:

SigningError – if any error occurs during the signing process

verify(signature, message, public_key)[source]

Verifies that a signature of a message was produced with the associated public key.

Parameters:
  • signature (str) – the hex-encoded signature
  • message (bytes) – the message bytes
  • public_key (PublicKey) – the public key to use for verification
Returns:

True if the public key is associated with the signature for that method, False otherwise

Return type:

boolean

new_random_private_key()[source]

Generates a new random PrivateKey using this context.

Returns:a random private key
Return type:(PrivateKey)
get_public_key(private_key)[source]

Produce a public key for the given private key.

Parameters:private_key (PrivateKey) – a private key
Returns:(PublicKey) the public key for the given private key

sawtooth_signing.secp256k1 module

class sawtooth_signing.secp256k1.Secp256k1PrivateKey(secp256k1_private_key)[source]

Bases: sawtooth_signing.core.PrivateKey

get_algorithm_name()[source]
as_hex()[source]
as_bytes()[source]
secp256k1_private_key
static from_hex(hex_str)[source]
static new_random()[source]
class sawtooth_signing.secp256k1.Secp256k1PublicKey(secp256k1_public_key)[source]

Bases: sawtooth_signing.core.PublicKey

secp256k1_public_key
get_algorithm_name()[source]
as_hex()[source]
as_bytes()[source]
static from_hex(hex_str)[source]
class sawtooth_signing.secp256k1.Secp256k1Context[source]

Bases: sawtooth_signing.core.Context

get_algorithm_name()[source]
sign(message, private_key)[source]
verify(signature, message, public_key)[source]
new_random_private_key()[source]
get_public_key(private_key)[source]

Module contents

class sawtooth_signing.Signer(context, private_key)[source]

Bases: object

A convenient wrapper of Context and PrivateKey

sign(message)[source]

Signs the given message

Parameters:message (bytes) – the message bytes
Returns:The signature in a hex-encoded string
Raises:SigningError – if any error occurs during the signing process
get_public_key()[source]

Return the public key for this Signer instance.

class sawtooth_signing.CryptoFactory(context)[source]

Bases: object

Factory for generating Signers.

context

Return the context that backs this factory instance

new_signer(private_key)[source]

Create a new signer for the given private key.

Parameters:private_key (PrivateKey) – a private key
Returns:a signer instance
Return type:(Signer)
sawtooth_signing.create_context(algorithm_name)[source]

Returns an algorithm instance by name.

Parameters:algorithm_name (str) – the algorithm name
Returns:a context instance for the given algorithm
Return type:(Context)
Raises:NoSuchAlgorithmError if the algorithm is unknown