essential-eth 0.5.1 → 0.5.5
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/Contract.d.ts +3 -2
- package/lib/cjs/classes/Contract.js +3 -2
- 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/encode-decode-transaction.d.ts +1 -0
- package/lib/cjs/classes/utils/encode-decode-transaction.js +4 -4
- package/lib/cjs/classes/utils/fetchers.d.ts +1 -1
- package/lib/cjs/index.d.ts +12 -4
- package/lib/cjs/index.js +16 -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 +284 -0
- package/lib/cjs/providers/BaseProvider.js +380 -0
- package/lib/cjs/providers/FallthroughProvider.d.ts +24 -0
- package/lib/cjs/providers/FallthroughProvider.js +65 -0
- package/lib/cjs/providers/JsonRpcProvider.d.ts +4 -200
- package/lib/cjs/providers/JsonRpcProvider.js +11 -263
- package/lib/cjs/providers/test/rpc-urls.d.ts +1 -0
- package/lib/cjs/providers/test/rpc-urls.js +1 -0
- package/lib/cjs/providers/utils/chains-info.d.ts +20 -0
- package/lib/cjs/providers/utils/chains-info.js +62 -2
- package/lib/cjs/shared/tiny-big/tiny-big.d.ts +2 -2
- package/lib/cjs/shared/tiny-big/tiny-big.js +2 -2
- package/lib/cjs/types/Transaction.types.d.ts +53 -0
- package/lib/cjs/utils/bytes.d.ts +86 -4
- package/lib/cjs/utils/bytes.js +83 -3
- 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 +5 -12
- 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/esm/classes/Contract.js +1 -1
- 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/encode-decode-transaction.d.ts +1 -0
- package/lib/esm/classes/utils/encode-decode-transaction.js +2 -2
- package/lib/esm/classes/utils/fetchers.d.ts +1 -1
- package/lib/esm/index.d.ts +12 -4
- package/lib/esm/index.js +10 -2
- 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 +19 -0
- package/lib/esm/providers/BaseProvider.js +107 -0
- package/lib/esm/providers/FallthroughProvider.d.ts +11 -0
- package/lib/esm/providers/FallthroughProvider.js +41 -0
- package/lib/esm/providers/JsonRpcProvider.d.ts +4 -12
- package/lib/esm/providers/JsonRpcProvider.js +8 -69
- package/lib/esm/providers/test/rpc-urls.d.ts +1 -0
- package/lib/esm/providers/test/rpc-urls.js +1 -0
- package/lib/esm/providers/utils/chains-info.d.ts +20 -0
- package/lib/esm/providers/utils/chains-info.js +62 -2
- package/lib/esm/types/Transaction.types.d.ts +45 -0
- package/lib/esm/utils/bytes.d.ts +5 -4
- package/lib/esm/utils/bytes.js +2 -2
- 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 +4 -10
- 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/package.json +19 -14
- package/readme.md +648 -95
package/lib/cjs/utils/bytes.d.ts
CHANGED
|
@@ -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
|
|
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;
|
|
@@ -33,12 +34,93 @@ export interface Signature {
|
|
|
33
34
|
yParityAndS: string;
|
|
34
35
|
compact: string;
|
|
35
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Returns true if and only if value is a valid [Bytes](#bytes) or DataHexString
|
|
39
|
+
* * Same as [`ethers.utils.isBytesLike`](https://docs.ethers.io/v5/api/utils/bytes/#utils-isBytesLike)
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```js
|
|
43
|
+
* isBytesLike([1,2,3]);
|
|
44
|
+
* // true
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```js
|
|
49
|
+
* isBytesLike(false);
|
|
50
|
+
* // false
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```js
|
|
55
|
+
* isBytesLike(new Uint8Array(1));
|
|
56
|
+
* // true
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
36
59
|
export declare function isBytesLike(value: any): value is BytesLike;
|
|
60
|
+
/**
|
|
61
|
+
* Returns true if and only if value is a valid [Bytes](#bytes)
|
|
62
|
+
* * Same as [`ethers.utils.isBytes`](https://docs.ethers.io/v5/api/utils/bytes/#utils-isBytes)
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```js
|
|
66
|
+
* isBytes([1,2,3]);
|
|
67
|
+
* // true
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```js
|
|
72
|
+
* isBytes(false);
|
|
73
|
+
* // false
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```js
|
|
78
|
+
* isBytes(new Uint8Array(1));
|
|
79
|
+
* // true
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
37
82
|
export declare function isBytes(value: any): value is Bytes;
|
|
83
|
+
/**
|
|
84
|
+
* Converts DataHexStringOrArrayish to a Uint8Array
|
|
85
|
+
* * Same as [`ethers.utils.arrayify`](https://docs.ethers.io/v5/api/utils/bytes/#utils-arrayify)
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```js
|
|
89
|
+
* arrayify(1);
|
|
90
|
+
* // Uint8Array(1) [ 1 ]
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```js
|
|
95
|
+
* arrayify(0x1234);
|
|
96
|
+
* // Uint8Array(2) [ 18, 52 ]
|
|
97
|
+
* ```
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```js
|
|
101
|
+
* arrayify('0x1', { hexPad: 'right' });
|
|
102
|
+
* // Uint8Array(1) [ 16 ]
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
38
105
|
export declare function arrayify(value: BytesLike | Hexable | number, options?: DataOptions): Uint8Array;
|
|
39
|
-
|
|
106
|
+
/**
|
|
107
|
+
* Concatenates all the BytesLike in arrayOfBytesLike into a single Uint8Array.
|
|
108
|
+
* * Same as [`ethers.utils.concat`](https://docs.ethers.io/v5/api/utils/bytes/#utils-concat)
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```js
|
|
112
|
+
* concat([0, 1]);
|
|
113
|
+
* // Uint8Array(2) [ 0, 1 ]
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
export declare function concat(arrayOfBytesLike: ReadonlyArray<BytesLikeWithNumber>): Uint8Array;
|
|
40
117
|
export declare function stripZeros(value: BytesLike): Uint8Array;
|
|
41
118
|
export declare function zeroPad(value: BytesLike, length: number): Uint8Array;
|
|
119
|
+
/**
|
|
120
|
+
* Returns true if and only if object is a valid hex string.
|
|
121
|
+
* If length is specified and object is not a valid DataHexString of length bytes, an InvalidArgument error is thrown.
|
|
122
|
+
* * Same as [`ethers.utils.isHexString`](https://docs.ethers.io/v5/api/utils/bytes/#utils-isHexString)
|
|
123
|
+
*/
|
|
42
124
|
export declare function isHexString(value: any, length?: number): boolean;
|
|
43
125
|
/**
|
|
44
126
|
* @example
|
|
@@ -52,7 +134,7 @@ export declare function isHexString(value: any, length?: number): boolean;
|
|
|
52
134
|
*/
|
|
53
135
|
export declare function hexlify(value: BytesLike | Hexable | number | bigint, options?: DataOptions): string;
|
|
54
136
|
export declare function hexDataLength(data: BytesLike): number | null;
|
|
55
|
-
export declare function hexDataSlice(data:
|
|
137
|
+
export declare function hexDataSlice(data: BytesLikeWithNumber, offset: number, endOffset?: number): string;
|
|
56
138
|
export declare function hexConcat(items: ReadonlyArray<BytesLike>): string;
|
|
57
139
|
export declare function hexValue(value: BytesLike | Hexable | number | bigint): string;
|
|
58
140
|
export declare function hexStripZeros(value: BytesLike): string;
|
|
@@ -87,4 +169,4 @@ export declare function hexStripZeros(value: BytesLike): string;
|
|
|
87
169
|
* // Throws
|
|
88
170
|
* ```
|
|
89
171
|
*/
|
|
90
|
-
export declare function hexZeroPad(value:
|
|
172
|
+
export declare function hexZeroPad(value: BytesLikeWithNumber, length: number): string;
|
package/lib/cjs/utils/bytes.js
CHANGED
|
@@ -3,10 +3,31 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.hexZeroPad = exports.hexStripZeros = exports.hexValue = exports.hexConcat = exports.hexDataSlice = exports.hexDataLength = exports.hexlify = exports.isHexString = exports.zeroPad = exports.stripZeros = exports.concat = exports.arrayify = exports.isBytes = exports.isBytesLike = void 0;
|
|
5
5
|
const logger_1 = require("../logger/logger");
|
|
6
|
-
///////////////////////////////
|
|
7
6
|
function isHexable(value) {
|
|
8
7
|
return !!value.toHexString;
|
|
9
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Returns true if and only if value is a valid [Bytes](#bytes) or DataHexString
|
|
11
|
+
* * Same as [`ethers.utils.isBytesLike`](https://docs.ethers.io/v5/api/utils/bytes/#utils-isBytesLike)
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```js
|
|
15
|
+
* isBytesLike([1,2,3]);
|
|
16
|
+
* // true
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```js
|
|
21
|
+
* isBytesLike(false);
|
|
22
|
+
* // false
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```js
|
|
27
|
+
* isBytesLike(new Uint8Array(1));
|
|
28
|
+
* // true
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
10
31
|
function isBytesLike(value) {
|
|
11
32
|
return (isHexString(value) && !(value.length % 2)) || isBytes(value);
|
|
12
33
|
}
|
|
@@ -14,6 +35,28 @@ exports.isBytesLike = isBytesLike;
|
|
|
14
35
|
function isInteger(value) {
|
|
15
36
|
return typeof value === 'number' && value == value && value % 1 === 0;
|
|
16
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Returns true if and only if value is a valid [Bytes](#bytes)
|
|
40
|
+
* * Same as [`ethers.utils.isBytes`](https://docs.ethers.io/v5/api/utils/bytes/#utils-isBytes)
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```js
|
|
44
|
+
* isBytes([1,2,3]);
|
|
45
|
+
* // true
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```js
|
|
50
|
+
* isBytes(false);
|
|
51
|
+
* // false
|
|
52
|
+
* ```
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```js
|
|
56
|
+
* isBytes(new Uint8Array(1));
|
|
57
|
+
* // true
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
17
60
|
function isBytes(value) {
|
|
18
61
|
if (value == null) {
|
|
19
62
|
return false;
|
|
@@ -36,6 +79,28 @@ function isBytes(value) {
|
|
|
36
79
|
return true;
|
|
37
80
|
}
|
|
38
81
|
exports.isBytes = isBytes;
|
|
82
|
+
/**
|
|
83
|
+
* Converts DataHexStringOrArrayish to a Uint8Array
|
|
84
|
+
* * Same as [`ethers.utils.arrayify`](https://docs.ethers.io/v5/api/utils/bytes/#utils-arrayify)
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```js
|
|
88
|
+
* arrayify(1);
|
|
89
|
+
* // Uint8Array(1) [ 1 ]
|
|
90
|
+
* ```
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```js
|
|
94
|
+
* arrayify(0x1234);
|
|
95
|
+
* // Uint8Array(2) [ 18, 52 ]
|
|
96
|
+
* ```
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```js
|
|
100
|
+
* arrayify('0x1', { hexPad: 'right' });
|
|
101
|
+
* // Uint8Array(1) [ 16 ]
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
39
104
|
function arrayify(value, options) {
|
|
40
105
|
if (!options) {
|
|
41
106
|
options = {};
|
|
@@ -85,8 +150,18 @@ function arrayify(value, options) {
|
|
|
85
150
|
return logger_1.logger.throwArgumentError('invalid arrayify value', 'value', value);
|
|
86
151
|
}
|
|
87
152
|
exports.arrayify = arrayify;
|
|
88
|
-
|
|
89
|
-
|
|
153
|
+
/**
|
|
154
|
+
* Concatenates all the BytesLike in arrayOfBytesLike into a single Uint8Array.
|
|
155
|
+
* * Same as [`ethers.utils.concat`](https://docs.ethers.io/v5/api/utils/bytes/#utils-concat)
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```js
|
|
159
|
+
* concat([0, 1]);
|
|
160
|
+
* // Uint8Array(2) [ 0, 1 ]
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
function concat(arrayOfBytesLike) {
|
|
164
|
+
const objects = arrayOfBytesLike.map((item) => arrayify(item));
|
|
90
165
|
const length = objects.reduce((accum, item) => accum + item.length, 0);
|
|
91
166
|
const result = new Uint8Array(length);
|
|
92
167
|
objects.reduce((offset, object) => {
|
|
@@ -123,6 +198,11 @@ function zeroPad(value, length) {
|
|
|
123
198
|
return result;
|
|
124
199
|
}
|
|
125
200
|
exports.zeroPad = zeroPad;
|
|
201
|
+
/**
|
|
202
|
+
* Returns true if and only if object is a valid hex string.
|
|
203
|
+
* If length is specified and object is not a valid DataHexString of length bytes, an InvalidArgument error is thrown.
|
|
204
|
+
* * Same as [`ethers.utils.isHexString`](https://docs.ethers.io/v5/api/utils/bytes/#utils-isHexString)
|
|
205
|
+
*/
|
|
126
206
|
function isHexString(value, length) {
|
|
127
207
|
if (typeof value !== 'string' || !value.match(/^0x[0-9A-Fa-f]*$/)) {
|
|
128
208
|
return false;
|
|
@@ -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,15 +1,15 @@
|
|
|
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
|
|
5
|
+
const encode_decode_transaction_1 = require("../classes/utils/encode-decode-transaction");
|
|
6
6
|
const logger_1 = require("../logger/logger");
|
|
7
7
|
const tiny_big_1 = require("../shared/tiny-big/tiny-big");
|
|
8
8
|
const bytes_1 = require("./bytes");
|
|
9
|
+
const keccak256_1 = require("./keccak256");
|
|
9
10
|
const regexBytes = new RegExp('^bytes([0-9]+)$');
|
|
10
11
|
const regexNumber = new RegExp('^(u?int)([0-9]*)$');
|
|
11
12
|
const regexArray = new RegExp('^(.*)\\[([0-9]*)\\]$');
|
|
12
|
-
const Zeros = '0000000000000000000000000000000000000000000000000000000000000000';
|
|
13
13
|
function _pack(type, value, isArray) {
|
|
14
14
|
switch (type) {
|
|
15
15
|
case 'address':
|
|
@@ -55,7 +55,7 @@ function _pack(type, value, isArray) {
|
|
|
55
55
|
logger_1.logger.throwArgumentError(`invalid value for ${type}`, 'value', value);
|
|
56
56
|
}
|
|
57
57
|
if (isArray) {
|
|
58
|
-
return (0, bytes_1.arrayify)((value +
|
|
58
|
+
return (0, bytes_1.arrayify)((value + encode_decode_transaction_1.hexFalse).substring(0, 66));
|
|
59
59
|
}
|
|
60
60
|
return value;
|
|
61
61
|
}
|
|
@@ -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;
|
|
@@ -40,7 +40,7 @@ export class BaseContract {
|
|
|
40
40
|
? estimateGas(data)
|
|
41
41
|
: null;
|
|
42
42
|
const req = () => __awaiter(this, void 0, void 0, function* () {
|
|
43
|
-
return yield post(this._provider.
|
|
43
|
+
return yield post(this._provider.selectRpcUrl(), buildRPCPostBody('eth_call', [
|
|
44
44
|
Object.assign({ to: this._address.toLowerCase(), data }, (decimalGas
|
|
45
45
|
? { gas: `0x${decimalGas.toString(16)}` }
|
|
46
46
|
: {})),
|