viem 1.18.8 → 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 +6 -0
- 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/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/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
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# viem
|
2
2
|
|
3
|
+
## 1.18.9
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- [#1464](https://github.com/wagmi-dev/viem/pull/1464) [`32098af0`](https://github.com/wagmi-dev/viem/commit/32098af0378c47a4032155f8947f88f9990cd25d) Thanks [@jxom](https://github.com/jxom)! - Fixed issue where `getFunctionSignature`/`getFunctionSelector` would not parse nested tuples in string-based signatures.
|
8
|
+
|
3
9
|
## 1.18.8
|
4
10
|
|
5
11
|
### Patch Changes
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"extractFunctionParts.js","sourceRoot":"","sources":["../../../utils/contract/extractFunctionParts.ts"],"names":[],"mappings":";;;AAEA,MAAM,WAAW,GAAG,qCAAqC,CAAA;
|
1
|
+
{"version":3,"file":"extractFunctionParts.js","sourceRoot":"","sources":["../../../utils/contract/extractFunctionParts.ts"],"names":[],"mappings":";;;AAEA,MAAM,WAAW,GAAG,qCAAqC,CAAA;AAKzD,SAAgB,oBAAoB,CAAC,GAAW;IAC9C,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;IACpC,MAAM,IAAI,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,SAAS,CAAA;IACpC,MAAM,IAAI,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,CAAA;IACvB,MAAM,MAAM,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,SAAS,CAAA;IACtC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAA;AAC/B,CAAC;AAND,oDAMC;AAKD,SAAgB,mBAAmB,CAAC,GAAW;IAC7C,OAAO,oBAAoB,CAAC,GAAG,CAAC,CAAC,IAAI,CAAA;AACvC,CAAC;AAFD,kDAEC;AAKD,SAAgB,qBAAqB,CAAC,GAAW;IAC/C,MAAM,MAAM,GAAG,oBAAoB,CAAC,GAAG,CAAC,CAAC,MAAM,CAAA;IAC/C,MAAM,WAAW,GAAG,MAAM,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAA;IACtE,OAAO,WAAW,EAAE,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAClC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;QACd,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;QAClD,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACrD,CAAC,CAAC,CAAA;AACL,CAAC;AARD,sDAQC;AAKD,SAAgB,mBAAmB,CAAC,GAAW;IAC7C,OAAO,oBAAoB,CAAC,GAAG,CAAC,CAAC,IAAI,CAAA;AACvC,CAAC;AAFD,kDAEC"}
|
@@ -1,15 +1,15 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.getFunctionSignature = void 0;
|
4
|
-
const
|
5
|
-
const
|
6
|
-
const getFunctionSignature = (
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
return
|
11
|
-
}
|
12
|
-
return (0,
|
4
|
+
const abitype_1 = require("abitype");
|
5
|
+
const normalizeSignature_js_1 = require("./normalizeSignature.js");
|
6
|
+
const getFunctionSignature = (fn_) => {
|
7
|
+
const fn = (() => {
|
8
|
+
if (typeof fn_ === 'string')
|
9
|
+
return fn_;
|
10
|
+
return (0, abitype_1.formatAbiItem)(fn_);
|
11
|
+
})();
|
12
|
+
return (0, normalizeSignature_js_1.normalizeSignature)(fn);
|
13
13
|
};
|
14
14
|
exports.getFunctionSignature = getFunctionSignature;
|
15
15
|
//# sourceMappingURL=getFunctionSignature.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"getFunctionSignature.js","sourceRoot":"","sources":["../../../utils/hash/getFunctionSignature.ts"],"names":[],"mappings":";;;
|
1
|
+
{"version":3,"file":"getFunctionSignature.js","sourceRoot":"","sources":["../../../utils/hash/getFunctionSignature.ts"],"names":[],"mappings":";;;AAAA,qCAAyD;AAGzD,mEAGgC;AAMzB,MAAM,oBAAoB,GAAG,CAAC,GAAyB,EAAE,EAAE;IAChE,MAAM,EAAE,GAAG,CAAC,GAAG,EAAE;QACf,IAAI,OAAO,GAAG,KAAK,QAAQ;YAAE,OAAO,GAAG,CAAA;QACvC,OAAO,IAAA,uBAAa,EAAC,GAAG,CAAC,CAAA;IAC3B,CAAC,CAAC,EAAE,CAAA;IACJ,OAAO,IAAA,0CAAkB,EAAC,EAAE,CAAC,CAAA;AAC/B,CAAC,CAAA;AANY,QAAA,oBAAoB,wBAMhC"}
|
@@ -0,0 +1,48 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.normalizeSignature = void 0;
|
4
|
+
const base_js_1 = require("../../errors/base.js");
|
5
|
+
function normalizeSignature(signature) {
|
6
|
+
let active = true;
|
7
|
+
let current = '';
|
8
|
+
let level = 0;
|
9
|
+
let result = '';
|
10
|
+
let valid = false;
|
11
|
+
for (let i = 0; i < signature.length; i++) {
|
12
|
+
const char = signature[i];
|
13
|
+
if (['(', ')', ','].includes(char))
|
14
|
+
active = true;
|
15
|
+
if (char === '(')
|
16
|
+
level++;
|
17
|
+
if (char === ')')
|
18
|
+
level--;
|
19
|
+
if (!active)
|
20
|
+
continue;
|
21
|
+
if (level === 0) {
|
22
|
+
if (char === ' ' && ['event', 'function', ''].includes(result))
|
23
|
+
result = '';
|
24
|
+
else {
|
25
|
+
result += char;
|
26
|
+
if (char === ')') {
|
27
|
+
valid = true;
|
28
|
+
break;
|
29
|
+
}
|
30
|
+
}
|
31
|
+
continue;
|
32
|
+
}
|
33
|
+
if (char === ' ') {
|
34
|
+
if (signature[i - 1] !== ',' && current !== ',' && current !== ',(') {
|
35
|
+
current = '';
|
36
|
+
active = false;
|
37
|
+
}
|
38
|
+
continue;
|
39
|
+
}
|
40
|
+
result += char;
|
41
|
+
current += char;
|
42
|
+
}
|
43
|
+
if (!valid)
|
44
|
+
throw new base_js_1.BaseError('Unable to normalize signature.');
|
45
|
+
return result;
|
46
|
+
}
|
47
|
+
exports.normalizeSignature = normalizeSignature;
|
48
|
+
//# sourceMappingURL=normalizeSignature.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"normalizeSignature.js","sourceRoot":"","sources":["../../../utils/hash/normalizeSignature.ts"],"names":[],"mappings":";;;AAAA,kDAAgD;AAOhD,SAAgB,kBAAkB,CAChC,SAAuC;IAEvC,IAAI,MAAM,GAAG,IAAI,CAAA;IACjB,IAAI,OAAO,GAAG,EAAE,CAAA;IAChB,IAAI,KAAK,GAAG,CAAC,CAAA;IACb,IAAI,MAAM,GAAG,EAAE,CAAA;IACf,IAAI,KAAK,GAAG,KAAK,CAAA;IAEjB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACzC,MAAM,IAAI,GAAG,SAAS,CAAC,CAAC,CAAC,CAAA;QAGzB,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC;YAAE,MAAM,GAAG,IAAI,CAAA;QAGjD,IAAI,IAAI,KAAK,GAAG;YAAE,KAAK,EAAE,CAAA;QACzB,IAAI,IAAI,KAAK,GAAG;YAAE,KAAK,EAAE,CAAA;QAGzB,IAAI,CAAC,MAAM;YAAE,SAAQ;QAGrB,IAAI,KAAK,KAAK,CAAC,EAAE;YACf,IAAI,IAAI,KAAK,GAAG,IAAI,CAAC,OAAO,EAAE,UAAU,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC;gBAC5D,MAAM,GAAG,EAAE,CAAA;iBACR;gBACH,MAAM,IAAI,IAAI,CAAA;gBAGd,IAAI,IAAI,KAAK,GAAG,EAAE;oBAChB,KAAK,GAAG,IAAI,CAAA;oBACZ,MAAK;iBACN;aACF;YAED,SAAQ;SACT;QAGD,IAAI,IAAI,KAAK,GAAG,EAAE;YAEhB,IAAI,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,GAAG,IAAI,OAAO,KAAK,GAAG,IAAI,OAAO,KAAK,IAAI,EAAE;gBACnE,OAAO,GAAG,EAAE,CAAA;gBACZ,MAAM,GAAG,KAAK,CAAA;aACf;YACD,SAAQ;SACT;QAED,MAAM,IAAI,IAAI,CAAA;QACd,OAAO,IAAI,IAAI,CAAA;KAChB;IAED,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,mBAAS,CAAC,gCAAgC,CAAC,CAAA;IAEjE,OAAO,MAAM,CAAA;AACf,CAAC;AAxDD,gDAwDC"}
|
@@ -1,4 +1,5 @@
|
|
1
1
|
const paramsRegex = /((function|event)\s)?(.*)(\((.*)\))/;
|
2
|
+
/** @deprecated – use `parseAbiItem` from `abitype`. */
|
2
3
|
export function extractFunctionParts(def) {
|
3
4
|
const parts = def.match(paramsRegex);
|
4
5
|
const type = parts?.[2] || undefined;
|
@@ -6,9 +7,11 @@ export function extractFunctionParts(def) {
|
|
6
7
|
const params = parts?.[5] || undefined;
|
7
8
|
return { type, name, params };
|
8
9
|
}
|
10
|
+
/** @deprecated – use `parseAbiItem` from `abitype`. */
|
9
11
|
export function extractFunctionName(def) {
|
10
12
|
return extractFunctionParts(def).name;
|
11
13
|
}
|
14
|
+
/** @deprecated – use `parseAbiItem` from `abitype`. */
|
12
15
|
export function extractFunctionParams(def) {
|
13
16
|
const params = extractFunctionParts(def).params;
|
14
17
|
const splitParams = params?.split(',').map((x) => x.trim().split(' '));
|
@@ -18,6 +21,7 @@ export function extractFunctionParams(def) {
|
|
18
21
|
...(param[1] === 'indexed' ? { indexed: true } : {}),
|
19
22
|
}));
|
20
23
|
}
|
24
|
+
/** @deprecated – use `parseAbiItem` from `abitype`. */
|
21
25
|
export function extractFunctionType(def) {
|
22
26
|
return extractFunctionParts(def).type;
|
23
27
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"extractFunctionParts.js","sourceRoot":"","sources":["../../../utils/contract/extractFunctionParts.ts"],"names":[],"mappings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CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;QAClD,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACrD,CAAC,CAAC,CAAA;AACL,CAAC;AAID,uDAAuD;AACvD,MAAM,UAAU,mBAAmB,CAAC,GAAW;IAC7C,OAAO,oBAAoB,CAAC,GAAG,CAAC,CAAC,IAAI,CAAA;AACvC,CAAC"}
|
@@ -1,11 +1,11 @@
|
|
1
|
-
import { formatAbiItem
|
2
|
-
import {
|
3
|
-
export const getFunctionSignature = (
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
return
|
8
|
-
}
|
9
|
-
return
|
1
|
+
import { formatAbiItem } from 'abitype';
|
2
|
+
import { normalizeSignature, } from './normalizeSignature.js';
|
3
|
+
export const getFunctionSignature = (fn_) => {
|
4
|
+
const fn = (() => {
|
5
|
+
if (typeof fn_ === 'string')
|
6
|
+
return fn_;
|
7
|
+
return formatAbiItem(fn_);
|
8
|
+
})();
|
9
|
+
return normalizeSignature(fn);
|
10
10
|
};
|
11
11
|
//# sourceMappingURL=getFunctionSignature.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"getFunctionSignature.js","sourceRoot":"","sources":["../../../utils/hash/getFunctionSignature.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"getFunctionSignature.js","sourceRoot":"","sources":["../../../utils/hash/getFunctionSignature.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,aAAa,EAAE,MAAM,SAAS,CAAA;AAGzD,OAAO,EAEL,kBAAkB,GACnB,MAAM,yBAAyB,CAAA;AAMhC,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,GAAyB,EAAE,EAAE;IAChE,MAAM,EAAE,GAAG,CAAC,GAAG,EAAE;QACf,IAAI,OAAO,GAAG,KAAK,QAAQ;YAAE,OAAO,GAAG,CAAA;QACvC,OAAO,aAAa,CAAC,GAAG,CAAC,CAAA;IAC3B,CAAC,CAAC,EAAE,CAAA;IACJ,OAAO,kBAAkB,CAAC,EAAE,CAAC,CAAA;AAC/B,CAAC,CAAA"}
|
@@ -0,0 +1,51 @@
|
|
1
|
+
import { BaseError } from '../../errors/base.js';
|
2
|
+
export function normalizeSignature(signature) {
|
3
|
+
let active = true;
|
4
|
+
let current = '';
|
5
|
+
let level = 0;
|
6
|
+
let result = '';
|
7
|
+
let valid = false;
|
8
|
+
for (let i = 0; i < signature.length; i++) {
|
9
|
+
const char = signature[i];
|
10
|
+
// If the character is a separator, we want to reactivate.
|
11
|
+
if (['(', ')', ','].includes(char))
|
12
|
+
active = true;
|
13
|
+
// If the character is a "level" token, we want to increment/decrement.
|
14
|
+
if (char === '(')
|
15
|
+
level++;
|
16
|
+
if (char === ')')
|
17
|
+
level--;
|
18
|
+
// If we aren't active, we don't want to mutate the result.
|
19
|
+
if (!active)
|
20
|
+
continue;
|
21
|
+
// If level === 0, we are at the definition level.
|
22
|
+
if (level === 0) {
|
23
|
+
if (char === ' ' && ['event', 'function', ''].includes(result))
|
24
|
+
result = '';
|
25
|
+
else {
|
26
|
+
result += char;
|
27
|
+
// If we are at the end of the definition, we must be finished.
|
28
|
+
if (char === ')') {
|
29
|
+
valid = true;
|
30
|
+
break;
|
31
|
+
}
|
32
|
+
}
|
33
|
+
continue;
|
34
|
+
}
|
35
|
+
// Ignore spaces
|
36
|
+
if (char === ' ') {
|
37
|
+
// If the previous character is a separator, and the current section isn't empty, we want to deactivate.
|
38
|
+
if (signature[i - 1] !== ',' && current !== ',' && current !== ',(') {
|
39
|
+
current = '';
|
40
|
+
active = false;
|
41
|
+
}
|
42
|
+
continue;
|
43
|
+
}
|
44
|
+
result += char;
|
45
|
+
current += char;
|
46
|
+
}
|
47
|
+
if (!valid)
|
48
|
+
throw new BaseError('Unable to normalize signature.');
|
49
|
+
return result;
|
50
|
+
}
|
51
|
+
//# sourceMappingURL=normalizeSignature.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"normalizeSignature.js","sourceRoot":"","sources":["../../../utils/hash/normalizeSignature.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAOhD,MAAM,UAAU,kBAAkB,CAChC,SAAuC;IAEvC,IAAI,MAAM,GAAG,IAAI,CAAA;IACjB,IAAI,OAAO,GAAG,EAAE,CAAA;IAChB,IAAI,KAAK,GAAG,CAAC,CAAA;IACb,IAAI,MAAM,GAAG,EAAE,CAAA;IACf,IAAI,KAAK,GAAG,KAAK,CAAA;IAEjB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACzC,MAAM,IAAI,GAAG,SAAS,CAAC,CAAC,CAAC,CAAA;QAEzB,0DAA0D;QAC1D,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC;YAAE,MAAM,GAAG,IAAI,CAAA;QAEjD,uEAAuE;QACvE,IAAI,IAAI,KAAK,GAAG;YAAE,KAAK,EAAE,CAAA;QACzB,IAAI,IAAI,KAAK,GAAG;YAAE,KAAK,EAAE,CAAA;QAEzB,2DAA2D;QAC3D,IAAI,CAAC,MAAM;YAAE,SAAQ;QAErB,kDAAkD;QAClD,IAAI,KAAK,KAAK,CAAC,EAAE;YACf,IAAI,IAAI,KAAK,GAAG,IAAI,CAAC,OAAO,EAAE,UAAU,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC;gBAC5D,MAAM,GAAG,EAAE,CAAA;iBACR;gBACH,MAAM,IAAI,IAAI,CAAA;gBAEd,+DAA+D;gBAC/D,IAAI,IAAI,KAAK,GAAG,EAAE;oBAChB,KAAK,GAAG,IAAI,CAAA;oBACZ,MAAK;iBACN;aACF;YAED,SAAQ;SACT;QAED,gBAAgB;QAChB,IAAI,IAAI,KAAK,GAAG,EAAE;YAChB,wGAAwG;YACxG,IAAI,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,GAAG,IAAI,OAAO,KAAK,GAAG,IAAI,OAAO,KAAK,IAAI,EAAE;gBACnE,OAAO,GAAG,EAAE,CAAA;gBACZ,MAAM,GAAG,KAAK,CAAA;aACf;YACD,SAAQ;SACT;QAED,MAAM,IAAI,IAAI,CAAA;QACd,OAAO,IAAI,IAAI,CAAA;KAChB;IAED,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,SAAS,CAAC,gCAAgC,CAAC,CAAA;IAEjE,OAAO,MAAM,CAAA;AACf,CAAC"}
|
@@ -1,18 +1,22 @@
|
|
1
1
|
import type { ErrorType } from '../../errors/utils.js';
|
2
2
|
export type ExtractFunctionPartsErrorType = ErrorType;
|
3
|
+
/** @deprecated – use `parseAbiItem` from `abitype`. */
|
3
4
|
export declare function extractFunctionParts(def: string): {
|
4
5
|
type: string | undefined;
|
5
6
|
name: string | undefined;
|
6
7
|
params: string | undefined;
|
7
8
|
};
|
8
9
|
export type ExtractFunctionNameErrorType = ErrorType;
|
10
|
+
/** @deprecated – use `parseAbiItem` from `abitype`. */
|
9
11
|
export declare function extractFunctionName(def: string): string | undefined;
|
10
12
|
export type ExtractFunctionParamsErrorType = ErrorType;
|
13
|
+
/** @deprecated – use `parseAbiItem` from `abitype`. */
|
11
14
|
export declare function extractFunctionParams(def: string): {
|
12
15
|
indexed?: boolean | undefined;
|
13
16
|
type: string;
|
14
17
|
name: string;
|
15
18
|
}[] | undefined;
|
16
19
|
export type ExtractFunctionTypeErrorType = ErrorType;
|
20
|
+
/** @deprecated – use `parseAbiItem` from `abitype`. */
|
17
21
|
export declare function extractFunctionType(def: string): string | undefined;
|
18
22
|
//# sourceMappingURL=extractFunctionParts.d.ts.map
|
@@ -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/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
|
+
}
|