essential-eth 0.5.0 → 0.5.1
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.
- package/lib/cjs/index.d.ts +3 -2
- package/lib/cjs/index.js +17 -3
- package/lib/cjs/logger/logger.d.ts +11 -0
- package/lib/cjs/logger/logger.js +36 -0
- package/lib/cjs/logger/package-version.d.ts +1 -0
- package/lib/cjs/logger/package-version.js +5 -0
- package/lib/cjs/providers/JsonRpcProvider.d.ts +1 -1
- package/lib/cjs/providers/JsonRpcProvider.js +1 -1
- package/lib/cjs/providers/utils/chains-info.d.ts +4 -0
- package/lib/cjs/providers/utils/chains-info.js +12 -0
- package/lib/cjs/shared/tiny-big/tiny-big.d.ts +7 -0
- package/lib/cjs/shared/tiny-big/tiny-big.js +25 -7
- package/lib/cjs/utils/bytes.d.ts +90 -0
- package/lib/cjs/utils/bytes.js +484 -0
- package/lib/cjs/utils/solidity-keccak256.d.ts +30 -0
- package/lib/cjs/utils/solidity-keccak256.js +125 -0
- package/lib/esm/index.d.ts +3 -2
- package/lib/esm/index.js +3 -2
- package/lib/esm/logger/logger.d.ts +11 -0
- package/lib/esm/logger/logger.js +33 -0
- package/lib/esm/logger/package-version.d.ts +1 -0
- package/lib/esm/logger/package-version.js +1 -0
- package/lib/esm/providers/JsonRpcProvider.d.ts +1 -1
- package/lib/esm/providers/JsonRpcProvider.js +1 -1
- package/lib/esm/providers/utils/chains-info.d.ts +4 -0
- package/lib/esm/providers/utils/chains-info.js +12 -0
- package/lib/esm/shared/tiny-big/tiny-big.d.ts +2 -0
- package/lib/esm/shared/tiny-big/tiny-big.js +20 -7
- package/lib/esm/utils/bytes.d.ts +39 -0
- package/lib/esm/utils/bytes.js +245 -0
- package/lib/esm/utils/solidity-keccak256.d.ts +3 -0
- package/lib/esm/utils/solidity-keccak256.js +91 -0
- package/package.json +12 -14
- package/lib/cjs/utils/hex-zero-pad.d.ts +0 -32
- package/lib/cjs/utils/hex-zero-pad.js +0 -52
- package/lib/esm/utils/hex-zero-pad.d.ts +0 -1
- package/lib/esm/utils/hex-zero-pad.js +0 -17
package/lib/cjs/index.d.ts
CHANGED
|
@@ -8,8 +8,9 @@ import { TransactionResponse } from './types/Transaction.types';
|
|
|
8
8
|
import { etherToGwei } from './utils/ether-to-gwei';
|
|
9
9
|
import { etherToWei } from './utils/ether-to-wei';
|
|
10
10
|
import { gweiToEther } from './utils/gwei-to-ether';
|
|
11
|
-
import { hexZeroPad } from './utils/hex-zero-pad';
|
|
12
11
|
import { isAddress } from './utils/is-address';
|
|
13
12
|
import { toChecksumAddress } from './utils/to-checksum-address';
|
|
14
13
|
import { weiToEther } from './utils/wei-to-ether';
|
|
15
|
-
export
|
|
14
|
+
export * from './utils/bytes';
|
|
15
|
+
export * from './utils/solidity-keccak256';
|
|
16
|
+
export { etherToWei, etherToGwei, isAddress, jsonRpcProvider, JsonRpcProvider, tinyBig, toChecksumAddress, weiToEther, gweiToEther, Contract, TinyBig, BlockResponse, ContractTypes, JSONABI, JSONABIArgument, Network, TransactionResponse, };
|
package/lib/cjs/index.js
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TinyBig = exports.Contract = exports.
|
|
17
|
+
exports.TinyBig = exports.Contract = exports.gweiToEther = exports.weiToEther = exports.toChecksumAddress = exports.tinyBig = exports.JsonRpcProvider = exports.jsonRpcProvider = exports.isAddress = exports.etherToGwei = exports.etherToWei = void 0;
|
|
4
18
|
const Contract_1 = require("./classes/Contract");
|
|
5
19
|
Object.defineProperty(exports, "Contract", { enumerable: true, get: function () { return Contract_1.Contract; } });
|
|
6
20
|
const JsonRpcProvider_1 = require("./providers/JsonRpcProvider");
|
|
@@ -15,11 +29,11 @@ const ether_to_wei_1 = require("./utils/ether-to-wei");
|
|
|
15
29
|
Object.defineProperty(exports, "etherToWei", { enumerable: true, get: function () { return ether_to_wei_1.etherToWei; } });
|
|
16
30
|
const gwei_to_ether_1 = require("./utils/gwei-to-ether");
|
|
17
31
|
Object.defineProperty(exports, "gweiToEther", { enumerable: true, get: function () { return gwei_to_ether_1.gweiToEther; } });
|
|
18
|
-
const hex_zero_pad_1 = require("./utils/hex-zero-pad");
|
|
19
|
-
Object.defineProperty(exports, "hexZeroPad", { enumerable: true, get: function () { return hex_zero_pad_1.hexZeroPad; } });
|
|
20
32
|
const is_address_1 = require("./utils/is-address");
|
|
21
33
|
Object.defineProperty(exports, "isAddress", { enumerable: true, get: function () { return is_address_1.isAddress; } });
|
|
22
34
|
const to_checksum_address_1 = require("./utils/to-checksum-address");
|
|
23
35
|
Object.defineProperty(exports, "toChecksumAddress", { enumerable: true, get: function () { return to_checksum_address_1.toChecksumAddress; } });
|
|
24
36
|
const wei_to_ether_1 = require("./utils/wei-to-ether");
|
|
25
37
|
Object.defineProperty(exports, "weiToEther", { enumerable: true, get: function () { return wei_to_ether_1.weiToEther; } });
|
|
38
|
+
__exportStar(require("./utils/bytes"), exports);
|
|
39
|
+
__exportStar(require("./utils/solidity-keccak256"), exports);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare class Logger {
|
|
2
|
+
private packageVersion;
|
|
3
|
+
constructor();
|
|
4
|
+
throwError(message: string, args: {
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
}): never;
|
|
7
|
+
throwArgumentError(message: string, arg: string, value: any): never;
|
|
8
|
+
checkSafeUint53(value: number, message?: string): void;
|
|
9
|
+
}
|
|
10
|
+
export declare const logger: Logger;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logger = void 0;
|
|
4
|
+
const package_version_1 = require("./package-version");
|
|
5
|
+
class Logger {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.packageVersion = package_version_1.version;
|
|
8
|
+
}
|
|
9
|
+
throwError(message, args) {
|
|
10
|
+
const argsLength = Object.keys(args).length;
|
|
11
|
+
throw new Error(`${message} (${Object.entries(args).map(([key, value], index) => `${key}=${value}${index < argsLength - 1 && ', '}`)}, version=essential-eth@${this.packageVersion})`);
|
|
12
|
+
}
|
|
13
|
+
throwArgumentError(message, arg, value) {
|
|
14
|
+
throw new Error(`${message} (argument="${arg}" value=${value}, version=essential-eth@${this.packageVersion})`);
|
|
15
|
+
}
|
|
16
|
+
checkSafeUint53(value, message = 'value not safe') {
|
|
17
|
+
if (typeof value !== 'number') {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (value < 0 || value >= 0x1fffffffffffff) {
|
|
21
|
+
this.throwError(message, {
|
|
22
|
+
operation: 'checkSafeInteger',
|
|
23
|
+
fault: 'out-of-safe-range',
|
|
24
|
+
value: value,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
if (value % 1) {
|
|
28
|
+
this.throwError(message, {
|
|
29
|
+
operation: 'checkSafeInteger',
|
|
30
|
+
fault: 'non-integer',
|
|
31
|
+
value: value,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.logger = new Logger();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const version = "0.5.1";
|
|
@@ -58,7 +58,7 @@ export declare class JsonRpcProvider {
|
|
|
58
58
|
* }
|
|
59
59
|
*```
|
|
60
60
|
*/
|
|
61
|
-
getBlock(timeFrame
|
|
61
|
+
getBlock(timeFrame?: BlockTag, returnTransactionObjects?: boolean): Promise<BlockResponse>;
|
|
62
62
|
/**
|
|
63
63
|
* Returns the network this provider is connected to
|
|
64
64
|
*/
|
|
@@ -73,7 +73,7 @@ class JsonRpcProvider {
|
|
|
73
73
|
* }
|
|
74
74
|
*```
|
|
75
75
|
*/
|
|
76
|
-
getBlock(timeFrame, returnTransactionObjects = false) {
|
|
76
|
+
getBlock(timeFrame = 'latest', returnTransactionObjects = false) {
|
|
77
77
|
return __awaiter(this, void 0, void 0, function* () {
|
|
78
78
|
let rpcTimeFrame;
|
|
79
79
|
if (typeof timeFrame === 'number') {
|
|
@@ -215,6 +215,7 @@ declare const _default: {
|
|
|
215
215
|
"2153": string[];
|
|
216
216
|
"2213": string[];
|
|
217
217
|
"2221": string[];
|
|
218
|
+
"2223": string[];
|
|
218
219
|
"2559": string[];
|
|
219
220
|
"3000": string[];
|
|
220
221
|
"3001": string[];
|
|
@@ -233,6 +234,8 @@ declare const _default: {
|
|
|
233
234
|
"4918": string[];
|
|
234
235
|
"5197": string[];
|
|
235
236
|
"5315": string[];
|
|
237
|
+
"5551": string[];
|
|
238
|
+
"5553": string[];
|
|
236
239
|
"5700": string[];
|
|
237
240
|
"5777": string[];
|
|
238
241
|
"5851": string[];
|
|
@@ -351,6 +354,7 @@ declare const _default: {
|
|
|
351
354
|
"11155111": string[];
|
|
352
355
|
"13371337": string[];
|
|
353
356
|
"18289463": string[];
|
|
357
|
+
"20180430": string[];
|
|
354
358
|
"20181205": string[];
|
|
355
359
|
"28945486": string[];
|
|
356
360
|
"35855456": string[];
|
|
@@ -655,6 +655,9 @@ exports.default = {
|
|
|
655
655
|
"2221": [
|
|
656
656
|
"kava"
|
|
657
657
|
],
|
|
658
|
+
"2223": [
|
|
659
|
+
"VChain"
|
|
660
|
+
],
|
|
658
661
|
"2559": [
|
|
659
662
|
"ktoc"
|
|
660
663
|
],
|
|
@@ -709,6 +712,12 @@ exports.default = {
|
|
|
709
712
|
"5315": [
|
|
710
713
|
"UZMI"
|
|
711
714
|
],
|
|
715
|
+
"5551": [
|
|
716
|
+
"Nahmii"
|
|
717
|
+
],
|
|
718
|
+
"5553": [
|
|
719
|
+
"Nahmii testnet"
|
|
720
|
+
],
|
|
712
721
|
"5700": [
|
|
713
722
|
"tsys"
|
|
714
723
|
],
|
|
@@ -1063,6 +1072,9 @@ exports.default = {
|
|
|
1063
1072
|
"18289463": [
|
|
1064
1073
|
"ilt"
|
|
1065
1074
|
],
|
|
1075
|
+
"20180430": [
|
|
1076
|
+
"spectrum"
|
|
1077
|
+
],
|
|
1066
1078
|
"20181205": [
|
|
1067
1079
|
"qki"
|
|
1068
1080
|
],
|
|
@@ -12,6 +12,13 @@ export declare class TinyBig extends Big {
|
|
|
12
12
|
toHexString(): string;
|
|
13
13
|
toNumber(): number;
|
|
14
14
|
toString(): string;
|
|
15
|
+
/**
|
|
16
|
+
* @param {String} str
|
|
17
|
+
* @param {String} padChar
|
|
18
|
+
* @param {Number} length
|
|
19
|
+
*/
|
|
20
|
+
private padAndChop;
|
|
21
|
+
toTwos(bitCount: number): Big;
|
|
15
22
|
}
|
|
16
23
|
/**
|
|
17
24
|
* Helper factory function so that you don't have to type "new" when instantiating a new TinyBig
|
|
@@ -12,13 +12,15 @@ const helpers_1 = require("./helpers");
|
|
|
12
12
|
*/
|
|
13
13
|
class TinyBig extends big_js_1.default {
|
|
14
14
|
constructor(value) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
super(value);
|
|
16
|
+
/**
|
|
17
|
+
* @param {String} str
|
|
18
|
+
* @param {String} padChar
|
|
19
|
+
* @param {Number} length
|
|
20
|
+
*/
|
|
21
|
+
this.padAndChop = (str, padChar, length) => {
|
|
22
|
+
return (Array(length).fill(padChar).join('') + str).slice(length * -1);
|
|
23
|
+
};
|
|
22
24
|
}
|
|
23
25
|
/**
|
|
24
26
|
* Used anytime you're passing in "value" to ethers or web3
|
|
@@ -36,6 +38,22 @@ class TinyBig extends big_js_1.default {
|
|
|
36
38
|
}
|
|
37
39
|
return (0, helpers_1.scientificStrToDecimalStr)(super.toString());
|
|
38
40
|
}
|
|
41
|
+
toTwos(bitCount) {
|
|
42
|
+
let binaryStr;
|
|
43
|
+
if (this.gte(0)) {
|
|
44
|
+
const twosComp = this.toNumber().toString(2);
|
|
45
|
+
binaryStr = this.padAndChop(twosComp, '0', bitCount || twosComp.length);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
binaryStr = this.plus(Math.pow(2, bitCount)).toNumber().toString(2);
|
|
49
|
+
if (Number(binaryStr) < 0) {
|
|
50
|
+
throw new Error('Cannot calculate twos complement');
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const binary = `0b${binaryStr}`;
|
|
54
|
+
const decimal = Number(binary);
|
|
55
|
+
return tinyBig(decimal);
|
|
56
|
+
}
|
|
39
57
|
}
|
|
40
58
|
exports.TinyBig = TinyBig;
|
|
41
59
|
/**
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
export declare type Bytes = ArrayLike<number>;
|
|
2
|
+
/**
|
|
3
|
+
* @example
|
|
4
|
+
* [1,2,3]
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* 0x123
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* '0x123'
|
|
11
|
+
*/
|
|
12
|
+
export declare type BytesLike = Bytes | string | number;
|
|
13
|
+
export interface DataOptions {
|
|
14
|
+
allowMissingPrefix?: boolean;
|
|
15
|
+
hexPad?: 'left' | 'right' | null;
|
|
16
|
+
}
|
|
17
|
+
export interface Hexable {
|
|
18
|
+
toHexString(): string;
|
|
19
|
+
}
|
|
20
|
+
export declare type SignatureLike = {
|
|
21
|
+
r: string;
|
|
22
|
+
s?: string;
|
|
23
|
+
_vs?: string;
|
|
24
|
+
recoveryParam?: number;
|
|
25
|
+
v?: number;
|
|
26
|
+
} | BytesLike;
|
|
27
|
+
export interface Signature {
|
|
28
|
+
r: string;
|
|
29
|
+
s: string;
|
|
30
|
+
_vs: string;
|
|
31
|
+
recoveryParam: number;
|
|
32
|
+
v: number;
|
|
33
|
+
yParityAndS: string;
|
|
34
|
+
compact: string;
|
|
35
|
+
}
|
|
36
|
+
export declare function isBytesLike(value: any): value is BytesLike;
|
|
37
|
+
export declare function isBytes(value: any): value is Bytes;
|
|
38
|
+
export declare function arrayify(value: BytesLike | Hexable | number, options?: DataOptions): Uint8Array;
|
|
39
|
+
export declare function concat(items: ReadonlyArray<BytesLike>): Uint8Array;
|
|
40
|
+
export declare function stripZeros(value: BytesLike): Uint8Array;
|
|
41
|
+
export declare function zeroPad(value: BytesLike, length: number): Uint8Array;
|
|
42
|
+
export declare function isHexString(value: any, length?: number): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* @example
|
|
45
|
+
* ```js
|
|
46
|
+
* hexlify(4);
|
|
47
|
+
* // '0x04'
|
|
48
|
+
*
|
|
49
|
+
* hexlify(14);
|
|
50
|
+
* // '0x0e'
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare function hexlify(value: BytesLike | Hexable | number | bigint, options?: DataOptions): string;
|
|
54
|
+
export declare function hexDataLength(data: BytesLike): number | null;
|
|
55
|
+
export declare function hexDataSlice(data: BytesLike, offset: number, endOffset?: number): string;
|
|
56
|
+
export declare function hexConcat(items: ReadonlyArray<BytesLike>): string;
|
|
57
|
+
export declare function hexValue(value: BytesLike | Hexable | number | bigint): string;
|
|
58
|
+
export declare function hexStripZeros(value: BytesLike): string;
|
|
59
|
+
/**
|
|
60
|
+
* Returns a hex string padded to a specified length of bytes.
|
|
61
|
+
*
|
|
62
|
+
* Similar to ["hexZeroPad" in ethers.js](https://docs.ethers.io/v5/api/utils/bytes/#utils-hexZeroPad)
|
|
63
|
+
*
|
|
64
|
+
* Differs from ["padLeft" in web3.js](https://web3js.readthedocs.io/en/v1.7.1/web3-utils.html#padleft) because web3 counts by characters, not bytes.
|
|
65
|
+
*
|
|
66
|
+
* @param hexValue - A hex-string, hex-number, or decimal number (auto-converts to base-16) to be padded
|
|
67
|
+
* @param length - The final length in bytes
|
|
68
|
+
*
|
|
69
|
+
* @throws - If the value is not a hex string or number
|
|
70
|
+
* @throws - If the value is longer than the length
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```javascript
|
|
74
|
+
* hexZeroPad('0x60', 2);
|
|
75
|
+
* // '0x0060'
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```javascript
|
|
80
|
+
* hexZeroPad(0x60, 3);
|
|
81
|
+
* // '0x000060'
|
|
82
|
+
* ```
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```javascript
|
|
86
|
+
* hexZeroPad('12345', 1);
|
|
87
|
+
* // Throws
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export declare function hexZeroPad(value: BytesLike, length: number): string;
|