viem 2.57.14 → 2.57.15
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 +44 -0
- package/_cjs/account-abstraction/utils/formatters/userOperationReceipt.js +2 -0
- package/_cjs/account-abstraction/utils/formatters/userOperationReceipt.js.map +1 -1
- package/_cjs/actions/public/estimateGas.js +5 -2
- package/_cjs/actions/public/estimateGas.js.map +1 -1
- package/_cjs/actions/public/fillTransaction.js +2 -0
- package/_cjs/actions/public/fillTransaction.js.map +1 -1
- package/_cjs/actions/public/getFilterChanges.js +1 -0
- package/_cjs/actions/public/getFilterChanges.js.map +1 -1
- package/_cjs/actions/public/getFilterLogs.js +1 -0
- package/_cjs/actions/public/getFilterLogs.js.map +1 -1
- package/_cjs/actions/public/watchBlockNumber.js +3 -1
- package/_cjs/actions/public/watchBlockNumber.js.map +1 -1
- package/_cjs/actions/public/watchBlocks.js +20 -8
- package/_cjs/actions/public/watchBlocks.js.map +1 -1
- package/_cjs/actions/public/watchContractEvent.js +10 -3
- package/_cjs/actions/public/watchContractEvent.js.map +1 -1
- package/_cjs/actions/public/watchEvent.js +5 -0
- package/_cjs/actions/public/watchEvent.js.map +1 -1
- package/_cjs/actions/wallet/prepareTransactionRequest.js +3 -2
- package/_cjs/actions/wallet/prepareTransactionRequest.js.map +1 -1
- package/_cjs/actions/wallet/sendTransaction.js +4 -2
- package/_cjs/actions/wallet/sendTransaction.js.map +1 -1
- package/_cjs/actions/wallet/sendTransactionSync.js +48 -7
- package/_cjs/actions/wallet/sendTransactionSync.js.map +1 -1
- package/_cjs/chains/definitions/hashKeyChain.js +4 -4
- package/_cjs/chains/definitions/hashKeyChain.js.map +1 -1
- package/_cjs/chains/definitions/hashkeyChainTestnet.js +4 -4
- package/_cjs/chains/definitions/hashkeyChainTestnet.js.map +1 -1
- package/_cjs/chains/definitions/turkchain.js +26 -0
- package/_cjs/chains/definitions/turkchain.js.map +1 -0
- package/_cjs/chains/definitions/zksync.js +1 -1
- package/_cjs/chains/definitions/zksync.js.map +1 -1
- package/_cjs/chains/index.js +4 -2
- package/_cjs/chains/index.js.map +1 -1
- package/_cjs/clients/createClient.js.map +1 -1
- package/_cjs/clients/transports/fallback.js +5 -0
- package/_cjs/clients/transports/fallback.js.map +1 -1
- package/_cjs/errors/node.js +10 -4
- package/_cjs/errors/node.js.map +1 -1
- package/_cjs/errors/typedData.js +4 -2
- package/_cjs/errors/typedData.js.map +1 -1
- package/_cjs/errors/version.js +1 -1
- package/_cjs/index.js +5 -4
- package/_cjs/index.js.map +1 -1
- package/_cjs/tempo/Account.js +85 -12
- package/_cjs/tempo/Account.js.map +1 -1
- package/_cjs/tempo/Transaction.js +2 -1
- package/_cjs/tempo/Transaction.js.map +1 -1
- package/_cjs/tempo/chainConfig.js +4 -12
- package/_cjs/tempo/chainConfig.js.map +1 -1
- package/_cjs/tempo/internal/relay/feePayer.js +18 -5
- package/_cjs/tempo/internal/relay/feePayer.js.map +1 -1
- package/_cjs/utils/abi/decodeEventLog.js +57 -7
- package/_cjs/utils/abi/decodeEventLog.js.map +1 -1
- package/_cjs/utils/abi/getAbiItem.js +27 -6
- package/_cjs/utils/abi/getAbiItem.js.map +1 -1
- package/_cjs/utils/abi/parseEventLogs.js +27 -4
- package/_cjs/utils/abi/parseEventLogs.js.map +1 -1
- package/_cjs/utils/authorization/recoverAuthorizationAddress.js +9 -2
- package/_cjs/utils/authorization/recoverAuthorizationAddress.js.map +1 -1
- package/_cjs/utils/authorization/verifyAuthorization.js +14 -4
- package/_cjs/utils/authorization/verifyAuthorization.js.map +1 -1
- package/_cjs/utils/ccip.js +134 -28
- package/_cjs/utils/ccip.js.map +1 -1
- package/_cjs/utils/ccipTunnel.js +5 -1
- package/_cjs/utils/ccipTunnel.js.map +1 -1
- package/_cjs/utils/ens/localBatchGatewayRequest.js +55 -5
- package/_cjs/utils/ens/localBatchGatewayRequest.js.map +1 -1
- package/_cjs/utils/internal/http.js +79 -0
- package/_cjs/utils/internal/http.js.map +1 -0
- package/_cjs/utils/nonceManager.js.map +1 -1
- package/_cjs/utils/rpc/http.js +3 -73
- package/_cjs/utils/rpc/http.js.map +1 -1
- package/_cjs/utils/transaction/assertRequest.js +2 -2
- package/_cjs/utils/transaction/assertRequest.js.map +1 -1
- package/_cjs/utils/transaction/assertTransaction.js +2 -2
- package/_cjs/utils/transaction/assertTransaction.js.map +1 -1
- package/_cjs/utils/transaction/parseTransaction.js +21 -7
- package/_cjs/utils/transaction/parseTransaction.js.map +1 -1
- package/_cjs/utils/typedData.js +19 -6
- package/_cjs/utils/typedData.js.map +1 -1
- package/_esm/account-abstraction/utils/formatters/userOperationReceipt.js +2 -0
- package/_esm/account-abstraction/utils/formatters/userOperationReceipt.js.map +1 -1
- package/_esm/actions/public/estimateGas.js +10 -5
- package/_esm/actions/public/estimateGas.js.map +1 -1
- package/_esm/actions/public/fillTransaction.js +2 -0
- package/_esm/actions/public/fillTransaction.js.map +1 -1
- package/_esm/actions/public/getFilterChanges.js +1 -0
- package/_esm/actions/public/getFilterChanges.js.map +1 -1
- package/_esm/actions/public/getFilterLogs.js +1 -0
- package/_esm/actions/public/getFilterLogs.js.map +1 -1
- package/_esm/actions/public/watchBlockNumber.js +5 -1
- package/_esm/actions/public/watchBlockNumber.js.map +1 -1
- package/_esm/actions/public/watchBlocks.js +28 -8
- package/_esm/actions/public/watchBlocks.js.map +1 -1
- package/_esm/actions/public/watchContractEvent.js +15 -5
- package/_esm/actions/public/watchContractEvent.js.map +1 -1
- package/_esm/actions/public/watchEvent.js +11 -2
- package/_esm/actions/public/watchEvent.js.map +1 -1
- package/_esm/actions/wallet/prepareTransactionRequest.js +3 -2
- package/_esm/actions/wallet/prepareTransactionRequest.js.map +1 -1
- package/_esm/actions/wallet/sendTransaction.js +6 -2
- package/_esm/actions/wallet/sendTransaction.js.map +1 -1
- package/_esm/actions/wallet/sendTransactionSync.js +59 -8
- package/_esm/actions/wallet/sendTransactionSync.js.map +1 -1
- package/_esm/chains/definitions/hashKeyChain.js +4 -4
- package/_esm/chains/definitions/hashKeyChain.js.map +1 -1
- package/_esm/chains/definitions/hashkeyChainTestnet.js +4 -4
- package/_esm/chains/definitions/hashkeyChainTestnet.js.map +1 -1
- package/_esm/chains/definitions/turkchain.js +23 -0
- package/_esm/chains/definitions/turkchain.js.map +1 -0
- package/_esm/chains/definitions/zksync.js +1 -1
- package/_esm/chains/definitions/zksync.js.map +1 -1
- package/_esm/chains/index.js +1 -0
- package/_esm/chains/index.js.map +1 -1
- package/_esm/clients/createClient.js.map +1 -1
- package/_esm/clients/transports/fallback.js +8 -0
- package/_esm/clients/transports/fallback.js.map +1 -1
- package/_esm/errors/node.js +10 -4
- package/_esm/errors/node.js.map +1 -1
- package/_esm/errors/typedData.js +5 -2
- 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/Account.js +122 -11
- package/_esm/tempo/Account.js.map +1 -1
- package/_esm/tempo/Transaction.js +2 -0
- package/_esm/tempo/Transaction.js.map +1 -1
- package/_esm/tempo/chainConfig.js +13 -15
- package/_esm/tempo/chainConfig.js.map +1 -1
- package/_esm/tempo/internal/relay/feePayer.js +24 -7
- package/_esm/tempo/internal/relay/feePayer.js.map +1 -1
- package/_esm/utils/abi/decodeEventLog.js +69 -7
- package/_esm/utils/abi/decodeEventLog.js.map +1 -1
- package/_esm/utils/abi/getAbiItem.js +34 -6
- package/_esm/utils/abi/getAbiItem.js.map +1 -1
- package/_esm/utils/abi/parseEventLogs.js +43 -10
- package/_esm/utils/abi/parseEventLogs.js.map +1 -1
- package/_esm/utils/authorization/recoverAuthorizationAddress.js +11 -2
- package/_esm/utils/authorization/recoverAuthorizationAddress.js.map +1 -1
- package/_esm/utils/authorization/verifyAuthorization.js +15 -4
- package/_esm/utils/authorization/verifyAuthorization.js.map +1 -1
- package/_esm/utils/ccip.js +163 -31
- package/_esm/utils/ccip.js.map +1 -1
- package/_esm/utils/ccipTunnel.js +5 -1
- package/_esm/utils/ccipTunnel.js.map +1 -1
- package/_esm/utils/ens/localBatchGatewayRequest.js +69 -4
- package/_esm/utils/ens/localBatchGatewayRequest.js.map +1 -1
- package/_esm/utils/internal/http.js +83 -0
- package/_esm/utils/internal/http.js.map +1 -0
- package/_esm/utils/nonceManager.js.map +1 -1
- package/_esm/utils/rpc/http.js +1 -75
- package/_esm/utils/rpc/http.js.map +1 -1
- package/_esm/utils/transaction/assertRequest.js +2 -2
- package/_esm/utils/transaction/assertRequest.js.map +1 -1
- package/_esm/utils/transaction/assertTransaction.js +2 -2
- package/_esm/utils/transaction/assertTransaction.js.map +1 -1
- package/_esm/utils/transaction/parseTransaction.js +24 -7
- package/_esm/utils/transaction/parseTransaction.js.map +1 -1
- package/_esm/utils/typedData.js +25 -8
- package/_esm/utils/typedData.js.map +1 -1
- package/_types/account-abstraction/utils/formatters/userOperationReceipt.d.ts.map +1 -1
- package/_types/actions/public/estimateGas.d.ts.map +1 -1
- package/_types/actions/public/fillTransaction.d.ts.map +1 -1
- package/_types/actions/public/getFilterChanges.d.ts.map +1 -1
- package/_types/actions/public/getFilterLogs.d.ts.map +1 -1
- package/_types/actions/public/watchBlockNumber.d.ts +6 -2
- package/_types/actions/public/watchBlockNumber.d.ts.map +1 -1
- package/_types/actions/public/watchBlocks.d.ts +7 -2
- package/_types/actions/public/watchBlocks.d.ts.map +1 -1
- package/_types/actions/public/watchContractEvent.d.ts.map +1 -1
- package/_types/actions/public/watchEvent.d.ts.map +1 -1
- package/_types/actions/wallet/prepareTransactionRequest.d.ts.map +1 -1
- package/_types/actions/wallet/sendTransaction.d.ts.map +1 -1
- package/_types/actions/wallet/sendTransactionSync.d.ts.map +1 -1
- package/_types/chains/definitions/hashKeyChain.d.ts +4 -4
- package/_types/chains/definitions/hashkeyChainTestnet.d.ts +4 -4
- package/_types/chains/definitions/turkchain.d.ts +53 -0
- package/_types/chains/definitions/turkchain.d.ts.map +1 -0
- package/_types/chains/definitions/zksync.d.ts +1 -1
- package/_types/chains/index.d.ts +1 -0
- package/_types/chains/index.d.ts.map +1 -1
- package/_types/clients/createClient.d.ts +6 -0
- package/_types/clients/createClient.d.ts.map +1 -1
- package/_types/clients/transports/fallback.d.ts.map +1 -1
- package/_types/errors/node.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/Account.d.ts +77 -4
- package/_types/tempo/Account.d.ts.map +1 -1
- package/_types/tempo/Relay.d.ts +1 -1
- package/_types/tempo/Relay.d.ts.map +1 -1
- package/_types/tempo/Transaction.d.ts +2 -0
- package/_types/tempo/Transaction.d.ts.map +1 -1
- package/_types/tempo/chainConfig.d.ts.map +1 -1
- package/_types/tempo/internal/relay/feePayer.d.ts.map +1 -1
- package/_types/tempo/internal/relay/utils.d.ts +8 -8
- package/_types/utils/abi/decodeEventLog.d.ts +13 -1
- package/_types/utils/abi/decodeEventLog.d.ts.map +1 -1
- package/_types/utils/abi/getAbiItem.d.ts.map +1 -1
- package/_types/utils/abi/parseEventLogs.d.ts.map +1 -1
- package/_types/utils/authorization/recoverAuthorizationAddress.d.ts +2 -1
- package/_types/utils/authorization/recoverAuthorizationAddress.d.ts.map +1 -1
- package/_types/utils/authorization/verifyAuthorization.d.ts.map +1 -1
- package/_types/utils/ccip.d.ts +24 -4
- package/_types/utils/ccip.d.ts.map +1 -1
- package/_types/utils/ccipTunnel.d.ts.map +1 -1
- package/_types/utils/ens/localBatchGatewayRequest.d.ts +26 -0
- package/_types/utils/ens/localBatchGatewayRequest.d.ts.map +1 -1
- package/_types/utils/internal/http.d.ts +16 -0
- package/_types/utils/internal/http.d.ts.map +1 -0
- package/_types/utils/nonceManager.d.ts +15 -1
- package/_types/utils/nonceManager.d.ts.map +1 -1
- package/_types/utils/rpc/http.d.ts.map +1 -1
- package/_types/utils/transaction/parseTransaction.d.ts.map +1 -1
- package/_types/utils/typedData.d.ts.map +1 -1
- package/account-abstraction/utils/formatters/userOperationReceipt.ts +1 -0
- package/actions/public/estimateGas.ts +12 -5
- package/actions/public/fillTransaction.ts +2 -0
- package/actions/public/getFilterChanges.ts +1 -0
- package/actions/public/getFilterLogs.ts +1 -0
- package/actions/public/watchBlockNumber.ts +11 -2
- package/actions/public/watchBlocks.ts +46 -14
- package/actions/public/watchContractEvent.ts +22 -4
- package/actions/public/watchEvent.ts +17 -1
- package/actions/wallet/prepareTransactionRequest.ts +6 -2
- package/actions/wallet/sendTransaction.ts +9 -3
- package/actions/wallet/sendTransactionSync.ts +74 -12
- package/chains/definitions/hashKeyChain.ts +4 -4
- package/chains/definitions/hashkeyChainTestnet.ts +4 -4
- package/chains/definitions/turkchain.ts +23 -0
- package/chains/definitions/zksync.ts +1 -1
- package/chains/index.ts +1 -0
- package/clients/createClient.ts +6 -0
- package/clients/transports/fallback.ts +11 -0
- package/errors/node.ts +11 -5
- package/errors/typedData.ts +5 -2
- package/errors/version.ts +1 -1
- package/index.ts +2 -0
- package/package.json +1 -1
- package/tempo/Account.ts +202 -16
- package/tempo/Relay.ts +1 -1
- package/tempo/Transaction.ts +3 -0
- package/tempo/chainConfig.ts +13 -15
- package/tempo/internal/relay/feePayer.ts +30 -7
- package/utils/abi/decodeEventLog.ts +97 -10
- package/utils/abi/getAbiItem.ts +35 -5
- package/utils/abi/parseEventLogs.ts +48 -11
- package/utils/authorization/recoverAuthorizationAddress.ts +18 -2
- package/utils/authorization/verifyAuthorization.ts +12 -7
- package/utils/ccip.ts +199 -33
- package/utils/ccipTunnel.ts +5 -1
- package/utils/ens/localBatchGatewayRequest.ts +82 -4
- package/utils/internal/http.ts +92 -0
- package/utils/nonceManager.ts +16 -1
- package/utils/rpc/http.ts +1 -83
- package/utils/transaction/assertRequest.ts +2 -2
- package/utils/transaction/assertTransaction.ts +2 -2
- package/utils/transaction/parseTransaction.ts +32 -7
- package/utils/typedData.ts +31 -8
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { batchGatewayAbi } from '../../constants/abis.js'
|
|
2
2
|
import { solidityError } from '../../constants/solidity.js'
|
|
3
|
+
import { HttpRequestError } from '../../errors/request.js'
|
|
3
4
|
import type { Hex } from '../../types/misc.js'
|
|
4
5
|
import { decodeFunctionData } from '../abi/decodeFunctionData.js'
|
|
5
6
|
import { encodeErrorResult } from '../abi/encodeErrorResult.js'
|
|
@@ -12,13 +13,67 @@ import type {
|
|
|
12
13
|
|
|
13
14
|
export const localBatchGatewayUrl = 'x-batch-gateway:true'
|
|
14
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Caps for one CCIP-Read lookup.
|
|
18
|
+
*
|
|
19
|
+
* - `concurrency`: gateway requests in flight at once, across nested batches.
|
|
20
|
+
* - `depth`: nested callbacks, and separately, nested local batches.
|
|
21
|
+
* - `queries`: gateway requests in total, across callbacks and nested batches.
|
|
22
|
+
* Each contract-chosen URL counts once, and a query with none counts once.
|
|
23
|
+
* Gateways a custom `ccipRead.request` adds (such as `ccipReadTunnel`'s
|
|
24
|
+
* `batchGateways`) are the caller's own and are not counted separately.
|
|
25
|
+
*/
|
|
26
|
+
export const ccipReadLimit = {
|
|
27
|
+
concurrency: 16,
|
|
28
|
+
depth: 4,
|
|
29
|
+
queries: 256,
|
|
30
|
+
} as const
|
|
31
|
+
|
|
32
|
+
/** Query and concurrency budget shared by every request of one lookup. */
|
|
33
|
+
export type CcipReadBudget = {
|
|
34
|
+
/** Gateway requests still allowed. */
|
|
35
|
+
queries: number
|
|
36
|
+
/** Runs a gateway request once a concurrency slot is free. */
|
|
37
|
+
run: <result>(fn: () => Promise<result>) => Promise<result>
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Creates the budget for one CCIP-Read lookup. */
|
|
41
|
+
export function createCcipReadBudget(): CcipReadBudget {
|
|
42
|
+
let active = 0
|
|
43
|
+
const queue: (() => void)[] = []
|
|
44
|
+
return {
|
|
45
|
+
queries: ccipReadLimit.queries,
|
|
46
|
+
async run(fn) {
|
|
47
|
+
if (active >= ccipReadLimit.concurrency)
|
|
48
|
+
await new Promise<void>((resolve) => queue.push(resolve))
|
|
49
|
+
else active++
|
|
50
|
+
try {
|
|
51
|
+
return await fn()
|
|
52
|
+
} finally {
|
|
53
|
+
// Hand the slot straight to the next waiter so a new caller cannot
|
|
54
|
+
// take it in between.
|
|
55
|
+
const next = queue.shift()
|
|
56
|
+
if (next) next()
|
|
57
|
+
else active--
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
15
63
|
export async function localBatchGatewayRequest(parameters: {
|
|
16
64
|
data: Hex
|
|
17
65
|
ccipRequest: (
|
|
18
66
|
parameters: CcipRequestParameters,
|
|
19
67
|
) => Promise<CcipRequestReturnType>
|
|
68
|
+
budget?: CcipReadBudget | undefined
|
|
69
|
+
depth?: number | undefined
|
|
20
70
|
}): Promise<Hex> {
|
|
21
|
-
const {
|
|
71
|
+
const {
|
|
72
|
+
data,
|
|
73
|
+
ccipRequest,
|
|
74
|
+
budget = createCcipReadBudget(),
|
|
75
|
+
depth = 0,
|
|
76
|
+
} = parameters
|
|
22
77
|
|
|
23
78
|
const {
|
|
24
79
|
args: [queries],
|
|
@@ -29,9 +84,32 @@ export async function localBatchGatewayRequest(parameters: {
|
|
|
29
84
|
await Promise.all(
|
|
30
85
|
queries.map(async (query, i) => {
|
|
31
86
|
try {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
87
|
+
const nested = query.urls.includes(localBatchGatewayUrl)
|
|
88
|
+
if (nested && depth + 1 >= ccipReadLimit.depth)
|
|
89
|
+
throw new HttpRequestError({
|
|
90
|
+
details: `CCIP Read exceeded the maximum batch depth (${ccipReadLimit.depth}).`,
|
|
91
|
+
url: localBatchGatewayUrl,
|
|
92
|
+
})
|
|
93
|
+
if (nested)
|
|
94
|
+
responses[i] = await localBatchGatewayRequest({
|
|
95
|
+
data: query.data,
|
|
96
|
+
ccipRequest,
|
|
97
|
+
budget,
|
|
98
|
+
depth: depth + 1,
|
|
99
|
+
})
|
|
100
|
+
else {
|
|
101
|
+
if (budget.queries <= 0)
|
|
102
|
+
throw new HttpRequestError({
|
|
103
|
+
details: `CCIP Read exceeded the maximum number of queries (${ccipReadLimit.queries}).`,
|
|
104
|
+
url: query.urls[0] ?? '',
|
|
105
|
+
})
|
|
106
|
+
// Each URL is a gateway request, so each one draws from the budget.
|
|
107
|
+
// A query with no URLs still costs one, since a custom request (such
|
|
108
|
+
// as `ccipReadTunnel`) may send it elsewhere.
|
|
109
|
+
const urls = query.urls.slice(0, budget.queries)
|
|
110
|
+
budget.queries -= Math.max(1, urls.length)
|
|
111
|
+
responses[i] = await budget.run(() => ccipRequest({ ...query, urls }))
|
|
112
|
+
}
|
|
35
113
|
failures[i] = false
|
|
36
114
|
} catch (err) {
|
|
37
115
|
failures[i] = true
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { ResponseBodyTooLargeError } from '../../errors/request.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns a signal that aborts as soon as any of `signals` aborts, and a
|
|
5
|
+
* `cleanup` function that detaches the listeners added to `signals`.
|
|
6
|
+
*/
|
|
7
|
+
export function anySignal(
|
|
8
|
+
signals: readonly (AbortSignal | null | undefined)[],
|
|
9
|
+
) {
|
|
10
|
+
const signals_ = signals.filter((signal) => !!signal)
|
|
11
|
+
if (signals_.length < 2)
|
|
12
|
+
return { signal: signals_[0] ?? null, cleanup: () => {} }
|
|
13
|
+
|
|
14
|
+
const controller = new AbortController()
|
|
15
|
+
const onAbort = () => {
|
|
16
|
+
cleanup()
|
|
17
|
+
controller.abort(signals_.find((signal) => signal.aborted)?.reason)
|
|
18
|
+
}
|
|
19
|
+
const cleanup = () => {
|
|
20
|
+
for (const signal of signals_) signal.removeEventListener('abort', onAbort)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
for (const signal of signals_) {
|
|
24
|
+
if (signal.aborted) {
|
|
25
|
+
cleanup()
|
|
26
|
+
controller.abort(signal.reason)
|
|
27
|
+
break
|
|
28
|
+
}
|
|
29
|
+
signal.addEventListener('abort', onAbort)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return { signal: controller.signal, cleanup }
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Reads a response body as text, throwing once it exceeds
|
|
37
|
+
* `maxResponseBodySize` bytes (`false` reads it whole).
|
|
38
|
+
*/
|
|
39
|
+
export async function readResponseBody(
|
|
40
|
+
response: Response,
|
|
41
|
+
{ maxResponseBodySize }: { maxResponseBodySize: number | false },
|
|
42
|
+
): Promise<string> {
|
|
43
|
+
if (maxResponseBodySize === false) return response.text()
|
|
44
|
+
|
|
45
|
+
const contentLength = response.headers.get('Content-Length')
|
|
46
|
+
if (contentLength) {
|
|
47
|
+
const size = Number(contentLength)
|
|
48
|
+
if (size > maxResponseBodySize) {
|
|
49
|
+
await response.body?.cancel()
|
|
50
|
+
throw new ResponseBodyTooLargeError({
|
|
51
|
+
maxSize: maxResponseBodySize,
|
|
52
|
+
size,
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (!response.body) {
|
|
58
|
+
const body = await response.text()
|
|
59
|
+
const size = new TextEncoder().encode(body).length
|
|
60
|
+
if (size > maxResponseBodySize)
|
|
61
|
+
throw new ResponseBodyTooLargeError({
|
|
62
|
+
maxSize: maxResponseBodySize,
|
|
63
|
+
size,
|
|
64
|
+
})
|
|
65
|
+
return body
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const reader = response.body.getReader()
|
|
69
|
+
const decoder = new TextDecoder()
|
|
70
|
+
let body = ''
|
|
71
|
+
let size = 0
|
|
72
|
+
|
|
73
|
+
try {
|
|
74
|
+
while (true) {
|
|
75
|
+
const { done, value } = await reader.read()
|
|
76
|
+
if (done) break
|
|
77
|
+
size += value.byteLength
|
|
78
|
+
if (size > maxResponseBodySize) {
|
|
79
|
+
await reader.cancel()
|
|
80
|
+
throw new ResponseBodyTooLargeError({
|
|
81
|
+
maxSize: maxResponseBodySize,
|
|
82
|
+
size,
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
body += decoder.decode(value, { stream: true })
|
|
86
|
+
}
|
|
87
|
+
body += decoder.decode()
|
|
88
|
+
return body
|
|
89
|
+
} finally {
|
|
90
|
+
reader.releaseLock()
|
|
91
|
+
}
|
|
92
|
+
}
|
package/utils/nonceManager.ts
CHANGED
|
@@ -14,6 +14,21 @@ type FunctionParameters = {
|
|
|
14
14
|
chainId: number
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
type ResetParameters = FunctionParameters & {
|
|
18
|
+
/**
|
|
19
|
+
* The nonce that `consume` returned for the send being reset.
|
|
20
|
+
*
|
|
21
|
+
* Set when a send fails after `consume` returned a nonce, and omitted
|
|
22
|
+
* when `consume` threw or `reset` is called outside of a send. Managers
|
|
23
|
+
* that track a nonce per send can use it to release that nonce only.
|
|
24
|
+
*
|
|
25
|
+
* A failed send does not prove the nonce is unused: the node may have
|
|
26
|
+
* accepted the transaction before the request failed (e.g. a timeout).
|
|
27
|
+
* Check the account's pending nonce before reusing a released nonce.
|
|
28
|
+
*/
|
|
29
|
+
nonce?: number | undefined
|
|
30
|
+
}
|
|
31
|
+
|
|
17
32
|
export type NonceManager = {
|
|
18
33
|
/** Get and increment a nonce. */
|
|
19
34
|
consume: (
|
|
@@ -24,7 +39,7 @@ export type NonceManager = {
|
|
|
24
39
|
/** Get a nonce. */
|
|
25
40
|
get: (chainId: FunctionParameters & { client: Client }) => Promise<number>
|
|
26
41
|
/** Reset a nonce. */
|
|
27
|
-
reset: (chainId:
|
|
42
|
+
reset: (chainId: ResetParameters) => void
|
|
28
43
|
}
|
|
29
44
|
|
|
30
45
|
/**
|
package/utils/rpc/http.ts
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
} from '../../errors/utils.js'
|
|
16
16
|
import type { RpcRequest, RpcResponse } from '../../types/rpc.js'
|
|
17
17
|
import type { MaybePromise } from '../../types/utils.js'
|
|
18
|
+
import { anySignal, readResponseBody } from '../internal/http.js'
|
|
18
19
|
import {
|
|
19
20
|
type WithTimeoutErrorType,
|
|
20
21
|
withTimeout,
|
|
@@ -241,89 +242,6 @@ export function getHttpRpcClient(
|
|
|
241
242
|
}
|
|
242
243
|
}
|
|
243
244
|
|
|
244
|
-
/**
|
|
245
|
-
* Returns a signal that aborts as soon as any of `signals` aborts, and a
|
|
246
|
-
* `cleanup` function that detaches the listeners added to `signals`.
|
|
247
|
-
*/
|
|
248
|
-
function anySignal(signals: readonly (AbortSignal | null | undefined)[]) {
|
|
249
|
-
const signals_ = signals.filter((signal) => !!signal)
|
|
250
|
-
if (signals_.length < 2)
|
|
251
|
-
return { signal: signals_[0] ?? null, cleanup: () => {} }
|
|
252
|
-
|
|
253
|
-
const controller = new AbortController()
|
|
254
|
-
const onAbort = () => {
|
|
255
|
-
cleanup()
|
|
256
|
-
controller.abort(signals_.find((signal) => signal.aborted)?.reason)
|
|
257
|
-
}
|
|
258
|
-
const cleanup = () => {
|
|
259
|
-
for (const signal of signals_) signal.removeEventListener('abort', onAbort)
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
for (const signal of signals_) {
|
|
263
|
-
if (signal.aborted) {
|
|
264
|
-
cleanup()
|
|
265
|
-
controller.abort(signal.reason)
|
|
266
|
-
break
|
|
267
|
-
}
|
|
268
|
-
signal.addEventListener('abort', onAbort)
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
return { signal: controller.signal, cleanup }
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
async function readResponseBody(
|
|
275
|
-
response: Response,
|
|
276
|
-
{ maxResponseBodySize }: { maxResponseBodySize: number | false },
|
|
277
|
-
): Promise<string> {
|
|
278
|
-
if (maxResponseBodySize === false) return response.text()
|
|
279
|
-
|
|
280
|
-
const contentLength = response.headers.get('Content-Length')
|
|
281
|
-
if (contentLength) {
|
|
282
|
-
const size = Number(contentLength)
|
|
283
|
-
if (size > maxResponseBodySize)
|
|
284
|
-
throw new ResponseBodyTooLargeError({
|
|
285
|
-
maxSize: maxResponseBodySize,
|
|
286
|
-
size,
|
|
287
|
-
})
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
if (!response.body) {
|
|
291
|
-
const body = await response.text()
|
|
292
|
-
const size = new TextEncoder().encode(body).length
|
|
293
|
-
if (size > maxResponseBodySize)
|
|
294
|
-
throw new ResponseBodyTooLargeError({
|
|
295
|
-
maxSize: maxResponseBodySize,
|
|
296
|
-
size,
|
|
297
|
-
})
|
|
298
|
-
return body
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
const reader = response.body.getReader()
|
|
302
|
-
const decoder = new TextDecoder()
|
|
303
|
-
let body = ''
|
|
304
|
-
let size = 0
|
|
305
|
-
|
|
306
|
-
try {
|
|
307
|
-
while (true) {
|
|
308
|
-
const { done, value } = await reader.read()
|
|
309
|
-
if (done) break
|
|
310
|
-
size += value.byteLength
|
|
311
|
-
if (size > maxResponseBodySize) {
|
|
312
|
-
await reader.cancel()
|
|
313
|
-
throw new ResponseBodyTooLargeError({
|
|
314
|
-
maxSize: maxResponseBodySize,
|
|
315
|
-
size,
|
|
316
|
-
})
|
|
317
|
-
}
|
|
318
|
-
body += decoder.decode(value, { stream: true })
|
|
319
|
-
}
|
|
320
|
-
body += decoder.decode()
|
|
321
|
-
return body
|
|
322
|
-
} finally {
|
|
323
|
-
reader.releaseLock()
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
|
|
327
245
|
function isRpcError(data: any) {
|
|
328
246
|
return (
|
|
329
247
|
typeof data?.error?.code === 'number' &&
|
|
@@ -42,8 +42,8 @@ export function assertRequest(args: AssertRequestParameters) {
|
|
|
42
42
|
if (maxFeePerGas && maxFeePerGas > maxUint256)
|
|
43
43
|
throw new FeeCapTooHighError({ maxFeePerGas })
|
|
44
44
|
if (
|
|
45
|
-
maxPriorityFeePerGas &&
|
|
46
|
-
maxFeePerGas &&
|
|
45
|
+
typeof maxPriorityFeePerGas === 'bigint' &&
|
|
46
|
+
typeof maxFeePerGas === 'bigint' &&
|
|
47
47
|
maxPriorityFeePerGas > maxFeePerGas
|
|
48
48
|
)
|
|
49
49
|
throw new TipAboveFeeCapError({ maxFeePerGas, maxPriorityFeePerGas })
|
|
@@ -103,8 +103,8 @@ export function assertTransactionEIP1559(
|
|
|
103
103
|
if (maxFeePerGas && maxFeePerGas > maxUint256)
|
|
104
104
|
throw new FeeCapTooHighError({ maxFeePerGas })
|
|
105
105
|
if (
|
|
106
|
-
maxPriorityFeePerGas &&
|
|
107
|
-
maxFeePerGas &&
|
|
106
|
+
typeof maxPriorityFeePerGas === 'bigint' &&
|
|
107
|
+
typeof maxFeePerGas === 'bigint' &&
|
|
108
108
|
maxPriorityFeePerGas > maxFeePerGas
|
|
109
109
|
)
|
|
110
110
|
throw new TipAboveFeeCapError({ maxFeePerGas, maxPriorityFeePerGas })
|
|
@@ -188,10 +188,14 @@ function parseTransactionEIP7702(
|
|
|
188
188
|
if (isHex(data) && data !== '0x') transaction.data = data
|
|
189
189
|
if (isHex(nonce)) transaction.nonce = nonce === '0x' ? 0 : hexToNumber(nonce)
|
|
190
190
|
if (isHex(value) && value !== '0x') transaction.value = hexToBigInt(value)
|
|
191
|
-
if (isHex(maxFeePerGas) && maxFeePerGas !== '0x')
|
|
192
|
-
transaction.maxFeePerGas = hexToBigInt(maxFeePerGas)
|
|
193
191
|
if (isHex(maxPriorityFeePerGas) && maxPriorityFeePerGas !== '0x')
|
|
194
192
|
transaction.maxPriorityFeePerGas = hexToBigInt(maxPriorityFeePerGas)
|
|
193
|
+
if (
|
|
194
|
+
isHex(maxFeePerGas) &&
|
|
195
|
+
(maxFeePerGas !== '0x' || transaction.maxPriorityFeePerGas)
|
|
196
|
+
)
|
|
197
|
+
transaction.maxFeePerGas =
|
|
198
|
+
maxFeePerGas === '0x' ? 0n : hexToBigInt(maxFeePerGas)
|
|
195
199
|
if (accessList.length !== 0 && accessList !== '0x')
|
|
196
200
|
transaction.accessList = parseAccessList(accessList as RecursiveArray<Hex>)
|
|
197
201
|
if (authorizationList.length !== 0 && authorizationList !== '0x')
|
|
@@ -289,10 +293,14 @@ function parseTransactionEIP4844(
|
|
|
289
293
|
if (isHex(value) && value !== '0x') transaction.value = hexToBigInt(value)
|
|
290
294
|
if (isHex(maxFeePerBlobGas) && maxFeePerBlobGas !== '0x')
|
|
291
295
|
transaction.maxFeePerBlobGas = hexToBigInt(maxFeePerBlobGas)
|
|
292
|
-
if (isHex(maxFeePerGas) && maxFeePerGas !== '0x')
|
|
293
|
-
transaction.maxFeePerGas = hexToBigInt(maxFeePerGas)
|
|
294
296
|
if (isHex(maxPriorityFeePerGas) && maxPriorityFeePerGas !== '0x')
|
|
295
297
|
transaction.maxPriorityFeePerGas = hexToBigInt(maxPriorityFeePerGas)
|
|
298
|
+
if (
|
|
299
|
+
isHex(maxFeePerGas) &&
|
|
300
|
+
(maxFeePerGas !== '0x' || transaction.maxPriorityFeePerGas)
|
|
301
|
+
)
|
|
302
|
+
transaction.maxFeePerGas =
|
|
303
|
+
maxFeePerGas === '0x' ? 0n : hexToBigInt(maxFeePerGas)
|
|
296
304
|
if (accessList.length !== 0 && accessList !== '0x')
|
|
297
305
|
transaction.accessList = parseAccessList(accessList as RecursiveArray<Hex>)
|
|
298
306
|
if (blobs && commitments && proofs)
|
|
@@ -378,10 +386,14 @@ function parseTransactionEIP1559(
|
|
|
378
386
|
if (isHex(data) && data !== '0x') transaction.data = data
|
|
379
387
|
if (isHex(nonce)) transaction.nonce = nonce === '0x' ? 0 : hexToNumber(nonce)
|
|
380
388
|
if (isHex(value) && value !== '0x') transaction.value = hexToBigInt(value)
|
|
381
|
-
if (isHex(maxFeePerGas) && maxFeePerGas !== '0x')
|
|
382
|
-
transaction.maxFeePerGas = hexToBigInt(maxFeePerGas)
|
|
383
389
|
if (isHex(maxPriorityFeePerGas) && maxPriorityFeePerGas !== '0x')
|
|
384
390
|
transaction.maxPriorityFeePerGas = hexToBigInt(maxPriorityFeePerGas)
|
|
391
|
+
if (
|
|
392
|
+
isHex(maxFeePerGas) &&
|
|
393
|
+
(maxFeePerGas !== '0x' || transaction.maxPriorityFeePerGas)
|
|
394
|
+
)
|
|
395
|
+
transaction.maxFeePerGas =
|
|
396
|
+
maxFeePerGas === '0x' ? 0n : hexToBigInt(maxFeePerGas)
|
|
385
397
|
if (accessList.length !== 0 && accessList !== '0x')
|
|
386
398
|
transaction.accessList = parseAccessList(accessList as RecursiveArray<Hex>)
|
|
387
399
|
|
|
@@ -583,11 +595,24 @@ function parseAuthorizationList(
|
|
|
583
595
|
const [chainId, address, nonce, yParity, r, s] =
|
|
584
596
|
serializedAuthorizationList[i]
|
|
585
597
|
|
|
598
|
+
// EIP-7702 permits any `y_parity` below 2**8 in an authorization tuple, and a
|
|
599
|
+
// tuple that fails recovery does not invalidate the transaction. Keep such a
|
|
600
|
+
// `yParity` as is, so that the transaction parses and re-serializes unchanged.
|
|
601
|
+
const yParity_ = yParity === '0x' ? 0n : hexToBigInt(yParity)
|
|
602
|
+
const signature =
|
|
603
|
+
yParity_ > 1n && yParity_ < 256n
|
|
604
|
+
? {
|
|
605
|
+
r: padHex(r, { size: 32 }),
|
|
606
|
+
s: padHex(s, { size: 32 }),
|
|
607
|
+
yParity: Number(yParity_),
|
|
608
|
+
}
|
|
609
|
+
: parseEIP155Signature([yParity, r, s])
|
|
610
|
+
|
|
586
611
|
authorizationList.push({
|
|
587
612
|
address,
|
|
588
613
|
chainId: chainId === '0x' ? 0 : hexToNumber(chainId),
|
|
589
614
|
nonce: nonce === '0x' ? 0 : hexToNumber(nonce),
|
|
590
|
-
...
|
|
615
|
+
...signature,
|
|
591
616
|
})
|
|
592
617
|
}
|
|
593
618
|
return authorizationList
|
package/utils/typedData.ts
CHANGED
|
@@ -87,10 +87,6 @@ export function validateTypedData<
|
|
|
87
87
|
const { name, type } = param
|
|
88
88
|
const value = data[name]
|
|
89
89
|
|
|
90
|
-
const baseType = type.replace(/(\[[0-9]*\])+$/, '')
|
|
91
|
-
if (baseType === 'int' || baseType === 'uint')
|
|
92
|
-
throw new InvalidTypedDataTypeError({ type })
|
|
93
|
-
|
|
94
90
|
const integerMatch = type.match(integerRegex)
|
|
95
91
|
if (
|
|
96
92
|
integerMatch &&
|
|
@@ -118,14 +114,16 @@ export function validateTypedData<
|
|
|
118
114
|
})
|
|
119
115
|
}
|
|
120
116
|
|
|
121
|
-
|
|
122
|
-
|
|
117
|
+
if (Object.hasOwn(types, type))
|
|
118
|
+
validateData(types[type]!, value as Record<string, unknown>)
|
|
123
119
|
}
|
|
124
120
|
}
|
|
125
121
|
|
|
126
|
-
// Validate struct types, including
|
|
127
|
-
// elements.
|
|
122
|
+
// Validate struct types and their field types, including structs that are
|
|
123
|
+
// only referenced as array elements.
|
|
128
124
|
for (const type of Object.keys(types)) validateReference(type)
|
|
125
|
+
for (const struct of Object.values(types))
|
|
126
|
+
for (const field of struct ?? []) validateField(field.type, types)
|
|
129
127
|
|
|
130
128
|
// Validate domain types.
|
|
131
129
|
if (types.EIP712Domain && domain) {
|
|
@@ -177,6 +175,31 @@ export function domainSeparator({ domain }: { domain: TypedDataDomain }): Hex {
|
|
|
177
175
|
})
|
|
178
176
|
}
|
|
179
177
|
|
|
178
|
+
/** @internal */
|
|
179
|
+
function validateField(
|
|
180
|
+
type: string,
|
|
181
|
+
types: Record<string, readonly TypedDataParameter[]>,
|
|
182
|
+
) {
|
|
183
|
+
const baseType = type.replace(/(\[[0-9]*\])+$/, '')
|
|
184
|
+
if (baseType === 'int' || baseType === 'uint')
|
|
185
|
+
throw new InvalidTypedDataTypeError({ type })
|
|
186
|
+
// A field type must be a struct defined in `types` or an EIP-712 atomic or
|
|
187
|
+
// dynamic type, so a type such as `uint7` or `bytes0` is not hashed.
|
|
188
|
+
if (!Object.hasOwn(types, baseType) && !isSolidityType(baseType))
|
|
189
|
+
throw new InvalidTypedDataTypeError({ type })
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** @internal */
|
|
193
|
+
function isSolidityType(type: string) {
|
|
194
|
+
return (
|
|
195
|
+
type === 'address' ||
|
|
196
|
+
type === 'bool' ||
|
|
197
|
+
type === 'string' ||
|
|
198
|
+
bytesRegex.test(type) ||
|
|
199
|
+
integerRegex.test(type)
|
|
200
|
+
)
|
|
201
|
+
}
|
|
202
|
+
|
|
180
203
|
/** @internal */
|
|
181
204
|
function validateReference(type: string) {
|
|
182
205
|
// Struct type must contain only letters, digits, `_` and `$`, and must not be
|