ETHSigner
Overview of account functionalities in the ZKsync Python SDK.
The ZKsync Python SDK has a method that generates a signature and a method that verifies messages.
For constructing the instance it needs only
account
and chain_id
.Key features
- Wallet Management: Create and manage wallets using private keys.
- Transaction Signing: Sign transactions using EIP712-typed data, ensuring secure and verifiable transactions.
- Signature Verification: Verify signed transactions to ensure authenticity and integrity.
Core components
- sign_typed_data
- Method to sign EIP712-typed ZKsync transactions, ensuring standardized and secure transaction formatting.
- verify_typed_data
- Method to verify the signed EIP712-typed ZKsync transactions, ensuring that the transactions are authentic and have not been tampered with.
Example
from zksync2.signer.eth_signer import PrivateKeyEthSigner
from eth_account import Account
from zksync2.module.module_builder import ZkSyncBuilder
account = Account.from_key("PRIVATE_KEY")
zksync_web3 = ZkSyncBuilder.build("ZKSYNC_NETWORK_URL")
chain_id = zksync_web3.zksync.chain_id
signer = PrivateKeyEthSigner(account, chain_id)
sign_typed_data
The signer is used to generate the signature of the provided transaction based on your account(your private key).
Parameters
Parameters | Return value | Description |
---|---|---|
EIP712 Structure, optional domain | Web3 py SignedMessage | Builds SignedMessage based on the encoded in EIP712 format Transaction. |
verify_typed_data
It's used to verify the provided transaction, whose signature is added to the final EIP712
transaction for its validation.
Parameters
Parameters | Return value | Description |
---|---|---|
signature, EIP712 structure, optional domain | bool | Returns True if the encoded transaction is signed with provided signature. |
The signer class also has the following properties:
Attribute | Description |
---|---|
address | Account address |
domain | Domain that is used to generate signature. It depends on chain_id of network. |
get_default_domain
Represents the domain parameters used for EIP-712 signing.
Inputs
Parameter | Type | Description |
---|---|---|
chain_id | int | The chain id used for generating domain. |
Example
from zksync2.signer.eth_signer import PrivateKeyEthSigner
from zksync2.module.module_builder import ZkSyncBuilder
zksync_web3 = ZkSyncBuilder.build("ZKSYNC_NETWORK_URL")
chain_id = zksync_web3.zksync.chain_id
domain = PrivateKeyEthSigner.get_default_domain(chain_id)