zksync-web3
Advanced tools
Comparing version 0.3.5 to 0.3.6
import { BigNumber, BigNumberish, ethers, BytesLike } from 'ethers'; | ||
import { Provider } from './provider'; | ||
import { Address, PriorityOpResponse, BlockTag, Eip712Meta, PriorityQueueType, PriorityOpTree, TransactionResponse } from './types'; | ||
import { Address, PriorityOpResponse, BlockTag, Eip712Meta, PriorityQueueType, PriorityOpTree, TransactionResponse, BalancesMap } from './types'; | ||
declare type Constructor<T = {}> = new (...args: any[]) => T; | ||
@@ -101,2 +101,3 @@ interface TxSender { | ||
getBalance(token?: Address, blockTag?: BlockTag): Promise<BigNumber>; | ||
getAllBalances(): Promise<BalancesMap>; | ||
_fillCustomData(data: Eip712Meta): Eip712Meta; | ||
@@ -103,0 +104,0 @@ withdraw(tx: { |
@@ -217,2 +217,5 @@ "use strict"; | ||
} | ||
async getAllBalances() { | ||
return await this._providerL2().getAllAccountBalances(await this.getAddress()); | ||
} | ||
_fillCustomData(data) { | ||
@@ -219,0 +222,0 @@ var _a, _b, _c, _d, _e, _f, _g; |
@@ -5,3 +5,3 @@ import { ethers, BigNumber, utils } from 'ethers'; | ||
import { ConnectionInfo } from '@ethersproject/web'; | ||
import { Address, EventFilter, BlockTag, TransactionResponse, TransactionRequest, TransactionStatus, Token, PriorityOpResponse } from './types'; | ||
import { Address, EventFilter, BlockTag, TransactionResponse, TransactionRequest, TransactionStatus, Token, PriorityOpResponse, BalancesMap } from './types'; | ||
import { Signer } from './signer'; | ||
@@ -22,2 +22,3 @@ export declare class Provider extends ethers.providers.JsonRpcProvider { | ||
getTokenPrice(token: Address): Promise<string | null>; | ||
getAllAccountBalances(address: Address): Promise<BalancesMap>; | ||
static getDefaultProvider(): Provider; | ||
@@ -24,0 +25,0 @@ newFilter(filter: EventFilter | Promise<EventFilter>): Promise<BigNumber>; |
@@ -102,2 +102,9 @@ "use strict"; | ||
} | ||
async getAllAccountBalances(address) { | ||
let balances = await this.send('zks_getAllAccountBalances', [address]); | ||
for (let token in balances) { | ||
balances[token] = ethers_1.BigNumber.from(balances[token]); | ||
} | ||
return balances; | ||
} | ||
static getDefaultProvider() { | ||
@@ -104,0 +111,0 @@ // TODO: different urls for different networks |
@@ -23,2 +23,3 @@ import { ethers } from 'ethers'; | ||
getBalance(token?: string, blockTag?: BlockTag): Promise<ethers.BigNumber>; | ||
getAllBalances(): Promise<import("./types").BalancesMap>; | ||
_fillCustomData(data: import("./types").Eip712Meta): import("./types").Eip712Meta; | ||
@@ -25,0 +26,0 @@ withdraw(tx: { |
@@ -79,2 +79,3 @@ "use strict"; | ||
var _a, _b, _c, _d, _e, _f, _g; | ||
(0, utils_1.checkNonZeroValue)(transaction); | ||
if (transaction.customData == null && transaction.type == null) { | ||
@@ -81,0 +82,0 @@ // use legacy txs by default |
@@ -1,2 +0,2 @@ | ||
import { BytesLike, BigNumberish, providers } from 'ethers'; | ||
import { BytesLike, BigNumberish, providers, BigNumber } from 'ethers'; | ||
export declare type Address = string; | ||
@@ -59,1 +59,4 @@ export declare type Signature = string; | ||
} | ||
export declare type BalancesMap = { | ||
[key: string]: BigNumber; | ||
}; |
import { utils, ethers, BigNumberish } from 'ethers'; | ||
import { SignatureLike } from '@ethersproject/bytes'; | ||
import { Address, PriorityQueueType, PriorityOpTree } from './types'; | ||
import { Address, PriorityQueueType, PriorityOpTree, TransactionRequest } from './types'; | ||
import { TypedDataDomain, TypedDataField } from '@ethersproject/abstract-signer'; | ||
@@ -33,3 +33,4 @@ export declare const MIN_TIMESTAMP = 0; | ||
export declare function getL2HashFromPriorityOp(txReceipt: ethers.providers.TransactionReceipt, zkSyncAddress: Address): string; | ||
export declare function isMessageSignatureCorrect(address: string, message: ethers.Bytes | string, signature: SignatureLike): boolean; | ||
export declare function isTypedDataSignatureCorrect(address: string, domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, value: Record<string, any>, signature: SignatureLike): boolean; | ||
export declare function isMessageSignatureCorrect(address: string, message: ethers.Bytes | string, signature: SignatureLike): Promise<boolean>; | ||
export declare function isTypedDataSignatureCorrect(address: string, domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, value: Record<string, any>, signature: SignatureLike): Promise<boolean>; | ||
export declare function checkNonZeroValue(transaction: TransactionRequest): void; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isTypedDataSignatureCorrect = exports.isMessageSignatureCorrect = exports.getL2HashFromPriorityOp = exports.getL2HashFromPriorityOpId = exports.parseTransaction = exports.serialize = exports.checkBaseCost = exports.layer1TxDefaults = exports.sleep = exports.isETH = exports.RECOMMENDED_GAS_LIMIT = exports.PRIORITY_OP_ID_BYTES = exports.IERC20 = exports.ZKSYNC_MAIN_ABI = exports.ETH_ADDRESS = exports.MAX_TIMESTAMP = exports.MIN_TIMESTAMP = void 0; | ||
exports.checkNonZeroValue = exports.isTypedDataSignatureCorrect = exports.isMessageSignatureCorrect = exports.getL2HashFromPriorityOp = exports.getL2HashFromPriorityOpId = exports.parseTransaction = exports.serialize = exports.checkBaseCost = exports.layer1TxDefaults = exports.sleep = exports.isETH = exports.RECOMMENDED_GAS_LIMIT = exports.PRIORITY_OP_ID_BYTES = exports.IERC20 = exports.ZKSYNC_MAIN_ABI = exports.ETH_ADDRESS = exports.MAX_TIMESTAMP = exports.MIN_TIMESTAMP = void 0; | ||
const ethers_1 = require("ethers"); | ||
@@ -200,3 +200,6 @@ const types_1 = require("./types"); | ||
} | ||
function isMessageSignatureCorrect(address, message, signature) { | ||
// Returns `true` or `false` depending on whether or not the account abstraction's | ||
// signature is correct. Note, that while currently it does not do any `async` actions. | ||
// in the future it will. That's why the `Promise<boolean>` is returned. | ||
async function isMessageSignatureCorrect(address, message, signature) { | ||
const msgHash = ethers_1.ethers.utils.hashMessage(message); | ||
@@ -206,3 +209,6 @@ return isECDSASignatureCorrect(address, msgHash, signature); | ||
exports.isMessageSignatureCorrect = isMessageSignatureCorrect; | ||
function isTypedDataSignatureCorrect(address, domain, types, value, signature) { | ||
// Returns `true` or `false` depending on whether or not the account abstraction's | ||
// EIP712 signature is correct. Note, that while currently it does not do any `async` actions. | ||
// in the future it will. That's why the `Promise<boolean>` is returned. | ||
async function isTypedDataSignatureCorrect(address, domain, types, value, signature) { | ||
const msgHash = ethers_1.ethers.utils._TypedDataEncoder.hash(domain, types, value); | ||
@@ -212,1 +218,12 @@ return isECDSASignatureCorrect(address, msgHash, signature); | ||
exports.isTypedDataSignatureCorrect = isTypedDataSignatureCorrect; | ||
// Throws error if transaction is not a withdrawal and contains non-zero value. | ||
function checkNonZeroValue(transaction) { | ||
var _a; | ||
const isWithdraw = transaction.customData != null && | ||
transaction.customData.withdrawToken != null && | ||
transaction.customData.withdrawToken != ethers_1.ethers.constants.AddressZero; | ||
if (!isWithdraw && !ethers_1.BigNumber.from((_a = transaction.value) !== null && _a !== void 0 ? _a : 0).isZero()) { | ||
throw new Error('Non-zero value is not supported for transactions'); | ||
} | ||
} | ||
exports.checkNonZeroValue = checkNonZeroValue; |
@@ -11,2 +11,3 @@ import { EIP712Signer } from './signer'; | ||
getBalance(token?: string, blockTag?: BlockTag): Promise<ethers.BigNumber>; | ||
getAllBalances(): Promise<import("./types").BalancesMap>; | ||
_fillCustomData(data: import("./types").Eip712Meta): import("./types").Eip712Meta; | ||
@@ -13,0 +14,0 @@ withdraw(tx: { |
@@ -64,2 +64,3 @@ "use strict"; | ||
var _a, _b; | ||
(0, utils_1.checkNonZeroValue)(transaction); | ||
if (transaction.type == null && transaction.customData == null) { | ||
@@ -66,0 +67,0 @@ // use legacy txs by default |
{ | ||
"name": "zksync-web3", | ||
"version": "0.3.5", | ||
"version": "0.3.6", | ||
"main": "build/index.js", | ||
@@ -5,0 +5,0 @@ "types": "build/index.d.ts", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
135162
3800