essential-eth 0.10.3 → 0.10.4-beta.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 (204) hide show
  1. package/dist/index.cjs +2024 -0
  2. package/dist/index.d.cts +330 -0
  3. package/dist/index.d.ts +330 -0
  4. package/dist/index.js +1952 -0
  5. package/package.json +13 -14
  6. package/dist/cjs/classes/Contract.d.ts +0 -81
  7. package/dist/cjs/classes/Contract.js +0 -139
  8. package/dist/cjs/classes/test/Contract/crv-abi.d.ts +0 -2
  9. package/dist/cjs/classes/test/Contract/crv-abi.js +0 -413
  10. package/dist/cjs/classes/test/Contract/ens-abi.d.ts +0 -2
  11. package/dist/cjs/classes/test/Contract/ens-abi.js +0 -453
  12. package/dist/cjs/classes/test/Contract/fei-abi.d.ts +0 -2
  13. package/dist/cjs/classes/test/Contract/fei-abi.js +0 -526
  14. package/dist/cjs/classes/test/Contract/foo-abi.d.ts +0 -2
  15. package/dist/cjs/classes/test/Contract/foo-abi.js +0 -42
  16. package/dist/cjs/classes/test/Contract/jokerrace-abi.d.ts +0 -2
  17. package/dist/cjs/classes/test/Contract/jokerrace-abi.js +0 -22
  18. package/dist/cjs/classes/test/Contract/uniswap-abi.d.ts +0 -2
  19. package/dist/cjs/classes/test/Contract/uniswap-abi.js +0 -121
  20. package/dist/cjs/classes/utils/clean-block.d.ts +0 -120
  21. package/dist/cjs/classes/utils/clean-block.js +0 -160
  22. package/dist/cjs/classes/utils/clean-log.d.ts +0 -9
  23. package/dist/cjs/classes/utils/clean-log.js +0 -39
  24. package/dist/cjs/classes/utils/clean-transaction-receipt.d.ts +0 -14
  25. package/dist/cjs/classes/utils/clean-transaction-receipt.js +0 -53
  26. package/dist/cjs/classes/utils/clean-transaction.d.ts +0 -14
  27. package/dist/cjs/classes/utils/clean-transaction.js +0 -54
  28. package/dist/cjs/classes/utils/encode-decode-transaction.d.ts +0 -16
  29. package/dist/cjs/classes/utils/encode-decode-transaction.js +0 -185
  30. package/dist/cjs/classes/utils/fetchers.d.ts +0 -53
  31. package/dist/cjs/classes/utils/fetchers.js +0 -85
  32. package/dist/cjs/classes/utils/hex-to-decimal.d.ts +0 -18
  33. package/dist/cjs/classes/utils/hex-to-decimal.js +0 -24
  34. package/dist/cjs/classes/utils/prepare-transaction.d.ts +0 -6
  35. package/dist/cjs/classes/utils/prepare-transaction.js +0 -47
  36. package/dist/cjs/index.d.ts +0 -24
  37. package/dist/cjs/index.js +0 -58
  38. package/dist/cjs/index.umd.js +0 -2
  39. package/dist/cjs/index.umd.js.map +0 -1
  40. package/dist/cjs/logger/logger.d.ts +0 -11
  41. package/dist/cjs/logger/logger.js +0 -37
  42. package/dist/cjs/logger/package-version.d.ts +0 -1
  43. package/dist/cjs/logger/package-version.js +0 -5
  44. package/dist/cjs/package.json +0 -1
  45. package/dist/cjs/providers/AlchemyProvider.d.ts +0 -4
  46. package/dist/cjs/providers/AlchemyProvider.js +0 -11
  47. package/dist/cjs/providers/BaseProvider.d.ts +0 -374
  48. package/dist/cjs/providers/BaseProvider.js +0 -514
  49. package/dist/cjs/providers/FallthroughProvider.d.ts +0 -24
  50. package/dist/cjs/providers/FallthroughProvider.js +0 -74
  51. package/dist/cjs/providers/JsonRpcProvider.d.ts +0 -33
  52. package/dist/cjs/providers/JsonRpcProvider.js +0 -46
  53. package/dist/cjs/providers/test/json-rpc-provider/get-logs/mocks.d.ts +0 -14
  54. package/dist/cjs/providers/test/json-rpc-provider/get-logs/mocks.js +0 -152
  55. package/dist/cjs/providers/test/mock-of.d.ts +0 -8
  56. package/dist/cjs/providers/test/mock-of.js +0 -12
  57. package/dist/cjs/providers/test/rpc-urls.d.ts +0 -12
  58. package/dist/cjs/providers/test/rpc-urls.js +0 -27
  59. package/dist/cjs/providers/utils/chains-info.d.ts +0 -24
  60. package/dist/cjs/providers/utils/chains-info.js +0 -71
  61. package/dist/cjs/shared/tiny-big/helpers.d.ts +0 -17
  62. package/dist/cjs/shared/tiny-big/helpers.js +0 -97
  63. package/dist/cjs/shared/tiny-big/tiny-big.d.ts +0 -58
  64. package/dist/cjs/shared/tiny-big/tiny-big.js +0 -101
  65. package/dist/cjs/shared/validate-type.d.ts +0 -3
  66. package/dist/cjs/shared/validate-type.js +0 -9
  67. package/dist/cjs/types/Block.types.d.ts +0 -41
  68. package/dist/cjs/types/Block.types.js +0 -2
  69. package/dist/cjs/types/Contract.types.d.ts +0 -24
  70. package/dist/cjs/types/Contract.types.js +0 -2
  71. package/dist/cjs/types/FeeData.types.d.ts +0 -7
  72. package/dist/cjs/types/FeeData.types.js +0 -2
  73. package/dist/cjs/types/Filter.types.d.ts +0 -16
  74. package/dist/cjs/types/Filter.types.js +0 -2
  75. package/dist/cjs/types/Network.types.d.ts +0 -8
  76. package/dist/cjs/types/Network.types.js +0 -2
  77. package/dist/cjs/types/Transaction.types.d.ts +0 -123
  78. package/dist/cjs/types/Transaction.types.js +0 -2
  79. package/dist/cjs/utils/bytes.d.ts +0 -289
  80. package/dist/cjs/utils/bytes.js +0 -711
  81. package/dist/cjs/utils/compute-address.d.ts +0 -17
  82. package/dist/cjs/utils/compute-address.js +0 -34
  83. package/dist/cjs/utils/compute-public-key.d.ts +0 -18
  84. package/dist/cjs/utils/compute-public-key.js +0 -26
  85. package/dist/cjs/utils/ether-to-gwei.d.ts +0 -27
  86. package/dist/cjs/utils/ether-to-gwei.js +0 -35
  87. package/dist/cjs/utils/ether-to-wei.d.ts +0 -27
  88. package/dist/cjs/utils/ether-to-wei.js +0 -35
  89. package/dist/cjs/utils/gwei-to-ether.d.ts +0 -27
  90. package/dist/cjs/utils/gwei-to-ether.js +0 -35
  91. package/dist/cjs/utils/hash-message.d.ts +0 -14
  92. package/dist/cjs/utils/hash-message.js +0 -30
  93. package/dist/cjs/utils/is-address.d.ts +0 -24
  94. package/dist/cjs/utils/is-address.js +0 -39
  95. package/dist/cjs/utils/keccak256.d.ts +0 -16
  96. package/dist/cjs/utils/keccak256.js +0 -31
  97. package/dist/cjs/utils/solidity-keccak256.d.ts +0 -39
  98. package/dist/cjs/utils/solidity-keccak256.js +0 -138
  99. package/dist/cjs/utils/split-signature.d.ts +0 -24
  100. package/dist/cjs/utils/split-signature.js +0 -163
  101. package/dist/cjs/utils/to-checksum-address.d.ts +0 -17
  102. package/dist/cjs/utils/to-checksum-address.js +0 -46
  103. package/dist/cjs/utils/to-utf8-bytes.d.ts +0 -15
  104. package/dist/cjs/utils/to-utf8-bytes.js +0 -21
  105. package/dist/cjs/utils/wei-to-ether.d.ts +0 -27
  106. package/dist/cjs/utils/wei-to-ether.js +0 -45
  107. package/dist/esm/classes/Contract.d.ts +0 -11
  108. package/dist/esm/classes/Contract.js +0 -58
  109. package/dist/esm/classes/test/Contract/crv-abi.d.ts +0 -2
  110. package/dist/esm/classes/test/Contract/crv-abi.js +0 -395
  111. package/dist/esm/classes/test/Contract/ens-abi.d.ts +0 -2
  112. package/dist/esm/classes/test/Contract/ens-abi.js +0 -435
  113. package/dist/esm/classes/test/Contract/fei-abi.d.ts +0 -2
  114. package/dist/esm/classes/test/Contract/fei-abi.js +0 -521
  115. package/dist/esm/classes/test/Contract/foo-abi.d.ts +0 -2
  116. package/dist/esm/classes/test/Contract/foo-abi.js +0 -33
  117. package/dist/esm/classes/test/Contract/jokerrace-abi.d.ts +0 -2
  118. package/dist/esm/classes/test/Contract/jokerrace-abi.js +0 -18
  119. package/dist/esm/classes/test/Contract/uniswap-abi.d.ts +0 -2
  120. package/dist/esm/classes/test/Contract/uniswap-abi.js +0 -116
  121. package/dist/esm/classes/utils/clean-block.d.ts +0 -2
  122. package/dist/esm/classes/utils/clean-block.js +0 -35
  123. package/dist/esm/classes/utils/clean-log.d.ts +0 -2
  124. package/dist/esm/classes/utils/clean-log.js +0 -28
  125. package/dist/esm/classes/utils/clean-transaction-receipt.d.ts +0 -2
  126. package/dist/esm/classes/utils/clean-transaction-receipt.js +0 -37
  127. package/dist/esm/classes/utils/clean-transaction.d.ts +0 -2
  128. package/dist/esm/classes/utils/clean-transaction.js +0 -36
  129. package/dist/esm/classes/utils/encode-decode-transaction.d.ts +0 -4
  130. package/dist/esm/classes/utils/encode-decode-transaction.js +0 -143
  131. package/dist/esm/classes/utils/fetchers.d.ts +0 -15
  132. package/dist/esm/classes/utils/fetchers.js +0 -37
  133. package/dist/esm/classes/utils/hex-to-decimal.d.ts +0 -1
  134. package/dist/esm/classes/utils/hex-to-decimal.js +0 -3
  135. package/dist/esm/classes/utils/prepare-transaction.d.ts +0 -2
  136. package/dist/esm/classes/utils/prepare-transaction.js +0 -36
  137. package/dist/esm/index.d.ts +0 -24
  138. package/dist/esm/index.js +0 -19
  139. package/dist/esm/logger/logger.d.ts +0 -11
  140. package/dist/esm/logger/logger.js +0 -34
  141. package/dist/esm/logger/package-version.d.ts +0 -1
  142. package/dist/esm/logger/package-version.js +0 -1
  143. package/dist/esm/providers/AlchemyProvider.d.ts +0 -4
  144. package/dist/esm/providers/AlchemyProvider.js +0 -7
  145. package/dist/esm/providers/BaseProvider.d.ts +0 -26
  146. package/dist/esm/providers/BaseProvider.js +0 -137
  147. package/dist/esm/providers/FallthroughProvider.d.ts +0 -11
  148. package/dist/esm/providers/FallthroughProvider.js +0 -50
  149. package/dist/esm/providers/JsonRpcProvider.d.ts +0 -7
  150. package/dist/esm/providers/JsonRpcProvider.js +0 -15
  151. package/dist/esm/providers/test/json-rpc-provider/get-logs/mocks.d.ts +0 -14
  152. package/dist/esm/providers/test/json-rpc-provider/get-logs/mocks.js +0 -142
  153. package/dist/esm/providers/test/mock-of.d.ts +0 -1
  154. package/dist/esm/providers/test/mock-of.js +0 -1
  155. package/dist/esm/providers/test/rpc-urls.d.ts +0 -12
  156. package/dist/esm/providers/test/rpc-urls.js +0 -21
  157. package/dist/esm/providers/utils/chains-info.d.ts +0 -24
  158. package/dist/esm/providers/utils/chains-info.js +0 -67
  159. package/dist/esm/shared/tiny-big/helpers.d.ts +0 -1
  160. package/dist/esm/shared/tiny-big/helpers.js +0 -58
  161. package/dist/esm/shared/tiny-big/tiny-big.d.ts +0 -10
  162. package/dist/esm/shared/tiny-big/tiny-big.js +0 -45
  163. package/dist/esm/shared/validate-type.d.ts +0 -3
  164. package/dist/esm/shared/validate-type.js +0 -5
  165. package/dist/esm/types/Block.types.d.ts +0 -40
  166. package/dist/esm/types/Block.types.js +0 -1
  167. package/dist/esm/types/Contract.types.d.ts +0 -24
  168. package/dist/esm/types/Contract.types.js +0 -1
  169. package/dist/esm/types/FeeData.types.d.ts +0 -7
  170. package/dist/esm/types/FeeData.types.js +0 -1
  171. package/dist/esm/types/Filter.types.d.ts +0 -12
  172. package/dist/esm/types/Filter.types.js +0 -1
  173. package/dist/esm/types/Network.types.d.ts +0 -5
  174. package/dist/esm/types/Network.types.js +0 -1
  175. package/dist/esm/types/Transaction.types.d.ts +0 -113
  176. package/dist/esm/types/Transaction.types.js +0 -1
  177. package/dist/esm/utils/bytes.d.ts +0 -40
  178. package/dist/esm/utils/bytes.js +0 -245
  179. package/dist/esm/utils/compute-address.d.ts +0 -1
  180. package/dist/esm/utils/compute-address.js +0 -12
  181. package/dist/esm/utils/compute-public-key.d.ts +0 -2
  182. package/dist/esm/utils/compute-public-key.js +0 -6
  183. package/dist/esm/utils/ether-to-gwei.d.ts +0 -3
  184. package/dist/esm/utils/ether-to-gwei.js +0 -7
  185. package/dist/esm/utils/ether-to-wei.d.ts +0 -3
  186. package/dist/esm/utils/ether-to-wei.js +0 -7
  187. package/dist/esm/utils/gwei-to-ether.d.ts +0 -3
  188. package/dist/esm/utils/gwei-to-ether.js +0 -7
  189. package/dist/esm/utils/hash-message.d.ts +0 -2
  190. package/dist/esm/utils/hash-message.js +0 -14
  191. package/dist/esm/utils/is-address.d.ts +0 -1
  192. package/dist/esm/utils/is-address.js +0 -12
  193. package/dist/esm/utils/keccak256.d.ts +0 -2
  194. package/dist/esm/utils/keccak256.js +0 -13
  195. package/dist/esm/utils/solidity-keccak256.d.ts +0 -2
  196. package/dist/esm/utils/solidity-keccak256.js +0 -85
  197. package/dist/esm/utils/split-signature.d.ts +0 -2
  198. package/dist/esm/utils/split-signature.js +0 -126
  199. package/dist/esm/utils/to-checksum-address.d.ts +0 -1
  200. package/dist/esm/utils/to-checksum-address.js +0 -25
  201. package/dist/esm/utils/to-utf8-bytes.d.ts +0 -1
  202. package/dist/esm/utils/to-utf8-bytes.js +0 -3
  203. package/dist/esm/utils/wei-to-ether.d.ts +0 -3
  204. package/dist/esm/utils/wei-to-ether.js +0 -16
@@ -1,163 +0,0 @@
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");
6
- /**
7
- * Expands a signature into the full signature object and fills in missing properties.
8
- *
9
- * Same as ["splitSignature" in ethers.js](https://docs.ethers.io/v5/api/utils/bytes/#utils-splitSignature)
10
- *
11
- * @param signature the signature object to split, parse, and compute missing properties from
12
- * @returns a full signature object with all properties filled
13
- * @example
14
- * ```javascript
15
- * const signature = '0x60bc4ed91f2021aefe7045f3f77bd12f87eb733aee24bd1965343b3c27b3971647252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee331b';
16
- * splitSignature(signature);
17
- * {
18
- * r: "0x60bc4ed91f2021aefe7045f3f77bd12f87eb733aee24bd1965343b3c27b39716",
19
- * s: "0x47252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33",
20
- * _vs: "0x47252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33",
21
- * recoveryParam: 0,
22
- * v: 27,
23
- * yParityAndS: "0x47252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33",
24
- * compact: "0x60bc4ed91f2021aefe7045f3f77bd12f87eb733aee24bd1965343b3c27b3971647252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33"
25
- * }
26
- * ```
27
- */
28
- function splitSignature(signature) {
29
- const result = {
30
- r: '0x',
31
- s: '0x',
32
- _vs: '0x',
33
- recoveryParam: 0,
34
- v: 0,
35
- yParityAndS: '0x',
36
- compact: '0x',
37
- };
38
- if ((0, bytes_1.isBytesLike)(signature)) {
39
- const bytes = (0, bytes_1.arrayify)(signature);
40
- // Get the r, s and v
41
- if (bytes.length === 64) {
42
- // EIP-2098; pull the v from the top bit of s and clear it
43
- result.v = 27 + (bytes[32] >> 7);
44
- 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));
51
- result.v = bytes[64];
52
- }
53
- else {
54
- logger_1.logger.throwArgumentError('invalid signature string', 'signature', signature);
55
- }
56
- // Allow a recid to be used as the v
57
- if (result.v < 27) {
58
- if (result.v === 0 || result.v === 1) {
59
- result.v += 27;
60
- }
61
- else {
62
- logger_1.logger.throwArgumentError('signature invalid v byte', 'signature', signature);
63
- }
64
- }
65
- // Compute recoveryParam from v
66
- result.recoveryParam = 1 - (result.v % 2);
67
- // Compute _vs from recoveryParam and s
68
- if (result.recoveryParam) {
69
- bytes[32] |= 0x80;
70
- }
71
- result._vs = (0, bytes_1.hexlify)(bytes.slice(32, 64));
72
- }
73
- else {
74
- result.r = signature.r;
75
- result.s = signature.s;
76
- result.v = signature.v;
77
- result.recoveryParam = signature.recoveryParam;
78
- result._vs = signature._vs;
79
- // If the _vs is available, use it to populate missing s, v and recoveryParam
80
- // and verify non-missing s, v and recoveryParam
81
- 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);
84
- // Set or check the recid
85
- const recoveryParam = vs_1[0] >= 128 ? 1 : 0;
86
- if (result.recoveryParam == null) {
87
- result.recoveryParam = recoveryParam;
88
- }
89
- else if (result.recoveryParam !== recoveryParam) {
90
- logger_1.logger.throwArgumentError('signature recoveryParam mismatch _vs', 'signature', signature);
91
- }
92
- // Set or check the s
93
- vs_1[0] &= 0x7f;
94
- const s = (0, bytes_1.hexlify)(vs_1);
95
- if (result.s == null) {
96
- result.s = s;
97
- }
98
- else if (result.s !== s) {
99
- logger_1.logger.throwArgumentError('signature v mismatch _vs', 'signature', signature);
100
- }
101
- }
102
- // Use recid and v to populate each other
103
- if (result.recoveryParam == null) {
104
- 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) {
108
- result.recoveryParam = result.v;
109
- }
110
- else {
111
- result.recoveryParam = 1 - (result.v % 2);
112
- }
113
- }
114
- else {
115
- if (result.v == null) {
116
- result.v = 27 + result.recoveryParam;
117
- }
118
- else {
119
- const recId = result.v === 0 || result.v === 1 ? result.v : 1 - (result.v % 2);
120
- if (result.recoveryParam !== recId) {
121
- logger_1.logger.throwArgumentError('signature recoveryParam mismatch v', 'signature', signature);
122
- }
123
- }
124
- }
125
- if (result.r == null || !(0, bytes_1.isHexString)(result.r)) {
126
- logger_1.logger.throwArgumentError('signature missing or invalid r', 'signature', signature);
127
- }
128
- else {
129
- result.r = (0, bytes_1.hexZeroPad)(result.r, 32);
130
- }
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);
138
- if (vs[0] >= 128) {
139
- logger_1.logger.throwArgumentError('signature s out of range', 'signature', signature);
140
- }
141
- if (result.recoveryParam) {
142
- vs[0] |= 0x80;
143
- }
144
- const _vs = (0, bytes_1.hexlify)(vs);
145
- if (result._vs) {
146
- if (!(0, bytes_1.isHexString)(result._vs)) {
147
- logger_1.logger.throwArgumentError('signature invalid _vs', 'signature', signature);
148
- }
149
- result._vs = (0, bytes_1.hexZeroPad)(result._vs, 32);
150
- }
151
- // Set or check the _vs
152
- if (result._vs == null) {
153
- result._vs = _vs;
154
- }
155
- else if (result._vs !== _vs) {
156
- logger_1.logger.throwArgumentError('signature _vs mismatch v and s', 'signature', signature);
157
- }
158
- }
159
- result.yParityAndS = result._vs;
160
- result.compact = result.r + result.yParityAndS.substring(2);
161
- return result;
162
- }
163
- exports.splitSignature = splitSignature;
@@ -1,17 +0,0 @@
1
- /**
2
- * Returns an Ethereum address in proper mixed-case checksum.
3
- * Does NOT support ICAP
4
- *
5
- * @param address An Ethereum address. Mixed, lower, and uppercase are all valid
6
- * @returns a valid checksum address
7
- * @example
8
- * ```javascript
9
- * toChecksumAddress('0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359');
10
- * // '0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359'
11
- * ```
12
- *
13
- * Similar to ["getAddress" in ethers.js](https://docs.ethers.io/v5/api/utils/address/#utils-getAddress)
14
- *
15
- * Similar to ["toChecksumAddress" in web3.js](https://web3js.readthedocs.io/en/v1.7.1/web3-utils.html#tochecksumaddress)
16
- */
17
- export declare function toChecksumAddress(address: string): string;
@@ -1,46 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toChecksumAddress = void 0;
4
- const sha3_1 = require("sha3");
5
- const validate_type_1 = require("../shared/validate-type");
6
- /**
7
- * Returns an Ethereum address in proper mixed-case checksum.
8
- * Does NOT support ICAP
9
- *
10
- * @param address An Ethereum address. Mixed, lower, and uppercase are all valid
11
- * @returns a valid checksum address
12
- * @example
13
- * ```javascript
14
- * toChecksumAddress('0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359');
15
- * // '0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359'
16
- * ```
17
- *
18
- * Similar to ["getAddress" in ethers.js](https://docs.ethers.io/v5/api/utils/address/#utils-getAddress)
19
- *
20
- * Similar to ["toChecksumAddress" in web3.js](https://web3js.readthedocs.io/en/v1.7.1/web3-utils.html#tochecksumaddress)
21
- */
22
- function toChecksumAddress(address) {
23
- (0, validate_type_1.validateType)(address, ['string']);
24
- if (!/^(0x)?[0-9a-f]{40}$/i.test(address)) {
25
- throw new Error(`Invalid Ethereum address "${address}"`);
26
- }
27
- const _address = address.toLowerCase().replace(/^0x/i, '');
28
- const keccak = new sha3_1.Keccak(256);
29
- const addressHash = keccak.update(_address).digest('hex').replace(/^0x/i, '');
30
- let checksumAddress = '0x';
31
- for (let i = 0; i < _address.length; i++) {
32
- // If ith character is 8 to f then make it uppercase
33
- if (parseInt(addressHash[i], 16) > 7) {
34
- checksumAddress += _address[i].toUpperCase();
35
- }
36
- else {
37
- checksumAddress += _address[i];
38
- }
39
- }
40
- if (address.match(/([A-F].*[a-f])|([a-f].*[A-F])/) &&
41
- checksumAddress !== address) {
42
- throw new Error(`Invalid Checksum address for "${address}"`);
43
- }
44
- return checksumAddress;
45
- }
46
- exports.toChecksumAddress = toChecksumAddress;
@@ -1,15 +0,0 @@
1
- /**
2
- * Converts a string into a UTF-8 Byte Array
3
- *
4
- * @param data the input to be converted to a UTF-8 Byte Array
5
- * @returns the specified data as a UTF-8 Byte Array
6
- * @example
7
- * ```javascript
8
- * toUtf8Bytes('essential-eth');
9
- * // Uint8Array { [Iterator] 0: 101, 1: 115, 2: 115, 3: 101, 4: 110, 5: 116, 6: 105, 7: 97, 8: 108, 9: 45, 10: 101, 11: 116, 12: 104 }
10
- *
11
- * toUtf8Bytes('ethereum');
12
- * // Uint8Array { [Iterator] 0: 101, 1: 116, 2: 104, 3: 101, 4: 114, 5: 101, 6: 117, 7: 109 }
13
- * ```
14
- */
15
- export declare function toUtf8Bytes(data: string): Uint8Array;
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toUtf8Bytes = void 0;
4
- /**
5
- * Converts a string into a UTF-8 Byte Array
6
- *
7
- * @param data the input to be converted to a UTF-8 Byte Array
8
- * @returns the specified data as a UTF-8 Byte Array
9
- * @example
10
- * ```javascript
11
- * toUtf8Bytes('essential-eth');
12
- * // Uint8Array { [Iterator] 0: 101, 1: 115, 2: 115, 3: 101, 4: 110, 5: 116, 6: 105, 7: 97, 8: 108, 9: 45, 10: 101, 11: 116, 12: 104 }
13
- *
14
- * toUtf8Bytes('ethereum');
15
- * // Uint8Array { [Iterator] 0: 101, 1: 116, 2: 104, 3: 101, 4: 114, 5: 101, 6: 117, 7: 109 }
16
- * ```
17
- */
18
- function toUtf8Bytes(data) {
19
- return new Uint8Array(Buffer.from(data));
20
- }
21
- exports.toUtf8Bytes = toUtf8Bytes;
@@ -1,27 +0,0 @@
1
- import type Big from 'big.js';
2
- import type { TinyBig } from '../shared/tiny-big/tiny-big';
3
- /**
4
- * Convert from Wei to Ether
5
- *
6
- * Similar to ["formatEther" in ethers.js](https://docs.ethers.io/v5/api/utils/display-logic/#utils-formatEther)
7
- *
8
- * Similar to ["fromWei" in web3.js](https://web3js.readthedocs.io/en/v1.7.1/web3-utils.html#fromwei)
9
- *
10
- * @param weiQuantity the amount of wei to convert to ether
11
- * @returns a number of ether equivalent to the specified wei
12
- * @example
13
- * ```javascript
14
- * weiToEther('1000000000000000000000').toString()
15
- * // '1000'
16
- * weiToEther(1000000000000000000000).toString()
17
- * // '1000'
18
- * ```
19
- * @example
20
- * ```javascript
21
- * weiToEther('1000000000000000000000').toNumber()
22
- * // 1000
23
- * weiToEther(1000000000000000000000).toNumber()
24
- * // 1000
25
- * ```
26
- */
27
- export declare function weiToEther(weiQuantity: string | number | TinyBig | Big): TinyBig;
@@ -1,45 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.weiToEther = void 0;
4
- const tiny_big_1 = require("../shared/tiny-big/tiny-big");
5
- const validate_type_1 = require("../shared/validate-type");
6
- /**
7
- * Convert from Wei to Ether
8
- *
9
- * Similar to ["formatEther" in ethers.js](https://docs.ethers.io/v5/api/utils/display-logic/#utils-formatEther)
10
- *
11
- * Similar to ["fromWei" in web3.js](https://web3js.readthedocs.io/en/v1.7.1/web3-utils.html#fromwei)
12
- *
13
- * @param weiQuantity the amount of wei to convert to ether
14
- * @returns a number of ether equivalent to the specified wei
15
- * @example
16
- * ```javascript
17
- * weiToEther('1000000000000000000000').toString()
18
- * // '1000'
19
- * weiToEther(1000000000000000000000).toString()
20
- * // '1000'
21
- * ```
22
- * @example
23
- * ```javascript
24
- * weiToEther('1000000000000000000000').toNumber()
25
- * // 1000
26
- * weiToEther(1000000000000000000000).toNumber()
27
- * // 1000
28
- * ```
29
- */
30
- function weiToEther(weiQuantity) {
31
- (0, validate_type_1.validateType)(weiQuantity, ['string', 'number', 'object']);
32
- // eslint-disable-next-line no-useless-catch
33
- try {
34
- let _weiQuantity = weiQuantity;
35
- if (typeof weiQuantity === 'string' && weiQuantity.slice(0, 2) === '0x') {
36
- _weiQuantity = BigInt(weiQuantity).toString();
37
- }
38
- const result = (0, tiny_big_1.tinyBig)(_weiQuantity).div('1000000000000000000');
39
- return (0, tiny_big_1.tinyBig)(result);
40
- }
41
- catch (error) {
42
- throw error;
43
- }
44
- }
45
- exports.weiToEther = weiToEther;
@@ -1,11 +0,0 @@
1
- import type { JsonRpcProvider } from '../providers/JsonRpcProvider';
2
- import type { ContractInterface } from '../types/Contract.types';
3
- export declare class BaseContract {
4
- private readonly _address;
5
- private readonly _provider;
6
- constructor(addressOrName: string, contractInterface: ContractInterface, signerOrProvider: JsonRpcProvider);
7
- }
8
- export declare function defineReadOnly<T>(object: T, name: string, value: any): void;
9
- export declare class Contract extends BaseContract {
10
- readonly [key: string]: any;
11
- }
@@ -1,58 +0,0 @@
1
- import { decodeRPCResponse, encodeData, } from './utils/encode-decode-transaction';
2
- function estimateGas(txnData) {
3
- txnData.split('').reduce((previousValue, currentValue) => {
4
- const characterCost = currentValue === '0' ? 4 : 68;
5
- return previousValue + characterCost;
6
- }, 0);
7
- }
8
- export class BaseContract {
9
- _address;
10
- _provider;
11
- constructor(addressOrName, contractInterface, signerOrProvider) {
12
- this._address = addressOrName;
13
- this._provider = signerOrProvider;
14
- contractInterface
15
- .filter((jsonABIArgument) => jsonABIArgument.type === 'function')
16
- .forEach((jsonABIArgument) => {
17
- if ('name' in jsonABIArgument &&
18
- typeof jsonABIArgument.name === 'string') {
19
- defineReadOnly(this, jsonABIArgument.name, async (..._args) => {
20
- let functionArguments = _args;
21
- let options = {};
22
- const lastArg = _args[_args.length - 1];
23
- if (!Array.isArray(lastArg) && typeof lastArg === 'object') {
24
- options = lastArg;
25
- functionArguments = _args.slice(0, _args.length - 1);
26
- }
27
- const data = encodeData(jsonABIArgument, functionArguments);
28
- const decimalGas = typeof options.gasLimit === 'number'
29
- ? options.gasLimit
30
- : typeof jsonABIArgument?.gas ===
31
- 'number'
32
- ? estimateGas(data)
33
- : null;
34
- const req = async () => {
35
- return await this._provider.call({
36
- to: this._address.toLowerCase(),
37
- data,
38
- ...(decimalGas
39
- ? { gas: `0x${decimalGas.toString(16)}` }
40
- : {}),
41
- }, 'latest');
42
- };
43
- const nodeResponse = await req();
44
- return decodeRPCResponse(jsonABIArgument, nodeResponse);
45
- });
46
- }
47
- });
48
- }
49
- }
50
- export function defineReadOnly(object, name, value) {
51
- Object.defineProperty(object, name, {
52
- enumerable: true,
53
- value: value,
54
- writable: false,
55
- });
56
- }
57
- export class Contract extends BaseContract {
58
- }
@@ -1,2 +0,0 @@
1
- import type { JSONABI } from '../../../types/Contract.types';
2
- export declare const abi: JSONABI;