viem 2.39.0 → 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 (71) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/_cjs/chains/definitions/jasmyChain.js +18 -0
  3. package/_cjs/chains/definitions/jasmyChain.js.map +1 -0
  4. package/_cjs/chains/definitions/jasmyChainTestnet.js +18 -0
  5. package/_cjs/chains/definitions/jasmyChainTestnet.js.map +1 -0
  6. package/_cjs/chains/definitions/potosTestnet.js +26 -0
  7. package/_cjs/chains/definitions/potosTestnet.js.map +1 -0
  8. package/_cjs/chains/index.js +15 -9
  9. package/_cjs/chains/index.js.map +1 -1
  10. package/_cjs/clients/createClient.js +1 -0
  11. package/_cjs/clients/createClient.js.map +1 -1
  12. package/_cjs/clients/transports/createTransport.js.map +1 -1
  13. package/_cjs/errors/version.js +1 -1
  14. package/_cjs/index.js.map +1 -1
  15. package/_cjs/utils/errors/getContractError.js +5 -2
  16. package/_cjs/utils/errors/getContractError.js.map +1 -1
  17. package/_cjs/utils/signature/hashTypedData.js +4 -7
  18. package/_cjs/utils/signature/hashTypedData.js.map +1 -1
  19. package/_cjs/utils/typedData.js +1 -1
  20. package/_cjs/utils/typedData.js.map +1 -1
  21. package/_esm/chains/definitions/jasmyChain.js +15 -0
  22. package/_esm/chains/definitions/jasmyChain.js.map +1 -0
  23. package/_esm/chains/definitions/jasmyChainTestnet.js +15 -0
  24. package/_esm/chains/definitions/jasmyChainTestnet.js.map +1 -0
  25. package/_esm/chains/definitions/potosTestnet.js +23 -0
  26. package/_esm/chains/definitions/potosTestnet.js.map +1 -0
  27. package/_esm/chains/index.js +3 -0
  28. package/_esm/chains/index.js.map +1 -1
  29. package/_esm/clients/createClient.js +1 -0
  30. package/_esm/clients/createClient.js.map +1 -1
  31. package/_esm/clients/transports/createTransport.js.map +1 -1
  32. package/_esm/errors/version.js +1 -1
  33. package/_esm/index.js.map +1 -1
  34. package/_esm/utils/errors/getContractError.js +6 -3
  35. package/_esm/utils/errors/getContractError.js.map +1 -1
  36. package/_esm/utils/signature/hashTypedData.js +4 -7
  37. package/_esm/utils/signature/hashTypedData.js.map +1 -1
  38. package/_esm/utils/typedData.js +1 -1
  39. package/_esm/utils/typedData.js.map +1 -1
  40. package/_types/chains/definitions/jasmyChain.d.ts +47 -0
  41. package/_types/chains/definitions/jasmyChain.d.ts.map +1 -0
  42. package/_types/chains/definitions/jasmyChainTestnet.d.ts +47 -0
  43. package/_types/chains/definitions/jasmyChainTestnet.d.ts.map +1 -0
  44. package/_types/chains/definitions/potosTestnet.d.ts +39 -0
  45. package/_types/chains/definitions/potosTestnet.d.ts.map +1 -0
  46. package/_types/chains/index.d.ts +3 -0
  47. package/_types/chains/index.d.ts.map +1 -1
  48. package/_types/clients/createClient.d.ts.map +1 -1
  49. package/_types/clients/transports/createTransport.d.ts +2 -0
  50. package/_types/clients/transports/createTransport.d.ts.map +1 -1
  51. package/_types/errors/version.d.ts +1 -1
  52. package/_types/index.d.ts +1 -1
  53. package/_types/index.d.ts.map +1 -1
  54. package/_types/types/typedData.d.ts +5 -5
  55. package/_types/types/typedData.d.ts.map +1 -1
  56. package/_types/utils/errors/getContractError.d.ts.map +1 -1
  57. package/_types/utils/signature/hashTypedData.d.ts +5 -11
  58. package/_types/utils/signature/hashTypedData.d.ts.map +1 -1
  59. package/chains/definitions/jasmyChain.ts +15 -0
  60. package/chains/definitions/jasmyChainTestnet.ts +15 -0
  61. package/chains/definitions/potosTestnet.ts +23 -0
  62. package/chains/index.ts +3 -0
  63. package/clients/createClient.ts +1 -0
  64. package/clients/transports/createTransport.ts +2 -0
  65. package/errors/version.ts +1 -1
  66. package/index.ts +5 -1
  67. package/package.json +1 -1
  68. package/types/typedData.ts +6 -4
  69. package/utils/errors/getContractError.ts +6 -3
  70. package/utils/signature/hashTypedData.ts +21 -22
  71. package/utils/typedData.ts +1 -1
@@ -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
  },