Signer#

BaseSigner interface#

class starknet_py.net.signer.BaseSigner#

Base class for transaction signer. Implement methods from this ABC to use a custom signer in Account.

abstract sign_message(typed_data: TypedData, account_address: int) List[int]#

Sign TypedData object for off-chain usage with the Starknet private key and return the signature. This adds a message prefix, so it can’t be interchanged with transactions.

Parameters:
  • typed_data – TypedData to be signed.

  • account_address – account address.

Returns:

the signature of the JSON object.

abstract sign_transaction(transaction: AccountTransaction) List[int]#

Sign execute transaction and return a signature

Parameters:

transaction – Execute transaction to sign

Returns:

transaction signature

abstract property public_key: int#

Public key of the signer.

Returns:

public key

BaseSigner default implementation#

By default, starknet.py uses StarkCurveSigner which works with OpenZeppelin’s account contract.

class starknet_py.net.signer.stark_curve_signer.StarkCurveSigner#
__init__(account_address: int | str, key_pair: KeyPair, chain_id: StarknetChainId | int)#
Parameters:
  • account_address – Address of the account contract.

  • key_pair – Key pair of the account contract.

  • chain_id – ChainId of the chain.

sign_message(typed_data: TypedData, account_address: int) List[int]#

Sign TypedData object for off-chain usage with the Starknet private key and return the signature. This adds a message prefix, so it can’t be interchanged with transactions.

Parameters:
  • typed_data – TypedData to be signed.

  • account_address – account address.

Returns:

the signature of the JSON object.

sign_transaction(transaction: AccountTransaction) List[int]#

Sign execute transaction and return a signature

Parameters:

transaction – Execute transaction to sign

Returns:

transaction signature

property private_key: int#

Private key of the signer.

property public_key: int#

Public key of the signer.

Returns:

public key

KeyPair#

class starknet_py.net.signer.stark_curve_signer.KeyPair#

KeyPair(private_key: Union[int, str], public_key: Union[int, str])

__init__(private_key: int | str, public_key: int | str)#
static from_keystore(path: str, password: str) KeyPair#

Create a key pair from a keystore file. The keystore file should follow the Ethereum keystore format.

Parameters:
  • path – Path to the keystore file.

  • password – Password to decrypt the keystore file.

Returns:

KeyPair object.

static from_private_key(key: int | str) KeyPair#
static generate() KeyPair#

Create a key pair from a randomly generated private key.

Returns:

KeyPair object.

private_key: int#
public_key: int#

Warning

Not Audited: The KeyPair.generate() function has not been audited for cryptographic security. Use at your own risk.

LedgerSigner#

To use LedgerSigner, you need to install starknetpy with ledger extra like this:

poetry add starknet_py[ledger]

Under a Debian or Ubuntu based system, you will need to install additional packages:

sudo apt install python3-dev libusb-1.0-0-dev libudev-dev

They are needed for compiling HIDAPI. Read official ledgerctl installation guide for more details.

class starknet_py.net.signer.ledger_signer.LedgerSigner#
__init__(chain_id: StarknetChainId | int, account_id: int = 0, application_name: str = 'LedgerW', signing_mode: LedgerSigningMode = LedgerSigningMode.CLEAR)#
Parameters:
  • chain_id – Chain ID.

  • account_id – ID of Ledger account. First account is 0, and incrementing on more accounts.

  • application_name – Name of the application, which is part of ERC2645 derivation path.

  • signing_mode – Signing mode (clear or blind).

sign_message(typed_data: TypedData, account_address: int) List[int]#

Sign TypedData object for off-chain usage with the Starknet private key and return the signature. This adds a message prefix, so it can’t be interchanged with transactions.

Parameters:
  • typed_data – TypedData to be signed.

  • account_address – account address.

Returns:

the signature of the JSON object.

sign_transaction(transaction: AccountTransaction) List[int]#

Sign execute transaction and return a signature

Parameters:

transaction – Execute transaction to sign

Returns:

transaction signature

property public_key: int#

Public key of the signer.

Returns:

public key

LedgerSigningMode#

class starknet_py.net.signer.ledger_signer.LedgerSigningMode#

Enum representing signing modes for Ledger

BLIND = 'blind'#

Device omits transaction details and simply asks for your signature, preventing you from verifying the contents and leaving you vulnerable to unknowingly authorizing malicious or unintended actions. ⚠️ Use at your own risk.

CLEAR = 'clear'#

Device displays the full transaction payload (amounts, addresses, data) so you can review and explicitly approve exactly what you’re signing.

EthSigner#

Signer compatible with the Ethereum signature.

class starknet_py.net.signer.eth_signer.EthSigner#
__init__(private_key: int | str, chain_id: StarknetChainId | int)#
sign_message(typed_data: TypedData, account_address: int) List[int]#

Sign TypedData object for off-chain usage with the Starknet private key and return the signature. This adds a message prefix, so it can’t be interchanged with transactions.

Parameters:
  • typed_data – TypedData to be signed.

  • account_address – account address.

Returns:

the signature of the JSON object.

sign_transaction(transaction: AccountTransaction) List[int]#

Sign execute transaction and return a signature

Parameters:

transaction – Execute transaction to sign

Returns:

transaction signature

property public_key: int#

Public key of the signer.

Returns:

public key