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.
- package/CHANGELOG.md +12 -0
- package/_cjs/errors/contract.js +1 -1
- package/_cjs/errors/contract.js.map +1 -1
- package/_cjs/errors/estimateGas.js +1 -1
- package/_cjs/errors/estimateGas.js.map +1 -1
- package/_cjs/errors/node.js +11 -11
- package/_cjs/errors/node.js.map +1 -1
- package/_cjs/errors/rpc.js +18 -18
- package/_cjs/errors/rpc.js.map +1 -1
- package/_cjs/errors/transaction.js +1 -1
- package/_cjs/errors/transaction.js.map +1 -1
- package/_cjs/utils/contract/extractFunctionParts.js.map +1 -1
- package/_cjs/utils/hash/getFunctionSignature.js +9 -9
- package/_cjs/utils/hash/getFunctionSignature.js.map +1 -1
- package/_cjs/utils/hash/normalizeSignature.js +48 -0
- package/_cjs/utils/hash/normalizeSignature.js.map +1 -0
- package/_esm/errors/contract.js +1 -1
- package/_esm/errors/contract.js.map +1 -1
- package/_esm/errors/estimateGas.js +1 -1
- package/_esm/errors/estimateGas.js.map +1 -1
- package/_esm/errors/node.js +11 -22
- package/_esm/errors/node.js.map +1 -1
- package/_esm/errors/rpc.js +18 -36
- package/_esm/errors/rpc.js.map +1 -1
- package/_esm/errors/transaction.js +1 -1
- package/_esm/errors/transaction.js.map +1 -1
- package/_esm/utils/contract/extractFunctionParts.js +4 -0
- package/_esm/utils/contract/extractFunctionParts.js.map +1 -1
- package/_esm/utils/hash/getFunctionSignature.js +9 -9
- package/_esm/utils/hash/getFunctionSignature.js.map +1 -1
- package/_esm/utils/hash/normalizeSignature.js +51 -0
- package/_esm/utils/hash/normalizeSignature.js.map +1 -0
- package/_types/utils/contract/extractFunctionParts.d.ts +4 -0
- package/_types/utils/contract/extractFunctionParts.d.ts.map +1 -1
- package/_types/utils/hash/getFunctionSignature.d.ts +4 -5
- package/_types/utils/hash/getFunctionSignature.d.ts.map +1 -1
- package/_types/utils/hash/normalizeSignature.d.ts +6 -0
- package/_types/utils/hash/normalizeSignature.d.ts.map +1 -0
- package/errors/contract.ts +1 -1
- package/errors/estimateGas.ts +1 -1
- package/errors/transaction.ts +1 -1
- package/package.json +1 -1
- package/utils/contract/extractFunctionParts.ts +4 -0
- package/utils/hash/getFunctionSignature.ts +11 -21
- 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
|
1
|
+
import { type AbiFunction } from 'abitype';
|
2
2
|
import type { ErrorType } from '../../errors/utils.js';
|
3
|
-
import { type
|
4
|
-
|
5
|
-
export
|
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,
|
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"}
|
package/errors/contract.ts
CHANGED
@@ -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
|
53
|
+
`${formatEther(value)} ${chain?.nativeCurrency?.symbol || 'ETH'}`,
|
54
54
|
data,
|
55
55
|
gas,
|
56
56
|
gasPrice:
|
package/errors/estimateGas.ts
CHANGED
@@ -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
|
43
|
+
`${formatEther(value)} ${chain?.nativeCurrency?.symbol || 'ETH'}`,
|
44
44
|
data,
|
45
45
|
gas,
|
46
46
|
gasPrice:
|
package/errors/transaction.ts
CHANGED
@@ -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
|
177
|
+
`${formatEther(value)} ${chain?.nativeCurrency?.symbol || 'ETH'}`,
|
178
178
|
data,
|
179
179
|
gas,
|
180
180
|
gasPrice:
|
package/package.json
CHANGED
@@ -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
|
1
|
+
import { type AbiFunction, formatAbiItem } from 'abitype'
|
2
2
|
|
3
3
|
import type { ErrorType } from '../../errors/utils.js'
|
4
4
|
import {
|
5
|
-
type
|
6
|
-
|
7
|
-
} from '
|
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
|
-
|
|
17
|
-
| ExtractFunctionParamsErrorType
|
18
|
-
| FormatAbiItemErrorType
|
10
|
+
| NormalizeSignatureErrorType
|
19
11
|
| ErrorType
|
20
12
|
|
21
|
-
export const getFunctionSignature = (
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
+
}
|