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.
Files changed (79) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/_cjs/accounts/utils/signAuthorization.js +3 -3
  3. package/_cjs/accounts/utils/signAuthorization.js.map +1 -1
  4. package/_cjs/actions/public/estimateGas.js +2 -2
  5. package/_cjs/actions/public/estimateGas.js.map +1 -1
  6. package/_cjs/actions/wallet/prepareAuthorization.js +12 -3
  7. package/_cjs/actions/wallet/prepareAuthorization.js.map +1 -1
  8. package/_cjs/errors/version.js +1 -1
  9. package/_cjs/experimental/erc7821/actions/execute.js +1 -1
  10. package/_cjs/experimental/erc7821/actions/execute.js.map +1 -1
  11. package/_cjs/experimental/erc7821/actions/executeBatches.js +1 -1
  12. package/_cjs/experimental/erc7821/actions/executeBatches.js.map +1 -1
  13. package/_cjs/utils/authorization/hashAuthorization.js +2 -2
  14. package/_cjs/utils/authorization/hashAuthorization.js.map +1 -1
  15. package/_cjs/utils/authorization/recoverAuthorizationAddress.js.map +1 -1
  16. package/_cjs/utils/authorization/serializeAuthorizationList.js +1 -1
  17. package/_cjs/utils/authorization/serializeAuthorizationList.js.map +1 -1
  18. package/_cjs/utils/formatters/transaction.js +1 -1
  19. package/_cjs/utils/formatters/transaction.js.map +1 -1
  20. package/_cjs/utils/formatters/transactionRequest.js +1 -1
  21. package/_cjs/utils/formatters/transactionRequest.js.map +1 -1
  22. package/_cjs/utils/transaction/assertTransaction.js +1 -1
  23. package/_cjs/utils/transaction/assertTransaction.js.map +1 -1
  24. package/_cjs/utils/transaction/parseTransaction.js +2 -2
  25. package/_cjs/utils/transaction/parseTransaction.js.map +1 -1
  26. package/_esm/accounts/utils/signAuthorization.js +3 -3
  27. package/_esm/accounts/utils/signAuthorization.js.map +1 -1
  28. package/_esm/actions/public/estimateGas.js +2 -2
  29. package/_esm/actions/public/estimateGas.js.map +1 -1
  30. package/_esm/actions/wallet/prepareAuthorization.js +12 -3
  31. package/_esm/actions/wallet/prepareAuthorization.js.map +1 -1
  32. package/_esm/errors/version.js +1 -1
  33. package/_esm/experimental/erc7821/actions/execute.js +1 -1
  34. package/_esm/experimental/erc7821/actions/execute.js.map +1 -1
  35. package/_esm/experimental/erc7821/actions/executeBatches.js +1 -1
  36. package/_esm/experimental/erc7821/actions/executeBatches.js.map +1 -1
  37. package/_esm/utils/authorization/hashAuthorization.js +2 -2
  38. package/_esm/utils/authorization/hashAuthorization.js.map +1 -1
  39. package/_esm/utils/authorization/recoverAuthorizationAddress.js.map +1 -1
  40. package/_esm/utils/authorization/serializeAuthorizationList.js +1 -1
  41. package/_esm/utils/authorization/serializeAuthorizationList.js.map +1 -1
  42. package/_esm/utils/formatters/transaction.js +1 -1
  43. package/_esm/utils/formatters/transaction.js.map +1 -1
  44. package/_esm/utils/formatters/transactionRequest.js +1 -1
  45. package/_esm/utils/formatters/transactionRequest.js.map +1 -1
  46. package/_esm/utils/transaction/assertTransaction.js +1 -1
  47. package/_esm/utils/transaction/assertTransaction.js.map +1 -1
  48. package/_esm/utils/transaction/parseTransaction.js +2 -2
  49. package/_esm/utils/transaction/parseTransaction.js.map +1 -1
  50. package/_types/accounts/types.d.ts +2 -2
  51. package/_types/accounts/types.d.ts.map +1 -1
  52. package/_types/accounts/utils/signAuthorization.d.ts +2 -2
  53. package/_types/accounts/utils/signAuthorization.d.ts.map +1 -1
  54. package/_types/actions/wallet/prepareAuthorization.d.ts +4 -3
  55. package/_types/actions/wallet/prepareAuthorization.d.ts.map +1 -1
  56. package/_types/errors/version.d.ts +1 -1
  57. package/_types/types/authorization.d.ts +14 -6
  58. package/_types/types/authorization.d.ts.map +1 -1
  59. package/_types/utils/authorization/hashAuthorization.d.ts +2 -2
  60. package/_types/utils/authorization/hashAuthorization.d.ts.map +1 -1
  61. package/_types/utils/authorization/recoverAuthorizationAddress.d.ts +4 -4
  62. package/_types/utils/authorization/recoverAuthorizationAddress.d.ts.map +1 -1
  63. package/_types/utils/authorization/serializeAuthorizationList.d.ts.map +1 -1
  64. package/accounts/types.ts +4 -2
  65. package/accounts/utils/signAuthorization.ts +5 -5
  66. package/actions/public/estimateGas.ts +2 -2
  67. package/actions/wallet/prepareAuthorization.ts +21 -11
  68. package/errors/version.ts +1 -1
  69. package/experimental/erc7821/actions/execute.ts +1 -1
  70. package/experimental/erc7821/actions/executeBatches.ts +1 -1
  71. package/package.json +1 -1
  72. package/types/authorization.ts +18 -12
  73. package/utils/authorization/hashAuthorization.ts +8 -7
  74. package/utils/authorization/recoverAuthorizationAddress.ts +11 -6
  75. package/utils/authorization/serializeAuthorizationList.ts +1 -2
  76. package/utils/formatters/transaction.ts +1 -1
  77. package/utils/formatters/transactionRequest.ts +1 -1
  78. package/utils/transaction/assertTransaction.ts +1 -1
  79. package/utils/transaction/parseTransaction.ts +2 -2
@@ -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
- > = OneOf<
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
- } & (signed extends true ? Signature : ExactPartial<Signature>)
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 { Authorization } from '../../types/authorization.js'
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> = Authorization & {
13
- /** Output format. @default "hex" */
14
- to?: to | To | undefined
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 contractAddress = parameters.contractAddress ?? parameters.address
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
- contractAddress,
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<Authorization | SignedAuthorization> = 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: authorization | OneOf<Authorization | SignedAuthorization>
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<Authorization | SignedAuthorization>,
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 Authorization),
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
- contractAddress: (authorization as any).address,
130
+ address: (authorization as any).address,
131
131
  chainId: Number(authorization.chainId),
132
132
  nonce: Number(authorization.nonce),
133
133
  r: authorization.r,
@@ -92,7 +92,7 @@ function formatAuthorizationList(
92
92
  return authorizationList.map(
93
93
  (authorization) =>
94
94
  ({
95
- address: authorization.contractAddress,
95
+ address: authorization.address,
96
96
  r: authorization.r
97
97
  ? numberToHex(BigInt(authorization.r))
98
98
  : 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.contractAddress ?? authorization.address
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, contractAddress, nonce, yParity, r, s] =
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
  })