viem 2.38.6 → 2.39.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.
Files changed (128) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/_cjs/account-abstraction/actions/bundler/waitForUserOperationReceipt.js +9 -3
  3. package/_cjs/account-abstraction/actions/bundler/waitForUserOperationReceipt.js.map +1 -1
  4. package/_cjs/actions/public/getTransaction.js +8 -2
  5. package/_cjs/actions/public/getTransaction.js.map +1 -1
  6. package/_cjs/chains/definitions/apeChain.js +1 -1
  7. package/_cjs/chains/definitions/apeChain.js.map +1 -1
  8. package/_cjs/chains/definitions/heliosTestnet.js +27 -0
  9. package/_cjs/chains/definitions/heliosTestnet.js.map +1 -0
  10. package/_cjs/chains/definitions/jasmyChain.js +18 -0
  11. package/_cjs/chains/definitions/jasmyChain.js.map +1 -0
  12. package/_cjs/chains/definitions/jasmyChainTestnet.js +18 -0
  13. package/_cjs/chains/definitions/jasmyChainTestnet.js.map +1 -0
  14. package/_cjs/chains/definitions/potos.js +26 -0
  15. package/_cjs/chains/definitions/potos.js.map +1 -0
  16. package/_cjs/chains/definitions/potosTestnet.js +26 -0
  17. package/_cjs/chains/definitions/potosTestnet.js.map +1 -0
  18. package/_cjs/chains/definitions/silentdata.js +22 -0
  19. package/_cjs/chains/definitions/silentdata.js.map +1 -0
  20. package/_cjs/chains/definitions/xoneMainnet.js +25 -0
  21. package/_cjs/chains/definitions/xoneMainnet.js.map +1 -0
  22. package/_cjs/chains/definitions/xoneTestnet.js +31 -0
  23. package/_cjs/chains/definitions/xoneTestnet.js.map +1 -0
  24. package/_cjs/chains/index.js +26 -10
  25. package/_cjs/chains/index.js.map +1 -1
  26. package/_cjs/clients/createClient.js +1 -0
  27. package/_cjs/clients/createClient.js.map +1 -1
  28. package/_cjs/clients/transports/createTransport.js.map +1 -1
  29. package/_cjs/errors/version.js +1 -1
  30. package/_cjs/index.js.map +1 -1
  31. package/_cjs/utils/errors/getContractError.js +5 -2
  32. package/_cjs/utils/errors/getContractError.js.map +1 -1
  33. package/_cjs/utils/signature/hashTypedData.js +4 -7
  34. package/_cjs/utils/signature/hashTypedData.js.map +1 -1
  35. package/_cjs/utils/typedData.js +1 -1
  36. package/_cjs/utils/typedData.js.map +1 -1
  37. package/_esm/account-abstraction/actions/bundler/waitForUserOperationReceipt.js +9 -3
  38. package/_esm/account-abstraction/actions/bundler/waitForUserOperationReceipt.js.map +1 -1
  39. package/_esm/actions/public/getTransaction.js +8 -2
  40. package/_esm/actions/public/getTransaction.js.map +1 -1
  41. package/_esm/chains/definitions/apeChain.js +1 -1
  42. package/_esm/chains/definitions/apeChain.js.map +1 -1
  43. package/_esm/chains/definitions/heliosTestnet.js +24 -0
  44. package/_esm/chains/definitions/heliosTestnet.js.map +1 -0
  45. package/_esm/chains/definitions/jasmyChain.js +15 -0
  46. package/_esm/chains/definitions/jasmyChain.js.map +1 -0
  47. package/_esm/chains/definitions/jasmyChainTestnet.js +15 -0
  48. package/_esm/chains/definitions/jasmyChainTestnet.js.map +1 -0
  49. package/_esm/chains/definitions/potos.js +23 -0
  50. package/_esm/chains/definitions/potos.js.map +1 -0
  51. package/_esm/chains/definitions/potosTestnet.js +23 -0
  52. package/_esm/chains/definitions/potosTestnet.js.map +1 -0
  53. package/_esm/chains/definitions/silentdata.js +19 -0
  54. package/_esm/chains/definitions/silentdata.js.map +1 -0
  55. package/_esm/chains/definitions/xoneMainnet.js +22 -0
  56. package/_esm/chains/definitions/xoneMainnet.js.map +1 -0
  57. package/_esm/chains/definitions/xoneTestnet.js +28 -0
  58. package/_esm/chains/definitions/xoneTestnet.js.map +1 -0
  59. package/_esm/chains/index.js +8 -0
  60. package/_esm/chains/index.js.map +1 -1
  61. package/_esm/clients/createClient.js +1 -0
  62. package/_esm/clients/createClient.js.map +1 -1
  63. package/_esm/clients/transports/createTransport.js.map +1 -1
  64. package/_esm/errors/version.js +1 -1
  65. package/_esm/index.js.map +1 -1
  66. package/_esm/utils/errors/getContractError.js +6 -3
  67. package/_esm/utils/errors/getContractError.js.map +1 -1
  68. package/_esm/utils/signature/hashTypedData.js +4 -7
  69. package/_esm/utils/signature/hashTypedData.js.map +1 -1
  70. package/_esm/utils/typedData.js +1 -1
  71. package/_esm/utils/typedData.js.map +1 -1
  72. package/_types/account-abstraction/actions/bundler/waitForUserOperationReceipt.d.ts.map +1 -1
  73. package/_types/actions/public/getTransaction.d.ts +10 -17
  74. package/_types/actions/public/getTransaction.d.ts.map +1 -1
  75. package/_types/chains/definitions/apeChain.d.ts +1 -1
  76. package/_types/chains/definitions/heliosTestnet.d.ts +40 -0
  77. package/_types/chains/definitions/heliosTestnet.d.ts.map +1 -0
  78. package/_types/chains/definitions/jasmyChain.d.ts +47 -0
  79. package/_types/chains/definitions/jasmyChain.d.ts.map +1 -0
  80. package/_types/chains/definitions/jasmyChainTestnet.d.ts +47 -0
  81. package/_types/chains/definitions/jasmyChainTestnet.d.ts.map +1 -0
  82. package/_types/chains/definitions/potos.d.ts +39 -0
  83. package/_types/chains/definitions/potos.d.ts.map +1 -0
  84. package/_types/chains/definitions/potosTestnet.d.ts +39 -0
  85. package/_types/chains/definitions/potosTestnet.d.ts.map +1 -0
  86. package/_types/chains/definitions/silentdata.d.ts +39 -0
  87. package/_types/chains/definitions/silentdata.d.ts.map +1 -0
  88. package/_types/chains/definitions/xoneMainnet.d.ts +40 -0
  89. package/_types/chains/definitions/xoneMainnet.d.ts.map +1 -0
  90. package/_types/chains/definitions/xoneTestnet.d.ts +40 -0
  91. package/_types/chains/definitions/xoneTestnet.d.ts.map +1 -0
  92. package/_types/chains/index.d.ts +8 -0
  93. package/_types/chains/index.d.ts.map +1 -1
  94. package/_types/clients/createClient.d.ts.map +1 -1
  95. package/_types/clients/transports/createTransport.d.ts +2 -0
  96. package/_types/clients/transports/createTransport.d.ts.map +1 -1
  97. package/_types/errors/version.d.ts +1 -1
  98. package/_types/index.d.ts +1 -1
  99. package/_types/index.d.ts.map +1 -1
  100. package/_types/types/eip1193.d.ts +12 -0
  101. package/_types/types/eip1193.d.ts.map +1 -1
  102. package/_types/types/typedData.d.ts +5 -5
  103. package/_types/types/typedData.d.ts.map +1 -1
  104. package/_types/utils/errors/getContractError.d.ts.map +1 -1
  105. package/_types/utils/signature/hashTypedData.d.ts +5 -11
  106. package/_types/utils/signature/hashTypedData.d.ts.map +1 -1
  107. package/account-abstraction/actions/bundler/waitForUserOperationReceipt.ts +17 -12
  108. package/actions/public/getTransaction.ts +48 -37
  109. package/chains/definitions/apeChain.ts +1 -1
  110. package/chains/definitions/heliosTestnet.ts +24 -0
  111. package/chains/definitions/jasmyChain.ts +15 -0
  112. package/chains/definitions/jasmyChainTestnet.ts +15 -0
  113. package/chains/definitions/potos.ts +23 -0
  114. package/chains/definitions/potosTestnet.ts +23 -0
  115. package/chains/definitions/silentdata.ts +19 -0
  116. package/chains/definitions/xoneMainnet.ts +22 -0
  117. package/chains/definitions/xoneTestnet.ts +28 -0
  118. package/chains/index.ts +8 -0
  119. package/clients/createClient.ts +1 -0
  120. package/clients/transports/createTransport.ts +2 -0
  121. package/errors/version.ts +1 -1
  122. package/index.ts +5 -1
  123. package/package.json +1 -1
  124. package/types/eip1193.ts +12 -0
  125. package/types/typedData.ts +6 -4
  126. package/utils/errors/getContractError.ts +6 -3
  127. package/utils/signature/hashTypedData.ts +21 -22
  128. package/utils/typedData.ts +1 -1
@@ -0,0 +1,15 @@
1
+ import { defineChain } from '../../utils/chain/defineChain.js'
2
+
3
+ export const jasmyChain = /*#__PURE__*/ defineChain({
4
+ id: 680,
5
+ name: 'Jasmy Chain',
6
+ network: 'jasmyChain',
7
+ nativeCurrency: { name: 'JasmyCoin', symbol: 'JASMY', decimals: 18 },
8
+ rpcUrls: {
9
+ default: {
10
+ http: ['https://rpc.jasmychain.io'],
11
+ webSocket: ['wss://rpc.jasmychain.io'],
12
+ },
13
+ },
14
+ testnet: false,
15
+ })
@@ -0,0 +1,15 @@
1
+ import { defineChain } from '../../utils/chain/defineChain.js'
2
+
3
+ export const jasmyChainTestnet = /*#__PURE__*/ defineChain({
4
+ id: 681,
5
+ name: 'Jasmy Chain Testnet',
6
+ network: 'jasmyChainTestnet',
7
+ nativeCurrency: { name: 'JasmyCoin', symbol: 'JASMY', decimals: 18 },
8
+ rpcUrls: {
9
+ default: {
10
+ http: ['https://rpc_testnet.jasmychain.io'],
11
+ webSocket: ['wss://rpc_testnet.jasmychain.io'],
12
+ },
13
+ },
14
+ testnet: true,
15
+ })
@@ -0,0 +1,23 @@
1
+ import { defineChain } from '../../utils/chain/defineChain.js'
2
+
3
+ export const potos = /*#__PURE__*/ defineChain({
4
+ id: 60603,
5
+ name: 'POTOS Mainnet',
6
+ nativeCurrency: {
7
+ decimals: 18,
8
+ name: 'POTOS Token',
9
+ symbol: 'POT',
10
+ },
11
+ rpcUrls: {
12
+ default: {
13
+ http: ['https://rpc.potos.hk'],
14
+ },
15
+ },
16
+ blockExplorers: {
17
+ default: {
18
+ name: 'POTOS Mainnet explorer',
19
+ url: 'https://scan.potos.hk',
20
+ },
21
+ },
22
+ testnet: false,
23
+ })
@@ -0,0 +1,23 @@
1
+ import { defineChain } from '../../utils/chain/defineChain.js'
2
+
3
+ export const potosTestnet = /*#__PURE__*/ defineChain({
4
+ id: 60600,
5
+ name: 'POTOS Testnet',
6
+ nativeCurrency: {
7
+ decimals: 18,
8
+ name: 'POTOS Token',
9
+ symbol: 'POT',
10
+ },
11
+ rpcUrls: {
12
+ default: {
13
+ http: ['https://rpc-testnet.potos.hk'],
14
+ },
15
+ },
16
+ blockExplorers: {
17
+ default: {
18
+ name: 'POTOS Testnet explorer',
19
+ url: 'https://scan-testnet.potos.hk',
20
+ },
21
+ },
22
+ testnet: true,
23
+ })
@@ -0,0 +1,19 @@
1
+ import { defineChain } from '../../utils/chain/defineChain.js'
2
+
3
+ export const silentData = /*#__PURE__*/ defineChain({
4
+ id: 380_929,
5
+ name: 'Silent Data Mainnet',
6
+ nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },
7
+ rpcUrls: {
8
+ default: {
9
+ http: ['https://mainnet.silentdata.com'],
10
+ },
11
+ },
12
+ blockExplorers: {
13
+ default: {
14
+ name: 'Silent Data Mainnet Explorer',
15
+ url: 'https://explorer-mainnet.rollup.silentdata.com',
16
+ },
17
+ },
18
+ testnet: false,
19
+ })
@@ -0,0 +1,22 @@
1
+ import { defineChain } from '../../utils/chain/defineChain.js'
2
+
3
+ export const xoneMainnet = /*#__PURE__*/ defineChain({
4
+ id: 3721,
5
+ name: 'Xone Chain Mainnet',
6
+ nativeCurrency: {
7
+ decimals: 18,
8
+ name: 'XOC',
9
+ symbol: 'XOC',
10
+ },
11
+ rpcUrls: {
12
+ default: { http: ['https://rpc.xone.org'] },
13
+ },
14
+ blockExplorers: {
15
+ default: {
16
+ name: 'Xone Mainnet Explorer',
17
+ url: 'https://xonescan.com',
18
+ apiUrl: 'http://api.xonescan.com/api',
19
+ },
20
+ },
21
+ testnet: false,
22
+ })
@@ -0,0 +1,28 @@
1
+ import { defineChain } from '../../utils/chain/defineChain.js'
2
+
3
+ export const xoneTestnet = /*#__PURE__*/ defineChain({
4
+ id: 33772211,
5
+ name: 'Xone Chain Testnet',
6
+ nativeCurrency: {
7
+ decimals: 18,
8
+ name: 'XOC',
9
+ symbol: 'XOC',
10
+ },
11
+ rpcUrls: {
12
+ default: {
13
+ http: [
14
+ 'https://rpc-testnet.xone.org',
15
+ 'https://rpc-testnet.xone.plus',
16
+ 'https://rpc-testnet.knight.center',
17
+ ],
18
+ },
19
+ },
20
+ blockExplorers: {
21
+ default: {
22
+ name: 'Xone Testnet Explorer',
23
+ url: 'https://testnet.xonescan.com',
24
+ apiUrl: 'http://api.testnet.xonescan.com/api',
25
+ },
26
+ },
27
+ testnet: true,
28
+ })
package/chains/index.ts CHANGED
@@ -255,6 +255,7 @@ export { hedera } from './definitions/hedera.js'
255
255
  export { hederaPreviewnet } from './definitions/hederaPreviewnet.js'
256
256
  export { hederaTestnet } from './definitions/hederaTestnet.js'
257
257
  export { hela } from './definitions/hela.js'
258
+ export { heliosTestnet } from './definitions/heliosTestnet.js'
258
259
  export { hemi } from './definitions/hemi.js'
259
260
  export { hemiSepolia } from './definitions/hemiSepolia.js'
260
261
  export { holesky } from './definitions/holesky.js'
@@ -285,6 +286,8 @@ export { iotaTestnet } from './definitions/iotaTestnet.js'
285
286
  export { iotex } from './definitions/iotex.js'
286
287
  export { iotexTestnet } from './definitions/iotexTestnet.js'
287
288
  export { iSunCoin } from './definitions/iSunCoin.js'
289
+ export { jasmyChain } from './definitions/jasmyChain.js'
290
+ export { jasmyChainTestnet } from './definitions/jasmyChainTestnet.js'
288
291
  export { jbc } from './definitions/jbc.js'
289
292
  export { jbcTestnet } from './definitions/jbcTestnet.js'
290
293
  export { jocMainnet } from './definitions/jocMainnet.js'
@@ -461,6 +464,8 @@ export { polygonZkEvmCardona } from './definitions/polygonZkEvmCardona.js'
461
464
  export { polygonZkEvmTestnet } from './definitions/polygonZkEvmTestnet.js'
462
465
  export { polynomial } from './definitions/polynomial.js'
463
466
  export { polynomialSepolia } from './definitions/polynomialSepolia.js'
467
+ export { potos } from './definitions/potos.js'
468
+ export { potosTestnet } from './definitions/potosTestnet.js'
464
469
  export { premiumBlockTestnet } from './definitions/premiumBlock.js'
465
470
  export { pulsechain } from './definitions/pulsechain.js'
466
471
  export { pulsechainV4 } from './definitions/pulsechainV4.js'
@@ -515,6 +520,7 @@ export { shiden } from './definitions/shiden.js'
515
520
  export { shimmer } from './definitions/shimmer.js'
516
521
  export { shimmerTestnet } from './definitions/shimmerTestnet.js'
517
522
  export { sidraChain } from './definitions/sidra.js'
523
+ export { silentData } from './definitions/silentdata.js'
518
524
  export { silicon } from './definitions/silicon.js'
519
525
  export { siliconSepolia } from './definitions/siliconSepolia.js'
520
526
  export { sixProtocol } from './definitions/sixProtocol.js'
@@ -648,6 +654,8 @@ export {
648
654
  x1Testnet,
649
655
  xLayerTestnet,
650
656
  } from './definitions/xLayerTestnet.js'
657
+ export { xoneMainnet } from './definitions/xoneMainnet.js'
658
+ export { xoneTestnet } from './definitions/xoneTestnet.js'
651
659
  export { xphereMainnet } from './definitions/xphereMainnet.js'
652
660
  export { xphereTestnet } from './definitions/xphereTestnet.js'
653
661
  export { xrOne } from './definitions/xrOne.js'
@@ -255,6 +255,7 @@ export function createClient(parameters: ClientConfig): Client {
255
255
  ? parseAccount(parameters.account)
256
256
  : undefined
257
257
  const { config, request, value } = parameters.transport({
258
+ account,
258
259
  chain,
259
260
  pollingInterval,
260
261
  })
@@ -1,4 +1,5 @@
1
1
  import type { ErrorType } from '../../errors/utils.js'
2
+ import type { Account } from '../../types/account.js'
2
3
  import type { Chain } from '../../types/chain.js'
3
4
  import type { EIP1193RequestFn } from '../../types/eip1193.js'
4
5
  import type { OneOf } from '../../types/utils.js'
@@ -44,6 +45,7 @@ export type Transport<
44
45
  > = <chain extends Chain | undefined = Chain>({
45
46
  chain,
46
47
  }: {
48
+ account?: Account | undefined
47
49
  chain?: chain | undefined
48
50
  pollingInterval?: ClientConfig['pollingInterval'] | undefined
49
51
  retryCount?: TransportConfig['retryCount'] | undefined
package/errors/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '2.38.6'
1
+ export const version = '2.39.2'
package/index.ts CHANGED
@@ -1227,7 +1227,11 @@ export type {
1227
1227
  TransactionType,
1228
1228
  } from './types/transaction.js'
1229
1229
  export type { GetPollOptions, GetTransportConfig } from './types/transport.js'
1230
- export type { TypedDataDefinition } from './types/typedData.js'
1230
+ export type {
1231
+ EIP712DomainDefinition,
1232
+ MessageDefinition,
1233
+ TypedDataDefinition,
1234
+ } from './types/typedData.js'
1231
1235
  export type {
1232
1236
  Assign,
1233
1237
  Branded,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "viem",
3
3
  "description": "TypeScript Interface for Ethereum",
4
- "version": "2.38.6",
4
+ "version": "2.39.2",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
7
7
  "types": "./_types/index.d.ts",
package/types/eip1193.ts CHANGED
@@ -1014,6 +1014,18 @@ export type PublicRpcSchema = [
1014
1014
  Parameters: [hash: Hash]
1015
1015
  ReturnType: Transaction | null
1016
1016
  },
1017
+ /**
1018
+ * @description Returns information about a transaction specified by sender and nonce
1019
+ * @link https://eips.ethereum.org/EIPS/eip-1474
1020
+ * @example
1021
+ * provider.request({ method: 'eth_getTransactionBySenderAndNonce', params: ['0x...', '0x...'] })
1022
+ * // => { ... }
1023
+ */
1024
+ {
1025
+ Method: 'eth_getTransactionBySenderAndNonce'
1026
+ Parameters: [sender: Address, nonce: Quantity]
1027
+ ReturnType: Transaction | null
1028
+ },
1017
1029
  /**
1018
1030
  * @description Returns the number of transactions sent from an address
1019
1031
  * @link https://eips.ethereum.org/EIPS/eip-1474
@@ -13,11 +13,12 @@ export type TypedDataDefinition<
13
13
  primaryTypes = typedData extends TypedData ? keyof typedData : string,
14
14
  > = primaryType extends 'EIP712Domain'
15
15
  ? EIP712DomainDefinition<typedData, primaryType>
16
- : MessageDefinition<typedData, primaryType, primaryTypes>
16
+ : MessageDefinition<typedData, primaryType, 'message', primaryTypes>
17
17
 
18
- type MessageDefinition<
18
+ export type MessageDefinition<
19
19
  typedData extends TypedData | Record<string, unknown> = TypedData,
20
20
  primaryType extends keyof typedData = keyof typedData,
21
+ messageKey extends string = 'message',
21
22
  ///
22
23
  primaryTypes = typedData extends TypedData ? keyof typedData : string,
23
24
  schema extends Record<string, unknown> = typedData extends TypedData
@@ -37,12 +38,13 @@ type MessageDefinition<
37
38
  ? domain
38
39
  : Prettify<TypedDataDomain>)
39
40
  | undefined
40
- message: { [_: string]: any } extends message // Check if message was inferred
41
+ } & {
42
+ [k in messageKey]: { [_: string]: any } extends message // Check if message was inferred
41
43
  ? Record<string, unknown>
42
44
  : message
43
45
  }
44
46
 
45
- type EIP712DomainDefinition<
47
+ export type EIP712DomainDefinition<
46
48
  typedData extends TypedData | Record<string, unknown> = TypedData,
47
49
  primaryType extends 'EIP712Domain' = 'EIP712Domain',
48
50
  ///
@@ -12,7 +12,7 @@ import {
12
12
  RawContractError,
13
13
  } from '../../errors/contract.js'
14
14
  import { RpcRequestError } from '../../errors/request.js'
15
- import { InternalRpcError } from '../../errors/rpc.js'
15
+ import { InternalRpcError, InvalidInputRpcError } from '../../errors/rpc.js'
16
16
  import type { ErrorType } from '../../errors/utils.js'
17
17
 
18
18
  const EXECUTION_REVERTED_ERROR_CODE = 3
@@ -59,8 +59,11 @@ export function getContractError<err extends ErrorType<string>>(
59
59
  if (err instanceof AbiDecodingZeroDataError)
60
60
  return new ContractFunctionZeroDataError({ functionName })
61
61
  if (
62
- [EXECUTION_REVERTED_ERROR_CODE, InternalRpcError.code].includes(code) &&
63
- (data || details || message || shortMessage)
62
+ ([EXECUTION_REVERTED_ERROR_CODE, InternalRpcError.code].includes(code) &&
63
+ (data || details || message || shortMessage)) ||
64
+ (code === InvalidInputRpcError.code &&
65
+ details === 'execution reverted' &&
66
+ data)
64
67
  ) {
65
68
  return new ContractFunctionRevertedError({
66
69
  abi,
@@ -1,10 +1,15 @@
1
1
  // Implementation forked and adapted from https://github.com/MetaMask/eth-sig-util/blob/main/src/sign-typed-data.ts
2
2
 
3
- import type { AbiParameter, TypedData, TypedDataDomain } from 'abitype'
3
+ import type { AbiParameter, TypedData } from 'abitype'
4
4
 
5
5
  import type { ErrorType } from '../../errors/utils.js'
6
6
  import type { Hex } from '../../types/misc.js'
7
- import type { TypedDataDefinition } from '../../types/typedData.js'
7
+ import type {
8
+ EIP712DomainDefinition,
9
+ MessageDefinition,
10
+ TypedDataDefinition,
11
+ } from '../../types/typedData.js'
12
+ import type { UnionOmit } from '../../types/utils.js'
8
13
  import {
9
14
  type EncodeAbiParametersErrorType,
10
15
  encodeAbiParameters,
@@ -86,17 +91,16 @@ export function hashTypedData<
86
91
 
87
92
  export type HashDomainErrorType = HashStructErrorType | ErrorType
88
93
 
89
- export function hashDomain({
94
+ export function hashDomain<
95
+ const typedData extends TypedData | Record<string, unknown> = TypedData,
96
+ >({
90
97
  domain,
91
98
  types,
92
- }: {
93
- domain: TypedDataDomain
94
- types: Record<string, MessageTypeProperty[]>
95
- }) {
99
+ }: UnionOmit<EIP712DomainDefinition<typedData>, 'primaryType'>) {
96
100
  return hashStruct({
97
- data: domain,
101
+ data: domain as Record<string, unknown>,
98
102
  primaryType: 'EIP712Domain',
99
- types,
103
+ types: types as Record<string, readonly MessageTypeProperty[]>,
100
104
  })
101
105
  }
102
106
 
@@ -105,19 +109,18 @@ export type HashStructErrorType =
105
109
  | Keccak256ErrorType
106
110
  | ErrorType
107
111
 
108
- export function hashStruct({
112
+ export function hashStruct<
113
+ const typedData extends TypedData | Record<string, unknown>,
114
+ primaryType extends keyof typedData | 'EIP712Domain',
115
+ >({
109
116
  data,
110
117
  primaryType,
111
118
  types,
112
- }: {
113
- data: Record<string, unknown>
114
- primaryType: string
115
- types: Record<string, readonly MessageTypeProperty[]>
116
- }) {
119
+ }: MessageDefinition<typedData, primaryType, 'data'>) {
117
120
  const encoded = encodeData({
118
- data,
121
+ data: data as Record<string, unknown>,
119
122
  primaryType,
120
- types,
123
+ types: types as Record<string, readonly MessageTypeProperty[]>,
121
124
  })
122
125
  return keccak256(encoded)
123
126
  }
@@ -244,11 +247,7 @@ function encodeField({
244
247
  ]
245
248
  }
246
249
 
247
- if (type === 'bytes') {
248
- const prepend = value.length % 2 ? '0' : ''
249
- value = `0x${prepend + value.slice(2)}`
250
- return [{ type: 'bytes32' }, keccak256(value)]
251
- }
250
+ if (type === 'bytes') return [{ type: 'bytes32' }, keccak256(value)]
252
251
 
253
252
  if (type === 'string') return [{ type: 'bytes32' }, keccak256(toHex(value))]
254
253
 
@@ -164,7 +164,7 @@ export type DomainSeparatorErrorType =
164
164
 
165
165
  export function domainSeparator({ domain }: { domain: TypedDataDomain }): Hex {
166
166
  return hashDomain({
167
- domain,
167
+ domain: domain as never,
168
168
  types: {
169
169
  EIP712Domain: getTypesForEIP712Domain({ domain }),
170
170
  },