@nomicfoundation/hardhat-utils 3.0.0-next.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/LICENSE +9 -0
- package/README.md +5 -0
- package/dist/src/bigint.d.ts +32 -0
- package/dist/src/bigint.d.ts.map +1 -0
- package/dist/src/bigint.js +54 -0
- package/dist/src/bigint.js.map +1 -0
- package/dist/src/bytecode.d.ts +27 -0
- package/dist/src/bytecode.d.ts.map +1 -0
- package/dist/src/bytecode.js +60 -0
- package/dist/src/bytecode.js.map +1 -0
- package/dist/src/bytes.d.ts +34 -0
- package/dist/src/bytes.d.ts.map +1 -0
- package/dist/src/bytes.js +47 -0
- package/dist/src/bytes.js.map +1 -0
- package/dist/src/ci.d.ts +7 -0
- package/dist/src/ci.d.ts.map +1 -0
- package/dist/src/ci.js +18 -0
- package/dist/src/ci.js.map +1 -0
- package/dist/src/common-errors.d.ts +5 -0
- package/dist/src/common-errors.d.ts.map +1 -0
- package/dist/src/common-errors.js +7 -0
- package/dist/src/common-errors.js.map +1 -0
- package/dist/src/crypto.d.ts +25 -0
- package/dist/src/crypto.d.ts.map +1 -0
- package/dist/src/crypto.js +32 -0
- package/dist/src/crypto.js.map +1 -0
- package/dist/src/date.d.ts +21 -0
- package/dist/src/date.d.ts.map +1 -0
- package/dist/src/date.js +27 -0
- package/dist/src/date.js.map +1 -0
- package/dist/src/debug.d.ts +16 -0
- package/dist/src/debug.d.ts.map +1 -0
- package/dist/src/debug.js +28 -0
- package/dist/src/debug.js.map +1 -0
- package/dist/src/error.d.ts +80 -0
- package/dist/src/error.d.ts.map +1 -0
- package/dist/src/error.js +97 -0
- package/dist/src/error.js.map +1 -0
- package/dist/src/errors/bytecode.d.ts +18 -0
- package/dist/src/errors/bytecode.d.ts.map +1 -0
- package/dist/src/errors/bytecode.js +59 -0
- package/dist/src/errors/bytecode.js.map +1 -0
- package/dist/src/errors/fs.d.ts +25 -0
- package/dist/src/errors/fs.d.ts.map +1 -0
- package/dist/src/errors/fs.js +41 -0
- package/dist/src/errors/fs.js.map +1 -0
- package/dist/src/errors/package.d.ts +8 -0
- package/dist/src/errors/package.d.ts.map +1 -0
- package/dist/src/errors/package.js +12 -0
- package/dist/src/errors/package.js.map +1 -0
- package/dist/src/errors/request.d.ts +25 -0
- package/dist/src/errors/request.d.ts.map +1 -0
- package/dist/src/errors/request.js +64 -0
- package/dist/src/errors/request.js.map +1 -0
- package/dist/src/errors/subprocess.d.ts +8 -0
- package/dist/src/errors/subprocess.d.ts.map +1 -0
- package/dist/src/errors/subprocess.js +12 -0
- package/dist/src/errors/subprocess.js.map +1 -0
- package/dist/src/eth.d.ts +56 -0
- package/dist/src/eth.d.ts.map +1 -0
- package/dist/src/eth.js +78 -0
- package/dist/src/eth.js.map +1 -0
- package/dist/src/fs.d.ts +241 -0
- package/dist/src/fs.d.ts.map +1 -0
- package/dist/src/fs.js +581 -0
- package/dist/src/fs.js.map +1 -0
- package/dist/src/global-dir.d.ts +28 -0
- package/dist/src/global-dir.d.ts.map +1 -0
- package/dist/src/global-dir.js +42 -0
- package/dist/src/global-dir.js.map +1 -0
- package/dist/src/hex.d.ts +117 -0
- package/dist/src/hex.d.ts.map +1 -0
- package/dist/src/hex.js +187 -0
- package/dist/src/hex.js.map +1 -0
- package/dist/src/internal/bytecode.d.ts +45 -0
- package/dist/src/internal/bytecode.d.ts.map +1 -0
- package/dist/src/internal/bytecode.js +73 -0
- package/dist/src/internal/bytecode.js.map +1 -0
- package/dist/src/internal/eth.d.ts +21 -0
- package/dist/src/internal/eth.d.ts.map +1 -0
- package/dist/src/internal/eth.js +58 -0
- package/dist/src/internal/eth.js.map +1 -0
- package/dist/src/internal/global-dir.d.ts +4 -0
- package/dist/src/internal/global-dir.d.ts.map +1 -0
- package/dist/src/internal/global-dir.js +6 -0
- package/dist/src/internal/global-dir.js.map +1 -0
- package/dist/src/internal/hex.d.ts +2 -0
- package/dist/src/internal/hex.d.ts.map +1 -0
- package/dist/src/internal/hex.js +16 -0
- package/dist/src/internal/hex.js.map +1 -0
- package/dist/src/internal/lang.d.ts +2 -0
- package/dist/src/internal/lang.d.ts.map +1 -0
- package/dist/src/internal/lang.js +9 -0
- package/dist/src/internal/lang.js.map +1 -0
- package/dist/src/internal/package.d.ts +2 -0
- package/dist/src/internal/package.d.ts.map +1 -0
- package/dist/src/internal/package.js +15 -0
- package/dist/src/internal/package.js.map +1 -0
- package/dist/src/internal/request.d.ts +20 -0
- package/dist/src/internal/request.d.ts.map +1 -0
- package/dist/src/internal/request.js +101 -0
- package/dist/src/internal/request.js.map +1 -0
- package/dist/src/lang.d.ts +30 -0
- package/dist/src/lang.d.ts.map +1 -0
- package/dist/src/lang.js +41 -0
- package/dist/src/lang.js.map +1 -0
- package/dist/src/number.d.ts +23 -0
- package/dist/src/number.d.ts.map +1 -0
- package/dist/src/number.js +30 -0
- package/dist/src/number.js.map +1 -0
- package/dist/src/package.d.ts +75 -0
- package/dist/src/package.d.ts.map +1 -0
- package/dist/src/package.js +97 -0
- package/dist/src/package.js.map +1 -0
- package/dist/src/path.d.ts +26 -0
- package/dist/src/path.d.ts.map +1 -0
- package/dist/src/path.js +38 -0
- package/dist/src/path.js.map +1 -0
- package/dist/src/request.d.ts +118 -0
- package/dist/src/request.d.ts.map +1 -0
- package/dist/src/request.js +208 -0
- package/dist/src/request.js.map +1 -0
- package/dist/src/stream.d.ts +10 -0
- package/dist/src/stream.d.ts.map +1 -0
- package/dist/src/stream.js +16 -0
- package/dist/src/stream.js.map +1 -0
- package/dist/src/string.d.ts +45 -0
- package/dist/src/string.d.ts.map +1 -0
- package/dist/src/string.js +60 -0
- package/dist/src/string.js.map +1 -0
- package/dist/src/subprocess.d.ts +13 -0
- package/dist/src/subprocess.d.ts.map +1 -0
- package/dist/src/subprocess.js +33 -0
- package/dist/src/subprocess.js.map +1 -0
- package/dist/src/synchronization.d.ts +6 -0
- package/dist/src/synchronization.d.ts.map +1 -0
- package/dist/src/synchronization.js +107 -0
- package/dist/src/synchronization.js.map +1 -0
- package/package.json +90 -0
- package/src/bigint.ts +61 -0
- package/src/bytecode.ts +90 -0
- package/src/bytes.ts +51 -0
- package/src/ci.ts +19 -0
- package/src/common-errors.ts +7 -0
- package/src/crypto.ts +35 -0
- package/src/date.ts +28 -0
- package/src/debug.ts +38 -0
- package/src/error.ts +105 -0
- package/src/errors/bytecode.ts +75 -0
- package/src/errors/fs.ts +47 -0
- package/src/errors/package.ts +13 -0
- package/src/errors/request.ts +84 -0
- package/src/errors/subprocess.ts +17 -0
- package/src/eth.ts +91 -0
- package/src/fs.ts +678 -0
- package/src/global-dir.ts +51 -0
- package/src/hex.ts +232 -0
- package/src/internal/bytecode.ts +129 -0
- package/src/internal/eth.ts +71 -0
- package/src/internal/global-dir.ts +10 -0
- package/src/internal/hex.ts +21 -0
- package/src/internal/lang.ts +12 -0
- package/src/internal/package.ts +15 -0
- package/src/internal/request.ts +165 -0
- package/src/lang.ts +48 -0
- package/src/number.ts +38 -0
- package/src/package.ts +143 -0
- package/src/path.ts +45 -0
- package/src/request.ts +341 -0
- package/src/stream.ts +16 -0
- package/src/string.ts +69 -0
- package/src/subprocess.ts +46 -0
- package/src/synchronization.ts +126 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
export type PrefixedHexString = `0x${string}`;
|
|
2
|
+
/**
|
|
3
|
+
* Converts a non-negative safe integer or bigint to a hexadecimal string.
|
|
4
|
+
*
|
|
5
|
+
* @param value The number to convert.
|
|
6
|
+
* @returns The hexadecimal representation of the number.
|
|
7
|
+
* @throws InvalidParameterError If the input is not a safe integer or is negative.
|
|
8
|
+
*/
|
|
9
|
+
export declare function numberToHexString(value: number | bigint): PrefixedHexString;
|
|
10
|
+
/**
|
|
11
|
+
* Converts a hexadecimal string to a bigint. The string must be a valid
|
|
12
|
+
* hexadecimal string. The string may be prefixed with "0x" or not. The
|
|
13
|
+
* empty string is considered a valid hexadecimal string, so is the string
|
|
14
|
+
* "0x" and will be converted to 0.
|
|
15
|
+
*
|
|
16
|
+
* @param hexString The hexadecimal string to convert. It must be a valid
|
|
17
|
+
* hexadecimal string.
|
|
18
|
+
* @returns The bigint representation of the hexadecimal string.
|
|
19
|
+
* @throws InvalidParameterError If the input is not a hexadecimal string.
|
|
20
|
+
*/
|
|
21
|
+
export declare function hexStringToBigInt(hexString: string): bigint;
|
|
22
|
+
/**
|
|
23
|
+
* Converts a hexadecimal string to a number. The string must be a valid
|
|
24
|
+
* hexadecimal string. The string may be prefixed with "0x" or not. The
|
|
25
|
+
* empty string is considered a valid hexadecimal string, so is the string
|
|
26
|
+
* "0x" and will be converted to 0.
|
|
27
|
+
*
|
|
28
|
+
* @param hexString The hexadecimal string to convert. It must be a valid
|
|
29
|
+
* hexadecimal string.
|
|
30
|
+
* @returns The number representation of the hexadecimal string.
|
|
31
|
+
* @throws InvalidParameterError If the input is not a hexadecimal string or the value exceeds the Number.MAX_SAFE_INTEGER limit.
|
|
32
|
+
*/
|
|
33
|
+
export declare function hexStringToNumber(hexString: string): number;
|
|
34
|
+
/**
|
|
35
|
+
* Converts a Uint8Array to a hexadecimal string.
|
|
36
|
+
*
|
|
37
|
+
* @param bytes The bytes to convert.
|
|
38
|
+
* @returns PrefixedHexString The hexadecimal representation of the bytes.
|
|
39
|
+
*/
|
|
40
|
+
export declare function bytesToHexString(bytes: Uint8Array): PrefixedHexString;
|
|
41
|
+
/**
|
|
42
|
+
* Converts a hexadecimal string to a Uint8Array. The string must be a valid
|
|
43
|
+
* hexadecimal string. The string may be prefixed with "0x" or not. The empty
|
|
44
|
+
* string is considered a valid hexadecimal string, so is the string "0x" and
|
|
45
|
+
* will be converted to Uint8Array([0]).
|
|
46
|
+
*
|
|
47
|
+
* @param hexString The hexadecimal string to convert.
|
|
48
|
+
* @returns The byte representation of the hexadecimal string.
|
|
49
|
+
* @throws InvalidParameterError If the input is not a hexadecimal string.
|
|
50
|
+
*/
|
|
51
|
+
export declare function hexStringToBytes(hexString: string): Uint8Array;
|
|
52
|
+
/**
|
|
53
|
+
* Normalizes and validates a string that represents a hexadecimal number.
|
|
54
|
+
* The normalization process includes trimming any leading or trailing
|
|
55
|
+
* whitespace, converting all characters to lowercase, and ensuring the string
|
|
56
|
+
* has a "0x" prefix. The validation process checks if the string is a valid
|
|
57
|
+
* hexadecimal string.
|
|
58
|
+
*
|
|
59
|
+
* @param hexString The hex string to normalize.
|
|
60
|
+
* @returns The normalized hexadecimal string.
|
|
61
|
+
*/
|
|
62
|
+
export declare function normalizeHexString(hexString: string): PrefixedHexString;
|
|
63
|
+
/**
|
|
64
|
+
* Checks if a string starts with "0x" (case-insensitive).
|
|
65
|
+
* This function does not validate the input.
|
|
66
|
+
*
|
|
67
|
+
* @param hexString The string to check.
|
|
68
|
+
* @returns True if the string starts with "0x", false otherwise.
|
|
69
|
+
*/
|
|
70
|
+
export declare function isPrefixedHexString(hexString: string): hexString is PrefixedHexString;
|
|
71
|
+
/**
|
|
72
|
+
* Removes the "0x" prefix from a hexadecimal string.
|
|
73
|
+
* If the string is not prefixed, it is returned as is.
|
|
74
|
+
* This function does not validate the input.
|
|
75
|
+
*
|
|
76
|
+
* @param hexString The hexadecimal string.
|
|
77
|
+
* @returns The hexadecimal string without the "0x" prefix.
|
|
78
|
+
*/
|
|
79
|
+
export declare function getUnprefixedHexString(hexString: string): string;
|
|
80
|
+
/**
|
|
81
|
+
* Adds the "0x" prefix to a hexadecimal string.
|
|
82
|
+
* If the string is already prefixed, it is returned as is.
|
|
83
|
+
* This function does not validate the input.
|
|
84
|
+
*
|
|
85
|
+
* @param hexString The hexadecimal string.
|
|
86
|
+
* @returns The hexadecimal string with the "0x" prefix.
|
|
87
|
+
*/
|
|
88
|
+
export declare function getPrefixedHexString(hexString: string): PrefixedHexString;
|
|
89
|
+
/**
|
|
90
|
+
* Checks if a value is a hexadecimal string. The string may be prefixed with
|
|
91
|
+
* "0x" or not. The empty string is considered a valid hexadecimal string, so
|
|
92
|
+
* is the string "0x".
|
|
93
|
+
*
|
|
94
|
+
* @param value The value to check.
|
|
95
|
+
* @returns True if the value is a hexadecimal string, false otherwise.
|
|
96
|
+
*/
|
|
97
|
+
export declare function isHexString(value: unknown): boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Removes leading zeros from a hexadecimal string, unless the string
|
|
100
|
+
* represents the number zero ("0x0").
|
|
101
|
+
* This function does not validate the input.
|
|
102
|
+
*
|
|
103
|
+
* @param hexString The hexadecimal string.
|
|
104
|
+
* @returns The hexadecimal string without leading zeros.
|
|
105
|
+
*/
|
|
106
|
+
export declare function unpadHexString(hexString: string): string;
|
|
107
|
+
/**
|
|
108
|
+
* Pads a hexadecimal string with zeros on the left to a specified length, or
|
|
109
|
+
* truncates it from the left if it's too long.
|
|
110
|
+
* This function does not validate the input.
|
|
111
|
+
*
|
|
112
|
+
* @param hexString The hexadecimal string to pad.
|
|
113
|
+
* @param length The desired length of the hexadecimal string.
|
|
114
|
+
* @returns The padded hexadecimal string.
|
|
115
|
+
*/
|
|
116
|
+
export declare function setLengthLeft(hexString: string, length: number): PrefixedHexString;
|
|
117
|
+
//# sourceMappingURL=hex.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hex.d.ts","sourceRoot":"","sources":["../../src/hex.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,iBAAiB,GAAG,KAAK,MAAM,EAAE,CAAC;AAE9C;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,iBAAiB,CAW3E;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAgB3D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAuB3D;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,UAAU,GAAG,iBAAiB,CAErE;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,UAAU,CAY9D;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,iBAAiB,CAUvE;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,MAAM,GAChB,SAAS,IAAI,iBAAiB,CAEhC;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAEhE;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,iBAAiB,CAEzE;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAEnD;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAIxD;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAC3B,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,GACb,iBAAiB,CAUnB"}
|
package/dist/src/hex.js
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { InvalidParameterError } from "./common-errors.js";
|
|
2
|
+
import { padToEven } from "./internal/hex.js";
|
|
3
|
+
/**
|
|
4
|
+
* Converts a non-negative safe integer or bigint to a hexadecimal string.
|
|
5
|
+
*
|
|
6
|
+
* @param value The number to convert.
|
|
7
|
+
* @returns The hexadecimal representation of the number.
|
|
8
|
+
* @throws InvalidParameterError If the input is not a safe integer or is negative.
|
|
9
|
+
*/
|
|
10
|
+
export function numberToHexString(value) {
|
|
11
|
+
if (value < 0 ||
|
|
12
|
+
(typeof value === "number" && !Number.isSafeInteger(value))) {
|
|
13
|
+
throw new InvalidParameterError(`Expected a non-negative safe integer or bigint. Received: ${value}`);
|
|
14
|
+
}
|
|
15
|
+
return `0x${value.toString(16)}`;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Converts a hexadecimal string to a bigint. The string must be a valid
|
|
19
|
+
* hexadecimal string. The string may be prefixed with "0x" or not. The
|
|
20
|
+
* empty string is considered a valid hexadecimal string, so is the string
|
|
21
|
+
* "0x" and will be converted to 0.
|
|
22
|
+
*
|
|
23
|
+
* @param hexString The hexadecimal string to convert. It must be a valid
|
|
24
|
+
* hexadecimal string.
|
|
25
|
+
* @returns The bigint representation of the hexadecimal string.
|
|
26
|
+
* @throws InvalidParameterError If the input is not a hexadecimal string.
|
|
27
|
+
*/
|
|
28
|
+
export function hexStringToBigInt(hexString) {
|
|
29
|
+
if (!isHexString(hexString)) {
|
|
30
|
+
throw new InvalidParameterError(`Expected a valid hexadecimal string. Received: ${hexString}`);
|
|
31
|
+
}
|
|
32
|
+
// Prefix the string as it is required to make BigInt interpret it as a
|
|
33
|
+
// hexadecimal number.
|
|
34
|
+
let prefixedHexString = getPrefixedHexString(hexString);
|
|
35
|
+
// BigInt does not support "0x" as a valid hexadecimal number, so we need to
|
|
36
|
+
// add a zero after the prefix if the string is "0x".
|
|
37
|
+
prefixedHexString = prefixedHexString === "0x" ? "0x0" : prefixedHexString;
|
|
38
|
+
const bigInt = BigInt(prefixedHexString);
|
|
39
|
+
return bigInt;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Converts a hexadecimal string to a number. The string must be a valid
|
|
43
|
+
* hexadecimal string. The string may be prefixed with "0x" or not. The
|
|
44
|
+
* empty string is considered a valid hexadecimal string, so is the string
|
|
45
|
+
* "0x" and will be converted to 0.
|
|
46
|
+
*
|
|
47
|
+
* @param hexString The hexadecimal string to convert. It must be a valid
|
|
48
|
+
* hexadecimal string.
|
|
49
|
+
* @returns The number representation of the hexadecimal string.
|
|
50
|
+
* @throws InvalidParameterError If the input is not a hexadecimal string or the value exceeds the Number.MAX_SAFE_INTEGER limit.
|
|
51
|
+
*/
|
|
52
|
+
export function hexStringToNumber(hexString) {
|
|
53
|
+
if (!isHexString(hexString)) {
|
|
54
|
+
throw new InvalidParameterError(`Expected a valid hexadecimal string. Received: ${hexString}`);
|
|
55
|
+
}
|
|
56
|
+
// Prefix the string as it is required to make parseInt interpret it as a
|
|
57
|
+
// hexadecimal number.
|
|
58
|
+
let prefixedHexString = getPrefixedHexString(hexString);
|
|
59
|
+
// Handle the special case where the string is "0x".
|
|
60
|
+
prefixedHexString = prefixedHexString === "0x" ? "0x0" : prefixedHexString;
|
|
61
|
+
const numberValue = parseInt(prefixedHexString, 16);
|
|
62
|
+
if (numberValue > Number.MAX_SAFE_INTEGER) {
|
|
63
|
+
throw new InvalidParameterError(`Value exceeds the safe integer limit. Received: ${hexString}`);
|
|
64
|
+
}
|
|
65
|
+
return numberValue;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Converts a Uint8Array to a hexadecimal string.
|
|
69
|
+
*
|
|
70
|
+
* @param bytes The bytes to convert.
|
|
71
|
+
* @returns PrefixedHexString The hexadecimal representation of the bytes.
|
|
72
|
+
*/
|
|
73
|
+
export function bytesToHexString(bytes) {
|
|
74
|
+
return getPrefixedHexString(Buffer.from(bytes).toString("hex"));
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Converts a hexadecimal string to a Uint8Array. The string must be a valid
|
|
78
|
+
* hexadecimal string. The string may be prefixed with "0x" or not. The empty
|
|
79
|
+
* string is considered a valid hexadecimal string, so is the string "0x" and
|
|
80
|
+
* will be converted to Uint8Array([0]).
|
|
81
|
+
*
|
|
82
|
+
* @param hexString The hexadecimal string to convert.
|
|
83
|
+
* @returns The byte representation of the hexadecimal string.
|
|
84
|
+
* @throws InvalidParameterError If the input is not a hexadecimal string.
|
|
85
|
+
*/
|
|
86
|
+
export function hexStringToBytes(hexString) {
|
|
87
|
+
if (!isHexString(hexString)) {
|
|
88
|
+
throw new InvalidParameterError(`Expected a valid hexadecimal string. Received: ${hexString}`);
|
|
89
|
+
}
|
|
90
|
+
// Pad the hex string if it's odd, as Buffer.from will truncate it
|
|
91
|
+
// the last character if it's not a full byte.
|
|
92
|
+
// See: https://nodejs.org/api/buffer.html#buffers-and-character-encodings
|
|
93
|
+
const unprefixedHexString = getUnprefixedHexString(padToEven(hexString));
|
|
94
|
+
return Uint8Array.from(Buffer.from(unprefixedHexString, "hex"));
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Normalizes and validates a string that represents a hexadecimal number.
|
|
98
|
+
* The normalization process includes trimming any leading or trailing
|
|
99
|
+
* whitespace, converting all characters to lowercase, and ensuring the string
|
|
100
|
+
* has a "0x" prefix. The validation process checks if the string is a valid
|
|
101
|
+
* hexadecimal string.
|
|
102
|
+
*
|
|
103
|
+
* @param hexString The hex string to normalize.
|
|
104
|
+
* @returns The normalized hexadecimal string.
|
|
105
|
+
*/
|
|
106
|
+
export function normalizeHexString(hexString) {
|
|
107
|
+
const normalizedHexString = hexString.trim().toLowerCase();
|
|
108
|
+
if (!isHexString(normalizedHexString)) {
|
|
109
|
+
throw new InvalidParameterError(`Expected a valid hexadecimal string. Received: ${hexString}`);
|
|
110
|
+
}
|
|
111
|
+
return getPrefixedHexString(normalizedHexString);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Checks if a string starts with "0x" (case-insensitive).
|
|
115
|
+
* This function does not validate the input.
|
|
116
|
+
*
|
|
117
|
+
* @param hexString The string to check.
|
|
118
|
+
* @returns True if the string starts with "0x", false otherwise.
|
|
119
|
+
*/
|
|
120
|
+
export function isPrefixedHexString(hexString) {
|
|
121
|
+
return hexString.toLowerCase().startsWith("0x");
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Removes the "0x" prefix from a hexadecimal string.
|
|
125
|
+
* If the string is not prefixed, it is returned as is.
|
|
126
|
+
* This function does not validate the input.
|
|
127
|
+
*
|
|
128
|
+
* @param hexString The hexadecimal string.
|
|
129
|
+
* @returns The hexadecimal string without the "0x" prefix.
|
|
130
|
+
*/
|
|
131
|
+
export function getUnprefixedHexString(hexString) {
|
|
132
|
+
return isPrefixedHexString(hexString) ? hexString.substring(2) : hexString;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Adds the "0x" prefix to a hexadecimal string.
|
|
136
|
+
* If the string is already prefixed, it is returned as is.
|
|
137
|
+
* This function does not validate the input.
|
|
138
|
+
*
|
|
139
|
+
* @param hexString The hexadecimal string.
|
|
140
|
+
* @returns The hexadecimal string with the "0x" prefix.
|
|
141
|
+
*/
|
|
142
|
+
export function getPrefixedHexString(hexString) {
|
|
143
|
+
return isPrefixedHexString(hexString) ? hexString : `0x${hexString}`;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Checks if a value is a hexadecimal string. The string may be prefixed with
|
|
147
|
+
* "0x" or not. The empty string is considered a valid hexadecimal string, so
|
|
148
|
+
* is the string "0x".
|
|
149
|
+
*
|
|
150
|
+
* @param value The value to check.
|
|
151
|
+
* @returns True if the value is a hexadecimal string, false otherwise.
|
|
152
|
+
*/
|
|
153
|
+
export function isHexString(value) {
|
|
154
|
+
return typeof value === "string" && /^(?:0x)?[0-9a-f]*$/i.test(value);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Removes leading zeros from a hexadecimal string, unless the string
|
|
158
|
+
* represents the number zero ("0x0").
|
|
159
|
+
* This function does not validate the input.
|
|
160
|
+
*
|
|
161
|
+
* @param hexString The hexadecimal string.
|
|
162
|
+
* @returns The hexadecimal string without leading zeros.
|
|
163
|
+
*/
|
|
164
|
+
export function unpadHexString(hexString) {
|
|
165
|
+
const unprefixedHexString = getUnprefixedHexString(hexString);
|
|
166
|
+
const unpaddedHexString = unprefixedHexString.replace(/^0+/, "");
|
|
167
|
+
return unpaddedHexString === "" ? "0x0" : `0x${unpaddedHexString}`;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Pads a hexadecimal string with zeros on the left to a specified length, or
|
|
171
|
+
* truncates it from the left if it's too long.
|
|
172
|
+
* This function does not validate the input.
|
|
173
|
+
*
|
|
174
|
+
* @param hexString The hexadecimal string to pad.
|
|
175
|
+
* @param length The desired length of the hexadecimal string.
|
|
176
|
+
* @returns The padded hexadecimal string.
|
|
177
|
+
*/
|
|
178
|
+
export function setLengthLeft(hexString, length) {
|
|
179
|
+
const unprefixedHexString = getUnprefixedHexString(hexString);
|
|
180
|
+
// if the string is longer than the desired length, truncate it
|
|
181
|
+
if (unprefixedHexString.length > length) {
|
|
182
|
+
return `0x${unprefixedHexString.slice(-length)}`;
|
|
183
|
+
}
|
|
184
|
+
const paddedHexString = unprefixedHexString.padStart(length, "0");
|
|
185
|
+
return `0x${paddedHexString}`;
|
|
186
|
+
}
|
|
187
|
+
//# sourceMappingURL=hex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hex.js","sourceRoot":"","sources":["../../src/hex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAI9C;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAsB;IACtD,IACE,KAAK,GAAG,CAAC;QACT,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,EAC3D,CAAC;QACD,MAAM,IAAI,qBAAqB,CAC7B,6DAA6D,KAAK,EAAE,CACrE,CAAC;IACJ,CAAC;IAED,OAAO,KAAK,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;AACnC,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,iBAAiB,CAAC,SAAiB;IACjD,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE,CAAC;QAC5B,MAAM,IAAI,qBAAqB,CAC7B,kDAAkD,SAAS,EAAE,CAC9D,CAAC;IACJ,CAAC;IACD,uEAAuE;IACvE,sBAAsB;IACtB,IAAI,iBAAiB,GAAG,oBAAoB,CAAC,SAAS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;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAAC,SAAiB;IAC9C,MAAM,mBAAmB,GAAG,sBAAsB,CAAC,SAAS,CAAC,CAAC;IAC9D,MAAM,iBAAiB,GAAG,mBAAmB,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACjE,OAAO,iBAAiB,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,iBAAiB,EAAE,CAAC;AACrE,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,aAAa,CAC3B,SAAiB,EACjB,MAAc;IAEd,MAAM,mBAAmB,GAAG,sBAAsB,CAAC,SAAS,CAAC,CAAC;IAE9D,+DAA+D;IAC/D,IAAI,mBAAmB,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC;QACxC,OAAO,KAAK,mBAAmB,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC;IACnD,CAAC;IAED,MAAM,eAAe,GAAG,mBAAmB,CAAC,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAClE,OAAO,KAAK,eAAe,EAAE,CAAC;AAChC,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { PrefixedHexString } from "../hex.js";
|
|
2
|
+
export interface Artifact {
|
|
3
|
+
bytecode: string;
|
|
4
|
+
linkReferences: {
|
|
5
|
+
[sourceName: string]: {
|
|
6
|
+
[libraryName: string]: Array<{
|
|
7
|
+
start: number;
|
|
8
|
+
length: number;
|
|
9
|
+
}>;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export interface LibraryLink {
|
|
14
|
+
sourceName: string;
|
|
15
|
+
libraryName: string;
|
|
16
|
+
libraryFqn: string;
|
|
17
|
+
address: string;
|
|
18
|
+
}
|
|
19
|
+
export interface LibraryAddresses {
|
|
20
|
+
[contractName: string]: PrefixedHexString;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Check that the provided library addresses are valid Ethereum addresses.
|
|
24
|
+
* If any of them are not, an InvalidLibraryAddressError is thrown.
|
|
25
|
+
*/
|
|
26
|
+
export declare function checkProvidedLibraryAddresses(providedLibraries: LibraryAddresses): void;
|
|
27
|
+
/**
|
|
28
|
+
* Check that the provided libraries can't be resolved to multiple libraries, or
|
|
29
|
+
* that they are not needed by the contract. If any of these conditions are met,
|
|
30
|
+
* an AmbiguousLibraryNameError or an UnnecessaryLibraryError is thrown.
|
|
31
|
+
*/
|
|
32
|
+
export declare function checkAmbiguousOrUnnecessaryLinks(providedLibraries: LibraryAddresses, neededLibraries: LibraryLink[]): void;
|
|
33
|
+
/**
|
|
34
|
+
* Check that each library is only provided once, either by its name or its
|
|
35
|
+
* fully qualified name. If a library is provided more than once, an
|
|
36
|
+
* OverlappingLibrariesError is thrown.
|
|
37
|
+
*/
|
|
38
|
+
export declare function checkOverlappingLibraryNames(providedLibraries: LibraryAddresses, neededLibraries: LibraryLink[]): void;
|
|
39
|
+
/**
|
|
40
|
+
* Check if the needed libraries have all their addresses resolved. If an
|
|
41
|
+
* address is missing, it means that the user didn't provide it in the
|
|
42
|
+
* providedLibraries map. In that case, an MissingLibrariesError is thrown.
|
|
43
|
+
*/
|
|
44
|
+
export declare function checkMissingLibraryAddresses(neededLibraries: LibraryLink[]): void;
|
|
45
|
+
//# sourceMappingURL=bytecode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bytecode.d.ts","sourceRoot":"","sources":["../../../src/internal/bytecode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAWnD,MAAM,WAAW,QAAQ;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE;QACd,CAAC,UAAU,EAAE,MAAM,GAAG;YACpB,CAAC,WAAW,EAAE,MAAM,GAAG,KAAK,CAAC;gBAAE,KAAK,EAAE,MAAM,CAAC;gBAAC,MAAM,EAAE,MAAM,CAAA;aAAE,CAAC,CAAC;SACjE,CAAC;KACH,CAAC;CACH;AAED,MAAM,WAAW,WAAW;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,gBAAgB;IAC/B,CAAC,YAAY,EAAE,MAAM,GAAG,iBAAiB,CAAC;CAC3C;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,CAC3C,iBAAiB,EAAE,gBAAgB,GAClC,IAAI,CAaN;AAED;;;;GAIG;AACH,wBAAgB,gCAAgC,CAC9C,iBAAiB,EAAE,gBAAgB,EACnC,eAAe,EAAE,WAAW,EAAE,GAC7B,IAAI,CAyBN;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,CAC1C,iBAAiB,EAAE,gBAAgB,EACnC,eAAe,EAAE,WAAW,EAAE,GAC7B,IAAI,CAcN;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,CAC1C,eAAe,EAAE,WAAW,EAAE,GAC7B,IAAI,CAUN"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { AmbiguousLibraryNameError, InvalidLibraryAddressError, MissingLibrariesError, OverlappingLibrariesError, UnnecessaryLibraryError, } from "../errors/bytecode.js";
|
|
2
|
+
import { isAddress } from "../eth.js";
|
|
3
|
+
/**
|
|
4
|
+
* Check that the provided library addresses are valid Ethereum addresses.
|
|
5
|
+
* If any of them are not, an InvalidLibraryAddressError is thrown.
|
|
6
|
+
*/
|
|
7
|
+
export function checkProvidedLibraryAddresses(providedLibraries) {
|
|
8
|
+
const librariesWithInvalidAddresses = {};
|
|
9
|
+
for (const [name, address] of Object.entries(providedLibraries)) {
|
|
10
|
+
if (!isAddress(address)) {
|
|
11
|
+
librariesWithInvalidAddresses[name] = address;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
if (Object.keys(librariesWithInvalidAddresses).length === 0) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
throw new InvalidLibraryAddressError(librariesWithInvalidAddresses);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Check that the provided libraries can't be resolved to multiple libraries, or
|
|
21
|
+
* that they are not needed by the contract. If any of these conditions are met,
|
|
22
|
+
* an AmbiguousLibraryNameError or an UnnecessaryLibraryError is thrown.
|
|
23
|
+
*/
|
|
24
|
+
export function checkAmbiguousOrUnnecessaryLinks(providedLibraries, neededLibraries) {
|
|
25
|
+
const ambiguousLibraries = {};
|
|
26
|
+
const unnecessaryLibraries = [];
|
|
27
|
+
for (const providedLibraryName of Object.keys(providedLibraries)) {
|
|
28
|
+
const matchingLibraries = neededLibraries.filter(({ libraryName, libraryFqn }) => libraryName === providedLibraryName ||
|
|
29
|
+
libraryFqn === providedLibraryName);
|
|
30
|
+
if (matchingLibraries.length > 1) {
|
|
31
|
+
ambiguousLibraries[providedLibraryName] = matchingLibraries;
|
|
32
|
+
}
|
|
33
|
+
else if (matchingLibraries.length === 0) {
|
|
34
|
+
unnecessaryLibraries.push(providedLibraryName);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (Object.keys(ambiguousLibraries).length > 0) {
|
|
38
|
+
throw new AmbiguousLibraryNameError(ambiguousLibraries);
|
|
39
|
+
}
|
|
40
|
+
if (unnecessaryLibraries.length > 0) {
|
|
41
|
+
throw new UnnecessaryLibraryError(unnecessaryLibraries);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Check that each library is only provided once, either by its name or its
|
|
46
|
+
* fully qualified name. If a library is provided more than once, an
|
|
47
|
+
* OverlappingLibrariesError is thrown.
|
|
48
|
+
*/
|
|
49
|
+
export function checkOverlappingLibraryNames(providedLibraries, neededLibraries) {
|
|
50
|
+
const overlappingLibraries = neededLibraries
|
|
51
|
+
.filter(({ libraryName, libraryFqn }) => providedLibraries[libraryFqn] !== undefined &&
|
|
52
|
+
providedLibraries[libraryName] !== undefined)
|
|
53
|
+
.map(({ libraryFqn }) => libraryFqn);
|
|
54
|
+
if (overlappingLibraries.length === 0) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
throw new OverlappingLibrariesError(overlappingLibraries);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Check if the needed libraries have all their addresses resolved. If an
|
|
61
|
+
* address is missing, it means that the user didn't provide it in the
|
|
62
|
+
* providedLibraries map. In that case, an MissingLibrariesError is thrown.
|
|
63
|
+
*/
|
|
64
|
+
export function checkMissingLibraryAddresses(neededLibraries) {
|
|
65
|
+
const missingLibraries = neededLibraries
|
|
66
|
+
.filter(({ address }) => address === undefined)
|
|
67
|
+
.map(({ libraryFqn }) => libraryFqn);
|
|
68
|
+
if (missingLibraries.length === 0) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
throw new MissingLibrariesError(missingLibraries);
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=bytecode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bytecode.js","sourceRoot":"","sources":["../../../src/internal/bytecode.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,yBAAyB,EACzB,0BAA0B,EAC1B,qBAAqB,EACrB,yBAAyB,EACzB,uBAAuB,GACxB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAsBtC;;;GAGG;AACH,MAAM,UAAU,6BAA6B,CAC3C,iBAAmC;IAEnC,MAAM,6BAA6B,GAAqB,EAAE,CAAC;IAC3D,KAAK,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,EAAE,CAAC;QAChE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;YACxB,6BAA6B,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC;QAChD,CAAC;IACH,CAAC;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ACL,CAAC,EAAE,WAAW,EAAE,UAAU,EAAE,EAAE,EAAE,CAC9B,iBAAiB,CAAC,UAAU,CAAC,KAAK,SAAS;QAC3C,iBAAiB,CAAC,WAAW,CAAC,KAAK,SAAS,CAC/C;SACA,GAAG,CAAC,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC;IAEvC,IAAI,oBAAoB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtC,OAAO;IACT,CAAC;IAED,MAAM,IAAI,yBAAyB,CAAC,oBAAoB,CAAC,CAAC;AAC5D,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,4BAA4B,CAC1C,eAA8B;IAE9B,MAAM,gBAAgB,GAAG,eAAe;SACrC,MAAM,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,OAAO,KAAK,SAAS,CAAC;SAC9C,GAAG,CAAC,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC;IAEvC,IAAI,gBAAgB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAClC,OAAO;IACT,CAAC;IAED,MAAM,IAAI,qBAAqB,CAAC,gBAAgB,CAAC,CAAC;AACpD,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
declare class RandomBytesGenerator {
|
|
2
|
+
#private;
|
|
3
|
+
private constructor();
|
|
4
|
+
static create(seed: string): Promise<RandomBytesGenerator>;
|
|
5
|
+
next(): Promise<Uint8Array>;
|
|
6
|
+
}
|
|
7
|
+
export declare function getHashGenerator(): Promise<RandomBytesGenerator>;
|
|
8
|
+
export declare function getAddressGenerator(): Promise<RandomBytesGenerator>;
|
|
9
|
+
/**
|
|
10
|
+
* Checks if a value is an Ethereum address and if the checksum is valid.
|
|
11
|
+
* This method is a a an adaptation of the ethereumjs methods at this link:
|
|
12
|
+
* https://github.com/ethereumjs/ethereumjs-monorepo/blob/47f388bfeec553519d11259fee7e7161a77b29b2/packages/util/src/account.ts#L440-L478
|
|
13
|
+
* The main differences are:
|
|
14
|
+
* - the two methods have been merged into one
|
|
15
|
+
* - tha `eip1191ChainId` parameter has been removed.
|
|
16
|
+
* - the code has been modified to use the `hardhat-utils` methods
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
export declare function isValidChecksum(hexAddress: string): Promise<boolean>;
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=eth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eth.d.ts","sourceRoot":"","sources":["../../../src/internal/eth.ts"],"names":[],"mappings":"AAIA,cAAM,oBAAoB;;IAGxB,OAAO;WAIa,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAM1D,IAAI,IAAI,OAAO,CAAC,UAAU,CAAC;CAOzC;AAKD,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,oBAAoB,CAAC,CAKtE;AAED,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,oBAAoB,CAAC,CAKzE;AAED;;;;;;;;;GASG;AACH,wBAAsB,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAiB1E"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { utf8StringToBytes } from "../bytes.js";
|
|
2
|
+
import { keccak256 } from "../crypto.js";
|
|
3
|
+
import { bytesToHexString, getUnprefixedHexString } from "../hex.js";
|
|
4
|
+
class RandomBytesGenerator {
|
|
5
|
+
#nextValue;
|
|
6
|
+
constructor(nextValue) {
|
|
7
|
+
this.#nextValue = nextValue;
|
|
8
|
+
}
|
|
9
|
+
static async create(seed) {
|
|
10
|
+
const nextValue = await keccak256(Buffer.from(seed));
|
|
11
|
+
return new RandomBytesGenerator(nextValue);
|
|
12
|
+
}
|
|
13
|
+
async next() {
|
|
14
|
+
const valueToReturn = this.#nextValue;
|
|
15
|
+
this.#nextValue = await keccak256(this.#nextValue);
|
|
16
|
+
return valueToReturn;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
let hashGenerator = null;
|
|
20
|
+
let addressGenerator = null;
|
|
21
|
+
export async function getHashGenerator() {
|
|
22
|
+
if (hashGenerator === null) {
|
|
23
|
+
hashGenerator = await RandomBytesGenerator.create("hashSeed");
|
|
24
|
+
}
|
|
25
|
+
return hashGenerator;
|
|
26
|
+
}
|
|
27
|
+
export async function getAddressGenerator() {
|
|
28
|
+
if (addressGenerator === null) {
|
|
29
|
+
addressGenerator = await RandomBytesGenerator.create("addressSeed");
|
|
30
|
+
}
|
|
31
|
+
return addressGenerator;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Checks if a value is an Ethereum address and if the checksum is valid.
|
|
35
|
+
* This method is a a an adaptation of the ethereumjs methods at this link:
|
|
36
|
+
* https://github.com/ethereumjs/ethereumjs-monorepo/blob/47f388bfeec553519d11259fee7e7161a77b29b2/packages/util/src/account.ts#L440-L478
|
|
37
|
+
* The main differences are:
|
|
38
|
+
* - the two methods have been merged into one
|
|
39
|
+
* - tha `eip1191ChainId` parameter has been removed.
|
|
40
|
+
* - the code has been modified to use the `hardhat-utils` methods
|
|
41
|
+
*
|
|
42
|
+
*/
|
|
43
|
+
export async function isValidChecksum(hexAddress) {
|
|
44
|
+
const address = getUnprefixedHexString(hexAddress).toLowerCase();
|
|
45
|
+
const bytes = utf8StringToBytes(address);
|
|
46
|
+
const hash = bytesToHexString(await keccak256(bytes)).slice(2);
|
|
47
|
+
let ret = "";
|
|
48
|
+
for (let i = 0; i < address.length; i++) {
|
|
49
|
+
if (parseInt(hash[i], 16) >= 8) {
|
|
50
|
+
ret += address[i].toUpperCase();
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
ret += address[i];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return `0x${ret}` === hexAddress;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=eth.js.map
|
|
@@ -0,0 +1 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AC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,UAAkB;IACtD,MAAM,OAAO,GAAG,sBAAsB,CAAC,UAAU,CAAC,CAAC,WAAW,EAAE,CAAC;IAEjE,MAAM,KAAK,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAC;IAEzC,MAAM,IAAI,GAAG,gBAAgB,CAAC,MAAM,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAE/D,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACxC,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;YAC/B,GAAG,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;QAClC,CAAC;aAAM,CAAC;YACN,GAAG,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC;QACpB,CAAC;IACH,CAAC;IAED,OAAO,KAAK,GAAG,EAAE,KAAK,UAAU,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global-dir.d.ts","sourceRoot":"","sources":["../../../src/internal/global-dir.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,WAAW,CAAC;AAEtC,eAAO,MAAM,oBAAoB,YAAY,CAAC;AAE9C,wBAAsB,aAAa,CACjC,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAGzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global-dir.js","sourceRoot":"","sources":["../../../src/internal/global-dir.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,oBAAoB,GAAG,SAAS,CAAC;AAE9C,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,WAAmB;IAEnB,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,CAAC;IACxD,OAAO,QAAQ,CAAC,WAAW,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hex.d.ts","sourceRoot":"","sources":["../../../src/internal/hex.ts"],"names":[],"mappings":"AAMA,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAc/C"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { getPrefixedHexString, getUnprefixedHexString, isPrefixedHexString, } from "../hex.js";
|
|
2
|
+
export function padToEven(value) {
|
|
3
|
+
const isPrefixed = isPrefixedHexString(value);
|
|
4
|
+
const unprefixed = getUnprefixedHexString(value);
|
|
5
|
+
let padded;
|
|
6
|
+
if (unprefixed.length === 0) {
|
|
7
|
+
// Pad the empty string with a single zero, as Buffer.from([]) will not
|
|
8
|
+
// interpret it correctly otherwise.
|
|
9
|
+
padded = "00";
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
padded = unprefixed.length % 2 === 0 ? unprefixed : `0${unprefixed}`;
|
|
13
|
+
}
|
|
14
|
+
return isPrefixed ? getPrefixedHexString(padded) : padded;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=hex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hex.js","sourceRoot":"","sources":["../../../src/internal/hex.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,WAAW,CAAC;AAEnB,MAAM,UAAU,SAAS,CAAC,KAAa;IACrC,MAAM,UAAU,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAC;IAC9C,MAAM,UAAU,GAAG,sBAAsB,CAAC,KAAK,CAAC,CAAC;IAEjD,IAAI,MAAM,CAAC;IACX,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5B,uEAAuE;QACvE,oCAAoC;QACpC,MAAM,GAAG,IAAI,CAAC;IAChB,CAAC;SAAM,CAAC;QACN,MAAM,GAAG,UAAU,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,UAAU,EAAE,CAAC;IACvE,CAAC;IAED,OAAO,UAAU,CAAC,CAAC,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;AAC5D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lang.d.ts","sourceRoot":"","sources":["../../../src/internal/lang.ts"],"names":[],"mappings":"AAGA,wBAAsB,oBAAoB,IAAI,OAAO,EAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,KAAK,CAAC,EAAC,CAQxE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lang.js","sourceRoot":"","sources":["../../../src/internal/lang.ts"],"names":[],"mappings":"AAEA,IAAI,KAAK,GAAoC,IAAI,CAAC;AAClD,MAAM,CAAC,KAAK,UAAU,oBAAoB;IACxC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,CAAC;IAE/C,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACnB,KAAK,GAAG,IAAI,EAAE,CAAC;IACjB,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.d.ts","sourceRoot":"","sources":["../../../src/internal/package.ts"],"names":[],"mappings":"AAEA,wBAAgB,WAAW,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAYrE"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { fileURLToPath } from "node:url";
|
|
2
|
+
export function getFilePath(filePathOrUrl) {
|
|
3
|
+
if (filePathOrUrl.startsWith("file://")) {
|
|
4
|
+
try {
|
|
5
|
+
// This can throw on Windows if the url is malformed,
|
|
6
|
+
// so we catch it and return undefined
|
|
7
|
+
return fileURLToPath(filePathOrUrl);
|
|
8
|
+
}
|
|
9
|
+
catch (_) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return filePathOrUrl;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=package.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.js","sourceRoot":"","sources":["../../../src/internal/package.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,UAAU,WAAW,CAAC,aAAqB;IAC/C,IAAI,aAAa,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QACxC,IAAI,CAAC;YACH,qDAAqD;YACrD,sCAAsC;YACtC,OAAO,aAAa,CAAC,aAAa,CAAC,CAAC;QACtC,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC;IAED,OAAO,aAAa,CAAC;AACvB,CAAC"}
|