essential-eth 0.8.0 → 0.9.1-next.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 +38 -34
  2. package/dist/cjs/classes/test/Contract/crv.test.js +146 -339
  3. package/dist/cjs/classes/test/Contract/ens-abi.d.ts +1 -1
  4. package/dist/cjs/classes/test/Contract/ens.test.js +9 -66
  5. package/dist/cjs/classes/test/Contract/fei.test.js +11 -11
  6. package/dist/cjs/classes/test/Contract/foo-abi.d.ts +1 -1
  7. package/dist/cjs/classes/test/Contract/uni.test.js +66 -164
  8. package/dist/cjs/classes/utils/clean-block.js +4 -4
  9. package/dist/cjs/classes/utils/clean-log.js +4 -4
  10. package/dist/cjs/classes/utils/clean-transaction-receipt.js +4 -4
  11. package/dist/cjs/classes/utils/clean-transaction.js +4 -4
  12. package/dist/cjs/classes/utils/encode-decode-transaction.js +10 -10
  13. package/dist/cjs/classes/utils/fetchers.d.ts +8 -2
  14. package/dist/cjs/classes/utils/fetchers.js +20 -12
  15. package/dist/cjs/classes/utils/prepare-transaction.js +4 -4
  16. package/dist/cjs/index.d.ts +21 -21
  17. package/dist/cjs/index.js +21 -21
  18. package/dist/cjs/index.umd.js +1 -1
  19. package/dist/cjs/index.umd.js.map +1 -1
  20. package/dist/cjs/logger/logger.js +79 -41
  21. package/dist/cjs/logger/package-version.d.ts +1 -1
  22. package/dist/cjs/logger/package-version.js +1 -1
  23. package/dist/cjs/providers/AlchemyProvider.d.ts +4 -0
  24. package/dist/cjs/providers/AlchemyProvider.js +84 -0
  25. package/dist/cjs/providers/BaseProvider.js +471 -404
  26. package/dist/cjs/providers/FallthroughProvider.js +74 -38
  27. package/dist/cjs/providers/JsonRpcProvider.js +52 -31
  28. package/dist/cjs/providers/test/fallthrough-provider/get-gas-price.test.js +9 -9
  29. package/dist/cjs/providers/test/get-transaction-count.test.js +54 -91
  30. package/dist/cjs/providers/test/json-rpc-provider/call.test.js +87 -148
  31. package/dist/cjs/providers/test/json-rpc-provider/estimate-gas.test.js +45 -116
  32. package/dist/cjs/providers/test/json-rpc-provider/get-balance.test.js +36 -74
  33. package/dist/cjs/providers/test/json-rpc-provider/get-block-number.test.js +27 -94
  34. package/dist/cjs/providers/test/json-rpc-provider/get-block.test.js +191 -278
  35. package/dist/cjs/providers/test/json-rpc-provider/get-code.test.js +106 -135
  36. package/dist/cjs/providers/test/json-rpc-provider/get-fee-data.test.js +48 -73
  37. package/dist/cjs/providers/test/json-rpc-provider/get-gas-price.test.js +29 -64
  38. package/dist/cjs/providers/test/json-rpc-provider/get-logs/get-logs.test.js +219 -0
  39. package/dist/cjs/providers/test/json-rpc-provider/get-logs/mocks.d.ts +14 -0
  40. package/dist/cjs/providers/test/json-rpc-provider/get-logs/mocks.js +149 -0
  41. package/dist/cjs/providers/test/json-rpc-provider/get-network.test.js +37 -79
  42. package/dist/cjs/providers/test/json-rpc-provider/get-transaction-receipt.test.js +136 -157
  43. package/dist/cjs/providers/test/json-rpc-provider/get-transaction.test.js +121 -162
  44. package/dist/cjs/providers/test/mock-of.d.ts +2 -0
  45. package/dist/cjs/providers/test/mock-of.js +9 -0
  46. package/dist/cjs/providers/test/rpc-urls.d.ts +1 -0
  47. package/dist/cjs/providers/test/rpc-urls.js +12 -6
  48. package/dist/cjs/providers/test/test-alchemy-provider.test.js +151 -0
  49. package/dist/cjs/providers/utils/chains-info.d.ts +5 -448
  50. package/dist/cjs/providers/utils/chains-info.js +13 -1344
  51. package/dist/cjs/shared/tiny-big/helpers.js +18 -18
  52. package/dist/cjs/shared/tiny-big/tiny-big.js +96 -56
  53. package/dist/cjs/shared/tiny-big/tiny-big.test.js +2 -2
  54. package/dist/cjs/shared/validate-type.d.ts +1 -1
  55. package/dist/cjs/shared/validate-type.js +4 -4
  56. package/dist/cjs/types/Block.types.d.ts +3 -3
  57. package/dist/cjs/types/Contract.types.d.ts +4 -4
  58. package/dist/cjs/types/Transaction.types.d.ts +5 -5
  59. package/dist/cjs/utils/bytes.d.ts +4 -4
  60. package/dist/cjs/utils/bytes.js +3 -3
  61. package/dist/cjs/utils/tests/bytes/arrayify.test.js +48 -24
  62. package/dist/cjs/utils/tests/bytes/concat.test.js +5 -3
  63. package/dist/cjs/utils/tests/bytes/hex-concat.test.js +15 -13
  64. package/dist/cjs/utils/tests/bytes/hex-data-length.test.js +49 -32
  65. package/dist/cjs/utils/tests/bytes/hex-data-slice.test.js +15 -16
  66. package/dist/cjs/utils/tests/bytes/hex-strip-zeros.test.js +57 -40
  67. package/dist/cjs/utils/tests/bytes/hex-value.test.js +118 -62
  68. package/dist/cjs/utils/tests/bytes/hex-zero-pad.test.js +71 -33
  69. package/dist/cjs/utils/tests/bytes/hexlify.test.js +45 -29
  70. package/dist/cjs/utils/tests/bytes/is-bytes-like.test.js +10 -11
  71. package/dist/cjs/utils/tests/bytes/is-bytes.test.js +70 -27
  72. package/dist/cjs/utils/tests/bytes/is-hex-string.test.js +37 -28
  73. package/dist/cjs/utils/tests/bytes/strip-zeros.test.js +94 -45
  74. package/dist/cjs/utils/tests/bytes/zero-pad.test.js +98 -34
  75. package/dist/cjs/utils/tests/compute-address.test.js +42 -20
  76. package/dist/cjs/utils/tests/compute-public-key.test.js +20 -9
  77. package/dist/cjs/utils/tests/ether-to-wei.test.js +5 -13
  78. package/dist/cjs/utils/tests/hash-message.test.js +26 -15
  79. package/dist/cjs/utils/tests/is-address.test.js +2 -9
  80. package/dist/cjs/utils/tests/keccak256.test.js +36 -12
  81. package/dist/cjs/utils/tests/solidity-keccak256.test.js +43 -42
  82. package/dist/cjs/utils/tests/split-signature.test.js +29 -8
  83. package/dist/cjs/utils/tests/to-checksum-address.test.js +1 -4
  84. package/dist/cjs/utils/tests/to-utf8-bytes.test.js +28 -8
  85. package/dist/cjs/utils/tests/wei-to-ether.test.js +10 -20
  86. package/dist/esm/classes/test/Contract/ens-abi.d.ts +1 -1
  87. package/dist/esm/classes/test/Contract/foo-abi.d.ts +1 -1
  88. package/dist/esm/classes/utils/fetchers.d.ts +8 -2
  89. package/dist/esm/classes/utils/fetchers.js +6 -3
  90. package/dist/esm/index.d.ts +21 -21
  91. package/dist/esm/index.js +16 -16
  92. package/dist/esm/logger/package-version.d.ts +1 -1
  93. package/dist/esm/logger/package-version.js +1 -1
  94. package/dist/esm/providers/AlchemyProvider.d.ts +4 -0
  95. package/dist/esm/providers/AlchemyProvider.js +7 -0
  96. package/dist/esm/providers/FallthroughProvider.js +15 -7
  97. package/dist/esm/providers/test/json-rpc-provider/get-logs/mocks.d.ts +14 -0
  98. package/dist/esm/providers/test/json-rpc-provider/get-logs/mocks.js +142 -0
  99. package/dist/esm/providers/test/mock-of.d.ts +2 -0
  100. package/dist/esm/providers/test/mock-of.js +1 -0
  101. package/dist/esm/providers/test/rpc-urls.d.ts +1 -0
  102. package/dist/esm/providers/test/rpc-urls.js +14 -6
  103. package/dist/esm/providers/utils/chains-info.d.ts +5 -448
  104. package/dist/esm/providers/utils/chains-info.js +13 -1344
  105. package/dist/esm/shared/validate-type.d.ts +1 -1
  106. package/dist/esm/types/Block.types.d.ts +3 -3
  107. package/dist/esm/types/Contract.types.d.ts +4 -4
  108. package/dist/esm/types/Transaction.types.d.ts +5 -5
  109. package/dist/esm/utils/bytes.d.ts +4 -4
  110. package/package.json +23 -51
  111. package/readme.md +16 -38
  112. package/dist/cjs/providers/test/json-rpc-provider/get-logs.test.js +0 -361
@@ -1,27 +1,49 @@
1
- import { utils } from "ethers";
2
1
  import { computeAddress } from "../../index";
3
- function testComputeAddress(keys) {
4
- keys.forEach(function(key) {
5
- expect(computeAddress(key)).toBe(utils.computeAddress(key));
6
- });
7
- }
8
2
  describe("computeAddress", function() {
9
- it("should match ethers.js - public key", function() {
10
- var publicKeys = [
11
- "0x04aaa2abcf8d119ad68b2c190abf34355a0029197911e2446007d5b44e6fddfd54352326fedac51eca491d59937c592ecffff65c6941037babbe26edfdbb32a688",
12
- "0x04e8aa3d196e3a785fb5b431265074c01f571a79231e0cc0fc28e67d9c648471aca8229cafcc6cd806cd1a679f538326577bf9485c68f7a1c90b5116b669f30473",
13
- "0x04110dfa471c3f04a6c9dfd857705eb080542c9672cf0f30d95f5fca382181293d6e91320916dd649d03c76818af8e7ee173781888e42e2f00bda9a8f797e0fd61",
14
- "0x04593bea29e692123fda1b6f8280b8414524c7838fd448abe6dd1e072bee5e2e9c66e19976b9310ce514d8612c5736201ddc3bb966412076cd4b24e7f649e779b3"
3
+ it("should compute correct address - public key", function() {
4
+ var testCases = [
5
+ {
6
+ key: "0x04aaa2abcf8d119ad68b2c190abf34355a0029197911e2446007d5b44e6fddfd54352326fedac51eca491d59937c592ecffff65c6941037babbe26edfdbb32a688",
7
+ expected: "0xeC46DEeFE5e342801A5ab221471B0f934bd04404"
8
+ },
9
+ {
10
+ key: "0x04e8aa3d196e3a785fb5b431265074c01f571a79231e0cc0fc28e67d9c648471aca8229cafcc6cd806cd1a679f538326577bf9485c68f7a1c90b5116b669f30473",
11
+ expected: "0xb17351DB661e7D40723B1ADA46B43586F2358b7A"
12
+ },
13
+ {
14
+ key: "0x04110dfa471c3f04a6c9dfd857705eb080542c9672cf0f30d95f5fca382181293d6e91320916dd649d03c76818af8e7ee173781888e42e2f00bda9a8f797e0fd61",
15
+ expected: "0x93a76f1B186A97A3EBd0E1f94Ec52a82FfFD646B"
16
+ },
17
+ {
18
+ key: "0x04593bea29e692123fda1b6f8280b8414524c7838fd448abe6dd1e072bee5e2e9c66e19976b9310ce514d8612c5736201ddc3bb966412076cd4b24e7f649e779b3",
19
+ expected: "0x9eb71738aaf20F659156535b13df2b809FC8aB26"
20
+ }
15
21
  ];
16
- testComputeAddress(publicKeys);
22
+ testCases.forEach(function(testCase) {
23
+ expect(computeAddress(testCase.key)).toBe(testCase.expected);
24
+ });
17
25
  });
18
- it("should match ethers.js - private key", function() {
19
- var privateKeys = [
20
- "0x8da4ef21b864d2cc526dbdb2a120bd2874c36c9d0a1fb7f8c63d7f7a8b41de8f",
21
- "0x42e12f76412f53de9d60df199a368699b6ec15d3798efb0b2a45b8c1b4f902a6",
22
- "0x262f8fffb353d3e11be770dd4208dcab1fa5c205d574a78088829f45b1ac2487",
23
- "0x1bcfb8b7a46e2f886ef61f8010426f70ce3c7fc1362973aa26d30b8f77711d93"
26
+ it("should compute correct address - private key", function() {
27
+ var testCases = [
28
+ {
29
+ key: "0x8da4ef21b864d2cc526dbdb2a120bd2874c36c9d0a1fb7f8c63d7f7a8b41de8f",
30
+ expected: "0x63FaC9201494f0bd17B9892B9fae4d52fe3BD377"
31
+ },
32
+ {
33
+ key: "0x42e12f76412f53de9d60df199a368699b6ec15d3798efb0b2a45b8c1b4f902a6",
34
+ expected: "0xE21C7F8e28058931C5aa0e36C42d0C40Daf7A698"
35
+ },
36
+ {
37
+ key: "0x262f8fffb353d3e11be770dd4208dcab1fa5c205d574a78088829f45b1ac2487",
38
+ expected: "0xE17826AC425D19b0531F4B99a243b9Cfb42219dd"
39
+ },
40
+ {
41
+ key: "0x1bcfb8b7a46e2f886ef61f8010426f70ce3c7fc1362973aa26d30b8f77711d93",
42
+ expected: "0xb17351DB661e7D40723B1ADA46B43586F2358b7A"
43
+ }
24
44
  ];
25
- testComputeAddress(privateKeys);
45
+ testCases.forEach(function(testCase) {
46
+ expect(computeAddress(testCase.key)).toBe(testCase.expected);
47
+ });
26
48
  });
27
49
  });
@@ -1,15 +1,26 @@
1
- import { utils } from "ethers";
2
1
  import { computePublicKey } from "../../index";
3
2
  describe("computePublicKey", function() {
4
- it("should match ethers.js", function() {
5
- var privateKeys = [
6
- "0x8da4ef21b864d2cc526dbdb2a120bd2874c36c9d0a1fb7f8c63d7f7a8b41de8f",
7
- "0x38a3159d73cefd392d0176c29b3cc60ff43e81813f5ab5782571511df9bb16e2",
8
- "0xb6d36857e1f9b68e413d2496bb588f3650cdcc2398b3941963c44db8108b8671",
9
- "0xf237d9763445d41150f9a199ad93ad478dff29ad8fe6fa00149ed12f40f8eb6f"
3
+ it("should compute correct public key", function() {
4
+ var testCases = [
5
+ {
6
+ privateKey: "0x8da4ef21b864d2cc526dbdb2a120bd2874c36c9d0a1fb7f8c63d7f7a8b41de8f",
7
+ expectedPublicKey: "0x04d11e94912283d217fd98be5ad59c659aede69bbef0e72a2213edf0fbd8de3cc95030d006b137e22b89e738e5565766b83d12c438fe970e3e729532fcfafad2a7"
8
+ },
9
+ {
10
+ privateKey: "0x38a3159d73cefd392d0176c29b3cc60ff43e81813f5ab5782571511df9bb16e2",
11
+ expectedPublicKey: "0x04d8c5ec2308fdec8535411b8f7eb0251b53f53bcdda3f49bc7959a5dc1e12d2fe721bdd212b20fdbfa770c56af2da1bcf3b77dd46d742b65154c80aac7d44adf1"
12
+ },
13
+ {
14
+ privateKey: "0xb6d36857e1f9b68e413d2496bb588f3650cdcc2398b3941963c44db8108b8671",
15
+ expectedPublicKey: "0x04dab3b4d14577ec72a25c5b4dc7b404052263ccde860bff23b8e68efa215de0f119ed4540cd230d5c84d8a13a8c2105aefba78f342a423893489ae69c3c8a8cfb"
16
+ },
17
+ {
18
+ privateKey: "0xf237d9763445d41150f9a199ad93ad478dff29ad8fe6fa00149ed12f40f8eb6f",
19
+ expectedPublicKey: "0x042b9627d5b5e187bcc9e4155c65f986091f76e379a9fe031a7f9797ec74ad70d399e3655e20d3c6b6ca63ef691fe558c1794d78199b697f28697cf44e150dcfb1"
20
+ }
10
21
  ];
11
- privateKeys.forEach(function(key) {
12
- expect(computePublicKey(key)).toBe(utils.computePublicKey(key));
22
+ testCases.forEach(function(testCase) {
23
+ expect(computePublicKey(testCase.privateKey)).toBe(testCase.expectedPublicKey);
13
24
  });
14
25
  });
15
26
  });
@@ -1,8 +1,5 @@
1
1
  import Big from "big.js";
2
- import * as ethers from "ethers";
3
- import web3 from "web3";
4
2
  import { etherToWei, tinyBig } from "../../index";
5
- import { scientificStrToDecimalStr } from "../../shared/tiny-big/helpers";
6
3
  describe("ether-to-wei", function() {
7
4
  it("happy path", function() {
8
5
  expect(etherToWei("100").toString()).toBe("100000000000000000000");
@@ -15,17 +12,12 @@ describe("ether-to-wei", function() {
15
12
  expect(etherToWei(Big(1000)).toString()).toBe("1000000000000000000000");
16
13
  expect(etherToWei(Big("1000.0")).toNumber()).toBe(1000000000000000000000);
17
14
  });
18
- it("matches ethers and web3 toString", function() {
19
- expect(etherToWei("-09999.0").toString()).toStrictEqual(ethers.utils.parseEther("-09999.0").toString());
20
- expect(etherToWei("-09999.0").toString()).toStrictEqual(web3.utils.toWei("-09999.0", "ether"));
15
+ it("matches expected toString", function() {
16
+ expect(etherToWei("-09999.0").toString()).toBe("-9999000000000000000000");
21
17
  });
22
- it("matches ethers and web3 toNumber", function() {
23
- /* easy */ expect(etherToWei("9").toNumber()).toStrictEqual(Number(ethers.utils.parseEther("9")));
24
- // web3 responds with scientific notation
25
- expect(etherToWei("9").toNumber()).toStrictEqual(Number(web3.utils.toWei("9", "ether")));
26
- /* harder */ expect(etherToWei("-0999999.90").toNumber()).toStrictEqual(Number(ethers.utils.parseEther("-0999999.90")));
27
- // web3 responds with scientific notation
28
- expect(etherToWei("-0999999.9").toNumber()).toStrictEqual(Number(scientificStrToDecimalStr(web3.utils.toWei("-0999999.9", "ether"))));
18
+ it("matches expected toNumber", function() {
19
+ /* easy */ expect(etherToWei("9").toNumber()).toBe(9000000000000000000);
20
+ /* harder */ expect(etherToWei("-0999999.90").toNumber()).toStrictEqual(-9.999999e23);
29
21
  });
30
22
  it("should throw for wrong types", function() {
31
23
  expect(function() {
@@ -1,21 +1,32 @@
1
- import { utils } from "ethers";
2
1
  import { hashMessage } from "../../index";
3
2
  describe("utils.hashMessage", function() {
4
- it("should match ethers.js", function() {
5
- var messages = [
6
- "0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb",
7
- "27b1fdb04752bbc536007a920d24acb045561c26" /* leading "0x" is not required */ ,
8
- [
9
- 1,
10
- 2
11
- ],
12
- [
13
- 0x1,
14
- 0x2
15
- ]
3
+ it("should compute correct hash", function() {
4
+ var testCases = [
5
+ {
6
+ message: "0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb",
7
+ expectedHash: "0x053af31bc24e13e344973ab25910ff8da04a8acdd63a04187f84b7a340e9d663"
8
+ },
9
+ {
10
+ message: "27b1fdb04752bbc536007a920d24acb045561c26",
11
+ expectedHash: "0xd8141e0ec15afbf98a6f93d51e1b8bb8d988be77bca76a5692b73493d232f4f1"
12
+ },
13
+ {
14
+ message: [
15
+ 1,
16
+ 2
17
+ ],
18
+ expectedHash: "0xd87309a295607439d67ad5243462242d36775fa665de60f4e26895808e01389b"
19
+ },
20
+ {
21
+ message: [
22
+ 0x1,
23
+ 0x2
24
+ ],
25
+ expectedHash: "0xd87309a295607439d67ad5243462242d36775fa665de60f4e26895808e01389b"
26
+ }
16
27
  ];
17
- messages.forEach(function(message) {
18
- expect(hashMessage(message)).toStrictEqual(utils.hashMessage(message));
28
+ testCases.forEach(function(testCase) {
29
+ expect(hashMessage(testCase.message)).toBe(testCase.expectedHash);
19
30
  });
20
31
  });
21
32
  });
@@ -1,5 +1,3 @@
1
- import { utils } from "ethers";
2
- import web3 from "web3";
3
1
  import { isAddress } from "../../index";
4
2
  describe("is-address", function() {
5
3
  it("should validate real addresses", function() {
@@ -15,8 +13,7 @@ describe("is-address", function() {
15
13
  "27b1fdb04752bbc536007a920d24acb045561c26" /* leading "0x" is not required */
16
14
  ];
17
15
  addresses.forEach(function(address) {
18
- expect(isAddress(address)).toStrictEqual(utils.isAddress(address));
19
- expect(isAddress(address)).toStrictEqual(web3.utils.isAddress(address));
16
+ expect(isAddress(address)).toBe(true);
20
17
  });
21
18
  });
22
19
  it("should return false on invalid addresses", function() {
@@ -31,11 +28,7 @@ describe("is-address", function() {
31
28
  "0x123"
32
29
  ];
33
30
  addresses.forEach(function(address) {
34
- var essentialEthIsAddress = isAddress(address);
35
- var ethersIsAddress = utils.isAddress(address);
36
- var web3IsAddress = web3.utils.isAddress(address);
37
- expect(essentialEthIsAddress).toStrictEqual(ethersIsAddress);
38
- expect(essentialEthIsAddress).toStrictEqual(web3IsAddress);
31
+ expect(isAddress(address)).toBe(false);
39
32
  });
40
33
  });
41
34
  it("invalid type inputs", function() {
@@ -1,24 +1,29 @@
1
- import { utils } from "ethers";
2
1
  import { keccak256 } from "./../keccak256";
3
2
  import { toUtf8Bytes } from "./../to-utf8-bytes";
4
3
  /**
5
4
  *
6
5
  * @param inputs
7
- */ function testKeccak256(inputs) {
8
- inputs.forEach(function(input) {
9
- expect(keccak256(input)).toBe(utils.keccak256(input));
6
+ * @param expected
7
+ */ function testKeccak256(inputs, expected) {
8
+ inputs.forEach(function(input, index) {
9
+ expect(keccak256(input)).toBe(expected[index]);
10
10
  });
11
11
  }
12
12
  describe("keccak256", function() {
13
- it("should match ethers.js hex strings", function() {
13
+ it("should match expected - hex strings", function() {
14
14
  var inputs = [
15
15
  "0x4d7F1790644Af787933c9fF0e2cff9a9B4299Abb",
16
16
  "0xB5503a7db1A9105cd459D99153e69a76a8EF1530",
17
17
  "0xaa0fc255b079e775f9307e5cfec472a555cebc3a"
18
18
  ];
19
- testKeccak256(inputs);
19
+ var expected = [
20
+ "0x72fe4a1287bb827ec8d04e045f7559955a8e694063af513008f111670674178a",
21
+ "0x012d02a94561e140985a0382377e7676eec97a73007e188ffd1d0a0c01b1eb4d",
22
+ "0xfe9ee1df3c10848ed968a46ced4a0bb9674195ece0cfc63959d8058d77700d84"
23
+ ];
24
+ testKeccak256(inputs, expected);
20
25
  });
21
- it("should match ethers.js bytes", function() {
26
+ it("should match expected - bytes", function() {
22
27
  var inputs = [
23
28
  [
24
29
  2,
@@ -38,9 +43,15 @@ describe("keccak256", function() {
38
43
  0x12
39
44
  ]
40
45
  ];
41
- testKeccak256(inputs);
46
+ var expected = [
47
+ "0x324544acf03f9c2ac85ab3a820ab3371bf7965a342bcdd5f74e28eb6d1f60050",
48
+ "0xfe10bfcde301e8b760615ba65ba2a0c7fb72f9bcdea7c45841ef7b355a443e51",
49
+ "0x56570de287d73cd1cb6092bb8fdee6173974955fdef345ae579ee9f475ea7432",
50
+ "0x5fa2358263196dbbf23d1ca7a509451f7a2f64c15837bfbb81298b1e3e24e4fa"
51
+ ];
52
+ testKeccak256(inputs, expected);
42
53
  });
43
- it("should match ethers.js numbers", function() {
54
+ it("should match expected - numbers", function() {
44
55
  var inputs = [
45
56
  23874234,
46
57
  123346,
@@ -48,9 +59,14 @@ describe("keccak256", function() {
48
59
  ].map(function(n) {
49
60
  return toUtf8Bytes(n.toString());
50
61
  });
51
- testKeccak256(inputs);
62
+ var expected = [
63
+ "0x6cc5c464579b7e93f9e3192ecad21e933e5497d24a067546a264874a1cdbe48d",
64
+ "0xf54c8ff9e4afcd296f686a15dda3b8f9f2da621866842b2427ab578e0aaa7344",
65
+ "0xd9ba3a9f9b521946abbae91c3799ac03a3ec95d2a69a5ab5974242d36e3c6f32"
66
+ ];
67
+ testKeccak256(inputs, expected);
52
68
  });
53
- it("should match ethers.js strings", function() {
69
+ it("should match expected - strings", function() {
54
70
  var inputs = [
55
71
  "essential-eth",
56
72
  "firstText",
@@ -59,7 +75,15 @@ describe("keccak256", function() {
59
75
  "2934823",
60
76
  "true"
61
77
  ].map(toUtf8Bytes);
62
- testKeccak256(inputs);
78
+ var expected = [
79
+ "0xd5b027dc2bddae7475604f19ca210363f0a3c63a32d79c2fff540b9c21249f2c",
80
+ "0x3b0c4ce69832f4f4036e87bf56b9062018040b5b0f031062bd9667fb579c844f",
81
+ "0x2f33a7c2165d73854f66613815214ba5812046579723927d001cabe696078ae7",
82
+ "0xf5590342e9e60df9335478edb075a7c323b2e11d690d18d35eaa32f13e48788d",
83
+ "0x0517ce0ae90a6a7f7f4770d867e1fc57e38e7f1d133942fdbcbabe53c98d3761",
84
+ "0x6273151f959616268004b58dbb21e5c851b7b8d04498b4aabee12291d22fc034"
85
+ ];
86
+ testKeccak256(inputs, expected);
63
87
  });
64
88
  // it('should match ethers.js bytes (dynamic size) & BytesLike', () => {
65
89
  // const inputs = [
@@ -1,15 +1,14 @@
1
- import { utils } from "ethers";
2
1
  import { solidityKeccak256 } from "../../index";
3
2
  /**
4
3
  *
5
4
  * @param inputs
6
5
  */ function testSolidityKeccak256(inputs) {
7
6
  inputs.forEach(function(input) {
8
- expect(solidityKeccak256(input.types, input.values)).toBe(utils.solidityKeccak256(input.types, input.values));
7
+ expect(solidityKeccak256(input.types, input.values)).toBe(input.expected);
9
8
  });
10
9
  }
11
10
  describe("solidityKeccak256", function() {
12
- it("should match ethers.js addresses", function() {
11
+ it("should match expected hash - addresses", function() {
13
12
  var inputs = [
14
13
  {
15
14
  types: [
@@ -17,7 +16,8 @@ describe("solidityKeccak256", function() {
17
16
  ],
18
17
  values: [
19
18
  "0x4d7F1790644Af787933c9fF0e2cff9a9B4299Abb"
20
- ]
19
+ ],
20
+ expected: "0x72fe4a1287bb827ec8d04e045f7559955a8e694063af513008f111670674178a"
21
21
  },
22
22
  {
23
23
  types: [
@@ -27,12 +27,13 @@ describe("solidityKeccak256", function() {
27
27
  values: [
28
28
  "0xB5503a7db1A9105cd459D99153e69a76a8EF1530",
29
29
  "0xaa0fc255b079e775f9307e5cfec472a555cebc3a"
30
- ]
30
+ ],
31
+ expected: "0x36020dd625e805ec80eb7c7e36e5b69108500af4bb4913245a3d643d33466581"
31
32
  }
32
33
  ];
33
34
  testSolidityKeccak256(inputs);
34
35
  });
35
- it("should match ethers.js strings", function() {
36
+ it("should match expected hash - strings", function() {
36
37
  var inputs = [
37
38
  {
38
39
  types: [
@@ -40,7 +41,8 @@ describe("solidityKeccak256", function() {
40
41
  ],
41
42
  values: [
42
43
  "essential-eth"
43
- ]
44
+ ],
45
+ expected: "0xd5b027dc2bddae7475604f19ca210363f0a3c63a32d79c2fff540b9c21249f2c"
44
46
  },
45
47
  {
46
48
  types: [
@@ -50,7 +52,8 @@ describe("solidityKeccak256", function() {
50
52
  values: [
51
53
  "firstText",
52
54
  "secondString"
53
- ]
55
+ ],
56
+ expected: "0xf9b3d91668a0f53719a929eb38ac29b07896b3a33ef806cfbe5033bb5ce1e58b"
54
57
  },
55
58
  {
56
59
  types: [
@@ -62,12 +65,13 @@ describe("solidityKeccak256", function() {
62
65
  "example1",
63
66
  "2934823",
64
67
  "true"
65
- ]
68
+ ],
69
+ expected: "0x731e3313bb527075d72c8a724eea170cdc200edf65c958d3014f666faf9a4d41"
66
70
  }
67
71
  ];
68
72
  testSolidityKeccak256(inputs);
69
73
  });
70
- it("should match ethers.js bytes (dynamic size) & BytesLike", function() {
74
+ it("should match expected hash for bytes (dynamic size) & BytesLike", function() {
71
75
  var inputs = [
72
76
  {
73
77
  types: [
@@ -82,7 +86,8 @@ describe("solidityKeccak256", function() {
82
86
  101,
83
87
  116
84
88
  ]
85
- ]
89
+ ],
90
+ expected: "0x65462b0520ef7d3df61b9992ed3bea0c56ead753be7c8b3614e0ce01e4cac41b"
86
91
  },
87
92
  {
88
93
  types: [
@@ -90,7 +95,8 @@ describe("solidityKeccak256", function() {
90
95
  ],
91
96
  values: [
92
97
  "0x62797465734c696b65"
93
- ]
98
+ ],
99
+ expected: "0x89ddb668afdb92cd9027c2ecf8ef3f36f2a76d07f72db32f17be6ddd5552abfb"
94
100
  },
95
101
  {
96
102
  types: [
@@ -109,12 +115,13 @@ describe("solidityKeccak256", function() {
109
115
  115,
110
116
  116
111
117
  ]
112
- ]
118
+ ],
119
+ expected: "0xb57d179e947e0bfe9813227c428eeea3558dc20e47a9fe64b9d9f29b9b5eeff0"
113
120
  }
114
121
  ];
115
122
  testSolidityKeccak256(inputs);
116
123
  });
117
- it("should match ethers.js bytes (static size)", function() {
124
+ it("should match expected hash for bytes (static size)", function() {
118
125
  var inputs = [
119
126
  {
120
127
  types: [
@@ -127,7 +134,8 @@ describe("solidityKeccak256", function() {
127
134
  115,
128
135
  116
129
136
  ]
130
- ]
137
+ ],
138
+ expected: "0x9c22ff5f21f0b81b113e63f7db6da94fedef11b2119b4088b89664fb9a3cb658"
131
139
  },
132
140
  {
133
141
  types: [
@@ -170,12 +178,13 @@ describe("solidityKeccak256", function() {
170
178
  [
171
179
  33
172
180
  ]
173
- ]
181
+ ],
182
+ expected: "0xe44f351d6a5adfe8e8917ee07b7269e9fb019a97fba5eeab82899b02e3f15d1f"
174
183
  }
175
184
  ];
176
185
  testSolidityKeccak256(inputs);
177
186
  });
178
- it('should match ethers.js booleans (specified as type "bool" to match solidity)', function() {
187
+ it('should match expected hash for booleans (specified as type "bool" to match solidity)', function() {
179
188
  var inputs = [
180
189
  {
181
190
  types: [
@@ -183,7 +192,8 @@ describe("solidityKeccak256", function() {
183
192
  ],
184
193
  values: [
185
194
  true
186
- ]
195
+ ],
196
+ expected: "0x5fe7f977e71dba2ea1a68e21057beebb9be2ac30c6410aa38d4f3fbe41dcffd2"
187
197
  },
188
198
  {
189
199
  types: [
@@ -193,12 +203,13 @@ describe("solidityKeccak256", function() {
193
203
  values: [
194
204
  false,
195
205
  false
196
- ]
206
+ ],
207
+ expected: "0x54a8c0ab653c15bfb48b47fd011ba2b9617af01cb45cab344acd57c924d56798"
197
208
  }
198
209
  ];
199
210
  testSolidityKeccak256(inputs);
200
211
  });
201
- it("should match ethers.js (signed and unsigned) integers", function() {
212
+ it("should match expected hash for (signed and unsigned) integers", function() {
202
213
  var inputs = [
203
214
  {
204
215
  types: [
@@ -206,7 +217,8 @@ describe("solidityKeccak256", function() {
206
217
  ],
207
218
  values: [
208
219
  -1
209
- ]
220
+ ],
221
+ expected: "0x06d41322d79dfed27126569cb9a80eb0967335bf2f3316359d2a93c779fcd38a"
210
222
  },
211
223
  {
212
224
  types: [
@@ -214,7 +226,8 @@ describe("solidityKeccak256", function() {
214
226
  ],
215
227
  values: [
216
228
  12
217
- ]
229
+ ],
230
+ expected: "0x505be1cd98680abcc2473d7336b83f86f30185d233a18e7dbf9a0add7f7fb583"
218
231
  },
219
232
  {
220
233
  types: [
@@ -224,28 +237,13 @@ describe("solidityKeccak256", function() {
224
237
  values: [
225
238
  -1,
226
239
  12
227
- ]
228
- }
229
- ];
230
- testSolidityKeccak256(inputs);
231
- });
232
- it("should match ethers.js array parsing", function() {
233
- var inputs = [
234
- {
235
- types: [
236
- "string[2]"
237
240
  ],
238
- values: [
239
- [
240
- "some-text",
241
- "additional-text"
242
- ]
243
- ]
241
+ expected: "0x81da7abb5c9c7515f57dab2fc946f01217ab52f3bd8958bc36bd55894451a93c"
244
242
  }
245
243
  ];
246
244
  testSolidityKeccak256(inputs);
247
245
  });
248
- it("should match ethers.js when passing different types into the same solidityKeccak256 function call", function() {
246
+ it("should match expected hash when passing different types into the same solidityKeccak256 function call", function() {
249
247
  var inputs = [
250
248
  {
251
249
  types: [
@@ -257,7 +255,8 @@ describe("solidityKeccak256", function() {
257
255
  -5,
258
256
  "essential-eth",
259
257
  true
260
- ]
258
+ ],
259
+ expected: "0xa7bbaa8154fe7d3d9a9d813fa435b386fd75dc57d02b620baafc04074658c454"
261
260
  },
262
261
  {
263
262
  types: [
@@ -274,7 +273,8 @@ describe("solidityKeccak256", function() {
274
273
  115,
275
274
  116
276
275
  ]
277
- ]
276
+ ],
277
+ expected: "0x6e4e133a4879decc8bf952c54092cb965ba979f38d5e6fb62d47e6bdd7ea390c"
278
278
  },
279
279
  {
280
280
  types: [
@@ -302,7 +302,8 @@ describe("solidityKeccak256", function() {
302
302
  false,
303
303
  true
304
304
  ]
305
- ]
305
+ ],
306
+ expected: "0xb66a5a976e76e7f2d8b2d5baff670f9937c12b6c3484a9479075d9ecfc2700d2"
306
307
  }
307
308
  ];
308
309
  testSolidityKeccak256(inputs);
@@ -1,17 +1,38 @@
1
- import { utils } from "ethers";
2
1
  import { splitSignature } from "../split-signature";
3
2
  describe("splitSignature", function() {
4
- it("should match ethers.js", function() {
5
- var signatures = [
6
- "0x60bc4ed91f2021aefe7045f3f77bd12f87eb733aee24bd1965343b3c27b3971647252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee331b",
7
- "0x60bc4ed91f2021aefe7045f3f77bd12f87eb733aee24bd1965343b3c27b3971647252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33"
3
+ it("should match expected results", function() {
4
+ var testCases = [
5
+ {
6
+ signature: "0x60bc4ed91f2021aefe7045f3f77bd12f87eb733aee24bd1965343b3c27b3971647252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee331b",
7
+ expected: {
8
+ _vs: "0x47252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33",
9
+ compact: "0x60bc4ed91f2021aefe7045f3f77bd12f87eb733aee24bd1965343b3c27b3971647252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33",
10
+ r: "0x60bc4ed91f2021aefe7045f3f77bd12f87eb733aee24bd1965343b3c27b39716",
11
+ recoveryParam: 0,
12
+ s: "0x47252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33",
13
+ v: 27,
14
+ yParityAndS: "0x47252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33"
15
+ }
16
+ },
17
+ {
18
+ signature: "0x60bc4ed91f2021aefe7045f3f77bd12f87eb733aee24bd1965343b3c27b3971647252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33",
19
+ expected: {
20
+ _vs: "0x47252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33",
21
+ compact: "0x60bc4ed91f2021aefe7045f3f77bd12f87eb733aee24bd1965343b3c27b3971647252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33",
22
+ r: "0x60bc4ed91f2021aefe7045f3f77bd12f87eb733aee24bd1965343b3c27b39716",
23
+ recoveryParam: 0,
24
+ s: "0x47252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33",
25
+ v: 27,
26
+ yParityAndS: "0x47252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33"
27
+ }
28
+ }
8
29
  ];
9
- signatures.forEach(function(signature) {
10
- expect(splitSignature(signature)).toStrictEqual(utils.splitSignature(signature));
30
+ testCases.forEach(function(testCase) {
31
+ expect(splitSignature(testCase.signature)).toStrictEqual(testCase.expected);
11
32
  });
12
33
  });
13
34
  it("should throw error on invalid signature", function() {
14
- var signature = "0x60bc4ed91f2021aefe7045f3f77bd12f87eb733aee24bd1965343b3c27b3971647252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33238423849234765127"; //invalid signature length
35
+ var signature = "0x60bc4ed91f2021aefe7045f3f77bd12f87eb733aee24bd1965343b3c27b3971647252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33238423849234765127";
15
36
  expect(function() {
16
37
  splitSignature(signature);
17
38
  }).toThrow("invalid signature string");
@@ -1,5 +1,3 @@
1
- import { utils } from "ethers";
2
- import web3 from "web3";
3
1
  import { toChecksumAddress } from "../../index";
4
2
  describe("ether-to-wei", function() {
5
3
  it("happy path", function() {
@@ -14,8 +12,7 @@ describe("ether-to-wei", function() {
14
12
  "0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb"
15
13
  ];
16
14
  addresses.forEach(function(address) {
17
- expect(toChecksumAddress(address)).toStrictEqual(utils.getAddress(address));
18
- expect(toChecksumAddress(address)).toStrictEqual(web3.utils.toChecksumAddress(address));
15
+ expect(toChecksumAddress(address)).toStrictEqual(address);
19
16
  });
20
17
  });
21
18
  it("invalid inputs", function() {
@@ -1,14 +1,34 @@
1
- import { utils } from "ethers";
2
1
  import { toUtf8Bytes } from "../../index";
3
2
  describe("utils.toUtf8Bytes", function() {
4
- it("should match ethers.js", function() {
5
- var inputs = [
6
- "0xa",
7
- "1",
8
- "false"
3
+ it("should correctly convert to UTF8 bytes", function() {
4
+ var testCases = [
5
+ {
6
+ input: "0xa",
7
+ expected: new Uint8Array([
8
+ 48,
9
+ 120,
10
+ 97
11
+ ])
12
+ },
13
+ {
14
+ input: "1",
15
+ expected: new Uint8Array([
16
+ 49
17
+ ])
18
+ },
19
+ {
20
+ input: "false",
21
+ expected: new Uint8Array([
22
+ 102,
23
+ 97,
24
+ 108,
25
+ 115,
26
+ 101
27
+ ])
28
+ }
9
29
  ];
10
- inputs.forEach(function(input) {
11
- expect(toUtf8Bytes(input)).toStrictEqual(utils.toUtf8Bytes(input));
30
+ testCases.forEach(function(testCase) {
31
+ expect(toUtf8Bytes(testCase.input)).toStrictEqual(testCase.expected);
12
32
  });
13
33
  });
14
34
  });