essential-eth 0.5.4 → 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/utils/fetchers.d.ts +1 -1
- package/lib/cjs/index.d.ts +9 -5
- package/lib/cjs/index.js +10 -2
- 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 +14 -0
- package/lib/cjs/providers/BaseProvider.js +19 -0
- package/lib/cjs/providers/FallthroughProvider.d.ts +1 -2
- package/lib/cjs/providers/utils/chains-info.d.ts +16 -0
- package/lib/cjs/providers/utils/chains-info.js +50 -2
- 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/split-signature.d.ts +26 -0
- package/lib/cjs/utils/split-signature.js +165 -0
- package/lib/esm/classes/utils/fetchers.d.ts +1 -1
- package/lib/esm/index.d.ts +9 -5
- package/lib/esm/index.js +7 -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 +1 -0
- package/lib/esm/providers/BaseProvider.js +6 -0
- package/lib/esm/providers/FallthroughProvider.d.ts +1 -2
- package/lib/esm/providers/utils/chains-info.d.ts +16 -0
- package/lib/esm/providers/utils/chains-info.js +50 -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/split-signature.d.ts +2 -0
- package/lib/esm/utils/split-signature.js +126 -0
- package/package.json +13 -10
- package/readme.md +615 -93
|
@@ -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_getTransactionReceipt' | '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';
|
|
3
3
|
export declare function buildRPCPostBody(method: RPCMethodName, params: unknown[]): {
|
|
4
4
|
jsonrpc: string;
|
|
5
5
|
id: number;
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
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';
|
|
14
18
|
import { toUtf8Bytes } from './utils/to-utf8-bytes';
|
|
15
19
|
import { weiToEther } from './utils/wei-to-ether';
|
|
@@ -17,4 +21,4 @@ export * from './utils/bytes';
|
|
|
17
21
|
export * from './utils/hash-message';
|
|
18
22
|
export * from './utils/keccak256';
|
|
19
23
|
export * from './utils/solidity-keccak256';
|
|
20
|
-
export { etherToWei, etherToGwei, isAddress, jsonRpcProvider, JsonRpcProvider, FallthroughProvider, tinyBig, toChecksumAddress, weiToEther, gweiToEther, toUtf8Bytes, Contract, TinyBig, BlockResponse, ContractTypes, JSONABI, JSONABIArgument, Network, TransactionResponse, };
|
|
24
|
+
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/cjs/index.js
CHANGED
|
@@ -14,8 +14,9 @@ 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.toUtf8Bytes = exports.gweiToEther = exports.weiToEther = exports.toChecksumAddress = exports.tinyBig = exports.FallthroughProvider = exports.JsonRpcProvider = exports.jsonRpcProvider = exports.isAddress = exports.etherToGwei = exports.etherToWei = void 0;
|
|
17
|
+
exports.BaseContract = exports.TinyBig = exports.Contract = exports.computePublicKey = exports.computeAddress = exports.toUtf8Bytes = exports.splitSignature = exports.hashMessage = 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
|
+
Object.defineProperty(exports, "BaseContract", { enumerable: true, get: function () { return Contract_1.BaseContract; } });
|
|
19
20
|
Object.defineProperty(exports, "Contract", { enumerable: true, get: function () { return Contract_1.Contract; } });
|
|
20
21
|
const FallthroughProvider_1 = require("./providers/FallthroughProvider");
|
|
21
22
|
Object.defineProperty(exports, "FallthroughProvider", { enumerable: true, get: function () { return FallthroughProvider_1.FallthroughProvider; } });
|
|
@@ -25,17 +26,24 @@ Object.defineProperty(exports, "jsonRpcProvider", { enumerable: true, get: funct
|
|
|
25
26
|
const tiny_big_1 = require("./shared/tiny-big/tiny-big");
|
|
26
27
|
Object.defineProperty(exports, "tinyBig", { enumerable: true, get: function () { return tiny_big_1.tinyBig; } });
|
|
27
28
|
Object.defineProperty(exports, "TinyBig", { enumerable: true, get: function () { return tiny_big_1.TinyBig; } });
|
|
29
|
+
const compute_address_1 = require("./utils/compute-address");
|
|
30
|
+
Object.defineProperty(exports, "computeAddress", { enumerable: true, get: function () { return compute_address_1.computeAddress; } });
|
|
31
|
+
const compute_public_key_1 = require("./utils/compute-public-key");
|
|
32
|
+
Object.defineProperty(exports, "computePublicKey", { enumerable: true, get: function () { return compute_public_key_1.computePublicKey; } });
|
|
28
33
|
const ether_to_gwei_1 = require("./utils/ether-to-gwei");
|
|
29
34
|
Object.defineProperty(exports, "etherToGwei", { enumerable: true, get: function () { return ether_to_gwei_1.etherToGwei; } });
|
|
30
35
|
const ether_to_wei_1 = require("./utils/ether-to-wei");
|
|
31
36
|
Object.defineProperty(exports, "etherToWei", { enumerable: true, get: function () { return ether_to_wei_1.etherToWei; } });
|
|
32
37
|
const gwei_to_ether_1 = require("./utils/gwei-to-ether");
|
|
33
38
|
Object.defineProperty(exports, "gweiToEther", { enumerable: true, get: function () { return gwei_to_ether_1.gweiToEther; } });
|
|
39
|
+
const hash_message_1 = require("./utils/hash-message");
|
|
40
|
+
Object.defineProperty(exports, "hashMessage", { enumerable: true, get: function () { return hash_message_1.hashMessage; } });
|
|
34
41
|
const is_address_1 = require("./utils/is-address");
|
|
35
42
|
Object.defineProperty(exports, "isAddress", { enumerable: true, get: function () { return is_address_1.isAddress; } });
|
|
43
|
+
const split_signature_1 = require("./utils/split-signature");
|
|
44
|
+
Object.defineProperty(exports, "splitSignature", { enumerable: true, get: function () { return split_signature_1.splitSignature; } });
|
|
36
45
|
const to_checksum_address_1 = require("./utils/to-checksum-address");
|
|
37
46
|
Object.defineProperty(exports, "toChecksumAddress", { enumerable: true, get: function () { return to_checksum_address_1.toChecksumAddress; } });
|
|
38
|
-
// import { verifyMessage } from './utils/verify-message';
|
|
39
47
|
const to_utf8_bytes_1 = require("./utils/to-utf8-bytes");
|
|
40
48
|
Object.defineProperty(exports, "toUtf8Bytes", { enumerable: true, get: function () { return to_utf8_bytes_1.toUtf8Bytes; } });
|
|
41
49
|
const wei_to_ether_1 = require("./utils/wei-to-ether");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "0.5.
|
|
1
|
+
export declare const version = "0.5.5";
|
|
@@ -24,6 +24,20 @@ export declare abstract class BaseProvider {
|
|
|
24
24
|
* Returns the network this provider is connected to
|
|
25
25
|
*/
|
|
26
26
|
getNetwork(): Promise<Network>;
|
|
27
|
+
/**
|
|
28
|
+
* Gets the number of the most recently mined block on the network the provider is connected to
|
|
29
|
+
*
|
|
30
|
+
* * Identical to [`ethers.provider.getBlockNumber`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getBlockNumber)
|
|
31
|
+
* * Identical to [`web3.eth.getBlockNumber`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getblocknumber)
|
|
32
|
+
*
|
|
33
|
+
* @returns the number of the most recently mined block
|
|
34
|
+
* @example
|
|
35
|
+
* ```js
|
|
36
|
+
* await provider.getBlockNumber();
|
|
37
|
+
* // 1053312
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
getBlockNumber(): Promise<number>;
|
|
27
41
|
/**
|
|
28
42
|
* * Similar to [`ethers.provider.getTransaction`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getTransaction), some information not included
|
|
29
43
|
*
|
|
@@ -50,6 +50,25 @@ class BaseProvider {
|
|
|
50
50
|
};
|
|
51
51
|
});
|
|
52
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Gets the number of the most recently mined block on the network the provider is connected to
|
|
55
|
+
*
|
|
56
|
+
* * Identical to [`ethers.provider.getBlockNumber`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getBlockNumber)
|
|
57
|
+
* * Identical to [`web3.eth.getBlockNumber`](https://web3js.readthedocs.io/en/v1.7.3/web3-eth.html#getblocknumber)
|
|
58
|
+
*
|
|
59
|
+
* @returns the number of the most recently mined block
|
|
60
|
+
* @example
|
|
61
|
+
* ```js
|
|
62
|
+
* await provider.getBlockNumber();
|
|
63
|
+
* // 1053312
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
getBlockNumber() {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
const currentBlockNumber = (yield this.post((0, fetchers_1.buildRPCPostBody)('eth_blockNumber', [])));
|
|
69
|
+
return Number((0, hex_to_decimal_1.hexToDecimal)(currentBlockNumber));
|
|
70
|
+
});
|
|
71
|
+
}
|
|
53
72
|
/**
|
|
54
73
|
* * Similar to [`ethers.provider.getTransaction`](https://docs.ethers.io/v5/api/providers/provider/#Provider-getTransaction), some information not included
|
|
55
74
|
*
|
|
@@ -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
|
/**
|
|
@@ -22,4 +22,3 @@ export declare class FallthroughProvider extends BaseProvider {
|
|
|
22
22
|
*/
|
|
23
23
|
post: (body: Record<string, unknown>) => Promise<any>;
|
|
24
24
|
}
|
|
25
|
-
export {};
|
|
@@ -119,6 +119,7 @@ declare const _default: {
|
|
|
119
119
|
"222": string[];
|
|
120
120
|
"225": string[];
|
|
121
121
|
"226": string[];
|
|
122
|
+
"239": string[];
|
|
122
123
|
"246": string[];
|
|
123
124
|
"250": string[];
|
|
124
125
|
"256": string[];
|
|
@@ -143,10 +144,14 @@ declare const _default: {
|
|
|
143
144
|
"499": string[];
|
|
144
145
|
"512": string[];
|
|
145
146
|
"513": string[];
|
|
147
|
+
"534": string[];
|
|
146
148
|
"555": string[];
|
|
147
149
|
"558": string[];
|
|
148
150
|
"588": string[];
|
|
151
|
+
"592": string[];
|
|
149
152
|
"595": string[];
|
|
153
|
+
"596": string[];
|
|
154
|
+
"597": string[];
|
|
150
155
|
"600": string[];
|
|
151
156
|
"666": string[];
|
|
152
157
|
"686": string[];
|
|
@@ -154,6 +159,7 @@ declare const _default: {
|
|
|
154
159
|
"707": string[];
|
|
155
160
|
"708": string[];
|
|
156
161
|
"721": string[];
|
|
162
|
+
"776": string[];
|
|
157
163
|
"777": string[];
|
|
158
164
|
"787": string[];
|
|
159
165
|
"788": string[];
|
|
@@ -201,14 +207,18 @@ declare const _default: {
|
|
|
201
207
|
"1620": string[];
|
|
202
208
|
"1657": string[];
|
|
203
209
|
"1688": string[];
|
|
210
|
+
"1819": string[];
|
|
204
211
|
"1856": string[];
|
|
205
212
|
"1898": string[];
|
|
206
213
|
"1984": string[];
|
|
207
214
|
"1987": string[];
|
|
208
215
|
"2001": string[];
|
|
216
|
+
"2008": string[];
|
|
217
|
+
"2009": string[];
|
|
209
218
|
"2020": string[];
|
|
210
219
|
"2021": string[];
|
|
211
220
|
"2022": string[];
|
|
221
|
+
"2023": string[];
|
|
212
222
|
"2025": string[];
|
|
213
223
|
"2100": string[];
|
|
214
224
|
"2101": string[];
|
|
@@ -219,6 +229,8 @@ declare const _default: {
|
|
|
219
229
|
"2223": string[];
|
|
220
230
|
"2559": string[];
|
|
221
231
|
"2569": string[];
|
|
232
|
+
"2612": string[];
|
|
233
|
+
"2613": string[];
|
|
222
234
|
"3000": string[];
|
|
223
235
|
"3001": string[];
|
|
224
236
|
"3331": string[];
|
|
@@ -254,6 +266,7 @@ declare const _default: {
|
|
|
254
266
|
"8723": string[];
|
|
255
267
|
"8724": string[];
|
|
256
268
|
"8888": string[];
|
|
269
|
+
"8898": string[];
|
|
257
270
|
"8995": string[];
|
|
258
271
|
"9000": string[];
|
|
259
272
|
"9001": string[];
|
|
@@ -274,10 +287,13 @@ declare const _default: {
|
|
|
274
287
|
"19845": string[];
|
|
275
288
|
"21337": string[];
|
|
276
289
|
"21816": string[];
|
|
290
|
+
"22023": string[];
|
|
277
291
|
"24484": string[];
|
|
278
292
|
"24734": string[];
|
|
293
|
+
"30067": string[];
|
|
279
294
|
"31102": string[];
|
|
280
295
|
"31337": string[];
|
|
296
|
+
"32520": string[];
|
|
281
297
|
"32659": string[];
|
|
282
298
|
"39797": string[];
|
|
283
299
|
"42069": string[];
|
|
@@ -367,6 +367,9 @@ exports.default = {
|
|
|
367
367
|
"226": [
|
|
368
368
|
"TLA"
|
|
369
369
|
],
|
|
370
|
+
"239": [
|
|
371
|
+
"AITD"
|
|
372
|
+
],
|
|
370
373
|
"246": [
|
|
371
374
|
"ewt"
|
|
372
375
|
],
|
|
@@ -439,6 +442,9 @@ exports.default = {
|
|
|
439
442
|
"513": [
|
|
440
443
|
"aact"
|
|
441
444
|
],
|
|
445
|
+
"534": [
|
|
446
|
+
"CNDL"
|
|
447
|
+
],
|
|
442
448
|
"555": [
|
|
443
449
|
"CLASS"
|
|
444
450
|
],
|
|
@@ -448,9 +454,18 @@ exports.default = {
|
|
|
448
454
|
"588": [
|
|
449
455
|
"metis-stardust"
|
|
450
456
|
],
|
|
457
|
+
"592": [
|
|
458
|
+
"astr"
|
|
459
|
+
],
|
|
451
460
|
"595": [
|
|
452
461
|
"maca"
|
|
453
462
|
],
|
|
463
|
+
"596": [
|
|
464
|
+
"tkar"
|
|
465
|
+
],
|
|
466
|
+
"597": [
|
|
467
|
+
"taca"
|
|
468
|
+
],
|
|
454
469
|
"600": [
|
|
455
470
|
"mesh-chain-testnet"
|
|
456
471
|
],
|
|
@@ -472,6 +487,9 @@ exports.default = {
|
|
|
472
487
|
"721": [
|
|
473
488
|
"tfeth"
|
|
474
489
|
],
|
|
490
|
+
"776": [
|
|
491
|
+
"opc"
|
|
492
|
+
],
|
|
475
493
|
"777": [
|
|
476
494
|
"cth"
|
|
477
495
|
],
|
|
@@ -613,6 +631,9 @@ exports.default = {
|
|
|
613
631
|
"1688": [
|
|
614
632
|
"LUDAN"
|
|
615
633
|
],
|
|
634
|
+
"1819": [
|
|
635
|
+
"cubet"
|
|
636
|
+
],
|
|
616
637
|
"1856": [
|
|
617
638
|
"tsf"
|
|
618
639
|
],
|
|
@@ -628,6 +649,12 @@ exports.default = {
|
|
|
628
649
|
"2001": [
|
|
629
650
|
"milkAda"
|
|
630
651
|
],
|
|
652
|
+
"2008": [
|
|
653
|
+
"cloudwalk_testnet"
|
|
654
|
+
],
|
|
655
|
+
"2009": [
|
|
656
|
+
"cloudwalk_mainnet"
|
|
657
|
+
],
|
|
631
658
|
"2020": [
|
|
632
659
|
"420"
|
|
633
660
|
],
|
|
@@ -637,6 +664,9 @@ exports.default = {
|
|
|
637
664
|
"2022": [
|
|
638
665
|
"edgt"
|
|
639
666
|
],
|
|
667
|
+
"2023": [
|
|
668
|
+
"taycan-testnet"
|
|
669
|
+
],
|
|
640
670
|
"2025": [
|
|
641
671
|
"rpg"
|
|
642
672
|
],
|
|
@@ -667,6 +697,12 @@ exports.default = {
|
|
|
667
697
|
"2569": [
|
|
668
698
|
"tpc"
|
|
669
699
|
],
|
|
700
|
+
"2612": [
|
|
701
|
+
"EZChain"
|
|
702
|
+
],
|
|
703
|
+
"2613": [
|
|
704
|
+
"Fuji-EZChain"
|
|
705
|
+
],
|
|
670
706
|
"3000": [
|
|
671
707
|
"cennz-r"
|
|
672
708
|
],
|
|
@@ -772,6 +808,9 @@ exports.default = {
|
|
|
772
808
|
"8888": [
|
|
773
809
|
"ambrostestnet"
|
|
774
810
|
],
|
|
811
|
+
"8898": [
|
|
812
|
+
"mmt"
|
|
813
|
+
],
|
|
775
814
|
"8995": [
|
|
776
815
|
"berg"
|
|
777
816
|
],
|
|
@@ -830,7 +869,10 @@ exports.default = {
|
|
|
830
869
|
"cennz-a"
|
|
831
870
|
],
|
|
832
871
|
"21816": [
|
|
833
|
-
"
|
|
872
|
+
"omc"
|
|
873
|
+
],
|
|
874
|
+
"22023": [
|
|
875
|
+
"SFL"
|
|
834
876
|
],
|
|
835
877
|
"24484": [
|
|
836
878
|
"web"
|
|
@@ -838,12 +880,18 @@ exports.default = {
|
|
|
838
880
|
"24734": [
|
|
839
881
|
"mintme"
|
|
840
882
|
],
|
|
883
|
+
"30067": [
|
|
884
|
+
"Piece"
|
|
885
|
+
],
|
|
841
886
|
"31102": [
|
|
842
887
|
"esn"
|
|
843
888
|
],
|
|
844
889
|
"31337": [
|
|
845
890
|
"got"
|
|
846
891
|
],
|
|
892
|
+
"32520": [
|
|
893
|
+
"Brise"
|
|
894
|
+
],
|
|
847
895
|
"32659": [
|
|
848
896
|
"fsn"
|
|
849
897
|
],
|
|
@@ -878,7 +926,7 @@ exports.default = {
|
|
|
878
926
|
"ALFA"
|
|
879
927
|
],
|
|
880
928
|
"45000": [
|
|
881
|
-
"
|
|
929
|
+
"Autobahn Network"
|
|
882
930
|
],
|
|
883
931
|
"47805": [
|
|
884
932
|
"REI"
|
|
@@ -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,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;
|
|
@@ -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_getTransactionReceipt' | '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';
|
|
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,15 +1,19 @@
|
|
|
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';
|
|
14
18
|
import { toUtf8Bytes } from './utils/to-utf8-bytes';
|
|
15
19
|
import { weiToEther } from './utils/wei-to-ether';
|
|
@@ -17,4 +21,4 @@ export * from './utils/bytes';
|
|
|
17
21
|
export * from './utils/hash-message';
|
|
18
22
|
export * from './utils/keccak256';
|
|
19
23
|
export * from './utils/solidity-keccak256';
|
|
20
|
-
export { etherToWei, etherToGwei, isAddress, jsonRpcProvider, JsonRpcProvider, FallthroughProvider, tinyBig, toChecksumAddress, weiToEther, gweiToEther, toUtf8Bytes, Contract, TinyBig, BlockResponse, ContractTypes, JSONABI, JSONABIArgument, Network, TransactionResponse, };
|
|
24
|
+
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, };
|