essential-eth 0.6.1 → 0.7.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.
Files changed (112) hide show
  1. package/dist/cjs/classes/Contract.js +310 -71
  2. package/dist/cjs/classes/test/Contract/crv-abi.js +252 -256
  3. package/dist/cjs/classes/test/Contract/crv.test.js +690 -0
  4. package/dist/cjs/classes/test/Contract/ens-abi.js +497 -212
  5. package/dist/cjs/classes/test/Contract/ens.test.js +217 -0
  6. package/dist/cjs/classes/test/Contract/fei-abi.js +605 -284
  7. package/dist/cjs/classes/test/Contract/fei.test.js +224 -0
  8. package/dist/cjs/classes/test/Contract/foo-abi.js +44 -21
  9. package/dist/cjs/classes/test/Contract/foo.test.js +33 -0
  10. package/dist/cjs/classes/test/Contract/uni.test.js +387 -0
  11. package/dist/cjs/classes/test/Contract/uniswap-abi.js +64 -68
  12. package/dist/cjs/classes/utils/clean-block.d.ts +1 -2
  13. package/dist/cjs/classes/utils/clean-block.js +52 -30
  14. package/dist/cjs/classes/utils/clean-log.js +42 -20
  15. package/dist/cjs/classes/utils/clean-transaction-receipt.js +51 -29
  16. package/dist/cjs/classes/utils/clean-transaction.js +52 -29
  17. package/dist/cjs/classes/utils/encode-decode-transaction.d.ts +1 -1
  18. package/dist/cjs/classes/utils/encode-decode-transaction.js +163 -83
  19. package/dist/cjs/classes/utils/fetchers.js +169 -42
  20. package/dist/cjs/classes/utils/hex-to-decimal.js +1 -6
  21. package/dist/cjs/classes/utils/prepare-transaction.js +59 -36
  22. package/dist/cjs/index.js +25 -54
  23. package/dist/cjs/index.umd.js +1 -1
  24. package/dist/cjs/index.umd.js.map +1 -1
  25. package/dist/cjs/logger/logger.js +79 -23
  26. package/dist/cjs/logger/package-version.d.ts +1 -1
  27. package/dist/cjs/logger/package-version.js +1 -4
  28. package/dist/cjs/providers/BaseProvider.js +824 -475
  29. package/dist/cjs/providers/FallthroughProvider.js +118 -37
  30. package/dist/cjs/providers/JsonRpcProvider.js +93 -28
  31. package/dist/cjs/providers/test/fallthrough-provider/get-gas-price.test.js +228 -0
  32. package/dist/cjs/providers/test/get-transaction-count.test.js +276 -0
  33. package/dist/cjs/providers/test/json-rpc-provider/call.test.js +436 -0
  34. package/dist/cjs/providers/test/json-rpc-provider/estimate-gas.test.js +288 -0
  35. package/dist/cjs/providers/test/json-rpc-provider/get-balance.test.js +261 -0
  36. package/dist/cjs/providers/test/json-rpc-provider/get-block-number.test.js +230 -0
  37. package/dist/cjs/providers/test/json-rpc-provider/get-block.test.js +501 -0
  38. package/dist/cjs/providers/test/json-rpc-provider/get-code.test.js +311 -0
  39. package/dist/cjs/providers/test/json-rpc-provider/get-gas-price.test.js +202 -0
  40. package/dist/cjs/providers/test/json-rpc-provider/get-logs.test.js +361 -0
  41. package/dist/cjs/providers/test/json-rpc-provider/get-network.test.js +274 -0
  42. package/dist/cjs/providers/test/json-rpc-provider/get-transaction-receipt.test.js +301 -0
  43. package/dist/cjs/providers/test/json-rpc-provider/get-transaction.test.js +307 -0
  44. package/dist/cjs/providers/test/rpc-urls.js +9 -12
  45. package/dist/cjs/providers/utils/chains-info.js +1 -3
  46. package/dist/cjs/shared/tiny-big/helpers.js +93 -42
  47. package/dist/cjs/shared/tiny-big/helpers.test.js +29 -0
  48. package/dist/cjs/shared/tiny-big/tiny-big.js +161 -72
  49. package/dist/cjs/shared/tiny-big/tiny-big.test.js +34 -0
  50. package/dist/cjs/shared/validate-type.js +7 -7
  51. package/dist/cjs/types/Block.types.js +1 -2
  52. package/dist/cjs/types/Contract.types.js +1 -2
  53. package/dist/cjs/types/Filter.types.js +1 -2
  54. package/dist/cjs/types/Network.types.js +3 -2
  55. package/dist/cjs/types/Transaction.types.js +1 -2
  56. package/dist/cjs/utils/bytes.js +286 -318
  57. package/dist/cjs/utils/compute-address.js +8 -14
  58. package/dist/cjs/utils/compute-public-key.js +5 -10
  59. package/dist/cjs/utils/ether-to-gwei.js +10 -11
  60. package/dist/cjs/utils/ether-to-wei.js +10 -11
  61. package/dist/cjs/utils/gwei-to-ether.js +10 -11
  62. package/dist/cjs/utils/hash-message.d.ts +1 -1
  63. package/dist/cjs/utils/hash-message.js +11 -14
  64. package/dist/cjs/utils/is-address.js +8 -12
  65. package/dist/cjs/utils/keccak256.js +8 -14
  66. package/dist/cjs/utils/solidity-keccak256.js +49 -60
  67. package/dist/cjs/utils/split-signature.js +55 -73
  68. package/dist/cjs/utils/tests/bytes/arrayify.test.js +40 -0
  69. package/dist/cjs/utils/tests/bytes/concat.test.js +15 -0
  70. package/dist/cjs/utils/tests/bytes/hex-concat.test.js +63 -0
  71. package/dist/cjs/utils/tests/bytes/hex-data-length.test.js +49 -0
  72. package/dist/cjs/utils/tests/bytes/hex-data-slice.test.js +52 -0
  73. package/dist/cjs/utils/tests/bytes/hex-strip-zeros.test.js +58 -0
  74. package/dist/cjs/utils/tests/bytes/hex-value.test.js +85 -0
  75. package/dist/cjs/utils/tests/bytes/hex-zero-pad.test.js +62 -0
  76. package/dist/cjs/utils/tests/bytes/hexlify.test.js +62 -0
  77. package/dist/cjs/utils/tests/bytes/is-bytes-like.test.js +69 -0
  78. package/dist/cjs/utils/tests/bytes/is-bytes.test.js +33 -0
  79. package/dist/cjs/utils/tests/bytes/is-hex-string.test.js +88 -0
  80. package/dist/cjs/utils/tests/bytes/strip-zeros.test.js +57 -0
  81. package/dist/cjs/utils/tests/bytes/zero-pad.test.js +80 -0
  82. package/dist/cjs/utils/tests/compute-address.test.js +27 -0
  83. package/dist/cjs/utils/tests/compute-public-key.test.js +15 -0
  84. package/dist/cjs/utils/tests/ether-to-gwei.test.js +26 -0
  85. package/dist/cjs/utils/tests/ether-to-wei.test.js +44 -0
  86. package/dist/cjs/utils/tests/gwei-to-ether.test.js +28 -0
  87. package/dist/cjs/utils/tests/hash-message.test.js +21 -0
  88. package/dist/cjs/utils/tests/is-address.test.js +55 -0
  89. package/dist/cjs/utils/tests/keccak256.test.js +97 -0
  90. package/dist/cjs/utils/tests/solidity-keccak256.test.js +310 -0
  91. package/dist/cjs/utils/tests/split-signature.test.js +25 -0
  92. package/dist/cjs/utils/tests/to-checksum-address.test.js +42 -0
  93. package/dist/cjs/utils/tests/to-utf8-bytes.test.js +14 -0
  94. package/dist/cjs/utils/tests/wei-to-ether.test.js +51 -0
  95. package/dist/cjs/utils/to-checksum-address.js +15 -20
  96. package/dist/cjs/utils/to-utf8-bytes.js +1 -6
  97. package/dist/cjs/utils/wei-to-ether.js +13 -15
  98. package/dist/esm/classes/Contract.js +3 -7
  99. package/dist/esm/classes/utils/clean-block.d.ts +1 -2
  100. package/dist/esm/classes/utils/clean-block.js +1 -1
  101. package/dist/esm/classes/utils/clean-transaction-receipt.js +2 -1
  102. package/dist/esm/classes/utils/clean-transaction.js +2 -1
  103. package/dist/esm/classes/utils/encode-decode-transaction.d.ts +1 -1
  104. package/dist/esm/classes/utils/encode-decode-transaction.js +37 -2
  105. package/dist/esm/logger/package-version.d.ts +1 -1
  106. package/dist/esm/logger/package-version.js +1 -1
  107. package/dist/esm/utils/compute-address.js +2 -1
  108. package/dist/esm/utils/hash-message.d.ts +1 -1
  109. package/dist/esm/utils/hash-message.js +3 -1
  110. package/dist/esm/utils/is-address.js +1 -1
  111. package/package.json +8 -6
  112. package/readme.md +34 -3
@@ -1,9 +1,7 @@
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");
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('0x04') &&
27
- !key.startsWith('0x03') &&
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 (0, __1.toChecksumAddress)((0, bytes_1.hexDataSlice)((0, keccak256_1.keccak256)((0, bytes_1.hexDataSlice)(key, 1)), 12));
26
+ return toChecksumAddress(hexDataSlice(keccak256(hexDataSlice(key, 1)), 12));
32
27
  }
33
- exports.computeAddress = computeAddress;
@@ -1,8 +1,5 @@
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");
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
- function computePublicKey(privKey) {
23
- privKey = (0, bytes_1.hexlify)(privKey).slice(2);
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
- "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");
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
- 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);
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
- "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");
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
- 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);
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
- "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");
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
- 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);
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 '../index';
1
+ import type { Bytes } from './bytes';
2
2
  export declare function hashMessage(message: Bytes | string): string;
@@ -1,8 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hashMessage = void 0;
4
- const index_1 = require("../index");
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
- function hashMessage(message) {
19
- if (typeof message === 'string') {
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 (0, index_1.keccak256)((0, index_1.concat)([
23
- (0, index_1.toUtf8Bytes)(messagePrefix),
24
- (0, index_1.toUtf8Bytes)(String(message.length)),
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
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
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
- function isAddress(address) {
30
- (0, validate_type_1.validateType)(address, ['string']);
25
+ */ export function isAddress(address) {
26
+ validateType(address, [
27
+ "string"
28
+ ]);
31
29
  try {
32
- (0, __1.toChecksumAddress)(address);
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
- "use strict";
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
- function keccak256(data) {
20
- let bufferableData;
21
- if (typeof data === 'string') {
22
- bufferableData = Buffer.from(data.replace(/^0x/, ''), 'hex');
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
- const keccak = new sha3_1.Keccak(256);
28
- const addressHash = '0x' + keccak.update(bufferableData).digest('hex');
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
- "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]*)\\]$');
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
- function _pack(type, value, isArray) {
24
- switch (type) {
25
- case 'address':
19
+ */ function _pack(type, value, isArray) {
20
+ switch(type){
21
+ case "address":
26
22
  if (isArray) {
27
- return (0, bytes_1.zeroPad)(value, 32);
23
+ return zeroPad(value, 32);
28
24
  }
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';
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 (0, bytes_1.zeroPad)(value, 32);
33
+ return zeroPad(value, 32);
38
34
  }
39
- return (0, bytes_1.arrayify)(value);
35
+ return arrayify(value);
40
36
  }
41
- let match = type.match(regexNumber);
37
+ var match = type.match(regexNumber);
42
38
  if (match) {
43
39
  //let signed = (match[1] === "int")
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);
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 = (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);
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
- 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);
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 ((0, bytes_1.arrayify)(value).byteLength !== size) {
65
- logger_1.logger.throwArgumentError(`invalid value for ${type}`, 'value', value);
57
+ if (arrayify(value).byteLength !== size1) {
58
+ logger.throwArgumentError("invalid value for ".concat(type), "value", value);
66
59
  }
67
60
  if (isArray) {
68
- return (0, bytes_1.arrayify)((value + encode_decode_transaction_1.hexFalse).substring(0, 66));
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
- const baseType = match[1];
75
- const count = parseInt(match[2] || String(value.length));
67
+ var baseType = match[1];
68
+ var count = parseInt(match[2] || String(value.length));
76
69
  if (count != value.length) {
77
- logger_1.logger.throwArgumentError(`invalid array length for ${type}`, 'value', value);
70
+ logger.throwArgumentError("invalid array length for ".concat(type), "value", value);
78
71
  }
79
- const result = [];
80
- value.forEach(function (value) {
72
+ var result = [];
73
+ value.forEach(function(value) {
81
74
  result.push(_pack(baseType, value, true));
82
75
  });
83
- return (0, bytes_1.concat)(result);
76
+ return concat(result);
84
77
  }
85
- return logger_1.logger.throwArgumentError('invalid type', 'type', type);
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
- logger_1.logger.throwArgumentError('wrong number of values; expected ${ types.length }', 'values', values);
95
+ logger.throwArgumentError("wrong number of values; expected ${ types.length }", "values", values);
104
96
  }
105
- const tight = [];
106
- types.forEach(function (type, index) {
97
+ var tight = [];
98
+ types.forEach(function(type, index) {
107
99
  tight.push(_pack(type, values[index]));
108
100
  });
109
- return (0, bytes_1.hexlify)((0, bytes_1.concat)(tight));
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
- function solidityKeccak256(types, values) {
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
- "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");
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
- function splitSignature(signature) {
29
- const result = {
30
- r: '0x',
31
- s: '0x',
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: '0x',
36
- compact: '0x',
31
+ yParityAndS: "0x",
32
+ compact: "0x"
37
33
  };
38
- if ((0, bytes_1.isBytesLike)(signature)) {
39
- const bytes = (0, bytes_1.arrayify)(signature);
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 = (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));
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
- else {
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
- else {
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 - (result.v % 2);
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 = (0, bytes_1.hexlify)(bytes.slice(32, 64));
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
- const vs_1 = (0, bytes_1.zeroPad)((0, bytes_1.arrayify)(result._vs), 32);
83
- result._vs = (0, bytes_1.hexlify)(vs_1);
74
+ var vs_1 = zeroPad(arrayify(result._vs), 32);
75
+ result._vs = hexlify(vs_1);
84
76
  // Set or check the recid
85
- const recoveryParam = vs_1[0] >= 128 ? 1 : 0;
77
+ var recoveryParam = vs_1[0] >= 128 ? 1 : 0;
86
78
  if (result.recoveryParam == null) {
87
79
  result.recoveryParam = recoveryParam;
88
- }
89
- else if (result.recoveryParam !== recoveryParam) {
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
- const s = (0, bytes_1.hexlify)(vs_1);
85
+ var s = hexlify(vs_1);
95
86
  if (result.s == null) {
96
87
  result.s = s;
97
- }
98
- else if (result.s !== s) {
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
- logger_1.logger.throwArgumentError('signature missing v and recoveryParam', 'signature', signature);
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
- else {
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
- else {
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
- logger_1.logger.throwArgumentError('signature recoveryParam mismatch v', 'signature', signature);
107
+ logger.throwArgumentError("signature recoveryParam mismatch v", "signature", signature);
122
108
  }
123
109
  }
124
110
  }
125
- if (result.r == null || !(0, bytes_1.isHexString)(result.r)) {
126
- logger_1.logger.throwArgumentError('signature missing or invalid r', 'signature', signature);
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
- else {
129
- result.r = (0, bytes_1.hexZeroPad)(result.r, 32);
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
- 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);
121
+ var vs = arrayify(result.s);
138
122
  if (vs[0] >= 128) {
139
- logger_1.logger.throwArgumentError('signature s out of range', 'signature', signature);
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
- const _vs = (0, bytes_1.hexlify)(vs);
128
+ var _vs = hexlify(vs);
145
129
  if (result._vs) {
146
- if (!(0, bytes_1.isHexString)(result._vs)) {
147
- logger_1.logger.throwArgumentError('signature invalid _vs', 'signature', signature);
130
+ if (!isHexString(result._vs)) {
131
+ logger.throwArgumentError("signature invalid _vs", "signature", signature);
148
132
  }
149
- result._vs = (0, bytes_1.hexZeroPad)(result._vs, 32);
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
- else if (result._vs !== _vs) {
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;