essential-eth 0.5.9 → 0.5.10

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 (199) 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/{lib/esm → dist}/classes/utils/clean-log.d.ts +2 -2
  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/esm → dist}/classes/utils/encode-decode-transaction.d.ts +4 -4
  12. package/{lib/esm → dist}/classes/utils/fetchers.d.ts +9 -9
  13. package/{lib/esm → dist}/classes/utils/hex-to-decimal.d.ts +1 -1
  14. package/{lib/esm → dist}/classes/utils/prepare-transaction.d.ts +2 -2
  15. package/dist/index.cjs +2 -0
  16. package/dist/index.cjs.map +1 -0
  17. package/{lib/esm → 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 -24
  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/cjs → dist}/providers/utils/chains-info.d.ts +467 -423
  35. package/{lib/esm → 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 -41
  39. package/{lib/cjs → dist}/types/Contract.types.d.ts +24 -24
  40. package/{lib/esm → dist}/types/Filter.types.d.ts +12 -12
  41. package/{lib/esm → dist}/types/Network.types.d.ts +5 -5
  42. package/{lib/esm → dist}/types/Transaction.types.d.ts +113 -113
  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/{lib/esm → dist}/utils/keccak256.d.ts +2 -2
  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/esm → dist}/utils/to-utf8-bytes.d.ts +1 -1
  56. package/dist/utils/wei-to-ether.d.ts +3 -0
  57. package/package.json +42 -19
  58. package/lib/cjs/classes/Contract.d.ts +0 -78
  59. package/lib/cjs/classes/Contract.js +0 -140
  60. package/lib/cjs/classes/test/Contract/crv-abi.d.ts +0 -2
  61. package/lib/cjs/classes/test/Contract/crv-abi.js +0 -488
  62. package/lib/cjs/classes/test/Contract/ens-abi.d.ts +0 -2
  63. package/lib/cjs/classes/test/Contract/ens-abi.js +0 -453
  64. package/lib/cjs/classes/test/Contract/fei-abi.d.ts +0 -2
  65. package/lib/cjs/classes/test/Contract/fei-abi.js +0 -526
  66. package/lib/cjs/classes/test/Contract/foo-abi.d.ts +0 -2
  67. package/lib/cjs/classes/test/Contract/foo-abi.js +0 -42
  68. package/lib/cjs/classes/test/Contract/uniswap-abi.d.ts +0 -2
  69. package/lib/cjs/classes/test/Contract/uniswap-abi.js +0 -121
  70. package/lib/cjs/classes/utils/clean-block.d.ts +0 -121
  71. package/lib/cjs/classes/utils/clean-block.js +0 -160
  72. package/lib/cjs/classes/utils/clean-log.d.ts +0 -9
  73. package/lib/cjs/classes/utils/clean-log.js +0 -37
  74. package/lib/cjs/classes/utils/clean-transaction-receipt.d.ts +0 -14
  75. package/lib/cjs/classes/utils/clean-transaction-receipt.js +0 -50
  76. package/lib/cjs/classes/utils/clean-transaction.d.ts +0 -14
  77. package/lib/cjs/classes/utils/clean-transaction.js +0 -51
  78. package/lib/cjs/classes/utils/encode-decode-transaction.d.ts +0 -16
  79. package/lib/cjs/classes/utils/encode-decode-transaction.js +0 -137
  80. package/lib/cjs/classes/utils/fetchers.d.ts +0 -39
  81. package/lib/cjs/classes/utils/fetchers.js +0 -81
  82. package/lib/cjs/classes/utils/hex-to-decimal.d.ts +0 -18
  83. package/lib/cjs/classes/utils/hex-to-decimal.js +0 -24
  84. package/lib/cjs/classes/utils/prepare-transaction.d.ts +0 -6
  85. package/lib/cjs/classes/utils/prepare-transaction.js +0 -45
  86. package/lib/cjs/index.d.ts +0 -25
  87. package/lib/cjs/index.js +0 -54
  88. package/lib/cjs/logger/logger.d.ts +0 -11
  89. package/lib/cjs/logger/logger.js +0 -36
  90. package/lib/cjs/logger/package-version.d.ts +0 -1
  91. package/lib/cjs/logger/package-version.js +0 -5
  92. package/lib/cjs/providers/BaseProvider.d.ts +0 -353
  93. package/lib/cjs/providers/BaseProvider.js +0 -512
  94. package/lib/cjs/providers/FallthroughProvider.d.ts +0 -24
  95. package/lib/cjs/providers/FallthroughProvider.js +0 -65
  96. package/lib/cjs/providers/JsonRpcProvider.d.ts +0 -33
  97. package/lib/cjs/providers/JsonRpcProvider.js +0 -46
  98. package/lib/cjs/providers/test/rpc-urls.js +0 -14
  99. package/lib/cjs/providers/utils/chains-info.js +0 -1270
  100. package/lib/cjs/shared/tiny-big/helpers.d.ts +0 -17
  101. package/lib/cjs/shared/tiny-big/helpers.js +0 -97
  102. package/lib/cjs/shared/tiny-big/tiny-big.d.ts +0 -58
  103. package/lib/cjs/shared/tiny-big/tiny-big.js +0 -101
  104. package/lib/cjs/shared/validate-type.js +0 -9
  105. package/lib/cjs/types/Block.types.js +0 -2
  106. package/lib/cjs/types/Contract.types.js +0 -2
  107. package/lib/cjs/types/Filter.types.d.ts +0 -16
  108. package/lib/cjs/types/Filter.types.js +0 -2
  109. package/lib/cjs/types/Network.types.d.ts +0 -8
  110. package/lib/cjs/types/Network.types.js +0 -2
  111. package/lib/cjs/types/Transaction.types.d.ts +0 -123
  112. package/lib/cjs/types/Transaction.types.js +0 -2
  113. package/lib/cjs/utils/bytes.d.ts +0 -289
  114. package/lib/cjs/utils/bytes.js +0 -711
  115. package/lib/cjs/utils/compute-address.d.ts +0 -17
  116. package/lib/cjs/utils/compute-address.js +0 -33
  117. package/lib/cjs/utils/compute-public-key.d.ts +0 -18
  118. package/lib/cjs/utils/compute-public-key.js +0 -26
  119. package/lib/cjs/utils/ether-to-gwei.d.ts +0 -27
  120. package/lib/cjs/utils/ether-to-gwei.js +0 -35
  121. package/lib/cjs/utils/ether-to-wei.d.ts +0 -27
  122. package/lib/cjs/utils/ether-to-wei.js +0 -35
  123. package/lib/cjs/utils/gwei-to-ether.d.ts +0 -27
  124. package/lib/cjs/utils/gwei-to-ether.js +0 -35
  125. package/lib/cjs/utils/hash-message.d.ts +0 -14
  126. package/lib/cjs/utils/hash-message.js +0 -28
  127. package/lib/cjs/utils/is-address.d.ts +0 -24
  128. package/lib/cjs/utils/is-address.js +0 -39
  129. package/lib/cjs/utils/keccak256.d.ts +0 -16
  130. package/lib/cjs/utils/keccak256.js +0 -31
  131. package/lib/cjs/utils/solidity-keccak256.d.ts +0 -39
  132. package/lib/cjs/utils/solidity-keccak256.js +0 -138
  133. package/lib/cjs/utils/split-signature.d.ts +0 -24
  134. package/lib/cjs/utils/split-signature.js +0 -163
  135. package/lib/cjs/utils/to-checksum-address.d.ts +0 -17
  136. package/lib/cjs/utils/to-checksum-address.js +0 -46
  137. package/lib/cjs/utils/to-utf8-bytes.d.ts +0 -15
  138. package/lib/cjs/utils/to-utf8-bytes.js +0 -21
  139. package/lib/cjs/utils/wei-to-ether.d.ts +0 -27
  140. package/lib/cjs/utils/wei-to-ether.js +0 -45
  141. package/lib/esm/classes/Contract.js +0 -65
  142. package/lib/esm/classes/test/Contract/crv-abi.d.ts +0 -2
  143. package/lib/esm/classes/test/Contract/crv-abi.js +0 -470
  144. package/lib/esm/classes/test/Contract/ens-abi.d.ts +0 -2
  145. package/lib/esm/classes/test/Contract/ens-abi.js +0 -435
  146. package/lib/esm/classes/test/Contract/fei-abi.d.ts +0 -2
  147. package/lib/esm/classes/test/Contract/fei-abi.js +0 -521
  148. package/lib/esm/classes/test/Contract/foo-abi.d.ts +0 -2
  149. package/lib/esm/classes/test/Contract/foo-abi.js +0 -33
  150. package/lib/esm/classes/test/Contract/uniswap-abi.d.ts +0 -2
  151. package/lib/esm/classes/test/Contract/uniswap-abi.js +0 -116
  152. package/lib/esm/classes/utils/clean-block.d.ts +0 -3
  153. package/lib/esm/classes/utils/clean-block.js +0 -35
  154. package/lib/esm/classes/utils/clean-log.js +0 -26
  155. package/lib/esm/classes/utils/clean-transaction-receipt.js +0 -34
  156. package/lib/esm/classes/utils/clean-transaction.js +0 -33
  157. package/lib/esm/classes/utils/encode-decode-transaction.js +0 -98
  158. package/lib/esm/classes/utils/fetchers.js +0 -43
  159. package/lib/esm/classes/utils/hex-to-decimal.js +0 -3
  160. package/lib/esm/classes/utils/prepare-transaction.js +0 -34
  161. package/lib/esm/index.js +0 -20
  162. package/lib/esm/logger/logger.js +0 -33
  163. package/lib/esm/logger/package-version.d.ts +0 -1
  164. package/lib/esm/logger/package-version.js +0 -1
  165. package/lib/esm/providers/BaseProvider.js +0 -157
  166. package/lib/esm/providers/FallthroughProvider.js +0 -41
  167. package/lib/esm/providers/JsonRpcProvider.js +0 -15
  168. package/lib/esm/providers/test/rpc-urls.d.ts +0 -11
  169. package/lib/esm/providers/test/rpc-urls.js +0 -11
  170. package/lib/esm/providers/utils/chains-info.d.ts +0 -423
  171. package/lib/esm/providers/utils/chains-info.js +0 -1266
  172. package/lib/esm/shared/tiny-big/helpers.js +0 -58
  173. package/lib/esm/shared/tiny-big/tiny-big.js +0 -45
  174. package/lib/esm/shared/validate-type.d.ts +0 -3
  175. package/lib/esm/shared/validate-type.js +0 -5
  176. package/lib/esm/types/Block.types.d.ts +0 -40
  177. package/lib/esm/types/Block.types.js +0 -1
  178. package/lib/esm/types/Contract.types.d.ts +0 -24
  179. package/lib/esm/types/Contract.types.js +0 -1
  180. package/lib/esm/types/Filter.types.js +0 -1
  181. package/lib/esm/types/Network.types.js +0 -1
  182. package/lib/esm/types/Transaction.types.js +0 -1
  183. package/lib/esm/utils/bytes.js +0 -245
  184. package/lib/esm/utils/compute-address.js +0 -11
  185. package/lib/esm/utils/compute-public-key.js +0 -6
  186. package/lib/esm/utils/ether-to-gwei.js +0 -7
  187. package/lib/esm/utils/ether-to-wei.d.ts +0 -3
  188. package/lib/esm/utils/ether-to-wei.js +0 -7
  189. package/lib/esm/utils/gwei-to-ether.d.ts +0 -3
  190. package/lib/esm/utils/gwei-to-ether.js +0 -7
  191. package/lib/esm/utils/hash-message.js +0 -12
  192. package/lib/esm/utils/is-address.js +0 -12
  193. package/lib/esm/utils/keccak256.js +0 -13
  194. package/lib/esm/utils/solidity-keccak256.js +0 -85
  195. package/lib/esm/utils/split-signature.js +0 -126
  196. package/lib/esm/utils/to-checksum-address.js +0 -25
  197. package/lib/esm/utils/to-utf8-bytes.js +0 -3
  198. package/lib/esm/utils/wei-to-ether.d.ts +0 -3
  199. package/lib/esm/utils/wei-to-ether.js +0 -16
@@ -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,45 +0,0 @@
1
- import Big from 'big.js';
2
- import { hexToDecimal } from '../../classes/utils/hex-to-decimal';
3
- import { scientificStrToDecimalStr } from './helpers';
4
- export class TinyBig extends Big {
5
- constructor(value) {
6
- if (typeof value === 'string' && value.startsWith('0x')) {
7
- value = hexToDecimal(value);
8
- }
9
- super(value);
10
- this.padAndChop = (str, padChar, length) => {
11
- return (Array(length).fill(padChar).join('') + str).slice(length * -1);
12
- };
13
- }
14
- toHexString() {
15
- return `0x${BigInt(this.toString()).toString(16)}`;
16
- }
17
- toNumber() {
18
- return Number(scientificStrToDecimalStr(super.toString()));
19
- }
20
- toString() {
21
- if (this.toNumber() === 0) {
22
- return '0';
23
- }
24
- return scientificStrToDecimalStr(super.toString());
25
- }
26
- toTwos(bitCount) {
27
- let binaryStr;
28
- if (this.gte(0)) {
29
- const twosComp = this.toNumber().toString(2);
30
- binaryStr = this.padAndChop(twosComp, '0', bitCount || twosComp.length);
31
- }
32
- else {
33
- binaryStr = this.plus(Math.pow(2, bitCount)).toNumber().toString(2);
34
- if (Number(binaryStr) < 0) {
35
- throw new Error('Cannot calculate twos complement');
36
- }
37
- }
38
- const binary = `0b${binaryStr}`;
39
- const decimal = Number(binary);
40
- return tinyBig(decimal);
41
- }
42
- }
43
- export function tinyBig(value) {
44
- return new TinyBig(value);
45
- }
@@ -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,40 +0,0 @@
1
- import { TinyBig } from './../shared/tiny-big/tiny-big';
2
- import { BlockTransactionResponse, RPCTransaction } from './Transaction.types';
3
- declare type Modify<T, R> = Omit<T, keyof R> & R;
4
- export declare type BlockResponse = Modify<RPCBlock, {
5
- baseFeePerGas: TinyBig;
6
- difficulty: TinyBig;
7
- gasLimit: TinyBig;
8
- gasUsed: TinyBig;
9
- nonce: TinyBig;
10
- number: number;
11
- size: TinyBig;
12
- timestamp: TinyBig;
13
- totalDifficulty: TinyBig;
14
- transactions: Array<string | BlockTransactionResponse>;
15
- }>;
16
- export interface RPCBlock {
17
- baseFeePerGas: string;
18
- difficulty: string;
19
- extraData: string;
20
- gasLimit: string;
21
- gasUsed: string;
22
- hash: string;
23
- logsBloom: string;
24
- miner: string;
25
- mixHash: string;
26
- nonce: string;
27
- number: string;
28
- parentHash: string;
29
- receiptsRoot: string;
30
- sha3Uncles: string;
31
- size: string;
32
- stateRoot: string;
33
- timestamp: string;
34
- totalDifficulty: string;
35
- transactions: Array<string | RPCTransaction>;
36
- transactionsRoot: string;
37
- uncles: Array<string>;
38
- }
39
- export declare type BlockTag = 'latest' | 'earliest' | 'pending' | number | string;
40
- 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 +0,0 @@
1
- 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,13 +0,0 @@
1
- import { Keccak } from 'sha3';
2
- export function 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
- }
@@ -1,85 +0,0 @@
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
- const regexBytes = new RegExp('^bytes([0-9]+)$');
8
- const regexNumber = new RegExp('^(u?int)([0-9]*)$');
9
- const regexArray = new RegExp('^(.*)\\[([0-9]*)\\]$');
10
- function _pack(type, value, isArray) {
11
- switch (type) {
12
- case 'address':
13
- if (isArray) {
14
- return zeroPad(value, 32);
15
- }
16
- return arrayify(value);
17
- case 'string':
18
- return Buffer.from(value);
19
- case 'bytes':
20
- return arrayify(value);
21
- case 'bool':
22
- value = value ? '0x01' : '0x00';
23
- if (isArray) {
24
- return zeroPad(value, 32);
25
- }
26
- return arrayify(value);
27
- }
28
- let match = type.match(regexNumber);
29
- if (match) {
30
- let size = parseInt(match[2] || '256');
31
- if ((match[2] && String(size) !== match[2]) ||
32
- size % 8 !== 0 ||
33
- size === 0 ||
34
- size > 256) {
35
- logger.throwArgumentError('invalid number type', 'type', type);
36
- }
37
- if (isArray) {
38
- size = 256;
39
- }
40
- value = tinyBig(value).toTwos(size).toNumber();
41
- const hexValue = hexlify(value);
42
- return zeroPad(hexValue, size / 8);
43
- }
44
- match = type.match(regexBytes);
45
- if (match) {
46
- const size = parseInt(match[1]);
47
- if (String(size) !== match[1] || size === 0 || size > 32) {
48
- logger.throwArgumentError('invalid bytes type', 'type', type);
49
- }
50
- if (arrayify(value).byteLength !== size) {
51
- logger.throwArgumentError(`invalid value for ${type}`, 'value', value);
52
- }
53
- if (isArray) {
54
- return arrayify((value + hexFalse).substring(0, 66));
55
- }
56
- return value;
57
- }
58
- match = type.match(regexArray);
59
- if (match && Array.isArray(value)) {
60
- const baseType = match[1];
61
- const count = parseInt(match[2] || String(value.length));
62
- if (count != value.length) {
63
- logger.throwArgumentError(`invalid array length for ${type}`, 'value', value);
64
- }
65
- const result = [];
66
- value.forEach(function (value) {
67
- result.push(_pack(baseType, value, true));
68
- });
69
- return concat(result);
70
- }
71
- return logger.throwArgumentError('invalid type', 'type', type);
72
- }
73
- export function pack(types, values) {
74
- if (types.length != values.length) {
75
- logger.throwArgumentError('wrong number of values; expected ${ types.length }', 'values', values);
76
- }
77
- const tight = [];
78
- types.forEach(function (type, index) {
79
- tight.push(_pack(type, values[index]));
80
- });
81
- return hexlify(concat(tight));
82
- }
83
- export function solidityKeccak256(types, values) {
84
- return keccak256(pack(types, values));
85
- }