Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Transaction Types #48

Merged
merged 26 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 36 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,42 @@ as part of the [official Web3.js plugin for ZKsync SDK docs](https://sdk.zksync.

## Plugin Components

- [RPC methods](https://sdk.zksync.io/js/web3js/rpc):
The[`RpcMethods` class](https://chainsafe.github.io/web3-plugin-zksync/classes/RpcMethods.html)
implements the [ZKsync JSON-RPC API](https://docs.zksync.io/build/api-reference/zks-rpc).
- [Constants](https://sdk.zksync.io/js/web3js/constants-types-utilities#constants): The
[`constants` package](https://chainsafe.github.io/web3-plugin-zksync/modules/constants.html)
includes well-known addresses, such as the address of the L1 ETH token.
- [Types](https://sdk.zksync.io/js/web3js/constants-types-utilities#types): The
[`types` package](https://chainsafe.github.io/web3-plugin-zksync/modules/types.html) defines
enums, interfaces, and types that are used for interacting with the ZKsync Era network.
- [Utilities](https://sdk.zksync.io/js/web3js/constants-types-utilities#utilities): The
[`utils` package](https://chainsafe.github.io/web3-plugin-zksync/modules/utils.html) exposes
helpful functions and contract definitions that can be used with the Web3.js plugin for ZKsync.
- [Wallet](https://sdk.zksync.io/js/web3js/wallet): The
[`ZKSyncWallet` class](https://chainsafe.github.io/web3-plugin-zksync/classes/ZKSyncWallet.html)
allows developers to create, manage, and use ZKsync accounts.
- [Paymasters](https://sdk.zksync.io/js/web3js/paymasters): The plugin includes a number of
helpful utilities for working with
[ZKsync paymasters](https://docs.zksync.io/build/developer-reference/account-abstraction/paymasters),
including a
[`getPaymasterParams` function](https://chainsafe.github.io/web3-plugin-zksync/functions/getPaymasterParams.html)
for generating paymaster parameters to add to a transaction.
- [Smart contracts](https://sdk.zksync.io/js/web3js/contracts): The
[`ContractFactory` class](https://chainsafe.github.io/web3-plugin-zksync/classes/ContractFactory.html)
can be used to deploy smart contracts to the ZKsync Era network. The return type of the
[`ContractFactory.deploy` method](https://chainsafe.github.io/web3-plugin-zksync/classes/ContractFactory.html#deploy)
is the standard
[Web3.js Contract class](https://docs.web3js.org/api/web3-eth-contract/class/Contract/).
- [Smart accounts](https://sdk.zksync.io/js/web3js/smart-accounts): The
[`SmartAccount` class](https://chainsafe.github.io/web3-plugin-zksync/classes/SmartAccount.html)
can be used to create
[ZKsync smart accounts](https://docs.zksync.io/build/developer-reference/account-abstraction/)
with custom logic for building and signing transactions. There are factory functions for
creating
[ECDSA smart accounts](https://chainsafe.github.io/web3-plugin-zksync/classes/ECDSASmartAccount.html#create)
and
[multi-signature ECDSA smart accounts](https://chainsafe.github.io/web3-plugin-zksync/classes/MultisigECDSASmartAccount.html#create).
- [RPC methods](https://sdk.zksync.io/js/web3js/rpc):
The[`RpcMethods` class](https://chainsafe.github.io/web3-plugin-zksync/classes/RpcMethods.html)
implements the [ZKsync JSON-RPC API](https://docs.zksync.io/build/api-reference/zks-rpc).
- [Constants](https://sdk.zksync.io/js/web3js/constants-types-utilities#constants): The
[`constants` package](https://chainsafe.github.io/web3-plugin-zksync/modules/constants.html)
includes well-known addresses, such as the address of the L1 ETH token.
- [Types](https://sdk.zksync.io/js/web3js/constants-types-utilities#types): The
[`types` package](https://chainsafe.github.io/web3-plugin-zksync/modules/types.html) defines
enums, interfaces, and types that are used for interacting with the ZKsync Era network.
- [Utilities](https://sdk.zksync.io/js/web3js/constants-types-utilities#utilities): The
[`utils` package](https://chainsafe.github.io/web3-plugin-zksync/modules/utils.html) exposes
helpful functions and contract definitions that can be used with the Web3.js plugin for ZKsync.
- [Wallet](https://sdk.zksync.io/js/web3js/wallet): The
[`ZKSyncWallet` class](https://chainsafe.github.io/web3-plugin-zksync/classes/ZKSyncWallet.html)
allows developers to create, manage, and use ZKsync accounts.
- [Paymasters](https://sdk.zksync.io/js/web3js/paymasters): The plugin includes a number of
helpful utilities for working with
[ZKsync paymasters](https://docs.zksync.io/build/developer-reference/account-abstraction/paymasters),
including a
[`getPaymasterParams` function](https://chainsafe.github.io/web3-plugin-zksync/functions/getPaymasterParams.html)
for generating paymaster parameters to add to a transaction.
- [Smart contracts](https://sdk.zksync.io/js/web3js/contracts): The
[`ContractFactory` class](https://chainsafe.github.io/web3-plugin-zksync/classes/ContractFactory.html)
can be used to deploy smart contracts to the ZKsync Era network. The return type of the
[`ContractFactory.deploy` method](https://chainsafe.github.io/web3-plugin-zksync/classes/ContractFactory.html#deploy)
is the standard
[Web3.js Contract class](https://docs.web3js.org/api/web3-eth-contract/class/Contract/).
- [Smart accounts](https://sdk.zksync.io/js/web3js/smart-accounts): The
[`SmartAccount` class](https://chainsafe.github.io/web3-plugin-zksync/classes/SmartAccount.html)
can be used to create
[ZKsync smart accounts](https://docs.zksync.io/build/developer-reference/account-abstraction/)
with custom logic for building and signing transactions. There are factory functions for
creating
[ECDSA smart accounts](https://chainsafe.github.io/web3-plugin-zksync/classes/ECDSASmartAccount.html#create)
and
[multi-signature ECDSA smart accounts](https://chainsafe.github.io/web3-plugin-zksync/classes/MultisigECDSASmartAccount.html#create).

## Contributing

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"build": "tsc --project tsconfig.build.json",
"test:prepare": "ts-node test/setup.ts",
"test:wait": "ts-node test/wait.ts",
"build:docs": "npx -y typedoc src/index.ts",
"build:docs": "npx -y typedoc src/index.ts --tsconfig tsconfig.build.json",
"test": "jest --config=./test/jest.config.js",
"test:unit": "jest --config=./test/jest.config.js test/unit",
"test:local": "jest --config=./test/jest.config.js --runInBand --maxConcurrency=1 test/local",
Expand Down Expand Up @@ -48,4 +48,4 @@
"peerDependencies": {
"web3": ">= 4.12.0"
}
}
}
13 changes: 7 additions & 6 deletions src/Eip712.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ import {
EIP712_TYPES,
ZERO_ADDRESS,
} from './constants';
import type {
import {
Eip712Meta,
Eip712SignedInput,
Eip712TxData,
EthereumSignature,
PaymasterParams,
TransactionRequest,
} from './types';
import { SignatureLike } from './utils';
import { concat, hashBytecode, SignatureObject, toBytes } from './utils';
Expand Down Expand Up @@ -233,7 +234,7 @@ export class EIP712 {

return new Uint8Array([...r, ...s, v]);
}
static raw(transaction: Eip712TxData, signature?: SignatureLike) {
static raw(transaction: TransactionRequest, signature?: SignatureLike) {
if (!transaction.chainId) {
throw Error("Transaction chainId isn't set!");
}
Expand All @@ -244,7 +245,7 @@ export class EIP712 {
);
}
const from = transaction.from;
const meta: Eip712Meta = transaction.customData ?? {};
const meta: Eip712Meta = (transaction.customData ?? {}) as Eip712Meta;
const maxFeePerGas = toHex(transaction.maxFeePerGas || transaction.gasPrice || 0);
const maxPriorityFeePerGas = toHex(transaction.maxPriorityFeePerGas || maxFeePerGas);

Expand Down Expand Up @@ -303,7 +304,7 @@ export class EIP712 {
}
return fields;
}
static serialize(transaction: Eip712TxData, signature?: SignatureLike): string {
static serialize(transaction: TransactionRequest, signature?: SignatureLike): string {
const fields = EIP712.raw(transaction, signature);
return concat([new Uint8Array([EIP712_TX_TYPE]), RLP.encode(fields)]);
}
Expand Down Expand Up @@ -340,12 +341,12 @@ export class EIP712Signer {
*
* @throws {Error} If `transaction.chainId` is not set.
*/
static getSignedDigest(transaction: Eip712TxData): Bytes {
static getSignedDigest(transaction: TransactionRequest): Bytes {
if (!transaction.chainId) {
throw Error("Transaction chainId isn't set!");
}

return web3Abi.getEncodedEip712Data(EIP712.txTypedData(transaction), true);
return web3Abi.getEncodedEip712Data(EIP712.txTypedData(transaction as Eip712TxData), true);
}

/**
Expand Down
Loading