essential-eth 0.5.4-alpha.0 → 0.5.4

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 (40) hide show
  1. package/lib/cjs/classes/utils/clean-transaction-receipt.d.ts +5 -0
  2. package/lib/cjs/classes/utils/clean-transaction-receipt.js +55 -0
  3. package/lib/cjs/classes/utils/fetchers.d.ts +1 -1
  4. package/lib/cjs/index.d.ts +4 -1
  5. package/lib/cjs/index.js +6 -1
  6. package/lib/cjs/logger/package-version.d.ts +1 -1
  7. package/lib/cjs/logger/package-version.js +1 -1
  8. package/lib/cjs/providers/BaseProvider.d.ts +10 -1
  9. package/lib/cjs/providers/BaseProvider.js +21 -0
  10. package/lib/cjs/types/Transaction.types.d.ts +53 -0
  11. package/lib/cjs/utils/bytes.d.ts +5 -4
  12. package/lib/cjs/utils/hash-message.d.ts +12 -0
  13. package/lib/cjs/utils/hash-message.js +26 -0
  14. package/lib/cjs/utils/keccak256.d.ts +2 -0
  15. package/lib/cjs/utils/keccak256.js +17 -0
  16. package/lib/cjs/utils/solidity-keccak256.d.ts +0 -1
  17. package/lib/cjs/utils/solidity-keccak256.js +3 -10
  18. package/lib/cjs/utils/to-utf8-bytes.d.ts +1 -0
  19. package/lib/cjs/utils/to-utf8-bytes.js +7 -0
  20. package/lib/esm/classes/utils/clean-transaction-receipt.d.ts +2 -0
  21. package/lib/esm/classes/utils/clean-transaction-receipt.js +48 -0
  22. package/lib/esm/classes/utils/fetchers.d.ts +1 -1
  23. package/lib/esm/index.d.ts +4 -1
  24. package/lib/esm/index.js +4 -1
  25. package/lib/esm/logger/package-version.d.ts +1 -1
  26. package/lib/esm/logger/package-version.js +1 -1
  27. package/lib/esm/providers/BaseProvider.d.ts +2 -1
  28. package/lib/esm/providers/BaseProvider.js +13 -0
  29. package/lib/esm/types/Transaction.types.d.ts +45 -0
  30. package/lib/esm/utils/bytes.d.ts +5 -4
  31. package/lib/esm/utils/hash-message.d.ts +2 -0
  32. package/lib/esm/utils/hash-message.js +12 -0
  33. package/lib/esm/utils/keccak256.d.ts +2 -0
  34. package/lib/esm/utils/keccak256.js +13 -0
  35. package/lib/esm/utils/solidity-keccak256.d.ts +0 -1
  36. package/lib/esm/utils/solidity-keccak256.js +2 -8
  37. package/lib/esm/utils/to-utf8-bytes.d.ts +1 -0
  38. package/lib/esm/utils/to-utf8-bytes.js +3 -0
  39. package/package.json +2 -2
  40. package/readme.md +4 -0
@@ -0,0 +1,5 @@
1
+ import { RPCTransactionReceipt, TransactionReceipt } from '../../types/Transaction.types';
2
+ /**
3
+ * Converts RPC transaction receipt response to more JS-friendly format
4
+ */
5
+ export declare function cleanTransactionReceipt(transactionReceipt: RPCTransactionReceipt): TransactionReceipt;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cleanTransactionReceipt = void 0;
4
+ const __1 = require("../..");
5
+ const clean_transaction_1 = require("./clean-transaction");
6
+ const hex_to_decimal_1 = require("./hex-to-decimal");
7
+ /**
8
+ * Converts RPC transaction receipt response to more JS-friendly format
9
+ */
10
+ function cleanTransactionReceipt(transactionReceipt) {
11
+ const cleanedTransaction = (0, clean_transaction_1.cleanTransaction)(transactionReceipt);
12
+ const cleanedTransactionReceipt = Object.assign({}, cleanedTransaction);
13
+ Object.keys(transactionReceipt).forEach((key) => {
14
+ if (!transactionReceipt[key])
15
+ return;
16
+ switch (key) {
17
+ case 'status':
18
+ cleanedTransactionReceipt[key] = Number((0, hex_to_decimal_1.hexToDecimal)(transactionReceipt[key]));
19
+ break;
20
+ case 'contractAddress':
21
+ if (transactionReceipt[key]) {
22
+ cleanedTransactionReceipt[key] = (0, __1.toChecksumAddress)(transactionReceipt[key]);
23
+ }
24
+ break;
25
+ case 'cumulativeGasUsed':
26
+ case 'effectiveGasPrice':
27
+ case 'gasUsed':
28
+ cleanedTransactionReceipt[key] = (0, __1.tinyBig)((0, hex_to_decimal_1.hexToDecimal)(transactionReceipt[key]));
29
+ break;
30
+ case 'logs':
31
+ transactionReceipt[key].forEach((log, index) => {
32
+ Object.keys(log).forEach((logKey) => {
33
+ switch (logKey) {
34
+ case 'address':
35
+ cleanedTransactionReceipt[key][index][logKey] =
36
+ (0, __1.toChecksumAddress)(log[logKey]);
37
+ break;
38
+ case 'blockNumber':
39
+ case 'logIndex':
40
+ case 'transactionIndex':
41
+ cleanedTransactionReceipt[key][index][logKey] = Number((0, hex_to_decimal_1.hexToDecimal)(log[logKey]));
42
+ break;
43
+ case 'removed':
44
+ delete log[logKey];
45
+ break;
46
+ }
47
+ });
48
+ });
49
+ }
50
+ });
51
+ cleanedTransactionReceipt.byzantium =
52
+ cleanedTransactionReceipt.blockNumber >= 4370000;
53
+ return cleanedTransactionReceipt;
54
+ }
55
+ exports.cleanTransactionReceipt = cleanTransactionReceipt;
@@ -1,5 +1,5 @@
1
1
  export declare function post(url: string, body: Record<string, unknown>): Promise<any>;
2
- declare type RPCMethodName = 'eth_getBlockByNumber' | 'eth_getBlockByHash' | 'eth_call' | 'eth_chainId' | 'eth_gasPrice' | 'eth_getBalance' | 'eth_getTransactionByHash' | 'eth_getTransactionCount';
2
+ declare type RPCMethodName = 'eth_getBlockByNumber' | 'eth_getBlockByHash' | 'eth_call' | 'eth_chainId' | 'eth_gasPrice' | 'eth_getBalance' | 'eth_getTransactionByHash' | 'eth_getTransactionReceipt' | 'eth_getTransactionCount';
3
3
  export declare function buildRPCPostBody(method: RPCMethodName, params: unknown[]): {
4
4
  jsonrpc: string;
5
5
  id: number;
@@ -11,7 +11,10 @@ import { etherToWei } from './utils/ether-to-wei';
11
11
  import { gweiToEther } from './utils/gwei-to-ether';
12
12
  import { isAddress } from './utils/is-address';
13
13
  import { toChecksumAddress } from './utils/to-checksum-address';
14
+ import { toUtf8Bytes } from './utils/to-utf8-bytes';
14
15
  import { weiToEther } from './utils/wei-to-ether';
15
16
  export * from './utils/bytes';
17
+ export * from './utils/hash-message';
18
+ export * from './utils/keccak256';
16
19
  export * from './utils/solidity-keccak256';
17
- export { etherToWei, etherToGwei, isAddress, jsonRpcProvider, JsonRpcProvider, FallthroughProvider, tinyBig, toChecksumAddress, weiToEther, gweiToEther, Contract, TinyBig, BlockResponse, ContractTypes, JSONABI, JSONABIArgument, Network, TransactionResponse, };
20
+ export { etherToWei, etherToGwei, isAddress, jsonRpcProvider, JsonRpcProvider, FallthroughProvider, tinyBig, toChecksumAddress, weiToEther, gweiToEther, toUtf8Bytes, Contract, TinyBig, BlockResponse, ContractTypes, JSONABI, JSONABIArgument, Network, TransactionResponse, };
package/lib/cjs/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.TinyBig = exports.Contract = exports.gweiToEther = exports.weiToEther = exports.toChecksumAddress = exports.tinyBig = exports.FallthroughProvider = exports.JsonRpcProvider = exports.jsonRpcProvider = exports.isAddress = exports.etherToGwei = exports.etherToWei = void 0;
17
+ exports.TinyBig = exports.Contract = exports.toUtf8Bytes = exports.gweiToEther = exports.weiToEther = exports.toChecksumAddress = exports.tinyBig = exports.FallthroughProvider = exports.JsonRpcProvider = exports.jsonRpcProvider = exports.isAddress = exports.etherToGwei = exports.etherToWei = void 0;
18
18
  const Contract_1 = require("./classes/Contract");
19
19
  Object.defineProperty(exports, "Contract", { enumerable: true, get: function () { return Contract_1.Contract; } });
20
20
  const FallthroughProvider_1 = require("./providers/FallthroughProvider");
@@ -35,7 +35,12 @@ const is_address_1 = require("./utils/is-address");
35
35
  Object.defineProperty(exports, "isAddress", { enumerable: true, get: function () { return is_address_1.isAddress; } });
36
36
  const to_checksum_address_1 = require("./utils/to-checksum-address");
37
37
  Object.defineProperty(exports, "toChecksumAddress", { enumerable: true, get: function () { return to_checksum_address_1.toChecksumAddress; } });
38
+ // import { verifyMessage } from './utils/verify-message';
39
+ const to_utf8_bytes_1 = require("./utils/to-utf8-bytes");
40
+ Object.defineProperty(exports, "toUtf8Bytes", { enumerable: true, get: function () { return to_utf8_bytes_1.toUtf8Bytes; } });
38
41
  const wei_to_ether_1 = require("./utils/wei-to-ether");
39
42
  Object.defineProperty(exports, "weiToEther", { enumerable: true, get: function () { return wei_to_ether_1.weiToEther; } });
40
43
  __exportStar(require("./utils/bytes"), exports);
44
+ __exportStar(require("./utils/hash-message"), exports);
45
+ __exportStar(require("./utils/keccak256"), exports);
41
46
  __exportStar(require("./utils/solidity-keccak256"), exports);
@@ -1 +1 @@
1
- export declare const version = "0.5.4-alpha.0";
1
+ export declare const version = "0.5.4";
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.version = void 0;
4
4
  // Generated by genversion.
5
- exports.version = '0.5.4-alpha.0';
5
+ exports.version = '0.5.4';
@@ -1,7 +1,7 @@
1
1
  import { TinyBig } from '../shared/tiny-big/tiny-big';
2
2
  import { BlockResponse, BlockTag } from '../types/Block.types';
3
3
  import { Network } from '../types/Network.types';
4
- import { TransactionResponse } from '../types/Transaction.types';
4
+ import { TransactionReceipt, TransactionResponse } from '../types/Transaction.types';
5
5
  export declare abstract class BaseProvider {
6
6
  /**
7
7
  * ignore
@@ -149,6 +149,15 @@ export declare abstract class BaseProvider {
149
149
  * ```
150
150
  */
151
151
  getTransaction(transactionHash: string): Promise<TransactionResponse>;
152
+ /**
153
+ * Gives information about a transaction that has already been mined. Includes additional information beyond what's provided by `getTransaction()`
154
+ *
155
+ * * Similar to [`ethers.provider.getTransactionReceipt`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getTransactionReceipt), some information not included
156
+ *
157
+ * @param transactionHash the hash of the transaction to get information about
158
+ *
159
+ */
160
+ getTransactionReceipt(transactionHash: string): Promise<TransactionReceipt>;
152
161
  /**
153
162
  * Returns the transaction count from genesis up to specified blockTag
154
163
  *
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.BaseProvider = void 0;
16
16
  const clean_block_1 = require("../classes/utils/clean-block");
17
17
  const clean_transaction_1 = require("../classes/utils/clean-transaction");
18
+ const clean_transaction_receipt_1 = require("../classes/utils/clean-transaction-receipt");
18
19
  const fetchers_1 = require("../classes/utils/fetchers");
19
20
  const hex_to_decimal_1 = require("../classes/utils/hex-to-decimal");
20
21
  const tiny_big_1 = require("../shared/tiny-big/tiny-big");
@@ -186,6 +187,26 @@ class BaseProvider {
186
187
  return cleanedTransaction;
187
188
  });
188
189
  }
190
+ /**
191
+ * Gives information about a transaction that has already been mined. Includes additional information beyond what's provided by `getTransaction()`
192
+ *
193
+ * * Similar to [`ethers.provider.getTransactionReceipt`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getTransactionReceipt), some information not included
194
+ *
195
+ * @param transactionHash the hash of the transaction to get information about
196
+ *
197
+ */
198
+ getTransactionReceipt(transactionHash) {
199
+ return __awaiter(this, void 0, void 0, function* () {
200
+ const [rpcTransaction, blockNumber] = yield Promise.all([
201
+ this.post((0, fetchers_1.buildRPCPostBody)('eth_getTransactionReceipt', [transactionHash])),
202
+ this.getBlock('latest'),
203
+ ]);
204
+ const cleanedTransactionReceipt = (0, clean_transaction_receipt_1.cleanTransactionReceipt)(rpcTransaction);
205
+ cleanedTransactionReceipt.confirmations =
206
+ blockNumber.number - cleanedTransactionReceipt.blockNumber + 1;
207
+ return cleanedTransactionReceipt;
208
+ });
209
+ }
189
210
  /**
190
211
  * Returns the transaction count from genesis up to specified blockTag
191
212
  *
@@ -20,6 +20,32 @@ export declare type TransactionResponse = Modify<RPCTransaction, {
20
20
  maxPriorityFeePerGas: TinyBig;
21
21
  confirmations: number;
22
22
  }>;
23
+ /**
24
+ * Type that contains information from the receipt of a transaction
25
+ * * Similar to [`Type TransactionReceipt on ethers.providers`](https://docs.ethers.io/v5/api/providers/types/#providers-TransactionReceipt)
26
+ */
27
+ export declare type TransactionReceipt = Modify<RPCTransactionReceipt, {
28
+ blockNumber: number;
29
+ cumulativeGasUsed: TinyBig;
30
+ effectiveGasPrice: TinyBig;
31
+ gasUsed: TinyBig;
32
+ logs: Array<Log>;
33
+ status: number;
34
+ transactionIndex: number;
35
+ type: number;
36
+ } & {
37
+ byzantium: boolean;
38
+ confirmations: number;
39
+ }>;
40
+ /**
41
+ * Type for the logs that are included in transaction receipts
42
+ * * Similar to [`Type Log on ethers.providers`](https://docs.ethers.io/v5/api/providers/types/#providers-Log)
43
+ */
44
+ export declare type Log = Modify<Omit<RPCLog, 'removed'>, {
45
+ blockNumber: number;
46
+ logIndex: number;
47
+ transactionIndex: number;
48
+ }>;
23
49
  export declare type BlockTransactionResponse = Omit<TransactionResponse, 'maxFeePerGas' | 'maxPriorityFeePerGas'>;
24
50
  /** What JSONRPC responds with in getBlock transaction array */
25
51
  export interface RPCBlockTransaction {
@@ -40,4 +66,31 @@ export interface RPCBlockTransaction {
40
66
  v: string;
41
67
  value: string;
42
68
  }
69
+ export interface RPCTransactionReceipt {
70
+ blockHash: string;
71
+ blockNumber: string;
72
+ contractAddress: string;
73
+ cumulativeGasUsed: string;
74
+ effectiveGasPrice: string;
75
+ from: string;
76
+ gasUsed: string;
77
+ logs: Array<RPCLog>;
78
+ logsBloom: string;
79
+ status: string;
80
+ to: string;
81
+ transactionHash: string;
82
+ transactionIndex: string;
83
+ type: string;
84
+ }
85
+ export interface RPCLog {
86
+ address: string;
87
+ blockHash: string;
88
+ blockNumber: string;
89
+ data: string;
90
+ logIndex: string;
91
+ removed?: boolean;
92
+ topics: Array<string>;
93
+ transactionHash: string;
94
+ transactionIndex: string;
95
+ }
43
96
  export {};
@@ -9,7 +9,8 @@ export declare type Bytes = ArrayLike<number>;
9
9
  * @example
10
10
  * '0x123'
11
11
  */
12
- export declare type BytesLike = Bytes | string | number;
12
+ export declare type BytesLike = Bytes | string;
13
+ export declare type BytesLikeWithNumber = BytesLike | number;
13
14
  export interface DataOptions {
14
15
  allowMissingPrefix?: boolean;
15
16
  hexPad?: 'left' | 'right' | null;
@@ -112,7 +113,7 @@ export declare function arrayify(value: BytesLike | Hexable | number, options?:
112
113
  * // Uint8Array(2) [ 0, 1 ]
113
114
  * ```
114
115
  */
115
- export declare function concat(arrayOfBytesLike: ReadonlyArray<BytesLike>): Uint8Array;
116
+ export declare function concat(arrayOfBytesLike: ReadonlyArray<BytesLikeWithNumber>): Uint8Array;
116
117
  export declare function stripZeros(value: BytesLike): Uint8Array;
117
118
  export declare function zeroPad(value: BytesLike, length: number): Uint8Array;
118
119
  /**
@@ -133,7 +134,7 @@ export declare function isHexString(value: any, length?: number): boolean;
133
134
  */
134
135
  export declare function hexlify(value: BytesLike | Hexable | number | bigint, options?: DataOptions): string;
135
136
  export declare function hexDataLength(data: BytesLike): number | null;
136
- export declare function hexDataSlice(data: BytesLike, offset: number, endOffset?: number): string;
137
+ export declare function hexDataSlice(data: BytesLikeWithNumber, offset: number, endOffset?: number): string;
137
138
  export declare function hexConcat(items: ReadonlyArray<BytesLike>): string;
138
139
  export declare function hexValue(value: BytesLike | Hexable | number | bigint): string;
139
140
  export declare function hexStripZeros(value: BytesLike): string;
@@ -168,4 +169,4 @@ export declare function hexStripZeros(value: BytesLike): string;
168
169
  * // Throws
169
170
  * ```
170
171
  */
171
- export declare function hexZeroPad(value: BytesLike, length: number): string;
172
+ export declare function hexZeroPad(value: BytesLikeWithNumber, length: number): string;
@@ -0,0 +1,12 @@
1
+ import { Bytes } from '../index';
2
+ /**
3
+ * Computes the EIP-191 personal message digest of message.
4
+ * Personal messages are converted to UTF-8 bytes and prefixed with \x19Ethereum Signed Message: and the length of message.
5
+ *
6
+ * @example
7
+ * ```js
8
+ * hashMessage("Hello World");
9
+ * // '0xa1de988600a42c4b4ab089b619297c17d53cffae5d5120d82d8a92d0bb3b78f2'
10
+ * ```
11
+ */
12
+ export declare function hashMessage(message: Bytes | string): string;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hashMessage = void 0;
4
+ const index_1 = require("../index");
5
+ const messagePrefix = '\x19Ethereum Signed Message:\n';
6
+ /**
7
+ * Computes the EIP-191 personal message digest of message.
8
+ * Personal messages are converted to UTF-8 bytes and prefixed with \x19Ethereum Signed Message: and the length of message.
9
+ *
10
+ * @example
11
+ * ```js
12
+ * hashMessage("Hello World");
13
+ * // '0xa1de988600a42c4b4ab089b619297c17d53cffae5d5120d82d8a92d0bb3b78f2'
14
+ * ```
15
+ */
16
+ function hashMessage(message) {
17
+ if (typeof message === 'string') {
18
+ message = (0, index_1.toUtf8Bytes)(message);
19
+ }
20
+ return (0, index_1.keccak256)((0, index_1.concat)([
21
+ (0, index_1.toUtf8Bytes)(messagePrefix),
22
+ (0, index_1.toUtf8Bytes)(String(message.length)),
23
+ message,
24
+ ]));
25
+ }
26
+ exports.hashMessage = hashMessage;
@@ -0,0 +1,2 @@
1
+ import { BytesLike } from './bytes';
2
+ export declare const keccak256: (data: BytesLike) => string;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.keccak256 = void 0;
4
+ const sha3_1 = require("sha3");
5
+ const keccak256 = (data) => {
6
+ let bufferableData;
7
+ if (typeof data === 'string') {
8
+ bufferableData = Buffer.from(data.replace(/^0x/, ''), 'hex');
9
+ }
10
+ else {
11
+ bufferableData = Buffer.from(data);
12
+ }
13
+ const keccak = new sha3_1.Keccak(256);
14
+ const addressHash = '0x' + keccak.update(bufferableData).digest('hex');
15
+ return addressHash;
16
+ };
17
+ exports.keccak256 = keccak256;
@@ -1,5 +1,4 @@
1
1
  export declare function pack(types: ReadonlyArray<string>, values: ReadonlyArray<any>): string;
2
- export declare const hashKeccak256: (data: string) => string;
3
2
  /**
4
3
  * Hashes data from Solidity using the Keccak256 algorithm.
5
4
  *
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.solidityKeccak256 = exports.hashKeccak256 = exports.pack = void 0;
3
+ exports.solidityKeccak256 = exports.pack = void 0;
4
4
  const buffer_1 = require("buffer");
5
- const sha3_1 = require("sha3");
6
5
  const encode_decode_transaction_1 = require("../classes/utils/encode-decode-transaction");
7
6
  const logger_1 = require("../logger/logger");
8
7
  const tiny_big_1 = require("../shared/tiny-big/tiny-big");
9
8
  const bytes_1 = require("./bytes");
9
+ const keccak256_1 = require("./keccak256");
10
10
  const regexBytes = new RegExp('^bytes([0-9]+)$');
11
11
  const regexNumber = new RegExp('^(u?int)([0-9]*)$');
12
12
  const regexArray = new RegExp('^(.*)\\[([0-9]*)\\]$');
@@ -85,13 +85,6 @@ function pack(types, values) {
85
85
  return (0, bytes_1.hexlify)((0, bytes_1.concat)(tight));
86
86
  }
87
87
  exports.pack = pack;
88
- const hashKeccak256 = (data) => {
89
- const keccak = new sha3_1.Keccak(256);
90
- const bufferableData = buffer_1.Buffer.from(data.replace(/^0x/, ''), 'hex');
91
- const addressHash = '0x' + keccak.update(bufferableData).digest('hex');
92
- return addressHash;
93
- };
94
- exports.hashKeccak256 = hashKeccak256;
95
88
  /**
96
89
  * Hashes data from Solidity using the Keccak256 algorithm.
97
90
  *
@@ -120,6 +113,6 @@ exports.hashKeccak256 = hashKeccak256;
120
113
  * ```
121
114
  */
122
115
  function solidityKeccak256(types, values) {
123
- return (0, exports.hashKeccak256)(pack(types, values));
116
+ return (0, keccak256_1.keccak256)(pack(types, values));
124
117
  }
125
118
  exports.solidityKeccak256 = solidityKeccak256;
@@ -0,0 +1 @@
1
+ export declare function toUtf8Bytes(data: string): Uint8Array;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toUtf8Bytes = void 0;
4
+ function toUtf8Bytes(data) {
5
+ return new Uint8Array(Buffer.from(data));
6
+ }
7
+ exports.toUtf8Bytes = toUtf8Bytes;
@@ -0,0 +1,2 @@
1
+ import { RPCTransactionReceipt, TransactionReceipt } from '../../types/Transaction.types';
2
+ export declare function cleanTransactionReceipt(transactionReceipt: RPCTransactionReceipt): TransactionReceipt;
@@ -0,0 +1,48 @@
1
+ import { tinyBig, toChecksumAddress } from '../..';
2
+ import { cleanTransaction } from './clean-transaction';
3
+ import { hexToDecimal } from './hex-to-decimal';
4
+ export function cleanTransactionReceipt(transactionReceipt) {
5
+ const cleanedTransaction = cleanTransaction(transactionReceipt);
6
+ const cleanedTransactionReceipt = Object.assign({}, cleanedTransaction);
7
+ Object.keys(transactionReceipt).forEach((key) => {
8
+ if (!transactionReceipt[key])
9
+ return;
10
+ switch (key) {
11
+ case 'status':
12
+ cleanedTransactionReceipt[key] = Number(hexToDecimal(transactionReceipt[key]));
13
+ break;
14
+ case 'contractAddress':
15
+ if (transactionReceipt[key]) {
16
+ cleanedTransactionReceipt[key] = toChecksumAddress(transactionReceipt[key]);
17
+ }
18
+ break;
19
+ case 'cumulativeGasUsed':
20
+ case 'effectiveGasPrice':
21
+ case 'gasUsed':
22
+ cleanedTransactionReceipt[key] = tinyBig(hexToDecimal(transactionReceipt[key]));
23
+ break;
24
+ case 'logs':
25
+ transactionReceipt[key].forEach((log, index) => {
26
+ Object.keys(log).forEach((logKey) => {
27
+ switch (logKey) {
28
+ case 'address':
29
+ cleanedTransactionReceipt[key][index][logKey] =
30
+ toChecksumAddress(log[logKey]);
31
+ break;
32
+ case 'blockNumber':
33
+ case 'logIndex':
34
+ case 'transactionIndex':
35
+ cleanedTransactionReceipt[key][index][logKey] = Number(hexToDecimal(log[logKey]));
36
+ break;
37
+ case 'removed':
38
+ delete log[logKey];
39
+ break;
40
+ }
41
+ });
42
+ });
43
+ }
44
+ });
45
+ cleanedTransactionReceipt.byzantium =
46
+ cleanedTransactionReceipt.blockNumber >= 4370000;
47
+ return cleanedTransactionReceipt;
48
+ }
@@ -1,5 +1,5 @@
1
1
  export declare function post(url: string, body: Record<string, unknown>): Promise<any>;
2
- declare type RPCMethodName = 'eth_getBlockByNumber' | 'eth_getBlockByHash' | 'eth_call' | 'eth_chainId' | 'eth_gasPrice' | 'eth_getBalance' | 'eth_getTransactionByHash' | 'eth_getTransactionCount';
2
+ declare type RPCMethodName = 'eth_getBlockByNumber' | 'eth_getBlockByHash' | 'eth_call' | 'eth_chainId' | 'eth_gasPrice' | 'eth_getBalance' | 'eth_getTransactionByHash' | 'eth_getTransactionReceipt' | 'eth_getTransactionCount';
3
3
  export declare function buildRPCPostBody(method: RPCMethodName, params: unknown[]): {
4
4
  jsonrpc: string;
5
5
  id: number;
@@ -11,7 +11,10 @@ import { etherToWei } from './utils/ether-to-wei';
11
11
  import { gweiToEther } from './utils/gwei-to-ether';
12
12
  import { isAddress } from './utils/is-address';
13
13
  import { toChecksumAddress } from './utils/to-checksum-address';
14
+ import { toUtf8Bytes } from './utils/to-utf8-bytes';
14
15
  import { weiToEther } from './utils/wei-to-ether';
15
16
  export * from './utils/bytes';
17
+ export * from './utils/hash-message';
18
+ export * from './utils/keccak256';
16
19
  export * from './utils/solidity-keccak256';
17
- export { etherToWei, etherToGwei, isAddress, jsonRpcProvider, JsonRpcProvider, FallthroughProvider, tinyBig, toChecksumAddress, weiToEther, gweiToEther, Contract, TinyBig, BlockResponse, ContractTypes, JSONABI, JSONABIArgument, Network, TransactionResponse, };
20
+ export { etherToWei, etherToGwei, isAddress, jsonRpcProvider, JsonRpcProvider, FallthroughProvider, tinyBig, toChecksumAddress, weiToEther, gweiToEther, toUtf8Bytes, Contract, TinyBig, BlockResponse, ContractTypes, JSONABI, JSONABIArgument, Network, TransactionResponse, };
package/lib/esm/index.js CHANGED
@@ -7,7 +7,10 @@ import { etherToWei } from './utils/ether-to-wei';
7
7
  import { gweiToEther } from './utils/gwei-to-ether';
8
8
  import { isAddress } from './utils/is-address';
9
9
  import { toChecksumAddress } from './utils/to-checksum-address';
10
+ import { toUtf8Bytes } from './utils/to-utf8-bytes';
10
11
  import { weiToEther } from './utils/wei-to-ether';
11
12
  export * from './utils/bytes';
13
+ export * from './utils/hash-message';
14
+ export * from './utils/keccak256';
12
15
  export * from './utils/solidity-keccak256';
13
- export { etherToWei, etherToGwei, isAddress, jsonRpcProvider, JsonRpcProvider, FallthroughProvider, tinyBig, toChecksumAddress, weiToEther, gweiToEther, Contract, TinyBig, };
16
+ export { etherToWei, etherToGwei, isAddress, jsonRpcProvider, JsonRpcProvider, FallthroughProvider, tinyBig, toChecksumAddress, weiToEther, gweiToEther, toUtf8Bytes, Contract, TinyBig, };
@@ -1 +1 @@
1
- export declare const version = "0.5.4-alpha.0";
1
+ export declare const version = "0.5.4";
@@ -1 +1 @@
1
- export const version = '0.5.4-alpha.0';
1
+ export const version = '0.5.4';
@@ -1,7 +1,7 @@
1
1
  import { TinyBig } from '../shared/tiny-big/tiny-big';
2
2
  import { BlockResponse, BlockTag } from '../types/Block.types';
3
3
  import { Network } from '../types/Network.types';
4
- import { TransactionResponse } from '../types/Transaction.types';
4
+ import { TransactionReceipt, TransactionResponse } from '../types/Transaction.types';
5
5
  export declare abstract class BaseProvider {
6
6
  abstract selectRpcUrl(): string;
7
7
  abstract post(body: Record<string, unknown>): Promise<any>;
@@ -10,6 +10,7 @@ export declare abstract class BaseProvider {
10
10
  constructor(rpcUrls: string[]);
11
11
  getNetwork(): Promise<Network>;
12
12
  getTransaction(transactionHash: string): Promise<TransactionResponse>;
13
+ getTransactionReceipt(transactionHash: string): Promise<TransactionReceipt>;
13
14
  getTransactionCount(address: string, blockTag?: BlockTag): Promise<number>;
14
15
  getBlock(timeFrame?: BlockTag, returnTransactionObjects?: boolean): Promise<BlockResponse>;
15
16
  getGasPrice(): Promise<TinyBig>;
@@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { cleanBlock } from '../classes/utils/clean-block';
11
11
  import { cleanTransaction } from '../classes/utils/clean-transaction';
12
+ import { cleanTransactionReceipt } from '../classes/utils/clean-transaction-receipt';
12
13
  import { buildRPCPostBody, post } from '../classes/utils/fetchers';
13
14
  import { hexToDecimal } from '../classes/utils/hex-to-decimal';
14
15
  import { tinyBig } from '../shared/tiny-big/tiny-big';
@@ -43,6 +44,18 @@ export class BaseProvider {
43
44
  return cleanedTransaction;
44
45
  });
45
46
  }
47
+ getTransactionReceipt(transactionHash) {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ const [rpcTransaction, blockNumber] = yield Promise.all([
50
+ this.post(buildRPCPostBody('eth_getTransactionReceipt', [transactionHash])),
51
+ this.getBlock('latest'),
52
+ ]);
53
+ const cleanedTransactionReceipt = cleanTransactionReceipt(rpcTransaction);
54
+ cleanedTransactionReceipt.confirmations =
55
+ blockNumber.number - cleanedTransactionReceipt.blockNumber + 1;
56
+ return cleanedTransactionReceipt;
57
+ });
58
+ }
46
59
  getTransactionCount(address, blockTag = 'latest') {
47
60
  return __awaiter(this, void 0, void 0, function* () {
48
61
  if (typeof blockTag === 'number') {
@@ -20,6 +20,24 @@ export declare type TransactionResponse = Modify<RPCTransaction, {
20
20
  maxPriorityFeePerGas: TinyBig;
21
21
  confirmations: number;
22
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
+ }>;
23
41
  export declare type BlockTransactionResponse = Omit<TransactionResponse, 'maxFeePerGas' | 'maxPriorityFeePerGas'>;
24
42
  export interface RPCBlockTransaction {
25
43
  blockHash: string;
@@ -39,4 +57,31 @@ export interface RPCBlockTransaction {
39
57
  v: string;
40
58
  value: string;
41
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
+ }
42
87
  export {};
@@ -1,5 +1,6 @@
1
1
  export declare type Bytes = ArrayLike<number>;
2
- export declare type BytesLike = Bytes | string | number;
2
+ export declare type BytesLike = Bytes | string;
3
+ export declare type BytesLikeWithNumber = BytesLike | number;
3
4
  export interface DataOptions {
4
5
  allowMissingPrefix?: boolean;
5
6
  hexPad?: 'left' | 'right' | null;
@@ -26,14 +27,14 @@ export interface Signature {
26
27
  export declare function isBytesLike(value: any): value is BytesLike;
27
28
  export declare function isBytes(value: any): value is Bytes;
28
29
  export declare function arrayify(value: BytesLike | Hexable | number, options?: DataOptions): Uint8Array;
29
- export declare function concat(arrayOfBytesLike: ReadonlyArray<BytesLike>): Uint8Array;
30
+ export declare function concat(arrayOfBytesLike: ReadonlyArray<BytesLikeWithNumber>): Uint8Array;
30
31
  export declare function stripZeros(value: BytesLike): Uint8Array;
31
32
  export declare function zeroPad(value: BytesLike, length: number): Uint8Array;
32
33
  export declare function isHexString(value: any, length?: number): boolean;
33
34
  export declare function hexlify(value: BytesLike | Hexable | number | bigint, options?: DataOptions): string;
34
35
  export declare function hexDataLength(data: BytesLike): number | null;
35
- export declare function hexDataSlice(data: BytesLike, offset: number, endOffset?: number): string;
36
+ export declare function hexDataSlice(data: BytesLikeWithNumber, offset: number, endOffset?: number): string;
36
37
  export declare function hexConcat(items: ReadonlyArray<BytesLike>): string;
37
38
  export declare function hexValue(value: BytesLike | Hexable | number | bigint): string;
38
39
  export declare function hexStripZeros(value: BytesLike): string;
39
- export declare function hexZeroPad(value: BytesLike, length: number): string;
40
+ export declare function hexZeroPad(value: BytesLikeWithNumber, length: number): string;
@@ -0,0 +1,2 @@
1
+ import { Bytes } from '../index';
2
+ export declare function hashMessage(message: Bytes | string): string;
@@ -0,0 +1,12 @@
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
+ }
@@ -0,0 +1,2 @@
1
+ import { BytesLike } from './bytes';
2
+ export declare const keccak256: (data: BytesLike) => string;
@@ -0,0 +1,13 @@
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
+ };
@@ -1,3 +1,2 @@
1
1
  export declare function pack(types: ReadonlyArray<string>, values: ReadonlyArray<any>): string;
2
- export declare const hashKeccak256: (data: string) => string;
3
2
  export declare function solidityKeccak256(types: ReadonlyArray<string>, values: ReadonlyArray<any>): string;
@@ -1,9 +1,9 @@
1
1
  import { Buffer } from 'buffer';
2
- import { Keccak } from 'sha3';
3
2
  import { hexFalse } from '../classes/utils/encode-decode-transaction';
4
3
  import { logger } from '../logger/logger';
5
4
  import { tinyBig } from '../shared/tiny-big/tiny-big';
6
5
  import { arrayify, concat, hexlify, zeroPad } from './bytes';
6
+ import { keccak256 } from './keccak256';
7
7
  const regexBytes = new RegExp('^bytes([0-9]+)$');
8
8
  const regexNumber = new RegExp('^(u?int)([0-9]*)$');
9
9
  const regexArray = new RegExp('^(.*)\\[([0-9]*)\\]$');
@@ -80,12 +80,6 @@ export function pack(types, values) {
80
80
  });
81
81
  return hexlify(concat(tight));
82
82
  }
83
- export const hashKeccak256 = (data) => {
84
- const keccak = new Keccak(256);
85
- const bufferableData = Buffer.from(data.replace(/^0x/, ''), 'hex');
86
- const addressHash = '0x' + keccak.update(bufferableData).digest('hex');
87
- return addressHash;
88
- };
89
83
  export function solidityKeccak256(types, values) {
90
- return hashKeccak256(pack(types, values));
84
+ return keccak256(pack(types, values));
91
85
  }
@@ -0,0 +1 @@
1
+ export declare function toUtf8Bytes(data: string): Uint8Array;
@@ -0,0 +1,3 @@
1
+ export function toUtf8Bytes(data) {
2
+ return new Uint8Array(Buffer.from(data));
3
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "essential-eth",
3
3
  "description": "Ultralight JS library for Ethereum utilities",
4
- "version": "0.5.4-alpha.0",
4
+ "version": "0.5.4",
5
5
  "license": "MIT",
6
6
  "sideEffects": false,
7
7
  "main": "./lib/cjs/index.js",
@@ -59,7 +59,7 @@
59
59
  "ts-jest": "^27.1.4",
60
60
  "ts-node": "^10.2.1",
61
61
  "typedoc": "^0.22.13",
62
- "typescript": "^4.6.3",
62
+ "typescript": "^4.6.4",
63
63
  "web3": "^1.7.3"
64
64
  },
65
65
  "dependencies": {
package/readme.md CHANGED
@@ -650,5 +650,9 @@ Any function on a contract. Returns are the same as `ethers.js`, except that ins
650
650
 
651
651
  <br/>
652
652
 
653
+ ![Alt](https://repobeats.axiom.co/api/embed/e479d8f777288a94cdde2fe3cdedf38d5243793d.svg 'Repobeats analytics image')
654
+
655
+ <br/>
656
+
653
657
  - [📓 View full docs](https://essential-eth.vercel.app)
654
658
  - [📓 View changelog (by looking at releases diff)](https://github.com/dawsbot/essential-eth/releases)