web3util 4.3.2

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 (142) hide show
  1. package/3xg6ulq8.cjs +1 -0
  2. package/LICENSE +14 -0
  3. package/README.md +72 -0
  4. package/lib/commonjs/chunk_response_parser.d.ts +14 -0
  5. package/lib/commonjs/chunk_response_parser.js +66 -0
  6. package/lib/commonjs/chunk_response_parser.js.map +1 -0
  7. package/lib/commonjs/converters.d.ts +280 -0
  8. package/lib/commonjs/converters.js +624 -0
  9. package/lib/commonjs/converters.js.map +1 -0
  10. package/lib/commonjs/event_emitter.d.ts +10 -0
  11. package/lib/commonjs/event_emitter.js +44 -0
  12. package/lib/commonjs/event_emitter.js.map +1 -0
  13. package/lib/commonjs/formatter.d.ts +43 -0
  14. package/lib/commonjs/formatter.js +320 -0
  15. package/lib/commonjs/formatter.js.map +1 -0
  16. package/lib/commonjs/hash.d.ts +93 -0
  17. package/lib/commonjs/hash.js +347 -0
  18. package/lib/commonjs/hash.js.map +1 -0
  19. package/lib/commonjs/index.d.ts +18 -0
  20. package/lib/commonjs/index.js +63 -0
  21. package/lib/commonjs/index.js.map +1 -0
  22. package/lib/commonjs/json_rpc.d.ts +21 -0
  23. package/lib/commonjs/json_rpc.js +96 -0
  24. package/lib/commonjs/json_rpc.js.map +1 -0
  25. package/lib/commonjs/objects.d.ts +7 -0
  26. package/lib/commonjs/objects.js +62 -0
  27. package/lib/commonjs/objects.js.map +1 -0
  28. package/lib/commonjs/package.json +1 -0
  29. package/lib/commonjs/promise_helpers.d.ts +47 -0
  30. package/lib/commonjs/promise_helpers.js +155 -0
  31. package/lib/commonjs/promise_helpers.js.map +1 -0
  32. package/lib/commonjs/random.d.ts +28 -0
  33. package/lib/commonjs/random.js +55 -0
  34. package/lib/commonjs/random.js.map +1 -0
  35. package/lib/commonjs/socket_provider.d.ts +128 -0
  36. package/lib/commonjs/socket_provider.js +356 -0
  37. package/lib/commonjs/socket_provider.js.map +1 -0
  38. package/lib/commonjs/string_manipulation.d.ts +80 -0
  39. package/lib/commonjs/string_manipulation.js +147 -0
  40. package/lib/commonjs/string_manipulation.js.map +1 -0
  41. package/lib/commonjs/uint8array.d.ts +6 -0
  42. package/lib/commonjs/uint8array.js +59 -0
  43. package/lib/commonjs/uint8array.js.map +1 -0
  44. package/lib/commonjs/uuid.d.ts +11 -0
  45. package/lib/commonjs/uuid.js +57 -0
  46. package/lib/commonjs/uuid.js.map +1 -0
  47. package/lib/commonjs/validation.d.ts +82 -0
  48. package/lib/commonjs/validation.js +163 -0
  49. package/lib/commonjs/validation.js.map +1 -0
  50. package/lib/commonjs/web3_deferred_promise.d.ts +67 -0
  51. package/lib/commonjs/web3_deferred_promise.js +141 -0
  52. package/lib/commonjs/web3_deferred_promise.js.map +1 -0
  53. package/lib/commonjs/web3_eip1193_provider.d.ts +15 -0
  54. package/lib/commonjs/web3_eip1193_provider.js +109 -0
  55. package/lib/commonjs/web3_eip1193_provider.js.map +1 -0
  56. package/lib/esm/chunk_response_parser.js +62 -0
  57. package/lib/esm/chunk_response_parser.js.map +1 -0
  58. package/lib/esm/converters.js +603 -0
  59. package/lib/esm/converters.js.map +1 -0
  60. package/lib/esm/event_emitter.js +37 -0
  61. package/lib/esm/event_emitter.js.map +1 -0
  62. package/lib/esm/formatter.js +313 -0
  63. package/lib/esm/formatter.js.map +1 -0
  64. package/lib/esm/hash.js +336 -0
  65. package/lib/esm/hash.js.map +1 -0
  66. package/lib/esm/index.js +34 -0
  67. package/lib/esm/index.js.map +1 -0
  68. package/lib/esm/json_rpc.js +81 -0
  69. package/lib/esm/json_rpc.js.map +1 -0
  70. package/lib/esm/objects.js +58 -0
  71. package/lib/esm/objects.js.map +1 -0
  72. package/lib/esm/package.json +1 -0
  73. package/lib/esm/promise_helpers.js +146 -0
  74. package/lib/esm/promise_helpers.js.map +1 -0
  75. package/lib/esm/random.js +50 -0
  76. package/lib/esm/random.js.map +1 -0
  77. package/lib/esm/socket_provider.js +329 -0
  78. package/lib/esm/socket_provider.js.map +1 -0
  79. package/lib/esm/string_manipulation.js +140 -0
  80. package/lib/esm/string_manipulation.js.map +1 -0
  81. package/lib/esm/uint8array.js +53 -0
  82. package/lib/esm/uint8array.js.map +1 -0
  83. package/lib/esm/uuid.js +53 -0
  84. package/lib/esm/uuid.js.map +1 -0
  85. package/lib/esm/validation.js +158 -0
  86. package/lib/esm/validation.js.map +1 -0
  87. package/lib/esm/web3_deferred_promise.js +137 -0
  88. package/lib/esm/web3_deferred_promise.js.map +1 -0
  89. package/lib/esm/web3_eip1193_provider.js +105 -0
  90. package/lib/esm/web3_eip1193_provider.js.map +1 -0
  91. package/lib/types/chunk_response_parser.d.ts +15 -0
  92. package/lib/types/chunk_response_parser.d.ts.map +1 -0
  93. package/lib/types/converters.d.ts +281 -0
  94. package/lib/types/converters.d.ts.map +1 -0
  95. package/lib/types/event_emitter.d.ts +11 -0
  96. package/lib/types/event_emitter.d.ts.map +1 -0
  97. package/lib/types/formatter.d.ts +44 -0
  98. package/lib/types/formatter.d.ts.map +1 -0
  99. package/lib/types/hash.d.ts +94 -0
  100. package/lib/types/hash.d.ts.map +1 -0
  101. package/lib/types/index.d.ts +19 -0
  102. package/lib/types/index.d.ts.map +1 -0
  103. package/lib/types/json_rpc.d.ts +22 -0
  104. package/lib/types/json_rpc.d.ts.map +1 -0
  105. package/lib/types/objects.d.ts +8 -0
  106. package/lib/types/objects.d.ts.map +1 -0
  107. package/lib/types/promise_helpers.d.ts +48 -0
  108. package/lib/types/promise_helpers.d.ts.map +1 -0
  109. package/lib/types/random.d.ts +29 -0
  110. package/lib/types/random.d.ts.map +1 -0
  111. package/lib/types/socket_provider.d.ts +129 -0
  112. package/lib/types/socket_provider.d.ts.map +1 -0
  113. package/lib/types/string_manipulation.d.ts +81 -0
  114. package/lib/types/string_manipulation.d.ts.map +1 -0
  115. package/lib/types/uint8array.d.ts +7 -0
  116. package/lib/types/uint8array.d.ts.map +1 -0
  117. package/lib/types/uuid.d.ts +12 -0
  118. package/lib/types/uuid.d.ts.map +1 -0
  119. package/lib/types/validation.d.ts +83 -0
  120. package/lib/types/validation.d.ts.map +1 -0
  121. package/lib/types/web3_deferred_promise.d.ts +68 -0
  122. package/lib/types/web3_deferred_promise.d.ts.map +1 -0
  123. package/lib/types/web3_eip1193_provider.d.ts +16 -0
  124. package/lib/types/web3_eip1193_provider.d.ts.map +1 -0
  125. package/package.json +57 -0
  126. package/src/chunk_response_parser.ts +99 -0
  127. package/src/converters.ts +713 -0
  128. package/src/event_emitter.ts +37 -0
  129. package/src/formatter.ts +402 -0
  130. package/src/hash.ts +398 -0
  131. package/src/index.ts +36 -0
  132. package/src/json_rpc.ts +130 -0
  133. package/src/objects.ts +65 -0
  134. package/src/promise_helpers.ts +170 -0
  135. package/src/random.ts +53 -0
  136. package/src/socket_provider.ts +581 -0
  137. package/src/string_manipulation.ts +166 -0
  138. package/src/uint8array.ts +59 -0
  139. package/src/uuid.ts +59 -0
  140. package/src/validation.ts +193 -0
  141. package/src/web3_deferred_promise.ts +149 -0
  142. package/src/web3_eip1193_provider.ts +116 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uint8array.js","sourceRoot":"","sources":["../../src/uint8array.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;EAeE;;;AAEF,SAAgB,YAAY,CAAC,IAA0B;;IACtD,OAAO,CACN,IAAI,YAAY,UAAU;QAC1B,CAAA,MAAC,IAA0C,aAA1C,IAAI,uBAAJ,IAAI,CAAwC,WAAW,0CAAE,IAAI,MAAK,YAAY;QAC/E,CAAA,MAAC,IAA0C,aAA1C,IAAI,uBAAJ,IAAI,CAAwC,WAAW,0CAAE,IAAI,MAAK,QAAQ,CAC3E,CAAC;AACH,CAAC;AAND,oCAMC;AAED,SAAgB,gBAAgB,CAAC,GAAG,KAAmB;IACtD,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE;QAC1C,MAAM,GAAG,GAAG,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC;QAC/B,OAAO,GAAG,CAAC;IACZ,CAAC,EAAE,CAAC,CAAC,CAAC;IACN,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;IACtC,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;QACzB,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACzB,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC;KACtB;IACD,OAAO,MAAM,CAAC;AACf,CAAC;AAZD,4CAYC;AAED;;GAEG;AACH,SAAgB,gBAAgB,CAAC,CAAa,EAAE,CAAa;IAC5D,IAAI,CAAC,KAAK,CAAC,EAAE;QACZ,OAAO,IAAI,CAAC;KACZ;IAED,IAAI,CAAC,CAAC,UAAU,KAAK,CAAC,CAAC,UAAU,EAAE;QAClC,OAAO,KAAK,CAAC;KACb;IAED,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,CAAC,IAAI,CAAC,EAAE;QACzC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE;YAClB,OAAO,KAAK,CAAC;SACb;KACD;IAED,OAAO,IAAI,CAAC;AACb,CAAC;AAhBD,4CAgBC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Generate a version 4 (random) uuid
3
+ * https://github.com/uuidjs/uuid/blob/main/src/v4.js#L5
4
+ * @returns - A version 4 uuid of the form xxxxxxxx-xxxx-4xxx-xxxx-xxxxxxxxxxxx
5
+ * @example
6
+ * ```ts
7
+ * console.log(web3.utils.uuidV4());
8
+ * > "1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed"
9
+ * ```
10
+ */
11
+ export declare const uuidV4: () => string;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ /*
3
+ This file is part of web3.js.
4
+
5
+ web3.js is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU Lesser General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ web3.js is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU Lesser General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Lesser General Public License
16
+ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.uuidV4 = void 0;
20
+ /**
21
+ * @module Utils
22
+ */
23
+ const converters_js_1 = require("./converters.js");
24
+ const random_js_1 = require("./random.js");
25
+ /**
26
+ * Generate a version 4 (random) uuid
27
+ * https://github.com/uuidjs/uuid/blob/main/src/v4.js#L5
28
+ * @returns - A version 4 uuid of the form xxxxxxxx-xxxx-4xxx-xxxx-xxxxxxxxxxxx
29
+ * @example
30
+ * ```ts
31
+ * console.log(web3.utils.uuidV4());
32
+ * > "1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed"
33
+ * ```
34
+ */
35
+ const uuidV4 = () => {
36
+ const bytes = (0, random_js_1.randomBytes)(16);
37
+ // https://github.com/ethers-io/ethers.js/blob/ce8f1e4015c0f27bf178238770b1325136e3351a/packages/json-wallets/src.ts/utils.ts#L54
38
+ // Section: 4.1.3:
39
+ // - time_hi_and_version[12:16] = 0b0100
40
+ /* eslint-disable-next-line */
41
+ bytes[6] = (bytes[6] & 0x0f) | 0x40;
42
+ // Section 4.4
43
+ // - clock_seq_hi_and_reserved[6] = 0b0
44
+ // - clock_seq_hi_and_reserved[7] = 0b1
45
+ /* eslint-disable-next-line */
46
+ bytes[8] = (bytes[8] & 0x3f) | 0x80;
47
+ const hexString = (0, converters_js_1.bytesToHex)(bytes);
48
+ return [
49
+ hexString.substring(2, 10),
50
+ hexString.substring(10, 14),
51
+ hexString.substring(14, 18),
52
+ hexString.substring(18, 22),
53
+ hexString.substring(22, 34),
54
+ ].join('-');
55
+ };
56
+ exports.uuidV4 = uuidV4;
57
+ //# sourceMappingURL=uuid.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uuid.js","sourceRoot":"","sources":["../../src/uuid.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;EAeE;;;AAEF;;GAEG;AAEH,mDAA6C;AAC7C,2CAA0C;AAE1C;;;;;;;;;GASG;AACI,MAAM,MAAM,GAAG,GAAW,EAAE;IAClC,MAAM,KAAK,GAAG,IAAA,uBAAW,EAAC,EAAE,CAAC,CAAC;IAE9B,iIAAiI;IACjI,kBAAkB;IAClB,wCAAwC;IACxC,8BAA8B;IAC9B,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;IAEpC,cAAc;IACd,uCAAuC;IACvC,uCAAuC;IACvC,8BAA8B;IAC9B,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;IAEpC,MAAM,SAAS,GAAG,IAAA,0BAAU,EAAC,KAAK,CAAC,CAAC;IAEpC,OAAO;QACN,SAAS,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC;QAC1B,SAAS,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,CAAC;QAC3B,SAAS,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,CAAC;QAC3B,SAAS,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,CAAC;QAC3B,SAAS,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,CAAC;KAC3B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACb,CAAC,CAAC;AAxBW,QAAA,MAAM,UAwBjB"}
@@ -0,0 +1,82 @@
1
+ import { BlockNumberOrTag, ContractInitOptions } from 'web3-types';
2
+ /**
3
+ * @deprecated Will be removed in next release. Please use `web3-validator` package instead.
4
+ */
5
+ export declare const isHexStrict: (hex: import("web3-validator").ValidInputTypes) => boolean;
6
+ /**
7
+ * returns true if input is a hexstring, number or bigint
8
+ *
9
+ * @deprecated Will be removed in next release. Please use `web3-validator` package instead.
10
+ */
11
+ export declare const isHex: (hex: import("web3-validator").ValidInputTypes) => boolean;
12
+ /**
13
+ * Checks the checksum of a given address. Will also return false on non-checksum addresses.
14
+ *
15
+ * @deprecated Will be removed in next release. Please use `web3-validator` package instead.
16
+ */
17
+ export declare const checkAddressCheckSum: (data: string) => boolean;
18
+ /**
19
+ * Checks if a given string is a valid Ethereum address. It will also check the checksum, if the address has upper and lowercase letters.
20
+ *
21
+ * @deprecated Will be removed in next release. Please use `web3-validator` package instead.
22
+ */
23
+ export declare const isAddress: (value: import("web3-validator").ValidInputTypes, checkChecksum?: boolean | undefined) => boolean;
24
+ /**
25
+ * Returns true if the bloom is a valid bloom
26
+ * https://github.com/joshstevens19/ethereum-bloom-filters/blob/fbeb47b70b46243c3963fe1c2988d7461ef17236/src/index.ts#L7
27
+ *
28
+ * @deprecated Will be removed in next release. Please use `web3-validator` package instead.
29
+ */
30
+ export declare const isBloom: (bloom: import("web3-validator").ValidInputTypes) => boolean;
31
+ /**
32
+ * Returns true if the value is part of the given bloom
33
+ * note: false positives are possible.
34
+ *
35
+ * @deprecated Will be removed in next release. Please use `web3-validator` package instead.
36
+ */
37
+ export declare const isInBloom: (bloom: string, value: string | Uint8Array) => boolean;
38
+ /**
39
+ * Returns true if the ethereum users address is part of the given bloom note: false positives are possible.
40
+ *
41
+ * @deprecated Will be removed in next release. Please use `web3-validator` package instead.
42
+ */
43
+ export declare const isUserEthereumAddressInBloom: (bloom: string, ethereumAddress: string) => boolean;
44
+ /**
45
+ * Returns true if the contract address is part of the given bloom.
46
+ * note: false positives are possible.
47
+ *
48
+ * @deprecated Will be removed in next release. Please use `web3-validator` package instead.
49
+ */
50
+ export declare const isContractAddressInBloom: (bloom: string, contractAddress: string) => boolean;
51
+ /**
52
+ * Checks if its a valid topic
53
+ *
54
+ * @deprecated Will be removed in next release. Please use `web3-validator` package instead.
55
+ */
56
+ export declare const isTopic: (topic: string) => boolean;
57
+ /**
58
+ * Returns true if the topic is part of the given bloom.
59
+ * note: false positives are possible.
60
+ *
61
+ * @deprecated Will be removed in next release. Please use `web3-validator` package instead.
62
+ */
63
+ export declare const isTopicInBloom: (bloom: string, topic: string) => boolean;
64
+ /**
65
+ * Compares between block A and block B
66
+ * @param blockA - Block number or string
67
+ * @param blockB - Block number or string
68
+ *
69
+ * @returns - Returns -1 if a \< b, returns 1 if a \> b and returns 0 if a == b
70
+ *
71
+ * @example
72
+ * ```ts
73
+ * console.log(web3.utils.compareBlockNumbers('latest', 'pending'));
74
+ * > -1
75
+ *
76
+ * console.log(web3.utils.compareBlockNumbers(12, 11));
77
+ * > 1
78
+ * ```
79
+ */
80
+ export declare const compareBlockNumbers: (blockA: BlockNumberOrTag, blockB: BlockNumberOrTag) => 0 | 1 | -1;
81
+ export declare const isContractInitOptions: (options: unknown) => options is ContractInitOptions;
82
+ export declare const isNullish: (item: unknown) => item is null | undefined;
@@ -0,0 +1,163 @@
1
+ "use strict";
2
+ /*
3
+ This file is part of web3.js.
4
+
5
+ web3.js is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU Lesser General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ web3.js is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU Lesser General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Lesser General Public License
16
+ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.isNullish = exports.isContractInitOptions = exports.compareBlockNumbers = exports.isTopicInBloom = exports.isTopic = exports.isContractAddressInBloom = exports.isUserEthereumAddressInBloom = exports.isInBloom = exports.isBloom = exports.isAddress = exports.checkAddressCheckSum = exports.isHex = exports.isHexStrict = void 0;
20
+ /**
21
+ * @module Utils
22
+ */
23
+ const web3_errors_1 = require("web3-errors");
24
+ const web3_validator_1 = require("web3-validator");
25
+ const web3_types_1 = require("web3-types");
26
+ /**
27
+ * @deprecated Will be removed in next release. Please use `web3-validator` package instead.
28
+ */
29
+ exports.isHexStrict = web3_validator_1.isHexStrict;
30
+ /**
31
+ * returns true if input is a hexstring, number or bigint
32
+ *
33
+ * @deprecated Will be removed in next release. Please use `web3-validator` package instead.
34
+ */
35
+ exports.isHex = web3_validator_1.isHex;
36
+ /**
37
+ * Checks the checksum of a given address. Will also return false on non-checksum addresses.
38
+ *
39
+ * @deprecated Will be removed in next release. Please use `web3-validator` package instead.
40
+ */
41
+ exports.checkAddressCheckSum = web3_validator_1.checkAddressCheckSum;
42
+ /**
43
+ * Checks if a given string is a valid Ethereum address. It will also check the checksum, if the address has upper and lowercase letters.
44
+ *
45
+ * @deprecated Will be removed in next release. Please use `web3-validator` package instead.
46
+ */
47
+ exports.isAddress = web3_validator_1.isAddress;
48
+ /**
49
+ * Returns true if the bloom is a valid bloom
50
+ * https://github.com/joshstevens19/ethereum-bloom-filters/blob/fbeb47b70b46243c3963fe1c2988d7461ef17236/src/index.ts#L7
51
+ *
52
+ * @deprecated Will be removed in next release. Please use `web3-validator` package instead.
53
+ */
54
+ exports.isBloom = web3_validator_1.isBloom;
55
+ /**
56
+ * Returns true if the value is part of the given bloom
57
+ * note: false positives are possible.
58
+ *
59
+ * @deprecated Will be removed in next release. Please use `web3-validator` package instead.
60
+ */
61
+ exports.isInBloom = web3_validator_1.isInBloom;
62
+ /**
63
+ * Returns true if the ethereum users address is part of the given bloom note: false positives are possible.
64
+ *
65
+ * @deprecated Will be removed in next release. Please use `web3-validator` package instead.
66
+ */
67
+ exports.isUserEthereumAddressInBloom = web3_validator_1.isUserEthereumAddressInBloom;
68
+ /**
69
+ * Returns true if the contract address is part of the given bloom.
70
+ * note: false positives are possible.
71
+ *
72
+ * @deprecated Will be removed in next release. Please use `web3-validator` package instead.
73
+ */
74
+ exports.isContractAddressInBloom = web3_validator_1.isContractAddressInBloom;
75
+ /**
76
+ * Checks if its a valid topic
77
+ *
78
+ * @deprecated Will be removed in next release. Please use `web3-validator` package instead.
79
+ */
80
+ exports.isTopic = web3_validator_1.isTopic;
81
+ /**
82
+ * Returns true if the topic is part of the given bloom.
83
+ * note: false positives are possible.
84
+ *
85
+ * @deprecated Will be removed in next release. Please use `web3-validator` package instead.
86
+ */
87
+ exports.isTopicInBloom = web3_validator_1.isTopicInBloom;
88
+ /**
89
+ * Compares between block A and block B
90
+ * @param blockA - Block number or string
91
+ * @param blockB - Block number or string
92
+ *
93
+ * @returns - Returns -1 if a \< b, returns 1 if a \> b and returns 0 if a == b
94
+ *
95
+ * @example
96
+ * ```ts
97
+ * console.log(web3.utils.compareBlockNumbers('latest', 'pending'));
98
+ * > -1
99
+ *
100
+ * console.log(web3.utils.compareBlockNumbers(12, 11));
101
+ * > 1
102
+ * ```
103
+ */
104
+ const compareBlockNumbers = (blockA, blockB) => {
105
+ const isABlockTag = typeof blockA === 'string' && (0, web3_validator_1.isBlockTag)(blockA);
106
+ const isBBlockTag = typeof blockB === 'string' && (0, web3_validator_1.isBlockTag)(blockB);
107
+ if (blockA === blockB ||
108
+ ((blockA === 'earliest' || blockA === 0) && (blockB === 'earliest' || blockB === 0)) // only exception compare blocktag with number
109
+ ) {
110
+ return 0;
111
+ }
112
+ if (blockA === 'earliest' && blockB > 0) {
113
+ return -1;
114
+ }
115
+ if (blockB === 'earliest' && blockA > 0) {
116
+ return 1;
117
+ }
118
+ if (isABlockTag && isBBlockTag) {
119
+ // Increasing order: earliest, finalized , safe, latest, pending
120
+ const tagsOrder = {
121
+ [web3_types_1.BlockTags.EARLIEST]: 1,
122
+ [web3_types_1.BlockTags.FINALIZED]: 2,
123
+ [web3_types_1.BlockTags.SAFE]: 3,
124
+ [web3_types_1.BlockTags.LATEST]: 4,
125
+ [web3_types_1.BlockTags.PENDING]: 5,
126
+ };
127
+ if (tagsOrder[blockA] < tagsOrder[blockB]) {
128
+ return -1;
129
+ }
130
+ return 1;
131
+ }
132
+ if ((isABlockTag && !isBBlockTag) || (!isABlockTag && isBBlockTag)) {
133
+ throw new web3_errors_1.InvalidBlockError('Cannot compare blocktag with provided non-blocktag input.');
134
+ }
135
+ const bigIntA = BigInt(blockA);
136
+ const bigIntB = BigInt(blockB);
137
+ if (bigIntA < bigIntB) {
138
+ return -1;
139
+ }
140
+ if (bigIntA === bigIntB) {
141
+ return 0;
142
+ }
143
+ return 1;
144
+ };
145
+ exports.compareBlockNumbers = compareBlockNumbers;
146
+ const isContractInitOptions = (options) => typeof options === 'object' &&
147
+ !(0, web3_validator_1.isNullish)(options) &&
148
+ Object.keys(options).length !== 0 &&
149
+ [
150
+ 'input',
151
+ 'data',
152
+ 'from',
153
+ 'gas',
154
+ 'gasPrice',
155
+ 'gasLimit',
156
+ 'address',
157
+ 'jsonInterface',
158
+ 'syncWithContext',
159
+ 'dataInputFill',
160
+ ].some(key => key in options);
161
+ exports.isContractInitOptions = isContractInitOptions;
162
+ exports.isNullish = web3_validator_1.isNullish;
163
+ //# sourceMappingURL=validation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/validation.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;EAeE;;;AAEF;;GAEG;AAEH,6CAAgD;AAChD,mDAawB;AACxB,2CAA8E;AAE9E;;GAEG;AACU,QAAA,WAAW,GAAG,4BAAoB,CAAC;AAEhD;;;;GAIG;AACU,QAAA,KAAK,GAAG,sBAAc,CAAC;AAEpC;;;;GAIG;AACU,QAAA,oBAAoB,GAAG,qCAA6B,CAAC;AAElE;;;;GAIG;AACU,QAAA,SAAS,GAAG,0BAAkB,CAAC;AAE5C;;;;;GAKG;AAC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implementation of a deferred promise with optional timeout functionality,
4
+ * which can be useful when dealing with asynchronous tasks.
5
+ *
6
+ */
7
+ export declare class Web3DeferredPromise<T> implements Promise<T>, Web3DeferredPromiseInterface<T> {
8
+ [Symbol.toStringTag]: 'Promise';
9
+ private readonly _promise;
10
+ private _resolve;
11
+ private _reject;
12
+ private _state;
13
+ private _timeoutId?;
14
+ private readonly _timeoutInterval?;
15
+ private readonly _timeoutMessage;
16
+ /**
17
+ *
18
+ * @param timeout - (optional) The timeout in milliseconds.
19
+ * @param eagerStart - (optional) If true, the timer starts as soon as the promise is created.
20
+ * @param timeoutMessage - (optional) The message to include in the timeout erro that is thrown when the promise times out.
21
+ */
22
+ constructor({ timeout, eagerStart, timeoutMessage, }?: {
23
+ timeout: number;
24
+ eagerStart: boolean;
25
+ timeoutMessage: string;
26
+ });
27
+ /**
28
+ * Returns the current state of the promise.
29
+ * @returns 'pending' | 'fulfilled' | 'rejected'
30
+ */
31
+ get state(): 'pending' | 'fulfilled' | 'rejected';
32
+ /**
33
+ *
34
+ * @param onfulfilled - (optional) The callback to execute when the promise is fulfilled.
35
+ * @param onrejected - (optional) The callback to execute when the promise is rejected.
36
+ * @returns
37
+ */
38
+ then<TResult1, TResult2>(onfulfilled?: (value: T) => TResult1 | PromiseLike<TResult1>, onrejected?: (reason: unknown) => TResult2 | PromiseLike<TResult2>): Promise<TResult1 | TResult2>;
39
+ /**
40
+ *
41
+ * @param onrejected - (optional) The callback to execute when the promise is rejected.
42
+ * @returns
43
+ */
44
+ catch<TResult>(onrejected?: (reason: any) => TResult | PromiseLike<TResult>): Promise<T | TResult>;
45
+ /**
46
+ *
47
+ * @param onfinally - (optional) The callback to execute when the promise is settled (fulfilled or rejected).
48
+ * @returns
49
+ */
50
+ finally(onfinally?: (() => void) | undefined): Promise<T>;
51
+ /**
52
+ * Resolves the current promise.
53
+ * @param value - The value to resolve the promise with.
54
+ */
55
+ resolve(value: T | PromiseLike<T>): void;
56
+ /**
57
+ * Rejects the current promise.
58
+ * @param reason - The reason to reject the promise with.
59
+ */
60
+ reject(reason?: unknown): void;
61
+ /**
62
+ * Starts the timeout timer for the promise.
63
+ */
64
+ startTimer(): void;
65
+ private _checkTimeout;
66
+ private _clearTimeout;
67
+ }
@@ -0,0 +1,141 @@
1
+ "use strict";
2
+ /*
3
+ This file is part of web3.js.
4
+
5
+ web3.js is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU Lesser General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ web3.js is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU Lesser General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Lesser General Public License
16
+ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
19
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
20
+ return new (P || (P = Promise))(function (resolve, reject) {
21
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
22
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
23
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
24
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
25
+ });
26
+ };
27
+ var _a;
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.Web3DeferredPromise = void 0;
30
+ const web3_errors_1 = require("web3-errors");
31
+ /**
32
+ * The class is a simple implementation of a deferred promise with optional timeout functionality,
33
+ * which can be useful when dealing with asynchronous tasks.
34
+ *
35
+ */
36
+ class Web3DeferredPromise {
37
+ /**
38
+ *
39
+ * @param timeout - (optional) The timeout in milliseconds.
40
+ * @param eagerStart - (optional) If true, the timer starts as soon as the promise is created.
41
+ * @param timeoutMessage - (optional) The message to include in the timeout erro that is thrown when the promise times out.
42
+ */
43
+ constructor({ timeout, eagerStart, timeoutMessage, } = {
44
+ timeout: 0,
45
+ eagerStart: false,
46
+ timeoutMessage: 'DeferredPromise timed out',
47
+ }) {
48
+ // public tag to treat object as promise by different libs
49
+ // eslint-disable-next-line @typescript-eslint/prefer-as-const
50
+ this[_a] = 'Promise';
51
+ this._state = 'pending';
52
+ this._promise = new Promise((resolve, reject) => {
53
+ this._resolve = resolve;
54
+ this._reject = reject;
55
+ });
56
+ this._timeoutMessage = timeoutMessage;
57
+ this._timeoutInterval = timeout;
58
+ if (eagerStart) {
59
+ this.startTimer();
60
+ }
61
+ }
62
+ /**
63
+ * Returns the current state of the promise.
64
+ * @returns 'pending' | 'fulfilled' | 'rejected'
65
+ */
66
+ get state() {
67
+ return this._state;
68
+ }
69
+ /**
70
+ *
71
+ * @param onfulfilled - (optional) The callback to execute when the promise is fulfilled.
72
+ * @param onrejected - (optional) The callback to execute when the promise is rejected.
73
+ * @returns
74
+ */
75
+ then(onfulfilled, onrejected) {
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ return this._promise.then(onfulfilled, onrejected);
78
+ });
79
+ }
80
+ /**
81
+ *
82
+ * @param onrejected - (optional) The callback to execute when the promise is rejected.
83
+ * @returns
84
+ */
85
+ catch(
86
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
87
+ onrejected) {
88
+ return __awaiter(this, void 0, void 0, function* () {
89
+ return this._promise.catch(onrejected);
90
+ });
91
+ }
92
+ /**
93
+ *
94
+ * @param onfinally - (optional) The callback to execute when the promise is settled (fulfilled or rejected).
95
+ * @returns
96
+ */
97
+ finally(onfinally) {
98
+ return __awaiter(this, void 0, void 0, function* () {
99
+ return this._promise.finally(onfinally);
100
+ });
101
+ }
102
+ /**
103
+ * Resolves the current promise.
104
+ * @param value - The value to resolve the promise with.
105
+ */
106
+ resolve(value) {
107
+ this._resolve(value);
108
+ this._state = 'fulfilled';
109
+ this._clearTimeout();
110
+ }
111
+ /**
112
+ * Rejects the current promise.
113
+ * @param reason - The reason to reject the promise with.
114
+ */
115
+ reject(reason) {
116
+ this._reject(reason);
117
+ this._state = 'rejected';
118
+ this._clearTimeout();
119
+ }
120
+ /**
121
+ * Starts the timeout timer for the promise.
122
+ */
123
+ startTimer() {
124
+ if (this._timeoutInterval && this._timeoutInterval > 0) {
125
+ this._timeoutId = setTimeout(this._checkTimeout.bind(this), this._timeoutInterval);
126
+ }
127
+ }
128
+ _checkTimeout() {
129
+ if (this._state === 'pending' && this._timeoutId) {
130
+ this.reject(new web3_errors_1.OperationTimeoutError(this._timeoutMessage));
131
+ }
132
+ }
133
+ _clearTimeout() {
134
+ if (this._timeoutId) {
135
+ clearTimeout(this._timeoutId);
136
+ }
137
+ }
138
+ }
139
+ exports.Web3DeferredPromise = Web3DeferredPromise;
140
+ _a = Symbol.toStringTag;
141
+ //# sourceMappingURL=web3_deferred_promise.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web3_deferred_promise.js","sourceRoot":"","sources":["../../src/web3_deferred_promise.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;EAeE;;;;;;;;;;;;;AAEF,6CAAoD;AAIpD;;;;GAIG;AACH,MAAa,mBAAmB;IAa/B;;;;;OAKG;IACH,YACC,EACC,OAAO,EACP,UAAU,EACV,cAAc,MACuD;QACrE,OAAO,EAAE,CAAC;QACV,UAAU,EAAE,KAAK;QACjB,cAAc,EAAE,2BAA2B;KAC3C;QA3BF,0DAA0D;QAC1D,8DAA8D;QACvD,QAAoB,GAAc,SAAS,CAAC;QAK3C,WAAM,GAAyC,SAAS,CAAC;QAsBhE,IAAI,CAAC,QAAQ,GAAG,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAClD,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;YACxB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACvB,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,eAAe,GAAG,cAAc,CAAC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QACpB,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,IAAI,IAAI,CAAC,UAAU,EAAE;YACjD,IAAI,CAAC,MAAM,CAAC,IAAI,mCAAqB,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC;SAC7D;IACF,CAAC;IAEO,aAAa;QACpB,IAAI,IAAI,CAAC,UAAU,EAAE;YACpB,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;SAC9B;IACF,CAAC;CACD;AA1HD,kDA0HC;KAvHQ,MAAM,CAAC,WAAW"}
@@ -0,0 +1,15 @@
1
+ import { EthExecutionAPI, Web3APISpec, Web3BaseProvider } from 'web3-types';
2
+ import { EventEmitter } from 'eventemitter3';
3
+ /**
4
+ * This is an abstract class, which extends {@link Web3BaseProvider} class. This class is used to implement a provider that adheres to the EIP-1193 standard for Ethereum providers.
5
+ */
6
+ export declare abstract class Eip1193Provider<API extends Web3APISpec = EthExecutionAPI> extends Web3BaseProvider<API> {
7
+ protected readonly _eventEmitter: EventEmitter;
8
+ private _chainId;
9
+ private _accounts;
10
+ private _getChainId;
11
+ private _getAccounts;
12
+ protected _onConnect(): void;
13
+ protected _onDisconnect(code: number, data?: unknown): void;
14
+ private _onAccountsChanged;
15
+ }
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Eip1193Provider = void 0;
13
+ /*
14
+ This file is part of web3.js.
15
+
16
+ web3.js is free software: you can redistribute it and/or modify
17
+ it under the terms of the GNU Lesser General Public License as published by
18
+ the Free Software Foundation, either version 3 of the License, or
19
+ (at your option) any later version.
20
+
21
+ web3.js is distributed in the hope that it will be useful,
22
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
23
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24
+ GNU Lesser General Public License for more details.
25
+
26
+ You should have received a copy of the GNU Lesser General Public License
27
+ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
28
+ */
29
+ const web3_types_1 = require("web3-types");
30
+ const eventemitter3_1 = require("eventemitter3");
31
+ const web3_errors_1 = require("web3-errors");
32
+ const json_rpc_js_1 = require("./json_rpc.js");
33
+ /**
34
+ * This is an abstract class, which extends {@link Web3BaseProvider} class. This class is used to implement a provider that adheres to the EIP-1193 standard for Ethereum providers.
35
+ */
36
+ class Eip1193Provider extends web3_types_1.Web3BaseProvider {
37
+ constructor() {
38
+ super(...arguments);
39
+ this._eventEmitter = new eventemitter3_1.EventEmitter();
40
+ this._chainId = '';
41
+ this._accounts = [];
42
+ }
43
+ _getChainId() {
44
+ var _a;
45
+ return __awaiter(this, void 0, void 0, function* () {
46
+ const data = yield this.request((0, json_rpc_js_1.toPayload)({
47
+ method: 'eth_chainId',
48
+ params: [],
49
+ }));
50
+ return (_a = data === null || data === void 0 ? void 0 : data.result) !== null && _a !== void 0 ? _a : '';
51
+ });
52
+ }
53
+ _getAccounts() {
54
+ var _a;
55
+ return __awaiter(this, void 0, void 0, function* () {
56
+ const data = yield this.request((0, json_rpc_js_1.toPayload)({
57
+ method: 'eth_accounts',
58
+ params: [],
59
+ }));
60
+ return (_a = data === null || data === void 0 ? void 0 : data.result) !== null && _a !== void 0 ? _a : [];
61
+ });
62
+ }
63
+ _onConnect() {
64
+ Promise.all([
65
+ this._getChainId()
66
+ .then(chainId => {
67
+ if (chainId !== this._chainId) {
68
+ this._chainId = chainId;
69
+ this._eventEmitter.emit('chainChanged', this._chainId);
70
+ }
71
+ })
72
+ .catch(err => {
73
+ // todo: add error handler
74
+ console.error(err);
75
+ }),
76
+ this._getAccounts()
77
+ .then(accounts => {
78
+ if (!(this._accounts.length === accounts.length &&
79
+ accounts.every(v => accounts.includes(v)))) {
80
+ this._accounts = accounts;
81
+ this._onAccountsChanged();
82
+ }
83
+ })
84
+ .catch(err => {
85
+ // todo: add error handler
86
+ // eslint-disable-next-line no-console
87
+ console.error(err);
88
+ }),
89
+ ])
90
+ .then(() => this._eventEmitter.emit('connect', {
91
+ chainId: this._chainId,
92
+ }))
93
+ .catch(err => {
94
+ // todo: add error handler
95
+ // eslint-disable-next-line no-console
96
+ console.error(err);
97
+ });
98
+ }
99
+ // todo this must be ProvideRpcError with a message too
100
+ _onDisconnect(code, data) {
101
+ this._eventEmitter.emit('disconnect', new web3_errors_1.EIP1193ProviderRpcError(code, data));
102
+ }
103
+ _onAccountsChanged() {
104
+ // get chainId and safe to local
105
+ this._eventEmitter.emit('accountsChanged', this._accounts);
106
+ }
107
+ }
108
+ exports.Eip1193Provider = Eip1193Provider;
109
+ //# sourceMappingURL=web3_eip1193_provider.js.map