essential-eth 0.5.4-alpha.0 → 0.5.6
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/classes/utils/clean-transaction-receipt.d.ts +5 -0
- package/lib/cjs/classes/utils/clean-transaction-receipt.js +55 -0
- package/lib/cjs/classes/utils/fetchers.d.ts +1 -1
- package/lib/cjs/index.d.ts +13 -5
- package/lib/cjs/index.js +15 -1
- package/lib/cjs/logger/package-version.d.ts +1 -1
- package/lib/cjs/logger/package-version.js +1 -1
- package/lib/cjs/providers/BaseProvider.d.ts +44 -1
- package/lib/cjs/providers/BaseProvider.js +65 -0
- package/lib/cjs/providers/FallthroughProvider.d.ts +1 -2
- package/lib/cjs/providers/types.d.ts +7 -0
- package/lib/cjs/providers/types.js +2 -0
- package/lib/cjs/providers/utils/chains-info.d.ts +16 -0
- package/lib/cjs/providers/utils/chains-info.js +50 -2
- package/lib/cjs/types/Transaction.types.d.ts +53 -0
- package/lib/cjs/utils/bytes.d.ts +5 -4
- package/lib/cjs/utils/compute-address.d.ts +8 -0
- package/lib/cjs/utils/compute-address.js +24 -0
- package/lib/cjs/utils/compute-public-key.d.ts +9 -0
- package/lib/cjs/utils/compute-public-key.js +17 -0
- package/lib/cjs/utils/hash-message.d.ts +12 -0
- package/lib/cjs/utils/hash-message.js +26 -0
- package/lib/cjs/utils/keccak256.d.ts +2 -0
- package/lib/cjs/utils/keccak256.js +17 -0
- package/lib/cjs/utils/solidity-keccak256.d.ts +0 -1
- package/lib/cjs/utils/solidity-keccak256.js +3 -10
- package/lib/cjs/utils/split-signature.d.ts +26 -0
- package/lib/cjs/utils/split-signature.js +165 -0
- package/lib/cjs/utils/to-utf8-bytes.d.ts +1 -0
- package/lib/cjs/utils/to-utf8-bytes.js +7 -0
- package/lib/cjs/utils/wei-to-ether.js +12 -2
- package/lib/esm/classes/utils/clean-transaction-receipt.d.ts +2 -0
- package/lib/esm/classes/utils/clean-transaction-receipt.js +48 -0
- package/lib/esm/classes/utils/fetchers.d.ts +1 -1
- package/lib/esm/index.d.ts +13 -5
- package/lib/esm/index.js +11 -3
- package/lib/esm/logger/package-version.d.ts +1 -1
- package/lib/esm/logger/package-version.js +1 -1
- package/lib/esm/providers/BaseProvider.d.ts +5 -1
- package/lib/esm/providers/BaseProvider.js +26 -0
- package/lib/esm/providers/FallthroughProvider.d.ts +1 -2
- package/lib/esm/providers/types.d.ts +7 -0
- package/lib/esm/providers/types.js +1 -0
- package/lib/esm/providers/utils/chains-info.d.ts +16 -0
- package/lib/esm/providers/utils/chains-info.js +50 -2
- package/lib/esm/types/Transaction.types.d.ts +45 -0
- package/lib/esm/utils/bytes.d.ts +5 -4
- package/lib/esm/utils/compute-address.d.ts +1 -0
- package/lib/esm/utils/compute-address.js +11 -0
- package/lib/esm/utils/compute-public-key.d.ts +2 -0
- package/lib/esm/utils/compute-public-key.js +6 -0
- package/lib/esm/utils/hash-message.d.ts +2 -0
- package/lib/esm/utils/hash-message.js +12 -0
- package/lib/esm/utils/keccak256.d.ts +2 -0
- package/lib/esm/utils/keccak256.js +13 -0
- package/lib/esm/utils/solidity-keccak256.d.ts +0 -1
- package/lib/esm/utils/solidity-keccak256.js +2 -8
- package/lib/esm/utils/split-signature.d.ts +2 -0
- package/lib/esm/utils/split-signature.js +126 -0
- package/lib/esm/utils/to-utf8-bytes.d.ts +1 -0
- package/lib/esm/utils/to-utf8-bytes.js +3 -0
- package/lib/esm/utils/wei-to-ether.js +11 -2
- package/package.json +14 -11
- package/readme.md +619 -93
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes the address that corresponds to a specified public or private key
|
|
3
|
+
*
|
|
4
|
+
* @param key the public or private key to find the address related to
|
|
5
|
+
*
|
|
6
|
+
* @returns the address that corresponds to the key specified
|
|
7
|
+
*/
|
|
8
|
+
export declare function computeAddress(key: string): string;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.computeAddress = void 0;
|
|
4
|
+
const __1 = require("..");
|
|
5
|
+
const bytes_1 = require("./bytes");
|
|
6
|
+
const keccak256_1 = require("./keccak256");
|
|
7
|
+
/**
|
|
8
|
+
* Computes the address that corresponds to a specified public or private key
|
|
9
|
+
*
|
|
10
|
+
* @param key the public or private key to find the address related to
|
|
11
|
+
*
|
|
12
|
+
* @returns the address that corresponds to the key specified
|
|
13
|
+
*/
|
|
14
|
+
function computeAddress(key) {
|
|
15
|
+
// compressed public keys start with 0x04
|
|
16
|
+
// uncompressed public keys start with 0x03 or 0x02
|
|
17
|
+
if (!key.startsWith('0x04') &&
|
|
18
|
+
!key.startsWith('0x03') &&
|
|
19
|
+
!key.startsWith('0x02')) {
|
|
20
|
+
key = (0, __1.computePublicKey)(key);
|
|
21
|
+
}
|
|
22
|
+
return (0, __1.toChecksumAddress)((0, bytes_1.hexDataSlice)((0, keccak256_1.keccak256)((0, bytes_1.hexDataSlice)(key, 1)), 12));
|
|
23
|
+
}
|
|
24
|
+
exports.computeAddress = computeAddress;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BytesLike } from './bytes';
|
|
2
|
+
/**
|
|
3
|
+
* Computes the public key from a given private key
|
|
4
|
+
*
|
|
5
|
+
* @param key the private key to find a public key from
|
|
6
|
+
*
|
|
7
|
+
* @returns the public key
|
|
8
|
+
*/
|
|
9
|
+
export declare function computePublicKey(privKey: BytesLike): string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.computePublicKey = void 0;
|
|
4
|
+
const secp256k1_1 = require("@noble/secp256k1");
|
|
5
|
+
const bytes_1 = require("./bytes");
|
|
6
|
+
/**
|
|
7
|
+
* Computes the public key from a given private key
|
|
8
|
+
*
|
|
9
|
+
* @param key the private key to find a public key from
|
|
10
|
+
*
|
|
11
|
+
* @returns the public key
|
|
12
|
+
*/
|
|
13
|
+
function computePublicKey(privKey) {
|
|
14
|
+
privKey = (0, bytes_1.hexlify)(privKey).slice(2);
|
|
15
|
+
return '0x' + secp256k1_1.Point.fromPrivateKey(privKey).toHex();
|
|
16
|
+
}
|
|
17
|
+
exports.computePublicKey = computePublicKey;
|
|
@@ -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,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,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.solidityKeccak256 = exports.
|
|
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,
|
|
116
|
+
return (0, keccak256_1.keccak256)(pack(types, values));
|
|
124
117
|
}
|
|
125
118
|
exports.solidityKeccak256 = solidityKeccak256;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Signature, SignatureLike } from './bytes';
|
|
2
|
+
/**
|
|
3
|
+
* Expands a signature into the full signature object and fills in missing properties.
|
|
4
|
+
*
|
|
5
|
+
* * Same as ["splitSignature" in ethers.js](https://docs.ethers.io/v5/api/utils/bytes/#utils-splitSignature)
|
|
6
|
+
*
|
|
7
|
+
* @param signature the signature object to split, parse, and compute missing properties from
|
|
8
|
+
*
|
|
9
|
+
* @returns a full signature object with all properties filled
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```javascript
|
|
13
|
+
* const signature = '0x60bc4ed91f2021aefe7045f3f77bd12f87eb733aee24bd1965343b3c27b3971647252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee331b';
|
|
14
|
+
* splitSignature(signature);
|
|
15
|
+
* {
|
|
16
|
+
* r: "0x60bc4ed91f2021aefe7045f3f77bd12f87eb733aee24bd1965343b3c27b39716",
|
|
17
|
+
* s: "0x47252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33",
|
|
18
|
+
* _vs: "0x47252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33",
|
|
19
|
+
* recoveryParam: 0,
|
|
20
|
+
* v: 27,
|
|
21
|
+
* yParityAndS: "0x47252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33",
|
|
22
|
+
* compact: "0x60bc4ed91f2021aefe7045f3f77bd12f87eb733aee24bd1965343b3c27b3971647252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33"
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function splitSignature(signature: SignatureLike): Signature;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.splitSignature = void 0;
|
|
4
|
+
const logger_1 = require("./../logger/logger");
|
|
5
|
+
const bytes_1 = require("./bytes");
|
|
6
|
+
/**
|
|
7
|
+
* Expands a signature into the full signature object and fills in missing properties.
|
|
8
|
+
*
|
|
9
|
+
* * Same as ["splitSignature" in ethers.js](https://docs.ethers.io/v5/api/utils/bytes/#utils-splitSignature)
|
|
10
|
+
*
|
|
11
|
+
* @param signature the signature object to split, parse, and compute missing properties from
|
|
12
|
+
*
|
|
13
|
+
* @returns a full signature object with all properties filled
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```javascript
|
|
17
|
+
* const signature = '0x60bc4ed91f2021aefe7045f3f77bd12f87eb733aee24bd1965343b3c27b3971647252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee331b';
|
|
18
|
+
* splitSignature(signature);
|
|
19
|
+
* {
|
|
20
|
+
* r: "0x60bc4ed91f2021aefe7045f3f77bd12f87eb733aee24bd1965343b3c27b39716",
|
|
21
|
+
* s: "0x47252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33",
|
|
22
|
+
* _vs: "0x47252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33",
|
|
23
|
+
* recoveryParam: 0,
|
|
24
|
+
* v: 27,
|
|
25
|
+
* yParityAndS: "0x47252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33",
|
|
26
|
+
* compact: "0x60bc4ed91f2021aefe7045f3f77bd12f87eb733aee24bd1965343b3c27b3971647252185b7d2abb411b01b5d1ac4ab41ea486df1e9b396758c1aec6c1b6eee33"
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
function splitSignature(signature) {
|
|
31
|
+
const result = {
|
|
32
|
+
r: '0x',
|
|
33
|
+
s: '0x',
|
|
34
|
+
_vs: '0x',
|
|
35
|
+
recoveryParam: 0,
|
|
36
|
+
v: 0,
|
|
37
|
+
yParityAndS: '0x',
|
|
38
|
+
compact: '0x',
|
|
39
|
+
};
|
|
40
|
+
if ((0, bytes_1.isBytesLike)(signature)) {
|
|
41
|
+
const bytes = (0, bytes_1.arrayify)(signature);
|
|
42
|
+
// Get the r, s and v
|
|
43
|
+
if (bytes.length === 64) {
|
|
44
|
+
// EIP-2098; pull the v from the top bit of s and clear it
|
|
45
|
+
result.v = 27 + (bytes[32] >> 7);
|
|
46
|
+
bytes[32] &= 0x7f;
|
|
47
|
+
result.r = (0, bytes_1.hexlify)(bytes.slice(0, 32));
|
|
48
|
+
result.s = (0, bytes_1.hexlify)(bytes.slice(32, 64));
|
|
49
|
+
}
|
|
50
|
+
else if (bytes.length === 65) {
|
|
51
|
+
result.r = (0, bytes_1.hexlify)(bytes.slice(0, 32));
|
|
52
|
+
result.s = (0, bytes_1.hexlify)(bytes.slice(32, 64));
|
|
53
|
+
result.v = bytes[64];
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
logger_1.logger.throwArgumentError('invalid signature string', 'signature', signature);
|
|
57
|
+
}
|
|
58
|
+
// Allow a recid to be used as the v
|
|
59
|
+
if (result.v < 27) {
|
|
60
|
+
if (result.v === 0 || result.v === 1) {
|
|
61
|
+
result.v += 27;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
logger_1.logger.throwArgumentError('signature invalid v byte', 'signature', signature);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// Compute recoveryParam from v
|
|
68
|
+
result.recoveryParam = 1 - (result.v % 2);
|
|
69
|
+
// Compute _vs from recoveryParam and s
|
|
70
|
+
if (result.recoveryParam) {
|
|
71
|
+
bytes[32] |= 0x80;
|
|
72
|
+
}
|
|
73
|
+
result._vs = (0, bytes_1.hexlify)(bytes.slice(32, 64));
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
result.r = signature.r;
|
|
77
|
+
result.s = signature.s;
|
|
78
|
+
result.v = signature.v;
|
|
79
|
+
result.recoveryParam = signature.recoveryParam;
|
|
80
|
+
result._vs = signature._vs;
|
|
81
|
+
// If the _vs is available, use it to populate missing s, v and recoveryParam
|
|
82
|
+
// and verify non-missing s, v and recoveryParam
|
|
83
|
+
if (result._vs != null) {
|
|
84
|
+
const vs_1 = (0, bytes_1.zeroPad)((0, bytes_1.arrayify)(result._vs), 32);
|
|
85
|
+
result._vs = (0, bytes_1.hexlify)(vs_1);
|
|
86
|
+
// Set or check the recid
|
|
87
|
+
const recoveryParam = vs_1[0] >= 128 ? 1 : 0;
|
|
88
|
+
if (result.recoveryParam == null) {
|
|
89
|
+
result.recoveryParam = recoveryParam;
|
|
90
|
+
}
|
|
91
|
+
else if (result.recoveryParam !== recoveryParam) {
|
|
92
|
+
logger_1.logger.throwArgumentError('signature recoveryParam mismatch _vs', 'signature', signature);
|
|
93
|
+
}
|
|
94
|
+
// Set or check the s
|
|
95
|
+
vs_1[0] &= 0x7f;
|
|
96
|
+
const s = (0, bytes_1.hexlify)(vs_1);
|
|
97
|
+
if (result.s == null) {
|
|
98
|
+
result.s = s;
|
|
99
|
+
}
|
|
100
|
+
else if (result.s !== s) {
|
|
101
|
+
logger_1.logger.throwArgumentError('signature v mismatch _vs', 'signature', signature);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
// Use recid and v to populate each other
|
|
105
|
+
if (result.recoveryParam == null) {
|
|
106
|
+
if (result.v == null) {
|
|
107
|
+
logger_1.logger.throwArgumentError('signature missing v and recoveryParam', 'signature', signature);
|
|
108
|
+
}
|
|
109
|
+
else if (result.v === 0 || result.v === 1) {
|
|
110
|
+
result.recoveryParam = result.v;
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
result.recoveryParam = 1 - (result.v % 2);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
if (result.v == null) {
|
|
118
|
+
result.v = 27 + result.recoveryParam;
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
const recId = result.v === 0 || result.v === 1 ? result.v : 1 - (result.v % 2);
|
|
122
|
+
if (result.recoveryParam !== recId) {
|
|
123
|
+
logger_1.logger.throwArgumentError('signature recoveryParam mismatch v', 'signature', signature);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (result.r == null || !(0, bytes_1.isHexString)(result.r)) {
|
|
128
|
+
logger_1.logger.throwArgumentError('signature missing or invalid r', 'signature', signature);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
result.r = (0, bytes_1.hexZeroPad)(result.r, 32);
|
|
132
|
+
}
|
|
133
|
+
if (result.s == null || !(0, bytes_1.isHexString)(result.s)) {
|
|
134
|
+
logger_1.logger.throwArgumentError('signature missing or invalid s', 'signature', signature);
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
result.s = (0, bytes_1.hexZeroPad)(result.s, 32);
|
|
138
|
+
}
|
|
139
|
+
const vs = (0, bytes_1.arrayify)(result.s);
|
|
140
|
+
if (vs[0] >= 128) {
|
|
141
|
+
logger_1.logger.throwArgumentError('signature s out of range', 'signature', signature);
|
|
142
|
+
}
|
|
143
|
+
if (result.recoveryParam) {
|
|
144
|
+
vs[0] |= 0x80;
|
|
145
|
+
}
|
|
146
|
+
const _vs = (0, bytes_1.hexlify)(vs);
|
|
147
|
+
if (result._vs) {
|
|
148
|
+
if (!(0, bytes_1.isHexString)(result._vs)) {
|
|
149
|
+
logger_1.logger.throwArgumentError('signature invalid _vs', 'signature', signature);
|
|
150
|
+
}
|
|
151
|
+
result._vs = (0, bytes_1.hexZeroPad)(result._vs, 32);
|
|
152
|
+
}
|
|
153
|
+
// Set or check the _vs
|
|
154
|
+
if (result._vs == null) {
|
|
155
|
+
result._vs = _vs;
|
|
156
|
+
}
|
|
157
|
+
else if (result._vs !== _vs) {
|
|
158
|
+
logger_1.logger.throwArgumentError('signature _vs mismatch v and s', 'signature', signature);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
result.yParityAndS = result._vs;
|
|
162
|
+
result.compact = result.r + result.yParityAndS.substring(2);
|
|
163
|
+
return result;
|
|
164
|
+
}
|
|
165
|
+
exports.splitSignature = splitSignature;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function toUtf8Bytes(data: string): Uint8Array;
|
|
@@ -28,7 +28,17 @@ const validate_type_1 = require("../shared/validate-type");
|
|
|
28
28
|
*/
|
|
29
29
|
function weiToEther(weiQuantity) {
|
|
30
30
|
(0, validate_type_1.validateType)(weiQuantity, ['string', 'number', 'object']);
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
// eslint-disable-next-line no-useless-catch
|
|
32
|
+
try {
|
|
33
|
+
let _weiQuantity = weiQuantity;
|
|
34
|
+
if (typeof weiQuantity === 'string' && weiQuantity.slice(0, 2) === '0x') {
|
|
35
|
+
_weiQuantity = BigInt(weiQuantity).toString();
|
|
36
|
+
}
|
|
37
|
+
const result = (0, tiny_big_1.tinyBig)(_weiQuantity).div('1000000000000000000');
|
|
38
|
+
return (0, tiny_big_1.tinyBig)(result);
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
33
43
|
}
|
|
34
44
|
exports.weiToEther = weiToEther;
|
|
@@ -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' | 'eth_blockNumber' | 'eth_estimateGas';
|
|
3
3
|
export declare function buildRPCPostBody(method: RPCMethodName, params: unknown[]): {
|
|
4
4
|
jsonrpc: string;
|
|
5
5
|
id: number;
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -1,17 +1,25 @@
|
|
|
1
|
-
import { Contract } from './classes/Contract';
|
|
2
|
-
import { FallthroughProvider } from './providers/FallthroughProvider';
|
|
1
|
+
import { BaseContract, Contract } from './classes/Contract';
|
|
2
|
+
import { ConstructorOptions, FallthroughProvider } from './providers/FallthroughProvider';
|
|
3
3
|
import { JsonRpcProvider, jsonRpcProvider } from './providers/JsonRpcProvider';
|
|
4
4
|
import { tinyBig, TinyBig } from './shared/tiny-big/tiny-big';
|
|
5
|
-
import { BlockResponse } from './types/Block.types';
|
|
5
|
+
import { BlockResponse, BlockTag, RPCBlock } from './types/Block.types';
|
|
6
6
|
import { ContractTypes, JSONABI, JSONABIArgument } from './types/Contract.types';
|
|
7
7
|
import { Network } from './types/Network.types';
|
|
8
|
-
import { TransactionResponse } from './types/Transaction.types';
|
|
8
|
+
import { BlockTransactionResponse, Log, RPCLog, RPCTransaction, RPCTransactionReceipt, TransactionReceipt, TransactionResponse } from './types/Transaction.types';
|
|
9
|
+
import { computeAddress } from './utils/compute-address';
|
|
10
|
+
import { computePublicKey } from './utils/compute-public-key';
|
|
9
11
|
import { etherToGwei } from './utils/ether-to-gwei';
|
|
10
12
|
import { etherToWei } from './utils/ether-to-wei';
|
|
11
13
|
import { gweiToEther } from './utils/gwei-to-ether';
|
|
14
|
+
import { hashMessage } from './utils/hash-message';
|
|
12
15
|
import { isAddress } from './utils/is-address';
|
|
16
|
+
import { splitSignature } from './utils/split-signature';
|
|
13
17
|
import { toChecksumAddress } from './utils/to-checksum-address';
|
|
18
|
+
import { toUtf8Bytes } from './utils/to-utf8-bytes';
|
|
14
19
|
import { weiToEther } from './utils/wei-to-ether';
|
|
20
|
+
export * from './providers/types';
|
|
15
21
|
export * from './utils/bytes';
|
|
22
|
+
export * from './utils/hash-message';
|
|
23
|
+
export * from './utils/keccak256';
|
|
16
24
|
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, };
|
|
25
|
+
export { etherToWei, etherToGwei, isAddress, jsonRpcProvider, JsonRpcProvider, FallthroughProvider, tinyBig, toChecksumAddress, weiToEther, gweiToEther, hashMessage, splitSignature, toUtf8Bytes, computeAddress, computePublicKey, Contract, TinyBig, BaseContract, BlockResponse, ContractTypes, JSONABI, JSONABIArgument, Network, TransactionResponse, RPCBlock, RPCTransaction, RPCTransactionReceipt, TransactionReceipt, BlockTag, RPCLog, Log, BlockTransactionResponse, ConstructorOptions, };
|
package/lib/esm/index.js
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
|
-
import { Contract } from './classes/Contract';
|
|
2
|
-
import { FallthroughProvider } from './providers/FallthroughProvider';
|
|
1
|
+
import { BaseContract, Contract } from './classes/Contract';
|
|
2
|
+
import { FallthroughProvider, } from './providers/FallthroughProvider';
|
|
3
3
|
import { JsonRpcProvider, jsonRpcProvider } from './providers/JsonRpcProvider';
|
|
4
4
|
import { tinyBig, TinyBig } from './shared/tiny-big/tiny-big';
|
|
5
|
+
import { computeAddress } from './utils/compute-address';
|
|
6
|
+
import { computePublicKey } from './utils/compute-public-key';
|
|
5
7
|
import { etherToGwei } from './utils/ether-to-gwei';
|
|
6
8
|
import { etherToWei } from './utils/ether-to-wei';
|
|
7
9
|
import { gweiToEther } from './utils/gwei-to-ether';
|
|
10
|
+
import { hashMessage } from './utils/hash-message';
|
|
8
11
|
import { isAddress } from './utils/is-address';
|
|
12
|
+
import { splitSignature } from './utils/split-signature';
|
|
9
13
|
import { toChecksumAddress } from './utils/to-checksum-address';
|
|
14
|
+
import { toUtf8Bytes } from './utils/to-utf8-bytes';
|
|
10
15
|
import { weiToEther } from './utils/wei-to-ether';
|
|
16
|
+
export * from './providers/types';
|
|
11
17
|
export * from './utils/bytes';
|
|
18
|
+
export * from './utils/hash-message';
|
|
19
|
+
export * from './utils/keccak256';
|
|
12
20
|
export * from './utils/solidity-keccak256';
|
|
13
|
-
export { etherToWei, etherToGwei, isAddress, jsonRpcProvider, JsonRpcProvider, FallthroughProvider, tinyBig, toChecksumAddress, weiToEther, gweiToEther, Contract, TinyBig, };
|
|
21
|
+
export { etherToWei, etherToGwei, isAddress, jsonRpcProvider, JsonRpcProvider, FallthroughProvider, tinyBig, toChecksumAddress, weiToEther, gweiToEther, hashMessage, splitSignature, toUtf8Bytes, computeAddress, computePublicKey, Contract, TinyBig, BaseContract, };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "0.5.
|
|
1
|
+
export declare const version = "0.5.6";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '0.5.
|
|
1
|
+
export const version = '0.5.6';
|
|
@@ -1,7 +1,8 @@
|
|
|
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
|
+
import { TransactionRequest } from './types';
|
|
5
6
|
export declare abstract class BaseProvider {
|
|
6
7
|
abstract selectRpcUrl(): string;
|
|
7
8
|
abstract post(body: Record<string, unknown>): Promise<any>;
|
|
@@ -9,9 +10,12 @@ export declare abstract class BaseProvider {
|
|
|
9
10
|
protected _post: (body: Record<string, unknown>) => Promise<any>;
|
|
10
11
|
constructor(rpcUrls: string[]);
|
|
11
12
|
getNetwork(): Promise<Network>;
|
|
13
|
+
getBlockNumber(): Promise<number>;
|
|
12
14
|
getTransaction(transactionHash: string): Promise<TransactionResponse>;
|
|
15
|
+
getTransactionReceipt(transactionHash: string): Promise<TransactionReceipt>;
|
|
13
16
|
getTransactionCount(address: string, blockTag?: BlockTag): Promise<number>;
|
|
14
17
|
getBlock(timeFrame?: BlockTag, returnTransactionObjects?: boolean): Promise<BlockResponse>;
|
|
15
18
|
getGasPrice(): Promise<TinyBig>;
|
|
16
19
|
getBalance(address: string, blockTag?: BlockTag): Promise<TinyBig>;
|
|
20
|
+
estimateGas(transaction: TransactionRequest): Promise<TinyBig>;
|
|
17
21
|
}
|
|
@@ -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';
|
|
@@ -31,6 +32,12 @@ export class BaseProvider {
|
|
|
31
32
|
};
|
|
32
33
|
});
|
|
33
34
|
}
|
|
35
|
+
getBlockNumber() {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
const currentBlockNumber = (yield this.post(buildRPCPostBody('eth_blockNumber', [])));
|
|
38
|
+
return Number(hexToDecimal(currentBlockNumber));
|
|
39
|
+
});
|
|
40
|
+
}
|
|
34
41
|
getTransaction(transactionHash) {
|
|
35
42
|
return __awaiter(this, void 0, void 0, function* () {
|
|
36
43
|
const [rpcTransaction, blockNumber] = yield Promise.all([
|
|
@@ -43,6 +50,18 @@ export class BaseProvider {
|
|
|
43
50
|
return cleanedTransaction;
|
|
44
51
|
});
|
|
45
52
|
}
|
|
53
|
+
getTransactionReceipt(transactionHash) {
|
|
54
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
const [rpcTransaction, blockNumber] = yield Promise.all([
|
|
56
|
+
this.post(buildRPCPostBody('eth_getTransactionReceipt', [transactionHash])),
|
|
57
|
+
this.getBlock('latest'),
|
|
58
|
+
]);
|
|
59
|
+
const cleanedTransactionReceipt = cleanTransactionReceipt(rpcTransaction);
|
|
60
|
+
cleanedTransactionReceipt.confirmations =
|
|
61
|
+
blockNumber.number - cleanedTransactionReceipt.blockNumber + 1;
|
|
62
|
+
return cleanedTransactionReceipt;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
46
65
|
getTransactionCount(address, blockTag = 'latest') {
|
|
47
66
|
return __awaiter(this, void 0, void 0, function* () {
|
|
48
67
|
if (typeof blockTag === 'number') {
|
|
@@ -85,4 +104,11 @@ export class BaseProvider {
|
|
|
85
104
|
return tinyBig(hexToDecimal(hexBalance));
|
|
86
105
|
});
|
|
87
106
|
}
|
|
107
|
+
estimateGas(transaction) {
|
|
108
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
const body = buildRPCPostBody('eth_estimateGas', [transaction]);
|
|
110
|
+
const gasUsed = (yield this.post(body));
|
|
111
|
+
return tinyBig(hexToDecimal(gasUsed));
|
|
112
|
+
});
|
|
113
|
+
}
|
|
88
114
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseProvider } from './BaseProvider';
|
|
2
|
-
interface ConstructorOptions {
|
|
2
|
+
export interface ConstructorOptions {
|
|
3
3
|
timeoutDuration?: number;
|
|
4
4
|
}
|
|
5
5
|
export declare class FallthroughProvider extends BaseProvider {
|
|
@@ -9,4 +9,3 @@ export declare class FallthroughProvider extends BaseProvider {
|
|
|
9
9
|
constructor(rpcUrls: string[], options?: ConstructorOptions);
|
|
10
10
|
post: (body: Record<string, unknown>) => Promise<any>;
|
|
11
11
|
}
|
|
12
|
-
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|