Generating a Key pair#
Key pair#
The Key pair is a pair of private and public keys. The private key is used to sign transactions, and the public key is used to verify the signature.
In the starknet.py you need to use the KeyPair
class to be able to create an Account
and StarkCurveSigner
object.
Generating random key pair#
Method generate()
allows to generate cryptographically strong pseudo-random numbers
suitable for managing secrets such as account authentication, tokens, and similar.
from starknet_py.net.signer.key_pair import KeyPair
key_pair = KeyPair.generate()
Creating key pair from private Key#
To create a key pair from a private key, use the from_private_key()
method.
from starknet_py.net.signer.key_pair import KeyPair
key_pair = KeyPair.from_private_key("0x1234abcd")
Reading key pair from keystore file#
Using from_keystore()
method there is possibility to import a key pair from a keystore file.
The keystore file should follow the Ethereum keystore format.
from starknet_py.net.signer.key_pair import KeyPair
key_pair = KeyPair.from_keystore("path/to/keystore", "password")