viem 1.18.7 → 1.18.9

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 (45) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/_cjs/errors/contract.js +1 -1
  3. package/_cjs/errors/contract.js.map +1 -1
  4. package/_cjs/errors/estimateGas.js +1 -1
  5. package/_cjs/errors/estimateGas.js.map +1 -1
  6. package/_cjs/errors/node.js +11 -11
  7. package/_cjs/errors/node.js.map +1 -1
  8. package/_cjs/errors/rpc.js +18 -18
  9. package/_cjs/errors/rpc.js.map +1 -1
  10. package/_cjs/errors/transaction.js +1 -1
  11. package/_cjs/errors/transaction.js.map +1 -1
  12. package/_cjs/utils/contract/extractFunctionParts.js.map +1 -1
  13. package/_cjs/utils/hash/getFunctionSignature.js +9 -9
  14. package/_cjs/utils/hash/getFunctionSignature.js.map +1 -1
  15. package/_cjs/utils/hash/normalizeSignature.js +48 -0
  16. package/_cjs/utils/hash/normalizeSignature.js.map +1 -0
  17. package/_esm/errors/contract.js +1 -1
  18. package/_esm/errors/contract.js.map +1 -1
  19. package/_esm/errors/estimateGas.js +1 -1
  20. package/_esm/errors/estimateGas.js.map +1 -1
  21. package/_esm/errors/node.js +11 -22
  22. package/_esm/errors/node.js.map +1 -1
  23. package/_esm/errors/rpc.js +18 -36
  24. package/_esm/errors/rpc.js.map +1 -1
  25. package/_esm/errors/transaction.js +1 -1
  26. package/_esm/errors/transaction.js.map +1 -1
  27. package/_esm/utils/contract/extractFunctionParts.js +4 -0
  28. package/_esm/utils/contract/extractFunctionParts.js.map +1 -1
  29. package/_esm/utils/hash/getFunctionSignature.js +9 -9
  30. package/_esm/utils/hash/getFunctionSignature.js.map +1 -1
  31. package/_esm/utils/hash/normalizeSignature.js +51 -0
  32. package/_esm/utils/hash/normalizeSignature.js.map +1 -0
  33. package/_types/utils/contract/extractFunctionParts.d.ts +4 -0
  34. package/_types/utils/contract/extractFunctionParts.d.ts.map +1 -1
  35. package/_types/utils/hash/getFunctionSignature.d.ts +4 -5
  36. package/_types/utils/hash/getFunctionSignature.d.ts.map +1 -1
  37. package/_types/utils/hash/normalizeSignature.d.ts +6 -0
  38. package/_types/utils/hash/normalizeSignature.d.ts.map +1 -0
  39. package/errors/contract.ts +1 -1
  40. package/errors/estimateGas.ts +1 -1
  41. package/errors/transaction.ts +1 -1
  42. package/package.json +1 -1
  43. package/utils/contract/extractFunctionParts.ts +4 -0
  44. package/utils/hash/getFunctionSignature.ts +11 -21
  45. package/utils/hash/normalizeSignature.ts +64 -0
@@ -1 +1 @@
1
- {"version":3,"file":"extractFunctionParts.d.ts","sourceRoot":"","sources":["../../../utils/contract/extractFunctionParts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAItD,MAAM,MAAM,6BAA6B,GAAG,SAAS,CAAA;AAErD,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM;;;;EAM/C;AAED,MAAM,MAAM,4BAA4B,GAAG,SAAS,CAAA;AAEpD,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,sBAE9C;AAED,MAAM,MAAM,8BAA8B,GAAG,SAAS,CAAA;AAEtD,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM;;;;gBAQhD;AAED,MAAM,MAAM,4BAA4B,GAAG,SAAS,CAAA;AAEpD,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,sBAE9C"}
1
+ {"version":3,"file":"extractFunctionParts.d.ts","sourceRoot":"","sources":["../../../utils/contract/extractFunctionParts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAItD,MAAM,MAAM,6BAA6B,GAAG,SAAS,CAAA;AAErD,uDAAuD;AACvD,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM;;;;EAM/C;AAED,MAAM,MAAM,4BAA4B,GAAG,SAAS,CAAA;AAEpD,uDAAuD;AACvD,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,sBAE9C;AAED,MAAM,MAAM,8BAA8B,GAAG,SAAS,CAAA;AAEtD,uDAAuD;AACvD,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM;;;;gBAQhD;AAED,MAAM,MAAM,4BAA4B,GAAG,SAAS,CAAA;AAEpD,uDAAuD;AACvD,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,sBAE9C"}
@@ -1,7 +1,6 @@
1
- import type { AbiFunction } from 'abitype';
1
+ import { type AbiFunction } from 'abitype';
2
2
  import type { ErrorType } from '../../errors/utils.js';
3
- import { type FormatAbiItemErrorType } from '../abi/formatAbiItem.js';
4
- import { type ExtractFunctionNameErrorType, type ExtractFunctionParamsErrorType } from '../contract/extractFunctionParts.js';
5
- export type GetFunctionSignatureErrorType = ExtractFunctionNameErrorType | ExtractFunctionParamsErrorType | FormatAbiItemErrorType | ErrorType;
6
- export declare const getFunctionSignature: (fn: string | AbiFunction) => string;
3
+ import { type NormalizeSignatureErrorType } from './normalizeSignature.js';
4
+ export type GetFunctionSignatureErrorType = NormalizeSignatureErrorType | ErrorType;
5
+ export declare const getFunctionSignature: (fn_: string | AbiFunction) => string;
7
6
  //# sourceMappingURL=getFunctionSignature.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getFunctionSignature.d.ts","sourceRoot":"","sources":["../../../utils/hash/getFunctionSignature.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAE1C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EACL,KAAK,sBAAsB,EAE5B,MAAM,yBAAyB,CAAA;AAChC,OAAO,EACL,KAAK,4BAA4B,EACjC,KAAK,8BAA8B,EAGpC,MAAM,qCAAqC,CAAA;AAE5C,MAAM,MAAM,6BAA6B,GACrC,4BAA4B,GAC5B,8BAA8B,GAC9B,sBAAsB,GACtB,SAAS,CAAA;AAEb,eAAO,MAAM,oBAAoB,OAAQ,MAAM,GAAG,WAAW,WAQ5D,CAAA"}
1
+ {"version":3,"file":"getFunctionSignature.d.ts","sourceRoot":"","sources":["../../../utils/hash/getFunctionSignature.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAiB,MAAM,SAAS,CAAA;AAEzD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EACL,KAAK,2BAA2B,EAEjC,MAAM,yBAAyB,CAAA;AAEhC,MAAM,MAAM,6BAA6B,GACrC,2BAA2B,GAC3B,SAAS,CAAA;AAEb,eAAO,MAAM,oBAAoB,QAAS,MAAM,GAAG,WAAW,WAM7D,CAAA"}
@@ -0,0 +1,6 @@
1
+ import type { ErrorType } from '../../errors/utils.js';
2
+ export type NormalizeSignatureParameters = string;
3
+ export type NormalizeSignatureReturnType = string;
4
+ export type NormalizeSignatureErrorType = ErrorType;
5
+ export declare function normalizeSignature(signature: NormalizeSignatureParameters): NormalizeSignatureReturnType;
6
+ //# sourceMappingURL=normalizeSignature.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalizeSignature.d.ts","sourceRoot":"","sources":["../../../utils/hash/normalizeSignature.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAEtD,MAAM,MAAM,4BAA4B,GAAG,MAAM,CAAA;AACjD,MAAM,MAAM,4BAA4B,GAAG,MAAM,CAAA;AACjD,MAAM,MAAM,2BAA2B,GAAG,SAAS,CAAA;AAEnD,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,4BAA4B,GACtC,4BAA4B,CAsD9B"}
@@ -50,7 +50,7 @@ export class CallExecutionError extends BaseError {
50
50
  to,
51
51
  value:
52
52
  typeof value !== 'undefined' &&
53
- `${formatEther(value)} ${chain?.nativeCurrency.symbol || 'ETH'}`,
53
+ `${formatEther(value)} ${chain?.nativeCurrency?.symbol || 'ETH'}`,
54
54
  data,
55
55
  gas,
56
56
  gasPrice:
@@ -40,7 +40,7 @@ export class EstimateGasExecutionError extends BaseError {
40
40
  to,
41
41
  value:
42
42
  typeof value !== 'undefined' &&
43
- `${formatEther(value)} ${chain?.nativeCurrency.symbol || 'ETH'}`,
43
+ `${formatEther(value)} ${chain?.nativeCurrency?.symbol || 'ETH'}`,
44
44
  data,
45
45
  gas,
46
46
  gasPrice:
@@ -174,7 +174,7 @@ export class TransactionExecutionError extends BaseError {
174
174
  to,
175
175
  value:
176
176
  typeof value !== 'undefined' &&
177
- `${formatEther(value)} ${chain?.nativeCurrency.symbol || 'ETH'}`,
177
+ `${formatEther(value)} ${chain?.nativeCurrency?.symbol || 'ETH'}`,
178
178
  data,
179
179
  gas,
180
180
  gasPrice:
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "viem",
3
3
  "description": "TypeScript Interface for Ethereum",
4
- "version": "1.18.7",
4
+ "version": "1.18.9",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
7
7
  "types": "./_types/index.d.ts",
@@ -4,6 +4,7 @@ const paramsRegex = /((function|event)\s)?(.*)(\((.*)\))/
4
4
 
5
5
  export type ExtractFunctionPartsErrorType = ErrorType
6
6
 
7
+ /** @deprecated – use `parseAbiItem` from `abitype`. */
7
8
  export function extractFunctionParts(def: string) {
8
9
  const parts = def.match(paramsRegex)
9
10
  const type = parts?.[2] || undefined
@@ -14,12 +15,14 @@ export function extractFunctionParts(def: string) {
14
15
 
15
16
  export type ExtractFunctionNameErrorType = ErrorType
16
17
 
18
+ /** @deprecated – use `parseAbiItem` from `abitype`. */
17
19
  export function extractFunctionName(def: string) {
18
20
  return extractFunctionParts(def).name
19
21
  }
20
22
 
21
23
  export type ExtractFunctionParamsErrorType = ErrorType
22
24
 
25
+ /** @deprecated – use `parseAbiItem` from `abitype`. */
23
26
  export function extractFunctionParams(def: string) {
24
27
  const params = extractFunctionParts(def).params
25
28
  const splitParams = params?.split(',').map((x) => x.trim().split(' '))
@@ -32,6 +35,7 @@ export function extractFunctionParams(def: string) {
32
35
 
33
36
  export type ExtractFunctionTypeErrorType = ErrorType
34
37
 
38
+ /** @deprecated – use `parseAbiItem` from `abitype`. */
35
39
  export function extractFunctionType(def: string) {
36
40
  return extractFunctionParts(def).type
37
41
  }
@@ -1,29 +1,19 @@
1
- import type { AbiFunction } from 'abitype'
1
+ import { type AbiFunction, formatAbiItem } from 'abitype'
2
2
 
3
3
  import type { ErrorType } from '../../errors/utils.js'
4
4
  import {
5
- type FormatAbiItemErrorType,
6
- formatAbiItem,
7
- } from '../abi/formatAbiItem.js'
8
- import {
9
- type ExtractFunctionNameErrorType,
10
- type ExtractFunctionParamsErrorType,
11
- extractFunctionName,
12
- extractFunctionParams,
13
- } from '../contract/extractFunctionParts.js'
5
+ type NormalizeSignatureErrorType,
6
+ normalizeSignature,
7
+ } from './normalizeSignature.js'
14
8
 
15
9
  export type GetFunctionSignatureErrorType =
16
- | ExtractFunctionNameErrorType
17
- | ExtractFunctionParamsErrorType
18
- | FormatAbiItemErrorType
10
+ | NormalizeSignatureErrorType
19
11
  | ErrorType
20
12
 
21
- export const getFunctionSignature = (fn: string | AbiFunction) => {
22
- if (typeof fn === 'string') {
23
- const name = extractFunctionName(fn)
24
- const params = extractFunctionParams(fn) || []
25
- return `${name}(${params.map(({ type }) => type).join(',')})`
26
- }
27
-
28
- return formatAbiItem(fn)
13
+ export const getFunctionSignature = (fn_: string | AbiFunction) => {
14
+ const fn = (() => {
15
+ if (typeof fn_ === 'string') return fn_
16
+ return formatAbiItem(fn_)
17
+ })()
18
+ return normalizeSignature(fn)
29
19
  }
@@ -0,0 +1,64 @@
1
+ import { BaseError } from '../../errors/base.js'
2
+ import type { ErrorType } from '../../errors/utils.js'
3
+
4
+ export type NormalizeSignatureParameters = string
5
+ export type NormalizeSignatureReturnType = string
6
+ export type NormalizeSignatureErrorType = ErrorType
7
+
8
+ export function normalizeSignature(
9
+ signature: NormalizeSignatureParameters,
10
+ ): NormalizeSignatureReturnType {
11
+ let active = true
12
+ let current = ''
13
+ let level = 0
14
+ let result = ''
15
+ let valid = false
16
+
17
+ for (let i = 0; i < signature.length; i++) {
18
+ const char = signature[i]
19
+
20
+ // If the character is a separator, we want to reactivate.
21
+ if (['(', ')', ','].includes(char)) active = true
22
+
23
+ // If the character is a "level" token, we want to increment/decrement.
24
+ if (char === '(') level++
25
+ if (char === ')') level--
26
+
27
+ // If we aren't active, we don't want to mutate the result.
28
+ if (!active) continue
29
+
30
+ // If level === 0, we are at the definition level.
31
+ if (level === 0) {
32
+ if (char === ' ' && ['event', 'function', ''].includes(result))
33
+ result = ''
34
+ else {
35
+ result += char
36
+
37
+ // If we are at the end of the definition, we must be finished.
38
+ if (char === ')') {
39
+ valid = true
40
+ break
41
+ }
42
+ }
43
+
44
+ continue
45
+ }
46
+
47
+ // Ignore spaces
48
+ if (char === ' ') {
49
+ // If the previous character is a separator, and the current section isn't empty, we want to deactivate.
50
+ if (signature[i - 1] !== ',' && current !== ',' && current !== ',(') {
51
+ current = ''
52
+ active = false
53
+ }
54
+ continue
55
+ }
56
+
57
+ result += char
58
+ current += char
59
+ }
60
+
61
+ if (!valid) throw new BaseError('Unable to normalize signature.')
62
+
63
+ return result
64
+ }