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
|
@@ -189,6 +189,9 @@ export default {
|
|
|
189
189
|
"69": [
|
|
190
190
|
"okov"
|
|
191
191
|
],
|
|
192
|
+
"70": [
|
|
193
|
+
"hsc"
|
|
194
|
+
],
|
|
192
195
|
"71": [
|
|
193
196
|
"cfxtest"
|
|
194
197
|
],
|
|
@@ -360,6 +363,9 @@ export default {
|
|
|
360
363
|
"226": [
|
|
361
364
|
"TLA"
|
|
362
365
|
],
|
|
366
|
+
"239": [
|
|
367
|
+
"AITD"
|
|
368
|
+
],
|
|
363
369
|
"246": [
|
|
364
370
|
"ewt"
|
|
365
371
|
],
|
|
@@ -432,6 +438,9 @@ export default {
|
|
|
432
438
|
"513": [
|
|
433
439
|
"aact"
|
|
434
440
|
],
|
|
441
|
+
"534": [
|
|
442
|
+
"CNDL"
|
|
443
|
+
],
|
|
435
444
|
"555": [
|
|
436
445
|
"CLASS"
|
|
437
446
|
],
|
|
@@ -441,9 +450,18 @@ export default {
|
|
|
441
450
|
"588": [
|
|
442
451
|
"metis-stardust"
|
|
443
452
|
],
|
|
453
|
+
"592": [
|
|
454
|
+
"astr"
|
|
455
|
+
],
|
|
444
456
|
"595": [
|
|
445
457
|
"maca"
|
|
446
458
|
],
|
|
459
|
+
"596": [
|
|
460
|
+
"tkar"
|
|
461
|
+
],
|
|
462
|
+
"597": [
|
|
463
|
+
"taca"
|
|
464
|
+
],
|
|
447
465
|
"600": [
|
|
448
466
|
"mesh-chain-testnet"
|
|
449
467
|
],
|
|
@@ -465,6 +483,9 @@ export default {
|
|
|
465
483
|
"721": [
|
|
466
484
|
"tfeth"
|
|
467
485
|
],
|
|
486
|
+
"776": [
|
|
487
|
+
"opc"
|
|
488
|
+
],
|
|
468
489
|
"777": [
|
|
469
490
|
"cth"
|
|
470
491
|
],
|
|
@@ -606,6 +627,9 @@ export default {
|
|
|
606
627
|
"1688": [
|
|
607
628
|
"LUDAN"
|
|
608
629
|
],
|
|
630
|
+
"1819": [
|
|
631
|
+
"cubet"
|
|
632
|
+
],
|
|
609
633
|
"1856": [
|
|
610
634
|
"tsf"
|
|
611
635
|
],
|
|
@@ -621,6 +645,12 @@ export default {
|
|
|
621
645
|
"2001": [
|
|
622
646
|
"milkAda"
|
|
623
647
|
],
|
|
648
|
+
"2008": [
|
|
649
|
+
"cloudwalk_testnet"
|
|
650
|
+
],
|
|
651
|
+
"2009": [
|
|
652
|
+
"cloudwalk_mainnet"
|
|
653
|
+
],
|
|
624
654
|
"2020": [
|
|
625
655
|
"420"
|
|
626
656
|
],
|
|
@@ -630,6 +660,9 @@ export default {
|
|
|
630
660
|
"2022": [
|
|
631
661
|
"edgt"
|
|
632
662
|
],
|
|
663
|
+
"2023": [
|
|
664
|
+
"taycan-testnet"
|
|
665
|
+
],
|
|
633
666
|
"2025": [
|
|
634
667
|
"rpg"
|
|
635
668
|
],
|
|
@@ -657,6 +690,15 @@ export default {
|
|
|
657
690
|
"2559": [
|
|
658
691
|
"ktoc"
|
|
659
692
|
],
|
|
693
|
+
"2569": [
|
|
694
|
+
"tpc"
|
|
695
|
+
],
|
|
696
|
+
"2612": [
|
|
697
|
+
"EZChain"
|
|
698
|
+
],
|
|
699
|
+
"2613": [
|
|
700
|
+
"Fuji-EZChain"
|
|
701
|
+
],
|
|
660
702
|
"3000": [
|
|
661
703
|
"cennz-r"
|
|
662
704
|
],
|
|
@@ -762,6 +804,9 @@ export default {
|
|
|
762
804
|
"8888": [
|
|
763
805
|
"ambrostestnet"
|
|
764
806
|
],
|
|
807
|
+
"8898": [
|
|
808
|
+
"mmt"
|
|
809
|
+
],
|
|
765
810
|
"8995": [
|
|
766
811
|
"berg"
|
|
767
812
|
],
|
|
@@ -820,7 +865,10 @@ export default {
|
|
|
820
865
|
"cennz-a"
|
|
821
866
|
],
|
|
822
867
|
"21816": [
|
|
823
|
-
"
|
|
868
|
+
"omc"
|
|
869
|
+
],
|
|
870
|
+
"22023": [
|
|
871
|
+
"SFL"
|
|
824
872
|
],
|
|
825
873
|
"24484": [
|
|
826
874
|
"web"
|
|
@@ -828,12 +876,18 @@ export default {
|
|
|
828
876
|
"24734": [
|
|
829
877
|
"mintme"
|
|
830
878
|
],
|
|
879
|
+
"30067": [
|
|
880
|
+
"Piece"
|
|
881
|
+
],
|
|
831
882
|
"31102": [
|
|
832
883
|
"esn"
|
|
833
884
|
],
|
|
834
885
|
"31337": [
|
|
835
886
|
"got"
|
|
836
887
|
],
|
|
888
|
+
"32520": [
|
|
889
|
+
"Brise"
|
|
890
|
+
],
|
|
837
891
|
"32659": [
|
|
838
892
|
"fsn"
|
|
839
893
|
],
|
|
@@ -868,7 +922,7 @@ export default {
|
|
|
868
922
|
"ALFA"
|
|
869
923
|
],
|
|
870
924
|
"45000": [
|
|
871
|
-
"
|
|
925
|
+
"Autobahn Network"
|
|
872
926
|
],
|
|
873
927
|
"47805": [
|
|
874
928
|
"REI"
|
|
@@ -900,6 +954,9 @@ export default {
|
|
|
900
954
|
"62320": [
|
|
901
955
|
"BKLV"
|
|
902
956
|
],
|
|
957
|
+
"62621": [
|
|
958
|
+
"mtv"
|
|
959
|
+
],
|
|
903
960
|
"63000": [
|
|
904
961
|
"ecs"
|
|
905
962
|
],
|
|
@@ -1035,6 +1092,9 @@ export default {
|
|
|
1035
1092
|
"444900": [
|
|
1036
1093
|
"wlkt"
|
|
1037
1094
|
],
|
|
1095
|
+
"512512": [
|
|
1096
|
+
"cmp"
|
|
1097
|
+
],
|
|
1038
1098
|
"666666": [
|
|
1039
1099
|
"vpioneer"
|
|
1040
1100
|
],
|
|
@@ -20,6 +20,24 @@ export declare type TransactionResponse = Modify<RPCTransaction, {
|
|
|
20
20
|
maxPriorityFeePerGas: TinyBig;
|
|
21
21
|
confirmations: number;
|
|
22
22
|
}>;
|
|
23
|
+
export declare type TransactionReceipt = Modify<RPCTransactionReceipt, {
|
|
24
|
+
blockNumber: number;
|
|
25
|
+
cumulativeGasUsed: TinyBig;
|
|
26
|
+
effectiveGasPrice: TinyBig;
|
|
27
|
+
gasUsed: TinyBig;
|
|
28
|
+
logs: Array<Log>;
|
|
29
|
+
status: number;
|
|
30
|
+
transactionIndex: number;
|
|
31
|
+
type: number;
|
|
32
|
+
} & {
|
|
33
|
+
byzantium: boolean;
|
|
34
|
+
confirmations: number;
|
|
35
|
+
}>;
|
|
36
|
+
export declare type Log = Modify<Omit<RPCLog, 'removed'>, {
|
|
37
|
+
blockNumber: number;
|
|
38
|
+
logIndex: number;
|
|
39
|
+
transactionIndex: number;
|
|
40
|
+
}>;
|
|
23
41
|
export declare type BlockTransactionResponse = Omit<TransactionResponse, 'maxFeePerGas' | 'maxPriorityFeePerGas'>;
|
|
24
42
|
export interface RPCBlockTransaction {
|
|
25
43
|
blockHash: string;
|
|
@@ -39,4 +57,31 @@ export interface RPCBlockTransaction {
|
|
|
39
57
|
v: string;
|
|
40
58
|
value: string;
|
|
41
59
|
}
|
|
60
|
+
export interface RPCTransactionReceipt {
|
|
61
|
+
blockHash: string;
|
|
62
|
+
blockNumber: string;
|
|
63
|
+
contractAddress: string;
|
|
64
|
+
cumulativeGasUsed: string;
|
|
65
|
+
effectiveGasPrice: string;
|
|
66
|
+
from: string;
|
|
67
|
+
gasUsed: string;
|
|
68
|
+
logs: Array<RPCLog>;
|
|
69
|
+
logsBloom: string;
|
|
70
|
+
status: string;
|
|
71
|
+
to: string;
|
|
72
|
+
transactionHash: string;
|
|
73
|
+
transactionIndex: string;
|
|
74
|
+
type: string;
|
|
75
|
+
}
|
|
76
|
+
export interface RPCLog {
|
|
77
|
+
address: string;
|
|
78
|
+
blockHash: string;
|
|
79
|
+
blockNumber: string;
|
|
80
|
+
data: string;
|
|
81
|
+
logIndex: string;
|
|
82
|
+
removed?: boolean;
|
|
83
|
+
topics: Array<string>;
|
|
84
|
+
transactionHash: string;
|
|
85
|
+
transactionIndex: string;
|
|
86
|
+
}
|
|
42
87
|
export {};
|
package/lib/esm/utils/bytes.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export declare type Bytes = ArrayLike<number>;
|
|
2
|
-
export declare type BytesLike = Bytes | string
|
|
2
|
+
export declare type BytesLike = Bytes | string;
|
|
3
|
+
export declare type BytesLikeWithNumber = BytesLike | number;
|
|
3
4
|
export interface DataOptions {
|
|
4
5
|
allowMissingPrefix?: boolean;
|
|
5
6
|
hexPad?: 'left' | 'right' | null;
|
|
@@ -26,14 +27,14 @@ export interface Signature {
|
|
|
26
27
|
export declare function isBytesLike(value: any): value is BytesLike;
|
|
27
28
|
export declare function isBytes(value: any): value is Bytes;
|
|
28
29
|
export declare function arrayify(value: BytesLike | Hexable | number, options?: DataOptions): Uint8Array;
|
|
29
|
-
export declare function concat(
|
|
30
|
+
export declare function concat(arrayOfBytesLike: ReadonlyArray<BytesLikeWithNumber>): Uint8Array;
|
|
30
31
|
export declare function stripZeros(value: BytesLike): Uint8Array;
|
|
31
32
|
export declare function zeroPad(value: BytesLike, length: number): Uint8Array;
|
|
32
33
|
export declare function isHexString(value: any, length?: number): boolean;
|
|
33
34
|
export declare function hexlify(value: BytesLike | Hexable | number | bigint, options?: DataOptions): string;
|
|
34
35
|
export declare function hexDataLength(data: BytesLike): number | null;
|
|
35
|
-
export declare function hexDataSlice(data:
|
|
36
|
+
export declare function hexDataSlice(data: BytesLikeWithNumber, offset: number, endOffset?: number): string;
|
|
36
37
|
export declare function hexConcat(items: ReadonlyArray<BytesLike>): string;
|
|
37
38
|
export declare function hexValue(value: BytesLike | Hexable | number | bigint): string;
|
|
38
39
|
export declare function hexStripZeros(value: BytesLike): string;
|
|
39
|
-
export declare function hexZeroPad(value:
|
|
40
|
+
export declare function hexZeroPad(value: BytesLikeWithNumber, length: number): string;
|
package/lib/esm/utils/bytes.js
CHANGED
|
@@ -77,8 +77,8 @@ export function arrayify(value, options) {
|
|
|
77
77
|
}
|
|
78
78
|
return logger.throwArgumentError('invalid arrayify value', 'value', value);
|
|
79
79
|
}
|
|
80
|
-
export function concat(
|
|
81
|
-
const objects =
|
|
80
|
+
export function concat(arrayOfBytesLike) {
|
|
81
|
+
const objects = arrayOfBytesLike.map((item) => arrayify(item));
|
|
82
82
|
const length = objects.reduce((accum, item) => accum + item.length, 0);
|
|
83
83
|
const result = new Uint8Array(length);
|
|
84
84
|
objects.reduce((offset, object) => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function computeAddress(key: string): string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { computePublicKey, toChecksumAddress } from '..';
|
|
2
|
+
import { hexDataSlice } from './bytes';
|
|
3
|
+
import { keccak256 } from './keccak256';
|
|
4
|
+
export function computeAddress(key) {
|
|
5
|
+
if (!key.startsWith('0x04') &&
|
|
6
|
+
!key.startsWith('0x03') &&
|
|
7
|
+
!key.startsWith('0x02')) {
|
|
8
|
+
key = computePublicKey(key);
|
|
9
|
+
}
|
|
10
|
+
return toChecksumAddress(hexDataSlice(keccak256(hexDataSlice(key, 1)), 12));
|
|
11
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { concat, keccak256, toUtf8Bytes } from '../index';
|
|
2
|
+
const messagePrefix = '\x19Ethereum Signed Message:\n';
|
|
3
|
+
export function hashMessage(message) {
|
|
4
|
+
if (typeof message === 'string') {
|
|
5
|
+
message = toUtf8Bytes(message);
|
|
6
|
+
}
|
|
7
|
+
return keccak256(concat([
|
|
8
|
+
toUtf8Bytes(messagePrefix),
|
|
9
|
+
toUtf8Bytes(String(message.length)),
|
|
10
|
+
message,
|
|
11
|
+
]));
|
|
12
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Keccak } from 'sha3';
|
|
2
|
+
export const keccak256 = (data) => {
|
|
3
|
+
let bufferableData;
|
|
4
|
+
if (typeof data === 'string') {
|
|
5
|
+
bufferableData = Buffer.from(data.replace(/^0x/, ''), 'hex');
|
|
6
|
+
}
|
|
7
|
+
else {
|
|
8
|
+
bufferableData = Buffer.from(data);
|
|
9
|
+
}
|
|
10
|
+
const keccak = new Keccak(256);
|
|
11
|
+
const addressHash = '0x' + keccak.update(bufferableData).digest('hex');
|
|
12
|
+
return addressHash;
|
|
13
|
+
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Buffer } from 'buffer';
|
|
2
|
-
import {
|
|
2
|
+
import { hexFalse } from '../classes/utils/encode-decode-transaction';
|
|
3
3
|
import { logger } from '../logger/logger';
|
|
4
4
|
import { tinyBig } from '../shared/tiny-big/tiny-big';
|
|
5
5
|
import { arrayify, concat, hexlify, zeroPad } from './bytes';
|
|
6
|
+
import { keccak256 } from './keccak256';
|
|
6
7
|
const regexBytes = new RegExp('^bytes([0-9]+)$');
|
|
7
8
|
const regexNumber = new RegExp('^(u?int)([0-9]*)$');
|
|
8
9
|
const regexArray = new RegExp('^(.*)\\[([0-9]*)\\]$');
|
|
9
|
-
const Zeros = '0000000000000000000000000000000000000000000000000000000000000000';
|
|
10
10
|
function _pack(type, value, isArray) {
|
|
11
11
|
switch (type) {
|
|
12
12
|
case 'address':
|
|
@@ -51,7 +51,7 @@ function _pack(type, value, isArray) {
|
|
|
51
51
|
logger.throwArgumentError(`invalid value for ${type}`, 'value', value);
|
|
52
52
|
}
|
|
53
53
|
if (isArray) {
|
|
54
|
-
return arrayify((value +
|
|
54
|
+
return arrayify((value + hexFalse).substring(0, 66));
|
|
55
55
|
}
|
|
56
56
|
return value;
|
|
57
57
|
}
|
|
@@ -80,12 +80,6 @@ export function pack(types, values) {
|
|
|
80
80
|
});
|
|
81
81
|
return hexlify(concat(tight));
|
|
82
82
|
}
|
|
83
|
-
export const hashKeccak256 = (data) => {
|
|
84
|
-
const keccak = new Keccak(256);
|
|
85
|
-
const bufferableData = Buffer.from(data.replace(/^0x/, ''), 'hex');
|
|
86
|
-
const addressHash = '0x' + keccak.update(bufferableData).digest('hex');
|
|
87
|
-
return addressHash;
|
|
88
|
-
};
|
|
89
83
|
export function solidityKeccak256(types, values) {
|
|
90
|
-
return
|
|
84
|
+
return keccak256(pack(types, values));
|
|
91
85
|
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { logger } from './../logger/logger';
|
|
2
|
+
import { arrayify, hexlify, hexZeroPad, isBytesLike, isHexString, zeroPad, } from './bytes';
|
|
3
|
+
export function splitSignature(signature) {
|
|
4
|
+
const result = {
|
|
5
|
+
r: '0x',
|
|
6
|
+
s: '0x',
|
|
7
|
+
_vs: '0x',
|
|
8
|
+
recoveryParam: 0,
|
|
9
|
+
v: 0,
|
|
10
|
+
yParityAndS: '0x',
|
|
11
|
+
compact: '0x',
|
|
12
|
+
};
|
|
13
|
+
if (isBytesLike(signature)) {
|
|
14
|
+
const bytes = arrayify(signature);
|
|
15
|
+
if (bytes.length === 64) {
|
|
16
|
+
result.v = 27 + (bytes[32] >> 7);
|
|
17
|
+
bytes[32] &= 0x7f;
|
|
18
|
+
result.r = hexlify(bytes.slice(0, 32));
|
|
19
|
+
result.s = hexlify(bytes.slice(32, 64));
|
|
20
|
+
}
|
|
21
|
+
else if (bytes.length === 65) {
|
|
22
|
+
result.r = hexlify(bytes.slice(0, 32));
|
|
23
|
+
result.s = hexlify(bytes.slice(32, 64));
|
|
24
|
+
result.v = bytes[64];
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
logger.throwArgumentError('invalid signature string', 'signature', signature);
|
|
28
|
+
}
|
|
29
|
+
if (result.v < 27) {
|
|
30
|
+
if (result.v === 0 || result.v === 1) {
|
|
31
|
+
result.v += 27;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
logger.throwArgumentError('signature invalid v byte', 'signature', signature);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
result.recoveryParam = 1 - (result.v % 2);
|
|
38
|
+
if (result.recoveryParam) {
|
|
39
|
+
bytes[32] |= 0x80;
|
|
40
|
+
}
|
|
41
|
+
result._vs = hexlify(bytes.slice(32, 64));
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
result.r = signature.r;
|
|
45
|
+
result.s = signature.s;
|
|
46
|
+
result.v = signature.v;
|
|
47
|
+
result.recoveryParam = signature.recoveryParam;
|
|
48
|
+
result._vs = signature._vs;
|
|
49
|
+
if (result._vs != null) {
|
|
50
|
+
const vs_1 = zeroPad(arrayify(result._vs), 32);
|
|
51
|
+
result._vs = hexlify(vs_1);
|
|
52
|
+
const recoveryParam = vs_1[0] >= 128 ? 1 : 0;
|
|
53
|
+
if (result.recoveryParam == null) {
|
|
54
|
+
result.recoveryParam = recoveryParam;
|
|
55
|
+
}
|
|
56
|
+
else if (result.recoveryParam !== recoveryParam) {
|
|
57
|
+
logger.throwArgumentError('signature recoveryParam mismatch _vs', 'signature', signature);
|
|
58
|
+
}
|
|
59
|
+
vs_1[0] &= 0x7f;
|
|
60
|
+
const s = hexlify(vs_1);
|
|
61
|
+
if (result.s == null) {
|
|
62
|
+
result.s = s;
|
|
63
|
+
}
|
|
64
|
+
else if (result.s !== s) {
|
|
65
|
+
logger.throwArgumentError('signature v mismatch _vs', 'signature', signature);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (result.recoveryParam == null) {
|
|
69
|
+
if (result.v == null) {
|
|
70
|
+
logger.throwArgumentError('signature missing v and recoveryParam', 'signature', signature);
|
|
71
|
+
}
|
|
72
|
+
else if (result.v === 0 || result.v === 1) {
|
|
73
|
+
result.recoveryParam = result.v;
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
result.recoveryParam = 1 - (result.v % 2);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
if (result.v == null) {
|
|
81
|
+
result.v = 27 + result.recoveryParam;
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
const recId = result.v === 0 || result.v === 1 ? result.v : 1 - (result.v % 2);
|
|
85
|
+
if (result.recoveryParam !== recId) {
|
|
86
|
+
logger.throwArgumentError('signature recoveryParam mismatch v', 'signature', signature);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (result.r == null || !isHexString(result.r)) {
|
|
91
|
+
logger.throwArgumentError('signature missing or invalid r', 'signature', signature);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
result.r = hexZeroPad(result.r, 32);
|
|
95
|
+
}
|
|
96
|
+
if (result.s == null || !isHexString(result.s)) {
|
|
97
|
+
logger.throwArgumentError('signature missing or invalid s', 'signature', signature);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
result.s = hexZeroPad(result.s, 32);
|
|
101
|
+
}
|
|
102
|
+
const vs = arrayify(result.s);
|
|
103
|
+
if (vs[0] >= 128) {
|
|
104
|
+
logger.throwArgumentError('signature s out of range', 'signature', signature);
|
|
105
|
+
}
|
|
106
|
+
if (result.recoveryParam) {
|
|
107
|
+
vs[0] |= 0x80;
|
|
108
|
+
}
|
|
109
|
+
const _vs = hexlify(vs);
|
|
110
|
+
if (result._vs) {
|
|
111
|
+
if (!isHexString(result._vs)) {
|
|
112
|
+
logger.throwArgumentError('signature invalid _vs', 'signature', signature);
|
|
113
|
+
}
|
|
114
|
+
result._vs = hexZeroPad(result._vs, 32);
|
|
115
|
+
}
|
|
116
|
+
if (result._vs == null) {
|
|
117
|
+
result._vs = _vs;
|
|
118
|
+
}
|
|
119
|
+
else if (result._vs !== _vs) {
|
|
120
|
+
logger.throwArgumentError('signature _vs mismatch v and s', 'signature', signature);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
result.yParityAndS = result._vs;
|
|
124
|
+
result.compact = result.r + result.yParityAndS.substring(2);
|
|
125
|
+
return result;
|
|
126
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function toUtf8Bytes(data: string): Uint8Array;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "essential-eth",
|
|
3
|
-
"description": "Ultralight JS
|
|
4
|
-
"version": "0.5.
|
|
3
|
+
"description": "Ultralight JS for Ethereum",
|
|
4
|
+
"version": "0.5.5",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"main": "./lib/cjs/index.js",
|
|
@@ -22,45 +22,50 @@
|
|
|
22
22
|
"tsc:esm": "tsc -p tsconfig.json",
|
|
23
23
|
"tsc:cjs": "tsc -p tsconfig-cjs.json",
|
|
24
24
|
"build": "rm -rf lib && npm run compile",
|
|
25
|
-
"
|
|
25
|
+
"build:readme": ". ./scripts/markdown-magic/build-readme.sh",
|
|
26
26
|
"jest": "jest",
|
|
27
27
|
"build:chains-info": "npx ts-node scripts/fetch-chains-info.ts # used in getNetwork()",
|
|
28
28
|
"update-deps": "sh ./scripts/pre-commit.sh",
|
|
29
29
|
"pre-commit": "run-p build:chains-info update-deps",
|
|
30
|
-
"prepare": "husky install"
|
|
30
|
+
"prepare": "husky install",
|
|
31
|
+
"version": "npx genversion --es6 src/logger/package-version.ts && git add src/logger/package-version.ts",
|
|
32
|
+
"postversion": "git push --follow-tags",
|
|
33
|
+
"prepublishOnly": "npm run build",
|
|
34
|
+
"doc": "typedoc"
|
|
31
35
|
},
|
|
32
36
|
"devDependencies": {
|
|
33
|
-
"@ethersproject/keccak256": "^5.4.0",
|
|
34
37
|
"@types/body-parser": "^1.19.1",
|
|
35
|
-
"@types/eslint": "^8.4.
|
|
38
|
+
"@types/eslint": "^8.4.2",
|
|
36
39
|
"@types/express": "^4.17.13",
|
|
37
40
|
"@types/jest": "^27.4.1",
|
|
38
41
|
"@types/jest-dev-server": "^5.0.0",
|
|
39
42
|
"@types/node": "^16.10.1",
|
|
40
43
|
"@types/prettier": "^2.4.4",
|
|
41
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
42
|
-
"@typescript-eslint/parser": "^5.
|
|
44
|
+
"@typescript-eslint/eslint-plugin": "^5.25.0",
|
|
45
|
+
"@typescript-eslint/parser": "^5.25.0",
|
|
43
46
|
"body-parser": "^1.19.0",
|
|
44
47
|
"dotenv": "^16.0.0",
|
|
45
|
-
"eslint": "^8.
|
|
46
|
-
"eslint-plugin-jest": "^26.
|
|
47
|
-
"ethers": "^5.6.
|
|
48
|
+
"eslint": "^8.16.0",
|
|
49
|
+
"eslint-plugin-jest": "^26.2.2",
|
|
50
|
+
"ethers": "^5.6.7",
|
|
48
51
|
"express": "^4.17.1",
|
|
49
52
|
"husky": "^7.0.4",
|
|
50
53
|
"jest": "^27.5.1",
|
|
51
54
|
"jest-dev-server": "^6.0.3",
|
|
52
55
|
"just-omit": "^2.0.1",
|
|
53
|
-
"lint-staged": "^12.4.
|
|
56
|
+
"lint-staged": "^12.4.1",
|
|
54
57
|
"npm-run-all": "^4.1.5",
|
|
58
|
+
"perf_hooks": "^0.0.1",
|
|
55
59
|
"prettier": "^2.6.2",
|
|
56
60
|
"prettier-plugin-organize-imports": "^2.3.4",
|
|
57
61
|
"ts-jest": "^27.1.4",
|
|
58
62
|
"ts-node": "^10.2.1",
|
|
59
|
-
"typedoc": "^0.22.
|
|
60
|
-
"typescript": "^4.6.
|
|
63
|
+
"typedoc": "^0.22.15",
|
|
64
|
+
"typescript": "^4.6.4",
|
|
61
65
|
"web3": "^1.7.3"
|
|
62
66
|
},
|
|
63
67
|
"dependencies": {
|
|
68
|
+
"@noble/secp256k1": "^1.5.5",
|
|
64
69
|
"@types/big.js": "^6.1.3",
|
|
65
70
|
"big.js": "^6.1.1",
|
|
66
71
|
"isomorphic-unfetch": "^3.1.0",
|