nucypher.blockchain.eth.signers

Submodules

class Signer

Bases: abc.ABC

log

Drop-in replacement of Twisted’s Logger, patching the emit() method to tolerate inputs with curly braces, i.e., not compliant with PEP 3101.

See Issue #724 and, particularly, https://github.com/nucypher/nucypher/issues/724#issuecomment-600190455

exception SignerError

Bases: Exception

Base exception class for signer errors

exception InvalidSignerURI

Bases: nucypher.blockchain.eth.signers.base.Signer.SignerError

Raised when an invalid signer URI is detected

exception AccountLocked(account: str)

Bases: nucypher.blockchain.eth.signers.base.Signer.SignerError

exception UnknownAccount(account: str)

Bases: nucypher.blockchain.eth.signers.base.Signer.SignerError

abstract classmethod uri_scheme()str
classmethod from_signer_uri(uri: str, testnet: bool = False)nucypher.blockchain.eth.signers.base.Signer
abstract is_device(account: str)bool

Some signing client support both software and hardware wallets, this method is implemented as a boolean to tell the difference.

abstract property accounts
abstract unlock_account(account: str, password: str, duration: int = None)bytes
abstract lock_account(account: str)str
abstract sign_transaction(transaction_dict: dict) → hexbytes.main.HexBytes
abstract sign_message(account: str, message: bytes, **kwargs) → hexbytes.main.HexBytes
handle_trezor_call(device_func)

Decorator for calls to trezorlib that require physical device interactions.

class TrezorSigner(testnet: bool = False)

Bases: nucypher.blockchain.eth.signers.base.Signer

A trezor message and transaction signing client.

DEFAULT_ACCOUNT_INDEX = 0
ADDRESS_CACHE_SIZE = 10
exception DeviceError

Bases: Exception

Base exception for trezor signing API

exception NoDeviceDetected

Bases: nucypher.blockchain.eth.signers.hardware.TrezorSigner.DeviceError

Raised when an operation requires a device but none are available

property derivation_root
classmethod uri_scheme()str
classmethod from_signer_uri(uri: str, testnet: bool = False)nucypher.blockchain.eth.signers.hardware.TrezorSigner

Return a trezor signer from URI string i.e. trezor:///my/trezor/path

is_device(account: str)bool

Trezor is always a device.

unlock_account(account: str, password: str, duration: int = None)bool

Defer account unlocking to the trezor, do not indicate application level unlocking logic.

lock_account(account: str)bool

Defer account locking to the trezor, do not indicate application level unlocking logic.

property accounts

Returns a list of cached trezor checksum addresses from initial derivation.

sign_message(message: bytes, checksum_address: str) → hexbytes.main.HexBytes

Signs a message via the TREZOR ethereum sign_message API and returns a named tuple containing the signature and the address used to sign it. This method requires interaction between the TREZOR and the user.

sign_transaction(transaction_dict: dict, rlp_encoded: bool = True) → Union[hexbytes.main.HexBytes, eth_account._utils.transactions.Transaction]

Sign a transaction with a trezor hardware wallet.

This non-mutative method handles transaction validation, field formatting, signing, and outgoing serialization. Accepts a standard transaction dictionary as input, and produces an RLP encoded raw signed transaction by default.

Internally the standard transaction dictionary is reformatted for trezor API consumption via calls trezorlib.client.ethereum.sign_tx.

WARNING: This function returns a raw signed transaction which can be broadcast by anyone with a connection to the ethereum network.

*Treat pre-signed raw transactions produced by this function like money.*

class Web3Signer(client)

Bases: nucypher.blockchain.eth.signers.base.Signer

classmethod uri_scheme()str
classmethod from_signer_uri(uri: str, testnet: bool = False)nucypher.blockchain.eth.signers.software.Web3Signer
is_connected()bool
property accounts
is_device(account: str)

Some signing client support both software and hardware wallets, this method is implemented as a boolean to tell the difference.

unlock_account(account: str, password: str, duration: int = None)
lock_account(account: str)
sign_message(account: str, message: bytes, **kwargs) → hexbytes.main.HexBytes
sign_transaction(transaction_dict: dict) → hexbytes.main.HexBytes
class ClefSigner(ipc_path: str = '~/.clef/clef.ipc', timeout: int = 180, testnet: bool = False)

Bases: nucypher.blockchain.eth.signers.base.Signer

DEFAULT_IPC_PATH = '~/.clef/clef.ipc'
SIGN_DATA_FOR_VALIDATOR = 'data/validator'
SIGN_DATA_FOR_CLIQUE = 'application/clique'
SIGN_DATA_FOR_ECRECOVER = 'text/plain'
DEFAULT_CONTENT_TYPE = 'text/plain'
SIGN_DATA_CONTENT_TYPES = ('data/validator', 'application/clique', 'text/plain')
TIMEOUT = 180
classmethod uri_scheme()str
classmethod is_valid_clef_uri(uri: str)bool
classmethod from_signer_uri(uri: str, testnet: bool = False)nucypher.blockchain.eth.signers.software.ClefSigner
is_connected()bool
is_device(account: str)

Some signing client support both software and hardware wallets, this method is implemented as a boolean to tell the difference.

property accounts
sign_transaction(transaction_dict: dict) → hexbytes.main.HexBytes
sign_message(account: str, message: bytes, content_type: str = None, validator_address: str = None, **kwargs) → hexbytes.main.HexBytes

See https://github.com/ethereum/go-ethereum/blob/a32a2b933ad6793a2fe4172cd46c5c5906da259a/signer/core/signed_data.go#L185

sign_data_for_validator(account: str, message: bytes, validator_address: str)
unlock_account(account: str, password: str, duration: int = None)bool
lock_account(account: str)bool
class KeystoreSigner(path: str, testnet: bool = False)

Bases: nucypher.blockchain.eth.signers.base.Signer

Local Web3 signer implementation supporting keystore files

exception InvalidKeyfile

Bases: nucypher.blockchain.eth.signers.base.Signer.SignerError, RuntimeError

Raised when a keyfile is corrupt or otherwise invalid. Keystore must be in the geth wallet format.

classmethod uri_scheme()str
property path

Read only access to the keystore path

classmethod from_signer_uri(uri: str, testnet: bool = False)nucypher.blockchain.eth.signers.base.Signer

Return a keystore signer from URI string i.e. keystore:///my/path/keystore

is_device(account: str)bool

Some signing client support both software and hardware wallets, this method is implemented as a boolean to tell the difference.

property accounts

Return a list of known keystore accounts read from

unlock_account(account: str, password: str, duration: int = None)bool

Decrypt the signing material from the key metadata file and cache it on the keystore instance is decryption is successful.

lock_account(account: str)bool

Deletes a local signer by its checksum address or raises UnknownAccount if the address is not a member of this keystore. Returns True if the account is no longer tracked and was successfully locked.

sign_transaction(transaction_dict: dict) → hexbytes.main.HexBytes

Produce a raw signed ethereum transaction signed by the account specified in the ‘from’ field of the transaction dictionary.

sign_message(account: str, message: bytes, **kwargs) → hexbytes.main.HexBytes