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