viem 0.0.0-main.20231107T003009 → 0.0.0-main.20231107T233815
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 +6 -0
- 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/version.js +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/node.js +22 -11
- package/_esm/errors/node.js.map +1 -1
- package/_esm/errors/rpc.js +36 -18
- package/_esm/errors/rpc.js.map +1 -1
- package/_esm/errors/version.js +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/errors/version.d.ts +1 -1
- 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/version.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
@@ -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
|
+
}
|