essential-eth 0.5.4 → 0.5.9
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/lib/cjs/classes/Contract.d.ts +10 -4
- package/lib/cjs/classes/Contract.js +15 -4
- package/lib/cjs/classes/utils/clean-block.d.ts +115 -0
- package/lib/cjs/classes/utils/clean-block.js +122 -9
- package/lib/cjs/classes/utils/clean-log.d.ts +9 -0
- package/lib/cjs/classes/utils/clean-log.js +37 -0
- package/lib/cjs/classes/utils/clean-transaction-receipt.d.ts +9 -0
- package/lib/cjs/classes/utils/clean-transaction-receipt.js +11 -16
- package/lib/cjs/classes/utils/clean-transaction.d.ts +9 -0
- package/lib/cjs/classes/utils/clean-transaction.js +10 -1
- package/lib/cjs/classes/utils/encode-decode-transaction.d.ts +12 -0
- package/lib/cjs/classes/utils/encode-decode-transaction.js +24 -0
- package/lib/cjs/classes/utils/fetchers.d.ts +31 -1
- package/lib/cjs/classes/utils/fetchers.js +30 -0
- package/lib/cjs/classes/utils/hex-to-decimal.d.ts +14 -1
- package/lib/cjs/classes/utils/hex-to-decimal.js +14 -1
- package/lib/cjs/classes/utils/prepare-transaction.d.ts +6 -0
- package/lib/cjs/classes/utils/prepare-transaction.js +45 -0
- package/lib/cjs/index.d.ts +10 -5
- package/lib/cjs/index.js +10 -2
- package/lib/cjs/logger/package-version.d.ts +1 -1
- package/lib/cjs/logger/package-version.js +1 -1
- package/lib/cjs/providers/BaseProvider.d.ts +282 -199
- package/lib/cjs/providers/BaseProvider.js +365 -214
- package/lib/cjs/providers/FallthroughProvider.d.ts +1 -2
- package/lib/cjs/providers/JsonRpcProvider.d.ts +6 -0
- package/lib/cjs/providers/JsonRpcProvider.js +6 -0
- package/lib/cjs/providers/utils/chains-info.d.ts +27 -0
- package/lib/cjs/providers/utils/chains-info.js +84 -3
- package/lib/cjs/shared/tiny-big/helpers.d.ts +16 -0
- package/lib/cjs/shared/tiny-big/helpers.js +27 -1
- package/lib/cjs/shared/tiny-big/tiny-big.d.ts +30 -4
- package/lib/cjs/shared/tiny-big/tiny-big.js +34 -4
- package/lib/cjs/types/Block.types.d.ts +11 -7
- package/lib/cjs/types/Filter.types.d.ts +16 -0
- package/lib/cjs/types/Filter.types.js +2 -0
- package/lib/cjs/types/Transaction.types.d.ts +33 -6
- package/lib/cjs/utils/bytes.d.ts +150 -33
- package/lib/cjs/utils/bytes.js +179 -32
- package/lib/cjs/utils/compute-address.d.ts +17 -0
- package/lib/cjs/utils/compute-address.js +33 -0
- package/lib/cjs/utils/compute-public-key.d.ts +18 -0
- package/lib/cjs/utils/compute-public-key.js +26 -0
- package/lib/cjs/utils/ether-to-gwei.d.ts +2 -1
- package/lib/cjs/utils/ether-to-gwei.js +2 -1
- package/lib/cjs/utils/ether-to-wei.d.ts +2 -1
- package/lib/cjs/utils/ether-to-wei.js +2 -1
- package/lib/cjs/utils/gwei-to-ether.d.ts +2 -1
- package/lib/cjs/utils/gwei-to-ether.js +2 -1
- package/lib/cjs/utils/hash-message.d.ts +3 -1
- package/lib/cjs/utils/hash-message.js +3 -1
- package/lib/cjs/utils/is-address.d.ts +2 -2
- package/lib/cjs/utils/is-address.js +2 -2
- package/lib/cjs/utils/keccak256.d.ts +15 -1
- package/lib/cjs/utils/keccak256.js +16 -2
- package/lib/cjs/utils/solidity-keccak256.d.ts +17 -7
- package/lib/cjs/utils/solidity-keccak256.js +27 -7
- package/lib/cjs/utils/split-signature.d.ts +24 -0
- package/lib/cjs/utils/split-signature.js +163 -0
- package/lib/cjs/utils/to-checksum-address.d.ts +2 -2
- package/lib/cjs/utils/to-checksum-address.js +2 -2
- package/lib/cjs/utils/to-utf8-bytes.d.ts +14 -0
- package/lib/cjs/utils/to-utf8-bytes.js +14 -0
- package/lib/cjs/utils/wei-to-ether.d.ts +2 -1
- package/lib/cjs/utils/wei-to-ether.js +14 -3
- package/lib/esm/classes/utils/clean-block.js +7 -8
- package/lib/esm/classes/utils/clean-log.d.ts +2 -0
- package/lib/esm/classes/utils/clean-log.js +26 -0
- package/lib/esm/classes/utils/clean-transaction-receipt.js +2 -16
- package/lib/esm/classes/utils/clean-transaction.js +1 -1
- package/lib/esm/classes/utils/fetchers.d.ts +1 -1
- package/lib/esm/classes/utils/prepare-transaction.d.ts +2 -0
- package/lib/esm/classes/utils/prepare-transaction.js +34 -0
- package/lib/esm/index.d.ts +10 -5
- package/lib/esm/index.js +7 -3
- package/lib/esm/logger/package-version.d.ts +1 -1
- package/lib/esm/logger/package-version.js +1 -1
- package/lib/esm/providers/BaseProvider.d.ts +7 -1
- package/lib/esm/providers/BaseProvider.js +67 -11
- package/lib/esm/providers/FallthroughProvider.d.ts +1 -2
- package/lib/esm/providers/utils/chains-info.d.ts +27 -0
- package/lib/esm/providers/utils/chains-info.js +84 -3
- package/lib/esm/shared/tiny-big/tiny-big.js +4 -0
- package/lib/esm/types/Block.types.d.ts +11 -7
- package/lib/esm/types/Filter.types.d.ts +12 -0
- package/lib/esm/types/Filter.types.js +1 -0
- package/lib/esm/types/Transaction.types.d.ts +31 -5
- package/lib/esm/utils/compute-address.d.ts +1 -0
- package/lib/esm/utils/compute-address.js +11 -0
- package/lib/esm/utils/compute-public-key.d.ts +2 -0
- package/lib/esm/utils/compute-public-key.js +6 -0
- package/lib/esm/utils/keccak256.d.ts +1 -1
- package/lib/esm/utils/keccak256.js +2 -2
- package/lib/esm/utils/split-signature.d.ts +2 -0
- package/lib/esm/utils/split-signature.js +126 -0
- package/lib/esm/utils/wei-to-ether.js +11 -2
- package/package.json +38 -11
- package/readme.md +1209 -335
|
@@ -1,15 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts arrays with types and values into a hex string that can be hashed
|
|
3
|
+
*
|
|
4
|
+
* @param types array of Solidity types, where `type[0]` is the type for `value[0]`
|
|
5
|
+
* @param values array of values, where `value[0]` is of type `type[0]`
|
|
6
|
+
* @returns a hex string with the data given, packed to include its types
|
|
7
|
+
* @example
|
|
8
|
+
* ```javascript
|
|
9
|
+
* const types = ['bool', 'string', 'uint64'];
|
|
10
|
+
* const values = [true, 'text', 30];
|
|
11
|
+
* pack(types, values);
|
|
12
|
+
* // '0x0174657874000000000000001e'
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
1
15
|
export declare function pack(types: ReadonlyArray<string>, values: ReadonlyArray<any>): string;
|
|
2
16
|
/**
|
|
3
17
|
* Hashes data from Solidity using the Keccak256 algorithm.
|
|
4
18
|
*
|
|
5
19
|
* Similar to ["solidityKeccak256" in ethers.js](https://docs.ethers.io/v5/api/utils/hashing/#utils-solidityKeccak256)
|
|
6
20
|
*
|
|
7
|
-
* @param types
|
|
8
|
-
*
|
|
9
|
-
* @
|
|
10
|
-
*
|
|
11
|
-
* @returns - A Keccak256 hash (hex string) based on the values provided
|
|
12
|
-
*
|
|
21
|
+
* @param types Each [Solidity type](https://docs.soliditylang.org/en/v0.8.13/types.html) corresponding to the values passed in. Helps the function parse and pack data properly.
|
|
22
|
+
* @param values Data to be concatenated (combined) and then hashed.
|
|
23
|
+
* @returns A Keccak256 hash (hex string) based on the values provided
|
|
13
24
|
* @example
|
|
14
25
|
* ```javascript
|
|
15
26
|
* const types = ['string', 'bool', 'uint32'];
|
|
@@ -17,7 +28,6 @@ export declare function pack(types: ReadonlyArray<string>, values: ReadonlyArray
|
|
|
17
28
|
* solidityKeccak256(types, values);
|
|
18
29
|
* // '0xe4d4c8e809faac09d58f468f0aeab9474fe8965d554c6c0f868c433c3fd6acab'
|
|
19
30
|
* ```
|
|
20
|
-
*
|
|
21
31
|
* @example
|
|
22
32
|
* ```javascript
|
|
23
33
|
* const types = ['bytes4', 'uint32[5]'];
|
|
@@ -10,6 +10,16 @@ const keccak256_1 = require("./keccak256");
|
|
|
10
10
|
const regexBytes = new RegExp('^bytes([0-9]+)$');
|
|
11
11
|
const regexNumber = new RegExp('^(u?int)([0-9]*)$');
|
|
12
12
|
const regexArray = new RegExp('^(.*)\\[([0-9]*)\\]$');
|
|
13
|
+
/**
|
|
14
|
+
* Packs a type and value together into a UTF-8 Byte Array
|
|
15
|
+
*
|
|
16
|
+
* @internal
|
|
17
|
+
* @param type the Solidity type used for the value given
|
|
18
|
+
* @param value the value to pack with its type
|
|
19
|
+
* @param isArray whether the specified data is in an array
|
|
20
|
+
* @returns packed data consisting of the type and value
|
|
21
|
+
* @example N/A - internal function
|
|
22
|
+
*/
|
|
13
23
|
function _pack(type, value, isArray) {
|
|
14
24
|
switch (type) {
|
|
15
25
|
case 'address':
|
|
@@ -74,6 +84,20 @@ function _pack(type, value, isArray) {
|
|
|
74
84
|
}
|
|
75
85
|
return logger_1.logger.throwArgumentError('invalid type', 'type', type);
|
|
76
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Converts arrays with types and values into a hex string that can be hashed
|
|
89
|
+
*
|
|
90
|
+
* @param types array of Solidity types, where `type[0]` is the type for `value[0]`
|
|
91
|
+
* @param values array of values, where `value[0]` is of type `type[0]`
|
|
92
|
+
* @returns a hex string with the data given, packed to include its types
|
|
93
|
+
* @example
|
|
94
|
+
* ```javascript
|
|
95
|
+
* const types = ['bool', 'string', 'uint64'];
|
|
96
|
+
* const values = [true, 'text', 30];
|
|
97
|
+
* pack(types, values);
|
|
98
|
+
* // '0x0174657874000000000000001e'
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
77
101
|
function pack(types, values) {
|
|
78
102
|
if (types.length != values.length) {
|
|
79
103
|
logger_1.logger.throwArgumentError('wrong number of values; expected ${ types.length }', 'values', values);
|
|
@@ -90,12 +114,9 @@ exports.pack = pack;
|
|
|
90
114
|
*
|
|
91
115
|
* Similar to ["solidityKeccak256" in ethers.js](https://docs.ethers.io/v5/api/utils/hashing/#utils-solidityKeccak256)
|
|
92
116
|
*
|
|
93
|
-
* @param types
|
|
94
|
-
*
|
|
95
|
-
* @
|
|
96
|
-
*
|
|
97
|
-
* @returns - A Keccak256 hash (hex string) based on the values provided
|
|
98
|
-
*
|
|
117
|
+
* @param types Each [Solidity type](https://docs.soliditylang.org/en/v0.8.13/types.html) corresponding to the values passed in. Helps the function parse and pack data properly.
|
|
118
|
+
* @param values Data to be concatenated (combined) and then hashed.
|
|
119
|
+
* @returns A Keccak256 hash (hex string) based on the values provided
|
|
99
120
|
* @example
|
|
100
121
|
* ```javascript
|
|
101
122
|
* const types = ['string', 'bool', 'uint32'];
|
|
@@ -103,7 +124,6 @@ exports.pack = pack;
|
|
|
103
124
|
* solidityKeccak256(types, values);
|
|
104
125
|
* // '0xe4d4c8e809faac09d58f468f0aeab9474fe8965d554c6c0f868c433c3fd6acab'
|
|
105
126
|
* ```
|
|
106
|
-
*
|
|
107
127
|
* @example
|
|
108
128
|
* ```javascript
|
|
109
129
|
* const types = ['bytes4', 'uint32[5]'];
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Signature, SignatureLike } from './bytes';
|
|
2
|
+
/**
|
|
3
|
+
* Expands a signature into the full signature object and fills in missing properties.
|
|
4
|
+
*
|
|
5
|
+
* Same as ["splitSignature" in ethers.js](https://docs.ethers.io/v5/api/utils/bytes/#utils-splitSignature)
|
|
6
|
+
*
|
|
7
|
+
* @param signature the signature object to split, parse, and compute missing properties from
|
|
8
|
+
* @returns a full signature object with all properties filled
|
|
9
|
+
* @example
|
|
10
|
+
* ```javascript
|
|
11
|
+
* const signature = '0x60bc4ed91f2021aefe7045f3f77bd12f87eb733aee24bd1965343b3c27b3971647252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee331b';
|
|
12
|
+
* splitSignature(signature);
|
|
13
|
+
* {
|
|
14
|
+
* r: "0x60bc4ed91f2021aefe7045f3f77bd12f87eb733aee24bd1965343b3c27b39716",
|
|
15
|
+
* s: "0x47252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33",
|
|
16
|
+
* _vs: "0x47252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33",
|
|
17
|
+
* recoveryParam: 0,
|
|
18
|
+
* v: 27,
|
|
19
|
+
* yParityAndS: "0x47252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33",
|
|
20
|
+
* compact: "0x60bc4ed91f2021aefe7045f3f77bd12f87eb733aee24bd1965343b3c27b3971647252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33"
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function splitSignature(signature: SignatureLike): Signature;
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.splitSignature = void 0;
|
|
4
|
+
const logger_1 = require("./../logger/logger");
|
|
5
|
+
const bytes_1 = require("./bytes");
|
|
6
|
+
/**
|
|
7
|
+
* Expands a signature into the full signature object and fills in missing properties.
|
|
8
|
+
*
|
|
9
|
+
* Same as ["splitSignature" in ethers.js](https://docs.ethers.io/v5/api/utils/bytes/#utils-splitSignature)
|
|
10
|
+
*
|
|
11
|
+
* @param signature the signature object to split, parse, and compute missing properties from
|
|
12
|
+
* @returns a full signature object with all properties filled
|
|
13
|
+
* @example
|
|
14
|
+
* ```javascript
|
|
15
|
+
* const signature = '0x60bc4ed91f2021aefe7045f3f77bd12f87eb733aee24bd1965343b3c27b3971647252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee331b';
|
|
16
|
+
* splitSignature(signature);
|
|
17
|
+
* {
|
|
18
|
+
* r: "0x60bc4ed91f2021aefe7045f3f77bd12f87eb733aee24bd1965343b3c27b39716",
|
|
19
|
+
* s: "0x47252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33",
|
|
20
|
+
* _vs: "0x47252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33",
|
|
21
|
+
* recoveryParam: 0,
|
|
22
|
+
* v: 27,
|
|
23
|
+
* yParityAndS: "0x47252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33",
|
|
24
|
+
* compact: "0x60bc4ed91f2021aefe7045f3f77bd12f87eb733aee24bd1965343b3c27b3971647252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33"
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
function splitSignature(signature) {
|
|
29
|
+
const result = {
|
|
30
|
+
r: '0x',
|
|
31
|
+
s: '0x',
|
|
32
|
+
_vs: '0x',
|
|
33
|
+
recoveryParam: 0,
|
|
34
|
+
v: 0,
|
|
35
|
+
yParityAndS: '0x',
|
|
36
|
+
compact: '0x',
|
|
37
|
+
};
|
|
38
|
+
if ((0, bytes_1.isBytesLike)(signature)) {
|
|
39
|
+
const bytes = (0, bytes_1.arrayify)(signature);
|
|
40
|
+
// Get the r, s and v
|
|
41
|
+
if (bytes.length === 64) {
|
|
42
|
+
// EIP-2098; pull the v from the top bit of s and clear it
|
|
43
|
+
result.v = 27 + (bytes[32] >> 7);
|
|
44
|
+
bytes[32] &= 0x7f;
|
|
45
|
+
result.r = (0, bytes_1.hexlify)(bytes.slice(0, 32));
|
|
46
|
+
result.s = (0, bytes_1.hexlify)(bytes.slice(32, 64));
|
|
47
|
+
}
|
|
48
|
+
else if (bytes.length === 65) {
|
|
49
|
+
result.r = (0, bytes_1.hexlify)(bytes.slice(0, 32));
|
|
50
|
+
result.s = (0, bytes_1.hexlify)(bytes.slice(32, 64));
|
|
51
|
+
result.v = bytes[64];
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
logger_1.logger.throwArgumentError('invalid signature string', 'signature', signature);
|
|
55
|
+
}
|
|
56
|
+
// Allow a recid to be used as the v
|
|
57
|
+
if (result.v < 27) {
|
|
58
|
+
if (result.v === 0 || result.v === 1) {
|
|
59
|
+
result.v += 27;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
logger_1.logger.throwArgumentError('signature invalid v byte', 'signature', signature);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// Compute recoveryParam from v
|
|
66
|
+
result.recoveryParam = 1 - (result.v % 2);
|
|
67
|
+
// Compute _vs from recoveryParam and s
|
|
68
|
+
if (result.recoveryParam) {
|
|
69
|
+
bytes[32] |= 0x80;
|
|
70
|
+
}
|
|
71
|
+
result._vs = (0, bytes_1.hexlify)(bytes.slice(32, 64));
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
result.r = signature.r;
|
|
75
|
+
result.s = signature.s;
|
|
76
|
+
result.v = signature.v;
|
|
77
|
+
result.recoveryParam = signature.recoveryParam;
|
|
78
|
+
result._vs = signature._vs;
|
|
79
|
+
// If the _vs is available, use it to populate missing s, v and recoveryParam
|
|
80
|
+
// and verify non-missing s, v and recoveryParam
|
|
81
|
+
if (result._vs != null) {
|
|
82
|
+
const vs_1 = (0, bytes_1.zeroPad)((0, bytes_1.arrayify)(result._vs), 32);
|
|
83
|
+
result._vs = (0, bytes_1.hexlify)(vs_1);
|
|
84
|
+
// Set or check the recid
|
|
85
|
+
const recoveryParam = vs_1[0] >= 128 ? 1 : 0;
|
|
86
|
+
if (result.recoveryParam == null) {
|
|
87
|
+
result.recoveryParam = recoveryParam;
|
|
88
|
+
}
|
|
89
|
+
else if (result.recoveryParam !== recoveryParam) {
|
|
90
|
+
logger_1.logger.throwArgumentError('signature recoveryParam mismatch _vs', 'signature', signature);
|
|
91
|
+
}
|
|
92
|
+
// Set or check the s
|
|
93
|
+
vs_1[0] &= 0x7f;
|
|
94
|
+
const s = (0, bytes_1.hexlify)(vs_1);
|
|
95
|
+
if (result.s == null) {
|
|
96
|
+
result.s = s;
|
|
97
|
+
}
|
|
98
|
+
else if (result.s !== s) {
|
|
99
|
+
logger_1.logger.throwArgumentError('signature v mismatch _vs', 'signature', signature);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// Use recid and v to populate each other
|
|
103
|
+
if (result.recoveryParam == null) {
|
|
104
|
+
if (result.v == null) {
|
|
105
|
+
logger_1.logger.throwArgumentError('signature missing v and recoveryParam', 'signature', signature);
|
|
106
|
+
}
|
|
107
|
+
else if (result.v === 0 || result.v === 1) {
|
|
108
|
+
result.recoveryParam = result.v;
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
result.recoveryParam = 1 - (result.v % 2);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
if (result.v == null) {
|
|
116
|
+
result.v = 27 + result.recoveryParam;
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
const recId = result.v === 0 || result.v === 1 ? result.v : 1 - (result.v % 2);
|
|
120
|
+
if (result.recoveryParam !== recId) {
|
|
121
|
+
logger_1.logger.throwArgumentError('signature recoveryParam mismatch v', 'signature', signature);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (result.r == null || !(0, bytes_1.isHexString)(result.r)) {
|
|
126
|
+
logger_1.logger.throwArgumentError('signature missing or invalid r', 'signature', signature);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
result.r = (0, bytes_1.hexZeroPad)(result.r, 32);
|
|
130
|
+
}
|
|
131
|
+
if (result.s == null || !(0, bytes_1.isHexString)(result.s)) {
|
|
132
|
+
logger_1.logger.throwArgumentError('signature missing or invalid s', 'signature', signature);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
result.s = (0, bytes_1.hexZeroPad)(result.s, 32);
|
|
136
|
+
}
|
|
137
|
+
const vs = (0, bytes_1.arrayify)(result.s);
|
|
138
|
+
if (vs[0] >= 128) {
|
|
139
|
+
logger_1.logger.throwArgumentError('signature s out of range', 'signature', signature);
|
|
140
|
+
}
|
|
141
|
+
if (result.recoveryParam) {
|
|
142
|
+
vs[0] |= 0x80;
|
|
143
|
+
}
|
|
144
|
+
const _vs = (0, bytes_1.hexlify)(vs);
|
|
145
|
+
if (result._vs) {
|
|
146
|
+
if (!(0, bytes_1.isHexString)(result._vs)) {
|
|
147
|
+
logger_1.logger.throwArgumentError('signature invalid _vs', 'signature', signature);
|
|
148
|
+
}
|
|
149
|
+
result._vs = (0, bytes_1.hexZeroPad)(result._vs, 32);
|
|
150
|
+
}
|
|
151
|
+
// Set or check the _vs
|
|
152
|
+
if (result._vs == null) {
|
|
153
|
+
result._vs = _vs;
|
|
154
|
+
}
|
|
155
|
+
else if (result._vs !== _vs) {
|
|
156
|
+
logger_1.logger.throwArgumentError('signature _vs mismatch v and s', 'signature', signature);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
result.yParityAndS = result._vs;
|
|
160
|
+
result.compact = result.r + result.yParityAndS.substring(2);
|
|
161
|
+
return result;
|
|
162
|
+
}
|
|
163
|
+
exports.splitSignature = splitSignature;
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Returns an Ethereum address in proper mixed-case checksum.
|
|
3
3
|
* Does NOT support ICAP
|
|
4
4
|
*
|
|
5
|
-
* @param address
|
|
6
|
-
*
|
|
5
|
+
* @param address An Ethereum address. Mixed, lower, and uppercase are all valid
|
|
6
|
+
* @returns a valid checksum address
|
|
7
7
|
* @example
|
|
8
8
|
* ```javascript
|
|
9
9
|
* toChecksumAddress('0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359');
|
|
@@ -7,8 +7,8 @@ const validate_type_1 = require("../shared/validate-type");
|
|
|
7
7
|
* Returns an Ethereum address in proper mixed-case checksum.
|
|
8
8
|
* Does NOT support ICAP
|
|
9
9
|
*
|
|
10
|
-
* @param address
|
|
11
|
-
*
|
|
10
|
+
* @param address An Ethereum address. Mixed, lower, and uppercase are all valid
|
|
11
|
+
* @returns a valid checksum address
|
|
12
12
|
* @example
|
|
13
13
|
* ```javascript
|
|
14
14
|
* toChecksumAddress('0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359');
|
|
@@ -1 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a string into a UTF-8 Byte Array
|
|
3
|
+
*
|
|
4
|
+
* @param data the input to be converted to a UTF-8 Byte Array
|
|
5
|
+
* @returns the specified data as a UTF-8 Byte Array
|
|
6
|
+
* @example
|
|
7
|
+
* ```javascript
|
|
8
|
+
* toUtf8Bytes('essential-eth');
|
|
9
|
+
* // Uint8Array { [Iterator] 0: 101, 1: 115, 2: 115, 3: 101, 4: 110, 5: 116, 6: 105, 7: 97, 8: 108, 9: 45, 10: 101, 11: 116, 12: 104 }
|
|
10
|
+
*
|
|
11
|
+
* toUtf8Bytes('ethereum');
|
|
12
|
+
* // Uint8Array { [Iterator] 0: 101, 1: 116, 2: 104, 3: 101, 4: 114, 5: 101, 6: 117, 7: 109 }
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
1
15
|
export declare function toUtf8Bytes(data: string): Uint8Array;
|
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.toUtf8Bytes = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Converts a string into a UTF-8 Byte Array
|
|
6
|
+
*
|
|
7
|
+
* @param data the input to be converted to a UTF-8 Byte Array
|
|
8
|
+
* @returns the specified data as a UTF-8 Byte Array
|
|
9
|
+
* @example
|
|
10
|
+
* ```javascript
|
|
11
|
+
* toUtf8Bytes('essential-eth');
|
|
12
|
+
* // Uint8Array { [Iterator] 0: 101, 1: 115, 2: 115, 3: 101, 4: 110, 5: 116, 6: 105, 7: 97, 8: 108, 9: 45, 10: 101, 11: 116, 12: 104 }
|
|
13
|
+
*
|
|
14
|
+
* toUtf8Bytes('ethereum');
|
|
15
|
+
* // Uint8Array { [Iterator] 0: 101, 1: 116, 2: 104, 3: 101, 4: 114, 5: 101, 6: 117, 7: 109 }
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
4
18
|
function toUtf8Bytes(data) {
|
|
5
19
|
return new Uint8Array(Buffer.from(data));
|
|
6
20
|
}
|
|
@@ -7,6 +7,8 @@ import { TinyBig } from '../shared/tiny-big/tiny-big';
|
|
|
7
7
|
*
|
|
8
8
|
* Similar to ["fromWei" in web3.js](https://web3js.readthedocs.io/en/v1.7.1/web3-utils.html#fromwei)
|
|
9
9
|
*
|
|
10
|
+
* @param weiQuantity the amount of wei to convert to ether
|
|
11
|
+
* @returns a number of ether equivalent to the specified wei
|
|
10
12
|
* @example
|
|
11
13
|
* ```javascript
|
|
12
14
|
* weiToEther('1000000000000000000000').toString()
|
|
@@ -14,7 +16,6 @@ import { TinyBig } from '../shared/tiny-big/tiny-big';
|
|
|
14
16
|
* weiToEther(1000000000000000000000).toString()
|
|
15
17
|
* // '1000'
|
|
16
18
|
* ```
|
|
17
|
-
*
|
|
18
19
|
* @example
|
|
19
20
|
* ```javascript
|
|
20
21
|
* weiToEther('1000000000000000000000').toNumber()
|
|
@@ -10,6 +10,8 @@ const validate_type_1 = require("../shared/validate-type");
|
|
|
10
10
|
*
|
|
11
11
|
* Similar to ["fromWei" in web3.js](https://web3js.readthedocs.io/en/v1.7.1/web3-utils.html#fromwei)
|
|
12
12
|
*
|
|
13
|
+
* @param weiQuantity the amount of wei to convert to ether
|
|
14
|
+
* @returns a number of ether equivalent to the specified wei
|
|
13
15
|
* @example
|
|
14
16
|
* ```javascript
|
|
15
17
|
* weiToEther('1000000000000000000000').toString()
|
|
@@ -17,7 +19,6 @@ const validate_type_1 = require("../shared/validate-type");
|
|
|
17
19
|
* weiToEther(1000000000000000000000).toString()
|
|
18
20
|
* // '1000'
|
|
19
21
|
* ```
|
|
20
|
-
*
|
|
21
22
|
* @example
|
|
22
23
|
* ```javascript
|
|
23
24
|
* weiToEther('1000000000000000000000').toNumber()
|
|
@@ -28,7 +29,17 @@ const validate_type_1 = require("../shared/validate-type");
|
|
|
28
29
|
*/
|
|
29
30
|
function weiToEther(weiQuantity) {
|
|
30
31
|
(0, validate_type_1.validateType)(weiQuantity, ['string', 'number', 'object']);
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
// eslint-disable-next-line no-useless-catch
|
|
33
|
+
try {
|
|
34
|
+
let _weiQuantity = weiQuantity;
|
|
35
|
+
if (typeof weiQuantity === 'string' && weiQuantity.slice(0, 2) === '0x') {
|
|
36
|
+
_weiQuantity = BigInt(weiQuantity).toString();
|
|
37
|
+
}
|
|
38
|
+
const result = (0, tiny_big_1.tinyBig)(_weiQuantity).div('1000000000000000000');
|
|
39
|
+
return (0, tiny_big_1.tinyBig)(result);
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
33
44
|
}
|
|
34
45
|
exports.weiToEther = weiToEther;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { toChecksumAddress } from '../..';
|
|
2
|
+
import { tinyBig } from '../../shared/tiny-big/tiny-big';
|
|
2
3
|
import { cleanTransaction } from './clean-transaction';
|
|
3
4
|
import { hexToDecimal } from './hex-to-decimal';
|
|
4
5
|
export function cleanBlock(block, returnTransactionObjects) {
|
|
@@ -7,22 +8,20 @@ export function cleanBlock(block, returnTransactionObjects) {
|
|
|
7
8
|
if (!block[key])
|
|
8
9
|
return;
|
|
9
10
|
switch (key) {
|
|
11
|
+
case 'difficulty':
|
|
12
|
+
case 'totalDifficulty':
|
|
10
13
|
case 'gasLimit':
|
|
11
14
|
case 'gasUsed':
|
|
12
|
-
case 'number':
|
|
13
15
|
case 'size':
|
|
14
16
|
case 'timestamp':
|
|
15
17
|
case 'baseFeePerGas':
|
|
16
|
-
cleanedBlock[key] =
|
|
18
|
+
cleanedBlock[key] = tinyBig(hexToDecimal(block[key]));
|
|
17
19
|
break;
|
|
18
|
-
case '
|
|
19
|
-
|
|
20
|
-
cleanedBlock[key] = hexToDecimal(block[key]);
|
|
20
|
+
case 'number':
|
|
21
|
+
cleanedBlock[key] = Number(hexToDecimal(block[key]));
|
|
21
22
|
break;
|
|
22
23
|
case 'miner':
|
|
23
|
-
|
|
24
|
-
cleanedBlock[key] = toChecksumAddress(block[key]);
|
|
25
|
-
}
|
|
24
|
+
cleanedBlock[key] = toChecksumAddress(block[key]);
|
|
26
25
|
break;
|
|
27
26
|
}
|
|
28
27
|
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { toChecksumAddress } from '../../utils/to-checksum-address';
|
|
2
|
+
import { hexToDecimal } from './hex-to-decimal';
|
|
3
|
+
export function cleanLog(log, receiptLog) {
|
|
4
|
+
const cleanedLog = Object.assign({}, log);
|
|
5
|
+
Object.keys(log).forEach((key) => {
|
|
6
|
+
switch (key) {
|
|
7
|
+
case 'address':
|
|
8
|
+
cleanedLog[key] = toChecksumAddress(log[key]);
|
|
9
|
+
break;
|
|
10
|
+
case 'blockNumber':
|
|
11
|
+
case 'logIndex':
|
|
12
|
+
case 'transactionIndex':
|
|
13
|
+
cleanedLog[key] = Number(hexToDecimal(log[key]));
|
|
14
|
+
break;
|
|
15
|
+
case 'removed':
|
|
16
|
+
if (receiptLog) {
|
|
17
|
+
delete cleanedLog[key];
|
|
18
|
+
}
|
|
19
|
+
else if (log[key] == null) {
|
|
20
|
+
cleanedLog[key] === false;
|
|
21
|
+
}
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return cleanedLog;
|
|
26
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { tinyBig, toChecksumAddress } from '../..';
|
|
2
|
+
import { cleanLog } from './clean-log';
|
|
2
3
|
import { cleanTransaction } from './clean-transaction';
|
|
3
4
|
import { hexToDecimal } from './hex-to-decimal';
|
|
4
5
|
export function cleanTransactionReceipt(transactionReceipt) {
|
|
@@ -23,22 +24,7 @@ export function cleanTransactionReceipt(transactionReceipt) {
|
|
|
23
24
|
break;
|
|
24
25
|
case 'logs':
|
|
25
26
|
transactionReceipt[key].forEach((log, index) => {
|
|
26
|
-
|
|
27
|
-
switch (logKey) {
|
|
28
|
-
case 'address':
|
|
29
|
-
cleanedTransactionReceipt[key][index][logKey] =
|
|
30
|
-
toChecksumAddress(log[logKey]);
|
|
31
|
-
break;
|
|
32
|
-
case 'blockNumber':
|
|
33
|
-
case 'logIndex':
|
|
34
|
-
case 'transactionIndex':
|
|
35
|
-
cleanedTransactionReceipt[key][index][logKey] = Number(hexToDecimal(log[logKey]));
|
|
36
|
-
break;
|
|
37
|
-
case 'removed':
|
|
38
|
-
delete log[logKey];
|
|
39
|
-
break;
|
|
40
|
-
}
|
|
41
|
-
});
|
|
27
|
+
cleanedTransactionReceipt[key][index] = cleanLog(log, true);
|
|
42
28
|
});
|
|
43
29
|
}
|
|
44
30
|
});
|
|
@@ -8,7 +8,6 @@ export function cleanTransaction(transaction) {
|
|
|
8
8
|
switch (key) {
|
|
9
9
|
case 'blockNumber':
|
|
10
10
|
case 'chainId':
|
|
11
|
-
case 'nonce':
|
|
12
11
|
case 'transactionIndex':
|
|
13
12
|
case 'type':
|
|
14
13
|
case 'v':
|
|
@@ -25,6 +24,7 @@ export function cleanTransaction(transaction) {
|
|
|
25
24
|
case 'gasPrice':
|
|
26
25
|
case 'maxFeePerGas':
|
|
27
26
|
case 'maxPriorityFeePerGas':
|
|
27
|
+
case 'nonce':
|
|
28
28
|
cleanedTransaction[key] = tinyBig(hexToDecimal(transaction[key]));
|
|
29
29
|
break;
|
|
30
30
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare function post(url: string, body: Record<string, unknown>): Promise<any>;
|
|
2
|
-
declare type RPCMethodName = 'eth_getBlockByNumber' | 'eth_getBlockByHash' | 'eth_call' | 'eth_chainId' | 'eth_gasPrice' | 'eth_getBalance' | 'eth_getTransactionByHash' | 'eth_getTransactionReceipt' | 'eth_getTransactionCount';
|
|
2
|
+
declare type RPCMethodName = 'eth_getBlockByNumber' | 'eth_getBlockByHash' | 'eth_call' | 'eth_chainId' | 'eth_gasPrice' | 'eth_getBalance' | 'eth_getTransactionByHash' | 'eth_getTransactionReceipt' | 'eth_getTransactionCount' | 'eth_getCode' | 'eth_blockNumber' | 'eth_estimateGas' | 'eth_getLogs';
|
|
3
3
|
export declare function buildRPCPostBody(method: RPCMethodName, params: unknown[]): {
|
|
4
4
|
jsonrpc: string;
|
|
5
5
|
id: number;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import Big from 'big.js';
|
|
2
|
+
import { TinyBig } from '../../shared/tiny-big/tiny-big';
|
|
3
|
+
import { hexlify } from '../../utils/bytes';
|
|
4
|
+
export function prepareTransaction(transaction) {
|
|
5
|
+
const preparedTransaction = Object.assign({}, transaction);
|
|
6
|
+
Object.keys(transaction).forEach((key) => {
|
|
7
|
+
switch (key) {
|
|
8
|
+
case 'gas':
|
|
9
|
+
case 'gasPrice':
|
|
10
|
+
case 'nonce':
|
|
11
|
+
case 'maxFeePerGas':
|
|
12
|
+
case 'maxPriorityFeePerGas':
|
|
13
|
+
case 'value': {
|
|
14
|
+
const value = transaction[key];
|
|
15
|
+
if (value instanceof TinyBig) {
|
|
16
|
+
preparedTransaction[key] = value.toHexString();
|
|
17
|
+
}
|
|
18
|
+
else if (value instanceof Big) {
|
|
19
|
+
preparedTransaction[key] = `0x${BigInt(value.toString()).toString(16)}`;
|
|
20
|
+
}
|
|
21
|
+
else if (typeof transaction[key] === 'number')
|
|
22
|
+
preparedTransaction[key] =
|
|
23
|
+
'0x' + transaction[key].toString(16);
|
|
24
|
+
else
|
|
25
|
+
preparedTransaction[key] = transaction[key].toString();
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
case 'data':
|
|
29
|
+
preparedTransaction[key] = hexlify(transaction[key]);
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
return preparedTransaction;
|
|
34
|
+
}
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
|
-
import { Contract } from './classes/Contract';
|
|
2
|
-
import { FallthroughProvider } from './providers/FallthroughProvider';
|
|
1
|
+
import { BaseContract, Contract } from './classes/Contract';
|
|
2
|
+
import { ConstructorOptions, FallthroughProvider } from './providers/FallthroughProvider';
|
|
3
3
|
import { JsonRpcProvider, jsonRpcProvider } from './providers/JsonRpcProvider';
|
|
4
4
|
import { tinyBig, TinyBig } from './shared/tiny-big/tiny-big';
|
|
5
|
-
import { BlockResponse } from './types/Block.types';
|
|
5
|
+
import { BlockResponse, BlockTag, RPCBlock } from './types/Block.types';
|
|
6
6
|
import { ContractTypes, JSONABI, JSONABIArgument } from './types/Contract.types';
|
|
7
|
+
import { Filter, FilterByBlockHash } from './types/Filter.types';
|
|
7
8
|
import { Network } from './types/Network.types';
|
|
8
|
-
import { TransactionResponse } from './types/Transaction.types';
|
|
9
|
+
import { BlockTransactionResponse, Log, RPCLog, RPCTransaction, RPCTransactionReceipt, RPCTransactionRequest, TransactionReceipt, TransactionRequest, TransactionResponse } from './types/Transaction.types';
|
|
10
|
+
import { computeAddress } from './utils/compute-address';
|
|
11
|
+
import { computePublicKey } from './utils/compute-public-key';
|
|
9
12
|
import { etherToGwei } from './utils/ether-to-gwei';
|
|
10
13
|
import { etherToWei } from './utils/ether-to-wei';
|
|
11
14
|
import { gweiToEther } from './utils/gwei-to-ether';
|
|
15
|
+
import { hashMessage } from './utils/hash-message';
|
|
12
16
|
import { isAddress } from './utils/is-address';
|
|
17
|
+
import { splitSignature } from './utils/split-signature';
|
|
13
18
|
import { toChecksumAddress } from './utils/to-checksum-address';
|
|
14
19
|
import { toUtf8Bytes } from './utils/to-utf8-bytes';
|
|
15
20
|
import { weiToEther } from './utils/wei-to-ether';
|
|
@@ -17,4 +22,4 @@ export * from './utils/bytes';
|
|
|
17
22
|
export * from './utils/hash-message';
|
|
18
23
|
export * from './utils/keccak256';
|
|
19
24
|
export * from './utils/solidity-keccak256';
|
|
20
|
-
export { etherToWei, etherToGwei, isAddress, jsonRpcProvider, JsonRpcProvider, FallthroughProvider, tinyBig, toChecksumAddress, weiToEther, gweiToEther, toUtf8Bytes, Contract, TinyBig, BlockResponse, ContractTypes, JSONABI, JSONABIArgument, Network, TransactionResponse, };
|
|
25
|
+
export { etherToWei, etherToGwei, isAddress, jsonRpcProvider, JsonRpcProvider, FallthroughProvider, tinyBig, toChecksumAddress, weiToEther, gweiToEther, hashMessage, splitSignature, toUtf8Bytes, computeAddress, computePublicKey, Contract, TinyBig, BaseContract, BlockResponse, ContractTypes, Filter, FilterByBlockHash, JSONABI, JSONABIArgument, Network, TransactionResponse, RPCBlock, RPCTransaction, RPCTransactionReceipt, TransactionRequest, RPCTransactionRequest, TransactionReceipt, BlockTag, RPCLog, Log, BlockTransactionResponse, ConstructorOptions, };
|
package/lib/esm/index.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import { Contract } from './classes/Contract';
|
|
2
|
-
import { FallthroughProvider } from './providers/FallthroughProvider';
|
|
1
|
+
import { BaseContract, Contract } from './classes/Contract';
|
|
2
|
+
import { FallthroughProvider, } from './providers/FallthroughProvider';
|
|
3
3
|
import { JsonRpcProvider, jsonRpcProvider } from './providers/JsonRpcProvider';
|
|
4
4
|
import { tinyBig, TinyBig } from './shared/tiny-big/tiny-big';
|
|
5
|
+
import { computeAddress } from './utils/compute-address';
|
|
6
|
+
import { computePublicKey } from './utils/compute-public-key';
|
|
5
7
|
import { etherToGwei } from './utils/ether-to-gwei';
|
|
6
8
|
import { etherToWei } from './utils/ether-to-wei';
|
|
7
9
|
import { gweiToEther } from './utils/gwei-to-ether';
|
|
10
|
+
import { hashMessage } from './utils/hash-message';
|
|
8
11
|
import { isAddress } from './utils/is-address';
|
|
12
|
+
import { splitSignature } from './utils/split-signature';
|
|
9
13
|
import { toChecksumAddress } from './utils/to-checksum-address';
|
|
10
14
|
import { toUtf8Bytes } from './utils/to-utf8-bytes';
|
|
11
15
|
import { weiToEther } from './utils/wei-to-ether';
|
|
@@ -13,4 +17,4 @@ export * from './utils/bytes';
|
|
|
13
17
|
export * from './utils/hash-message';
|
|
14
18
|
export * from './utils/keccak256';
|
|
15
19
|
export * from './utils/solidity-keccak256';
|
|
16
|
-
export { etherToWei, etherToGwei, isAddress, jsonRpcProvider, JsonRpcProvider, FallthroughProvider, tinyBig, toChecksumAddress, weiToEther, gweiToEther, toUtf8Bytes, Contract, TinyBig, };
|
|
20
|
+
export { etherToWei, etherToGwei, isAddress, jsonRpcProvider, JsonRpcProvider, FallthroughProvider, tinyBig, toChecksumAddress, weiToEther, gweiToEther, hashMessage, splitSignature, toUtf8Bytes, computeAddress, computePublicKey, Contract, TinyBig, BaseContract, };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "0.5.
|
|
1
|
+
export declare const version = "0.5.9";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '0.5.
|
|
1
|
+
export const version = '0.5.9';
|