viem 1.10.13 → 1.11.0

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 (78) hide show
  1. package/CHANGELOG.md +6 -4
  2. package/_cjs/chains/definitions/kroma.js +26 -0
  3. package/_cjs/chains/definitions/kroma.js.map +1 -0
  4. package/_cjs/chains/definitions/kromaSepolia.js +26 -0
  5. package/_cjs/chains/definitions/kromaSepolia.js.map +1 -0
  6. package/_cjs/chains/definitions/optimismSepolia.js +39 -0
  7. package/_cjs/chains/definitions/optimismSepolia.js.map +1 -0
  8. package/_cjs/chains/index.js +8 -2
  9. package/_cjs/chains/index.js.map +1 -1
  10. package/_cjs/errors/node.js +11 -11
  11. package/_cjs/errors/node.js.map +1 -1
  12. package/_cjs/errors/rpc.js +18 -18
  13. package/_cjs/errors/rpc.js.map +1 -1
  14. package/_cjs/index.js +5 -1
  15. package/_cjs/index.js.map +1 -1
  16. package/_cjs/utils/hash/getEventSelector.js +5 -6
  17. package/_cjs/utils/hash/getEventSelector.js.map +1 -1
  18. package/_cjs/utils/hash/getEventSignature.js +9 -0
  19. package/_cjs/utils/hash/getEventSignature.js.map +1 -0
  20. package/_cjs/utils/hash/getFunctionSelector.js +5 -6
  21. package/_cjs/utils/hash/getFunctionSelector.js.map +1 -1
  22. package/_cjs/utils/hash/getFunctionSignature.js +15 -0
  23. package/_cjs/utils/hash/getFunctionSignature.js.map +1 -0
  24. package/_cjs/utils/hash/hashFunction.js +2 -4
  25. package/_cjs/utils/hash/hashFunction.js.map +1 -1
  26. package/_esm/chains/definitions/kroma.js +23 -0
  27. package/_esm/chains/definitions/kroma.js.map +1 -0
  28. package/_esm/chains/definitions/kromaSepolia.js +23 -0
  29. package/_esm/chains/definitions/kromaSepolia.js.map +1 -0
  30. package/_esm/chains/definitions/optimismSepolia.js +36 -0
  31. package/_esm/chains/definitions/optimismSepolia.js.map +1 -0
  32. package/_esm/chains/index.js +3 -0
  33. package/_esm/chains/index.js.map +1 -1
  34. package/_esm/errors/node.js +11 -22
  35. package/_esm/errors/node.js.map +1 -1
  36. package/_esm/errors/rpc.js +18 -36
  37. package/_esm/errors/rpc.js.map +1 -1
  38. package/_esm/index.js +2 -0
  39. package/_esm/index.js.map +1 -1
  40. package/_esm/utils/hash/getEventSelector.js +5 -6
  41. package/_esm/utils/hash/getEventSelector.js.map +1 -1
  42. package/_esm/utils/hash/getEventSignature.js +5 -0
  43. package/_esm/utils/hash/getEventSignature.js.map +1 -0
  44. package/_esm/utils/hash/getFunctionSelector.js +5 -6
  45. package/_esm/utils/hash/getFunctionSelector.js.map +1 -1
  46. package/_esm/utils/hash/getFunctionSignature.js +11 -0
  47. package/_esm/utils/hash/getFunctionSignature.js.map +1 -0
  48. package/_esm/utils/hash/hashFunction.js +2 -4
  49. package/_esm/utils/hash/hashFunction.js.map +1 -1
  50. package/_types/chains/definitions/kroma.d.ts +26 -0
  51. package/_types/chains/definitions/kroma.d.ts.map +1 -0
  52. package/_types/chains/definitions/kromaSepolia.d.ts +26 -0
  53. package/_types/chains/definitions/kromaSepolia.d.ts.map +1 -0
  54. package/_types/chains/definitions/optimismSepolia.d.ts +331 -0
  55. package/_types/chains/definitions/optimismSepolia.d.ts.map +1 -0
  56. package/_types/chains/index.d.ts +3 -0
  57. package/_types/chains/index.d.ts.map +1 -1
  58. package/_types/index.d.ts +2 -0
  59. package/_types/index.d.ts.map +1 -1
  60. package/_types/utils/hash/getEventSelector.d.ts +1 -2
  61. package/_types/utils/hash/getEventSelector.d.ts.map +1 -1
  62. package/_types/utils/hash/getEventSignature.d.ts +3 -0
  63. package/_types/utils/hash/getEventSignature.d.ts.map +1 -0
  64. package/_types/utils/hash/getFunctionSelector.d.ts.map +1 -1
  65. package/_types/utils/hash/getFunctionSignature.d.ts +3 -0
  66. package/_types/utils/hash/getFunctionSignature.d.ts.map +1 -0
  67. package/_types/utils/hash/hashFunction.d.ts.map +1 -1
  68. package/chains/definitions/kroma.ts +23 -0
  69. package/chains/definitions/kromaSepolia.ts +23 -0
  70. package/chains/definitions/optimismSepolia.ts +39 -0
  71. package/chains/index.ts +3 -0
  72. package/index.ts +2 -0
  73. package/package.json +1 -1
  74. package/utils/hash/getEventSelector.ts +7 -6
  75. package/utils/hash/getEventSignature.ts +7 -0
  76. package/utils/hash/getFunctionSelector.ts +7 -5
  77. package/utils/hash/getFunctionSignature.ts +17 -0
  78. package/utils/hash/hashFunction.ts +2 -7
@@ -1,9 +1,10 @@
1
1
  import type { AbiEvent } from 'abitype'
2
- import type { EventDefinition } from '../../types/contract.js'
3
2
 
4
- import { hashAbiItem, hashFunction } from './hashFunction.js'
3
+ import { toBytes } from '../encoding/toBytes.js'
4
+ import { getEventSignature } from './getEventSignature.js'
5
+ import { keccak256 } from './keccak256.js'
5
6
 
6
- export const getEventSelector = (event: EventDefinition | AbiEvent) => {
7
- if (typeof event === 'string') return hashFunction(event)
8
- return hashAbiItem(event)
9
- }
7
+ const hash = (value: string) => keccak256(toBytes(value))
8
+
9
+ export const getEventSelector = (fn: string | AbiEvent) =>
10
+ hash(getEventSignature(fn))
@@ -0,0 +1,7 @@
1
+ import type { AbiEvent, AbiFunction } from 'abitype'
2
+
3
+ import { getFunctionSignature } from './getFunctionSignature.js'
4
+
5
+ export const getEventSignature = (fn: string | AbiEvent) => {
6
+ return getFunctionSignature(fn as {} as AbiFunction)
7
+ }
@@ -1,9 +1,11 @@
1
1
  import type { AbiFunction } from 'abitype'
2
2
  import { slice } from '../data/slice.js'
3
3
 
4
- import { hashAbiItem, hashFunction } from './hashFunction.js'
4
+ import { toBytes } from '../encoding/toBytes.js'
5
+ import { getFunctionSignature } from './getFunctionSignature.js'
6
+ import { keccak256 } from './keccak256.js'
5
7
 
6
- export const getFunctionSelector = (fn: string | AbiFunction) => {
7
- if (typeof fn === 'string') return slice(hashFunction(fn), 0, 4)
8
- return slice(hashAbiItem(fn), 0, 4)
9
- }
8
+ const hash = (value: string) => keccak256(toBytes(value))
9
+
10
+ export const getFunctionSelector = (fn: string | AbiFunction) =>
11
+ slice(hash(getFunctionSignature(fn)), 0, 4)
@@ -0,0 +1,17 @@
1
+ import type { AbiFunction } from 'abitype'
2
+
3
+ import { formatAbiItem } from '../abi/formatAbiItem.js'
4
+ import {
5
+ extractFunctionName,
6
+ extractFunctionParams,
7
+ } from '../contract/extractFunctionParts.js'
8
+
9
+ export const getFunctionSignature = (fn: string | AbiFunction) => {
10
+ if (typeof fn === 'string') {
11
+ const name = extractFunctionName(fn)
12
+ const params = extractFunctionParams(fn) || []
13
+ return `${name}(${params.map(({ type }) => type).join(',')})`
14
+ }
15
+
16
+ return formatAbiItem(fn)
17
+ }
@@ -1,19 +1,14 @@
1
1
  import type { AbiEvent, AbiFunction } from 'abitype'
2
2
  import { formatAbiItem } from '../abi/formatAbiItem.js'
3
- import {
4
- extractFunctionName,
5
- extractFunctionParams,
6
- } from '../contract/extractFunctionParts.js'
7
3
  import { toBytes } from '../encoding/toBytes.js'
8
4
 
5
+ import { getFunctionSignature } from './getFunctionSignature.js'
9
6
  import { keccak256 } from './keccak256.js'
10
7
 
11
8
  const hash = (value: string) => keccak256(toBytes(value))
12
9
 
13
10
  export function hashFunction(def: string) {
14
- const name = extractFunctionName(def)
15
- const params = extractFunctionParams(def) || []
16
- return hash(`${name}(${params.map(({ type }) => type).join(',')})`)
11
+ return hash(getFunctionSignature(def))
17
12
  }
18
13
 
19
14
  export function hashAbiItem(abiItem: AbiFunction | AbiEvent) {