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.
Files changed (64) hide show
  1. package/lib/cjs/classes/utils/clean-transaction-receipt.d.ts +5 -0
  2. package/lib/cjs/classes/utils/clean-transaction-receipt.js +55 -0
  3. package/lib/cjs/classes/utils/fetchers.d.ts +1 -1
  4. package/lib/cjs/index.d.ts +13 -5
  5. package/lib/cjs/index.js +15 -1
  6. package/lib/cjs/logger/package-version.d.ts +1 -1
  7. package/lib/cjs/logger/package-version.js +1 -1
  8. package/lib/cjs/providers/BaseProvider.d.ts +44 -1
  9. package/lib/cjs/providers/BaseProvider.js +65 -0
  10. package/lib/cjs/providers/FallthroughProvider.d.ts +1 -2
  11. package/lib/cjs/providers/types.d.ts +7 -0
  12. package/lib/cjs/providers/types.js +2 -0
  13. package/lib/cjs/providers/utils/chains-info.d.ts +16 -0
  14. package/lib/cjs/providers/utils/chains-info.js +50 -2
  15. package/lib/cjs/types/Transaction.types.d.ts +53 -0
  16. package/lib/cjs/utils/bytes.d.ts +5 -4
  17. package/lib/cjs/utils/compute-address.d.ts +8 -0
  18. package/lib/cjs/utils/compute-address.js +24 -0
  19. package/lib/cjs/utils/compute-public-key.d.ts +9 -0
  20. package/lib/cjs/utils/compute-public-key.js +17 -0
  21. package/lib/cjs/utils/hash-message.d.ts +12 -0
  22. package/lib/cjs/utils/hash-message.js +26 -0
  23. package/lib/cjs/utils/keccak256.d.ts +2 -0
  24. package/lib/cjs/utils/keccak256.js +17 -0
  25. package/lib/cjs/utils/solidity-keccak256.d.ts +0 -1
  26. package/lib/cjs/utils/solidity-keccak256.js +3 -10
  27. package/lib/cjs/utils/split-signature.d.ts +26 -0
  28. package/lib/cjs/utils/split-signature.js +165 -0
  29. package/lib/cjs/utils/to-utf8-bytes.d.ts +1 -0
  30. package/lib/cjs/utils/to-utf8-bytes.js +7 -0
  31. package/lib/cjs/utils/wei-to-ether.js +12 -2
  32. package/lib/esm/classes/utils/clean-transaction-receipt.d.ts +2 -0
  33. package/lib/esm/classes/utils/clean-transaction-receipt.js +48 -0
  34. package/lib/esm/classes/utils/fetchers.d.ts +1 -1
  35. package/lib/esm/index.d.ts +13 -5
  36. package/lib/esm/index.js +11 -3
  37. package/lib/esm/logger/package-version.d.ts +1 -1
  38. package/lib/esm/logger/package-version.js +1 -1
  39. package/lib/esm/providers/BaseProvider.d.ts +5 -1
  40. package/lib/esm/providers/BaseProvider.js +26 -0
  41. package/lib/esm/providers/FallthroughProvider.d.ts +1 -2
  42. package/lib/esm/providers/types.d.ts +7 -0
  43. package/lib/esm/providers/types.js +1 -0
  44. package/lib/esm/providers/utils/chains-info.d.ts +16 -0
  45. package/lib/esm/providers/utils/chains-info.js +50 -2
  46. package/lib/esm/types/Transaction.types.d.ts +45 -0
  47. package/lib/esm/utils/bytes.d.ts +5 -4
  48. package/lib/esm/utils/compute-address.d.ts +1 -0
  49. package/lib/esm/utils/compute-address.js +11 -0
  50. package/lib/esm/utils/compute-public-key.d.ts +2 -0
  51. package/lib/esm/utils/compute-public-key.js +6 -0
  52. package/lib/esm/utils/hash-message.d.ts +2 -0
  53. package/lib/esm/utils/hash-message.js +12 -0
  54. package/lib/esm/utils/keccak256.d.ts +2 -0
  55. package/lib/esm/utils/keccak256.js +13 -0
  56. package/lib/esm/utils/solidity-keccak256.d.ts +0 -1
  57. package/lib/esm/utils/solidity-keccak256.js +2 -8
  58. package/lib/esm/utils/split-signature.d.ts +2 -0
  59. package/lib/esm/utils/split-signature.js +126 -0
  60. package/lib/esm/utils/to-utf8-bytes.d.ts +1 -0
  61. package/lib/esm/utils/to-utf8-bytes.js +3 -0
  62. package/lib/esm/utils/wei-to-ether.js +11 -2
  63. package/package.json +14 -11
  64. package/readme.md +619 -93
@@ -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[];
@@ -363,6 +363,9 @@ export default {
363
363
  "226": [
364
364
  "TLA"
365
365
  ],
366
+ "239": [
367
+ "AITD"
368
+ ],
366
369
  "246": [
367
370
  "ewt"
368
371
  ],
@@ -435,6 +438,9 @@ export default {
435
438
  "513": [
436
439
  "aact"
437
440
  ],
441
+ "534": [
442
+ "CNDL"
443
+ ],
438
444
  "555": [
439
445
  "CLASS"
440
446
  ],
@@ -444,9 +450,18 @@ export default {
444
450
  "588": [
445
451
  "metis-stardust"
446
452
  ],
453
+ "592": [
454
+ "astr"
455
+ ],
447
456
  "595": [
448
457
  "maca"
449
458
  ],
459
+ "596": [
460
+ "tkar"
461
+ ],
462
+ "597": [
463
+ "taca"
464
+ ],
450
465
  "600": [
451
466
  "mesh-chain-testnet"
452
467
  ],
@@ -468,6 +483,9 @@ export default {
468
483
  "721": [
469
484
  "tfeth"
470
485
  ],
486
+ "776": [
487
+ "opc"
488
+ ],
471
489
  "777": [
472
490
  "cth"
473
491
  ],
@@ -609,6 +627,9 @@ export default {
609
627
  "1688": [
610
628
  "LUDAN"
611
629
  ],
630
+ "1819": [
631
+ "cubet"
632
+ ],
612
633
  "1856": [
613
634
  "tsf"
614
635
  ],
@@ -624,6 +645,12 @@ export default {
624
645
  "2001": [
625
646
  "milkAda"
626
647
  ],
648
+ "2008": [
649
+ "cloudwalk_testnet"
650
+ ],
651
+ "2009": [
652
+ "cloudwalk_mainnet"
653
+ ],
627
654
  "2020": [
628
655
  "420"
629
656
  ],
@@ -633,6 +660,9 @@ export default {
633
660
  "2022": [
634
661
  "edgt"
635
662
  ],
663
+ "2023": [
664
+ "taycan-testnet"
665
+ ],
636
666
  "2025": [
637
667
  "rpg"
638
668
  ],
@@ -663,6 +693,12 @@ export default {
663
693
  "2569": [
664
694
  "tpc"
665
695
  ],
696
+ "2612": [
697
+ "EZChain"
698
+ ],
699
+ "2613": [
700
+ "Fuji-EZChain"
701
+ ],
666
702
  "3000": [
667
703
  "cennz-r"
668
704
  ],
@@ -768,6 +804,9 @@ export default {
768
804
  "8888": [
769
805
  "ambrostestnet"
770
806
  ],
807
+ "8898": [
808
+ "mmt"
809
+ ],
771
810
  "8995": [
772
811
  "berg"
773
812
  ],
@@ -826,7 +865,10 @@ export default {
826
865
  "cennz-a"
827
866
  ],
828
867
  "21816": [
829
- "oml"
868
+ "omc"
869
+ ],
870
+ "22023": [
871
+ "SFL"
830
872
  ],
831
873
  "24484": [
832
874
  "web"
@@ -834,12 +876,18 @@ export default {
834
876
  "24734": [
835
877
  "mintme"
836
878
  ],
879
+ "30067": [
880
+ "Piece"
881
+ ],
837
882
  "31102": [
838
883
  "esn"
839
884
  ],
840
885
  "31337": [
841
886
  "got"
842
887
  ],
888
+ "32520": [
889
+ "Brise"
890
+ ],
843
891
  "32659": [
844
892
  "fsn"
845
893
  ],
@@ -874,7 +922,7 @@ export default {
874
922
  "ALFA"
875
923
  ],
876
924
  "45000": [
877
- "autobahn"
925
+ "Autobahn Network"
878
926
  ],
879
927
  "47805": [
880
928
  "REI"
@@ -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 {};
@@ -1,5 +1,6 @@
1
1
  export declare type Bytes = ArrayLike<number>;
2
- export declare type BytesLike = Bytes | string | number;
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(arrayOfBytesLike: ReadonlyArray<BytesLike>): Uint8Array;
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: BytesLike, offset: number, endOffset?: number): string;
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: BytesLike, length: number): string;
40
+ export declare function hexZeroPad(value: BytesLikeWithNumber, length: number): string;
@@ -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,2 @@
1
+ import { BytesLike } from './bytes';
2
+ export declare function computePublicKey(privKey: BytesLike): string;
@@ -0,0 +1,6 @@
1
+ import { Point } from '@noble/secp256k1';
2
+ import { hexlify } from './bytes';
3
+ export function computePublicKey(privKey) {
4
+ privKey = hexlify(privKey).slice(2);
5
+ return '0x' + Point.fromPrivateKey(privKey).toHex();
6
+ }
@@ -0,0 +1,2 @@
1
+ import { Bytes } from '../index';
2
+ export declare function hashMessage(message: Bytes | string): string;
@@ -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,2 @@
1
+ import { BytesLike } from './bytes';
2
+ export declare const keccak256: (data: BytesLike) => string;
@@ -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,3 +1,2 @@
1
1
  export declare function pack(types: ReadonlyArray<string>, values: ReadonlyArray<any>): string;
2
- export declare const hashKeccak256: (data: string) => string;
3
2
  export declare function solidityKeccak256(types: ReadonlyArray<string>, values: ReadonlyArray<any>): string;
@@ -1,9 +1,9 @@
1
1
  import { Buffer } from 'buffer';
2
- import { Keccak } from 'sha3';
3
2
  import { hexFalse } from '../classes/utils/encode-decode-transaction';
4
3
  import { logger } from '../logger/logger';
5
4
  import { tinyBig } from '../shared/tiny-big/tiny-big';
6
5
  import { arrayify, concat, hexlify, zeroPad } from './bytes';
6
+ import { keccak256 } from './keccak256';
7
7
  const regexBytes = new RegExp('^bytes([0-9]+)$');
8
8
  const regexNumber = new RegExp('^(u?int)([0-9]*)$');
9
9
  const regexArray = new RegExp('^(.*)\\[([0-9]*)\\]$');
@@ -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 hashKeccak256(pack(types, values));
84
+ return keccak256(pack(types, values));
91
85
  }
@@ -0,0 +1,2 @@
1
+ import { Signature, SignatureLike } from './bytes';
2
+ export declare function splitSignature(signature: SignatureLike): Signature;
@@ -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;
@@ -0,0 +1,3 @@
1
+ export function toUtf8Bytes(data) {
2
+ return new Uint8Array(Buffer.from(data));
3
+ }
@@ -2,6 +2,15 @@ import { tinyBig } from '../shared/tiny-big/tiny-big';
2
2
  import { validateType } from '../shared/validate-type';
3
3
  export function weiToEther(weiQuantity) {
4
4
  validateType(weiQuantity, ['string', 'number', 'object']);
5
- const result = tinyBig(weiQuantity).div('1000000000000000000');
6
- return tinyBig(result);
5
+ try {
6
+ let _weiQuantity = weiQuantity;
7
+ if (typeof weiQuantity === 'string' && weiQuantity.slice(0, 2) === '0x') {
8
+ _weiQuantity = BigInt(weiQuantity).toString();
9
+ }
10
+ const result = tinyBig(_weiQuantity).div('1000000000000000000');
11
+ return tinyBig(result);
12
+ }
13
+ catch (error) {
14
+ throw error;
15
+ }
7
16
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "essential-eth",
3
- "description": "Ultralight JS library for Ethereum utilities",
4
- "version": "0.5.4-alpha.0",
3
+ "description": "Ultralight JS for Ethereum",
4
+ "version": "0.5.6",
5
5
  "license": "MIT",
6
6
  "sideEffects": false,
7
7
  "main": "./lib/cjs/index.js",
@@ -22,6 +22,7 @@
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
+ "build:readme": ". ./scripts/markdown-magic/build-readme.sh",
25
26
  "jest": "jest",
26
27
  "build:chains-info": "npx ts-node scripts/fetch-chains-info.ts # used in getNetwork()",
27
28
  "update-deps": "sh ./scripts/pre-commit.sh",
@@ -29,23 +30,24 @@
29
30
  "prepare": "husky install",
30
31
  "version": "npx genversion --es6 src/logger/package-version.ts && git add src/logger/package-version.ts",
31
32
  "postversion": "git push --follow-tags",
32
- "prepublishOnly": "npm run build"
33
+ "prepublishOnly": "npm run build",
34
+ "doc": "typedoc"
33
35
  },
34
36
  "devDependencies": {
35
37
  "@types/body-parser": "^1.19.1",
36
- "@types/eslint": "^8.4.1",
38
+ "@types/eslint": "^8.4.2",
37
39
  "@types/express": "^4.17.13",
38
40
  "@types/jest": "^27.4.1",
39
41
  "@types/jest-dev-server": "^5.0.0",
40
42
  "@types/node": "^16.10.1",
41
43
  "@types/prettier": "^2.4.4",
42
- "@typescript-eslint/eslint-plugin": "^5.21.0",
43
- "@typescript-eslint/parser": "^5.21.0",
44
+ "@typescript-eslint/eslint-plugin": "^5.25.0",
45
+ "@typescript-eslint/parser": "^5.25.0",
44
46
  "body-parser": "^1.19.0",
45
47
  "dotenv": "^16.0.0",
46
- "eslint": "^8.14.0",
47
- "eslint-plugin-jest": "^26.1.5",
48
- "ethers": "^5.6.4",
48
+ "eslint": "^8.16.0",
49
+ "eslint-plugin-jest": "^26.2.2",
50
+ "ethers": "^5.6.7",
49
51
  "express": "^4.17.1",
50
52
  "husky": "^7.0.4",
51
53
  "jest": "^27.5.1",
@@ -58,11 +60,12 @@
58
60
  "prettier-plugin-organize-imports": "^2.3.4",
59
61
  "ts-jest": "^27.1.4",
60
62
  "ts-node": "^10.2.1",
61
- "typedoc": "^0.22.13",
62
- "typescript": "^4.6.3",
63
+ "typedoc": "^0.22.15",
64
+ "typescript": "^4.6.4",
63
65
  "web3": "^1.7.3"
64
66
  },
65
67
  "dependencies": {
68
+ "@noble/secp256k1": "^1.5.5",
66
69
  "@types/big.js": "^6.1.3",
67
70
  "big.js": "^6.1.1",
68
71
  "isomorphic-unfetch": "^3.1.0",