@nomicfoundation/hardhat-utils 5.1.1 → 5.1.2
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 +14 -0
- package/dist/src/abi.d.ts +110 -1
- package/dist/src/abi.d.ts.map +1 -1
- package/dist/src/abi.js +109 -3
- package/dist/src/abi.js.map +1 -1
- package/dist/src/bytes.js +1 -1
- package/dist/src/bytes.js.map +1 -1
- package/dist/src/errors/abi.d.ts +26 -3
- package/dist/src/errors/abi.d.ts.map +1 -1
- package/dist/src/errors/abi.js +42 -5
- package/dist/src/errors/abi.js.map +1 -1
- package/dist/src/internal/abi-signature.d.ts +34 -0
- package/dist/src/internal/abi-signature.d.ts.map +1 -0
- package/dist/src/internal/abi-signature.js +335 -0
- package/dist/src/internal/abi-signature.js.map +1 -0
- package/dist/src/internal/abi.d.ts +8 -0
- package/dist/src/internal/abi.d.ts.map +1 -1
- package/dist/src/internal/abi.js +19 -8
- package/dist/src/internal/abi.js.map +1 -1
- package/dist/src/internal/request.d.ts +1 -0
- package/dist/src/internal/request.d.ts.map +1 -1
- package/dist/src/internal/request.js +12 -0
- package/dist/src/internal/request.js.map +1 -1
- package/package.json +1 -1
- package/src/abi.ts +197 -1
- package/src/bytes.ts +1 -1
- package/src/errors/abi.ts +68 -11
- package/src/internal/abi-signature.ts +428 -0
- package/src/internal/abi.ts +23 -8
- package/src/internal/request.ts +14 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @nomicfoundation/hardhat-utils
|
|
2
2
|
|
|
3
|
+
## 5.1.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#8748](https://github.com/NomicFoundation/hardhat/pull/8748) [`e2c81c4`](https://github.com/NomicFoundation/hardhat/commit/e2c81c4e8a2ddb951e525f8f91811b7911e5e2e7) Thanks [@ChristopherDedominici](https://github.com/ChristopherDedominici)! - Fixed `encodeAbiParameters` accepting the invalid types `bytes01` to `bytes09` as `bytes1` to `bytes9`.
|
|
8
|
+
|
|
9
|
+
- [#8755](https://github.com/NomicFoundation/hardhat/pull/8755) [`5c2887e`](https://github.com/NomicFoundation/hardhat/commit/5c2887ea05a2881b6196218493183927850c934e) Thanks [@ChristopherDedominici](https://github.com/ChristopherDedominici)! - Made the `kind` argument of `isAbiEncodingError` optional, so it can check for an ABI encoding error of any kind.
|
|
10
|
+
|
|
11
|
+
- [#8748](https://github.com/NomicFoundation/hardhat/pull/8748) [`cd4987c`](https://github.com/NomicFoundation/hardhat/commit/cd4987c947b1ce8f1a5da63b8b8e5f65950a2606) Thanks [@ChristopherDedominici](https://github.com/ChristopherDedominici)! - Added functions to parse human-readable ABI signatures and parameters, and compute their selectors and event topics.
|
|
12
|
+
|
|
13
|
+
- [#8712](https://github.com/NomicFoundation/hardhat/pull/8712) [`665c386`](https://github.com/NomicFoundation/hardhat/commit/665c386fc8f62c77e47d180ef31d41cfef5dc04d) Thanks [@schaable](https://github.com/schaable)! - Improved the reliability of network requests on slow or unstable connections.
|
|
14
|
+
|
|
15
|
+
- [#8838](https://github.com/NomicFoundation/hardhat/pull/8838) [`9d453de`](https://github.com/NomicFoundation/hardhat/commit/9d453de8770f394b966e4592dee22c79fb98f0b2) Thanks [@zjuncal](https://github.com/zjuncal)! - Fixed `setLengthLeft` returning the whole byte array instead of an empty array when truncating to a length of `0`.
|
|
16
|
+
|
|
3
17
|
## 5.1.1
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/dist/src/abi.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export interface AbiParameter {
|
|
|
6
6
|
readonly name?: string;
|
|
7
7
|
readonly type: string;
|
|
8
8
|
readonly components?: readonly AbiParameter[];
|
|
9
|
+
readonly indexed?: boolean;
|
|
9
10
|
}
|
|
10
11
|
/**
|
|
11
12
|
* An entry of a contract's ABI. Only the fields needed to encode values are
|
|
@@ -16,6 +17,49 @@ export interface AbiFragment {
|
|
|
16
17
|
readonly name?: string;
|
|
17
18
|
readonly inputs?: readonly AbiParameter[];
|
|
18
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* A parsed human-readable signature of a function, event or error.
|
|
22
|
+
*/
|
|
23
|
+
export interface AbiSignature {
|
|
24
|
+
/** The keyword the signature starts with, if any. */
|
|
25
|
+
readonly kind?: "function" | "event" | "error" | "constructor";
|
|
26
|
+
/**
|
|
27
|
+
* The name, or "" for a constructor or a bare parameter list, like
|
|
28
|
+
* `(uint256,bool)`.
|
|
29
|
+
*/
|
|
30
|
+
readonly name: string;
|
|
31
|
+
readonly inputs: readonly AbiParameter[];
|
|
32
|
+
/**
|
|
33
|
+
* The return types, written as `f(uint256)(bool)` or
|
|
34
|
+
* `f(uint256) returns (bool)`. They can hold custom types, like `IPool`, kept
|
|
35
|
+
* as written, which aren't ABI types and must be resolved before decoding.
|
|
36
|
+
*/
|
|
37
|
+
readonly outputs: readonly AbiParameter[];
|
|
38
|
+
/** Set to true if the signature has the `anonymous` modifier of events. */
|
|
39
|
+
readonly anonymous?: boolean;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A parsed human-readable signature of a function or error.
|
|
43
|
+
*/
|
|
44
|
+
export interface AbiFunctionSignature {
|
|
45
|
+
/** The keyword the signature starts with, if any. */
|
|
46
|
+
readonly kind?: "function" | "error";
|
|
47
|
+
readonly name: string;
|
|
48
|
+
readonly inputs: readonly AbiParameter[];
|
|
49
|
+
/** The return types. See `AbiSignature#outputs`. */
|
|
50
|
+
readonly outputs: readonly AbiParameter[];
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* A parsed human-readable signature of an event.
|
|
54
|
+
*/
|
|
55
|
+
export interface AbiEventSignature {
|
|
56
|
+
/** The keyword the signature starts with, if any. */
|
|
57
|
+
readonly kind?: "event";
|
|
58
|
+
readonly name: string;
|
|
59
|
+
readonly inputs: readonly AbiParameter[];
|
|
60
|
+
/** Whether the event is anonymous, so it doesn't log its topic. */
|
|
61
|
+
readonly anonymous: boolean;
|
|
62
|
+
}
|
|
19
63
|
/**
|
|
20
64
|
* The signedness and size of a Solidity integer type.
|
|
21
65
|
*/
|
|
@@ -75,5 +119,70 @@ export declare function getAbiConstructorParameters(abi: readonly AbiFragment[])
|
|
|
75
119
|
* @throws AbiEncodingFailedError If the encoder fails for any other reason.
|
|
76
120
|
*/
|
|
77
121
|
export declare function encodeAbiParameters(parameters: readonly AbiParameter[], values: readonly unknown[]): Promise<PrefixedHexString>;
|
|
78
|
-
|
|
122
|
+
/**
|
|
123
|
+
* Parses a human-readable signature, like `transfer(address,uint256)`.
|
|
124
|
+
*
|
|
125
|
+
* It also accepts parameter names, the `indexed` and data location keywords,
|
|
126
|
+
* tuples written as `(...)` or `tuple(...)`, and whole Solidity declarations,
|
|
127
|
+
* like `function balanceOf(address owner) external view returns (uint256);`.
|
|
128
|
+
* Type aliases are normalized, so `uint` becomes `uint256` and `byte` becomes
|
|
129
|
+
* `bytes1`, and function types must be written as `function`. Custom types,
|
|
130
|
+
* like structs or contracts, are only accepted as return types, as resolving
|
|
131
|
+
* them to ABI types needs their definitions.
|
|
132
|
+
*
|
|
133
|
+
* @param signature The signature to parse.
|
|
134
|
+
* @returns The parsed signature.
|
|
135
|
+
* @throws InvalidAbiSignatureError If the signature is invalid.
|
|
136
|
+
*/
|
|
137
|
+
export declare function parseAbiSignature(signature: string): AbiSignature;
|
|
138
|
+
/**
|
|
139
|
+
* Parses a human-readable signature of a function or error, like
|
|
140
|
+
* `transfer(address,uint256)` or `error Unauthorized(address)`, accepting the
|
|
141
|
+
* same syntax as `parseAbiSignature`.
|
|
142
|
+
*
|
|
143
|
+
* @param signature The signature to parse.
|
|
144
|
+
* @returns The parsed signature.
|
|
145
|
+
* @throws InvalidAbiSignatureError If the signature is invalid, has no name, or
|
|
146
|
+
* is of an event or a constructor.
|
|
147
|
+
*/
|
|
148
|
+
export declare function parseAbiFunctionSignature(signature: string): AbiFunctionSignature;
|
|
149
|
+
/**
|
|
150
|
+
* Parses a human-readable signature of an event, like
|
|
151
|
+
* `Transfer(address,address,uint256)`, accepting the same syntax as
|
|
152
|
+
* `parseAbiSignature`.
|
|
153
|
+
*
|
|
154
|
+
* @param signature The signature to parse.
|
|
155
|
+
* @returns The parsed signature.
|
|
156
|
+
* @throws InvalidAbiSignatureError If the signature is invalid, has no name, has
|
|
157
|
+
* return types, or is of a function, error or constructor.
|
|
158
|
+
*/
|
|
159
|
+
export declare function parseAbiEventSignature(signature: string): AbiEventSignature;
|
|
160
|
+
/**
|
|
161
|
+
* Parses a single human-readable parameter, like `uint256`, `address payable`
|
|
162
|
+
* or `(address to, uint256 amount)[]`, accepting the same syntax as the
|
|
163
|
+
* parameters of `parseAbiSignature`.
|
|
164
|
+
*
|
|
165
|
+
* @param parameter The parameter to parse.
|
|
166
|
+
* @returns The parsed parameter.
|
|
167
|
+
* @throws InvalidAbiSignatureError If the parameter is invalid, or isn't a
|
|
168
|
+
* single one.
|
|
169
|
+
*/
|
|
170
|
+
export declare function parseAbiParameter(parameter: string): AbiParameter;
|
|
171
|
+
/**
|
|
172
|
+
* Returns the selector of a function or error: the first 4 bytes of the
|
|
173
|
+
* keccak256 hash of its canonical signature.
|
|
174
|
+
*
|
|
175
|
+
* @param signature The parsed signature.
|
|
176
|
+
* @returns The 4-byte selector, like `0xa9059cbb`.
|
|
177
|
+
*/
|
|
178
|
+
export declare function getAbiSelector(signature: AbiFunctionSignature): Promise<PrefixedHexString>;
|
|
179
|
+
/**
|
|
180
|
+
* Returns the topic of an event: the keccak256 hash of its canonical
|
|
181
|
+
* signature, which non-anonymous events log as their first topic.
|
|
182
|
+
*
|
|
183
|
+
* @param signature The parsed signature.
|
|
184
|
+
* @returns The 32-byte topic.
|
|
185
|
+
*/
|
|
186
|
+
export declare function getAbiEventTopic(signature: AbiEventSignature): Promise<PrefixedHexString>;
|
|
187
|
+
export { AbiEncodingError, AbiEncodingFailedError, AbiParametersLengthMismatchError, AbiValueOutOfBoundsError, DuplicateAbiParameterNameError, InvalidAbiSignatureError, InvalidAbiValueError, UnsupportedAbiTypeError, isAbiEncodingError, isInvalidAbiSignatureError, type AbiEncodingErrorKind, type AnyAbiEncodingError, } from "./errors/abi.js";
|
|
79
188
|
//# sourceMappingURL=abi.d.ts.map
|
package/dist/src/abi.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abi.d.ts","sourceRoot":"","sources":["../../src/abi.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"abi.d.ts","sourceRoot":"","sources":["../../src/abi.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAwBlD;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,CAAC,EAAE,SAAS,YAAY,EAAE,CAAC;IAC9C,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,YAAY,EAAE,CAAC;CAC3C;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,qDAAqD;IACrD,QAAQ,CAAC,IAAI,CAAC,EAAE,UAAU,GAAG,OAAO,GAAG,OAAO,GAAG,aAAa,CAAC;IAC/D;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,SAAS,YAAY,EAAE,CAAC;IACzC;;;;OAIG;IACH,QAAQ,CAAC,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;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,mBAAmB,CACvC,UAAU,EAAE,SAAS,YAAY,EAAE,EACnC,MAAM,EAAE,SAAS,OAAO,EAAE,GACzB,OAAO,CAAC,iBAAiB,CAAC,CAsD5B;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,YAAY,CAEjE;AAED;;;;;;;;;GASG;AACH,wBAAgB,yBAAyB,CACvC,SAAS,EAAE,MAAM,GAChB,oBAAoB,CA2BtB;AAED;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,MAAM,GAAG,iBAAiB,CA4B3E;AAED;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,YAAY,CAEjE;AAED;;;;;;GAMG;AACH,wBAAsB,cAAc,CAClC,SAAS,EAAE,oBAAoB,GAC9B,OAAO,CAAC,iBAAiB,CAAC,CAI5B;AAED;;;;;;GAMG;AACH,wBAAsB,gBAAgB,CACpC,SAAS,EAAE,iBAAiB,GAC3B,OAAO,CAAC,iBAAiB,CAAC,CAE5B;AAED,OAAO,EACL,gBAAgB,EAChB,sBAAsB,EACtB,gCAAgC,EAChC,wBAAwB,EACxB,8BAA8B,EAC9B,wBAAwB,EACxB,oBAAoB,EACpB,uBAAuB,EACvB,kBAAkB,EAClB,0BAA0B,EAC1B,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,GACzB,MAAM,iBAAiB,CAAC"}
|
package/dist/src/abi.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ensureError } from "./error.js";
|
|
2
|
-
import { AbiEncodingFailedError, AbiParametersLengthMismatchError, } from "./errors/abi.js";
|
|
3
|
-
import { getPrefixedHexString } from "./hex.js";
|
|
2
|
+
import { AbiEncodingFailedError, AbiParametersLengthMismatchError, InvalidAbiSignatureError, } from "./errors/abi.js";
|
|
3
|
+
import { bytesToHexString, getPrefixedHexString } from "./hex.js";
|
|
4
|
+
import { AbiSignatureParser, hashCanonicalAbiSignature, } from "./internal/abi-signature.js";
|
|
4
5
|
import { assertNoDuplicateAbiParameterNames, normalizeAbiValue, toUnnamedAbiParameters, } from "./internal/abi.js";
|
|
5
6
|
// We don't load micro-eth-signer on startup because it's slow to initialize,
|
|
6
7
|
// and most callers of this module never encode anything.
|
|
@@ -110,5 +111,110 @@ export async function encodeAbiParameters(parameters, values) {
|
|
|
110
111
|
}
|
|
111
112
|
return getPrefixedHexString(encoded);
|
|
112
113
|
}
|
|
113
|
-
|
|
114
|
+
/**
|
|
115
|
+
* Parses a human-readable signature, like `transfer(address,uint256)`.
|
|
116
|
+
*
|
|
117
|
+
* It also accepts parameter names, the `indexed` and data location keywords,
|
|
118
|
+
* tuples written as `(...)` or `tuple(...)`, and whole Solidity declarations,
|
|
119
|
+
* like `function balanceOf(address owner) external view returns (uint256);`.
|
|
120
|
+
* Type aliases are normalized, so `uint` becomes `uint256` and `byte` becomes
|
|
121
|
+
* `bytes1`, and function types must be written as `function`. Custom types,
|
|
122
|
+
* like structs or contracts, are only accepted as return types, as resolving
|
|
123
|
+
* them to ABI types needs their definitions.
|
|
124
|
+
*
|
|
125
|
+
* @param signature The signature to parse.
|
|
126
|
+
* @returns The parsed signature.
|
|
127
|
+
* @throws InvalidAbiSignatureError If the signature is invalid.
|
|
128
|
+
*/
|
|
129
|
+
export function parseAbiSignature(signature) {
|
|
130
|
+
return new AbiSignatureParser(signature).parse();
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Parses a human-readable signature of a function or error, like
|
|
134
|
+
* `transfer(address,uint256)` or `error Unauthorized(address)`, accepting the
|
|
135
|
+
* same syntax as `parseAbiSignature`.
|
|
136
|
+
*
|
|
137
|
+
* @param signature The signature to parse.
|
|
138
|
+
* @returns The parsed signature.
|
|
139
|
+
* @throws InvalidAbiSignatureError If the signature is invalid, has no name, or
|
|
140
|
+
* is of an event or a constructor.
|
|
141
|
+
*/
|
|
142
|
+
export function parseAbiFunctionSignature(signature) {
|
|
143
|
+
const { kind, name, inputs, outputs, anonymous } = parseAbiSignature(signature);
|
|
144
|
+
if (kind === "event" ||
|
|
145
|
+
anonymous === true ||
|
|
146
|
+
inputs.some((input) => input.indexed === true)) {
|
|
147
|
+
throw new InvalidAbiSignatureError(signature, "it's an event, not a function or error");
|
|
148
|
+
}
|
|
149
|
+
if (kind === "constructor") {
|
|
150
|
+
throw new InvalidAbiSignatureError(signature, "it's a constructor, not a function or error");
|
|
151
|
+
}
|
|
152
|
+
if (name === "") {
|
|
153
|
+
throw new InvalidAbiSignatureError(signature, "it must include a name");
|
|
154
|
+
}
|
|
155
|
+
return { ...(kind !== undefined && { kind }), name, inputs, outputs };
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Parses a human-readable signature of an event, like
|
|
159
|
+
* `Transfer(address,address,uint256)`, accepting the same syntax as
|
|
160
|
+
* `parseAbiSignature`.
|
|
161
|
+
*
|
|
162
|
+
* @param signature The signature to parse.
|
|
163
|
+
* @returns The parsed signature.
|
|
164
|
+
* @throws InvalidAbiSignatureError If the signature is invalid, has no name, has
|
|
165
|
+
* return types, or is of a function, error or constructor.
|
|
166
|
+
*/
|
|
167
|
+
export function parseAbiEventSignature(signature) {
|
|
168
|
+
const { kind, name, inputs, outputs, anonymous } = parseAbiSignature(signature);
|
|
169
|
+
if (kind === "function" || kind === "error" || kind === "constructor") {
|
|
170
|
+
throw new InvalidAbiSignatureError(signature, `it's ${kind === "error" ? "an" : "a"} ${kind}, not an event`);
|
|
171
|
+
}
|
|
172
|
+
if (outputs.length > 0) {
|
|
173
|
+
throw new InvalidAbiSignatureError(signature, "events can't have return types");
|
|
174
|
+
}
|
|
175
|
+
if (name === "") {
|
|
176
|
+
throw new InvalidAbiSignatureError(signature, "it must include a name");
|
|
177
|
+
}
|
|
178
|
+
return {
|
|
179
|
+
...(kind !== undefined && { kind }),
|
|
180
|
+
name,
|
|
181
|
+
inputs,
|
|
182
|
+
anonymous: anonymous === true,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Parses a single human-readable parameter, like `uint256`, `address payable`
|
|
187
|
+
* or `(address to, uint256 amount)[]`, accepting the same syntax as the
|
|
188
|
+
* parameters of `parseAbiSignature`.
|
|
189
|
+
*
|
|
190
|
+
* @param parameter The parameter to parse.
|
|
191
|
+
* @returns The parsed parameter.
|
|
192
|
+
* @throws InvalidAbiSignatureError If the parameter is invalid, or isn't a
|
|
193
|
+
* single one.
|
|
194
|
+
*/
|
|
195
|
+
export function parseAbiParameter(parameter) {
|
|
196
|
+
return new AbiSignatureParser(parameter).parseSingleParameter();
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Returns the selector of a function or error: the first 4 bytes of the
|
|
200
|
+
* keccak256 hash of its canonical signature.
|
|
201
|
+
*
|
|
202
|
+
* @param signature The parsed signature.
|
|
203
|
+
* @returns The 4-byte selector, like `0xa9059cbb`.
|
|
204
|
+
*/
|
|
205
|
+
export async function getAbiSelector(signature) {
|
|
206
|
+
const hash = await hashCanonicalAbiSignature(signature);
|
|
207
|
+
return bytesToHexString(hash.subarray(0, 4));
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Returns the topic of an event: the keccak256 hash of its canonical
|
|
211
|
+
* signature, which non-anonymous events log as their first topic.
|
|
212
|
+
*
|
|
213
|
+
* @param signature The parsed signature.
|
|
214
|
+
* @returns The 32-byte topic.
|
|
215
|
+
*/
|
|
216
|
+
export async function getAbiEventTopic(signature) {
|
|
217
|
+
return bytesToHexString(await hashCanonicalAbiSignature(signature));
|
|
218
|
+
}
|
|
219
|
+
export { AbiEncodingError, AbiEncodingFailedError, AbiParametersLengthMismatchError, AbiValueOutOfBoundsError, DuplicateAbiParameterNameError, InvalidAbiSignatureError, InvalidAbiValueError, UnsupportedAbiTypeError, isAbiEncodingError, isInvalidAbiSignatureError, } from "./errors/abi.js";
|
|
114
220
|
//# sourceMappingURL=abi.js.map
|
package/dist/src/abi.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abi.js","sourceRoot":"","sources":["../../src/abi.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EACL,sBAAsB,EACtB,gCAAgC,
|
|
1
|
+
{"version":3,"file":"abi.js","sourceRoot":"","sources":["../../src/abi.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EACL,sBAAsB,EACtB,gCAAgC,EAChC,wBAAwB,GACzB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAClE,OAAO,EACL,kBAAkB,EAClB,yBAAyB,GAC1B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,kCAAkC,EAClC,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,mBAAmB,CAAC;AAE3B,6EAA6E;AAC7E,yDAAyD;AACzD,IAAI,kBAAsD,CAAC;AAoF3D,MAAM,gBAAgB,GAAG,sBAAsB,CAAC;AAEhD;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,MAAM,KAAK,GAAG,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAE1C,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACnB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAE7D,IAAI,IAAI,GAAG,GAAG,IAAI,IAAI,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;QACjC,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,EAAE,MAAM,EAA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IAAI,wBAAwB,CAChC,SAAS,EACT,gCAAgC,CACjC,CAAC;IACJ,CAAC;IAED,IAAI,IAAI,KAAK,EAAE,EAAE,CAAC;QAChB,MAAM,IAAI,wBAAwB,CAAC,SAAS,EAAE,wBAAwB,CAAC,CAAC;IAC1E,CAAC;IAED,OAAO;QACL,GAAG,CAAC,IAAI,KAAK,SAAS,IAAI,EAAE,IAAI,EAAE,CAAC;QACnC,IAAI;QACJ,MAAM;QACN,SAAS,EAAE,SAAS,KAAK,IAAI;KAC9B,CAAC;AACJ,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,iBAAiB,CAAC,SAAiB;IACjD,OAAO,IAAI,kBAAkB,CAAC,SAAS,CAAC,CAAC,oBAAoB,EAAE,CAAC;AAClE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,SAA+B;IAE/B,MAAM,IAAI,GAAG,MAAM,yBAAyB,CAAC,SAAS,CAAC,CAAC;IAExD,OAAO,gBAAgB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAC/C,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,SAA4B;IAE5B,OAAO,gBAAgB,CAAC,MAAM,yBAAyB,CAAC,SAAS,CAAC,CAAC,CAAC;AACtE,CAAC;AAED,OAAO,EACL,gBAAgB,EAChB,sBAAsB,EACtB,gCAAgC,EAChC,wBAAwB,EACxB,8BAA8B,EAC9B,wBAAwB,EACxB,oBAAoB,EACpB,uBAAuB,EACvB,kBAAkB,EAClB,0BAA0B,GAG3B,MAAM,iBAAiB,CAAC"}
|
package/dist/src/bytes.js
CHANGED
|
@@ -27,7 +27,7 @@ export function setLengthLeft(bytes, length) {
|
|
|
27
27
|
padded.set(bytes, length - bytes.length);
|
|
28
28
|
return padded;
|
|
29
29
|
}
|
|
30
|
-
return bytes.subarray(-length);
|
|
30
|
+
return length === 0 ? bytes.subarray(0, 0) : bytes.subarray(-length);
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
33
|
* Checks if two Uint8Arrays are equal.
|
package/dist/src/bytes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bytes.js","sourceRoot":"","sources":["../../src/bytes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,eAAe,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EACL,kBAAkB,EAClB,6BAA6B,GAC9B,MAAM,oBAAoB,CAAC;AAE5B;;;;;GAKG;AACH,MAAM,UAAU,OAAO,CAAC,KAAc;IACpC,OAAO,KAAK,YAAY,UAAU,CAAC;AACrC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAAC,KAAiB,EAAE,MAAc;IAC7D,IAAI,KAAK,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC;QAC1B,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;QACtC,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;QACzC,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,OAAO,KAAK,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"bytes.js","sourceRoot":"","sources":["../../src/bytes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,eAAe,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,OAAO,E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eAAe,CAAC,iBAAiB;YAChD,CAAC,kBAAkB,CAAC,KAAK,CAAC,MAAM,GAAG,6BAA6B,CAAC,EACjE,CAAC;YACD,OAAO,MAAM,eAAe,CAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC1D,CAAC;QAED,uEAAuE;QACvE,wCAAwC;QACxC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAC7E,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,WAAW,CAAC,CAAC,CAAC,CAAC;QACf,MAAM,IAAI,qBAAqB,CAC7B,4CAA4C,EAC5C,CAAC,CACF,CAAC;IACJ,CAAC;AACH,CAAC;AAED,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/src/errors/abi.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { CustomError } from "../error.js";
|
|
2
|
+
declare const ABI_ENCODING_ERROR_KINDS: readonly ["parameters-length-mismatch", "invalid-value", "value-out-of-bounds", "unsupported-type", "duplicate-parameter-name", "encoding-failed"];
|
|
2
3
|
/**
|
|
3
4
|
* Discriminates the errors that ABI encoding can throw.
|
|
4
5
|
*/
|
|
5
|
-
export type AbiEncodingErrorKind =
|
|
6
|
+
export type AbiEncodingErrorKind = (typeof ABI_ENCODING_ERROR_KINDS)[number];
|
|
6
7
|
/**
|
|
7
8
|
* Base class of every error thrown while ABI-encoding values.
|
|
8
9
|
*
|
|
@@ -81,13 +82,35 @@ export declare class AbiEncodingFailedError extends AbiEncodingError {
|
|
|
81
82
|
*/
|
|
82
83
|
export type AnyAbiEncodingError = AbiParametersLengthMismatchError | InvalidAbiValueError | AbiValueOutOfBoundsError | UnsupportedAbiTypeError | DuplicateAbiParameterNameError | AbiEncodingFailedError;
|
|
83
84
|
/**
|
|
84
|
-
* Checks whether a value is
|
|
85
|
+
* Checks whether a value is an ABI encoding error, optionally of a given kind.
|
|
85
86
|
*
|
|
86
87
|
* @param error The value to check.
|
|
87
|
-
* @param kind The kind of error to check for.
|
|
88
|
+
* @param kind The kind of error to check for. If omitted, any kind matches.
|
|
88
89
|
* @returns True if the value is an ABI encoding error of that kind.
|
|
89
90
|
*/
|
|
91
|
+
export declare function isAbiEncodingError(error: unknown): error is AnyAbiEncodingError;
|
|
90
92
|
export declare function isAbiEncodingError<KindT extends AbiEncodingErrorKind>(error: unknown, kind: KindT): error is Extract<AnyAbiEncodingError, {
|
|
91
93
|
kind: KindT;
|
|
92
94
|
}>;
|
|
95
|
+
/**
|
|
96
|
+
* Thrown when a human-readable ABI signature can't be parsed.
|
|
97
|
+
*
|
|
98
|
+
* Consumers should discriminate with `isInvalidAbiSignatureError` rather than
|
|
99
|
+
* `instanceof`, for the same reason as `isAbiEncodingError`.
|
|
100
|
+
*/
|
|
101
|
+
export declare class InvalidAbiSignatureError extends CustomError {
|
|
102
|
+
readonly input: string;
|
|
103
|
+
readonly reason: string;
|
|
104
|
+
readonly kind: "invalid-signature";
|
|
105
|
+
constructor(input: string, reason: string);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Whether an error is an `InvalidAbiSignatureError`, even if thrown by another
|
|
109
|
+
* copy of this package.
|
|
110
|
+
*
|
|
111
|
+
* @param error The value to check.
|
|
112
|
+
* @returns Whether it's an `InvalidAbiSignatureError`.
|
|
113
|
+
*/
|
|
114
|
+
export declare function isInvalidAbiSignatureError(error: unknown): error is InvalidAbiSignatureError;
|
|
115
|
+
export {};
|
|
93
116
|
//# sourceMappingURL=abi.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abi.d.ts","sourceRoot":"","sources":["../../../src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AAED;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,wBAAwB,CAMnC"}
|
package/dist/src/errors/abi.js
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
import { CustomError } from "../error.js";
|
|
2
|
+
const ABI_ENCODING_ERROR_KINDS = [
|
|
3
|
+
"parameters-length-mismatch",
|
|
4
|
+
"invalid-value",
|
|
5
|
+
"value-out-of-bounds",
|
|
6
|
+
"unsupported-type",
|
|
7
|
+
"duplicate-parameter-name",
|
|
8
|
+
"encoding-failed",
|
|
9
|
+
];
|
|
10
|
+
// unknown so that any `kind` can be looked up without narrowing it first
|
|
11
|
+
const ABI_ENCODING_ERROR_KIND_SET = new Set(ABI_ENCODING_ERROR_KINDS);
|
|
2
12
|
/**
|
|
3
13
|
* Base class of every error thrown while ABI-encoding values.
|
|
4
14
|
*
|
|
@@ -104,14 +114,41 @@ export class AbiEncodingFailedError extends AbiEncodingError {
|
|
|
104
114
|
super(`The values could not be ABI-encoded: ${cause.message}.`, cause);
|
|
105
115
|
}
|
|
106
116
|
}
|
|
117
|
+
export function isAbiEncodingError(error, kind) {
|
|
118
|
+
if (!(error instanceof Error) || !("kind" in error)) {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
if (kind === undefined) {
|
|
122
|
+
return ABI_ENCODING_ERROR_KIND_SET.has(error.kind);
|
|
123
|
+
}
|
|
124
|
+
return error.kind === kind;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Thrown when a human-readable ABI signature can't be parsed.
|
|
128
|
+
*
|
|
129
|
+
* Consumers should discriminate with `isInvalidAbiSignatureError` rather than
|
|
130
|
+
* `instanceof`, for the same reason as `isAbiEncodingError`.
|
|
131
|
+
*/
|
|
132
|
+
export class InvalidAbiSignatureError extends CustomError {
|
|
133
|
+
input;
|
|
134
|
+
reason;
|
|
135
|
+
kind = "invalid-signature";
|
|
136
|
+
constructor(input, reason) {
|
|
137
|
+
super(`The ABI signature "${input}" is invalid: ${reason}.`);
|
|
138
|
+
this.input = input;
|
|
139
|
+
this.reason = reason;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
107
142
|
/**
|
|
108
|
-
*
|
|
143
|
+
* Whether an error is an `InvalidAbiSignatureError`, even if thrown by another
|
|
144
|
+
* copy of this package.
|
|
109
145
|
*
|
|
110
146
|
* @param error The value to check.
|
|
111
|
-
* @
|
|
112
|
-
* @returns True if the value is an ABI encoding error of that kind.
|
|
147
|
+
* @returns Whether it's an `InvalidAbiSignatureError`.
|
|
113
148
|
*/
|
|
114
|
-
export function
|
|
115
|
-
return error instanceof Error &&
|
|
149
|
+
export function isInvalidAbiSignatureError(error) {
|
|
150
|
+
return (error instanceof Error &&
|
|
151
|
+
"kind" in error &&
|
|
152
|
+
error.kind === "invalid-signature");
|
|
116
153
|
}
|
|
117
154
|
//# sourceMappingURL=abi.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abi.js","sourceRoot":"","sources":["../../../src/errors/abi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"abi.js","sourceRoot":"","sources":["../../../src/errors/abi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,MAAM,wBAAwB,GAAG;IAC/B,4BAA4B;IAC5B,eAAe;IACf,qBAAqB;IACrB,kBAAkB;IAClB,0BAA0B;IAC1B,iBAAiB;CACT,CAAC;AAOX,yEAAyE;AACzE,MAAM,2BAA2B,GAAyB,IAAI,GAAG,CAC/D,wBAAwB,CACzB,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,OAAgB,gBAAiB,SAAQ,WAAW;CAEzD;AAED;;;GAGG;AACH,MAAM,OAAO,gCAAiC,SAAQ,gBAAgB;IAKlD;IACA;IALF,IAAI,GAClB,4BAA4B,CAAC;IAE/B,YACkB,cA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K,CAAQ;QACb,WAAM,GAAN,MAAM,CAAQ;IAGhC,CAAC;CACF;AAED;;;;;;GAMG;AACH,MAAM,UAAU,0BAA0B,CACxC,KAAc;IAEd,OAAO,CACL,KAAK,YAAY,KAAK;QACtB,MAAM,IAAI,KAAK;QACf,KAAK,CAAC,IAAI,KAAK,mBAAmB,CACnC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { AbiParameter, AbiSignature } from "../abi.js";
|
|
2
|
+
/**
|
|
3
|
+
* Returns the canonical form of a signature, as used to compute its selector
|
|
4
|
+
* or topic: its name and input types, without spaces nor parameter names.
|
|
5
|
+
*
|
|
6
|
+
* @param signature The parsed signature.
|
|
7
|
+
* @returns The canonical signature, like `transfer(address,uint256)`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getCanonicalAbiSignature({ name, inputs, }: Pick<AbiSignature, "name" | "inputs">): string;
|
|
10
|
+
/**
|
|
11
|
+
* Returns the keccak256 hash of a signature's canonical form. Its first 4 bytes
|
|
12
|
+
* are a function's or error's selector, and the whole hash is an event's topic.
|
|
13
|
+
*
|
|
14
|
+
* @param signature The parsed signature.
|
|
15
|
+
* @returns The 32-byte hash.
|
|
16
|
+
*/
|
|
17
|
+
export declare function hashCanonicalAbiSignature(signature: Pick<AbiSignature, "name" | "inputs">): Promise<Uint8Array>;
|
|
18
|
+
/**
|
|
19
|
+
* A parser of human-readable ABI signatures, or of a single parameter of one.
|
|
20
|
+
* See `parseAbiSignature` for the syntax it accepts.
|
|
21
|
+
*/
|
|
22
|
+
export declare class AbiSignatureParser {
|
|
23
|
+
#private;
|
|
24
|
+
/**
|
|
25
|
+
* Splits the input into tokens. Call `parse` to parse it as a signature, or
|
|
26
|
+
* `parseSingleParameter` to parse it as a parameter.
|
|
27
|
+
*/
|
|
28
|
+
constructor(input: string);
|
|
29
|
+
/** Parses the whole input as a single parameter, like `uint256 amount`. */
|
|
30
|
+
parseSingleParameter(): AbiParameter;
|
|
31
|
+
/** Parses the whole input as a signature, like `transfer(address,uint)`. */
|
|
32
|
+
parse(): AbiSignature;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=abi-signature.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abi-signature.d.ts","sourceRoot":"","sources":["../../../src/internal/abi-signature.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAgD5D;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CAAC,EACvC,IAAI,EACJ,MAAM,GACP,EAAE,IAAI,CAAC,YAAY,EAAE,MAAM,GAAG,QAAQ,CAAC,GAAG,MAAM,CAEhD;AAED;;;;;;GAMG;AACH,wBAAsB,yBAAyB,CAC7C,SAAS,EAAE,IAAI,CAAC,YAAY,EAAE,MAAM,GAAG,QAAQ,CAAC,GAC/C,OAAO,CAAC,UAAU,CAAC,CAIrB;AAWD;;;GAGG;AACH,qBAAa,kBAAkB;;IAa7B;;;OAGG;gBACS,KAAK,EAAE,MAAM;IAOzB,2EAA2E;IACpE,oBAAoB,IAAI,YAAY;IAU3C,4EAA4E;IACrE,KAAK,IAAI,YAAY;CAyR7B"}
|