viem 2.24.0 → 2.24.1
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 +8 -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/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/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/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/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
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
|
})
|