@nomicfoundation/hardhat-utils 4.2.0 → 4.4.0
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 +20 -0
- package/dist/src/abi.d.ts +79 -0
- package/dist/src/abi.d.ts.map +1 -0
- package/dist/src/abi.js +114 -0
- package/dist/src/abi.js.map +1 -0
- package/dist/src/errors/abi.d.ts +93 -0
- package/dist/src/errors/abi.d.ts.map +1 -0
- package/dist/src/errors/abi.js +117 -0
- package/dist/src/errors/abi.js.map +1 -0
- package/dist/src/errors/request.d.ts +4 -0
- package/dist/src/errors/request.d.ts.map +1 -1
- package/dist/src/errors/request.js +7 -0
- package/dist/src/errors/request.js.map +1 -1
- package/dist/src/eth.d.ts +9 -0
- package/dist/src/eth.d.ts.map +1 -1
- package/dist/src/eth.js +16 -1
- package/dist/src/eth.js.map +1 -1
- package/dist/src/internal/abi.d.ts +50 -0
- package/dist/src/internal/abi.d.ts.map +1 -0
- package/dist/src/internal/abi.js +248 -0
- package/dist/src/internal/abi.js.map +1 -0
- package/dist/src/internal/bytes.js +3 -3
- package/dist/src/internal/bytes.js.map +1 -1
- package/dist/src/internal/eth.d.ts +14 -5
- package/dist/src/internal/eth.d.ts.map +1 -1
- package/dist/src/internal/eth.js +16 -6
- package/dist/src/internal/eth.js.map +1 -1
- package/dist/src/internal/request.d.ts +37 -0
- package/dist/src/internal/request.d.ts.map +1 -1
- package/dist/src/internal/request.js +168 -1
- package/dist/src/internal/request.js.map +1 -1
- package/dist/src/request.d.ts +26 -9
- package/dist/src/request.d.ts.map +1 -1
- package/dist/src/request.js +31 -38
- package/dist/src/request.js.map +1 -1
- package/package.json +5 -3
- package/src/abi.ts +199 -0
- package/src/errors/abi.ts +156 -0
- package/src/errors/request.ts +12 -0
- package/src/eth.ts +22 -0
- package/src/internal/abi.ts +431 -0
- package/src/internal/bytes.ts +4 -4
- package/src/internal/eth.ts +23 -6
- package/src/internal/request.ts +218 -0
- package/src/request.ts +38 -45
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.js","sourceRoot":"","sources":["../../../src/internal/request.ts"],"names":[],"mappings":"AAIA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,+BAA+B,EAC/B,kBAAkB,EAClB,aAAa,EACb,mBAAmB,EACnB,uBAAuB,
|
|
1
|
+
{"version":3,"file":"request.js","sourceRoot":"","sources":["../../../src/internal/request.ts"],"names":[],"mappings":"AAIA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,+BAA+B,EAC/B,kBAAkB,EAClB,aAAa,EACb,oBAAoB,EACpB,UAAU,EACV,mBAAmB,EACnB,uBAAuB,EACvB,cAAc,GACf,MAAM,eAAe,CAAC;AAYvB,gFAAgF;AAChF,sEAAsE;AACtE,IAAI,MAAkC,CAAC;AAEvC,MAAM,oBAAoB,GAAa,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;AACtE,MAAM,mBAAmB,GAAa,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;AACnE,MAAM,iBAAiB,GAAa,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;AAE7D,wEAAwE;AACxE,wDAAwD;AACxD,MAAM,kBAAkB,GAAgB,IAAI,GAAG,CAAC;IAC9C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AC,IAAI,CAAC;YACX,QAAQ,EAAE,iBAAiB,CACzB,CAAC,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAChE;YACD,IAAI,EAAE,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;SAC/D,CAAC,CAAC;IACL,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/dist/src/request.d.ts
CHANGED
|
@@ -11,7 +11,9 @@ export type Interceptable = Undici.Interceptable;
|
|
|
11
11
|
* Options to configure the dispatcher.
|
|
12
12
|
*
|
|
13
13
|
* @param timeout The timeout in milliseconds. Defaults to {@link DEFAULT_TIMEOUT_IN_MILLISECONDS}.
|
|
14
|
-
* @param proxy The proxy to use. If not provided,
|
|
14
|
+
* @param proxy The proxy to use. If not provided, it's resolved from the
|
|
15
|
+
* `https_proxy`/`HTTPS_PROXY` and `http_proxy`/`HTTP_PROXY` environment
|
|
16
|
+
* variables, unless `NO_PROXY` excludes the url or it points at loopback.
|
|
15
17
|
* @param pool Whether to use a pool dispatcher. Defaults to `false`.
|
|
16
18
|
* @param maxConnections The maximum number of connections to use in the pool. Defaults to {@link DEFAULT_POOL_MAX_CONNECTIONS}.
|
|
17
19
|
* @param isTestDispatcher Whether to use a test dispatcher. Defaults to `false`. It's highly recommended to use a test dispatcher in tests to avoid hanging tests.
|
|
@@ -97,14 +99,21 @@ export declare function postFormRequest(url: string, body: unknown, requestOptio
|
|
|
97
99
|
export declare function download(url: string, destination: string, requestOptions?: RequestOptions, dispatcherOrDispatcherOptions?: Undici.Dispatcher | DispatcherOptions): Promise<void>;
|
|
98
100
|
/**
|
|
99
101
|
* Creates a dispatcher based on the provided options.
|
|
100
|
-
* If the `proxy` option is set,
|
|
102
|
+
* If the `proxy` option is set, or a proxy is configured in the environment for
|
|
103
|
+
* the given url, it creates a {@link Undici.ProxyAgent} dispatcher.
|
|
101
104
|
* If the `pool` option is set to `true`, it creates a {@link Undici.Pool} dispatcher.
|
|
102
105
|
* Otherwise, it creates a basic {@link Undici.Agent} dispatcher.
|
|
103
106
|
*
|
|
107
|
+
* A proxy resolved from the environment takes precedence over `pool`, as a
|
|
108
|
+
* {@link Undici.Pool} is bound to a single origin and can't tunnel. Set
|
|
109
|
+
* `NO_PROXY` to opt a host out, or pass a {@link Undici.Dispatcher} to the
|
|
110
|
+
* request helpers to bypass this entirely.
|
|
111
|
+
*
|
|
104
112
|
* @param url The url to make requests to.
|
|
105
113
|
* @param options The options to configure the dispatcher. See {@link DispatcherOptions}.
|
|
106
114
|
* @returns The configured dispatcher instance.
|
|
107
|
-
* @throws DispatcherError If the dispatcher can't be created
|
|
115
|
+
* @throws DispatcherError If the dispatcher can't be created, including when the
|
|
116
|
+
* proxy configured in the environment isn't a valid url.
|
|
108
117
|
*/
|
|
109
118
|
export declare function getDispatcher(url: string, { timeout, proxy, pool, maxConnections, isTestDispatcher, }?: DispatcherOptions): Promise<Dispatcher>;
|
|
110
119
|
export declare function getTestDispatcher(options?: {
|
|
@@ -113,6 +122,11 @@ export declare function getTestDispatcher(options?: {
|
|
|
113
122
|
/**
|
|
114
123
|
* Determines whether a proxy should be used for a given url.
|
|
115
124
|
*
|
|
125
|
+
* Loopback addresses are never proxied, so that a local node stays reachable
|
|
126
|
+
* when a proxy is configured for everything else. Beyond those, `NO_PROXY` (or
|
|
127
|
+
* `no_proxy`) is the opt-out: `*` disables proxying entirely, and every other
|
|
128
|
+
* entry is matched as described in {@link isExcludedByNoProxy}.
|
|
129
|
+
*
|
|
116
130
|
* @param url The url to check.
|
|
117
131
|
* @returns `true` if a proxy should be used for the url, `false` otherwise.
|
|
118
132
|
*/
|
|
@@ -125,14 +139,17 @@ export declare function shouldUseProxy(url: string): boolean;
|
|
|
125
139
|
*/
|
|
126
140
|
export declare function isValidUrl(url: string): boolean;
|
|
127
141
|
/**
|
|
128
|
-
* Returns the proxy
|
|
129
|
-
* For HTTPS
|
|
130
|
-
* For HTTP
|
|
142
|
+
* Returns the proxy url from environment variables based on the target url.
|
|
143
|
+
* For HTTPS urls, checks `https_proxy` then `HTTPS_PROXY`.
|
|
144
|
+
* For HTTP urls, checks `http_proxy` then `HTTP_PROXY`.
|
|
131
145
|
* Falls back to the other protocol's proxy if none found.
|
|
132
146
|
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
147
|
+
* Empty and whitespace-only values are treated as unset, and the returned value
|
|
148
|
+
* is trimmed. It isn't validated: use {@link isValidUrl} if you need that.
|
|
149
|
+
*
|
|
150
|
+
* @param url The target url to determine proxy for.
|
|
151
|
+
* @returns The proxy url, or `undefined` if none are set.
|
|
135
152
|
*/
|
|
136
153
|
export declare function getProxyUrl(url: string): string | undefined;
|
|
137
|
-
export { ConnectionRefusedError, DispatcherError, DownloadError, RequestError, RequestTimeoutError, ResponseStatusCodeError, } from "./errors/request.js";
|
|
154
|
+
export { ConnectionRefusedError, DispatcherError, DownloadError, InvalidProxyUrlError, RequestError, RequestTimeoutError, ResponseStatusCodeError, } from "./errors/request.js";
|
|
138
155
|
//# sourceMappingURL=request.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,YAAY,MAAM,aAAa,CAAC;AAG5C,OAAO,KAAK,KAAK,MAAM,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,YAAY,MAAM,aAAa,CAAC;AAG5C,OAAO,KAAK,KAAK,MAAM,MAAM,QAAQ,CAAC;AA2BtC,eAAO,MAAM,+BAA+B,SAAU,CAAC;AACvD,eAAO,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GED
|
@@ -4,7 +4,7 @@ import { pipeline } from "node:stream/promises";
|
|
|
4
4
|
import { ensureError } from "./error.js";
|
|
5
5
|
import { DownloadError, RequestError, DispatcherError, } from "./errors/request.js";
|
|
6
6
|
import { move, remove } from "./fs.js";
|
|
7
|
-
import { generateTempFilePath, getBaseDispatcherOptions, getBaseRequestOptions, getBasicDispatcher, getPoolDispatcher, getProxyDispatcher, handleError, } from "./internal/request.js";
|
|
7
|
+
import { findProxyEnvVar, generateTempFilePath, getBaseDispatcherOptions, getBaseRequestOptions, getBasicDispatcher, getPoolDispatcher, getProxyDispatcher, handleError, isExcludedByNoProxy, isLoopbackUrl, resolveProxyFromEnv, } from "./internal/request.js";
|
|
8
8
|
export const DEFAULT_TIMEOUT_IN_MILLISECONDS = 300_000; // Aligned with undici
|
|
9
9
|
export const DEFAULT_MAX_REDIRECTS = 10;
|
|
10
10
|
export const DEFAULT_POOL_MAX_CONNECTIONS = 128;
|
|
@@ -168,23 +168,31 @@ export async function download(url, destination, requestOptions = {}, dispatcher
|
|
|
168
168
|
}
|
|
169
169
|
/**
|
|
170
170
|
* Creates a dispatcher based on the provided options.
|
|
171
|
-
* If the `proxy` option is set,
|
|
171
|
+
* If the `proxy` option is set, or a proxy is configured in the environment for
|
|
172
|
+
* the given url, it creates a {@link Undici.ProxyAgent} dispatcher.
|
|
172
173
|
* If the `pool` option is set to `true`, it creates a {@link Undici.Pool} dispatcher.
|
|
173
174
|
* Otherwise, it creates a basic {@link Undici.Agent} dispatcher.
|
|
174
175
|
*
|
|
176
|
+
* A proxy resolved from the environment takes precedence over `pool`, as a
|
|
177
|
+
* {@link Undici.Pool} is bound to a single origin and can't tunnel. Set
|
|
178
|
+
* `NO_PROXY` to opt a host out, or pass a {@link Undici.Dispatcher} to the
|
|
179
|
+
* request helpers to bypass this entirely.
|
|
180
|
+
*
|
|
175
181
|
* @param url The url to make requests to.
|
|
176
182
|
* @param options The options to configure the dispatcher. See {@link DispatcherOptions}.
|
|
177
183
|
* @returns The configured dispatcher instance.
|
|
178
|
-
* @throws DispatcherError If the dispatcher can't be created
|
|
184
|
+
* @throws DispatcherError If the dispatcher can't be created, including when the
|
|
185
|
+
* proxy configured in the environment isn't a valid url.
|
|
179
186
|
*/
|
|
180
187
|
export async function getDispatcher(url, { timeout, proxy, pool, maxConnections, isTestDispatcher, } = {}) {
|
|
181
188
|
try {
|
|
182
|
-
if (pool
|
|
189
|
+
if (pool === true && proxy !== undefined) {
|
|
183
190
|
throw new Error("The pool and proxy options can't be used at the same time");
|
|
184
191
|
}
|
|
185
192
|
const baseOptions = getBaseDispatcherOptions(timeout, isTestDispatcher);
|
|
186
|
-
|
|
187
|
-
|
|
193
|
+
const resolvedProxy = proxy ?? resolveProxyFromEnv(url);
|
|
194
|
+
if (resolvedProxy !== undefined) {
|
|
195
|
+
return await getProxyDispatcher(resolvedProxy, baseOptions);
|
|
188
196
|
}
|
|
189
197
|
if (pool === true) {
|
|
190
198
|
return await getPoolDispatcher(url, {
|
|
@@ -209,22 +217,17 @@ export async function getTestDispatcher(options = {}) {
|
|
|
209
217
|
/**
|
|
210
218
|
* Determines whether a proxy should be used for a given url.
|
|
211
219
|
*
|
|
220
|
+
* Loopback addresses are never proxied, so that a local node stays reachable
|
|
221
|
+
* when a proxy is configured for everything else. Beyond those, `NO_PROXY` (or
|
|
222
|
+
* `no_proxy`) is the opt-out: `*` disables proxying entirely, and every other
|
|
223
|
+
* entry is matched as described in {@link isExcludedByNoProxy}.
|
|
224
|
+
*
|
|
212
225
|
* @param url The url to check.
|
|
213
226
|
* @returns `true` if a proxy should be used for the url, `false` otherwise.
|
|
214
227
|
*/
|
|
215
228
|
export function shouldUseProxy(url) {
|
|
216
|
-
const
|
|
217
|
-
|
|
218
|
-
if (hostname === "localhost" || hostname === "127.0.0.1" || noProxy === "*") {
|
|
219
|
-
return false;
|
|
220
|
-
}
|
|
221
|
-
if (noProxy !== undefined && noProxy !== "") {
|
|
222
|
-
const noProxySet = new Set(noProxy.split(","));
|
|
223
|
-
if (noProxySet.has(hostname)) {
|
|
224
|
-
return false;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
return true;
|
|
229
|
+
const parsedUrl = new URL(url);
|
|
230
|
+
return !isLoopbackUrl(parsedUrl) && !isExcludedByNoProxy(parsedUrl);
|
|
228
231
|
}
|
|
229
232
|
/**
|
|
230
233
|
* Determines whether an absolute url is valid.
|
|
@@ -242,29 +245,19 @@ export function isValidUrl(url) {
|
|
|
242
245
|
}
|
|
243
246
|
}
|
|
244
247
|
/**
|
|
245
|
-
* Returns the proxy
|
|
246
|
-
* For HTTPS
|
|
247
|
-
* For HTTP
|
|
248
|
+
* Returns the proxy url from environment variables based on the target url.
|
|
249
|
+
* For HTTPS urls, checks `https_proxy` then `HTTPS_PROXY`.
|
|
250
|
+
* For HTTP urls, checks `http_proxy` then `HTTP_PROXY`.
|
|
248
251
|
* Falls back to the other protocol's proxy if none found.
|
|
249
252
|
*
|
|
250
|
-
*
|
|
251
|
-
*
|
|
253
|
+
* Empty and whitespace-only values are treated as unset, and the returned value
|
|
254
|
+
* is trimmed. It isn't validated: use {@link isValidUrl} if you need that.
|
|
255
|
+
*
|
|
256
|
+
* @param url The target url to determine proxy for.
|
|
257
|
+
* @returns The proxy url, or `undefined` if none are set.
|
|
252
258
|
*/
|
|
253
259
|
export function getProxyUrl(url) {
|
|
254
|
-
|
|
255
|
-
if (protocol === "https:") {
|
|
256
|
-
return (process.env.https_proxy ??
|
|
257
|
-
process.env.HTTPS_PROXY ??
|
|
258
|
-
process.env.http_proxy ??
|
|
259
|
-
process.env.HTTP_PROXY);
|
|
260
|
-
}
|
|
261
|
-
else if (protocol === "http:") {
|
|
262
|
-
return (process.env.http_proxy ??
|
|
263
|
-
process.env.HTTP_PROXY ??
|
|
264
|
-
process.env.https_proxy ??
|
|
265
|
-
process.env.HTTPS_PROXY);
|
|
266
|
-
}
|
|
267
|
-
return undefined;
|
|
260
|
+
return findProxyEnvVar(url)?.value;
|
|
268
261
|
}
|
|
269
|
-
export { ConnectionRefusedError, DispatcherError, DownloadError, RequestError, RequestTimeoutError, ResponseStatusCodeError, } from "./errors/request.js";
|
|
262
|
+
export { ConnectionRefusedError, DispatcherError, DownloadError, InvalidProxyUrlError, RequestError, RequestTimeoutError, ResponseStatusCodeError, } from "./errors/request.js";
|
|
270
263
|
//# sourceMappingURL=request.js.map
|
package/dist/src/request.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.js","sourceRoot":"","sources":["../../src/request.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,WAAW,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EACL,aAAa,EACb,YAAY,EACZ,eAAe,GAChB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EACL,oBAAoB,EACpB,wBAAwB,EACxB,qBAAqB,EACrB,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,WAAW,
|
|
1
|
+
{"version":3,"file":"request.js","sourceRoot":"","sources":["../../src/request.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,WAAW,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EACL,aAAa,EACb,YAAY,EACZ,eAAe,GAChB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EACL,eAAe,EACf,oBAAoB,EACpB,wBAAwB,EACx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"version": "4.4.0",
|
|
4
4
|
"description": "Utilities for Hardhat and its plugins",
|
|
5
5
|
"homepage": "https://github.com/NomicFoundation/hardhat/tree/main/packages/hardhat-utils",
|
|
6
6
|
"repository": {
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"type": "module",
|
|
14
14
|
"exports": {
|
|
15
|
+
"./abi": "./dist/src/abi.js",
|
|
15
16
|
"./bigint": "./dist/src/bigint.js",
|
|
16
17
|
"./bytecode": "./dist/src/bytecode.js",
|
|
17
18
|
"./bytes": "./dist/src/bytes.js",
|
|
@@ -62,17 +63,18 @@
|
|
|
62
63
|
"c8": "^12.0.0",
|
|
63
64
|
"eslint": "9.39.5",
|
|
64
65
|
"expect-type": "^1.4.0",
|
|
65
|
-
"prettier": "3.9.
|
|
66
|
+
"prettier": "3.9.8",
|
|
66
67
|
"rimraf": "^6.1.3",
|
|
67
68
|
"tsx": "^4.23.1",
|
|
68
69
|
"typescript": "~6.0.3"
|
|
69
70
|
},
|
|
70
71
|
"dependencies": {
|
|
71
|
-
"@streamparser/json-node": "^0.0.
|
|
72
|
+
"@streamparser/json-node": "^0.0.26",
|
|
72
73
|
"env-paths": "^4.0.0",
|
|
73
74
|
"ethereum-cryptography": "^3.0.0",
|
|
74
75
|
"fast-equals": "^6.0.0",
|
|
75
76
|
"json-stream-stringify": "^3.1.7",
|
|
77
|
+
"micro-eth-signer": "^0.19.0",
|
|
76
78
|
"rfdc": "^1.3.1",
|
|
77
79
|
"undici": "^7.29.0"
|
|
78
80
|
},
|
package/src/abi.ts
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import type { PrefixedHexString } from "./hex.js";
|
|
2
|
+
import type { deployContract as DeployContractT } from "micro-eth-signer/advanced/abi.js";
|
|
3
|
+
|
|
4
|
+
import { ensureError } from "./error.js";
|
|
5
|
+
import {
|
|
6
|
+
AbiEncodingFailedError,
|
|
7
|
+
AbiParametersLengthMismatchError,
|
|
8
|
+
} from "./errors/abi.js";
|
|
9
|
+
import { getPrefixedHexString } from "./hex.js";
|
|
10
|
+
import {
|
|
11
|
+
assertNoDuplicateAbiParameterNames,
|
|
12
|
+
normalizeAbiValue,
|
|
13
|
+
toUnnamedAbiParameters,
|
|
14
|
+
} from "./internal/abi.js";
|
|
15
|
+
|
|
16
|
+
// We don't load micro-eth-signer on startup because it's slow to initialize,
|
|
17
|
+
// and most callers of this module never encode anything.
|
|
18
|
+
let deployContractImpl: typeof DeployContractT | undefined;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A parameter of an ABI fragment.
|
|
22
|
+
*/
|
|
23
|
+
export interface AbiParameter {
|
|
24
|
+
readonly name?: string;
|
|
25
|
+
readonly type: string;
|
|
26
|
+
readonly components?: readonly AbiParameter[];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* An entry of a contract's ABI. Only the fields needed to encode values are
|
|
31
|
+
* modeled.
|
|
32
|
+
*/
|
|
33
|
+
export interface AbiFragment {
|
|
34
|
+
readonly type?: string;
|
|
35
|
+
readonly name?: string;
|
|
36
|
+
readonly inputs?: readonly AbiParameter[];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The signedness and size of a Solidity integer type.
|
|
41
|
+
*/
|
|
42
|
+
export interface IntType {
|
|
43
|
+
readonly signed: boolean;
|
|
44
|
+
readonly bits: number;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The inclusive range of values that a Solidity integer type can hold.
|
|
49
|
+
*/
|
|
50
|
+
export interface IntTypeRange {
|
|
51
|
+
readonly min: bigint;
|
|
52
|
+
readonly max: bigint;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const INT_TYPE_PATTERN = /^(u?)int([1-9]\d*)?$/;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Parses a Solidity integer type name, like `uint256` or `int128`, into its
|
|
59
|
+
* signedness and size in bits. As in Solidity, `uint` and `int` are accepted as
|
|
60
|
+
* aliases of the 256-bit types.
|
|
61
|
+
*
|
|
62
|
+
* @param type The type name to parse.
|
|
63
|
+
* @returns The parsed type, or `undefined` if it isn't a Solidity integer type.
|
|
64
|
+
*/
|
|
65
|
+
export function parseIntType(type: string): IntType | undefined {
|
|
66
|
+
const match = INT_TYPE_PATTERN.exec(type);
|
|
67
|
+
|
|
68
|
+
if (match === null) {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const bits = match[2] === undefined ? 256 : Number(match[2]);
|
|
73
|
+
|
|
74
|
+
if (bits > 256 || bits % 8 !== 0) {
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return { signed: match[1] === "", bits };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Returns the inclusive range of values that a Solidity integer type can hold.
|
|
83
|
+
*
|
|
84
|
+
* @param intType The integer type, as returned by {@link parseIntType}.
|
|
85
|
+
* @returns The minimum and maximum values of the type.
|
|
86
|
+
*/
|
|
87
|
+
export function getIntTypeRange({ signed, bits }: IntType): IntTypeRange {
|
|
88
|
+
if (signed) {
|
|
89
|
+
const bound = 2n ** BigInt(bits - 1);
|
|
90
|
+
return { min: -bound, max: bound - 1n };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return { min: 0n, max: 2n ** BigInt(bits) - 1n };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Returns the parameters of the constructor declared in an ABI.
|
|
98
|
+
*
|
|
99
|
+
* An ABI that declares no constructor yields an empty array, matching the
|
|
100
|
+
* Solidity semantics of an implicit parameterless constructor.
|
|
101
|
+
*
|
|
102
|
+
* @param abi The ABI to read the constructor from.
|
|
103
|
+
* @returns The constructor's parameters.
|
|
104
|
+
*/
|
|
105
|
+
export function getAbiConstructorParameters(
|
|
106
|
+
abi: readonly AbiFragment[],
|
|
107
|
+
): readonly AbiParameter[] {
|
|
108
|
+
return abi.find(({ type }) => type === "constructor")?.inputs ?? [];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* ABI-encodes a list of values, as Solidity encodes a constructor's arguments
|
|
113
|
+
* (i.e. without a function selector).
|
|
114
|
+
*
|
|
115
|
+
* Values are accepted in the same shapes that most Ethereum libraries accept:
|
|
116
|
+
* integers as bigints, safe numbers, or decimal or hex strings; `bytes` as hex
|
|
117
|
+
* strings or `Uint8Array`s; tuples as arrays or as objects keyed by component
|
|
118
|
+
* name; and addresses with or without the "0x" prefix.
|
|
119
|
+
*
|
|
120
|
+
* @param parameters The ABI parameters to encode the values as.
|
|
121
|
+
* @param values The values to encode, in the order of the parameters.
|
|
122
|
+
* @returns The encoded values as a prefixed hex string, or "0x" if there are none.
|
|
123
|
+
* @throws AbiParametersLengthMismatchError If the counts don't match.
|
|
124
|
+
* @throws InvalidAbiValueError If a value can't be encoded as its type.
|
|
125
|
+
* @throws AbiValueOutOfBoundsError If a numeric value is out of its type's range.
|
|
126
|
+
* @throws UnsupportedAbiTypeError If a parameter's type can't be encoded.
|
|
127
|
+
* @throws AbiEncodingFailedError If the encoder fails for any other reason.
|
|
128
|
+
*/
|
|
129
|
+
export async function encodeAbiParameters(
|
|
130
|
+
parameters: readonly AbiParameter[],
|
|
131
|
+
values: readonly unknown[],
|
|
132
|
+
): Promise<PrefixedHexString> {
|
|
133
|
+
if (parameters.length !== values.length) {
|
|
134
|
+
throw new AbiParametersLengthMismatchError(
|
|
135
|
+
parameters.length,
|
|
136
|
+
values.length,
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Returning here also keeps micro-eth-signer unloaded.
|
|
141
|
+
if (parameters.length === 0) {
|
|
142
|
+
return "0x";
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
assertNoDuplicateAbiParameterNames(parameters);
|
|
146
|
+
|
|
147
|
+
// The values are normalized sequentially so that, when more than one is
|
|
148
|
+
// invalid, the error reported is always the one of the first.
|
|
149
|
+
const normalizedValues = [];
|
|
150
|
+
for (const [i, parameter] of parameters.entries()) {
|
|
151
|
+
normalizedValues.push(
|
|
152
|
+
await normalizeAbiValue(parameter, values[i], parameter.name ?? `[${i}]`),
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (deployContractImpl === undefined) {
|
|
157
|
+
({ deployContract: deployContractImpl } =
|
|
158
|
+
await import("micro-eth-signer/advanced/abi.js"));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// The encoder takes the bare value when there's a single parameter, and a
|
|
162
|
+
// positional array otherwise. The array is positional at every level because
|
|
163
|
+
// toUnnamedAbiParameters drops the names.
|
|
164
|
+
const value =
|
|
165
|
+
parameters.length === 1 ? normalizedValues[0] : normalizedValues;
|
|
166
|
+
|
|
167
|
+
// NOTE: this must not be annotated nor frozen with `as const`. With `type`
|
|
168
|
+
// widened to `string`, micro-eth-signer's generic overload resolves to its
|
|
169
|
+
// untyped form, which is what we want for a dynamically built ABI.
|
|
170
|
+
const abi = [
|
|
171
|
+
{ type: "constructor", inputs: toUnnamedAbiParameters(parameters) },
|
|
172
|
+
];
|
|
173
|
+
|
|
174
|
+
let encoded: string;
|
|
175
|
+
try {
|
|
176
|
+
// deployContract returns `<bytecode><encoded args>`, so we pass no bytecode.
|
|
177
|
+
encoded = deployContractImpl(abi, "0x", value);
|
|
178
|
+
} catch (error) {
|
|
179
|
+
// Reached by types that pass validation but the encoder still refuses,
|
|
180
|
+
// such as `uint256[0][]`, whose zero-size element it treats as a DoS risk.
|
|
181
|
+
ensureError(error);
|
|
182
|
+
throw new AbiEncodingFailedError(error);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return getPrefixedHexString(encoded);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export {
|
|
189
|
+
AbiEncodingError,
|
|
190
|
+
AbiEncodingFailedError,
|
|
191
|
+
AbiParametersLengthMismatchError,
|
|
192
|
+
AbiValueOutOfBoundsError,
|
|
193
|
+
DuplicateAbiParameterNameError,
|
|
194
|
+
InvalidAbiValueError,
|
|
195
|
+
UnsupportedAbiTypeError,
|
|
196
|
+
isAbiEncodingError,
|
|
197
|
+
type AbiEncodingErrorKind,
|
|
198
|
+
type AnyAbiEncodingError,
|
|
199
|
+
} from "./errors/abi.js";
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { CustomError } from "../error.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Discriminates the errors that ABI encoding can throw.
|
|
5
|
+
*/
|
|
6
|
+
export type AbiEncodingErrorKind =
|
|
7
|
+
| "parameters-length-mismatch"
|
|
8
|
+
| "invalid-value"
|
|
9
|
+
| "value-out-of-bounds"
|
|
10
|
+
| "unsupported-type"
|
|
11
|
+
| "duplicate-parameter-name"
|
|
12
|
+
| "encoding-failed";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Base class of every error thrown while ABI-encoding values.
|
|
16
|
+
*
|
|
17
|
+
* Consumers should discriminate with `isAbiEncodingError` rather than
|
|
18
|
+
* `instanceof`, so that the checks keep working if more than one copy of this
|
|
19
|
+
* package ends up installed.
|
|
20
|
+
*/
|
|
21
|
+
export abstract class AbiEncodingError extends CustomError {
|
|
22
|
+
public abstract readonly kind: AbiEncodingErrorKind;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Thrown when the number of values to encode doesn't match the number of
|
|
27
|
+
* parameters.
|
|
28
|
+
*/
|
|
29
|
+
export class AbiParametersLengthMismatchError extends AbiEncodingError {
|
|
30
|
+
public readonly kind: "parameters-length-mismatch" =
|
|
31
|
+
"parameters-length-mismatch";
|
|
32
|
+
|
|
33
|
+
constructor(
|
|
34
|
+
public readonly expectedLength: number,
|
|
35
|
+
public readonly providedLength: number,
|
|
36
|
+
) {
|
|
37
|
+
super(
|
|
38
|
+
`Expected ${expectedLength} values to encode, but ${providedLength} were provided.`,
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Thrown when a value can't be encoded as its parameter's Solidity type.
|
|
45
|
+
*/
|
|
46
|
+
export class InvalidAbiValueError extends AbiEncodingError {
|
|
47
|
+
public readonly kind: "invalid-value" = "invalid-value";
|
|
48
|
+
|
|
49
|
+
constructor(
|
|
50
|
+
public readonly path: string,
|
|
51
|
+
public readonly solidityType: string,
|
|
52
|
+
public readonly value: unknown,
|
|
53
|
+
public readonly reason: string,
|
|
54
|
+
) {
|
|
55
|
+
super(
|
|
56
|
+
`The value provided for the parameter "${path}" of type "${solidityType}" cannot be encoded. Reason: ${reason}.`,
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Thrown when a numeric value is outside the range of its Solidity type.
|
|
63
|
+
*/
|
|
64
|
+
export class AbiValueOutOfBoundsError extends AbiEncodingError {
|
|
65
|
+
public readonly kind: "value-out-of-bounds" = "value-out-of-bounds";
|
|
66
|
+
|
|
67
|
+
constructor(
|
|
68
|
+
public readonly path: string,
|
|
69
|
+
public readonly solidityType: string,
|
|
70
|
+
public readonly value: unknown,
|
|
71
|
+
public readonly min: bigint,
|
|
72
|
+
public readonly max: bigint,
|
|
73
|
+
) {
|
|
74
|
+
super(
|
|
75
|
+
`The value provided for the parameter "${path}" is out of bounds for the type "${solidityType}". Expected a value between ${min} and ${max}.`,
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Thrown when a parameter's Solidity type can't be encoded at all.
|
|
82
|
+
*/
|
|
83
|
+
export class UnsupportedAbiTypeError extends AbiEncodingError {
|
|
84
|
+
public readonly kind: "unsupported-type" = "unsupported-type";
|
|
85
|
+
|
|
86
|
+
constructor(
|
|
87
|
+
public readonly path: string,
|
|
88
|
+
public readonly solidityType: string,
|
|
89
|
+
) {
|
|
90
|
+
super(
|
|
91
|
+
`The type "${solidityType}" of the parameter "${path}" is not supported.`,
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Thrown when two parameters, or two components of the same tuple, share a
|
|
98
|
+
* name.
|
|
99
|
+
*
|
|
100
|
+
* Only a hand-written ABI can carry duplicate names; solc never emits one. The
|
|
101
|
+
* encoder's own guard covers named parameters only, and names are stripped
|
|
102
|
+
* before it runs, so it never sees them.
|
|
103
|
+
*/
|
|
104
|
+
export class DuplicateAbiParameterNameError extends AbiEncodingError {
|
|
105
|
+
public readonly kind: "duplicate-parameter-name" = "duplicate-parameter-name";
|
|
106
|
+
|
|
107
|
+
constructor(
|
|
108
|
+
// undefined when the duplicate is between top-level parameters
|
|
109
|
+
public readonly path: string | undefined,
|
|
110
|
+
public readonly duplicatedName: string,
|
|
111
|
+
) {
|
|
112
|
+
super(
|
|
113
|
+
path === undefined
|
|
114
|
+
? `Two or more parameters are named "${duplicatedName}".`
|
|
115
|
+
: `Two or more components of the parameter "${path}" are named "${duplicatedName}".`,
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Thrown when the encoder refuses values that already passed validation.
|
|
122
|
+
*/
|
|
123
|
+
export class AbiEncodingFailedError extends AbiEncodingError {
|
|
124
|
+
public readonly kind: "encoding-failed" = "encoding-failed";
|
|
125
|
+
|
|
126
|
+
constructor(cause: Error) {
|
|
127
|
+
// The encoder's messages don't end with a period, so one is added to keep
|
|
128
|
+
// this message punctuated like the rest.
|
|
129
|
+
super(`The values could not be ABI-encoded: ${cause.message}.`, cause);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* The union of every error that ABI encoding can throw.
|
|
135
|
+
*/
|
|
136
|
+
export type AnyAbiEncodingError =
|
|
137
|
+
| AbiParametersLengthMismatchError
|
|
138
|
+
| InvalidAbiValueError
|
|
139
|
+
| AbiValueOutOfBoundsError
|
|
140
|
+
| UnsupportedAbiTypeError
|
|
141
|
+
| DuplicateAbiParameterNameError
|
|
142
|
+
| AbiEncodingFailedError;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Checks whether a value is the ABI encoding error of the given kind.
|
|
146
|
+
*
|
|
147
|
+
* @param error The value to check.
|
|
148
|
+
* @param kind The kind of error to check for.
|
|
149
|
+
* @returns True if the value is an ABI encoding error of that kind.
|
|
150
|
+
*/
|
|
151
|
+
export function isAbiEncodingError<KindT extends AbiEncodingErrorKind>(
|
|
152
|
+
error: unknown,
|
|
153
|
+
kind: KindT,
|
|
154
|
+
): error is Extract<AnyAbiEncodingError, { kind: KindT }> {
|
|
155
|
+
return error instanceof Error && "kind" in error && error.kind === kind;
|
|
156
|
+
}
|