essential-eth 0.5.6 → 0.5.10-next.2

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 (196) hide show
  1. package/{lib/esm → dist}/classes/Contract.d.ts +11 -11
  2. package/dist/classes/test/Contract/crv-abi.d.ts +2 -0
  3. package/dist/classes/test/Contract/ens-abi.d.ts +2 -0
  4. package/dist/classes/test/Contract/fei-abi.d.ts +2 -0
  5. package/dist/classes/test/Contract/foo-abi.d.ts +2 -0
  6. package/dist/classes/test/Contract/uniswap-abi.d.ts +2 -0
  7. package/dist/classes/utils/clean-block.d.ts +3 -0
  8. package/dist/classes/utils/clean-log.d.ts +2 -0
  9. package/{lib/esm → dist}/classes/utils/clean-transaction-receipt.d.ts +2 -2
  10. package/{lib/esm → dist}/classes/utils/clean-transaction.d.ts +2 -2
  11. package/{lib/cjs → dist}/classes/utils/encode-decode-transaction.d.ts +4 -4
  12. package/{lib/cjs → dist}/classes/utils/fetchers.d.ts +9 -9
  13. package/{lib/esm → dist}/classes/utils/hex-to-decimal.d.ts +1 -1
  14. package/dist/classes/utils/prepare-transaction.d.ts +2 -0
  15. package/dist/index.cjs +2 -0
  16. package/dist/index.cjs.map +1 -0
  17. package/{lib/cjs → dist}/index.d.ts +25 -25
  18. package/dist/index.js +2 -0
  19. package/dist/index.js.map +1 -0
  20. package/dist/index.modern.js +2 -0
  21. package/dist/index.modern.js.map +1 -0
  22. package/dist/index.modern.mjs +2 -0
  23. package/dist/index.modern.mjs.map +1 -0
  24. package/dist/index.module.js +2 -0
  25. package/dist/index.module.js.map +1 -0
  26. package/dist/index.umd.js +2 -0
  27. package/dist/index.umd.js.map +1 -0
  28. package/{lib/esm → dist}/logger/logger.d.ts +11 -11
  29. package/dist/logger/package-version.d.ts +1 -0
  30. package/{lib/esm → dist}/providers/BaseProvider.d.ts +24 -21
  31. package/{lib/esm → dist}/providers/FallthroughProvider.d.ts +11 -11
  32. package/{lib/esm → dist}/providers/JsonRpcProvider.d.ts +7 -7
  33. package/{lib/cjs → dist}/providers/test/rpc-urls.d.ts +11 -11
  34. package/{lib/esm → dist}/providers/utils/chains-info.d.ts +467 -412
  35. package/{lib/cjs → dist}/shared/tiny-big/helpers.d.ts +1 -1
  36. package/{lib/esm → dist}/shared/tiny-big/tiny-big.d.ts +10 -10
  37. package/{lib/cjs → dist}/shared/validate-type.d.ts +3 -3
  38. package/{lib/cjs → dist}/types/Block.types.d.ts +40 -37
  39. package/{lib/cjs → dist}/types/Contract.types.d.ts +24 -24
  40. package/dist/types/Filter.types.d.ts +12 -0
  41. package/{lib/esm → dist}/types/Network.types.d.ts +5 -5
  42. package/{lib/cjs → dist}/types/Transaction.types.d.ts +113 -96
  43. package/{lib/esm → dist}/utils/bytes.d.ts +40 -40
  44. package/{lib/esm → dist}/utils/compute-address.d.ts +1 -1
  45. package/{lib/esm → dist}/utils/compute-public-key.d.ts +2 -2
  46. package/{lib/esm → dist}/utils/ether-to-gwei.d.ts +3 -3
  47. package/dist/utils/ether-to-wei.d.ts +3 -0
  48. package/dist/utils/gwei-to-ether.d.ts +3 -0
  49. package/{lib/esm → dist}/utils/hash-message.d.ts +2 -2
  50. package/{lib/esm → dist}/utils/is-address.d.ts +1 -1
  51. package/dist/utils/keccak256.d.ts +2 -0
  52. package/{lib/esm → dist}/utils/solidity-keccak256.d.ts +2 -2
  53. package/{lib/esm → dist}/utils/split-signature.d.ts +2 -2
  54. package/{lib/esm → dist}/utils/to-checksum-address.d.ts +1 -1
  55. package/{lib/cjs → dist}/utils/to-utf8-bytes.d.ts +1 -1
  56. package/dist/utils/wei-to-ether.d.ts +3 -0
  57. package/package.json +66 -19
  58. package/readme.md +643 -291
  59. package/lib/cjs/classes/Contract.d.ts +0 -72
  60. package/lib/cjs/classes/Contract.js +0 -129
  61. package/lib/cjs/classes/test/Contract/crv-abi.d.ts +0 -2
  62. package/lib/cjs/classes/test/Contract/crv-abi.js +0 -488
  63. package/lib/cjs/classes/test/Contract/ens-abi.d.ts +0 -2
  64. package/lib/cjs/classes/test/Contract/ens-abi.js +0 -453
  65. package/lib/cjs/classes/test/Contract/fei-abi.d.ts +0 -2
  66. package/lib/cjs/classes/test/Contract/fei-abi.js +0 -526
  67. package/lib/cjs/classes/test/Contract/foo-abi.d.ts +0 -2
  68. package/lib/cjs/classes/test/Contract/foo-abi.js +0 -42
  69. package/lib/cjs/classes/test/Contract/uniswap-abi.d.ts +0 -2
  70. package/lib/cjs/classes/test/Contract/uniswap-abi.js +0 -121
  71. package/lib/cjs/classes/utils/clean-block.d.ts +0 -6
  72. package/lib/cjs/classes/utils/clean-block.js +0 -47
  73. package/lib/cjs/classes/utils/clean-transaction-receipt.d.ts +0 -5
  74. package/lib/cjs/classes/utils/clean-transaction-receipt.js +0 -55
  75. package/lib/cjs/classes/utils/clean-transaction.d.ts +0 -5
  76. package/lib/cjs/classes/utils/clean-transaction.js +0 -42
  77. package/lib/cjs/classes/utils/encode-decode-transaction.js +0 -113
  78. package/lib/cjs/classes/utils/fetchers.js +0 -51
  79. package/lib/cjs/classes/utils/hex-to-decimal.d.ts +0 -5
  80. package/lib/cjs/classes/utils/hex-to-decimal.js +0 -11
  81. package/lib/cjs/index.js +0 -55
  82. package/lib/cjs/logger/logger.d.ts +0 -11
  83. package/lib/cjs/logger/logger.js +0 -36
  84. package/lib/cjs/logger/package-version.d.ts +0 -1
  85. package/lib/cjs/logger/package-version.js +0 -5
  86. package/lib/cjs/providers/BaseProvider.d.ts +0 -304
  87. package/lib/cjs/providers/BaseProvider.js +0 -405
  88. package/lib/cjs/providers/FallthroughProvider.d.ts +0 -24
  89. package/lib/cjs/providers/FallthroughProvider.js +0 -65
  90. package/lib/cjs/providers/JsonRpcProvider.d.ts +0 -27
  91. package/lib/cjs/providers/JsonRpcProvider.js +0 -40
  92. package/lib/cjs/providers/test/rpc-urls.js +0 -14
  93. package/lib/cjs/providers/types.d.ts +0 -7
  94. package/lib/cjs/providers/types.js +0 -2
  95. package/lib/cjs/providers/utils/chains-info.d.ts +0 -412
  96. package/lib/cjs/providers/utils/chains-info.js +0 -1237
  97. package/lib/cjs/shared/tiny-big/helpers.js +0 -71
  98. package/lib/cjs/shared/tiny-big/tiny-big.d.ts +0 -32
  99. package/lib/cjs/shared/tiny-big/tiny-big.js +0 -71
  100. package/lib/cjs/shared/validate-type.js +0 -9
  101. package/lib/cjs/types/Block.types.js +0 -2
  102. package/lib/cjs/types/Contract.types.js +0 -2
  103. package/lib/cjs/types/Network.types.d.ts +0 -8
  104. package/lib/cjs/types/Network.types.js +0 -2
  105. package/lib/cjs/types/Transaction.types.js +0 -2
  106. package/lib/cjs/utils/bytes.d.ts +0 -172
  107. package/lib/cjs/utils/bytes.js +0 -564
  108. package/lib/cjs/utils/compute-address.d.ts +0 -8
  109. package/lib/cjs/utils/compute-address.js +0 -24
  110. package/lib/cjs/utils/compute-public-key.d.ts +0 -9
  111. package/lib/cjs/utils/compute-public-key.js +0 -17
  112. package/lib/cjs/utils/ether-to-gwei.d.ts +0 -26
  113. package/lib/cjs/utils/ether-to-gwei.js +0 -34
  114. package/lib/cjs/utils/ether-to-wei.d.ts +0 -26
  115. package/lib/cjs/utils/ether-to-wei.js +0 -34
  116. package/lib/cjs/utils/gwei-to-ether.d.ts +0 -26
  117. package/lib/cjs/utils/gwei-to-ether.js +0 -34
  118. package/lib/cjs/utils/hash-message.d.ts +0 -12
  119. package/lib/cjs/utils/hash-message.js +0 -26
  120. package/lib/cjs/utils/is-address.d.ts +0 -24
  121. package/lib/cjs/utils/is-address.js +0 -39
  122. package/lib/cjs/utils/keccak256.d.ts +0 -2
  123. package/lib/cjs/utils/keccak256.js +0 -17
  124. package/lib/cjs/utils/solidity-keccak256.d.ts +0 -29
  125. package/lib/cjs/utils/solidity-keccak256.js +0 -118
  126. package/lib/cjs/utils/split-signature.d.ts +0 -26
  127. package/lib/cjs/utils/split-signature.js +0 -165
  128. package/lib/cjs/utils/to-checksum-address.d.ts +0 -17
  129. package/lib/cjs/utils/to-checksum-address.js +0 -46
  130. package/lib/cjs/utils/to-utf8-bytes.js +0 -7
  131. package/lib/cjs/utils/wei-to-ether.d.ts +0 -26
  132. package/lib/cjs/utils/wei-to-ether.js +0 -44
  133. package/lib/esm/classes/Contract.js +0 -65
  134. package/lib/esm/classes/test/Contract/crv-abi.d.ts +0 -2
  135. package/lib/esm/classes/test/Contract/crv-abi.js +0 -470
  136. package/lib/esm/classes/test/Contract/ens-abi.d.ts +0 -2
  137. package/lib/esm/classes/test/Contract/ens-abi.js +0 -435
  138. package/lib/esm/classes/test/Contract/fei-abi.d.ts +0 -2
  139. package/lib/esm/classes/test/Contract/fei-abi.js +0 -521
  140. package/lib/esm/classes/test/Contract/foo-abi.d.ts +0 -2
  141. package/lib/esm/classes/test/Contract/foo-abi.js +0 -33
  142. package/lib/esm/classes/test/Contract/uniswap-abi.d.ts +0 -2
  143. package/lib/esm/classes/test/Contract/uniswap-abi.js +0 -116
  144. package/lib/esm/classes/utils/clean-block.d.ts +0 -3
  145. package/lib/esm/classes/utils/clean-block.js +0 -36
  146. package/lib/esm/classes/utils/clean-transaction-receipt.js +0 -48
  147. package/lib/esm/classes/utils/clean-transaction.js +0 -33
  148. package/lib/esm/classes/utils/encode-decode-transaction.d.ts +0 -4
  149. package/lib/esm/classes/utils/encode-decode-transaction.js +0 -98
  150. package/lib/esm/classes/utils/fetchers.d.ts +0 -9
  151. package/lib/esm/classes/utils/fetchers.js +0 -43
  152. package/lib/esm/classes/utils/hex-to-decimal.js +0 -3
  153. package/lib/esm/index.d.ts +0 -25
  154. package/lib/esm/index.js +0 -21
  155. package/lib/esm/logger/logger.js +0 -33
  156. package/lib/esm/logger/package-version.d.ts +0 -1
  157. package/lib/esm/logger/package-version.js +0 -1
  158. package/lib/esm/providers/BaseProvider.js +0 -114
  159. package/lib/esm/providers/FallthroughProvider.js +0 -41
  160. package/lib/esm/providers/JsonRpcProvider.js +0 -15
  161. package/lib/esm/providers/test/rpc-urls.d.ts +0 -11
  162. package/lib/esm/providers/test/rpc-urls.js +0 -11
  163. package/lib/esm/providers/types.d.ts +0 -7
  164. package/lib/esm/providers/types.js +0 -1
  165. package/lib/esm/providers/utils/chains-info.js +0 -1233
  166. package/lib/esm/shared/tiny-big/helpers.d.ts +0 -1
  167. package/lib/esm/shared/tiny-big/helpers.js +0 -58
  168. package/lib/esm/shared/tiny-big/tiny-big.js +0 -41
  169. package/lib/esm/shared/validate-type.d.ts +0 -3
  170. package/lib/esm/shared/validate-type.js +0 -5
  171. package/lib/esm/types/Block.types.d.ts +0 -36
  172. package/lib/esm/types/Block.types.js +0 -1
  173. package/lib/esm/types/Contract.types.d.ts +0 -24
  174. package/lib/esm/types/Contract.types.js +0 -1
  175. package/lib/esm/types/Network.types.js +0 -1
  176. package/lib/esm/types/Transaction.types.d.ts +0 -87
  177. package/lib/esm/types/Transaction.types.js +0 -1
  178. package/lib/esm/utils/bytes.js +0 -245
  179. package/lib/esm/utils/compute-address.js +0 -11
  180. package/lib/esm/utils/compute-public-key.js +0 -6
  181. package/lib/esm/utils/ether-to-gwei.js +0 -7
  182. package/lib/esm/utils/ether-to-wei.d.ts +0 -3
  183. package/lib/esm/utils/ether-to-wei.js +0 -7
  184. package/lib/esm/utils/gwei-to-ether.d.ts +0 -3
  185. package/lib/esm/utils/gwei-to-ether.js +0 -7
  186. package/lib/esm/utils/hash-message.js +0 -12
  187. package/lib/esm/utils/is-address.js +0 -12
  188. package/lib/esm/utils/keccak256.d.ts +0 -2
  189. package/lib/esm/utils/keccak256.js +0 -13
  190. package/lib/esm/utils/solidity-keccak256.js +0 -85
  191. package/lib/esm/utils/split-signature.js +0 -126
  192. package/lib/esm/utils/to-checksum-address.js +0 -25
  193. package/lib/esm/utils/to-utf8-bytes.d.ts +0 -1
  194. package/lib/esm/utils/to-utf8-bytes.js +0 -3
  195. package/lib/esm/utils/wei-to-ether.d.ts +0 -3
  196. package/lib/esm/utils/wei-to-ether.js +0 -16
@@ -1 +0,0 @@
1
- export declare function scientificStrToDecimalStr(scientificString: string): string;
@@ -1,58 +0,0 @@
1
- function stripTrailingZeroes(numberString) {
2
- const isNegative = numberString.startsWith('-');
3
- numberString = numberString.replace('-', '');
4
- numberString = numberString.replace(/\.0*$/g, '');
5
- numberString = numberString.replace(/^0+/, '');
6
- if (numberString.includes('.')) {
7
- numberString = numberString.replace(/0+$/, '');
8
- }
9
- if (numberString.startsWith('.')) {
10
- numberString = `0${numberString}`;
11
- }
12
- return `${isNegative ? '-' : ''}${numberString}`;
13
- }
14
- export function scientificStrToDecimalStr(scientificString) {
15
- if (!scientificString.match(/e/i)) {
16
- return stripTrailingZeroes(scientificString);
17
- }
18
- let [base, power] = scientificString.split(/e/i);
19
- const isNegative = Number(base) < 0;
20
- base = base.replace('-', '');
21
- base = stripTrailingZeroes(base);
22
- const [wholeNumber, fraction = ''] = base.split('.');
23
- if (Number(power) === 0) {
24
- return `${isNegative ? '-' : ''}${stripTrailingZeroes(base)}`;
25
- }
26
- else {
27
- const includesDecimal = base.includes('.');
28
- if (!includesDecimal) {
29
- base = `${base}.`;
30
- }
31
- base = base.replace('.', '');
32
- const baseLength = base.length;
33
- let splitPaddedNumber;
34
- if (Number(power) < 0) {
35
- if (wholeNumber.length < Math.abs(Number(power))) {
36
- base = base.padStart(baseLength + Math.abs(Number(power)) - wholeNumber.length, '0');
37
- }
38
- splitPaddedNumber = base.split('');
39
- if (wholeNumber.length < Math.abs(Number(power))) {
40
- splitPaddedNumber = ['.', ...splitPaddedNumber];
41
- }
42
- else {
43
- splitPaddedNumber.splice(splitPaddedNumber.length - Math.abs(Number(power)), 0, '.');
44
- }
45
- }
46
- else {
47
- if (fraction.length < Math.abs(Number(power))) {
48
- base = base.padEnd(baseLength + Math.abs(Number(power)) - fraction.length, '0');
49
- }
50
- splitPaddedNumber = base.split('');
51
- if (fraction.length > Math.abs(Number(power))) {
52
- splitPaddedNumber.splice(splitPaddedNumber.length - Math.abs(Number(power)), 0, '.');
53
- }
54
- }
55
- const toReturn = stripTrailingZeroes(splitPaddedNumber.join(''));
56
- return `${isNegative ? '-' : ''}${toReturn}`;
57
- }
58
- }
@@ -1,41 +0,0 @@
1
- import Big from 'big.js';
2
- import { scientificStrToDecimalStr } from './helpers';
3
- export class TinyBig extends Big {
4
- constructor(value) {
5
- super(value);
6
- this.padAndChop = (str, padChar, length) => {
7
- return (Array(length).fill(padChar).join('') + str).slice(length * -1);
8
- };
9
- }
10
- toHexString() {
11
- return `0x${BigInt(this.toString()).toString(16)}`;
12
- }
13
- toNumber() {
14
- return Number(scientificStrToDecimalStr(super.toString()));
15
- }
16
- toString() {
17
- if (this.toNumber() === 0) {
18
- return '0';
19
- }
20
- return scientificStrToDecimalStr(super.toString());
21
- }
22
- toTwos(bitCount) {
23
- let binaryStr;
24
- if (this.gte(0)) {
25
- const twosComp = this.toNumber().toString(2);
26
- binaryStr = this.padAndChop(twosComp, '0', bitCount || twosComp.length);
27
- }
28
- else {
29
- binaryStr = this.plus(Math.pow(2, bitCount)).toNumber().toString(2);
30
- if (Number(binaryStr) < 0) {
31
- throw new Error('Cannot calculate twos complement');
32
- }
33
- }
34
- const binary = `0b${binaryStr}`;
35
- const decimal = Number(binary);
36
- return tinyBig(decimal);
37
- }
38
- }
39
- export function tinyBig(value) {
40
- return new TinyBig(value);
41
- }
@@ -1,3 +0,0 @@
1
- declare type JSPrimitiveTypes = 'string' | 'number' | 'bigint' | 'boolean' | 'symbol' | 'undefined' | 'object' | 'function';
2
- export declare const validateType: (value: unknown, allowedTypes: JSPrimitiveTypes[]) => void;
3
- export {};
@@ -1,5 +0,0 @@
1
- export const validateType = (value, allowedTypes) => {
2
- if (!allowedTypes.includes(typeof value)) {
3
- throw new Error(`${allowedTypes.join(' or ')} required. Received ${typeof value}`);
4
- }
5
- };
@@ -1,36 +0,0 @@
1
- import { BlockTransactionResponse, RPCTransaction } from './Transaction.types';
2
- declare type Modify<T, R> = Omit<T, keyof R> & R;
3
- export declare type BlockResponse = Modify<RPCBlock, {
4
- gasLimit: number;
5
- gasUsed: number;
6
- number: number;
7
- size: number;
8
- timestamp: number;
9
- baseFeePerGas: number;
10
- transactions: Array<string | BlockTransactionResponse>;
11
- }>;
12
- export interface RPCBlock {
13
- baseFeePerGas: string;
14
- difficulty: string;
15
- extraData: string;
16
- gasLimit: string;
17
- gasUsed: string;
18
- hash: string;
19
- logsBloom: string;
20
- miner: string;
21
- mixHash: string;
22
- nonce: string;
23
- number: string;
24
- parentHash: string;
25
- receiptsRoot: string;
26
- sha3Uncles: string;
27
- size: string;
28
- stateRoot: string;
29
- timestamp: string;
30
- totalDifficulty: string;
31
- transactions: Array<string> | Array<RPCTransaction>;
32
- transactionsRoot: string;
33
- uncles: unknown[];
34
- }
35
- export declare type BlockTag = 'latest' | 'earliest' | 'pending' | number | string;
36
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,24 +0,0 @@
1
- export declare type ContractTypes = 'bool' | 'bytes1' | 'bytes2' | 'bytes3' | 'bytes4' | 'bytes5' | 'bytes6' | 'bytes7' | 'bytes8' | 'bytes9' | 'bytes10' | 'bytes11' | 'bytes12' | 'bytes13' | 'bytes14' | 'bytes15' | 'bytes16' | 'bytes17' | 'bytes18' | 'bytes19' | 'bytes20' | 'bytes21' | 'bytes22' | 'bytes23' | 'bytes24' | 'bytes25' | 'bytes26' | 'bytes27' | 'bytes28' | 'bytes29' | 'bytes30' | 'bytes31' | 'bytes32' | 'bytes32[]' | 'address' | 'address payable' | 'address[4]' | 'address[100]' | 'uint256' | 'uint256[100]' | 'uint8' | 'uint32' | string;
2
- export declare type ContractInterface = JSONABI;
3
- export declare type ContractFunction<T = any> = (...args: Array<any>) => Promise<T>;
4
- export interface JSONABIArgument {
5
- anonymous?: false;
6
- inputs: {
7
- internalType?: ContractTypes | string;
8
- name: string;
9
- type: ContractTypes;
10
- indexed?: boolean;
11
- }[];
12
- name?: string;
13
- outputs?: {
14
- internalType?: ContractTypes | string;
15
- name: string;
16
- type: ContractTypes;
17
- }[];
18
- stateMutability?: 'view' | 'nonpayable' | string;
19
- type: 'function' | 'event' | 'constructor' | 'error' | 'fallback';
20
- gas?: number;
21
- constant?: boolean;
22
- payable?: boolean;
23
- }
24
- export declare type JSONABI = JSONABIArgument[];
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,87 +0,0 @@
1
- import { TinyBig } from '../shared/tiny-big/tiny-big';
2
- declare type Modify<T, R> = Omit<T, keyof R> & R;
3
- export interface RPCTransaction extends RPCBlockTransaction {
4
- maxFeePerGas: string;
5
- maxPriorityFeePerGas: string;
6
- }
7
- export declare type TransactionResponse = Modify<RPCTransaction, {
8
- blockNumber: number;
9
- chainId: number;
10
- nonce: number;
11
- transactionIndex: number;
12
- type: number;
13
- v: number;
14
- value: TinyBig;
15
- gasPrice: TinyBig;
16
- gas: TinyBig;
17
- gasLimit: TinyBig;
18
- } & {
19
- maxFeePerGas: TinyBig;
20
- maxPriorityFeePerGas: TinyBig;
21
- confirmations: number;
22
- }>;
23
- export declare type TransactionReceipt = Modify<RPCTransactionReceipt, {
24
- blockNumber: number;
25
- cumulativeGasUsed: TinyBig;
26
- effectiveGasPrice: TinyBig;
27
- gasUsed: TinyBig;
28
- logs: Array<Log>;
29
- status: number;
30
- transactionIndex: number;
31
- type: number;
32
- } & {
33
- byzantium: boolean;
34
- confirmations: number;
35
- }>;
36
- export declare type Log = Modify<Omit<RPCLog, 'removed'>, {
37
- blockNumber: number;
38
- logIndex: number;
39
- transactionIndex: number;
40
- }>;
41
- export declare type BlockTransactionResponse = Omit<TransactionResponse, 'maxFeePerGas' | 'maxPriorityFeePerGas'>;
42
- export interface RPCBlockTransaction {
43
- blockHash: string;
44
- blockNumber: string;
45
- chainId: string;
46
- from: string;
47
- gas: string;
48
- gasPrice: string;
49
- hash: string;
50
- input: string;
51
- nonce: string;
52
- r: string;
53
- s: string;
54
- to: string;
55
- transactionIndex: string;
56
- type: string;
57
- v: string;
58
- value: string;
59
- }
60
- export interface RPCTransactionReceipt {
61
- blockHash: string;
62
- blockNumber: string;
63
- contractAddress: string;
64
- cumulativeGasUsed: string;
65
- effectiveGasPrice: string;
66
- from: string;
67
- gasUsed: string;
68
- logs: Array<RPCLog>;
69
- logsBloom: string;
70
- status: string;
71
- to: string;
72
- transactionHash: string;
73
- transactionIndex: string;
74
- type: string;
75
- }
76
- export interface RPCLog {
77
- address: string;
78
- blockHash: string;
79
- blockNumber: string;
80
- data: string;
81
- logIndex: string;
82
- removed?: boolean;
83
- topics: Array<string>;
84
- transactionHash: string;
85
- transactionIndex: string;
86
- }
87
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,245 +0,0 @@
1
- import { logger } from '../logger/logger';
2
- function isHexable(value) {
3
- return !!value.toHexString;
4
- }
5
- export function isBytesLike(value) {
6
- return (isHexString(value) && !(value.length % 2)) || isBytes(value);
7
- }
8
- function isInteger(value) {
9
- return typeof value === 'number' && value == value && value % 1 === 0;
10
- }
11
- export function isBytes(value) {
12
- if (value == null) {
13
- return false;
14
- }
15
- if (value.constructor === Uint8Array) {
16
- return true;
17
- }
18
- if (typeof value === 'string') {
19
- return false;
20
- }
21
- if (!isInteger(value.length) || value.length < 0) {
22
- return false;
23
- }
24
- for (let i = 0; i < value.length; i++) {
25
- const v = value[i];
26
- if (!isInteger(v) || v < 0 || v >= 256) {
27
- return false;
28
- }
29
- }
30
- return true;
31
- }
32
- export function arrayify(value, options) {
33
- if (!options) {
34
- options = {};
35
- }
36
- if (typeof value === 'number') {
37
- logger.checkSafeUint53(value, 'invalid arrayify value');
38
- const result = [];
39
- while (value) {
40
- result.unshift(value & 0xff);
41
- value = parseInt(String(value / 256));
42
- }
43
- if (result.length === 0) {
44
- result.push(0);
45
- }
46
- return new Uint8Array(result);
47
- }
48
- if (options.allowMissingPrefix &&
49
- typeof value === 'string' &&
50
- value.substring(0, 2) !== '0x') {
51
- value = '0x' + value;
52
- }
53
- if (isHexable(value)) {
54
- value = value.toHexString();
55
- }
56
- if (isHexString(value)) {
57
- let hex = value.substring(2);
58
- if (hex.length % 2) {
59
- if (options.hexPad === 'left') {
60
- hex = '0' + hex;
61
- }
62
- else if (options.hexPad === 'right') {
63
- hex += '0';
64
- }
65
- else {
66
- logger.throwArgumentError('hex data is odd-length', 'value', value);
67
- }
68
- }
69
- const result = [];
70
- for (let i = 0; i < hex.length; i += 2) {
71
- result.push(parseInt(hex.substring(i, i + 2), 16));
72
- }
73
- return new Uint8Array(result);
74
- }
75
- if (isBytes(value)) {
76
- return new Uint8Array(value);
77
- }
78
- return logger.throwArgumentError('invalid arrayify value', 'value', value);
79
- }
80
- export function concat(arrayOfBytesLike) {
81
- const objects = arrayOfBytesLike.map((item) => arrayify(item));
82
- const length = objects.reduce((accum, item) => accum + item.length, 0);
83
- const result = new Uint8Array(length);
84
- objects.reduce((offset, object) => {
85
- result.set(object, offset);
86
- return offset + object.length;
87
- }, 0);
88
- return result;
89
- }
90
- export function stripZeros(value) {
91
- let result = arrayify(value);
92
- if (result.length === 0) {
93
- return result;
94
- }
95
- let start = 0;
96
- while (start < result.length && result[start] === 0) {
97
- start++;
98
- }
99
- if (start) {
100
- result = result.slice(start);
101
- }
102
- return result;
103
- }
104
- export function zeroPad(value, length) {
105
- value = arrayify(value);
106
- if (value.length > length) {
107
- logger.throwArgumentError('value out of range', 'value', value);
108
- }
109
- const result = new Uint8Array(length);
110
- result.set(value, length - value.length);
111
- return result;
112
- }
113
- export function isHexString(value, length) {
114
- if (typeof value !== 'string' || !value.match(/^0x[0-9A-Fa-f]*$/)) {
115
- return false;
116
- }
117
- if (length && value.length !== 2 + 2 * length) {
118
- return false;
119
- }
120
- return true;
121
- }
122
- const HexCharacters = '0123456789abcdef';
123
- export function hexlify(value, options) {
124
- if (!options) {
125
- options = {};
126
- }
127
- if (typeof value === 'number') {
128
- logger.checkSafeUint53(value, 'invalid hexlify value');
129
- let hex = '';
130
- while (value) {
131
- hex = HexCharacters[value & 0xf] + hex;
132
- value = Math.floor(value / 16);
133
- }
134
- if (hex.length) {
135
- if (hex.length % 2) {
136
- hex = '0' + hex;
137
- }
138
- return '0x' + hex;
139
- }
140
- return '0x00';
141
- }
142
- if (typeof value === 'bigint') {
143
- value = value.toString(16);
144
- if (value.length % 2) {
145
- return '0x0' + value;
146
- }
147
- return '0x' + value;
148
- }
149
- if (options.allowMissingPrefix &&
150
- typeof value === 'string' &&
151
- value.substring(0, 2) !== '0x') {
152
- value = '0x' + value;
153
- }
154
- if (isHexable(value)) {
155
- return value.toHexString();
156
- }
157
- if (isHexString(value)) {
158
- if (value.length % 2) {
159
- if (options.hexPad === 'left') {
160
- value = '0x0' + value.substring(2);
161
- }
162
- else if (options.hexPad === 'right') {
163
- value += '0';
164
- }
165
- else {
166
- logger.throwArgumentError('hex data is odd-length', 'value', value);
167
- }
168
- }
169
- return value.toLowerCase();
170
- }
171
- if (isBytes(value)) {
172
- let result = '0x';
173
- for (let i = 0; i < value.length; i++) {
174
- const v = value[i];
175
- result += HexCharacters[(v & 0xf0) >> 4] + HexCharacters[v & 0x0f];
176
- }
177
- return result;
178
- }
179
- return logger.throwArgumentError('invalid hexlify value', 'value', value);
180
- }
181
- export function hexDataLength(data) {
182
- if (typeof data !== 'string') {
183
- data = hexlify(data);
184
- }
185
- else if (!isHexString(data) || data.length % 2) {
186
- return null;
187
- }
188
- return (data.length - 2) / 2;
189
- }
190
- export function hexDataSlice(data, offset, endOffset) {
191
- if (typeof data !== 'string') {
192
- data = hexlify(data);
193
- }
194
- else if (!isHexString(data) || data.length % 2) {
195
- logger.throwArgumentError('invalid hexData', 'value', data);
196
- }
197
- offset = 2 + 2 * offset;
198
- if (endOffset != null) {
199
- return '0x' + data.substring(offset, 2 + 2 * endOffset);
200
- }
201
- return '0x' + data.substring(offset);
202
- }
203
- export function hexConcat(items) {
204
- let result = '0x';
205
- items.forEach((item) => {
206
- result += hexlify(item).substring(2);
207
- });
208
- return result;
209
- }
210
- export function hexValue(value) {
211
- const trimmed = hexStripZeros(hexlify(value, { hexPad: 'left' }));
212
- if (trimmed === '0x') {
213
- return '0x0';
214
- }
215
- return trimmed;
216
- }
217
- export function hexStripZeros(value) {
218
- if (typeof value !== 'string') {
219
- value = hexlify(value);
220
- }
221
- if (!isHexString(value)) {
222
- logger.throwArgumentError('invalid hex string', 'value', value);
223
- }
224
- value = value.substring(2);
225
- let offset = 0;
226
- while (offset < value.length && value[offset] === '0') {
227
- offset++;
228
- }
229
- return '0x' + value.substring(offset);
230
- }
231
- export function hexZeroPad(value, length) {
232
- if (typeof value !== 'string') {
233
- value = hexlify(value);
234
- }
235
- else if (!isHexString(value)) {
236
- logger.throwArgumentError('invalid hex string', 'value', value);
237
- }
238
- if (value.length > 2 * length + 2) {
239
- logger.throwError('value out of range', { value, length });
240
- }
241
- while (value.length < 2 * length + 2) {
242
- value = '0x0' + value.substring(2);
243
- }
244
- return value;
245
- }
@@ -1,11 +0,0 @@
1
- import { computePublicKey, toChecksumAddress } from '..';
2
- import { hexDataSlice } from './bytes';
3
- import { keccak256 } from './keccak256';
4
- export function computeAddress(key) {
5
- if (!key.startsWith('0x04') &&
6
- !key.startsWith('0x03') &&
7
- !key.startsWith('0x02')) {
8
- key = computePublicKey(key);
9
- }
10
- return toChecksumAddress(hexDataSlice(keccak256(hexDataSlice(key, 1)), 12));
11
- }
@@ -1,6 +0,0 @@
1
- import { Point } from '@noble/secp256k1';
2
- import { hexlify } from './bytes';
3
- export function computePublicKey(privKey) {
4
- privKey = hexlify(privKey).slice(2);
5
- return '0x' + Point.fromPrivateKey(privKey).toHex();
6
- }
@@ -1,7 +0,0 @@
1
- import { tinyBig } from '../shared/tiny-big/tiny-big';
2
- import { validateType } from '../shared/validate-type';
3
- export function etherToGwei(etherQuantity) {
4
- validateType(etherQuantity, ['string', 'number', 'object']);
5
- const result = tinyBig(etherQuantity).times('1000000000');
6
- return tinyBig(result);
7
- }
@@ -1,3 +0,0 @@
1
- import Big from 'big.js';
2
- import { TinyBig } from '../shared/tiny-big/tiny-big';
3
- export declare function etherToWei(etherQuantity: string | number | TinyBig | Big): TinyBig;
@@ -1,7 +0,0 @@
1
- import { tinyBig } from '../shared/tiny-big/tiny-big';
2
- import { validateType } from '../shared/validate-type';
3
- export function etherToWei(etherQuantity) {
4
- validateType(etherQuantity, ['string', 'number', 'object']);
5
- const result = tinyBig(etherQuantity).times('1000000000000000000');
6
- return tinyBig(result);
7
- }
@@ -1,3 +0,0 @@
1
- import Big from 'big.js';
2
- import { TinyBig } from './../shared/tiny-big/tiny-big';
3
- export declare function gweiToEther(gweiQuantity: string | number | TinyBig | Big): TinyBig;
@@ -1,7 +0,0 @@
1
- import { tinyBig } from '../shared/tiny-big/tiny-big';
2
- import { validateType } from '../shared/validate-type';
3
- export function gweiToEther(gweiQuantity) {
4
- validateType(gweiQuantity, ['string', 'number', 'object']);
5
- const result = tinyBig(gweiQuantity).div('1000000000');
6
- return tinyBig(result);
7
- }
@@ -1,12 +0,0 @@
1
- import { concat, keccak256, toUtf8Bytes } from '../index';
2
- const messagePrefix = '\x19Ethereum Signed Message:\n';
3
- export function hashMessage(message) {
4
- if (typeof message === 'string') {
5
- message = toUtf8Bytes(message);
6
- }
7
- return keccak256(concat([
8
- toUtf8Bytes(messagePrefix),
9
- toUtf8Bytes(String(message.length)),
10
- message,
11
- ]));
12
- }
@@ -1,12 +0,0 @@
1
- import { toChecksumAddress } from '..';
2
- import { validateType } from '../shared/validate-type';
3
- export function isAddress(address) {
4
- validateType(address, ['string']);
5
- try {
6
- toChecksumAddress(address);
7
- return true;
8
- }
9
- catch (error) {
10
- return false;
11
- }
12
- }
@@ -1,2 +0,0 @@
1
- import { BytesLike } from './bytes';
2
- export declare const keccak256: (data: BytesLike) => string;
@@ -1,13 +0,0 @@
1
- import { Keccak } from 'sha3';
2
- export const keccak256 = (data) => {
3
- let bufferableData;
4
- if (typeof data === 'string') {
5
- bufferableData = Buffer.from(data.replace(/^0x/, ''), 'hex');
6
- }
7
- else {
8
- bufferableData = Buffer.from(data);
9
- }
10
- const keccak = new Keccak(256);
11
- const addressHash = '0x' + keccak.update(bufferableData).digest('hex');
12
- return addressHash;
13
- };