viem 2.57.18 → 2.57.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +42 -0
- package/_cjs/accounts/index.js +2 -1
- package/_cjs/accounts/index.js.map +1 -1
- package/_cjs/accounts/utils/publicKeyToAddress.js +15 -0
- package/_cjs/accounts/utils/publicKeyToAddress.js.map +1 -1
- package/_cjs/actions/ens/getEnsText.js.map +1 -1
- package/_cjs/actions/public/call.js +19 -3
- package/_cjs/actions/public/call.js.map +1 -1
- package/_cjs/actions/public/estimateMaxPriorityFeePerGas.js +1 -1
- package/_cjs/actions/public/estimateMaxPriorityFeePerGas.js.map +1 -1
- package/_cjs/actions/public/getDelegation.js +2 -1
- package/_cjs/actions/public/getDelegation.js.map +1 -1
- package/_cjs/actions/public/getFeeHistory.js.map +1 -1
- package/_cjs/actions/token/internal.js +2 -10
- package/_cjs/actions/token/internal.js.map +1 -1
- package/_cjs/actions/wallet/deployContract.js +2 -1
- package/_cjs/actions/wallet/deployContract.js.map +1 -1
- package/_cjs/actions/wallet/prepareTransactionRequest.js +99 -76
- package/_cjs/actions/wallet/prepareTransactionRequest.js.map +1 -1
- package/_cjs/actions/wallet/sendCalls.js +2 -1
- package/_cjs/actions/wallet/sendCalls.js.map +1 -1
- package/_cjs/actions/wallet/signAuthorization.js +2 -1
- package/_cjs/actions/wallet/signAuthorization.js.map +1 -1
- package/_cjs/chains/definitions/darwinia.js +1 -1
- package/_cjs/chains/definitions/darwinia.js.map +1 -1
- package/_cjs/chains/definitions/flowMainnet.js +1 -1
- package/_cjs/chains/definitions/flowMainnet.js.map +1 -1
- package/_cjs/chains/definitions/kinetiqElysium.js +30 -0
- package/_cjs/chains/definitions/kinetiqElysium.js.map +1 -0
- package/_cjs/chains/definitions/kinetiqElysiumTestnet.js +31 -0
- package/_cjs/chains/definitions/kinetiqElysiumTestnet.js.map +1 -0
- package/_cjs/chains/index.js +14 -9
- package/_cjs/chains/index.js.map +1 -1
- package/_cjs/errors/encoding.js +9 -1
- package/_cjs/errors/encoding.js.map +1 -1
- package/_cjs/errors/typedData.js +2 -0
- package/_cjs/errors/typedData.js.map +1 -1
- package/_cjs/errors/version.js +1 -1
- package/_cjs/index.js +6 -5
- package/_cjs/index.js.map +1 -1
- package/_cjs/tempo/actions/accounts.js +14 -4
- package/_cjs/tempo/actions/accounts.js.map +1 -1
- package/_cjs/tempo/chainConfig.js +23 -1
- package/_cjs/tempo/chainConfig.js.map +1 -1
- package/_cjs/tempo/internal/relay.js +2 -2
- package/_cjs/tempo/internal/relay.js.map +1 -1
- package/_cjs/tempo/internal/utils.js +2 -10
- package/_cjs/tempo/internal/utils.js.map +1 -1
- package/_cjs/tokens/defineToken.js +1 -1
- package/_cjs/tokens/defineToken.js.map +1 -1
- package/_cjs/tokens/definitions/ousd.js +1 -0
- package/_cjs/tokens/definitions/ousd.js.map +1 -1
- package/_cjs/utils/address/getAddress.js +7 -6
- package/_cjs/utils/address/getAddress.js.map +1 -1
- package/_cjs/utils/address/isAddress.js +8 -12
- package/_cjs/utils/address/isAddress.js.map +1 -1
- package/_cjs/utils/encoding/fromRlp.js +33 -8
- package/_cjs/utils/encoding/fromRlp.js.map +1 -1
- package/_cjs/utils/index.js +5 -4
- package/_cjs/utils/index.js.map +1 -1
- package/_cjs/utils/promise/createBatchScheduler.js +7 -2
- package/_cjs/utils/promise/createBatchScheduler.js.map +1 -1
- package/_cjs/utils/typedData.js +5 -9
- package/_cjs/utils/typedData.js.map +1 -1
- package/_esm/accounts/index.js +1 -1
- package/_esm/accounts/index.js.map +1 -1
- package/_esm/accounts/utils/publicKeyToAddress.js +20 -1
- package/_esm/accounts/utils/publicKeyToAddress.js.map +1 -1
- package/_esm/actions/ens/getEnsText.js.map +1 -1
- package/_esm/actions/public/call.js +19 -3
- package/_esm/actions/public/call.js.map +1 -1
- package/_esm/actions/public/estimateMaxPriorityFeePerGas.js +1 -1
- package/_esm/actions/public/estimateMaxPriorityFeePerGas.js.map +1 -1
- package/_esm/actions/public/getDelegation.js +2 -1
- package/_esm/actions/public/getDelegation.js.map +1 -1
- package/_esm/actions/public/getFeeHistory.js.map +1 -1
- package/_esm/actions/token/internal.js +2 -10
- package/_esm/actions/token/internal.js.map +1 -1
- package/_esm/actions/wallet/deployContract.js +2 -1
- package/_esm/actions/wallet/deployContract.js.map +1 -1
- package/_esm/actions/wallet/prepareTransactionRequest.js +111 -79
- package/_esm/actions/wallet/prepareTransactionRequest.js.map +1 -1
- package/_esm/actions/wallet/sendCalls.js +2 -1
- package/_esm/actions/wallet/sendCalls.js.map +1 -1
- package/_esm/actions/wallet/signAuthorization.js +2 -1
- package/_esm/actions/wallet/signAuthorization.js.map +1 -1
- package/_esm/chains/definitions/darwinia.js +1 -1
- package/_esm/chains/definitions/darwinia.js.map +1 -1
- package/_esm/chains/definitions/flowMainnet.js +1 -1
- package/_esm/chains/definitions/flowMainnet.js.map +1 -1
- package/_esm/chains/definitions/kinetiqElysium.js +27 -0
- package/_esm/chains/definitions/kinetiqElysium.js.map +1 -0
- package/_esm/chains/definitions/kinetiqElysiumTestnet.js +28 -0
- package/_esm/chains/definitions/kinetiqElysiumTestnet.js.map +1 -0
- package/_esm/chains/index.js +2 -0
- package/_esm/chains/index.js.map +1 -1
- package/_esm/errors/encoding.js +8 -0
- package/_esm/errors/encoding.js.map +1 -1
- package/_esm/errors/typedData.js +2 -0
- package/_esm/errors/typedData.js.map +1 -1
- package/_esm/errors/version.js +1 -1
- package/_esm/index.js +1 -1
- package/_esm/index.js.map +1 -1
- package/_esm/tempo/actions/accounts.js +19 -5
- package/_esm/tempo/actions/accounts.js.map +1 -1
- package/_esm/tempo/chainConfig.js +25 -1
- package/_esm/tempo/chainConfig.js.map +1 -1
- package/_esm/tempo/internal/relay/feePayer.js +1 -1
- package/_esm/tempo/internal/relay/feePayer.js.map +1 -1
- package/_esm/tempo/internal/relay.js +8 -3
- package/_esm/tempo/internal/relay.js.map +1 -1
- package/_esm/tempo/internal/utils.js +2 -10
- package/_esm/tempo/internal/utils.js.map +1 -1
- package/_esm/tokens/defineToken.js +2 -1
- package/_esm/tokens/defineToken.js.map +1 -1
- package/_esm/tokens/definitions/ousd.js +2 -1
- package/_esm/tokens/definitions/ousd.js.map +1 -1
- package/_esm/utils/address/getAddress.js +32 -6
- package/_esm/utils/address/getAddress.js.map +1 -1
- package/_esm/utils/address/isAddress.js +32 -12
- package/_esm/utils/address/isAddress.js.map +1 -1
- package/_esm/utils/encoding/fromRlp.js +37 -9
- package/_esm/utils/encoding/fromRlp.js.map +1 -1
- package/_esm/utils/index.js +1 -1
- package/_esm/utils/index.js.map +1 -1
- package/_esm/utils/promise/createBatchScheduler.js +7 -2
- package/_esm/utils/promise/createBatchScheduler.js.map +1 -1
- package/_esm/utils/typedData.js +7 -9
- package/_esm/utils/typedData.js.map +1 -1
- package/_types/accounts/index.d.ts +1 -1
- package/_types/accounts/index.d.ts.map +1 -1
- package/_types/accounts/utils/publicKeyToAddress.d.ts +16 -2
- package/_types/accounts/utils/publicKeyToAddress.d.ts.map +1 -1
- package/_types/actions/ens/getEnsText.d.ts +2 -1
- package/_types/actions/ens/getEnsText.d.ts.map +1 -1
- package/_types/actions/public/call.d.ts +1 -1
- package/_types/actions/public/call.d.ts.map +1 -1
- package/_types/actions/public/estimateMaxPriorityFeePerGas.d.ts +1 -1
- package/_types/actions/public/estimateMaxPriorityFeePerGas.d.ts.map +1 -1
- package/_types/actions/public/getDelegation.d.ts.map +1 -1
- package/_types/actions/public/getFeeHistory.d.ts +2 -1
- package/_types/actions/public/getFeeHistory.d.ts.map +1 -1
- package/_types/actions/token/internal.d.ts.map +1 -1
- package/_types/actions/wallet/deployContract.d.ts.map +1 -1
- package/_types/actions/wallet/prepareTransactionRequest.d.ts +2 -1
- package/_types/actions/wallet/prepareTransactionRequest.d.ts.map +1 -1
- package/_types/actions/wallet/sendCalls.d.ts.map +1 -1
- package/_types/actions/wallet/signAuthorization.d.ts.map +1 -1
- package/_types/chains/definitions/darwinia.d.ts +1 -1
- package/_types/chains/definitions/darwinia.d.ts.map +1 -1
- package/_types/chains/definitions/flowMainnet.d.ts +1 -1
- package/_types/chains/definitions/flowMainnet.d.ts.map +1 -1
- package/_types/chains/definitions/kinetiqElysium.d.ts +52 -0
- package/_types/chains/definitions/kinetiqElysium.d.ts.map +1 -0
- package/_types/chains/definitions/kinetiqElysiumTestnet.d.ts +52 -0
- package/_types/chains/definitions/kinetiqElysiumTestnet.d.ts.map +1 -0
- package/_types/chains/index.d.ts +2 -0
- package/_types/chains/index.d.ts.map +1 -1
- package/_types/errors/encoding.d.ts +9 -0
- package/_types/errors/encoding.d.ts.map +1 -1
- package/_types/errors/typedData.d.ts.map +1 -1
- package/_types/errors/version.d.ts +1 -1
- package/_types/index.d.ts +1 -1
- package/_types/index.d.ts.map +1 -1
- package/_types/tempo/actions/accounts.d.ts +4 -1
- package/_types/tempo/actions/accounts.d.ts.map +1 -1
- package/_types/tempo/chainConfig.d.ts.map +1 -1
- package/_types/tempo/internal/utils.d.ts.map +1 -1
- package/_types/tokens/defineToken.d.ts +5 -1
- package/_types/tokens/defineToken.d.ts.map +1 -1
- package/_types/tokens/definitions/ousd.d.ts +2 -1
- package/_types/tokens/definitions/ousd.d.ts.map +1 -1
- package/_types/tokens/sets.d.ts +3 -0
- package/_types/tokens/sets.d.ts.map +1 -1
- package/_types/utils/address/getAddress.d.ts +23 -0
- package/_types/utils/address/getAddress.d.ts.map +1 -1
- package/_types/utils/address/isAddress.d.ts +22 -0
- package/_types/utils/address/isAddress.d.ts.map +1 -1
- package/_types/utils/encoding/fromRlp.d.ts +3 -3
- package/_types/utils/encoding/fromRlp.d.ts.map +1 -1
- package/_types/utils/index.d.ts +1 -1
- package/_types/utils/index.d.ts.map +1 -1
- package/_types/utils/promise/createBatchScheduler.d.ts.map +1 -1
- package/_types/utils/typedData.d.ts.map +1 -1
- package/_types/zksync/errors/bridge.d.ts +1 -1
- package/_types/zksync/errors/bridge.d.ts.map +1 -1
- package/accounts/index.ts +2 -0
- package/accounts/utils/publicKeyToAddress.ts +27 -1
- package/actions/ens/getEnsText.ts +2 -0
- package/actions/public/call.ts +20 -3
- package/actions/public/estimateMaxPriorityFeePerGas.ts +2 -2
- package/actions/public/getDelegation.ts +6 -1
- package/actions/public/getFeeHistory.ts +2 -0
- package/actions/token/internal.ts +2 -10
- package/actions/wallet/deployContract.ts +6 -1
- package/actions/wallet/prepareTransactionRequest.ts +138 -107
- package/actions/wallet/sendCalls.ts +6 -1
- package/actions/wallet/signAuthorization.ts +6 -1
- package/chains/definitions/darwinia.ts +1 -1
- package/chains/definitions/flowMainnet.ts +1 -1
- package/chains/definitions/kinetiqElysium.ts +27 -0
- package/chains/definitions/kinetiqElysiumTestnet.ts +28 -0
- package/chains/index.ts +2 -0
- package/errors/encoding.ts +12 -0
- package/errors/typedData.ts +2 -0
- package/errors/version.ts +1 -1
- package/index.ts +2 -0
- package/package.json +2 -2
- package/tempo/actions/accounts.ts +24 -6
- package/tempo/chainConfig.ts +33 -5
- package/tempo/internal/relay/feePayer.ts +1 -1
- package/tempo/internal/relay.ts +8 -3
- package/tempo/internal/utils.ts +2 -10
- package/tokens/defineToken.ts +6 -2
- package/tokens/definitions/ousd.ts +2 -1
- package/utils/address/getAddress.ts +31 -6
- package/utils/address/isAddress.ts +31 -10
- package/utils/encoding/fromRlp.ts +37 -5
- package/utils/index.ts +2 -0
- package/utils/promise/createBatchScheduler.ts +10 -2
- package/utils/typedData.ts +7 -9
- package/zksync/errors/bridge.ts +1 -1
package/tokens/defineToken.ts
CHANGED
|
@@ -17,6 +17,8 @@ export type Tokens = readonly Token[]
|
|
|
17
17
|
export type ResolvedToken = {
|
|
18
18
|
/** Token contract address. */
|
|
19
19
|
address: Address
|
|
20
|
+
/** Chain id the token was resolved for. */
|
|
21
|
+
chainId: number
|
|
20
22
|
/** Token currency denomination. */
|
|
21
23
|
currency?: string | undefined
|
|
22
24
|
/** Token decimals, used to parse human-readable `amount` strings. */
|
|
@@ -57,6 +59,7 @@ export type ResolvedToken = {
|
|
|
57
59
|
* usdc(1)
|
|
58
60
|
* // {
|
|
59
61
|
* // address: '0xA0b8…48',
|
|
62
|
+
* // chainId: 1,
|
|
60
63
|
* // currency: 'USD',
|
|
61
64
|
* // decimals: 6,
|
|
62
65
|
* // name: 'USD Coin',
|
|
@@ -76,7 +79,7 @@ export function defineToken<const token extends defineToken.Parameters>(
|
|
|
76
79
|
const address = (addresses as Record<number, Address>)[chainId]
|
|
77
80
|
if (!address)
|
|
78
81
|
throw new Error(`Token has no address for chain id "${chainId}".`)
|
|
79
|
-
return { address, currency, decimals, name, popular, symbol }
|
|
82
|
+
return { address, chainId, currency, decimals, name, popular, symbol }
|
|
80
83
|
}
|
|
81
84
|
return Object.defineProperties(fn, {
|
|
82
85
|
addresses: { enumerable: true, value: addresses },
|
|
@@ -113,13 +116,14 @@ export namespace defineToken {
|
|
|
113
116
|
|
|
114
117
|
export type ReturnType<token extends Parameters = Parameters> = {
|
|
115
118
|
/**
|
|
116
|
-
* Resolves the token config (`address`, `currency`, `decimals`, `name`,
|
|
119
|
+
* Resolves the token config (`address`, `chainId`, `currency`, `decimals`, `name`,
|
|
117
120
|
* `popular`, `symbol`) for a chain id.
|
|
118
121
|
*/
|
|
119
122
|
<chainId extends keyof token['addresses']>(
|
|
120
123
|
chainId: chainId,
|
|
121
124
|
): {
|
|
122
125
|
address: token['addresses'][chainId]
|
|
126
|
+
chainId: chainId
|
|
123
127
|
currency: ParameterValue<token, 'currency'>
|
|
124
128
|
decimals: token['decimals']
|
|
125
129
|
name: ParameterValue<token, 'name'>
|
|
@@ -2,7 +2,7 @@ import { defineToken } from '../defineToken.js'
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* [Open USD](https://joinopenstandard.com/) token, with canonical contract
|
|
5
|
-
* addresses on Ethereum, Tempo, and Base.
|
|
5
|
+
* addresses on Ethereum, Tempo, Tempo Moderato, and Base.
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
8
|
* ```ts
|
|
@@ -17,6 +17,7 @@ export const ousd = /*#__PURE__*/ defineToken({
|
|
|
17
17
|
1: '0x9f6F3991D525015a6F8CaF062C83b62fD3AC4436', // mainnet
|
|
18
18
|
4217: '0x20c0000000000000000000006a37DA5C996874BE', // tempo
|
|
19
19
|
8453: '0xB2000000000000000000002fEb517dFeC7415344', // base
|
|
20
|
+
42431: '0x20c0000000000000000000006a37DA5C996874BE', // tempoModerato
|
|
20
21
|
},
|
|
21
22
|
currency: 'USD',
|
|
22
23
|
decimals: 6,
|
|
@@ -17,6 +17,12 @@ export type ChecksumAddressErrorType =
|
|
|
17
17
|
| StringToBytesErrorType
|
|
18
18
|
| ErrorType
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Returns the [EIP-55](https://eips.ethereum.org/EIPS/eip-55) checksummed form
|
|
22
|
+
* of an address. The input's casing is ignored.
|
|
23
|
+
*
|
|
24
|
+
* Does not validate the input; use {@link getAddress} for untrusted strings.
|
|
25
|
+
*/
|
|
20
26
|
export function checksumAddress(
|
|
21
27
|
address_: Address,
|
|
22
28
|
/**
|
|
@@ -31,12 +37,14 @@ export function checksumAddress(
|
|
|
31
37
|
*/
|
|
32
38
|
chainId?: number | undefined,
|
|
33
39
|
): Address {
|
|
34
|
-
|
|
35
|
-
|
|
40
|
+
// The checksum depends only on the lowercase address, so every casing of an
|
|
41
|
+
// address shares one cache entry.
|
|
42
|
+
const lower = address_.toLowerCase()
|
|
43
|
+
const cacheKey = `${lower}.${chainId}`
|
|
44
|
+
const cached = checksumAddressCache.get(cacheKey)
|
|
45
|
+
if (cached) return cached
|
|
36
46
|
|
|
37
|
-
const hexAddress = chainId
|
|
38
|
-
? `${chainId}${address_.toLowerCase()}`
|
|
39
|
-
: address_.substring(2).toLowerCase()
|
|
47
|
+
const hexAddress = chainId ? `${chainId}${lower}` : lower.substring(2)
|
|
40
48
|
const hash = keccak256(stringToBytes(hexAddress), 'bytes')
|
|
41
49
|
|
|
42
50
|
const address = (
|
|
@@ -52,7 +60,7 @@ export function checksumAddress(
|
|
|
52
60
|
}
|
|
53
61
|
|
|
54
62
|
const result = `0x${address.join('')}` as const
|
|
55
|
-
checksumAddressCache.set(
|
|
63
|
+
checksumAddressCache.set(cacheKey, result)
|
|
56
64
|
return result
|
|
57
65
|
}
|
|
58
66
|
|
|
@@ -61,6 +69,23 @@ export type GetAddressErrorType =
|
|
|
61
69
|
| IsAddressErrorType
|
|
62
70
|
| ErrorType
|
|
63
71
|
|
|
72
|
+
/**
|
|
73
|
+
* Converts an address into its [EIP-55](https://eips.ethereum.org/EIPS/eip-55)
|
|
74
|
+
* checksummed form. Throws if the string is not a `0x`-prefixed, 20-byte hex
|
|
75
|
+
* string.
|
|
76
|
+
*
|
|
77
|
+
* The input's casing is ignored, so an address with a wrong checksum is
|
|
78
|
+
* returned with the correct one. To reject a wrong checksum, check the input
|
|
79
|
+
* with {@link isAddress} first.
|
|
80
|
+
*
|
|
81
|
+
* - Docs: https://viem.sh/docs/utilities/getAddress
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* import { getAddress } from 'viem'
|
|
85
|
+
*
|
|
86
|
+
* getAddress('0x787bc77f1700dce0f8c1581c18a12d3153d1b150')
|
|
87
|
+
* // '0x787bc77F1700DCE0f8c1581c18A12d3153D1B150'
|
|
88
|
+
*/
|
|
64
89
|
export function getAddress(
|
|
65
90
|
address: string,
|
|
66
91
|
/**
|
|
@@ -19,21 +19,42 @@ export type IsAddressOptions = {
|
|
|
19
19
|
|
|
20
20
|
export type IsAddressErrorType = ErrorType
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Checks if a string is a valid address.
|
|
24
|
+
*
|
|
25
|
+
* In strict mode (the default), a mixed-case address must match its
|
|
26
|
+
* [EIP-55](https://eips.ethereum.org/EIPS/eip-55) checksum. An all-lowercase
|
|
27
|
+
* address has no checksum and is valid.
|
|
28
|
+
*
|
|
29
|
+
* Use this to validate user input. {@link getAddress} does not validate the
|
|
30
|
+
* checksum; it returns the checksummed form of any casing.
|
|
31
|
+
*
|
|
32
|
+
* - Docs: https://viem.sh/docs/utilities/isAddress
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* import { isAddress } from 'viem'
|
|
36
|
+
*
|
|
37
|
+
* isAddress('0x787bc77F1700DCE0f8c1581c18A12d3153D1B150')
|
|
38
|
+
* // true
|
|
39
|
+
* isAddress('0x787bc77F1700DCE0f8c1581c18A12d3153D1b150') // last `B` lowercased
|
|
40
|
+
* // false
|
|
41
|
+
* isAddress('0x787bc77f1700dce0f8c1581c18a12d3153d1b150')
|
|
42
|
+
* // true
|
|
43
|
+
*/
|
|
22
44
|
export function isAddress(
|
|
23
45
|
address: string,
|
|
24
46
|
options?: IsAddressOptions | undefined,
|
|
25
47
|
): address is Address {
|
|
26
48
|
const { strict = true } = options ?? {}
|
|
27
|
-
|
|
49
|
+
if (!addressRegex.test(address)) return false
|
|
50
|
+
if (!strict || address.toLowerCase() === address) return true
|
|
28
51
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
})()
|
|
37
|
-
isAddressCache.set(cacheKey, result)
|
|
52
|
+
// Only the checksum comparison is cached; the checks above are cheaper than a
|
|
53
|
+
// cache lookup.
|
|
54
|
+
let result = isAddressCache.get(address)
|
|
55
|
+
if (result === undefined) {
|
|
56
|
+
result = checksumAddress(address as Address) === address
|
|
57
|
+
isAddressCache.set(address, result)
|
|
58
|
+
}
|
|
38
59
|
return result
|
|
39
60
|
}
|
|
@@ -6,6 +6,8 @@ import {
|
|
|
6
6
|
type RlpDepthLimitExceededErrorType,
|
|
7
7
|
RlpListBoundaryExceededError,
|
|
8
8
|
type RlpListBoundaryExceededErrorType,
|
|
9
|
+
RlpNonCanonicalError,
|
|
10
|
+
type RlpNonCanonicalErrorType,
|
|
9
11
|
RlpTrailingBytesError,
|
|
10
12
|
type RlpTrailingBytesErrorType,
|
|
11
13
|
} from '../../errors/encoding.js'
|
|
@@ -35,6 +37,7 @@ export type FromRlpErrorType =
|
|
|
35
37
|
| HexToBytesErrorType
|
|
36
38
|
| InvalidHexValueErrorType
|
|
37
39
|
| RlpDepthLimitExceededErrorType
|
|
40
|
+
| RlpNonCanonicalErrorType
|
|
38
41
|
| RlpTrailingBytesErrorType
|
|
39
42
|
| ErrorType
|
|
40
43
|
|
|
@@ -91,6 +94,11 @@ function fromRlpCursor<to extends To = 'hex'>(
|
|
|
91
94
|
if (prefix < 0xc0) {
|
|
92
95
|
const length = readLength(cursor, prefix, 0x80)
|
|
93
96
|
const bytes = cursor.readBytes(length)
|
|
97
|
+
// A single byte below `0x80` is its own encoding (Yellow Paper, Appendix B).
|
|
98
|
+
if (prefix >= 0x80 && length === 1 && bytes[0]! < 0x80)
|
|
99
|
+
throw new RlpNonCanonicalError({
|
|
100
|
+
reason: 'single byte below `0x80` has a length prefix',
|
|
101
|
+
})
|
|
94
102
|
return (to === 'hex' ? bytesToHex(bytes) : bytes) as FromRlpReturnType<to>
|
|
95
103
|
}
|
|
96
104
|
|
|
@@ -104,18 +112,42 @@ function fromRlpCursor<to extends To = 'hex'>(
|
|
|
104
112
|
) as {} as FromRlpReturnType<to>
|
|
105
113
|
}
|
|
106
114
|
|
|
107
|
-
type ReadLengthErrorType = BaseErrorType | ErrorType
|
|
115
|
+
type ReadLengthErrorType = BaseErrorType | RlpNonCanonicalErrorType | ErrorType
|
|
108
116
|
|
|
109
117
|
function readLength(cursor: Cursor, prefix: number, offset: number) {
|
|
110
118
|
if (offset === 0x80 && prefix < 0x80) return 1
|
|
111
119
|
if (prefix <= offset + 55) return prefix - offset
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
if (prefix === offset + 55 +
|
|
115
|
-
|
|
120
|
+
// Long-form lengths must be above 55 and have no leading zero bytes
|
|
121
|
+
// (Yellow Paper, Appendix B).
|
|
122
|
+
if (prefix === offset + 55 + 1) {
|
|
123
|
+
const length = cursor.readUint8()
|
|
124
|
+
if (length <= 55) throw nonCanonicalLengthError(length)
|
|
125
|
+
return length
|
|
126
|
+
}
|
|
127
|
+
if (prefix === offset + 55 + 2) {
|
|
128
|
+
const length = cursor.readUint16()
|
|
129
|
+
if (length <= 0xff) throw nonCanonicalLengthError(length)
|
|
130
|
+
return length
|
|
131
|
+
}
|
|
132
|
+
if (prefix === offset + 55 + 3) {
|
|
133
|
+
const length = cursor.readUint24()
|
|
134
|
+
if (length <= 0xffff) throw nonCanonicalLengthError(length)
|
|
135
|
+
return length
|
|
136
|
+
}
|
|
137
|
+
if (prefix === offset + 55 + 4) {
|
|
138
|
+
const length = cursor.readUint32()
|
|
139
|
+
if (length <= 0xffffff) throw nonCanonicalLengthError(length)
|
|
140
|
+
return length
|
|
141
|
+
}
|
|
116
142
|
throw new BaseError('Invalid RLP prefix')
|
|
117
143
|
}
|
|
118
144
|
|
|
145
|
+
function nonCanonicalLengthError(length: number) {
|
|
146
|
+
return new RlpNonCanonicalError({
|
|
147
|
+
reason: `length \`${length}\` does not use the shortest length prefix`,
|
|
148
|
+
})
|
|
149
|
+
}
|
|
150
|
+
|
|
119
151
|
type ReadListErrorType = RlpListBoundaryExceededErrorType | ErrorType
|
|
120
152
|
|
|
121
153
|
function readList<to extends To>(
|
package/utils/index.ts
CHANGED
|
@@ -38,6 +38,10 @@ type CreateBatchSchedulerReturnType<
|
|
|
38
38
|
export type CreateBatchSchedulerErrorType = ErrorType
|
|
39
39
|
|
|
40
40
|
const schedulerCache = /*#__PURE__*/ new Map<number | string, SchedulerItem[]>()
|
|
41
|
+
const timerCache = /*#__PURE__*/ new Map<
|
|
42
|
+
number | string,
|
|
43
|
+
ReturnType<typeof setTimeout>
|
|
44
|
+
>()
|
|
41
45
|
|
|
42
46
|
/** @internal */
|
|
43
47
|
export function createBatchScheduler<
|
|
@@ -78,7 +82,11 @@ export function createBatchScheduler<
|
|
|
78
82
|
})
|
|
79
83
|
}
|
|
80
84
|
|
|
81
|
-
const flush = () =>
|
|
85
|
+
const flush = () => {
|
|
86
|
+
clearTimeout(timerCache.get(id))
|
|
87
|
+
timerCache.delete(id)
|
|
88
|
+
schedulerCache.delete(id)
|
|
89
|
+
}
|
|
82
90
|
|
|
83
91
|
const getBatchedArgs = () =>
|
|
84
92
|
getScheduler().map(({ args }) => args) as parameters[]
|
|
@@ -104,7 +112,7 @@ export function createBatchScheduler<
|
|
|
104
112
|
}
|
|
105
113
|
|
|
106
114
|
setScheduler({ args, resolve, reject })
|
|
107
|
-
setTimeout(exec, wait)
|
|
115
|
+
timerCache.set(id, setTimeout(exec, wait))
|
|
108
116
|
return promise
|
|
109
117
|
},
|
|
110
118
|
} as unknown as CreateBatchSchedulerReturnType<parameters, returnType>
|
package/utils/typedData.ts
CHANGED
|
@@ -145,19 +145,17 @@ export function getTypesForEIP712Domain({
|
|
|
145
145
|
}: {
|
|
146
146
|
domain?: TypedDataDomain | undefined
|
|
147
147
|
}): TypedDataParameter[] {
|
|
148
|
+
// A field is part of the schema when it is present on the domain (not
|
|
149
|
+
// `undefined` or `null`).
|
|
148
150
|
return [
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
name: 'chainId',
|
|
154
|
-
type: 'uint256',
|
|
155
|
-
},
|
|
156
|
-
domain?.verifyingContract && {
|
|
151
|
+
domain?.name != null && { name: 'name', type: 'string' },
|
|
152
|
+
domain?.version != null && { name: 'version', type: 'string' },
|
|
153
|
+
domain?.chainId != null && { name: 'chainId', type: 'uint256' },
|
|
154
|
+
domain?.verifyingContract != null && {
|
|
157
155
|
name: 'verifyingContract',
|
|
158
156
|
type: 'address',
|
|
159
157
|
},
|
|
160
|
-
domain?.salt && { name: 'salt', type: 'bytes32' },
|
|
158
|
+
domain?.salt != null && { name: 'salt', type: 'bytes32' },
|
|
161
159
|
].filter(Boolean) as TypedDataParameter[]
|
|
162
160
|
}
|
|
163
161
|
|
package/zksync/errors/bridge.ts
CHANGED
|
@@ -18,7 +18,7 @@ export class BaseFeeHigherThanValueError extends BaseError {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export type TxHashNotFoundInLogsErrorType =
|
|
21
|
+
export type TxHashNotFoundInLogsErrorType = TxHashNotFoundInLogsError & {
|
|
22
22
|
name: 'TxHashNotFoundInLogsError'
|
|
23
23
|
}
|
|
24
24
|
export class TxHashNotFoundInLogsError extends BaseError {
|