Skip to content

Signer

Signer Base Class

Signer

The Signer class

This is an abstract base class that is used for signing transactions and messages.

__init__(self) -> None special

Source code in flow_py_sdk/signer/signer.py
def __init__(self) -> None:
    super().__init__()

sign(self, message: bytes, tag: Optional[bytes] = None) -> bytes

The sign method signs a message with a tag and returns the signature

Parameters

message : bytes The message to sign. tag : str The tag to sign with.

Returns

bytes The signed message.

Source code in flow_py_sdk/signer/signer.py
@abstractmethod
def sign(self, message: bytes, tag: Optional[bytes] = None) -> bytes:
    """The sign method signs a message with a tag and returns the signature

    Parameters
    ----------
    message : bytes
        The message to sign.
    tag : str
        The tag to sign with.

    Returns
    -------
    bytes
        The signed message.

    """
    pass

sign_transaction(self, message: bytes) -> bytes

The sign_user_message method signs a message with the transaction tag and returns the signature

Used to sign user messages

Parameters

message : bytes The message to sign.

Returns

bytes The signed message.

Source code in flow_py_sdk/signer/signer.py
def sign_transaction(self, message: bytes) -> bytes:
    """The sign_user_message method signs a message with the transaction tag and returns the signature

    Used to sign user messages

    Parameters
    ----------
    message : bytes
        The message to sign.

    Returns
    -------
    bytes
        The signed message.

    """
    return self.sign(message, TransactionDomainTag)

sign_user_message(self, message: bytes) -> bytes

The sign_user_message method signs a message with the user tag and returns the signature

Used to sign user messages

Parameters

message : int The message to sign.

Returns

bytes The signed message.

Source code in flow_py_sdk/signer/signer.py
def sign_user_message(self, message: bytes) -> bytes:
    """The sign_user_message method signs a message with the user tag and returns the signature

    Used to sign user messages

    Parameters
    ----------
    message : int
        The message to sign.

    Returns
    -------
    bytes
        The signed message.

    """
    return self.sign(message, UserDomainTag)

In Memory signer Implementation

InMemorySigner

__init__(self, *, hash_algo: HashAlgo, sign_algo: SignAlgo, private_key_hex: str) -> None special

Source code in flow_py_sdk/signer/in_memory_signer.py
def __init__(
    self, *, hash_algo: HashAlgo, sign_algo: SignAlgo, private_key_hex: str
) -> None:
    super().__init__()
    self.hash_algo = hash_algo
    self.key = ecdsa.SigningKey.from_string(
        bytes.fromhex(private_key_hex), curve=sign_algo.get_signing_curve()
    )
    self.verifier = InMemoryVerifier(
        hash_algo=hash_algo,
        sign_algo=sign_algo,
        public_key_hex=self.key.get_verifying_key().to_string().hex(),
    )

sign(self, message: bytes, tag: Optional[bytes] = None) -> bytes

The sign method signs a message with a tag and returns the signature

Parameters

message : bytes The message to sign. tag : str The tag to sign with.

Returns

bytes The signed message.

Source code in flow_py_sdk/signer/in_memory_signer.py
def sign(self, message: bytes, tag: Optional[bytes] = None) -> bytes:
    hash_ = self._hash_message(message, tag)
    return self.key.sign_digest_deterministic(hash_)

verify(self, signature: bytes, message: bytes, tag: bytes) -> bool

The verify method signs a message with a tag and returns the signature

Parameters

signature : bytes The signature to verify. message : bytes The message to verify. tag : str The tag to verify.

Returns

bool Is the signature valid.

Source code in flow_py_sdk/signer/in_memory_signer.py
def verify(self, signature: bytes, message: bytes, tag: bytes) -> bool:
    return self.verifier.verify(signature, message, tag)