essential-eth 0.9.1-next.0 → 0.9.1-next.1
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/dist/cjs/classes/Contract.js +66 -311
- package/dist/cjs/classes/test/Contract/crv-abi.js +256 -252
- package/dist/cjs/classes/test/Contract/ens-abi.js +212 -497
- package/dist/cjs/classes/test/Contract/fei-abi.js +284 -605
- package/dist/cjs/classes/test/Contract/foo-abi.js +21 -44
- package/dist/cjs/classes/test/Contract/uniswap-abi.js +68 -64
- package/dist/cjs/classes/utils/clean-block.js +30 -52
- package/dist/cjs/classes/utils/clean-log.js +20 -42
- package/dist/cjs/classes/utils/clean-transaction-receipt.js +30 -51
- package/dist/cjs/classes/utils/clean-transaction.js +30 -52
- package/dist/cjs/classes/utils/encode-decode-transaction.js +107 -148
- package/dist/cjs/classes/utils/fetchers.js +44 -166
- package/dist/cjs/classes/utils/hex-to-decimal.js +6 -1
- package/dist/cjs/classes/utils/prepare-transaction.js +36 -59
- package/dist/cjs/index.js +56 -25
- package/dist/cjs/index.umd.js +1 -1
- package/dist/cjs/index.umd.js.map +1 -1
- package/dist/cjs/logger/logger.js +29 -123
- package/dist/cjs/logger/package-version.d.ts +1 -1
- package/dist/cjs/logger/package-version.js +4 -1
- package/dist/cjs/providers/AlchemyProvider.js +9 -82
- package/dist/cjs/providers/BaseProvider.js +520 -958
- package/dist/cjs/providers/FallthroughProvider.js +47 -156
- package/dist/cjs/providers/JsonRpcProvider.js +28 -114
- package/dist/cjs/providers/test/json-rpc-provider/get-logs/mocks.js +104 -101
- package/dist/cjs/providers/test/mock-of.js +6 -3
- package/dist/cjs/providers/test/rpc-urls.js +23 -15
- package/dist/cjs/providers/utils/chains-info.js +3 -1
- package/dist/cjs/shared/tiny-big/helpers.js +42 -93
- package/dist/cjs/shared/tiny-big/tiny-big.js +81 -210
- package/dist/cjs/shared/validate-type.js +7 -7
- package/dist/cjs/types/Block.types.js +2 -1
- package/dist/cjs/types/Contract.types.js +2 -1
- package/dist/cjs/types/FeeData.types.js +2 -1
- package/dist/cjs/types/Filter.types.js +2 -1
- package/dist/cjs/types/Network.types.js +2 -3
- package/dist/cjs/types/Transaction.types.js +2 -1
- package/dist/cjs/utils/bytes.js +318 -286
- package/dist/cjs/utils/compute-address.js +15 -8
- package/dist/cjs/utils/compute-public-key.js +10 -5
- package/dist/cjs/utils/ether-to-gwei.js +11 -10
- package/dist/cjs/utils/ether-to-wei.js +11 -10
- package/dist/cjs/utils/gwei-to-ether.js +11 -10
- package/dist/cjs/utils/hash-message.js +16 -11
- package/dist/cjs/utils/is-address.js +12 -8
- package/dist/cjs/utils/keccak256.js +14 -8
- package/dist/cjs/utils/solidity-keccak256.js +60 -49
- package/dist/cjs/utils/split-signature.js +73 -55
- package/dist/cjs/utils/to-checksum-address.js +20 -15
- package/dist/cjs/utils/to-utf8-bytes.js +6 -1
- package/dist/cjs/utils/wei-to-ether.js +15 -13
- package/dist/esm/logger/package-version.d.ts +1 -1
- package/dist/esm/logger/package-version.js +1 -1
- package/package.json +2 -2
- package/readme.md +1 -1
- package/dist/cjs/classes/test/Contract/crv.test.js +0 -497
- package/dist/cjs/classes/test/Contract/ens.test.js +0 -160
- package/dist/cjs/classes/test/Contract/fei.test.js +0 -224
- package/dist/cjs/classes/test/Contract/foo.test.js +0 -33
- package/dist/cjs/classes/test/Contract/uni.test.js +0 -289
- package/dist/cjs/providers/test/fallthrough-provider/get-gas-price.test.js +0 -228
- package/dist/cjs/providers/test/get-transaction-count.test.js +0 -239
- package/dist/cjs/providers/test/json-rpc-provider/call.test.js +0 -375
- package/dist/cjs/providers/test/json-rpc-provider/estimate-gas.test.js +0 -217
- package/dist/cjs/providers/test/json-rpc-provider/get-balance.test.js +0 -223
- package/dist/cjs/providers/test/json-rpc-provider/get-block-number.test.js +0 -163
- package/dist/cjs/providers/test/json-rpc-provider/get-block.test.js +0 -414
- package/dist/cjs/providers/test/json-rpc-provider/get-code.test.js +0 -282
- package/dist/cjs/providers/test/json-rpc-provider/get-fee-data.test.js +0 -187
- package/dist/cjs/providers/test/json-rpc-provider/get-gas-price.test.js +0 -167
- package/dist/cjs/providers/test/json-rpc-provider/get-logs/get-logs.test.js +0 -219
- package/dist/cjs/providers/test/json-rpc-provider/get-network.test.js +0 -232
- package/dist/cjs/providers/test/json-rpc-provider/get-transaction-receipt.test.js +0 -280
- package/dist/cjs/providers/test/json-rpc-provider/get-transaction.test.js +0 -266
- package/dist/cjs/providers/test/test-alchemy-provider.test.js +0 -151
- package/dist/cjs/shared/tiny-big/helpers.test.js +0 -29
- package/dist/cjs/shared/tiny-big/tiny-big.test.js +0 -34
- package/dist/cjs/utils/tests/bytes/arrayify.test.js +0 -64
- package/dist/cjs/utils/tests/bytes/concat.test.js +0 -17
- package/dist/cjs/utils/tests/bytes/hex-concat.test.js +0 -65
- package/dist/cjs/utils/tests/bytes/hex-data-length.test.js +0 -66
- package/dist/cjs/utils/tests/bytes/hex-data-slice.test.js +0 -51
- package/dist/cjs/utils/tests/bytes/hex-strip-zeros.test.js +0 -75
- package/dist/cjs/utils/tests/bytes/hex-value.test.js +0 -141
- package/dist/cjs/utils/tests/bytes/hex-zero-pad.test.js +0 -100
- package/dist/cjs/utils/tests/bytes/hexlify.test.js +0 -78
- package/dist/cjs/utils/tests/bytes/is-bytes-like.test.js +0 -68
- package/dist/cjs/utils/tests/bytes/is-bytes.test.js +0 -76
- package/dist/cjs/utils/tests/bytes/is-hex-string.test.js +0 -97
- package/dist/cjs/utils/tests/bytes/strip-zeros.test.js +0 -106
- package/dist/cjs/utils/tests/bytes/zero-pad.test.js +0 -144
- package/dist/cjs/utils/tests/compute-address.test.js +0 -49
- package/dist/cjs/utils/tests/compute-public-key.test.js +0 -26
- package/dist/cjs/utils/tests/ether-to-gwei.test.js +0 -26
- package/dist/cjs/utils/tests/ether-to-wei.test.js +0 -36
- package/dist/cjs/utils/tests/gwei-to-ether.test.js +0 -28
- package/dist/cjs/utils/tests/hash-message.test.js +0 -32
- package/dist/cjs/utils/tests/is-address.test.js +0 -48
- package/dist/cjs/utils/tests/keccak256.test.js +0 -121
- package/dist/cjs/utils/tests/solidity-keccak256.test.js +0 -311
- package/dist/cjs/utils/tests/split-signature.test.js +0 -46
- package/dist/cjs/utils/tests/to-checksum-address.test.js +0 -39
- package/dist/cjs/utils/tests/to-utf8-bytes.test.js +0 -34
- package/dist/cjs/utils/tests/wei-to-ether.test.js +0 -41
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.computeAddress = void 0;
|
|
4
|
+
const bytes_1 = require("./bytes");
|
|
5
|
+
const compute_public_key_1 = require("./compute-public-key");
|
|
6
|
+
const keccak256_1 = require("./keccak256");
|
|
7
|
+
const to_checksum_address_1 = require("./to-checksum-address");
|
|
5
8
|
/**
|
|
6
9
|
* Computes the address that corresponds to a specified public or private key
|
|
7
10
|
*
|
|
@@ -17,11 +20,15 @@ import { toChecksumAddress } from "./to-checksum-address";
|
|
|
17
20
|
* computeAddress('0x2f2c419acf4a1da8c1ebea75bb3fcfbd3ec2aa3bf0162901ccdc2f38b8f92427'); // private key
|
|
18
21
|
* // '0xA2902059a7BF992f1450BACD7357CCAa5cC8336a'
|
|
19
22
|
* ```
|
|
20
|
-
*/
|
|
23
|
+
*/
|
|
24
|
+
function computeAddress(key) {
|
|
21
25
|
// compressed public keys start with 0x04
|
|
22
26
|
// uncompressed public keys start with 0x03 or 0x02
|
|
23
|
-
if (!key.startsWith(
|
|
24
|
-
key
|
|
27
|
+
if (!key.startsWith('0x04') &&
|
|
28
|
+
!key.startsWith('0x03') &&
|
|
29
|
+
!key.startsWith('0x02')) {
|
|
30
|
+
key = (0, compute_public_key_1.computePublicKey)(key);
|
|
25
31
|
}
|
|
26
|
-
return toChecksumAddress(hexDataSlice(keccak256(hexDataSlice(key, 1)), 12));
|
|
32
|
+
return (0, to_checksum_address_1.toChecksumAddress)((0, bytes_1.hexDataSlice)((0, keccak256_1.keccak256)((0, bytes_1.hexDataSlice)(key, 1)), 12));
|
|
27
33
|
}
|
|
34
|
+
exports.computeAddress = computeAddress;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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");
|
|
3
6
|
/**
|
|
4
7
|
* Computes the public key from a given private key
|
|
5
8
|
*
|
|
@@ -15,7 +18,9 @@ import { hexlify } from "./bytes";
|
|
|
15
18
|
* computePublicKey([50,102,50,99,52,49,57,97,99,102,52,97,49,100,97,56,99,49,101,98,101,97,55,53,98,98,51,102,99,102,98,100]);
|
|
16
19
|
* // '0x04a9cea77eca949df84f661cee153426fb51f2294b9364b4fac240df57360b9b0ac9c99e4d7966491ab4c81f8c82e0cd24ec5759832ad4ab736d22c7d90b806ee8'
|
|
17
20
|
* ```
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
*/
|
|
22
|
+
function computePublicKey(privKey) {
|
|
23
|
+
privKey = (0, bytes_1.hexlify)(privKey).slice(2);
|
|
24
|
+
return '0x' + secp256k1_1.Point.fromPrivateKey(privKey).toHex();
|
|
21
25
|
}
|
|
26
|
+
exports.computePublicKey = computePublicKey;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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");
|
|
3
6
|
/**
|
|
4
7
|
* Convert from Ether to Gwei
|
|
5
8
|
*
|
|
@@ -23,12 +26,10 @@ import { validateType } from "../shared/validate-type";
|
|
|
23
26
|
* etherToGwei(1000).toNumber()
|
|
24
27
|
* // 1000000000000
|
|
25
28
|
* ```
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
]);
|
|
32
|
-
var result = tinyBig(etherQuantity).times("1000000000");
|
|
33
|
-
return tinyBig(result);
|
|
29
|
+
*/
|
|
30
|
+
function etherToGwei(etherQuantity) {
|
|
31
|
+
(0, validate_type_1.validateType)(etherQuantity, ['string', 'number', 'object']);
|
|
32
|
+
const result = (0, tiny_big_1.tinyBig)(etherQuantity).times('1000000000');
|
|
33
|
+
return (0, tiny_big_1.tinyBig)(result);
|
|
34
34
|
}
|
|
35
|
+
exports.etherToGwei = etherToGwei;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.etherToWei = void 0;
|
|
4
|
+
const tiny_big_1 = require("../shared/tiny-big/tiny-big");
|
|
5
|
+
const validate_type_1 = require("../shared/validate-type");
|
|
3
6
|
/**
|
|
4
7
|
* Convert Ether to Wei
|
|
5
8
|
*
|
|
@@ -23,12 +26,10 @@ import { validateType } from "../shared/validate-type";
|
|
|
23
26
|
* etherToWei(1000).toNumber()
|
|
24
27
|
* // 1000000000000000000000
|
|
25
28
|
* ```
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
]);
|
|
32
|
-
var result = tinyBig(etherQuantity).times("1000000000000000000");
|
|
33
|
-
return tinyBig(result);
|
|
29
|
+
*/
|
|
30
|
+
function etherToWei(etherQuantity) {
|
|
31
|
+
(0, validate_type_1.validateType)(etherQuantity, ['string', 'number', 'object']);
|
|
32
|
+
const result = (0, tiny_big_1.tinyBig)(etherQuantity).times('1000000000000000000');
|
|
33
|
+
return (0, tiny_big_1.tinyBig)(result);
|
|
34
34
|
}
|
|
35
|
+
exports.etherToWei = etherToWei;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.gweiToEther = void 0;
|
|
4
|
+
const tiny_big_1 = require("../shared/tiny-big/tiny-big");
|
|
5
|
+
const validate_type_1 = require("../shared/validate-type");
|
|
3
6
|
/**
|
|
4
7
|
* Convert from Gwei to Ether
|
|
5
8
|
*
|
|
@@ -23,12 +26,10 @@ import { validateType } from "../shared/validate-type";
|
|
|
23
26
|
* gweiToEther(1000000000000).toNumber()
|
|
24
27
|
* // 1000
|
|
25
28
|
* ```
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
]);
|
|
32
|
-
var result = tinyBig(gweiQuantity).div("1000000000");
|
|
33
|
-
return tinyBig(result);
|
|
29
|
+
*/
|
|
30
|
+
function gweiToEther(gweiQuantity) {
|
|
31
|
+
(0, validate_type_1.validateType)(gweiQuantity, ['string', 'number', 'object']);
|
|
32
|
+
const result = (0, tiny_big_1.tinyBig)(gweiQuantity).div('1000000000');
|
|
33
|
+
return (0, tiny_big_1.tinyBig)(result);
|
|
34
34
|
}
|
|
35
|
+
exports.gweiToEther = gweiToEther;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hashMessage = void 0;
|
|
4
|
+
const bytes_1 = require("./bytes");
|
|
5
|
+
const keccak256_1 = require("./keccak256");
|
|
6
|
+
const to_utf8_bytes_1 = require("./to-utf8-bytes");
|
|
7
|
+
const messagePrefix = '\x19Ethereum Signed Message:\n';
|
|
5
8
|
/**
|
|
6
9
|
* Computes the EIP-191 personal message digest of message.
|
|
7
10
|
* Personal messages are converted to UTF-8 bytes and prefixed with \x19Ethereum Signed Message: and the length of message.
|
|
@@ -13,13 +16,15 @@ var messagePrefix = "\x19Ethereum Signed Message:\n";
|
|
|
13
16
|
* hashMessage("Hello World");
|
|
14
17
|
* // '0xa1de988600a42c4b4ab089b619297c17d53cffae5d5120d82d8a92d0bb3b78f2'
|
|
15
18
|
* ```
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
*/
|
|
20
|
+
function hashMessage(message) {
|
|
21
|
+
if (typeof message === 'string') {
|
|
22
|
+
message = (0, to_utf8_bytes_1.toUtf8Bytes)(message);
|
|
19
23
|
}
|
|
20
|
-
return keccak256(concat([
|
|
21
|
-
toUtf8Bytes(messagePrefix),
|
|
22
|
-
toUtf8Bytes(String(message.length)),
|
|
23
|
-
message
|
|
24
|
+
return (0, keccak256_1.keccak256)((0, bytes_1.concat)([
|
|
25
|
+
(0, to_utf8_bytes_1.toUtf8Bytes)(messagePrefix),
|
|
26
|
+
(0, to_utf8_bytes_1.toUtf8Bytes)(String(message.length)),
|
|
27
|
+
message,
|
|
24
28
|
]));
|
|
25
29
|
}
|
|
30
|
+
exports.hashMessage = hashMessage;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isAddress = void 0;
|
|
4
|
+
const validate_type_1 = require("../shared/validate-type");
|
|
5
|
+
const to_checksum_address_1 = require("./to-checksum-address");
|
|
3
6
|
/**
|
|
4
7
|
* Returns a boolean as to whether the input is a valid address.
|
|
5
8
|
* Does NOT support ICAP addresses
|
|
@@ -22,14 +25,15 @@ import { toChecksumAddress } from "./to-checksum-address";
|
|
|
22
25
|
* isAddress('vitalik.eth');
|
|
23
26
|
* // false
|
|
24
27
|
* ```
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
]);
|
|
28
|
+
*/
|
|
29
|
+
function isAddress(address) {
|
|
30
|
+
(0, validate_type_1.validateType)(address, ['string']);
|
|
29
31
|
try {
|
|
30
|
-
toChecksumAddress(address);
|
|
32
|
+
(0, to_checksum_address_1.toChecksumAddress)(address);
|
|
31
33
|
return true;
|
|
32
|
-
}
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
33
36
|
return false;
|
|
34
37
|
}
|
|
35
38
|
}
|
|
39
|
+
exports.isAddress = isAddress;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.keccak256 = void 0;
|
|
4
|
+
const sha3_1 = require("sha3");
|
|
2
5
|
/**
|
|
3
6
|
* Hashes data into a Keccak256 hex string
|
|
4
7
|
*
|
|
@@ -12,14 +15,17 @@ import { Keccak } from "sha3";
|
|
|
12
15
|
* keccak256('0x123');
|
|
13
16
|
* // '0x5fa2358263196dbbf23d1ca7a509451f7a2f64c15837bfbb81298b1e3e24e4fa'
|
|
14
17
|
* ```
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
*/
|
|
19
|
+
function keccak256(data) {
|
|
20
|
+
let bufferableData;
|
|
21
|
+
if (typeof data === 'string') {
|
|
22
|
+
bufferableData = Buffer.from(data.replace(/^0x/, ''), 'hex');
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
20
25
|
bufferableData = Buffer.from(data);
|
|
21
26
|
}
|
|
22
|
-
|
|
23
|
-
|
|
27
|
+
const keccak = new sha3_1.Keccak(256);
|
|
28
|
+
const addressHash = '0x' + keccak.update(bufferableData).digest('hex');
|
|
24
29
|
return addressHash;
|
|
25
30
|
}
|
|
31
|
+
exports.keccak256 = keccak256;
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.solidityKeccak256 = exports.pack = void 0;
|
|
4
|
+
const buffer_1 = require("buffer");
|
|
5
|
+
const encode_decode_transaction_1 = require("../classes/utils/encode-decode-transaction");
|
|
6
|
+
const logger_1 = require("../logger/logger");
|
|
7
|
+
const tiny_big_1 = require("../shared/tiny-big/tiny-big");
|
|
8
|
+
const bytes_1 = require("./bytes");
|
|
9
|
+
const keccak256_1 = require("./keccak256");
|
|
10
|
+
const regexBytes = new RegExp('^bytes([0-9]+)$');
|
|
11
|
+
const regexNumber = new RegExp('^(u?int)([0-9]*)$');
|
|
12
|
+
const regexArray = new RegExp('^(.*)\\[([0-9]*)\\]$');
|
|
10
13
|
/**
|
|
11
14
|
* Packs a type and value together into a UTF-8 Byte Array
|
|
12
15
|
*
|
|
@@ -16,66 +19,70 @@ var regexArray = new RegExp("^(.*)\\[([0-9]*)\\]$");
|
|
|
16
19
|
* @param isArray whether the specified data is in an array
|
|
17
20
|
* @returns packed data consisting of the type and value
|
|
18
21
|
* @example N/A - internal function
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
*/
|
|
23
|
+
function _pack(type, value, isArray) {
|
|
24
|
+
switch (type) {
|
|
25
|
+
case 'address':
|
|
22
26
|
if (isArray) {
|
|
23
|
-
return zeroPad(value, 32);
|
|
27
|
+
return (0, bytes_1.zeroPad)(value, 32);
|
|
24
28
|
}
|
|
25
|
-
return arrayify(value);
|
|
26
|
-
case
|
|
27
|
-
return Buffer.from(value);
|
|
28
|
-
case
|
|
29
|
-
return arrayify(value);
|
|
30
|
-
case
|
|
31
|
-
value = value ?
|
|
29
|
+
return (0, bytes_1.arrayify)(value);
|
|
30
|
+
case 'string':
|
|
31
|
+
return buffer_1.Buffer.from(value);
|
|
32
|
+
case 'bytes':
|
|
33
|
+
return (0, bytes_1.arrayify)(value);
|
|
34
|
+
case 'bool':
|
|
35
|
+
value = value ? '0x01' : '0x00';
|
|
32
36
|
if (isArray) {
|
|
33
|
-
return zeroPad(value, 32);
|
|
37
|
+
return (0, bytes_1.zeroPad)(value, 32);
|
|
34
38
|
}
|
|
35
|
-
return arrayify(value);
|
|
39
|
+
return (0, bytes_1.arrayify)(value);
|
|
36
40
|
}
|
|
37
|
-
|
|
41
|
+
let match = type.match(regexNumber);
|
|
38
42
|
if (match) {
|
|
39
43
|
//let signed = (match[1] === "int")
|
|
40
|
-
|
|
41
|
-
if (match[2] && String(size) !== match[2] ||
|
|
42
|
-
|
|
44
|
+
let size = parseInt(match[2] || '256');
|
|
45
|
+
if ((match[2] && String(size) !== match[2]) ||
|
|
46
|
+
size % 8 !== 0 ||
|
|
47
|
+
size === 0 ||
|
|
48
|
+
size > 256) {
|
|
49
|
+
logger_1.logger.throwArgumentError('invalid number type', 'type', type);
|
|
43
50
|
}
|
|
44
51
|
if (isArray) {
|
|
45
52
|
size = 256;
|
|
46
53
|
}
|
|
47
|
-
value = tinyBig(value).toTwos(size).toNumber();
|
|
48
|
-
|
|
49
|
-
return zeroPad(hexValue, size / 8);
|
|
54
|
+
value = (0, tiny_big_1.tinyBig)(value).toTwos(size).toNumber();
|
|
55
|
+
const hexValue = (0, bytes_1.hexlify)(value);
|
|
56
|
+
return (0, bytes_1.zeroPad)(hexValue, size / 8);
|
|
50
57
|
}
|
|
51
58
|
match = type.match(regexBytes);
|
|
52
59
|
if (match) {
|
|
53
|
-
|
|
54
|
-
if (String(
|
|
55
|
-
logger.throwArgumentError(
|
|
60
|
+
const size = parseInt(match[1]);
|
|
61
|
+
if (String(size) !== match[1] || size === 0 || size > 32) {
|
|
62
|
+
logger_1.logger.throwArgumentError('invalid bytes type', 'type', type);
|
|
56
63
|
}
|
|
57
|
-
if (arrayify(value).byteLength !==
|
|
58
|
-
logger.throwArgumentError(
|
|
64
|
+
if ((0, bytes_1.arrayify)(value).byteLength !== size) {
|
|
65
|
+
logger_1.logger.throwArgumentError(`invalid value for ${type}`, 'value', value);
|
|
59
66
|
}
|
|
60
67
|
if (isArray) {
|
|
61
|
-
return arrayify((value + hexFalse).substring(0, 66));
|
|
68
|
+
return (0, bytes_1.arrayify)((value + encode_decode_transaction_1.hexFalse).substring(0, 66));
|
|
62
69
|
}
|
|
63
70
|
return value;
|
|
64
71
|
}
|
|
65
72
|
match = type.match(regexArray);
|
|
66
73
|
if (match && Array.isArray(value)) {
|
|
67
|
-
|
|
68
|
-
|
|
74
|
+
const baseType = match[1];
|
|
75
|
+
const count = parseInt(match[2] || String(value.length));
|
|
69
76
|
if (count != value.length) {
|
|
70
|
-
logger.throwArgumentError(
|
|
77
|
+
logger_1.logger.throwArgumentError(`invalid array length for ${type}`, 'value', value);
|
|
71
78
|
}
|
|
72
|
-
|
|
73
|
-
value.forEach(function(value) {
|
|
79
|
+
const result = [];
|
|
80
|
+
value.forEach(function (value) {
|
|
74
81
|
result.push(_pack(baseType, value, true));
|
|
75
82
|
});
|
|
76
|
-
return concat(result);
|
|
83
|
+
return (0, bytes_1.concat)(result);
|
|
77
84
|
}
|
|
78
|
-
return logger.throwArgumentError(
|
|
85
|
+
return logger_1.logger.throwArgumentError('invalid type', 'type', type);
|
|
79
86
|
}
|
|
80
87
|
/**
|
|
81
88
|
* Converts arrays with types and values into a hex string that can be hashed
|
|
@@ -90,16 +97,18 @@ var regexArray = new RegExp("^(.*)\\[([0-9]*)\\]$");
|
|
|
90
97
|
* pack(types, values);
|
|
91
98
|
* // '0x0174657874000000000000001e'
|
|
92
99
|
* ```
|
|
93
|
-
*/
|
|
100
|
+
*/
|
|
101
|
+
function pack(types, values) {
|
|
94
102
|
if (types.length != values.length) {
|
|
95
|
-
logger.throwArgumentError(
|
|
103
|
+
logger_1.logger.throwArgumentError('wrong number of values; expected ${ types.length }', 'values', values);
|
|
96
104
|
}
|
|
97
|
-
|
|
98
|
-
types.forEach(function(type, index) {
|
|
105
|
+
const tight = [];
|
|
106
|
+
types.forEach(function (type, index) {
|
|
99
107
|
tight.push(_pack(type, values[index]));
|
|
100
108
|
});
|
|
101
|
-
return hexlify(concat(tight));
|
|
109
|
+
return (0, bytes_1.hexlify)((0, bytes_1.concat)(tight));
|
|
102
110
|
}
|
|
111
|
+
exports.pack = pack;
|
|
103
112
|
/**
|
|
104
113
|
* Hashes data from Solidity using the Keccak256 algorithm.
|
|
105
114
|
*
|
|
@@ -122,6 +131,8 @@ var regexArray = new RegExp("^(.*)\\[([0-9]*)\\]$");
|
|
|
122
131
|
* solidityKeccak256(types, values);
|
|
123
132
|
* // '0x038707a887f09355dc545412b058e7ba8f3c74047050c7c5e5e52eec608053d9'
|
|
124
133
|
* ```
|
|
125
|
-
*/
|
|
126
|
-
|
|
134
|
+
*/
|
|
135
|
+
function solidityKeccak256(types, values) {
|
|
136
|
+
return (0, keccak256_1.keccak256)(pack(types, values));
|
|
127
137
|
}
|
|
138
|
+
exports.solidityKeccak256 = solidityKeccak256;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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");
|
|
3
6
|
/**
|
|
4
7
|
* Expands a signature into the full signature object and fills in missing properties.
|
|
5
8
|
*
|
|
@@ -21,48 +24,53 @@ import { arrayify, hexlify, hexZeroPad, isBytesLike, isHexString, zeroPad } from
|
|
|
21
24
|
* compact: "0x60bc4ed91f2021aefe7045f3f77bd12f87eb733aee24bd1965343b3c27b3971647252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33"
|
|
22
25
|
* }
|
|
23
26
|
* ```
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
*/
|
|
28
|
+
function splitSignature(signature) {
|
|
29
|
+
const result = {
|
|
30
|
+
r: '0x',
|
|
31
|
+
s: '0x',
|
|
32
|
+
_vs: '0x',
|
|
29
33
|
recoveryParam: 0,
|
|
30
34
|
v: 0,
|
|
31
|
-
yParityAndS:
|
|
32
|
-
compact:
|
|
35
|
+
yParityAndS: '0x',
|
|
36
|
+
compact: '0x',
|
|
33
37
|
};
|
|
34
|
-
if (isBytesLike(signature)) {
|
|
35
|
-
|
|
38
|
+
if ((0, bytes_1.isBytesLike)(signature)) {
|
|
39
|
+
const bytes = (0, bytes_1.arrayify)(signature);
|
|
36
40
|
// Get the r, s and v
|
|
37
41
|
if (bytes.length === 64) {
|
|
38
42
|
// EIP-2098; pull the v from the top bit of s and clear it
|
|
39
43
|
result.v = 27 + (bytes[32] >> 7);
|
|
40
44
|
bytes[32] &= 0x7f;
|
|
41
|
-
result.r = hexlify(bytes.slice(0, 32));
|
|
42
|
-
result.s = hexlify(bytes.slice(32, 64));
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
result.
|
|
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));
|
|
46
51
|
result.v = bytes[64];
|
|
47
|
-
}
|
|
48
|
-
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
logger_1.logger.throwArgumentError('invalid signature string', 'signature', signature);
|
|
49
55
|
}
|
|
50
56
|
// Allow a recid to be used as the v
|
|
51
57
|
if (result.v < 27) {
|
|
52
58
|
if (result.v === 0 || result.v === 1) {
|
|
53
59
|
result.v += 27;
|
|
54
|
-
}
|
|
55
|
-
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
logger_1.logger.throwArgumentError('signature invalid v byte', 'signature', signature);
|
|
56
63
|
}
|
|
57
64
|
}
|
|
58
65
|
// Compute recoveryParam from v
|
|
59
|
-
result.recoveryParam = 1 - result.v % 2;
|
|
66
|
+
result.recoveryParam = 1 - (result.v % 2);
|
|
60
67
|
// Compute _vs from recoveryParam and s
|
|
61
68
|
if (result.recoveryParam) {
|
|
62
69
|
bytes[32] |= 0x80;
|
|
63
70
|
}
|
|
64
|
-
result._vs = hexlify(bytes.slice(32, 64));
|
|
65
|
-
}
|
|
71
|
+
result._vs = (0, bytes_1.hexlify)(bytes.slice(32, 64));
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
66
74
|
result.r = signature.r;
|
|
67
75
|
result.s = signature.s;
|
|
68
76
|
result.v = signature.v;
|
|
@@ -71,75 +79,85 @@ import { arrayify, hexlify, hexZeroPad, isBytesLike, isHexString, zeroPad } from
|
|
|
71
79
|
// If the _vs is available, use it to populate missing s, v and recoveryParam
|
|
72
80
|
// and verify non-missing s, v and recoveryParam
|
|
73
81
|
if (result._vs != null) {
|
|
74
|
-
|
|
75
|
-
result._vs = hexlify(vs_1);
|
|
82
|
+
const vs_1 = (0, bytes_1.zeroPad)((0, bytes_1.arrayify)(result._vs), 32);
|
|
83
|
+
result._vs = (0, bytes_1.hexlify)(vs_1);
|
|
76
84
|
// Set or check the recid
|
|
77
|
-
|
|
85
|
+
const recoveryParam = vs_1[0] >= 128 ? 1 : 0;
|
|
78
86
|
if (result.recoveryParam == null) {
|
|
79
87
|
result.recoveryParam = recoveryParam;
|
|
80
|
-
}
|
|
81
|
-
|
|
88
|
+
}
|
|
89
|
+
else if (result.recoveryParam !== recoveryParam) {
|
|
90
|
+
logger_1.logger.throwArgumentError('signature recoveryParam mismatch _vs', 'signature', signature);
|
|
82
91
|
}
|
|
83
92
|
// Set or check the s
|
|
84
93
|
vs_1[0] &= 0x7f;
|
|
85
|
-
|
|
94
|
+
const s = (0, bytes_1.hexlify)(vs_1);
|
|
86
95
|
if (result.s == null) {
|
|
87
96
|
result.s = s;
|
|
88
|
-
}
|
|
89
|
-
|
|
97
|
+
}
|
|
98
|
+
else if (result.s !== s) {
|
|
99
|
+
logger_1.logger.throwArgumentError('signature v mismatch _vs', 'signature', signature);
|
|
90
100
|
}
|
|
91
101
|
}
|
|
92
102
|
// Use recid and v to populate each other
|
|
93
103
|
if (result.recoveryParam == null) {
|
|
94
104
|
if (result.v == null) {
|
|
95
|
-
logger.throwArgumentError(
|
|
96
|
-
}
|
|
105
|
+
logger_1.logger.throwArgumentError('signature missing v and recoveryParam', 'signature', signature);
|
|
106
|
+
}
|
|
107
|
+
else if (result.v === 0 || result.v === 1) {
|
|
97
108
|
result.recoveryParam = result.v;
|
|
98
|
-
} else {
|
|
99
|
-
result.recoveryParam = 1 - result.v % 2;
|
|
100
109
|
}
|
|
101
|
-
|
|
110
|
+
else {
|
|
111
|
+
result.recoveryParam = 1 - (result.v % 2);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
102
115
|
if (result.v == null) {
|
|
103
116
|
result.v = 27 + result.recoveryParam;
|
|
104
|
-
}
|
|
105
|
-
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
const recId = result.v === 0 || result.v === 1 ? result.v : 1 - (result.v % 2);
|
|
106
120
|
if (result.recoveryParam !== recId) {
|
|
107
|
-
logger.throwArgumentError(
|
|
121
|
+
logger_1.logger.throwArgumentError('signature recoveryParam mismatch v', 'signature', signature);
|
|
108
122
|
}
|
|
109
123
|
}
|
|
110
124
|
}
|
|
111
|
-
if (result.r == null || !isHexString(result.r)) {
|
|
112
|
-
logger.throwArgumentError(
|
|
113
|
-
} else {
|
|
114
|
-
result.r = hexZeroPad(result.r, 32);
|
|
125
|
+
if (result.r == null || !(0, bytes_1.isHexString)(result.r)) {
|
|
126
|
+
logger_1.logger.throwArgumentError('signature missing or invalid r', 'signature', signature);
|
|
115
127
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
} else {
|
|
119
|
-
result.s = hexZeroPad(result.s, 32);
|
|
128
|
+
else {
|
|
129
|
+
result.r = (0, bytes_1.hexZeroPad)(result.r, 32);
|
|
120
130
|
}
|
|
121
|
-
|
|
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);
|
|
122
138
|
if (vs[0] >= 128) {
|
|
123
|
-
logger.throwArgumentError(
|
|
139
|
+
logger_1.logger.throwArgumentError('signature s out of range', 'signature', signature);
|
|
124
140
|
}
|
|
125
141
|
if (result.recoveryParam) {
|
|
126
142
|
vs[0] |= 0x80;
|
|
127
143
|
}
|
|
128
|
-
|
|
144
|
+
const _vs = (0, bytes_1.hexlify)(vs);
|
|
129
145
|
if (result._vs) {
|
|
130
|
-
if (!isHexString(result._vs)) {
|
|
131
|
-
logger.throwArgumentError(
|
|
146
|
+
if (!(0, bytes_1.isHexString)(result._vs)) {
|
|
147
|
+
logger_1.logger.throwArgumentError('signature invalid _vs', 'signature', signature);
|
|
132
148
|
}
|
|
133
|
-
result._vs = hexZeroPad(result._vs, 32);
|
|
149
|
+
result._vs = (0, bytes_1.hexZeroPad)(result._vs, 32);
|
|
134
150
|
}
|
|
135
151
|
// Set or check the _vs
|
|
136
152
|
if (result._vs == null) {
|
|
137
153
|
result._vs = _vs;
|
|
138
|
-
}
|
|
139
|
-
|
|
154
|
+
}
|
|
155
|
+
else if (result._vs !== _vs) {
|
|
156
|
+
logger_1.logger.throwArgumentError('signature _vs mismatch v and s', 'signature', signature);
|
|
140
157
|
}
|
|
141
158
|
}
|
|
142
159
|
result.yParityAndS = result._vs;
|
|
143
160
|
result.compact = result.r + result.yParityAndS.substring(2);
|
|
144
161
|
return result;
|
|
145
162
|
}
|
|
163
|
+
exports.splitSignature = splitSignature;
|