@nomicfoundation/hardhat-utils 4.1.9 → 4.3.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 +18 -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/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 -1
- package/dist/src/internal/request.d.ts.map +1 -1
- package/dist/src/internal/request.js +199 -9
- 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 +3 -3
- package/src/errors/request.ts +12 -0
- package/src/eth.ts +22 -0
- package/src/internal/eth.ts +23 -6
- package/src/internal/request.ts +257 -9
- package/src/request.ts +38 -45
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,MAAM,qBAAqB,KAAK,CAAC;AACxC,eAAO,MAAM,4BAA4B,MAAM,CAAC;AAChD,eAAO,MAAM,kBAAkB,YAAY,CAAC;AAE5C,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;AAC3C,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,SAAS,CAAC;AAC9C,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,aAAa,CAAC;AAMjD;;;;;;;;;;GAUG;AACH,MAAM,WAAW,iBAAiB;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAClC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,WAAW,CAAC,EAAE,WAAW,GAAG,YAAY,CAAC;CAC1C;AAED,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE;QACJ,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC;QACrB,I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c,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAInD;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAO/C;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAE3D;AAED,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,aAAa,EACb,oBAAoB,EACpB,YAAY,EACZ,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,qBAAqB,CAAC"}
|
package/dist/src/request.js
CHANGED
|
@@ -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,OAA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;;;;;GAWG;AACH,MAAM,UAAU,WAAW,CAAC,GAAW;IACrC,OAAO,eAAe,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC;AACrC,CAAC;AAED,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,aAAa,EACb,oBAAoB,EACpB,YAAY,EACZ,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,qBAAqB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nomicfoundation/hardhat-utils",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.3.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": {
|
|
@@ -70,11 +70,11 @@
|
|
|
70
70
|
"dependencies": {
|
|
71
71
|
"@streamparser/json-node": "^0.0.22",
|
|
72
72
|
"env-paths": "^4.0.0",
|
|
73
|
-
"ethereum-cryptography": "^
|
|
73
|
+
"ethereum-cryptography": "^3.0.0",
|
|
74
74
|
"fast-equals": "^6.0.0",
|
|
75
75
|
"json-stream-stringify": "^3.1.7",
|
|
76
76
|
"rfdc": "^1.3.1",
|
|
77
|
-
"undici": "^
|
|
77
|
+
"undici": "^7.29.0"
|
|
78
78
|
},
|
|
79
79
|
"scripts": {
|
|
80
80
|
"lint": "pnpm eslint && pnpm prettier --check",
|
package/src/errors/request.ts
CHANGED
|
@@ -22,6 +22,18 @@ export class DispatcherError extends CustomError {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
export class InvalidProxyUrlError extends CustomError {
|
|
26
|
+
public readonly envVarName: string;
|
|
27
|
+
|
|
28
|
+
constructor(envVarName: string, cause?: Error) {
|
|
29
|
+
super(
|
|
30
|
+
`The proxy url configured in the ${envVarName} environment variable is not a valid url`,
|
|
31
|
+
cause,
|
|
32
|
+
);
|
|
33
|
+
this.envVarName = envVarName;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
25
37
|
export class RequestTimeoutError extends CustomError {
|
|
26
38
|
constructor(url: string, cause?: Error) {
|
|
27
39
|
super(`Request to ${sanitizeUrl(url)} timed out`, cause);
|
package/src/eth.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { PrefixedHexString } from "./hex.js";
|
|
2
2
|
|
|
3
|
+
import { InvalidParameterError } from "./common-errors.js";
|
|
3
4
|
import { bytesToHexString, numberToHexString, setLengthLeft } from "./hex.js";
|
|
4
5
|
import {
|
|
5
6
|
getAddressGenerator,
|
|
6
7
|
getHashGenerator,
|
|
7
8
|
isValidChecksum,
|
|
9
|
+
toChecksumAddress as toChecksumAddressImpl,
|
|
8
10
|
} from "./internal/eth.js";
|
|
9
11
|
|
|
10
12
|
/**
|
|
@@ -27,6 +29,26 @@ export async function isValidChecksumAddress(value: unknown): Promise<boolean> {
|
|
|
27
29
|
return await (isAddress(value) && isValidChecksum(value));
|
|
28
30
|
}
|
|
29
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Converts an Ethereum address to its EIP-55 checksummed representation.
|
|
34
|
+
*
|
|
35
|
+
* @param address The address to convert. It can be checksummed or not, but it
|
|
36
|
+
* must be a valid Ethereum address.
|
|
37
|
+
* @returns The EIP-55 checksummed representation of the address.
|
|
38
|
+
* @throws InvalidParameterError If the input is not an Ethereum address.
|
|
39
|
+
*/
|
|
40
|
+
export async function toChecksumAddress(
|
|
41
|
+
address: string,
|
|
42
|
+
): Promise<PrefixedHexString> {
|
|
43
|
+
if (!isAddress(address)) {
|
|
44
|
+
throw new InvalidParameterError(
|
|
45
|
+
`Expected an Ethereum address. Received: ${address}`,
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return await toChecksumAddressImpl(address);
|
|
50
|
+
}
|
|
51
|
+
|
|
30
52
|
/**
|
|
31
53
|
* Checks if a value is an Ethereum hash.
|
|
32
54
|
*
|
package/src/internal/eth.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { PrefixedHexString } from "../hex.js";
|
|
2
|
+
|
|
1
3
|
import { utf8StringToBytes } from "../bytes.js";
|
|
2
4
|
import { keccak256 } from "../crypto.js";
|
|
3
5
|
import { bytesToHexString, getUnprefixedHexString } from "../hex.js";
|
|
@@ -42,16 +44,19 @@ export async function getAddressGenerator(): Promise<RandomBytesGenerator> {
|
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
/**
|
|
45
|
-
*
|
|
46
|
-
* This method is
|
|
47
|
+
* Converts an Ethereum address to its EIP-55 checksummed representation.
|
|
48
|
+
* This method is an adaptation of the ethereumjs methods at this link:
|
|
47
49
|
* https://github.com/ethereumjs/ethereumjs-monorepo/blob/47f388bfeec553519d11259fee7e7161a77b29b2/packages/util/src/account.ts#L440-L478
|
|
48
50
|
* The main differences are:
|
|
49
|
-
* - the
|
|
50
|
-
* - tha `eip1191ChainId` parameter has been removed.
|
|
51
|
+
* - the `eip1191ChainId` parameter has been removed.
|
|
51
52
|
* - the code has been modified to use the `hardhat-utils` methods
|
|
52
53
|
*
|
|
54
|
+
* It doesn't validate that the input is an Ethereum address; callers must
|
|
55
|
+
* check that first (see the public wrappers in `../eth.ts`).
|
|
53
56
|
*/
|
|
54
|
-
export async function
|
|
57
|
+
export async function toChecksumAddress(
|
|
58
|
+
hexAddress: PrefixedHexString,
|
|
59
|
+
): Promise<PrefixedHexString> {
|
|
55
60
|
const address = getUnprefixedHexString(hexAddress).toLowerCase();
|
|
56
61
|
|
|
57
62
|
const bytes = utf8StringToBytes(address);
|
|
@@ -67,5 +72,17 @@ export async function isValidChecksum(hexAddress: string): Promise<boolean> {
|
|
|
67
72
|
}
|
|
68
73
|
}
|
|
69
74
|
|
|
70
|
-
return `0x${ret}
|
|
75
|
+
return `0x${ret}`;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Checks if the checksum of an address is valid.
|
|
80
|
+
*
|
|
81
|
+
* It doesn't validate that the input is an Ethereum address; callers must
|
|
82
|
+
* check that first (see the public wrappers in `../eth.ts`).
|
|
83
|
+
*/
|
|
84
|
+
export async function isValidChecksum(
|
|
85
|
+
hexAddress: PrefixedHexString,
|
|
86
|
+
): Promise<boolean> {
|
|
87
|
+
return (await toChecksumAddress(hexAddress)) === hexAddress;
|
|
71
88
|
}
|