essential-eth 0.5.6 → 0.5.10-next.2
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/esm → dist}/classes/Contract.d.ts +11 -11
- package/dist/classes/test/Contract/crv-abi.d.ts +2 -0
- package/dist/classes/test/Contract/ens-abi.d.ts +2 -0
- package/dist/classes/test/Contract/fei-abi.d.ts +2 -0
- package/dist/classes/test/Contract/foo-abi.d.ts +2 -0
- package/dist/classes/test/Contract/uniswap-abi.d.ts +2 -0
- package/dist/classes/utils/clean-block.d.ts +3 -0
- package/dist/classes/utils/clean-log.d.ts +2 -0
- package/{lib/esm → dist}/classes/utils/clean-transaction-receipt.d.ts +2 -2
- package/{lib/esm → dist}/classes/utils/clean-transaction.d.ts +2 -2
- package/{lib/cjs → dist}/classes/utils/encode-decode-transaction.d.ts +4 -4
- package/{lib/cjs → dist}/classes/utils/fetchers.d.ts +9 -9
- package/{lib/esm → dist}/classes/utils/hex-to-decimal.d.ts +1 -1
- package/dist/classes/utils/prepare-transaction.d.ts +2 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/{lib/cjs → dist}/index.d.ts +25 -25
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/index.modern.js +2 -0
- package/dist/index.modern.js.map +1 -0
- package/dist/index.modern.mjs +2 -0
- package/dist/index.modern.mjs.map +1 -0
- package/dist/index.module.js +2 -0
- package/dist/index.module.js.map +1 -0
- package/dist/index.umd.js +2 -0
- package/dist/index.umd.js.map +1 -0
- package/{lib/esm → dist}/logger/logger.d.ts +11 -11
- package/dist/logger/package-version.d.ts +1 -0
- package/{lib/esm → dist}/providers/BaseProvider.d.ts +24 -21
- package/{lib/esm → dist}/providers/FallthroughProvider.d.ts +11 -11
- package/{lib/esm → dist}/providers/JsonRpcProvider.d.ts +7 -7
- package/{lib/cjs → dist}/providers/test/rpc-urls.d.ts +11 -11
- package/{lib/esm → dist}/providers/utils/chains-info.d.ts +467 -412
- package/{lib/cjs → dist}/shared/tiny-big/helpers.d.ts +1 -1
- package/{lib/esm → dist}/shared/tiny-big/tiny-big.d.ts +10 -10
- package/{lib/cjs → dist}/shared/validate-type.d.ts +3 -3
- package/{lib/cjs → dist}/types/Block.types.d.ts +40 -37
- package/{lib/cjs → dist}/types/Contract.types.d.ts +24 -24
- package/dist/types/Filter.types.d.ts +12 -0
- package/{lib/esm → dist}/types/Network.types.d.ts +5 -5
- package/{lib/cjs → dist}/types/Transaction.types.d.ts +113 -96
- package/{lib/esm → dist}/utils/bytes.d.ts +40 -40
- package/{lib/esm → dist}/utils/compute-address.d.ts +1 -1
- package/{lib/esm → dist}/utils/compute-public-key.d.ts +2 -2
- package/{lib/esm → dist}/utils/ether-to-gwei.d.ts +3 -3
- package/dist/utils/ether-to-wei.d.ts +3 -0
- package/dist/utils/gwei-to-ether.d.ts +3 -0
- package/{lib/esm → dist}/utils/hash-message.d.ts +2 -2
- package/{lib/esm → dist}/utils/is-address.d.ts +1 -1
- package/dist/utils/keccak256.d.ts +2 -0
- package/{lib/esm → dist}/utils/solidity-keccak256.d.ts +2 -2
- package/{lib/esm → dist}/utils/split-signature.d.ts +2 -2
- package/{lib/esm → dist}/utils/to-checksum-address.d.ts +1 -1
- package/{lib/cjs → dist}/utils/to-utf8-bytes.d.ts +1 -1
- package/dist/utils/wei-to-ether.d.ts +3 -0
- package/package.json +66 -19
- package/readme.md +643 -291
- package/lib/cjs/classes/Contract.d.ts +0 -72
- package/lib/cjs/classes/Contract.js +0 -129
- package/lib/cjs/classes/test/Contract/crv-abi.d.ts +0 -2
- package/lib/cjs/classes/test/Contract/crv-abi.js +0 -488
- package/lib/cjs/classes/test/Contract/ens-abi.d.ts +0 -2
- package/lib/cjs/classes/test/Contract/ens-abi.js +0 -453
- package/lib/cjs/classes/test/Contract/fei-abi.d.ts +0 -2
- package/lib/cjs/classes/test/Contract/fei-abi.js +0 -526
- package/lib/cjs/classes/test/Contract/foo-abi.d.ts +0 -2
- package/lib/cjs/classes/test/Contract/foo-abi.js +0 -42
- package/lib/cjs/classes/test/Contract/uniswap-abi.d.ts +0 -2
- package/lib/cjs/classes/test/Contract/uniswap-abi.js +0 -121
- package/lib/cjs/classes/utils/clean-block.d.ts +0 -6
- package/lib/cjs/classes/utils/clean-block.js +0 -47
- package/lib/cjs/classes/utils/clean-transaction-receipt.d.ts +0 -5
- package/lib/cjs/classes/utils/clean-transaction-receipt.js +0 -55
- package/lib/cjs/classes/utils/clean-transaction.d.ts +0 -5
- package/lib/cjs/classes/utils/clean-transaction.js +0 -42
- package/lib/cjs/classes/utils/encode-decode-transaction.js +0 -113
- package/lib/cjs/classes/utils/fetchers.js +0 -51
- package/lib/cjs/classes/utils/hex-to-decimal.d.ts +0 -5
- package/lib/cjs/classes/utils/hex-to-decimal.js +0 -11
- package/lib/cjs/index.js +0 -55
- package/lib/cjs/logger/logger.d.ts +0 -11
- package/lib/cjs/logger/logger.js +0 -36
- package/lib/cjs/logger/package-version.d.ts +0 -1
- package/lib/cjs/logger/package-version.js +0 -5
- package/lib/cjs/providers/BaseProvider.d.ts +0 -304
- package/lib/cjs/providers/BaseProvider.js +0 -405
- package/lib/cjs/providers/FallthroughProvider.d.ts +0 -24
- package/lib/cjs/providers/FallthroughProvider.js +0 -65
- package/lib/cjs/providers/JsonRpcProvider.d.ts +0 -27
- package/lib/cjs/providers/JsonRpcProvider.js +0 -40
- package/lib/cjs/providers/test/rpc-urls.js +0 -14
- package/lib/cjs/providers/types.d.ts +0 -7
- package/lib/cjs/providers/types.js +0 -2
- package/lib/cjs/providers/utils/chains-info.d.ts +0 -412
- package/lib/cjs/providers/utils/chains-info.js +0 -1237
- package/lib/cjs/shared/tiny-big/helpers.js +0 -71
- package/lib/cjs/shared/tiny-big/tiny-big.d.ts +0 -32
- package/lib/cjs/shared/tiny-big/tiny-big.js +0 -71
- package/lib/cjs/shared/validate-type.js +0 -9
- package/lib/cjs/types/Block.types.js +0 -2
- package/lib/cjs/types/Contract.types.js +0 -2
- package/lib/cjs/types/Network.types.d.ts +0 -8
- package/lib/cjs/types/Network.types.js +0 -2
- package/lib/cjs/types/Transaction.types.js +0 -2
- package/lib/cjs/utils/bytes.d.ts +0 -172
- package/lib/cjs/utils/bytes.js +0 -564
- package/lib/cjs/utils/compute-address.d.ts +0 -8
- package/lib/cjs/utils/compute-address.js +0 -24
- package/lib/cjs/utils/compute-public-key.d.ts +0 -9
- package/lib/cjs/utils/compute-public-key.js +0 -17
- package/lib/cjs/utils/ether-to-gwei.d.ts +0 -26
- package/lib/cjs/utils/ether-to-gwei.js +0 -34
- package/lib/cjs/utils/ether-to-wei.d.ts +0 -26
- package/lib/cjs/utils/ether-to-wei.js +0 -34
- package/lib/cjs/utils/gwei-to-ether.d.ts +0 -26
- package/lib/cjs/utils/gwei-to-ether.js +0 -34
- package/lib/cjs/utils/hash-message.d.ts +0 -12
- package/lib/cjs/utils/hash-message.js +0 -26
- package/lib/cjs/utils/is-address.d.ts +0 -24
- package/lib/cjs/utils/is-address.js +0 -39
- package/lib/cjs/utils/keccak256.d.ts +0 -2
- package/lib/cjs/utils/keccak256.js +0 -17
- package/lib/cjs/utils/solidity-keccak256.d.ts +0 -29
- package/lib/cjs/utils/solidity-keccak256.js +0 -118
- package/lib/cjs/utils/split-signature.d.ts +0 -26
- package/lib/cjs/utils/split-signature.js +0 -165
- package/lib/cjs/utils/to-checksum-address.d.ts +0 -17
- package/lib/cjs/utils/to-checksum-address.js +0 -46
- package/lib/cjs/utils/to-utf8-bytes.js +0 -7
- package/lib/cjs/utils/wei-to-ether.d.ts +0 -26
- package/lib/cjs/utils/wei-to-ether.js +0 -44
- package/lib/esm/classes/Contract.js +0 -65
- package/lib/esm/classes/test/Contract/crv-abi.d.ts +0 -2
- package/lib/esm/classes/test/Contract/crv-abi.js +0 -470
- package/lib/esm/classes/test/Contract/ens-abi.d.ts +0 -2
- package/lib/esm/classes/test/Contract/ens-abi.js +0 -435
- package/lib/esm/classes/test/Contract/fei-abi.d.ts +0 -2
- package/lib/esm/classes/test/Contract/fei-abi.js +0 -521
- package/lib/esm/classes/test/Contract/foo-abi.d.ts +0 -2
- package/lib/esm/classes/test/Contract/foo-abi.js +0 -33
- package/lib/esm/classes/test/Contract/uniswap-abi.d.ts +0 -2
- package/lib/esm/classes/test/Contract/uniswap-abi.js +0 -116
- package/lib/esm/classes/utils/clean-block.d.ts +0 -3
- package/lib/esm/classes/utils/clean-block.js +0 -36
- package/lib/esm/classes/utils/clean-transaction-receipt.js +0 -48
- package/lib/esm/classes/utils/clean-transaction.js +0 -33
- package/lib/esm/classes/utils/encode-decode-transaction.d.ts +0 -4
- package/lib/esm/classes/utils/encode-decode-transaction.js +0 -98
- package/lib/esm/classes/utils/fetchers.d.ts +0 -9
- package/lib/esm/classes/utils/fetchers.js +0 -43
- package/lib/esm/classes/utils/hex-to-decimal.js +0 -3
- package/lib/esm/index.d.ts +0 -25
- package/lib/esm/index.js +0 -21
- package/lib/esm/logger/logger.js +0 -33
- package/lib/esm/logger/package-version.d.ts +0 -1
- package/lib/esm/logger/package-version.js +0 -1
- package/lib/esm/providers/BaseProvider.js +0 -114
- package/lib/esm/providers/FallthroughProvider.js +0 -41
- package/lib/esm/providers/JsonRpcProvider.js +0 -15
- package/lib/esm/providers/test/rpc-urls.d.ts +0 -11
- package/lib/esm/providers/test/rpc-urls.js +0 -11
- package/lib/esm/providers/types.d.ts +0 -7
- package/lib/esm/providers/types.js +0 -1
- package/lib/esm/providers/utils/chains-info.js +0 -1233
- package/lib/esm/shared/tiny-big/helpers.d.ts +0 -1
- package/lib/esm/shared/tiny-big/helpers.js +0 -58
- package/lib/esm/shared/tiny-big/tiny-big.js +0 -41
- package/lib/esm/shared/validate-type.d.ts +0 -3
- package/lib/esm/shared/validate-type.js +0 -5
- package/lib/esm/types/Block.types.d.ts +0 -36
- package/lib/esm/types/Block.types.js +0 -1
- package/lib/esm/types/Contract.types.d.ts +0 -24
- package/lib/esm/types/Contract.types.js +0 -1
- package/lib/esm/types/Network.types.js +0 -1
- package/lib/esm/types/Transaction.types.d.ts +0 -87
- package/lib/esm/types/Transaction.types.js +0 -1
- package/lib/esm/utils/bytes.js +0 -245
- package/lib/esm/utils/compute-address.js +0 -11
- package/lib/esm/utils/compute-public-key.js +0 -6
- package/lib/esm/utils/ether-to-gwei.js +0 -7
- package/lib/esm/utils/ether-to-wei.d.ts +0 -3
- package/lib/esm/utils/ether-to-wei.js +0 -7
- package/lib/esm/utils/gwei-to-ether.d.ts +0 -3
- package/lib/esm/utils/gwei-to-ether.js +0 -7
- package/lib/esm/utils/hash-message.js +0 -12
- package/lib/esm/utils/is-address.js +0 -12
- package/lib/esm/utils/keccak256.d.ts +0 -2
- package/lib/esm/utils/keccak256.js +0 -13
- package/lib/esm/utils/solidity-keccak256.js +0 -85
- package/lib/esm/utils/split-signature.js +0 -126
- package/lib/esm/utils/to-checksum-address.js +0 -25
- package/lib/esm/utils/to-utf8-bytes.d.ts +0 -1
- package/lib/esm/utils/to-utf8-bytes.js +0 -3
- package/lib/esm/utils/wei-to-ether.d.ts +0 -3
- package/lib/esm/utils/wei-to-ether.js +0 -16
package/lib/cjs/utils/bytes.js
DELETED
|
@@ -1,564 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// primary duplicate code from https://github.com/ethers-io/ethers.js/blob/f599d6f23dad0d0acaa3828d6b7acaab2d5e455b/packages/bytes/src.ts/index.ts
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.hexZeroPad = exports.hexStripZeros = exports.hexValue = exports.hexConcat = exports.hexDataSlice = exports.hexDataLength = exports.hexlify = exports.isHexString = exports.zeroPad = exports.stripZeros = exports.concat = exports.arrayify = exports.isBytes = exports.isBytesLike = void 0;
|
|
5
|
-
const logger_1 = require("../logger/logger");
|
|
6
|
-
function isHexable(value) {
|
|
7
|
-
return !!value.toHexString;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Returns true if and only if value is a valid [Bytes](#bytes) or DataHexString
|
|
11
|
-
* * Same as [`ethers.utils.isBytesLike`](https://docs.ethers.io/v5/api/utils/bytes/#utils-isBytesLike)
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```js
|
|
15
|
-
* isBytesLike([1,2,3]);
|
|
16
|
-
* // true
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```js
|
|
21
|
-
* isBytesLike(false);
|
|
22
|
-
* // false
|
|
23
|
-
* ```
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```js
|
|
27
|
-
* isBytesLike(new Uint8Array(1));
|
|
28
|
-
* // true
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
function isBytesLike(value) {
|
|
32
|
-
return (isHexString(value) && !(value.length % 2)) || isBytes(value);
|
|
33
|
-
}
|
|
34
|
-
exports.isBytesLike = isBytesLike;
|
|
35
|
-
function isInteger(value) {
|
|
36
|
-
return typeof value === 'number' && value == value && value % 1 === 0;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Returns true if and only if value is a valid [Bytes](#bytes)
|
|
40
|
-
* * Same as [`ethers.utils.isBytes`](https://docs.ethers.io/v5/api/utils/bytes/#utils-isBytes)
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* ```js
|
|
44
|
-
* isBytes([1,2,3]);
|
|
45
|
-
* // true
|
|
46
|
-
* ```
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* ```js
|
|
50
|
-
* isBytes(false);
|
|
51
|
-
* // false
|
|
52
|
-
* ```
|
|
53
|
-
*
|
|
54
|
-
* @example
|
|
55
|
-
* ```js
|
|
56
|
-
* isBytes(new Uint8Array(1));
|
|
57
|
-
* // true
|
|
58
|
-
* ```
|
|
59
|
-
*/
|
|
60
|
-
function isBytes(value) {
|
|
61
|
-
if (value == null) {
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
if (value.constructor === Uint8Array) {
|
|
65
|
-
return true;
|
|
66
|
-
}
|
|
67
|
-
if (typeof value === 'string') {
|
|
68
|
-
return false;
|
|
69
|
-
}
|
|
70
|
-
if (!isInteger(value.length) || value.length < 0) {
|
|
71
|
-
return false;
|
|
72
|
-
}
|
|
73
|
-
for (let i = 0; i < value.length; i++) {
|
|
74
|
-
const v = value[i];
|
|
75
|
-
if (!isInteger(v) || v < 0 || v >= 256) {
|
|
76
|
-
return false;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return true;
|
|
80
|
-
}
|
|
81
|
-
exports.isBytes = isBytes;
|
|
82
|
-
/**
|
|
83
|
-
* Converts DataHexStringOrArrayish to a Uint8Array
|
|
84
|
-
* * Same as [`ethers.utils.arrayify`](https://docs.ethers.io/v5/api/utils/bytes/#utils-arrayify)
|
|
85
|
-
*
|
|
86
|
-
* @example
|
|
87
|
-
* ```js
|
|
88
|
-
* arrayify(1);
|
|
89
|
-
* // Uint8Array(1) [ 1 ]
|
|
90
|
-
* ```
|
|
91
|
-
*
|
|
92
|
-
* @example
|
|
93
|
-
* ```js
|
|
94
|
-
* arrayify(0x1234);
|
|
95
|
-
* // Uint8Array(2) [ 18, 52 ]
|
|
96
|
-
* ```
|
|
97
|
-
*
|
|
98
|
-
* @example
|
|
99
|
-
* ```js
|
|
100
|
-
* arrayify('0x1', { hexPad: 'right' });
|
|
101
|
-
* // Uint8Array(1) [ 16 ]
|
|
102
|
-
* ```
|
|
103
|
-
*/
|
|
104
|
-
function arrayify(value, options) {
|
|
105
|
-
if (!options) {
|
|
106
|
-
options = {};
|
|
107
|
-
}
|
|
108
|
-
if (typeof value === 'number') {
|
|
109
|
-
logger_1.logger.checkSafeUint53(value, 'invalid arrayify value');
|
|
110
|
-
const result = [];
|
|
111
|
-
while (value) {
|
|
112
|
-
result.unshift(value & 0xff);
|
|
113
|
-
value = parseInt(String(value / 256));
|
|
114
|
-
}
|
|
115
|
-
if (result.length === 0) {
|
|
116
|
-
result.push(0);
|
|
117
|
-
}
|
|
118
|
-
return new Uint8Array(result);
|
|
119
|
-
}
|
|
120
|
-
if (options.allowMissingPrefix &&
|
|
121
|
-
typeof value === 'string' &&
|
|
122
|
-
value.substring(0, 2) !== '0x') {
|
|
123
|
-
value = '0x' + value;
|
|
124
|
-
}
|
|
125
|
-
if (isHexable(value)) {
|
|
126
|
-
value = value.toHexString();
|
|
127
|
-
}
|
|
128
|
-
if (isHexString(value)) {
|
|
129
|
-
let hex = value.substring(2);
|
|
130
|
-
if (hex.length % 2) {
|
|
131
|
-
if (options.hexPad === 'left') {
|
|
132
|
-
hex = '0' + hex;
|
|
133
|
-
}
|
|
134
|
-
else if (options.hexPad === 'right') {
|
|
135
|
-
hex += '0';
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
logger_1.logger.throwArgumentError('hex data is odd-length', 'value', value);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
const result = [];
|
|
142
|
-
for (let i = 0; i < hex.length; i += 2) {
|
|
143
|
-
result.push(parseInt(hex.substring(i, i + 2), 16));
|
|
144
|
-
}
|
|
145
|
-
return new Uint8Array(result);
|
|
146
|
-
}
|
|
147
|
-
if (isBytes(value)) {
|
|
148
|
-
return new Uint8Array(value);
|
|
149
|
-
}
|
|
150
|
-
return logger_1.logger.throwArgumentError('invalid arrayify value', 'value', value);
|
|
151
|
-
}
|
|
152
|
-
exports.arrayify = arrayify;
|
|
153
|
-
/**
|
|
154
|
-
* Concatenates all the BytesLike in arrayOfBytesLike into a single Uint8Array.
|
|
155
|
-
* * Same as [`ethers.utils.concat`](https://docs.ethers.io/v5/api/utils/bytes/#utils-concat)
|
|
156
|
-
*
|
|
157
|
-
* @example
|
|
158
|
-
* ```js
|
|
159
|
-
* concat([0, 1]);
|
|
160
|
-
* // Uint8Array(2) [ 0, 1 ]
|
|
161
|
-
* ```
|
|
162
|
-
*/
|
|
163
|
-
function concat(arrayOfBytesLike) {
|
|
164
|
-
const objects = arrayOfBytesLike.map((item) => arrayify(item));
|
|
165
|
-
const length = objects.reduce((accum, item) => accum + item.length, 0);
|
|
166
|
-
const result = new Uint8Array(length);
|
|
167
|
-
objects.reduce((offset, object) => {
|
|
168
|
-
result.set(object, offset);
|
|
169
|
-
return offset + object.length;
|
|
170
|
-
}, 0);
|
|
171
|
-
return result;
|
|
172
|
-
}
|
|
173
|
-
exports.concat = concat;
|
|
174
|
-
function stripZeros(value) {
|
|
175
|
-
let result = arrayify(value);
|
|
176
|
-
if (result.length === 0) {
|
|
177
|
-
return result;
|
|
178
|
-
}
|
|
179
|
-
// Find the first non-zero entry
|
|
180
|
-
let start = 0;
|
|
181
|
-
while (start < result.length && result[start] === 0) {
|
|
182
|
-
start++;
|
|
183
|
-
}
|
|
184
|
-
// If we started with zeros, strip them
|
|
185
|
-
if (start) {
|
|
186
|
-
result = result.slice(start);
|
|
187
|
-
}
|
|
188
|
-
return result;
|
|
189
|
-
}
|
|
190
|
-
exports.stripZeros = stripZeros;
|
|
191
|
-
function zeroPad(value, length) {
|
|
192
|
-
value = arrayify(value);
|
|
193
|
-
if (value.length > length) {
|
|
194
|
-
logger_1.logger.throwArgumentError('value out of range', 'value', value);
|
|
195
|
-
}
|
|
196
|
-
const result = new Uint8Array(length);
|
|
197
|
-
result.set(value, length - value.length);
|
|
198
|
-
return result;
|
|
199
|
-
}
|
|
200
|
-
exports.zeroPad = zeroPad;
|
|
201
|
-
/**
|
|
202
|
-
* Returns true if and only if object is a valid hex string.
|
|
203
|
-
* If length is specified and object is not a valid DataHexString of length bytes, an InvalidArgument error is thrown.
|
|
204
|
-
* * Same as [`ethers.utils.isHexString`](https://docs.ethers.io/v5/api/utils/bytes/#utils-isHexString)
|
|
205
|
-
*/
|
|
206
|
-
function isHexString(value, length) {
|
|
207
|
-
if (typeof value !== 'string' || !value.match(/^0x[0-9A-Fa-f]*$/)) {
|
|
208
|
-
return false;
|
|
209
|
-
}
|
|
210
|
-
if (length && value.length !== 2 + 2 * length) {
|
|
211
|
-
return false;
|
|
212
|
-
}
|
|
213
|
-
return true;
|
|
214
|
-
}
|
|
215
|
-
exports.isHexString = isHexString;
|
|
216
|
-
const HexCharacters = '0123456789abcdef';
|
|
217
|
-
/**
|
|
218
|
-
* @example
|
|
219
|
-
* ```js
|
|
220
|
-
* hexlify(4);
|
|
221
|
-
* // '0x04'
|
|
222
|
-
*
|
|
223
|
-
* hexlify(14);
|
|
224
|
-
* // '0x0e'
|
|
225
|
-
* ```
|
|
226
|
-
*/
|
|
227
|
-
function hexlify(value, options) {
|
|
228
|
-
if (!options) {
|
|
229
|
-
options = {};
|
|
230
|
-
}
|
|
231
|
-
if (typeof value === 'number') {
|
|
232
|
-
logger_1.logger.checkSafeUint53(value, 'invalid hexlify value');
|
|
233
|
-
let hex = '';
|
|
234
|
-
while (value) {
|
|
235
|
-
hex = HexCharacters[value & 0xf] + hex;
|
|
236
|
-
value = Math.floor(value / 16);
|
|
237
|
-
}
|
|
238
|
-
if (hex.length) {
|
|
239
|
-
if (hex.length % 2) {
|
|
240
|
-
hex = '0' + hex;
|
|
241
|
-
}
|
|
242
|
-
return '0x' + hex;
|
|
243
|
-
}
|
|
244
|
-
return '0x00';
|
|
245
|
-
}
|
|
246
|
-
if (typeof value === 'bigint') {
|
|
247
|
-
value = value.toString(16);
|
|
248
|
-
if (value.length % 2) {
|
|
249
|
-
return '0x0' + value;
|
|
250
|
-
}
|
|
251
|
-
return '0x' + value;
|
|
252
|
-
}
|
|
253
|
-
if (options.allowMissingPrefix &&
|
|
254
|
-
typeof value === 'string' &&
|
|
255
|
-
value.substring(0, 2) !== '0x') {
|
|
256
|
-
value = '0x' + value;
|
|
257
|
-
}
|
|
258
|
-
if (isHexable(value)) {
|
|
259
|
-
return value.toHexString();
|
|
260
|
-
}
|
|
261
|
-
if (isHexString(value)) {
|
|
262
|
-
if (value.length % 2) {
|
|
263
|
-
if (options.hexPad === 'left') {
|
|
264
|
-
value = '0x0' + value.substring(2);
|
|
265
|
-
}
|
|
266
|
-
else if (options.hexPad === 'right') {
|
|
267
|
-
value += '0';
|
|
268
|
-
}
|
|
269
|
-
else {
|
|
270
|
-
logger_1.logger.throwArgumentError('hex data is odd-length', 'value', value);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
return value.toLowerCase();
|
|
274
|
-
}
|
|
275
|
-
if (isBytes(value)) {
|
|
276
|
-
let result = '0x';
|
|
277
|
-
for (let i = 0; i < value.length; i++) {
|
|
278
|
-
const v = value[i];
|
|
279
|
-
result += HexCharacters[(v & 0xf0) >> 4] + HexCharacters[v & 0x0f];
|
|
280
|
-
}
|
|
281
|
-
return result;
|
|
282
|
-
}
|
|
283
|
-
return logger_1.logger.throwArgumentError('invalid hexlify value', 'value', value);
|
|
284
|
-
}
|
|
285
|
-
exports.hexlify = hexlify;
|
|
286
|
-
function hexDataLength(data) {
|
|
287
|
-
if (typeof data !== 'string') {
|
|
288
|
-
data = hexlify(data);
|
|
289
|
-
}
|
|
290
|
-
else if (!isHexString(data) || data.length % 2) {
|
|
291
|
-
return null;
|
|
292
|
-
}
|
|
293
|
-
return (data.length - 2) / 2;
|
|
294
|
-
}
|
|
295
|
-
exports.hexDataLength = hexDataLength;
|
|
296
|
-
function hexDataSlice(data, offset, endOffset) {
|
|
297
|
-
if (typeof data !== 'string') {
|
|
298
|
-
data = hexlify(data);
|
|
299
|
-
}
|
|
300
|
-
else if (!isHexString(data) || data.length % 2) {
|
|
301
|
-
logger_1.logger.throwArgumentError('invalid hexData', 'value', data);
|
|
302
|
-
}
|
|
303
|
-
offset = 2 + 2 * offset;
|
|
304
|
-
if (endOffset != null) {
|
|
305
|
-
return '0x' + data.substring(offset, 2 + 2 * endOffset);
|
|
306
|
-
}
|
|
307
|
-
return '0x' + data.substring(offset);
|
|
308
|
-
}
|
|
309
|
-
exports.hexDataSlice = hexDataSlice;
|
|
310
|
-
function hexConcat(items) {
|
|
311
|
-
let result = '0x';
|
|
312
|
-
items.forEach((item) => {
|
|
313
|
-
result += hexlify(item).substring(2);
|
|
314
|
-
});
|
|
315
|
-
return result;
|
|
316
|
-
}
|
|
317
|
-
exports.hexConcat = hexConcat;
|
|
318
|
-
function hexValue(value) {
|
|
319
|
-
const trimmed = hexStripZeros(hexlify(value, { hexPad: 'left' }));
|
|
320
|
-
if (trimmed === '0x') {
|
|
321
|
-
return '0x0';
|
|
322
|
-
}
|
|
323
|
-
return trimmed;
|
|
324
|
-
}
|
|
325
|
-
exports.hexValue = hexValue;
|
|
326
|
-
function hexStripZeros(value) {
|
|
327
|
-
if (typeof value !== 'string') {
|
|
328
|
-
value = hexlify(value);
|
|
329
|
-
}
|
|
330
|
-
if (!isHexString(value)) {
|
|
331
|
-
logger_1.logger.throwArgumentError('invalid hex string', 'value', value);
|
|
332
|
-
}
|
|
333
|
-
value = value.substring(2);
|
|
334
|
-
let offset = 0;
|
|
335
|
-
while (offset < value.length && value[offset] === '0') {
|
|
336
|
-
offset++;
|
|
337
|
-
}
|
|
338
|
-
return '0x' + value.substring(offset);
|
|
339
|
-
}
|
|
340
|
-
exports.hexStripZeros = hexStripZeros;
|
|
341
|
-
/**
|
|
342
|
-
* Returns a hex string padded to a specified length of bytes.
|
|
343
|
-
*
|
|
344
|
-
* Similar to ["hexZeroPad" in ethers.js](https://docs.ethers.io/v5/api/utils/bytes/#utils-hexZeroPad)
|
|
345
|
-
*
|
|
346
|
-
* Differs from ["padLeft" in web3.js](https://web3js.readthedocs.io/en/v1.7.1/web3-utils.html#padleft) because web3 counts by characters, not bytes.
|
|
347
|
-
*
|
|
348
|
-
* @param hexValue - A hex-string, hex-number, or decimal number (auto-converts to base-16) to be padded
|
|
349
|
-
* @param length - The final length in bytes
|
|
350
|
-
*
|
|
351
|
-
* @throws - If the value is not a hex string or number
|
|
352
|
-
* @throws - If the value is longer than the length
|
|
353
|
-
*
|
|
354
|
-
* @example
|
|
355
|
-
* ```javascript
|
|
356
|
-
* hexZeroPad('0x60', 2);
|
|
357
|
-
* // '0x0060'
|
|
358
|
-
* ```
|
|
359
|
-
*
|
|
360
|
-
* @example
|
|
361
|
-
* ```javascript
|
|
362
|
-
* hexZeroPad(0x60, 3);
|
|
363
|
-
* // '0x000060'
|
|
364
|
-
* ```
|
|
365
|
-
*
|
|
366
|
-
* @example
|
|
367
|
-
* ```javascript
|
|
368
|
-
* hexZeroPad('12345', 1);
|
|
369
|
-
* // Throws
|
|
370
|
-
* ```
|
|
371
|
-
*/
|
|
372
|
-
function hexZeroPad(value, length) {
|
|
373
|
-
if (typeof value !== 'string') {
|
|
374
|
-
value = hexlify(value);
|
|
375
|
-
}
|
|
376
|
-
else if (!isHexString(value)) {
|
|
377
|
-
logger_1.logger.throwArgumentError('invalid hex string', 'value', value);
|
|
378
|
-
}
|
|
379
|
-
if (value.length > 2 * length + 2) {
|
|
380
|
-
logger_1.logger.throwError('value out of range', { value, length });
|
|
381
|
-
}
|
|
382
|
-
while (value.length < 2 * length + 2) {
|
|
383
|
-
value = '0x0' + value.substring(2);
|
|
384
|
-
}
|
|
385
|
-
return value;
|
|
386
|
-
}
|
|
387
|
-
exports.hexZeroPad = hexZeroPad;
|
|
388
|
-
// export function splitSignature(signature: SignatureLike): Signature {
|
|
389
|
-
// const result: Signature = {
|
|
390
|
-
// r: '0x',
|
|
391
|
-
// s: '0x',
|
|
392
|
-
// _vs: '0x',
|
|
393
|
-
// recoveryParam: 0,
|
|
394
|
-
// v: 0,
|
|
395
|
-
// yParityAndS: '0x',
|
|
396
|
-
// compact: '0x',
|
|
397
|
-
// };
|
|
398
|
-
// if (isBytesLike(signature)) {
|
|
399
|
-
// const bytes: Uint8Array = arrayify(signature);
|
|
400
|
-
// // Get the r, s and v
|
|
401
|
-
// if (bytes.length === 64) {
|
|
402
|
-
// // EIP-2098; pull the v from the top bit of s and clear it
|
|
403
|
-
// result.v = 27 + (bytes[32] >> 7);
|
|
404
|
-
// bytes[32] &= 0x7f;
|
|
405
|
-
// result.r = hexlify(bytes.slice(0, 32));
|
|
406
|
-
// result.s = hexlify(bytes.slice(32, 64));
|
|
407
|
-
// } else if (bytes.length === 65) {
|
|
408
|
-
// result.r = hexlify(bytes.slice(0, 32));
|
|
409
|
-
// result.s = hexlify(bytes.slice(32, 64));
|
|
410
|
-
// result.v = bytes[64];
|
|
411
|
-
// } else {
|
|
412
|
-
// logger.throwArgumentError(
|
|
413
|
-
// 'invalid signature string',
|
|
414
|
-
// 'signature',
|
|
415
|
-
// signature,
|
|
416
|
-
// );
|
|
417
|
-
// }
|
|
418
|
-
// // Allow a recid to be used as the v
|
|
419
|
-
// if (result.v < 27) {
|
|
420
|
-
// if (result.v === 0 || result.v === 1) {
|
|
421
|
-
// result.v += 27;
|
|
422
|
-
// } else {
|
|
423
|
-
// logger.throwArgumentError(
|
|
424
|
-
// 'signature invalid v byte',
|
|
425
|
-
// 'signature',
|
|
426
|
-
// signature,
|
|
427
|
-
// );
|
|
428
|
-
// }
|
|
429
|
-
// }
|
|
430
|
-
// // Compute recoveryParam from v
|
|
431
|
-
// result.recoveryParam = 1 - (result.v % 2);
|
|
432
|
-
// // Compute _vs from recoveryParam and s
|
|
433
|
-
// if (result.recoveryParam) {
|
|
434
|
-
// bytes[32] |= 0x80;
|
|
435
|
-
// }
|
|
436
|
-
// result._vs = hexlify(bytes.slice(32, 64));
|
|
437
|
-
// } else {
|
|
438
|
-
// result.r = signature.r;
|
|
439
|
-
// result.s = signature.s;
|
|
440
|
-
// result.v = signature.v;
|
|
441
|
-
// result.recoveryParam = signature.recoveryParam;
|
|
442
|
-
// result._vs = signature._vs;
|
|
443
|
-
// // If the _vs is available, use it to populate missing s, v and recoveryParam
|
|
444
|
-
// // and verify non-missing s, v and recoveryParam
|
|
445
|
-
// if (result._vs != null) {
|
|
446
|
-
// const vs = zeroPad(arrayify(result._vs), 32);
|
|
447
|
-
// result._vs = hexlify(vs);
|
|
448
|
-
// // Set or check the recid
|
|
449
|
-
// const recoveryParam = vs[0] >= 128 ? 1 : 0;
|
|
450
|
-
// if (result.recoveryParam == null) {
|
|
451
|
-
// result.recoveryParam = recoveryParam;
|
|
452
|
-
// } else if (result.recoveryParam !== recoveryParam) {
|
|
453
|
-
// logger.throwArgumentError(
|
|
454
|
-
// 'signature recoveryParam mismatch _vs',
|
|
455
|
-
// 'signature',
|
|
456
|
-
// signature,
|
|
457
|
-
// );
|
|
458
|
-
// }
|
|
459
|
-
// // Set or check the s
|
|
460
|
-
// vs[0] &= 0x7f;
|
|
461
|
-
// const s = hexlify(vs);
|
|
462
|
-
// if (result.s == null) {
|
|
463
|
-
// result.s = s;
|
|
464
|
-
// } else if (result.s !== s) {
|
|
465
|
-
// logger.throwArgumentError(
|
|
466
|
-
// 'signature v mismatch _vs',
|
|
467
|
-
// 'signature',
|
|
468
|
-
// signature,
|
|
469
|
-
// );
|
|
470
|
-
// }
|
|
471
|
-
// }
|
|
472
|
-
// // Use recid and v to populate each other
|
|
473
|
-
// if (result.recoveryParam == null) {
|
|
474
|
-
// if (result.v == null) {
|
|
475
|
-
// logger.throwArgumentError(
|
|
476
|
-
// 'signature missing v and recoveryParam',
|
|
477
|
-
// 'signature',
|
|
478
|
-
// signature,
|
|
479
|
-
// );
|
|
480
|
-
// } else if (result.v === 0 || result.v === 1) {
|
|
481
|
-
// result.recoveryParam = result.v;
|
|
482
|
-
// } else {
|
|
483
|
-
// result.recoveryParam = 1 - (result.v % 2);
|
|
484
|
-
// }
|
|
485
|
-
// } else {
|
|
486
|
-
// if (result.v == null) {
|
|
487
|
-
// result.v = 27 + result.recoveryParam;
|
|
488
|
-
// } else {
|
|
489
|
-
// const recId =
|
|
490
|
-
// result.v === 0 || result.v === 1 ? result.v : 1 - (result.v % 2);
|
|
491
|
-
// if (result.recoveryParam !== recId) {
|
|
492
|
-
// logger.throwArgumentError(
|
|
493
|
-
// 'signature recoveryParam mismatch v',
|
|
494
|
-
// 'signature',
|
|
495
|
-
// signature,
|
|
496
|
-
// );
|
|
497
|
-
// }
|
|
498
|
-
// }
|
|
499
|
-
// }
|
|
500
|
-
// if (result.r == null || !isHexString(result.r)) {
|
|
501
|
-
// logger.throwArgumentError(
|
|
502
|
-
// 'signature missing or invalid r',
|
|
503
|
-
// 'signature',
|
|
504
|
-
// signature,
|
|
505
|
-
// );
|
|
506
|
-
// } else {
|
|
507
|
-
// result.r = hexZeroPad(result.r, 32);
|
|
508
|
-
// }
|
|
509
|
-
// if (result.s == null || !isHexString(result.s)) {
|
|
510
|
-
// logger.throwArgumentError(
|
|
511
|
-
// 'signature missing or invalid s',
|
|
512
|
-
// 'signature',
|
|
513
|
-
// signature,
|
|
514
|
-
// );
|
|
515
|
-
// } else {
|
|
516
|
-
// result.s = hexZeroPad(result.s, 32);
|
|
517
|
-
// }
|
|
518
|
-
// const vs = arrayify(result.s);
|
|
519
|
-
// if (vs[0] >= 128) {
|
|
520
|
-
// logger.throwArgumentError(
|
|
521
|
-
// 'signature s out of range',
|
|
522
|
-
// 'signature',
|
|
523
|
-
// signature,
|
|
524
|
-
// );
|
|
525
|
-
// }
|
|
526
|
-
// if (result.recoveryParam) {
|
|
527
|
-
// vs[0] |= 0x80;
|
|
528
|
-
// }
|
|
529
|
-
// const _vs = hexlify(vs);
|
|
530
|
-
// if (result._vs) {
|
|
531
|
-
// if (!isHexString(result._vs)) {
|
|
532
|
-
// logger.throwArgumentError(
|
|
533
|
-
// 'signature invalid _vs',
|
|
534
|
-
// 'signature',
|
|
535
|
-
// signature,
|
|
536
|
-
// );
|
|
537
|
-
// }
|
|
538
|
-
// result._vs = hexZeroPad(result._vs, 32);
|
|
539
|
-
// }
|
|
540
|
-
// // Set or check the _vs
|
|
541
|
-
// if (result._vs == null) {
|
|
542
|
-
// result._vs = _vs;
|
|
543
|
-
// } else if (result._vs !== _vs) {
|
|
544
|
-
// logger.throwArgumentError(
|
|
545
|
-
// 'signature _vs mismatch v and s',
|
|
546
|
-
// 'signature',
|
|
547
|
-
// signature,
|
|
548
|
-
// );
|
|
549
|
-
// }
|
|
550
|
-
// }
|
|
551
|
-
// result.yParityAndS = result._vs;
|
|
552
|
-
// result.compact = result.r + result.yParityAndS.substring(2);
|
|
553
|
-
// return result;
|
|
554
|
-
// }
|
|
555
|
-
// export function joinSignature(signature: SignatureLike): string {
|
|
556
|
-
// signature = splitSignature(signature);
|
|
557
|
-
// return hexlify(
|
|
558
|
-
// concat([
|
|
559
|
-
// signature.r,
|
|
560
|
-
// signature.s,
|
|
561
|
-
// signature.recoveryParam ? '0x1c' : '0x1b',
|
|
562
|
-
// ]),
|
|
563
|
-
// );
|
|
564
|
-
// }
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Computes the address that corresponds to a specified public or private key
|
|
3
|
-
*
|
|
4
|
-
* @param key the public or private key to find the address related to
|
|
5
|
-
*
|
|
6
|
-
* @returns the address that corresponds to the key specified
|
|
7
|
-
*/
|
|
8
|
-
export declare function computeAddress(key: string): string;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.computeAddress = void 0;
|
|
4
|
-
const __1 = require("..");
|
|
5
|
-
const bytes_1 = require("./bytes");
|
|
6
|
-
const keccak256_1 = require("./keccak256");
|
|
7
|
-
/**
|
|
8
|
-
* Computes the address that corresponds to a specified public or private key
|
|
9
|
-
*
|
|
10
|
-
* @param key the public or private key to find the address related to
|
|
11
|
-
*
|
|
12
|
-
* @returns the address that corresponds to the key specified
|
|
13
|
-
*/
|
|
14
|
-
function computeAddress(key) {
|
|
15
|
-
// compressed public keys start with 0x04
|
|
16
|
-
// uncompressed public keys start with 0x03 or 0x02
|
|
17
|
-
if (!key.startsWith('0x04') &&
|
|
18
|
-
!key.startsWith('0x03') &&
|
|
19
|
-
!key.startsWith('0x02')) {
|
|
20
|
-
key = (0, __1.computePublicKey)(key);
|
|
21
|
-
}
|
|
22
|
-
return (0, __1.toChecksumAddress)((0, bytes_1.hexDataSlice)((0, keccak256_1.keccak256)((0, bytes_1.hexDataSlice)(key, 1)), 12));
|
|
23
|
-
}
|
|
24
|
-
exports.computeAddress = computeAddress;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { BytesLike } from './bytes';
|
|
2
|
-
/**
|
|
3
|
-
* Computes the public key from a given private key
|
|
4
|
-
*
|
|
5
|
-
* @param key the private key to find a public key from
|
|
6
|
-
*
|
|
7
|
-
* @returns the public key
|
|
8
|
-
*/
|
|
9
|
-
export declare function computePublicKey(privKey: BytesLike): string;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.computePublicKey = void 0;
|
|
4
|
-
const secp256k1_1 = require("@noble/secp256k1");
|
|
5
|
-
const bytes_1 = require("./bytes");
|
|
6
|
-
/**
|
|
7
|
-
* Computes the public key from a given private key
|
|
8
|
-
*
|
|
9
|
-
* @param key the private key to find a public key from
|
|
10
|
-
*
|
|
11
|
-
* @returns the public key
|
|
12
|
-
*/
|
|
13
|
-
function computePublicKey(privKey) {
|
|
14
|
-
privKey = (0, bytes_1.hexlify)(privKey).slice(2);
|
|
15
|
-
return '0x' + secp256k1_1.Point.fromPrivateKey(privKey).toHex();
|
|
16
|
-
}
|
|
17
|
-
exports.computePublicKey = computePublicKey;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import Big from 'big.js';
|
|
2
|
-
import { TinyBig } from '../shared/tiny-big/tiny-big';
|
|
3
|
-
/**
|
|
4
|
-
* Convert from Ether to Gwei
|
|
5
|
-
*
|
|
6
|
-
* No direct equivalent in ether.js; requires multiple functions to achieve.
|
|
7
|
-
*
|
|
8
|
-
* No direct equivalent in web3; requires multiple functions to achieve.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```javascript
|
|
12
|
-
* etherToGwei('1000').toString()
|
|
13
|
-
* // '1000000000000'
|
|
14
|
-
* etherToGwei(1000).toString()
|
|
15
|
-
* // '1000000000000'
|
|
16
|
-
* ```
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```javascript
|
|
20
|
-
* etherToGwei('1000').toNumber()
|
|
21
|
-
* // 1000000000000
|
|
22
|
-
* etherToGwei(1000).toNumber()
|
|
23
|
-
* // 1000000000000
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
export declare function etherToGwei(etherQuantity: string | number | TinyBig | Big): TinyBig;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.etherToGwei = void 0;
|
|
4
|
-
const tiny_big_1 = require("../shared/tiny-big/tiny-big");
|
|
5
|
-
const validate_type_1 = require("../shared/validate-type");
|
|
6
|
-
/**
|
|
7
|
-
* Convert from Ether to Gwei
|
|
8
|
-
*
|
|
9
|
-
* No direct equivalent in ether.js; requires multiple functions to achieve.
|
|
10
|
-
*
|
|
11
|
-
* No direct equivalent in web3; requires multiple functions to achieve.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```javascript
|
|
15
|
-
* etherToGwei('1000').toString()
|
|
16
|
-
* // '1000000000000'
|
|
17
|
-
* etherToGwei(1000).toString()
|
|
18
|
-
* // '1000000000000'
|
|
19
|
-
* ```
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```javascript
|
|
23
|
-
* etherToGwei('1000').toNumber()
|
|
24
|
-
* // 1000000000000
|
|
25
|
-
* etherToGwei(1000).toNumber()
|
|
26
|
-
* // 1000000000000
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
function etherToGwei(etherQuantity) {
|
|
30
|
-
(0, validate_type_1.validateType)(etherQuantity, ['string', 'number', 'object']);
|
|
31
|
-
const result = (0, tiny_big_1.tinyBig)(etherQuantity).times('1000000000');
|
|
32
|
-
return (0, tiny_big_1.tinyBig)(result);
|
|
33
|
-
}
|
|
34
|
-
exports.etherToGwei = etherToGwei;
|