-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bb4a918
commit f6ccfce
Showing
6 changed files
with
379 additions
and
57 deletions.
There are no files selected for viewing
83 changes: 26 additions & 57 deletions
83
content/sdk/30.python/02.api/01.accounts/00.introduction.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,43 @@ | ||
--- | ||
title: Introduction | ||
description: Overview of account functionalities in the ZKsync Python SDK. | ||
tags: ["web3", "blockchain", "zksync", "accounts"] | ||
description: Manage accounts and sign transactions in the ZKsync Python SDK. | ||
tags: ["zksync", "account management", "wallet creation", "transaction signing", "cryptocurrency", "ethereum"] | ||
--- | ||
|
||
The ZKsync Python SDK has a method that generates a signature and a method that verifies messages. | ||
The ZKsync Python SDK offers classes for signing ZKsync transactions: | ||
|
||
::callout{icon="i-heroicons-light-bulb"} | ||
For constructing the instance it needs only `account` and `chain_id`. | ||
:: | ||
- **`Wallet`**: Manage and sign transactions with ZKsync features. | ||
- **`EthSigner`**: Sign transactions with an Ethereum signer. | ||
- **`SmartAccount`**: Support account abstraction with factory classes: | ||
- **`ECDSASmartAccount`**: Use a single ECDSA key. | ||
- **`MultisigECDSASmartAccount`**: Use multiple ECDSA keys. | ||
|
||
### Key Features | ||
### Why use these classes? | ||
|
||
- **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. | ||
- **Smart Contract Interaction:** Deploy and interact with smart contracts using custom signing logic. | ||
They simplify ZKsync blockchain interactions by providing: | ||
|
||
### Core Components | ||
- **Security**: Securely manage private keys and sign transactions. | ||
- **Convenience**: Easily create and manage accounts with advanced features. | ||
- **Compatibility**: Extend existing libraries for seamless project integration. | ||
|
||
1. **Wallet** | ||
- A class that facilitates the creation of wallets from private keys, interaction with ZKsync and Ethereum nodes, | ||
and managing account balances. | ||
### Classes | ||
|
||
2. **sign_typed_data** | ||
- Method to sign EIP712-typed ZKsync transactions, ensuring standardized and secure transaction formatting. | ||
#### `Wallet` | ||
|
||
3. **verify_typed_data** | ||
- Method to verify the signed EIP712-typed ZKsync transactions, ensuring that the transactions are authentic and | ||
have not been tampered with. | ||
The `Wallet` class allows you to create and manage wallets, sign transactions, and interact with the ZKsync network seamlessly. | ||
|
||
#### Example | ||
#### `EthSigner` | ||
|
||
```python | ||
from zksync2.signer.eth_signer import PrivateKeyEthSigner | ||
from eth_account import Account | ||
from zksync2.module.module_builder import ZkSyncBuilder | ||
The `EthSigner` class signs ZKsync transactions using an Ethereum signer, enabling compatibility with Ethereum-based | ||
tools and workflows. | ||
|
||
#### `SmartAccount` | ||
|
||
account = Account.from_key("PRIVATE_KEY") | ||
zksync_web3 = ZkSyncBuilder.build("ZKSYNC_NETWORK_URL") | ||
The `SmartAccount` class provides better support for account abstraction, allowing for more advanced account | ||
management features. Factory classes for `SmartAccount` include: | ||
|
||
chain_id = zksync_web3.zksync.chain_id | ||
signer = PrivateKeyEthSigner(account, chain_id) | ||
- **`ECDSASmartAccount`**: Uses a single ECDSA key for signing payloads. | ||
- **`MultisigECDSASmartAccount`**: Uses multiple ECDSA keys for signing payloads. | ||
|
||
``` | ||
|
||
### 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. | | ||
These classes enhance the functionality and security of managing accounts and signing transactions on the ZKsync | ||
network using the Python SDK. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
--- | ||
title: EthSigner | ||
description: Overview of account functionalities in the ZKsync Python SDK. | ||
tags: ["web3", "ethsigner", "zksync", "accounts"] | ||
--- | ||
|
||
The ZKsync Python SDK has a method that generates a signature and a method that verifies messages. | ||
|
||
::callout{icon="i-heroicons-light-bulb"} | ||
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. | ||
- **Smart Contract Interaction:** Deploy and interact with smart contracts using custom signing logic. | ||
|
||
### Core Components | ||
|
||
1. **Wallet** | ||
- A class that facilitates the creation of wallets from private keys, interaction with ZKsync and Ethereum nodes, | ||
and managing account balances. | ||
|
||
2. **sign_typed_data** | ||
- Method to sign EIP712-typed ZKsync transactions, ensuring standardized and secure transaction formatting. | ||
|
||
3. **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 | ||
|
||
```python | ||
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 | ||
|
||
```python | ||
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) | ||
``` |
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.