viem 2.24.0 → 2.24.2
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 +14 -0
- package/_cjs/accounts/utils/signAuthorization.js +3 -3
- package/_cjs/accounts/utils/signAuthorization.js.map +1 -1
- package/_cjs/actions/public/estimateGas.js +2 -2
- package/_cjs/actions/public/estimateGas.js.map +1 -1
- package/_cjs/actions/wallet/prepareAuthorization.js +12 -3
- package/_cjs/actions/wallet/prepareAuthorization.js.map +1 -1
- package/_cjs/errors/version.js +1 -1
- package/_cjs/experimental/erc7821/actions/execute.js +1 -1
- package/_cjs/experimental/erc7821/actions/execute.js.map +1 -1
- package/_cjs/experimental/erc7821/actions/executeBatches.js +1 -1
- package/_cjs/experimental/erc7821/actions/executeBatches.js.map +1 -1
- package/_cjs/experimental/index.js +15 -1
- package/_cjs/experimental/index.js.map +1 -1
- package/_cjs/utils/authorization/hashAuthorization.js +2 -2
- package/_cjs/utils/authorization/hashAuthorization.js.map +1 -1
- package/_cjs/utils/authorization/recoverAuthorizationAddress.js.map +1 -1
- package/_cjs/utils/authorization/serializeAuthorizationList.js +1 -1
- package/_cjs/utils/authorization/serializeAuthorizationList.js.map +1 -1
- package/_cjs/utils/formatters/transaction.js +1 -1
- package/_cjs/utils/formatters/transaction.js.map +1 -1
- package/_cjs/utils/formatters/transactionRequest.js +1 -1
- package/_cjs/utils/formatters/transactionRequest.js.map +1 -1
- package/_cjs/utils/transaction/assertTransaction.js +1 -1
- package/_cjs/utils/transaction/assertTransaction.js.map +1 -1
- package/_cjs/utils/transaction/parseTransaction.js +2 -2
- package/_cjs/utils/transaction/parseTransaction.js.map +1 -1
- package/_esm/accounts/utils/signAuthorization.js +3 -3
- package/_esm/accounts/utils/signAuthorization.js.map +1 -1
- package/_esm/actions/public/estimateGas.js +2 -2
- package/_esm/actions/public/estimateGas.js.map +1 -1
- package/_esm/actions/wallet/prepareAuthorization.js +12 -3
- package/_esm/actions/wallet/prepareAuthorization.js.map +1 -1
- package/_esm/errors/version.js +1 -1
- package/_esm/experimental/erc7821/actions/execute.js +1 -1
- package/_esm/experimental/erc7821/actions/execute.js.map +1 -1
- package/_esm/experimental/erc7821/actions/executeBatches.js +1 -1
- package/_esm/experimental/erc7821/actions/executeBatches.js.map +1 -1
- package/_esm/experimental/index.js +23 -0
- package/_esm/experimental/index.js.map +1 -1
- package/_esm/utils/authorization/hashAuthorization.js +2 -2
- package/_esm/utils/authorization/hashAuthorization.js.map +1 -1
- package/_esm/utils/authorization/recoverAuthorizationAddress.js.map +1 -1
- package/_esm/utils/authorization/serializeAuthorizationList.js +1 -1
- package/_esm/utils/authorization/serializeAuthorizationList.js.map +1 -1
- package/_esm/utils/formatters/transaction.js +1 -1
- package/_esm/utils/formatters/transaction.js.map +1 -1
- package/_esm/utils/formatters/transactionRequest.js +1 -1
- package/_esm/utils/formatters/transactionRequest.js.map +1 -1
- package/_esm/utils/transaction/assertTransaction.js +1 -1
- package/_esm/utils/transaction/assertTransaction.js.map +1 -1
- package/_esm/utils/transaction/parseTransaction.js +2 -2
- package/_esm/utils/transaction/parseTransaction.js.map +1 -1
- package/_types/accounts/types.d.ts +2 -2
- package/_types/accounts/types.d.ts.map +1 -1
- package/_types/accounts/utils/signAuthorization.d.ts +2 -2
- package/_types/accounts/utils/signAuthorization.d.ts.map +1 -1
- package/_types/actions/wallet/prepareAuthorization.d.ts +4 -3
- package/_types/actions/wallet/prepareAuthorization.d.ts.map +1 -1
- package/_types/errors/version.d.ts +1 -1
- package/_types/experimental/index.d.ts +75 -0
- package/_types/experimental/index.d.ts.map +1 -1
- package/_types/types/authorization.d.ts +14 -6
- package/_types/types/authorization.d.ts.map +1 -1
- package/_types/utils/authorization/hashAuthorization.d.ts +2 -2
- package/_types/utils/authorization/hashAuthorization.d.ts.map +1 -1
- package/_types/utils/authorization/recoverAuthorizationAddress.d.ts +4 -4
- package/_types/utils/authorization/recoverAuthorizationAddress.d.ts.map +1 -1
- package/_types/utils/authorization/serializeAuthorizationList.d.ts.map +1 -1
- package/accounts/types.ts +4 -2
- package/accounts/utils/signAuthorization.ts +5 -5
- package/actions/public/estimateGas.ts +2 -2
- package/actions/wallet/prepareAuthorization.ts +21 -11
- package/errors/version.ts +1 -1
- package/experimental/erc7821/actions/execute.ts +1 -1
- package/experimental/erc7821/actions/executeBatches.ts +1 -1
- package/experimental/index.ts +85 -0
- package/package.json +1 -1
- package/types/authorization.ts +18 -12
- package/utils/authorization/hashAuthorization.ts +8 -7
- package/utils/authorization/recoverAuthorizationAddress.ts +11 -6
- package/utils/authorization/serializeAuthorizationList.ts +1 -2
- package/utils/formatters/transaction.ts +1 -1
- package/utils/formatters/transactionRequest.ts +1 -1
- package/utils/transaction/assertTransaction.ts +1 -1
- package/utils/transaction/parseTransaction.ts +2 -2
@@ -1,6 +1,6 @@
|
|
1
1
|
import type { ErrorType } from '../../errors/utils.js'
|
2
2
|
import type {
|
3
|
-
|
3
|
+
AuthorizationRequest,
|
4
4
|
SignedAuthorization,
|
5
5
|
} from '../../types/authorization.js'
|
6
6
|
import type { Hex, Signature } from '../../types/misc.js'
|
@@ -19,7 +19,7 @@ import {
|
|
19
19
|
type To = 'object' | 'bytes' | 'hex'
|
20
20
|
|
21
21
|
export type SignAuthorizationParameters<to extends To = 'object'> =
|
22
|
-
|
22
|
+
AuthorizationRequest & {
|
23
23
|
/** The private key to sign with. */
|
24
24
|
privateKey: Hex
|
25
25
|
to?: SignParameters<to>['to'] | undefined
|
@@ -41,15 +41,15 @@ export async function signAuthorization<to extends To = 'object'>(
|
|
41
41
|
parameters: SignAuthorizationParameters<to>,
|
42
42
|
): Promise<SignAuthorizationReturnType<to>> {
|
43
43
|
const { chainId, nonce, privateKey, to = 'object' } = parameters
|
44
|
-
const
|
44
|
+
const address = parameters.contractAddress ?? parameters.address
|
45
45
|
const signature = await sign({
|
46
|
-
hash: hashAuthorization({
|
46
|
+
hash: hashAuthorization({ address, chainId, nonce }),
|
47
47
|
privateKey,
|
48
48
|
to,
|
49
49
|
})
|
50
50
|
if (to === 'object')
|
51
51
|
return {
|
52
|
-
|
52
|
+
address,
|
53
53
|
chainId,
|
54
54
|
nonce,
|
55
55
|
...(signature as Signature),
|
@@ -211,14 +211,14 @@ export async function estimateGas<
|
|
211
211
|
const value = await getBalance(client, { address: request.from })
|
212
212
|
const estimates = await Promise.all(
|
213
213
|
authorizationList.map(async (authorization) => {
|
214
|
-
const {
|
214
|
+
const { address } = authorization
|
215
215
|
const estimate = await estimateGas_rpc({
|
216
216
|
block,
|
217
217
|
request: {
|
218
218
|
authorizationList: undefined,
|
219
219
|
data,
|
220
220
|
from: account?.address,
|
221
|
-
to:
|
221
|
+
to: address,
|
222
222
|
value: numberToHex(value),
|
223
223
|
},
|
224
224
|
rpcStateOverride,
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import type { Address } from 'abitype'
|
1
2
|
import type { Account } from '../../accounts/types.js'
|
2
3
|
import {
|
3
4
|
type ParseAccountErrorType,
|
@@ -11,9 +12,13 @@ import {
|
|
11
12
|
} from '../../errors/account.js'
|
12
13
|
import type { ErrorType } from '../../errors/utils.js'
|
13
14
|
import type { GetAccountParameter } from '../../types/account.js'
|
14
|
-
import type {
|
15
|
+
import type {
|
16
|
+
Authorization,
|
17
|
+
AuthorizationRequest,
|
18
|
+
} from '../../types/authorization.js'
|
15
19
|
import type { Chain } from '../../types/chain.js'
|
16
20
|
import type { PartialBy } from '../../types/utils.js'
|
21
|
+
import { isAddressEqual } from '../../utils/address/isAddressEqual.js'
|
17
22
|
import type { RequestErrorType } from '../../utils/buildRequest.js'
|
18
23
|
import { getAction } from '../../utils/getAction.js'
|
19
24
|
import { getChainId } from '../public/getChainId.js'
|
@@ -22,14 +27,14 @@ import { getTransactionCount } from '../public/getTransactionCount.js'
|
|
22
27
|
export type PrepareAuthorizationParameters<
|
23
28
|
account extends Account | undefined = Account | undefined,
|
24
29
|
> = GetAccountParameter<account> &
|
25
|
-
PartialBy<
|
30
|
+
PartialBy<AuthorizationRequest, 'chainId' | 'nonce'> & {
|
26
31
|
/**
|
27
32
|
* Whether the EIP-7702 Transaction will be executed by the EOA (signing this Authorization) or another Account.
|
28
33
|
*
|
29
34
|
* By default, it will be assumed that the EIP-7702 Transaction will
|
30
35
|
* be executed by another Account.
|
31
36
|
*/
|
32
|
-
executor?: 'self' | undefined
|
37
|
+
executor?: 'self' | Account | Address | undefined
|
33
38
|
}
|
34
39
|
|
35
40
|
export type PrepareAuthorizationReturnType = Authorization
|
@@ -88,12 +93,7 @@ export async function prepareAuthorization<
|
|
88
93
|
client: Client<Transport, chain, account>,
|
89
94
|
parameters: PrepareAuthorizationParameters<account>,
|
90
95
|
): Promise<PrepareAuthorizationReturnType> {
|
91
|
-
const {
|
92
|
-
account: account_ = client.account,
|
93
|
-
chainId,
|
94
|
-
executor,
|
95
|
-
nonce,
|
96
|
-
} = parameters
|
96
|
+
const { account: account_ = client.account, chainId, nonce } = parameters
|
97
97
|
|
98
98
|
if (!account_)
|
99
99
|
throw new AccountNotFoundError({
|
@@ -101,8 +101,14 @@ export async function prepareAuthorization<
|
|
101
101
|
})
|
102
102
|
const account = parseAccount(account_)
|
103
103
|
|
104
|
+
const executor = (() => {
|
105
|
+
if (!parameters.executor) return undefined
|
106
|
+
if (parameters.executor === 'self') return parameters.executor
|
107
|
+
return parseAccount(parameters.executor)
|
108
|
+
})()
|
109
|
+
|
104
110
|
const authorization = {
|
105
|
-
|
111
|
+
address: parameters.contractAddress ?? parameters.address,
|
106
112
|
chainId,
|
107
113
|
nonce,
|
108
114
|
} as Authorization
|
@@ -121,7 +127,11 @@ export async function prepareAuthorization<
|
|
121
127
|
address: account.address,
|
122
128
|
blockTag: 'pending',
|
123
129
|
})
|
124
|
-
if (
|
130
|
+
if (
|
131
|
+
executor === 'self' ||
|
132
|
+
(executor?.address && isAddressEqual(executor.address, account.address))
|
133
|
+
)
|
134
|
+
authorization.nonce += 1
|
125
135
|
}
|
126
136
|
|
127
137
|
return authorization
|
package/errors/version.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const version = '2.24.
|
1
|
+
export const version = '2.24.2'
|
@@ -144,7 +144,7 @@ export async function execute<
|
|
144
144
|
): Promise<ExecuteReturnType> {
|
145
145
|
const { authorizationList, calls, opData } = parameters
|
146
146
|
|
147
|
-
const address = authorizationList?.[0]?.
|
147
|
+
const address = authorizationList?.[0]?.address ?? parameters.address
|
148
148
|
const mode = opData ? executionMode.opData : executionMode.default
|
149
149
|
|
150
150
|
const supported = await withCache(
|
@@ -167,7 +167,7 @@ export async function executeBatches<
|
|
167
167
|
): Promise<ExecuteBatchesReturnType> {
|
168
168
|
const { authorizationList, batches } = parameters
|
169
169
|
|
170
|
-
const address = authorizationList?.[0]?.
|
170
|
+
const address = authorizationList?.[0]?.address ?? parameters.address
|
171
171
|
|
172
172
|
const supported = await withCache(
|
173
173
|
() =>
|
package/experimental/index.ts
CHANGED
@@ -43,6 +43,91 @@ export {
|
|
43
43
|
eip5792Actions,
|
44
44
|
} from './eip5792/decorators/eip5792.js'
|
45
45
|
|
46
|
+
export {
|
47
|
+
/** @deprecated This is no longer experimental – use `import type { WalletActions } from 'viem'` instead. */
|
48
|
+
type WalletActions as Eip7702Actions,
|
49
|
+
/** @deprecated This is no longer experimental – use `import { createWalletClient } from 'viem'` or `import { walletActions } from 'viem'` instead. */
|
50
|
+
walletActions as eip7702Actions,
|
51
|
+
} from '../clients/decorators/wallet.js'
|
52
|
+
export {
|
53
|
+
/** @deprecated This is no longer experimental – use `import type { PrepareAuthorizationParameters } from 'viem/actions'` instead. */
|
54
|
+
type PrepareAuthorizationParameters,
|
55
|
+
/** @deprecated This is no longer experimental – use `import type { PrepareAuthorizationReturnType } from 'viem/actions'` instead. */
|
56
|
+
type PrepareAuthorizationReturnType,
|
57
|
+
/** @deprecated This is no longer experimental – use `import type { PrepareAuthorizationErrorType } from 'viem/actions'` instead. */
|
58
|
+
type PrepareAuthorizationErrorType,
|
59
|
+
/** @deprecated This is no longer experimental – use `import { prepareAuthorization } from 'viem/actions'` instead. */
|
60
|
+
prepareAuthorization,
|
61
|
+
} from '../actions/wallet/prepareAuthorization.js'
|
62
|
+
export {
|
63
|
+
/** @deprecated This is no longer experimental – use `import type { SignAuthorizationParameters } from 'viem/actions'` instead. */
|
64
|
+
type SignAuthorizationParameters,
|
65
|
+
/** @deprecated This is no longer experimental – use `import type { SignAuthorizationReturnType } from 'viem/actions'` instead. */
|
66
|
+
type SignAuthorizationReturnType,
|
67
|
+
/** @deprecated This is no longer experimental – use `import type { SignAuthorizationErrorType } from 'viem/actions'` instead. */
|
68
|
+
type SignAuthorizationErrorType,
|
69
|
+
/** @deprecated This is no longer experimental – use `import { signAuthorization } from 'viem/actions'` instead. */
|
70
|
+
signAuthorization,
|
71
|
+
} from '../actions/wallet/signAuthorization.js'
|
72
|
+
export {
|
73
|
+
/** @deprecated This is no longer experimental – use `import type { Authorization } from 'viem'` instead. */
|
74
|
+
type Authorization,
|
75
|
+
/** @deprecated This is no longer experimental – use `import type { SignedAuthorization } from 'viem'` instead. */
|
76
|
+
type SignedAuthorization,
|
77
|
+
/** @deprecated This is no longer experimental – use `import type { AuthorizationList } from 'viem'` instead. */
|
78
|
+
type AuthorizationList,
|
79
|
+
/** @deprecated This is no longer experimental – use `import type { SignedAuthorizationList } from 'viem'` instead. */
|
80
|
+
type SignedAuthorizationList,
|
81
|
+
/** @deprecated This is no longer experimental – use `import type { SerializedAuthorization } from 'viem'` instead. */
|
82
|
+
type SerializedAuthorization,
|
83
|
+
/** @deprecated This is no longer experimental – use `import type { SerializedAuthorizationList } from 'viem'` instead. */
|
84
|
+
type SerializedAuthorizationList,
|
85
|
+
} from '../types/authorization.js'
|
86
|
+
export {
|
87
|
+
/** @deprecated This is no longer experimental – use `import type { RpcAuthorizationList } from 'viem'` instead. */
|
88
|
+
type RpcAuthorizationList,
|
89
|
+
/** @deprecated This is no longer experimental – use `import type { RpcAuthorization } from 'viem'` instead. */
|
90
|
+
type RpcAuthorization,
|
91
|
+
} from '../types/rpc.js'
|
92
|
+
export {
|
93
|
+
/** @deprecated This is no longer experimental – use `import type { HashAuthorizationParameters } from 'viem/utils'` instead. */
|
94
|
+
type HashAuthorizationParameters,
|
95
|
+
/** @deprecated This is no longer experimental – use `import type { HashAuthorizationReturnType } from 'viem/utils'` instead. */
|
96
|
+
type HashAuthorizationReturnType,
|
97
|
+
/** @deprecated This is no longer experimental – use `import type { HashAuthorizationErrorType } from 'viem/utils'` instead. */
|
98
|
+
type HashAuthorizationErrorType,
|
99
|
+
/** @deprecated This is no longer experimental – use `import { hashAuthorization } from 'viem/utils'` instead. */
|
100
|
+
hashAuthorization,
|
101
|
+
} from '../utils/authorization/hashAuthorization.js'
|
102
|
+
export {
|
103
|
+
/** @deprecated This is no longer experimental – use `import type { RecoverAuthorizationAddressParameters } from 'viem/utils'` instead. */
|
104
|
+
type RecoverAuthorizationAddressParameters,
|
105
|
+
/** @deprecated This is no longer experimental – use `import type { RecoverAuthorizationAddressReturnType } from 'viem/utils'` instead. */
|
106
|
+
type RecoverAuthorizationAddressReturnType,
|
107
|
+
/** @deprecated This is no longer experimental – use `import type { RecoverAuthorizationAddressErrorType } from 'viem/utils'` instead. */
|
108
|
+
type RecoverAuthorizationAddressErrorType,
|
109
|
+
/** @deprecated This is no longer experimental – use `import { recoverAuthorizationAddress } from 'viem/utils'` instead. */
|
110
|
+
recoverAuthorizationAddress,
|
111
|
+
} from '../utils/authorization/recoverAuthorizationAddress.js'
|
112
|
+
export {
|
113
|
+
/** @deprecated This is no longer experimental – use `import type { SerializeAuthorizationListReturnType } from 'viem/utils'` instead. */
|
114
|
+
type SerializeAuthorizationListReturnType,
|
115
|
+
/** @deprecated This is no longer experimental – use `import type { SerializeAuthorizationListErrorType } from 'viem/utils'` instead. */
|
116
|
+
type SerializeAuthorizationListErrorType,
|
117
|
+
/** @deprecated This is no longer experimental – use `import { serializeAuthorizationList } from 'viem/utils'` instead. */
|
118
|
+
serializeAuthorizationList,
|
119
|
+
} from '../utils/authorization/serializeAuthorizationList.js'
|
120
|
+
export {
|
121
|
+
/** @deprecated This is no longer experimental – use `import type { VerifyAuthorizationParameters } from 'viem/utils'` instead. */
|
122
|
+
type VerifyAuthorizationParameters,
|
123
|
+
/** @deprecated This is no longer experimental – use `import type { VerifyAuthorizationReturnType } from 'viem/utils'` instead. */
|
124
|
+
type VerifyAuthorizationReturnType,
|
125
|
+
/** @deprecated This is no longer experimental – use `import type { VerifyAuthorizationErrorType } from 'viem/utils'` instead. */
|
126
|
+
type VerifyAuthorizationErrorType,
|
127
|
+
/** @deprecated This is no longer experimental – use `import { verifyAuthorization } from 'viem/utils'` instead. */
|
128
|
+
verifyAuthorization,
|
129
|
+
} from '../utils/authorization/verifyAuthorization.js'
|
130
|
+
|
46
131
|
export {
|
47
132
|
type GrantPermissionsParameters,
|
48
133
|
type GrantPermissionsReturnType,
|
package/package.json
CHANGED
package/types/authorization.ts
CHANGED
@@ -2,10 +2,25 @@ import type { Address } from 'abitype'
|
|
2
2
|
import type { Hex, Signature } from './misc.js'
|
3
3
|
import type { ExactPartial, OneOf } from './utils.js'
|
4
4
|
|
5
|
-
export type Authorization<
|
5
|
+
export type Authorization<uint32 = number, signed extends boolean = false> = {
|
6
|
+
/** Address of the contract to delegate to. */
|
7
|
+
address: Address
|
8
|
+
/** Chain ID. */
|
9
|
+
chainId: uint32
|
10
|
+
/** Nonce of the EOA to delegate to. */
|
11
|
+
nonce: uint32
|
12
|
+
} & (signed extends true ? Signature : ExactPartial<Signature>)
|
13
|
+
|
14
|
+
export type AuthorizationList<
|
6
15
|
uint32 = number,
|
7
16
|
signed extends boolean = false,
|
8
|
-
> =
|
17
|
+
> = readonly Authorization<uint32, signed>[]
|
18
|
+
|
19
|
+
export type AuthorizationRequest<uint32 = number> = OneOf<
|
20
|
+
| {
|
21
|
+
/** Address of the contract to delegate to. */
|
22
|
+
address: Address
|
23
|
+
}
|
9
24
|
| {
|
10
25
|
/**
|
11
26
|
* Address of the contract to delegate to.
|
@@ -13,21 +28,12 @@ export type Authorization<
|
|
13
28
|
*/
|
14
29
|
contractAddress: Address
|
15
30
|
}
|
16
|
-
| {
|
17
|
-
/** Address of the contract to delegate to. */
|
18
|
-
address: Address
|
19
|
-
}
|
20
31
|
> & {
|
21
32
|
/** Chain ID. */
|
22
33
|
chainId: uint32
|
23
34
|
/** Nonce of the EOA to delegate to. */
|
24
35
|
nonce: uint32
|
25
|
-
}
|
26
|
-
|
27
|
-
export type AuthorizationList<
|
28
|
-
uint32 = number,
|
29
|
-
signed extends boolean = false,
|
30
|
-
> = readonly Authorization<uint32, signed>[]
|
36
|
+
}
|
31
37
|
|
32
38
|
export type SignedAuthorization<uint32 = number> = Authorization<uint32, true>
|
33
39
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { ErrorType } from '../../errors/utils.js'
|
2
|
-
import type {
|
2
|
+
import type { AuthorizationRequest } from '../../types/authorization.js'
|
3
3
|
import type { ByteArray, Hex } from '../../types/misc.js'
|
4
4
|
import { type ConcatHexErrorType, concatHex } from '../data/concat.js'
|
5
5
|
import { type HexToBytesErrorType, hexToBytes } from '../encoding/toBytes.js'
|
@@ -9,10 +9,11 @@ import { type Keccak256ErrorType, keccak256 } from '../hash/keccak256.js'
|
|
9
9
|
|
10
10
|
type To = 'hex' | 'bytes'
|
11
11
|
|
12
|
-
export type HashAuthorizationParameters<to extends To> =
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
export type HashAuthorizationParameters<to extends To> =
|
13
|
+
AuthorizationRequest & {
|
14
|
+
/** Output format. @default "hex" */
|
15
|
+
to?: to | To | undefined
|
16
|
+
}
|
16
17
|
|
17
18
|
export type HashAuthorizationReturnType<to extends To> =
|
18
19
|
| (to extends 'bytes' ? ByteArray : never)
|
@@ -33,13 +34,13 @@ export function hashAuthorization<to extends To = 'hex'>(
|
|
33
34
|
parameters: HashAuthorizationParameters<to>,
|
34
35
|
): HashAuthorizationReturnType<to> {
|
35
36
|
const { chainId, nonce, to } = parameters
|
36
|
-
const
|
37
|
+
const address = parameters.contractAddress ?? parameters.address
|
37
38
|
const hash = keccak256(
|
38
39
|
concatHex([
|
39
40
|
'0x05',
|
40
41
|
toRlp([
|
41
42
|
chainId ? numberToHex(chainId) : '0x',
|
42
|
-
|
43
|
+
address,
|
43
44
|
nonce ? numberToHex(nonce) : '0x',
|
44
45
|
]),
|
45
46
|
]),
|
@@ -3,6 +3,7 @@ import type { Address } from 'abitype'
|
|
3
3
|
import type { ErrorType } from '../../errors/utils.js'
|
4
4
|
import type {
|
5
5
|
Authorization,
|
6
|
+
AuthorizationRequest,
|
6
7
|
SignedAuthorization,
|
7
8
|
} from '../../types/authorization.js'
|
8
9
|
import type { ByteArray, Hex, Signature } from '../../types/misc.js'
|
@@ -17,9 +18,9 @@ import {
|
|
17
18
|
} from './hashAuthorization.js'
|
18
19
|
|
19
20
|
export type RecoverAuthorizationAddressParameters<
|
20
|
-
authorization extends OneOf<
|
21
|
-
Authorization | SignedAuthorization
|
22
|
-
>,
|
21
|
+
authorization extends OneOf<
|
22
|
+
Authorization | AuthorizationRequest | SignedAuthorization
|
23
|
+
> = OneOf<Authorization | AuthorizationRequest | SignedAuthorization>,
|
23
24
|
//
|
24
25
|
_signature = Hex | ByteArray | OneOf<Signature | SignedAuthorization>,
|
25
26
|
> = {
|
@@ -29,7 +30,9 @@ export type RecoverAuthorizationAddressParameters<
|
|
29
30
|
* - If an unsigned `authorization` is provided, the `signature` property is required.
|
30
31
|
* - If a signed `authorization` is provided, the `signature` property does not need to be provided.
|
31
32
|
*/
|
32
|
-
authorization:
|
33
|
+
authorization:
|
34
|
+
| authorization
|
35
|
+
| OneOf<Authorization | AuthorizationRequest | SignedAuthorization>
|
33
36
|
} & (authorization extends SignedAuthorization
|
34
37
|
? {
|
35
38
|
/** Signature of the Authorization. Not required if the `authorization` is signed. */
|
@@ -48,14 +51,16 @@ export type RecoverAuthorizationAddressErrorType =
|
|
48
51
|
| ErrorType
|
49
52
|
|
50
53
|
export async function recoverAuthorizationAddress<
|
51
|
-
const authorization extends OneOf<
|
54
|
+
const authorization extends OneOf<
|
55
|
+
Authorization | AuthorizationRequest | SignedAuthorization
|
56
|
+
>,
|
52
57
|
>(
|
53
58
|
parameters: RecoverAuthorizationAddressParameters<authorization>,
|
54
59
|
): Promise<RecoverAuthorizationAddressReturnType> {
|
55
60
|
const { authorization, signature } = parameters
|
56
61
|
|
57
62
|
return recoverAddress({
|
58
|
-
hash: hashAuthorization(authorization as
|
63
|
+
hash: hashAuthorization(authorization as AuthorizationRequest),
|
59
64
|
signature: (signature ?? authorization) as Signature,
|
60
65
|
})
|
61
66
|
}
|
@@ -21,8 +21,7 @@ export function serializeAuthorizationList(
|
|
21
21
|
const serializedAuthorizationList = []
|
22
22
|
for (const authorization of authorizationList) {
|
23
23
|
const { chainId, nonce, ...signature } = authorization
|
24
|
-
const contractAddress =
|
25
|
-
authorization.contractAddress ?? authorization.address
|
24
|
+
const contractAddress = authorization.address
|
26
25
|
serializedAuthorizationList.push([
|
27
26
|
chainId ? toHex(chainId) : '0x',
|
28
27
|
contractAddress,
|
@@ -127,7 +127,7 @@ function formatAuthorizationList(
|
|
127
127
|
authorizationList: RpcAuthorizationList,
|
128
128
|
): SignedAuthorizationList {
|
129
129
|
return authorizationList.map((authorization) => ({
|
130
|
-
|
130
|
+
address: (authorization as any).address,
|
131
131
|
chainId: Number(authorization.chainId),
|
132
132
|
nonce: Number(authorization.nonce),
|
133
133
|
r: authorization.r,
|
@@ -49,7 +49,7 @@ export function assertTransactionEIP7702(
|
|
49
49
|
if (authorizationList) {
|
50
50
|
for (const authorization of authorizationList) {
|
51
51
|
const { chainId } = authorization
|
52
|
-
const address = authorization.
|
52
|
+
const address = authorization.address
|
53
53
|
if (!isAddress(address)) throw new InvalidAddressError({ address })
|
54
54
|
if (chainId < 0) throw new InvalidChainIdError({ chainId })
|
55
55
|
}
|
@@ -576,12 +576,12 @@ function parseAuthorizationList(
|
|
576
576
|
): SignedAuthorizationList {
|
577
577
|
const authorizationList: Mutable<SignedAuthorizationList> = []
|
578
578
|
for (let i = 0; i < serializedAuthorizationList.length; i++) {
|
579
|
-
const [chainId,
|
579
|
+
const [chainId, address, nonce, yParity, r, s] =
|
580
580
|
serializedAuthorizationList[i]
|
581
581
|
|
582
582
|
authorizationList.push({
|
583
|
+
address,
|
583
584
|
chainId: hexToNumber(chainId),
|
584
|
-
contractAddress,
|
585
585
|
nonce: hexToNumber(nonce),
|
586
586
|
...parseEIP155Signature([yParity, r, s]),
|
587
587
|
})
|