@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
package/LICENSE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Nomic Foundation
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the minimum of two bigints.
|
|
3
|
+
*
|
|
4
|
+
* @param x The first number to compare.
|
|
5
|
+
* @param y The second number to compare.
|
|
6
|
+
* @returns The smaller of the two numbers.
|
|
7
|
+
*/
|
|
8
|
+
export declare function min(x: bigint, y: bigint): bigint;
|
|
9
|
+
/**
|
|
10
|
+
* Returns the maximum of two bigints.
|
|
11
|
+
*
|
|
12
|
+
* @param x The first number to compare.
|
|
13
|
+
* @param y The second number to compare.
|
|
14
|
+
* @returns The larger of the two numbers.
|
|
15
|
+
*/
|
|
16
|
+
export declare function max(x: bigint, y: bigint): bigint;
|
|
17
|
+
/**
|
|
18
|
+
* Converts a value to a bigint.
|
|
19
|
+
*
|
|
20
|
+
* This function supports several types of input:
|
|
21
|
+
* - `number`: Must be an integer and a safe integer. If it's not, an error is thrown.
|
|
22
|
+
* - `bigint`: Returned as is.
|
|
23
|
+
* - `string`: Converted to a bigint using the BigInt constructor.
|
|
24
|
+
*
|
|
25
|
+
* If the input is of an unsupported type, an error is thrown.
|
|
26
|
+
*
|
|
27
|
+
* @param value The value to convert to a bigint.
|
|
28
|
+
* @returns The input value converted to a bigint.
|
|
29
|
+
* @throws InvalidParameterError If the input value cannot be converted to a bigint.
|
|
30
|
+
*/
|
|
31
|
+
export declare function toBigInt(value: number | string | bigint): bigint;
|
|
32
|
+
//# sourceMappingURL=bigint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bigint.d.ts","sourceRoot":"","sources":["../../src/bigint.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED;;;;;;GAMG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAqBhE"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { InvalidParameterError } from "./common-errors.js";
|
|
2
|
+
import { unreachable } from "./error.js";
|
|
3
|
+
/**
|
|
4
|
+
* Returns the minimum of two bigints.
|
|
5
|
+
*
|
|
6
|
+
* @param x The first number to compare.
|
|
7
|
+
* @param y The second number to compare.
|
|
8
|
+
* @returns The smaller of the two numbers.
|
|
9
|
+
*/
|
|
10
|
+
export function min(x, y) {
|
|
11
|
+
return x < y ? x : y;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Returns the maximum of two bigints.
|
|
15
|
+
*
|
|
16
|
+
* @param x The first number to compare.
|
|
17
|
+
* @param y The second number to compare.
|
|
18
|
+
* @returns The larger of the two numbers.
|
|
19
|
+
*/
|
|
20
|
+
export function max(x, y) {
|
|
21
|
+
return x > y ? x : y;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Converts a value to a bigint.
|
|
25
|
+
*
|
|
26
|
+
* This function supports several types of input:
|
|
27
|
+
* - `number`: Must be an integer and a safe integer. If it's not, an error is thrown.
|
|
28
|
+
* - `bigint`: Returned as is.
|
|
29
|
+
* - `string`: Converted to a bigint using the BigInt constructor.
|
|
30
|
+
*
|
|
31
|
+
* If the input is of an unsupported type, an error is thrown.
|
|
32
|
+
*
|
|
33
|
+
* @param value The value to convert to a bigint.
|
|
34
|
+
* @returns The input value converted to a bigint.
|
|
35
|
+
* @throws InvalidParameterError If the input value cannot be converted to a bigint.
|
|
36
|
+
*/
|
|
37
|
+
export function toBigInt(value) {
|
|
38
|
+
switch (typeof value) {
|
|
39
|
+
case "number":
|
|
40
|
+
if (!Number.isInteger(value)) {
|
|
41
|
+
throw new InvalidParameterError(`${value} is not an integer`);
|
|
42
|
+
}
|
|
43
|
+
if (!Number.isSafeInteger(value)) {
|
|
44
|
+
throw new InvalidParameterError(`Integer ${value} is unsafe. Consider using ${value}n instead. For more details, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isSafeInteger`);
|
|
45
|
+
}
|
|
46
|
+
// `break;` intentionally omitted. fallthrough desired.
|
|
47
|
+
case "string":
|
|
48
|
+
case "bigint":
|
|
49
|
+
return BigInt(value);
|
|
50
|
+
default:
|
|
51
|
+
unreachable(value, new InvalidParameterError(`Unsupported type: ${typeof value}`));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=bigint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bigint.js","sourceRoot":"","sources":["../../src/bigint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC;;;;;;GAMG;AACH,MAAM,UAAU,GAAG,CAAC,CAAS,EAAE,CAAS;IACtC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACvB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,GAAG,CAAC,CAAS,EAAE,CAAS;IACtC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACvB,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,QAAQ,CAAC,KAA+B;IACtD,QAAQ,OAAO,KAAK,EAAE,CAAC;QACrB,KAAK,QAAQ;YACX,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC7B,MAAM,IAAI,qBAAqB,CAAC,GAAG,KAAK,oBAAoB,CAAC,CAAC;YAChE,CAAC;YACD,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;gBACjC,MAAM,IAAI,qBAAqB,CAC7B,WAAW,KAAK,8BAA8B,KAAK,wIAAwI,CAC5L,CAAC;YACJ,CAAC;QACH,uDAAuD;QACvD,KAAK,QAAQ,CAAC;QACd,KAAK,QAAQ;YACX,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;QACvB;YACE,WAAW,CACT,KAAK,EACL,IAAI,qBAAqB,CAAC,qBAAqB,OAAO,KAAK,EAAE,CAAC,CAC/D,CAAC;IACN,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { PrefixedHexString } from "./hex.js";
|
|
2
|
+
import type { Artifact, LibraryAddresses, LibraryLink } from "./internal/bytecode.js";
|
|
3
|
+
/**
|
|
4
|
+
* Resolves the linked bytecode for a given contract artifact by substituting
|
|
5
|
+
* the required library placeholders within the bytecode with the provided
|
|
6
|
+
* library addresses.
|
|
7
|
+
*
|
|
8
|
+
* @param artifact The contract artifact containing the bytecode and link references.
|
|
9
|
+
* @param providedLibraries An object containing library names as keys and their addresses as values.
|
|
10
|
+
* @returns The linked bytecode with all required libraries correctly linked.
|
|
11
|
+
* @throws InvalidLibraryAddressError If any provided library address is invalid.
|
|
12
|
+
* @throws AmbiguousLibraryNameError If any provided library name matches multiple needed libraries.
|
|
13
|
+
* @throws UnnecessaryLibraryError If any provided library name is not needed by the contract.
|
|
14
|
+
* @throws OverlappingLibrariesError If any library is provided more than once.
|
|
15
|
+
* @throws MissingLibrariesError If any needed library address is missing.
|
|
16
|
+
*/
|
|
17
|
+
export declare function resolveLinkedBytecode(artifact: Artifact, providedLibraries: LibraryAddresses): PrefixedHexString;
|
|
18
|
+
/**
|
|
19
|
+
* Links the bytecode of a contract artifact with the provided library addresses.
|
|
20
|
+
* This function does not perform any validation on the provided libraries.
|
|
21
|
+
*
|
|
22
|
+
* @param artifact The contract artifact containing the bytecode and link references.
|
|
23
|
+
* @param libraries An array of LibraryLink objects representing the libraries to be linked.
|
|
24
|
+
* @returns The linked bytecode with all provided libraries correctly linked.
|
|
25
|
+
*/
|
|
26
|
+
export declare function linkBytecode(artifact: Artifact, libraries: LibraryLink[]): PrefixedHexString;
|
|
27
|
+
//# sourceMappingURL=bytecode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bytecode.d.ts","sourceRoot":"","sources":["../../src/bytecode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,KAAK,EACV,QAAQ,EACR,gBAAgB,EAChB,WAAW,EACZ,MAAM,wBAAwB,CAAC;AAUhC;;;;;;;;;;;;;GAaG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,QAAQ,EAClB,iBAAiB,EAAE,gBAAgB,GAClC,iBAAiB,CA0BnB;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,WAAW,EAAE,GACvB,iBAAiB,CAkBnB"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { getPrefixedHexString, getUnprefixedHexString } from "./hex.js";
|
|
2
|
+
import { checkAmbiguousOrUnnecessaryLinks, checkMissingLibraryAddresses, checkOverlappingLibraryNames, checkProvidedLibraryAddresses, } from "./internal/bytecode.js";
|
|
3
|
+
/**
|
|
4
|
+
* Resolves the linked bytecode for a given contract artifact by substituting
|
|
5
|
+
* the required library placeholders within the bytecode with the provided
|
|
6
|
+
* library addresses.
|
|
7
|
+
*
|
|
8
|
+
* @param artifact The contract artifact containing the bytecode and link references.
|
|
9
|
+
* @param providedLibraries An object containing library names as keys and their addresses as values.
|
|
10
|
+
* @returns The linked bytecode with all required libraries correctly linked.
|
|
11
|
+
* @throws InvalidLibraryAddressError If any provided library address is invalid.
|
|
12
|
+
* @throws AmbiguousLibraryNameError If any provided library name matches multiple needed libraries.
|
|
13
|
+
* @throws UnnecessaryLibraryError If any provided library name is not needed by the contract.
|
|
14
|
+
* @throws OverlappingLibrariesError If any library is provided more than once.
|
|
15
|
+
* @throws MissingLibrariesError If any needed library address is missing.
|
|
16
|
+
*/
|
|
17
|
+
export function resolveLinkedBytecode(artifact, providedLibraries) {
|
|
18
|
+
checkProvidedLibraryAddresses(providedLibraries);
|
|
19
|
+
const neededLibraries = [];
|
|
20
|
+
for (const [sourceName, sourceLibraries] of Object.entries(artifact.linkReferences)) {
|
|
21
|
+
for (const libraryName of Object.keys(sourceLibraries)) {
|
|
22
|
+
const libraryFqn = `${sourceName}:${libraryName}`;
|
|
23
|
+
const address = providedLibraries[libraryFqn] ?? providedLibraries[libraryName];
|
|
24
|
+
neededLibraries.push({
|
|
25
|
+
sourceName,
|
|
26
|
+
libraryName,
|
|
27
|
+
libraryFqn,
|
|
28
|
+
address,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
checkAmbiguousOrUnnecessaryLinks(providedLibraries, neededLibraries);
|
|
33
|
+
checkOverlappingLibraryNames(providedLibraries, neededLibraries);
|
|
34
|
+
checkMissingLibraryAddresses(neededLibraries);
|
|
35
|
+
return linkBytecode(artifact, neededLibraries);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Links the bytecode of a contract artifact with the provided library addresses.
|
|
39
|
+
* This function does not perform any validation on the provided libraries.
|
|
40
|
+
*
|
|
41
|
+
* @param artifact The contract artifact containing the bytecode and link references.
|
|
42
|
+
* @param libraries An array of LibraryLink objects representing the libraries to be linked.
|
|
43
|
+
* @returns The linked bytecode with all provided libraries correctly linked.
|
|
44
|
+
*/
|
|
45
|
+
export function linkBytecode(artifact, libraries) {
|
|
46
|
+
const { bytecode, linkReferences } = artifact;
|
|
47
|
+
let linkedBytecode = bytecode;
|
|
48
|
+
for (const { sourceName, libraryName, address } of libraries) {
|
|
49
|
+
const contractLinkReferences = linkReferences[sourceName]?.[libraryName] ?? [];
|
|
50
|
+
const unprefixedAddress = getUnprefixedHexString(address);
|
|
51
|
+
for (const { start, length } of contractLinkReferences) {
|
|
52
|
+
linkedBytecode =
|
|
53
|
+
linkedBytecode.substring(0, 2 + start * 2) +
|
|
54
|
+
unprefixedAddress +
|
|
55
|
+
linkedBytecode.substring(2 + (start + length) * 2);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return getPrefixedHexString(linkedBytecode);
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=bytecode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bytecode.js","sourceRoot":"","sources":["../../src/bytecode.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AACxE,OAAO,EACL,gCAAgC,EAChC,4BAA4B,EAC5B,4BAA4B,EAC5B,6BAA6B,GAC9B,MAAM,wBAAwB,CAAC;AAEhC;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,qBAAqB,CACnC,QAAkB,EAClB,iBAAmC;IAEnC,6BAA6B,CAAC,iBAAiB,CAAC,CAAC;IAEjD,MAAM,eAAe,GAAkB,EAAE,CAAC;IAC1C,KAAK,MAAM,CAAC,UAAU,EAAE,eAAe,CAAC,IAAI,MAAM,CAAC,OAAO,CACxD,QAAQ,CAAC,cAAc,CACxB,EAAE,CAAC;QACF,KAAK,MAAM,WAAW,IAAI,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC;YACvD,MAAM,UAAU,GAAG,GAAG,UAAU,IAAI,WAAW,EAAE,CAAC;YAClD,MAAM,OAAO,GACX,iBAAiB,CAAC,UAAU,CAAC,IAAI,iBAAiB,CAAC,WAAW,CAAC,CAAC;YAElE,eAAe,CAAC,IAAI,CAAC;gBACnB,UAAU;gBACV,WAAW;gBACX,UAAU;gBACV,OAAO;aACR,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,gCAAgC,CAAC,iBAAiB,EAAE,eAAe,CAAC,CAAC;IACrE,4BAA4B,CAAC,iBAAiB,EAAE,eAAe,CAAC,CAAC;IACjE,4BAA4B,CAAC,eAAe,CAAC,CAAC;IAE9C,OAAO,YAAY,CAAC,QAAQ,EAAE,eAAe,CAAC,CAAC;AACjD,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAC1B,QAAkB,EAClB,SAAwB;IAExB,MAAM,EAAE,QAAQ,EAAE,cAAc,EAAE,GAAG,QAAQ,CAAC;IAC9C,IAAI,cAAc,GAAG,QAAQ,CAAC;IAE9B,KAAK,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE,IAAI,SAAS,EAAE,CAAC;QAC7D,MAAM,sBAAsB,GAC1B,cAAc,CAAC,UAAU,CAAC,EAAE,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;QAClD,MAAM,iBAAiB,GAAG,sBAAsB,CAAC,OAAO,CAAC,CAAC;QAE1D,KAAK,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,sBAAsB,EAAE,CAAC;YACvD,cAAc;gBACZ,cAAc,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC;oBAC1C,iBAAiB;oBACjB,cAAc,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;IAED,OAAO,oBAAoB,CAAC,cAAc,CAAC,CAAC;AAC9C,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a value is an instance of Uint8Array.
|
|
3
|
+
*
|
|
4
|
+
* @param value The value to check.
|
|
5
|
+
* @returns True if the value is a Uint8Array, false otherwise.
|
|
6
|
+
*/
|
|
7
|
+
export declare function isBytes(value: unknown): value is Uint8Array;
|
|
8
|
+
/**
|
|
9
|
+
* Pads a Uint8Array with zeros on the left to a specified length, or truncates
|
|
10
|
+
* it from the left if it's too long.
|
|
11
|
+
*
|
|
12
|
+
* @param bytes The Uint8Array to pad or truncate.
|
|
13
|
+
* @param length The desired length of the Uint8Array.
|
|
14
|
+
* @returns The padded or truncated Uint8Array.
|
|
15
|
+
*/
|
|
16
|
+
export declare function setLengthLeft(bytes: Uint8Array, length: number): Uint8Array;
|
|
17
|
+
/**
|
|
18
|
+
* Checks if two Uint8Arrays are equal.
|
|
19
|
+
*
|
|
20
|
+
* @param x The first Uint8Array to compare.
|
|
21
|
+
* @param y The second Uint8Array to compare.
|
|
22
|
+
* @returns True if the Uint8Arrays are equal, false otherwise.
|
|
23
|
+
*/
|
|
24
|
+
export declare function equalsBytes(x: Uint8Array, y: Uint8Array): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Converts a UTF-8 encoded string into a byte array.
|
|
27
|
+
*
|
|
28
|
+
* @param utf8String The UTF-8 encoded string to convert to bytes.
|
|
29
|
+
* @returns A Uint8Array representing the byte sequence of the input UTF-8 string.
|
|
30
|
+
*/
|
|
31
|
+
export declare function utf8StringToBytes(utf8String: string): Uint8Array;
|
|
32
|
+
export { bytesToBigInt, bytesToNumber, numberToBytes } from "./number.js";
|
|
33
|
+
export { bytesToHexString, hexStringToBytes } from "./hex.js";
|
|
34
|
+
//# sourceMappingURL=bytes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bytes.d.ts","sourceRoot":"","sources":["../../src/bytes.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU,CAE3D;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,UAAU,CAQ3E;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,OAAO,CAEjE;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,UAAU,CAEhE;AAED,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a value is an instance of Uint8Array.
|
|
3
|
+
*
|
|
4
|
+
* @param value The value to check.
|
|
5
|
+
* @returns True if the value is a Uint8Array, false otherwise.
|
|
6
|
+
*/
|
|
7
|
+
export function isBytes(value) {
|
|
8
|
+
return value instanceof Uint8Array;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Pads a Uint8Array with zeros on the left to a specified length, or truncates
|
|
12
|
+
* it from the left if it's too long.
|
|
13
|
+
*
|
|
14
|
+
* @param bytes The Uint8Array to pad or truncate.
|
|
15
|
+
* @param length The desired length of the Uint8Array.
|
|
16
|
+
* @returns The padded or truncated Uint8Array.
|
|
17
|
+
*/
|
|
18
|
+
export function setLengthLeft(bytes, length) {
|
|
19
|
+
if (bytes.length < length) {
|
|
20
|
+
const padded = new Uint8Array(length);
|
|
21
|
+
padded.set(bytes, length - bytes.length);
|
|
22
|
+
return padded;
|
|
23
|
+
}
|
|
24
|
+
return bytes.subarray(-length);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Checks if two Uint8Arrays are equal.
|
|
28
|
+
*
|
|
29
|
+
* @param x The first Uint8Array to compare.
|
|
30
|
+
* @param y The second Uint8Array to compare.
|
|
31
|
+
* @returns True if the Uint8Arrays are equal, false otherwise.
|
|
32
|
+
*/
|
|
33
|
+
export function equalsBytes(x, y) {
|
|
34
|
+
return x.length === y.length && x.every((xVal, i) => xVal === y[i]);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Converts a UTF-8 encoded string into a byte array.
|
|
38
|
+
*
|
|
39
|
+
* @param utf8String The UTF-8 encoded string to convert to bytes.
|
|
40
|
+
* @returns A Uint8Array representing the byte sequence of the input UTF-8 string.
|
|
41
|
+
*/
|
|
42
|
+
export function utf8StringToBytes(utf8String) {
|
|
43
|
+
return new TextEncoder().encode(utf8String);
|
|
44
|
+
}
|
|
45
|
+
export { bytesToBigInt, bytesToNumber, numberToBytes } from "./number.js";
|
|
46
|
+
export { bytesToHexString, hexStringToBytes } from "./hex.js";
|
|
47
|
+
//# sourceMappingURL=bytes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bytes.js","sourceRoot":"","sources":["../../src/bytes.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,OAAO,CAAC,KAAc;IACpC,OAAO,KAAK,YAAY,UAAU,CAAC;AACrC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAAC,KAAiB,EAAE,MAAc;IAC7D,IAAI,KAAK,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC;QAC1B,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;QACtC,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;QACzC,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,OAAO,KAAK,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC;AACjC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,CAAa,EAAE,CAAa;IACtD,OAAO,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACtE,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,UAAkB;IAClD,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;AAC9C,CAAC;AAED,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/src/ci.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ci.d.ts","sourceRoot":"","sources":["../../src/ci.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,IAAI,IAAI,OAAO,CAa9B"}
|
package/dist/src/ci.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks whether the current process is running in a CI environment.
|
|
3
|
+
*
|
|
4
|
+
* @returns True if the current process is running in a CI environment.
|
|
5
|
+
*/
|
|
6
|
+
export function isCi() {
|
|
7
|
+
const env = process.env;
|
|
8
|
+
return (env.GITHUB_ACTIONS !== undefined || // GitHub Actions
|
|
9
|
+
env.NOW !== undefined || // Vercel Now
|
|
10
|
+
env.DEPLOYMENT_ID !== undefined || // Vercel Now
|
|
11
|
+
env.CODEBUILD_BUILD_NUMBER !== undefined || // AWS CodeBuild
|
|
12
|
+
env.CI !== undefined || // Travis CI, CircleCI, Cirrus CI, GitLab CI, Appveyor, CodeShip, dsari
|
|
13
|
+
env.CONTINUOUS_INTEGRATION !== undefined || // Travis CI, Cirrus CI
|
|
14
|
+
env.BUILD_NUMBER !== undefined || // Jenkins, TeamCity
|
|
15
|
+
env.RUN_ID !== undefined // TaskCluster, dsari
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=ci.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ci.js","sourceRoot":"","sources":["../../src/ci.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,IAAI;IAClB,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IAExB,OAAO,CACL,GAAG,CAAC,cAAc,KAAK,SAAS,IAAI,iBAAiB;QACrD,GAAG,CAAC,GAAG,KAAK,SAAS,IAAI,aAAa;QACtC,GAAG,CAAC,aAAa,KAAK,SAAS,IAAI,aAAa;QAChD,GAAG,CAAC,sBAAsB,KAAK,SAAS,IAAI,gBAAgB;QAC5D,GAAG,CAAC,EAAE,KAAK,SAAS,IAAI,uEAAuE;QAC/F,GAAG,CAAC,sBAAsB,KAAK,SAAS,IAAI,uBAAuB;QACnE,GAAG,CAAC,YAAY,KAAK,SAAS,IAAI,oBAAoB;QACtD,GAAG,CAAC,MAAM,KAAK,SAAS,CAAC,qBAAqB;KAC/C,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common-errors.d.ts","sourceRoot":"","sources":["../../src/common-errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,qBAAa,qBAAsB,SAAQ,WAAW;gBACxC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK;CAG3C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common-errors.js","sourceRoot":"","sources":["../../src/common-errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,MAAM,OAAO,qBAAsB,SAAQ,WAAW;IACpD,YAAY,OAAe,EAAE,KAAa;QACxC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACxB,CAAC;CACF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes the Keccak-256 hash of the input bytes.
|
|
3
|
+
*
|
|
4
|
+
* @param bytes The input bytes to hash.
|
|
5
|
+
* @returns The Keccak-256 hash of the input bytes.
|
|
6
|
+
*/
|
|
7
|
+
export declare function keccak256(bytes: Uint8Array): Promise<Uint8Array>;
|
|
8
|
+
/**
|
|
9
|
+
* Creates a non-cryptographic hash-based identifier for the given input.
|
|
10
|
+
*
|
|
11
|
+
* This function is primarily intended for generating unique identifiers from
|
|
12
|
+
* a given input string.
|
|
13
|
+
* It uses the SHA-1 hash algorithm, which is not cryptographically secure, but
|
|
14
|
+
* is sufficient for this use case as long as the input is not generated by an
|
|
15
|
+
* attacker.
|
|
16
|
+
*
|
|
17
|
+
* Note: The exact algorithm used (SHA-1) is not crucial for the function's
|
|
18
|
+
* purpose of generating unique identifiers, and could be replaced if needed.
|
|
19
|
+
*
|
|
20
|
+
* @param data The input string to be hashed.
|
|
21
|
+
* @returns The SHA-1 hash of the input string, represented as a
|
|
22
|
+
* hexadecimal string.
|
|
23
|
+
*/
|
|
24
|
+
export declare function createNonCryptographicHashId(data: string): Promise<string>;
|
|
25
|
+
//# sourceMappingURL=crypto.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../src/crypto.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAsB,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAEtE;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,4BAA4B,CAChD,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,MAAM,CAAC,CAIjB"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { keccak256 as keccak256Impl } from "ethereum-cryptography/keccak";
|
|
2
|
+
/**
|
|
3
|
+
* Computes the Keccak-256 hash of the input bytes.
|
|
4
|
+
*
|
|
5
|
+
* @param bytes The input bytes to hash.
|
|
6
|
+
* @returns The Keccak-256 hash of the input bytes.
|
|
7
|
+
*/
|
|
8
|
+
export async function keccak256(bytes) {
|
|
9
|
+
return keccak256Impl(bytes);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Creates a non-cryptographic hash-based identifier for the given input.
|
|
13
|
+
*
|
|
14
|
+
* This function is primarily intended for generating unique identifiers from
|
|
15
|
+
* a given input string.
|
|
16
|
+
* It uses the SHA-1 hash algorithm, which is not cryptographically secure, but
|
|
17
|
+
* is sufficient for this use case as long as the input is not generated by an
|
|
18
|
+
* attacker.
|
|
19
|
+
*
|
|
20
|
+
* Note: The exact algorithm used (SHA-1) is not crucial for the function's
|
|
21
|
+
* purpose of generating unique identifiers, and could be replaced if needed.
|
|
22
|
+
*
|
|
23
|
+
* @param data The input string to be hashed.
|
|
24
|
+
* @returns The SHA-1 hash of the input string, represented as a
|
|
25
|
+
* hexadecimal string.
|
|
26
|
+
*/
|
|
27
|
+
export async function createNonCryptographicHashId(data) {
|
|
28
|
+
const message = new TextEncoder().encode(data);
|
|
29
|
+
const buffer = await crypto.subtle.digest("SHA-1", message);
|
|
30
|
+
return Buffer.from(buffer).toString("hex");
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=crypto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.js","sourceRoot":"","sources":["../../src/crypto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAE1E;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,KAAiB;IAC/C,OAAO,aAAa,CAAC,KAAK,CAAC,CAAC;AAC9B,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,KAAK,UAAU,4BAA4B,CAChD,IAAY;IAEZ,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC/C,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC5D,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAC7C,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a string, number, or Date object to a Unix timestamp (seconds since the Unix Epoch).
|
|
3
|
+
*
|
|
4
|
+
* @param value The string to convert.
|
|
5
|
+
* @returns The Unix timestamp.
|
|
6
|
+
*/
|
|
7
|
+
export declare function toSeconds(value: string | number | Date): number;
|
|
8
|
+
/**
|
|
9
|
+
* Converts a Unix timestamp to a Date object.
|
|
10
|
+
*
|
|
11
|
+
* @param timestamp The Unix timestamp to convert.
|
|
12
|
+
* @returns The Date object.
|
|
13
|
+
*/
|
|
14
|
+
export declare function secondsToDate(timestamp: number): Date;
|
|
15
|
+
/**
|
|
16
|
+
* Gets the current Unix timestamp (seconds since the Unix Epoch).
|
|
17
|
+
*
|
|
18
|
+
* @returns The current Unix timestamp.
|
|
19
|
+
*/
|
|
20
|
+
export declare function now(): number;
|
|
21
|
+
//# sourceMappingURL=date.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../src/date.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,MAAM,CAE/D;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAErD;AAED;;;;GAIG;AACH,wBAAgB,GAAG,IAAI,MAAM,CAE5B"}
|
package/dist/src/date.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a string, number, or Date object to a Unix timestamp (seconds since the Unix Epoch).
|
|
3
|
+
*
|
|
4
|
+
* @param value The string to convert.
|
|
5
|
+
* @returns The Unix timestamp.
|
|
6
|
+
*/
|
|
7
|
+
export function toSeconds(value) {
|
|
8
|
+
return Math.floor(new Date(value).getTime() / 1000);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Converts a Unix timestamp to a Date object.
|
|
12
|
+
*
|
|
13
|
+
* @param timestamp The Unix timestamp to convert.
|
|
14
|
+
* @returns The Date object.
|
|
15
|
+
*/
|
|
16
|
+
export function secondsToDate(timestamp) {
|
|
17
|
+
return new Date(timestamp * 1000);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Gets the current Unix timestamp (seconds since the Unix Epoch).
|
|
21
|
+
*
|
|
22
|
+
* @returns The current Unix timestamp.
|
|
23
|
+
*/
|
|
24
|
+
export function now() {
|
|
25
|
+
return Math.floor(Date.now() / 1000);
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=date.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date.js","sourceRoot":"","sources":["../../src/date.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,KAA6B;IACrD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;AACtD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,SAAiB;IAC7C,OAAO,IAAI,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC;AACpC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,GAAG;IACjB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;AACvC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A simple decorator that adds debug logging for when a method is entered and exited.
|
|
3
|
+
*
|
|
4
|
+
* This decorator is meant to be used for debugging purposes only. It should not be committed in runtime code.
|
|
5
|
+
*
|
|
6
|
+
* Example usage:
|
|
7
|
+
*
|
|
8
|
+
* ```
|
|
9
|
+
* class MyClass {
|
|
10
|
+
* @withDebugLogs("MyClass:exampleClassMethod")
|
|
11
|
+
* public function exampleClassMethod(...)
|
|
12
|
+
* }
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare function withDebugLogs<This, Args extends any[], Return>(tag?: string): (originalMethod: (this: This, ...args: Args) => Return, _context: ClassMethodDecoratorContext<This, (this: This, ...args: Args) => Return>) => (this: This, ...args: Args) => Return;
|
|
16
|
+
//# sourceMappingURL=debug.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../../src/debug.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,SAAS,GAAG,EAAE,EAAE,MAAM,EAC5D,GAAG,GAAE,MAAW,oBAGE,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,IAAI,KAAK,MAAM,YAC3C,2BAA2B,CACnC,IAAI,EACJ,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,IAAI,KAAK,MAAM,CACtC,KACA,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,IAAI,KAAK,MAAM,CAYzC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import debugLib from "debug";
|
|
2
|
+
/**
|
|
3
|
+
* A simple decorator that adds debug logging for when a method is entered and exited.
|
|
4
|
+
*
|
|
5
|
+
* This decorator is meant to be used for debugging purposes only. It should not be committed in runtime code.
|
|
6
|
+
*
|
|
7
|
+
* Example usage:
|
|
8
|
+
*
|
|
9
|
+
* ```
|
|
10
|
+
* class MyClass {
|
|
11
|
+
* @withDebugLogs("MyClass:exampleClassMethod")
|
|
12
|
+
* public function exampleClassMethod(...)
|
|
13
|
+
* }
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export function withDebugLogs(tag = "") {
|
|
17
|
+
return function actualDecorator(originalMethod, _context) {
|
|
18
|
+
const log = debugLib(`hardhat:dev:core${tag === "" ? "" : `:${tag}`}`);
|
|
19
|
+
function replacementMethod(...args) {
|
|
20
|
+
log(`Entering method with args:`, args);
|
|
21
|
+
const result = originalMethod.call(this, ...args);
|
|
22
|
+
log(`Exiting method.`);
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
return replacementMethod;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=debug.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debug.js","sourceRoot":"","sources":["../../src/debug.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,OAAO,CAAC;AAE7B;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,aAAa,CAC3B,MAAc,EAAE;IAEhB,OAAO,SAAS,eAAe,CAC7B,cAAqD,EACrD,QAGC;QAED,MAAM,GAAG,GAAG,QAAQ,CAAC,mBAAmB,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,EAAE,CAAC,CAAC;QAEvE,SAAS,iBAAiB,CAAa,GAAG,IAAU;YAClD,GAAG,CAAC,4BAA4B,EAAE,IAAI,CAAC,CAAC;YACxC,MAAM,MAAM,GAAG,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;YAClD,GAAG,CAAC,iBAAiB,CAAC,CAAC;YACvB,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,OAAO,iBAAiB,CAAC;IAC3B,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract custom error class, which inherits from the built-in Error class,
|
|
3
|
+
* making sure that the standard errror properties are set, and the stack trace
|
|
4
|
+
* is not polluted with the custom error class' code.
|
|
5
|
+
*
|
|
6
|
+
* This class supports the `cause` property, which can be used to pass the
|
|
7
|
+
* original error that caused the custom error to be thrown. Note that it needs
|
|
8
|
+
* to be an instance of the built-in Error class, or a subclass of it. See `ensureError`
|
|
9
|
+
* for a convinient way of using it.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* class MyCustomError extends CustomError {
|
|
14
|
+
* }
|
|
15
|
+
*
|
|
16
|
+
* try {
|
|
17
|
+
* mayThrow();
|
|
18
|
+
* } catch (error) {
|
|
19
|
+
* ensureError(error);
|
|
20
|
+
* throw new MyCustomError('Something went wrong', error);
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare abstract class CustomError extends Error {
|
|
25
|
+
stack: string;
|
|
26
|
+
constructor(message: string, cause?: Error);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Ensures that the provided value is an instance of an error.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* This function is meant to be used in a catch block to ensure that you caught the right error.
|
|
33
|
+
*
|
|
34
|
+
* ```ts
|
|
35
|
+
* // Ensuring that you got an Error
|
|
36
|
+
* try {
|
|
37
|
+
* mayThrow();
|
|
38
|
+
* } catch (error) {
|
|
39
|
+
* ensureError(error);
|
|
40
|
+
* console.err(error.message);
|
|
41
|
+
* }
|
|
42
|
+
*
|
|
43
|
+
* // Ensuring that you got a specific error
|
|
44
|
+
* try {
|
|
45
|
+
* mayThrow();
|
|
46
|
+
* } catch (error) {
|
|
47
|
+
* ensureError(error, MyError);
|
|
48
|
+
* console.err(error.myMessage());
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @param thrown The value to check.
|
|
53
|
+
* @param ErrorType The error type to check against.
|
|
54
|
+
* @throws The value if its not an instance of the specified error type.
|
|
55
|
+
*/
|
|
56
|
+
export declare function ensureError<ErrorT extends Error>(thrown: unknown, ErrorType?: new (...args: any[]) => ErrorT): asserts thrown is ErrorT;
|
|
57
|
+
/**
|
|
58
|
+
* Throws an error for an unreachable code path. This function is typically
|
|
59
|
+
* used in a default case of a switch statement where all possible values of
|
|
60
|
+
* the switched variable should be handled in other cases. If the default case
|
|
61
|
+
* is reached, it means that an unexpected value was encountered, so an error
|
|
62
|
+
* is thrown.
|
|
63
|
+
*
|
|
64
|
+
* Note: The `@typescript-eslint/switch-exhaustiveness-check` rule checks for
|
|
65
|
+
* exhaustiveness in switch statements by comparing the types of the switch
|
|
66
|
+
* expression and the case clauses. However, it only works with union types and
|
|
67
|
+
* enum types. If you're switching on the result of the `typeof` operator or
|
|
68
|
+
* any other expression that doesn't return a union type or an enum type, this
|
|
69
|
+
* rule cannot enforce exhaustiveness. In such cases, you can use this function
|
|
70
|
+
* in the default case to ensure that an error is thrown if an unexpected value
|
|
71
|
+
* is encountered.
|
|
72
|
+
*
|
|
73
|
+
* @param _value The unexpected value. This parameter is unused and is only for
|
|
74
|
+
* the purpose of type checking.
|
|
75
|
+
* @param error The error to throw.
|
|
76
|
+
* @returns This function never returns normally. It always throws an error.
|
|
77
|
+
* @throws Will throw an error when called.
|
|
78
|
+
*/
|
|
79
|
+
export declare function unreachable(_value: never, error: Error): never;
|
|
80
|
+
//# sourceMappingURL=error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/error.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,8BAAsB,WAAY,SAAQ,KAAK;IAC7B,KAAK,EAAG,MAAM,CAAC;gBAEnB,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK;CAK3C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,WAAW,CAAC,MAAM,SAAS,KAAK,EAC9C,MAAM,EAAE,OAAO,EACf,SAAS,CAAC,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,GACzC,OAAO,CAAC,MAAM,IAAI,MAAM,CAc1B;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,GAAG,KAAK,CAE9D"}
|