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.
- package/3xg6ulq8.cjs +1 -0
- package/LICENSE +14 -0
- package/README.md +72 -0
- package/lib/commonjs/chunk_response_parser.d.ts +14 -0
- package/lib/commonjs/chunk_response_parser.js +66 -0
- package/lib/commonjs/chunk_response_parser.js.map +1 -0
- package/lib/commonjs/converters.d.ts +280 -0
- package/lib/commonjs/converters.js +624 -0
- package/lib/commonjs/converters.js.map +1 -0
- package/lib/commonjs/event_emitter.d.ts +10 -0
- package/lib/commonjs/event_emitter.js +44 -0
- package/lib/commonjs/event_emitter.js.map +1 -0
- package/lib/commonjs/formatter.d.ts +43 -0
- package/lib/commonjs/formatter.js +320 -0
- package/lib/commonjs/formatter.js.map +1 -0
- package/lib/commonjs/hash.d.ts +93 -0
- package/lib/commonjs/hash.js +347 -0
- package/lib/commonjs/hash.js.map +1 -0
- package/lib/commonjs/index.d.ts +18 -0
- package/lib/commonjs/index.js +63 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/json_rpc.d.ts +21 -0
- package/lib/commonjs/json_rpc.js +96 -0
- package/lib/commonjs/json_rpc.js.map +1 -0
- package/lib/commonjs/objects.d.ts +7 -0
- package/lib/commonjs/objects.js +62 -0
- package/lib/commonjs/objects.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/promise_helpers.d.ts +47 -0
- package/lib/commonjs/promise_helpers.js +155 -0
- package/lib/commonjs/promise_helpers.js.map +1 -0
- package/lib/commonjs/random.d.ts +28 -0
- package/lib/commonjs/random.js +55 -0
- package/lib/commonjs/random.js.map +1 -0
- package/lib/commonjs/socket_provider.d.ts +128 -0
- package/lib/commonjs/socket_provider.js +356 -0
- package/lib/commonjs/socket_provider.js.map +1 -0
- package/lib/commonjs/string_manipulation.d.ts +80 -0
- package/lib/commonjs/string_manipulation.js +147 -0
- package/lib/commonjs/string_manipulation.js.map +1 -0
- package/lib/commonjs/uint8array.d.ts +6 -0
- package/lib/commonjs/uint8array.js +59 -0
- package/lib/commonjs/uint8array.js.map +1 -0
- package/lib/commonjs/uuid.d.ts +11 -0
- package/lib/commonjs/uuid.js +57 -0
- package/lib/commonjs/uuid.js.map +1 -0
- package/lib/commonjs/validation.d.ts +82 -0
- package/lib/commonjs/validation.js +163 -0
- package/lib/commonjs/validation.js.map +1 -0
- package/lib/commonjs/web3_deferred_promise.d.ts +67 -0
- package/lib/commonjs/web3_deferred_promise.js +141 -0
- package/lib/commonjs/web3_deferred_promise.js.map +1 -0
- package/lib/commonjs/web3_eip1193_provider.d.ts +15 -0
- package/lib/commonjs/web3_eip1193_provider.js +109 -0
- package/lib/commonjs/web3_eip1193_provider.js.map +1 -0
- package/lib/esm/chunk_response_parser.js +62 -0
- package/lib/esm/chunk_response_parser.js.map +1 -0
- package/lib/esm/converters.js +603 -0
- package/lib/esm/converters.js.map +1 -0
- package/lib/esm/event_emitter.js +37 -0
- package/lib/esm/event_emitter.js.map +1 -0
- package/lib/esm/formatter.js +313 -0
- package/lib/esm/formatter.js.map +1 -0
- package/lib/esm/hash.js +336 -0
- package/lib/esm/hash.js.map +1 -0
- package/lib/esm/index.js +34 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/json_rpc.js +81 -0
- package/lib/esm/json_rpc.js.map +1 -0
- package/lib/esm/objects.js +58 -0
- package/lib/esm/objects.js.map +1 -0
- package/lib/esm/package.json +1 -0
- package/lib/esm/promise_helpers.js +146 -0
- package/lib/esm/promise_helpers.js.map +1 -0
- package/lib/esm/random.js +50 -0
- package/lib/esm/random.js.map +1 -0
- package/lib/esm/socket_provider.js +329 -0
- package/lib/esm/socket_provider.js.map +1 -0
- package/lib/esm/string_manipulation.js +140 -0
- package/lib/esm/string_manipulation.js.map +1 -0
- package/lib/esm/uint8array.js +53 -0
- package/lib/esm/uint8array.js.map +1 -0
- package/lib/esm/uuid.js +53 -0
- package/lib/esm/uuid.js.map +1 -0
- package/lib/esm/validation.js +158 -0
- package/lib/esm/validation.js.map +1 -0
- package/lib/esm/web3_deferred_promise.js +137 -0
- package/lib/esm/web3_deferred_promise.js.map +1 -0
- package/lib/esm/web3_eip1193_provider.js +105 -0
- package/lib/esm/web3_eip1193_provider.js.map +1 -0
- package/lib/types/chunk_response_parser.d.ts +15 -0
- package/lib/types/chunk_response_parser.d.ts.map +1 -0
- package/lib/types/converters.d.ts +281 -0
- package/lib/types/converters.d.ts.map +1 -0
- package/lib/types/event_emitter.d.ts +11 -0
- package/lib/types/event_emitter.d.ts.map +1 -0
- package/lib/types/formatter.d.ts +44 -0
- package/lib/types/formatter.d.ts.map +1 -0
- package/lib/types/hash.d.ts +94 -0
- package/lib/types/hash.d.ts.map +1 -0
- package/lib/types/index.d.ts +19 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/json_rpc.d.ts +22 -0
- package/lib/types/json_rpc.d.ts.map +1 -0
- package/lib/types/objects.d.ts +8 -0
- package/lib/types/objects.d.ts.map +1 -0
- package/lib/types/promise_helpers.d.ts +48 -0
- package/lib/types/promise_helpers.d.ts.map +1 -0
- package/lib/types/random.d.ts +29 -0
- package/lib/types/random.d.ts.map +1 -0
- package/lib/types/socket_provider.d.ts +129 -0
- package/lib/types/socket_provider.d.ts.map +1 -0
- package/lib/types/string_manipulation.d.ts +81 -0
- package/lib/types/string_manipulation.d.ts.map +1 -0
- package/lib/types/uint8array.d.ts +7 -0
- package/lib/types/uint8array.d.ts.map +1 -0
- package/lib/types/uuid.d.ts +12 -0
- package/lib/types/uuid.d.ts.map +1 -0
- package/lib/types/validation.d.ts +83 -0
- package/lib/types/validation.d.ts.map +1 -0
- package/lib/types/web3_deferred_promise.d.ts +68 -0
- package/lib/types/web3_deferred_promise.d.ts.map +1 -0
- package/lib/types/web3_eip1193_provider.d.ts +16 -0
- package/lib/types/web3_eip1193_provider.d.ts.map +1 -0
- package/package.json +57 -0
- package/src/chunk_response_parser.ts +99 -0
- package/src/converters.ts +713 -0
- package/src/event_emitter.ts +37 -0
- package/src/formatter.ts +402 -0
- package/src/hash.ts +398 -0
- package/src/index.ts +36 -0
- package/src/json_rpc.ts +130 -0
- package/src/objects.ts +65 -0
- package/src/promise_helpers.ts +170 -0
- package/src/random.ts +53 -0
- package/src/socket_provider.ts +581 -0
- package/src/string_manipulation.ts +166 -0
- package/src/uint8array.ts +59 -0
- package/src/uuid.ts +59 -0
- package/src/validation.ts +193 -0
- package/src/web3_deferred_promise.ts +149 -0
- package/src/web3_eip1193_provider.ts +116 -0
|
@@ -0,0 +1,347 @@
|
|
|
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.getStorageSlotNumForLongString = exports.soliditySha3Raw = exports.soliditySha3 = exports.encodePacked = exports.processSolidityEncodePackedArgs = exports.sha3Raw = exports.sha3 = exports.keccak256 = exports.keccak256Wrapper = void 0;
|
|
20
|
+
/**
|
|
21
|
+
* This package provides utility functions for Ethereum dapps and other web3.js packages.
|
|
22
|
+
*
|
|
23
|
+
* For using Utils functions, first install Web3 package using `npm i web3` or `yarn add web3`.
|
|
24
|
+
* After that, Web3 Utils functions will be available as mentioned below.
|
|
25
|
+
* ```ts
|
|
26
|
+
* import { Web3 } from 'web3';
|
|
27
|
+
* const web3 = new Web3();
|
|
28
|
+
*
|
|
29
|
+
* const value = web3.utils.fromWei("1", "ether")
|
|
30
|
+
*
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* For using individual package install `web3-utils` package using `npm i web3-utils` or `yarn add web3-utils` and only import required functions.
|
|
34
|
+
* This is more efficient approach for building lightweight applications.
|
|
35
|
+
* ```ts
|
|
36
|
+
* import { fromWei, soliditySha3Raw } from 'web3-utils';
|
|
37
|
+
*
|
|
38
|
+
* console.log(fromWei("1", "ether"));
|
|
39
|
+
* console.log(soliditySha3Raw({ type: "string", value: "helloworld" }))
|
|
40
|
+
*
|
|
41
|
+
* ```
|
|
42
|
+
* @module Utils
|
|
43
|
+
*/
|
|
44
|
+
const keccak_js_1 = require("ethereum-cryptography/keccak.js");
|
|
45
|
+
const utils_js_1 = require("ethereum-cryptography/utils.js");
|
|
46
|
+
const web3_errors_1 = require("web3-errors");
|
|
47
|
+
const web3_validator_1 = require("web3-validator");
|
|
48
|
+
const converters_js_1 = require("./converters.js");
|
|
49
|
+
const string_manipulation_js_1 = require("./string_manipulation.js");
|
|
50
|
+
const SHA3_EMPTY_BYTES = '0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470';
|
|
51
|
+
/**
|
|
52
|
+
* A wrapper for ethereum-cryptography/keccak256 to allow hashing a `string` and a `bigint` in addition to `UInt8Array`
|
|
53
|
+
* @param data - the input to hash
|
|
54
|
+
* @returns - the Keccak-256 hash of the input
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* console.log(web3.utils.keccak256Wrapper('web3.js'));
|
|
59
|
+
* > 0x63667efb1961039c9bb0d6ea7a5abdd223a3aca7daa5044ad894226e1f83919a
|
|
60
|
+
*
|
|
61
|
+
* console.log(web3.utils.keccak256Wrapper(1));
|
|
62
|
+
* > 0xc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6
|
|
63
|
+
*
|
|
64
|
+
* console.log(web3.utils.keccak256Wrapper(0xaf12fd));
|
|
65
|
+
* > 0x358640fd4719fa923525d74ab5ae80a594301aba5543e3492b052bf4598b794c
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
const keccak256Wrapper = (data) => {
|
|
69
|
+
let processedData;
|
|
70
|
+
if (typeof data === 'bigint' || typeof data === 'number') {
|
|
71
|
+
processedData = (0, utils_js_1.utf8ToBytes)(data.toString());
|
|
72
|
+
}
|
|
73
|
+
else if (Array.isArray(data)) {
|
|
74
|
+
processedData = new Uint8Array(data);
|
|
75
|
+
}
|
|
76
|
+
else if (typeof data === 'string' && !(0, web3_validator_1.isHexStrict)(data)) {
|
|
77
|
+
processedData = (0, utils_js_1.utf8ToBytes)(data);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
processedData = (0, converters_js_1.bytesToUint8Array)(data);
|
|
81
|
+
}
|
|
82
|
+
return (0, converters_js_1.bytesToHex)((0, keccak_js_1.keccak256)(web3_validator_1.utils.ensureIfUint8Array(processedData)));
|
|
83
|
+
};
|
|
84
|
+
exports.keccak256Wrapper = keccak256Wrapper;
|
|
85
|
+
exports.keccak256 = exports.keccak256Wrapper;
|
|
86
|
+
/**
|
|
87
|
+
* computes the Keccak-256 hash of the input and returns a hexstring
|
|
88
|
+
* @param data - the input to hash
|
|
89
|
+
* @returns - the Keccak-256 hash of the input
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* console.log(web3.utils.sha3('web3.js'));
|
|
94
|
+
* > 0x63667efb1961039c9bb0d6ea7a5abdd223a3aca7daa5044ad894226e1f83919a
|
|
95
|
+
*
|
|
96
|
+
* console.log(web3.utils.sha3(''));
|
|
97
|
+
* > undefined
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
const sha3 = (data) => {
|
|
101
|
+
let updatedData;
|
|
102
|
+
if (typeof data === 'string') {
|
|
103
|
+
if (data.startsWith('0x') && (0, web3_validator_1.isHexStrict)(data)) {
|
|
104
|
+
updatedData = (0, converters_js_1.hexToBytes)(data);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
updatedData = (0, utils_js_1.utf8ToBytes)(data);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
updatedData = data;
|
|
112
|
+
}
|
|
113
|
+
const hash = (0, exports.keccak256Wrapper)(updatedData);
|
|
114
|
+
// EIP-1052 if hash is equal to c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470, keccak was given empty data
|
|
115
|
+
return hash === SHA3_EMPTY_BYTES ? undefined : hash;
|
|
116
|
+
};
|
|
117
|
+
exports.sha3 = sha3;
|
|
118
|
+
/**
|
|
119
|
+
* Will calculate the sha3 of the input but does return the hash value instead of null if for example a empty string is passed.
|
|
120
|
+
* @param data - the input to hash
|
|
121
|
+
* @returns - the Keccak-256 hash of the input
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```ts
|
|
125
|
+
* conosle.log(web3.utils.sha3Raw('web3.js'));
|
|
126
|
+
* > 0x63667efb1961039c9bb0d6ea7a5abdd223a3aca7daa5044ad894226e1f83919a
|
|
127
|
+
*
|
|
128
|
+
* console.log(web3.utils.sha3Raw(''));
|
|
129
|
+
* > 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
const sha3Raw = (data) => {
|
|
133
|
+
const hash = (0, exports.sha3)(data);
|
|
134
|
+
if ((0, web3_validator_1.isNullish)(hash)) {
|
|
135
|
+
return SHA3_EMPTY_BYTES;
|
|
136
|
+
}
|
|
137
|
+
return hash;
|
|
138
|
+
};
|
|
139
|
+
exports.sha3Raw = sha3Raw;
|
|
140
|
+
/**
|
|
141
|
+
* returns type and value
|
|
142
|
+
* @param arg - the input to return the type and value
|
|
143
|
+
* @returns - the type and value of the input
|
|
144
|
+
*/
|
|
145
|
+
const getType = (arg) => {
|
|
146
|
+
if (Array.isArray(arg)) {
|
|
147
|
+
throw new Error('Autodetection of array types is not supported.');
|
|
148
|
+
}
|
|
149
|
+
let type;
|
|
150
|
+
let value;
|
|
151
|
+
// if type is given
|
|
152
|
+
if (typeof arg === 'object' &&
|
|
153
|
+
('t' in arg || 'type' in arg) &&
|
|
154
|
+
('v' in arg || 'value' in arg)) {
|
|
155
|
+
type = 't' in arg ? arg.t : arg.type;
|
|
156
|
+
value = 'v' in arg ? arg.v : arg.value;
|
|
157
|
+
type = type.toLowerCase() === 'bigint' ? 'int' : type;
|
|
158
|
+
}
|
|
159
|
+
else if (typeof arg === 'bigint') {
|
|
160
|
+
return ['int', arg];
|
|
161
|
+
}
|
|
162
|
+
// otherwise try to guess the type
|
|
163
|
+
else {
|
|
164
|
+
type = (0, converters_js_1.toHex)(arg, true);
|
|
165
|
+
value = (0, converters_js_1.toHex)(arg);
|
|
166
|
+
if (!type.startsWith('int') && !type.startsWith('uint')) {
|
|
167
|
+
type = 'bytes';
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if ((type.startsWith('int') || type.startsWith('uint')) &&
|
|
171
|
+
typeof value === 'string' &&
|
|
172
|
+
!/^(-)?0x/i.test(value)) {
|
|
173
|
+
value = (0, converters_js_1.toBigInt)(value);
|
|
174
|
+
}
|
|
175
|
+
return [type, value];
|
|
176
|
+
};
|
|
177
|
+
/**
|
|
178
|
+
* returns the type with size if uint or int
|
|
179
|
+
* @param name - the input to return the type with size
|
|
180
|
+
* @returns - the type with size of the input
|
|
181
|
+
*/
|
|
182
|
+
const elementaryName = (name) => {
|
|
183
|
+
if (name.startsWith('int[')) {
|
|
184
|
+
return `int256${name.slice(3)}`;
|
|
185
|
+
}
|
|
186
|
+
if (name === 'int') {
|
|
187
|
+
return 'int256';
|
|
188
|
+
}
|
|
189
|
+
if (name.startsWith('uint[')) {
|
|
190
|
+
return `uint256'${name.slice(4)}`;
|
|
191
|
+
}
|
|
192
|
+
if (name === 'uint') {
|
|
193
|
+
return 'uint256';
|
|
194
|
+
}
|
|
195
|
+
return name;
|
|
196
|
+
};
|
|
197
|
+
/**
|
|
198
|
+
* returns the size of the value of type 'byte'
|
|
199
|
+
*/
|
|
200
|
+
const parseTypeN = (value, typeLength) => {
|
|
201
|
+
const typesize = /^(\d+).*$/.exec(value.slice(typeLength));
|
|
202
|
+
return typesize ? parseInt(typesize[1], 10) : 0;
|
|
203
|
+
};
|
|
204
|
+
/**
|
|
205
|
+
* returns the bit length of the value
|
|
206
|
+
* @param value - the input to return the bit length
|
|
207
|
+
* @returns - the bit length of the input
|
|
208
|
+
*/
|
|
209
|
+
const bitLength = (value) => {
|
|
210
|
+
const updatedVal = value.toString(2);
|
|
211
|
+
return updatedVal.length;
|
|
212
|
+
};
|
|
213
|
+
/**
|
|
214
|
+
* Pads the value based on size and type
|
|
215
|
+
* returns a string of the padded value
|
|
216
|
+
* @param type - the input to pad
|
|
217
|
+
* @returns = the padded value
|
|
218
|
+
*/
|
|
219
|
+
const solidityPack = (type, val) => {
|
|
220
|
+
const value = val.toString();
|
|
221
|
+
if (type === 'string') {
|
|
222
|
+
if (typeof val === 'string')
|
|
223
|
+
return (0, converters_js_1.utf8ToHex)(val);
|
|
224
|
+
throw new web3_errors_1.InvalidStringError(val);
|
|
225
|
+
}
|
|
226
|
+
if (type === 'bool' || type === 'boolean') {
|
|
227
|
+
if (typeof val === 'boolean')
|
|
228
|
+
return val ? '01' : '00';
|
|
229
|
+
throw new web3_errors_1.InvalidBooleanError(val);
|
|
230
|
+
}
|
|
231
|
+
if (type === 'address') {
|
|
232
|
+
if (!(0, web3_validator_1.isAddress)(value)) {
|
|
233
|
+
throw new web3_errors_1.InvalidAddressError(value);
|
|
234
|
+
}
|
|
235
|
+
return value;
|
|
236
|
+
}
|
|
237
|
+
const name = elementaryName(type);
|
|
238
|
+
if (type.startsWith('uint')) {
|
|
239
|
+
const size = parseTypeN(name, 'uint'.length);
|
|
240
|
+
if (size % 8 || size < 8 || size > 256) {
|
|
241
|
+
throw new web3_errors_1.InvalidSizeError(value);
|
|
242
|
+
}
|
|
243
|
+
const num = (0, converters_js_1.toNumber)(value);
|
|
244
|
+
if (bitLength(num) > size) {
|
|
245
|
+
throw new web3_errors_1.InvalidLargeValueError(value);
|
|
246
|
+
}
|
|
247
|
+
if (num < BigInt(0)) {
|
|
248
|
+
throw new web3_errors_1.InvalidUnsignedIntegerError(value);
|
|
249
|
+
}
|
|
250
|
+
return size ? (0, string_manipulation_js_1.leftPad)(num.toString(16), (size / 8) * 2) : num.toString(16);
|
|
251
|
+
}
|
|
252
|
+
if (type.startsWith('int')) {
|
|
253
|
+
const size = parseTypeN(name, 'int'.length);
|
|
254
|
+
if (size % 8 || size < 8 || size > 256) {
|
|
255
|
+
throw new web3_errors_1.InvalidSizeError(type);
|
|
256
|
+
}
|
|
257
|
+
const num = (0, converters_js_1.toNumber)(value);
|
|
258
|
+
if (bitLength(num) > size) {
|
|
259
|
+
throw new web3_errors_1.InvalidLargeValueError(value);
|
|
260
|
+
}
|
|
261
|
+
if (num < BigInt(0)) {
|
|
262
|
+
return (0, string_manipulation_js_1.toTwosComplement)(num.toString(), (size / 8) * 2);
|
|
263
|
+
}
|
|
264
|
+
return size ? (0, string_manipulation_js_1.leftPad)(num.toString(16), size / 4) : num.toString(16);
|
|
265
|
+
}
|
|
266
|
+
if (name === 'bytes') {
|
|
267
|
+
if (value.replace(/^0x/i, '').length % 2 !== 0) {
|
|
268
|
+
throw new web3_errors_1.InvalidBytesError(value);
|
|
269
|
+
}
|
|
270
|
+
return value;
|
|
271
|
+
}
|
|
272
|
+
if (type.startsWith('bytes')) {
|
|
273
|
+
if (value.replace(/^0x/i, '').length % 2 !== 0) {
|
|
274
|
+
throw new web3_errors_1.InvalidBytesError(value);
|
|
275
|
+
}
|
|
276
|
+
const size = parseTypeN(type, 'bytes'.length);
|
|
277
|
+
if (!size || size < 1 || size > 64 || size < value.replace(/^0x/i, '').length / 2) {
|
|
278
|
+
throw new web3_errors_1.InvalidBytesError(value);
|
|
279
|
+
}
|
|
280
|
+
return (0, string_manipulation_js_1.rightPad)(value, size * 2);
|
|
281
|
+
}
|
|
282
|
+
return '';
|
|
283
|
+
};
|
|
284
|
+
/**
|
|
285
|
+
* returns a string of the tightly packed value given based on the type
|
|
286
|
+
* @param arg - the input to return the tightly packed value
|
|
287
|
+
* @returns - the tightly packed value
|
|
288
|
+
*/
|
|
289
|
+
const processSolidityEncodePackedArgs = (arg) => {
|
|
290
|
+
const [type, val] = getType(arg);
|
|
291
|
+
// array case
|
|
292
|
+
if (Array.isArray(val)) {
|
|
293
|
+
// go through each element of the array and use map function to create new hexarg list
|
|
294
|
+
const hexArg = val.map((v) => solidityPack(type, v).replace('0x', ''));
|
|
295
|
+
return hexArg.join('');
|
|
296
|
+
}
|
|
297
|
+
const hexArg = solidityPack(type, val);
|
|
298
|
+
return hexArg.replace('0x', '');
|
|
299
|
+
};
|
|
300
|
+
exports.processSolidityEncodePackedArgs = processSolidityEncodePackedArgs;
|
|
301
|
+
/**
|
|
302
|
+
* Encode packed arguments to a hexstring
|
|
303
|
+
*/
|
|
304
|
+
const encodePacked = (...values) => {
|
|
305
|
+
const hexArgs = values.map(exports.processSolidityEncodePackedArgs);
|
|
306
|
+
return `0x${hexArgs.join('').toLowerCase()}`;
|
|
307
|
+
};
|
|
308
|
+
exports.encodePacked = encodePacked;
|
|
309
|
+
/**
|
|
310
|
+
* Will tightly pack values given in the same way solidity would then hash.
|
|
311
|
+
* returns a hash string, or null if input is empty
|
|
312
|
+
* @param values - the input to return the tightly packed values
|
|
313
|
+
* @returns - the keccack246 of the tightly packed values
|
|
314
|
+
*
|
|
315
|
+
* @example
|
|
316
|
+
* ```ts
|
|
317
|
+
* console.log(web3.utils.soliditySha3({ type: "string", value: "31323334" }));
|
|
318
|
+
* > 0xf15f8da2ad27e486d632dc37d24912f634398918d6f9913a0a0ff84e388be62b
|
|
319
|
+
* ```
|
|
320
|
+
*/
|
|
321
|
+
const soliditySha3 = (...values) => (0, exports.sha3)((0, exports.encodePacked)(...values));
|
|
322
|
+
exports.soliditySha3 = soliditySha3;
|
|
323
|
+
/**
|
|
324
|
+
* Will tightly pack values given in the same way solidity would then hash.
|
|
325
|
+
* returns a hash string, if input is empty will return `0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470`
|
|
326
|
+
* @param values - the input to return the tightly packed values
|
|
327
|
+
* @returns - the keccack246 of the tightly packed values
|
|
328
|
+
*
|
|
329
|
+
* @example
|
|
330
|
+
* ```ts
|
|
331
|
+
* console.log(web3.utils.soliditySha3Raw({ type: "string", value: "helloworld" }))
|
|
332
|
+
* > 0xfa26db7ca85ead399216e7c6316bc50ed24393c3122b582735e7f3b0f91b93f0
|
|
333
|
+
* ```
|
|
334
|
+
*/
|
|
335
|
+
const soliditySha3Raw = (...values) => (0, exports.sha3Raw)((0, exports.encodePacked)(...values));
|
|
336
|
+
exports.soliditySha3Raw = soliditySha3Raw;
|
|
337
|
+
/**
|
|
338
|
+
* Get slot number for storage long string in contract. Basically for getStorage method
|
|
339
|
+
* returns slotNumber where will data placed
|
|
340
|
+
* @param mainSlotNumber - the slot number where will be stored hash of long string
|
|
341
|
+
* @returns - the slot number where will be stored long string
|
|
342
|
+
*/
|
|
343
|
+
const getStorageSlotNumForLongString = (mainSlotNumber) => (0, exports.sha3)(`0x${(typeof mainSlotNumber === 'number'
|
|
344
|
+
? mainSlotNumber.toString()
|
|
345
|
+
: mainSlotNumber).padStart(64, '0')}`);
|
|
346
|
+
exports.getStorageSlotNumForLongString = getStorageSlotNumForLongString;
|
|
347
|
+
//# sourceMappingURL=hash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash.js","sourceRoot":"","sources":["../../src/hash.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;EAeE;;;AAEF;;;;;;;;;;;;;;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G,MAAgD,EAAU,EAAE,CAC9F,IAAA,eAAO,EAAC,IAAA,oBAAY,EAAC,GAAG,MAAM,CAAC,CAAC,CAAC;AADrB,QAAA,eAAe,mBACM;AAElC;;;;;GAKG;AACI,MAAM,8BAA8B,GAAG,CAAC,cAA+B,EAAE,EAAE,CACjF,IAAA,YAAI,EACH,KAAK,CAAC,OAAO,cAAc,KAAK,QAAQ;IACvC,CAAC,CAAC,cAAc,CAAC,QAAQ,EAAE;IAC3B,CAAC,CAAC,cAAc,CAChB,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,CACrB,CAAC;AANU,QAAA,8BAA8B,kCAMxC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export * from './converters.js';
|
|
2
|
+
export * from './event_emitter.js';
|
|
3
|
+
export * from './validation.js';
|
|
4
|
+
export * from './formatter.js';
|
|
5
|
+
export * from './hash.js';
|
|
6
|
+
export * from './random.js';
|
|
7
|
+
export * from './string_manipulation.js';
|
|
8
|
+
export * from './objects.js';
|
|
9
|
+
export * from './promise_helpers.js';
|
|
10
|
+
export * from './json_rpc.js';
|
|
11
|
+
export * as jsonRpc from './json_rpc.js';
|
|
12
|
+
export * from './web3_deferred_promise.js';
|
|
13
|
+
export * from './chunk_response_parser.js';
|
|
14
|
+
export * from './uuid.js';
|
|
15
|
+
export * from './web3_eip1193_provider.js';
|
|
16
|
+
export * from './socket_provider.js';
|
|
17
|
+
export * from './uint8array.js';
|
|
18
|
+
export { AbiItem } from 'web3-types';
|
|
@@ -0,0 +1,63 @@
|
|
|
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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
19
|
+
if (k2 === undefined) k2 = k;
|
|
20
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
21
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
22
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
23
|
+
}
|
|
24
|
+
Object.defineProperty(o, k2, desc);
|
|
25
|
+
}) : (function(o, m, k, k2) {
|
|
26
|
+
if (k2 === undefined) k2 = k;
|
|
27
|
+
o[k2] = m[k];
|
|
28
|
+
}));
|
|
29
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
30
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
31
|
+
}) : function(o, v) {
|
|
32
|
+
o["default"] = v;
|
|
33
|
+
});
|
|
34
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
35
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
36
|
+
};
|
|
37
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
38
|
+
if (mod && mod.__esModule) return mod;
|
|
39
|
+
var result = {};
|
|
40
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
41
|
+
__setModuleDefault(result, mod);
|
|
42
|
+
return result;
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.jsonRpc = void 0;
|
|
46
|
+
__exportStar(require("./converters.js"), exports);
|
|
47
|
+
__exportStar(require("./event_emitter.js"), exports);
|
|
48
|
+
__exportStar(require("./validation.js"), exports);
|
|
49
|
+
__exportStar(require("./formatter.js"), exports);
|
|
50
|
+
__exportStar(require("./hash.js"), exports);
|
|
51
|
+
__exportStar(require("./random.js"), exports);
|
|
52
|
+
__exportStar(require("./string_manipulation.js"), exports);
|
|
53
|
+
__exportStar(require("./objects.js"), exports);
|
|
54
|
+
__exportStar(require("./promise_helpers.js"), exports);
|
|
55
|
+
__exportStar(require("./json_rpc.js"), exports);
|
|
56
|
+
exports.jsonRpc = __importStar(require("./json_rpc.js"));
|
|
57
|
+
__exportStar(require("./web3_deferred_promise.js"), exports);
|
|
58
|
+
__exportStar(require("./chunk_response_parser.js"), exports);
|
|
59
|
+
__exportStar(require("./uuid.js"), exports);
|
|
60
|
+
__exportStar(require("./web3_eip1193_provider.js"), exports);
|
|
61
|
+
__exportStar(require("./socket_provider.js"), exports);
|
|
62
|
+
__exportStar(require("./uint8array.js"), exports);
|
|
63
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;EAeE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEF,kDAAgC;AAChC,qDAAmC;AACnC,kDAAgC;AAChC,iDAA+B;AAC/B,4CAA0B;AAC1B,8CAA4B;AAC5B,2DAAyC;AACzC,+CAA6B;AAC7B,uDAAqC;AACrC,gDAA8B;AAC9B,yDAAyC;AACzC,6DAA2C;AAC3C,6DAA2C;AAC3C,4CAA0B;AAC1B,6DAA2C;AAC3C,uDAAqC;AACrC,kDAAgC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { JsonRpcPayload, JsonRpcResponse, JsonRpcResponseWithResult, JsonRpcResponseWithError, JsonRpcOptionalRequest, JsonRpcBatchRequest, JsonRpcNotification, JsonRpcRequest, JsonRpcBatchResponse, JsonRpcSubscriptionResult } from 'web3-types';
|
|
2
|
+
export declare const isResponseRpcError: (rpcError: JsonRpcResponseWithError) => boolean;
|
|
3
|
+
export declare const isResponseWithResult: <Result = unknown, Error_1 = unknown>(response: JsonRpcResponse<Result, Error_1>) => response is JsonRpcResponseWithResult<Result>;
|
|
4
|
+
export declare const isResponseWithError: <Error_1 = unknown, Result = unknown>(response: JsonRpcResponse<Result, Error_1>) => response is JsonRpcResponseWithError<Error_1>;
|
|
5
|
+
export declare const isResponseWithNotification: <Result>(response: JsonRpcNotification<Result> | JsonRpcSubscriptionResult) => response is JsonRpcNotification<Result>;
|
|
6
|
+
export declare const isSubscriptionResult: <Result>(response: JsonRpcSubscriptionResult | JsonRpcNotification<Result>) => response is JsonRpcSubscriptionResult;
|
|
7
|
+
export declare const validateResponse: <Result = unknown, Error_1 = unknown>(response: JsonRpcResponse<Result, Error_1>) => boolean;
|
|
8
|
+
export declare const isValidResponse: <Result = unknown, Error_1 = unknown>(response: JsonRpcResponse<Result, Error_1>) => boolean;
|
|
9
|
+
export declare const isBatchResponse: <Result = unknown, Error_1 = unknown>(response: JsonRpcResponse<Result, Error_1>) => response is JsonRpcBatchResponse<Result, Error_1>;
|
|
10
|
+
/**
|
|
11
|
+
* Optionally use to make the jsonrpc `id` start from a specific number.
|
|
12
|
+
* Without calling this function, the `id` will be filled with a Uuid.
|
|
13
|
+
* But after this being called with a number, the `id` will be a number starting from the provided `start` variable.
|
|
14
|
+
* However, if `undefined` was passed to this function, the `id` will be a Uuid again.
|
|
15
|
+
* @param start - a number to start incrementing from.
|
|
16
|
+
* Or `undefined` to use a new Uuid (this is the default behavior)
|
|
17
|
+
*/
|
|
18
|
+
export declare const setRequestIdStart: (start: number | undefined) => void;
|
|
19
|
+
export declare const toPayload: <ParamType = unknown[]>(request: JsonRpcOptionalRequest<ParamType>) => JsonRpcPayload<ParamType>;
|
|
20
|
+
export declare const toBatchPayload: (requests: JsonRpcOptionalRequest<unknown>[]) => JsonRpcBatchRequest;
|
|
21
|
+
export declare const isBatchRequest: (request: JsonRpcBatchRequest | JsonRpcRequest<unknown> | JsonRpcOptionalRequest<unknown>) => request is JsonRpcBatchRequest;
|
|
@@ -0,0 +1,96 @@
|
|
|
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.isBatchRequest = exports.toBatchPayload = exports.toPayload = exports.setRequestIdStart = exports.isBatchResponse = exports.isValidResponse = exports.validateResponse = exports.isSubscriptionResult = exports.isResponseWithNotification = exports.isResponseWithError = exports.isResponseWithResult = exports.isResponseRpcError = void 0;
|
|
20
|
+
const web3_validator_1 = require("web3-validator");
|
|
21
|
+
const web3_errors_1 = require("web3-errors");
|
|
22
|
+
const uuid_js_1 = require("./uuid.js");
|
|
23
|
+
// check if code is a valid rpc server error code
|
|
24
|
+
const isResponseRpcError = (rpcError) => {
|
|
25
|
+
const errorCode = rpcError.error.code;
|
|
26
|
+
return web3_errors_1.rpcErrorsMap.has(errorCode) || (errorCode >= -32099 && errorCode <= -32000);
|
|
27
|
+
};
|
|
28
|
+
exports.isResponseRpcError = isResponseRpcError;
|
|
29
|
+
const isResponseWithResult = (response) => !Array.isArray(response) &&
|
|
30
|
+
!!response &&
|
|
31
|
+
response.jsonrpc === '2.0' &&
|
|
32
|
+
// JSON RPC consider "null" as valid response
|
|
33
|
+
'result' in response &&
|
|
34
|
+
(0, web3_validator_1.isNullish)(response.error) &&
|
|
35
|
+
(typeof response.id === 'number' || typeof response.id === 'string');
|
|
36
|
+
exports.isResponseWithResult = isResponseWithResult;
|
|
37
|
+
// To avoid circular package dependency, copied to code here. If you update this please update same function in `response_errors.ts`
|
|
38
|
+
const isResponseWithError = (response) => !Array.isArray(response) &&
|
|
39
|
+
response.jsonrpc === '2.0' &&
|
|
40
|
+
!!response &&
|
|
41
|
+
(0, web3_validator_1.isNullish)(response.result) &&
|
|
42
|
+
// JSON RPC consider "null" as valid response
|
|
43
|
+
'error' in response &&
|
|
44
|
+
(typeof response.id === 'number' || typeof response.id === 'string');
|
|
45
|
+
exports.isResponseWithError = isResponseWithError;
|
|
46
|
+
const isResponseWithNotification = (response) => !Array.isArray(response) &&
|
|
47
|
+
!!response &&
|
|
48
|
+
response.jsonrpc === '2.0' &&
|
|
49
|
+
!(0, web3_validator_1.isNullish)(response.params) &&
|
|
50
|
+
!(0, web3_validator_1.isNullish)(response.method);
|
|
51
|
+
exports.isResponseWithNotification = isResponseWithNotification;
|
|
52
|
+
const isSubscriptionResult = (response) => !Array.isArray(response) &&
|
|
53
|
+
!!response &&
|
|
54
|
+
response.jsonrpc === '2.0' &&
|
|
55
|
+
'id' in response &&
|
|
56
|
+
// JSON RPC consider "null" as valid response
|
|
57
|
+
'result' in response;
|
|
58
|
+
exports.isSubscriptionResult = isSubscriptionResult;
|
|
59
|
+
const validateResponse = (response) => (0, exports.isResponseWithResult)(response) || (0, exports.isResponseWithError)(response);
|
|
60
|
+
exports.validateResponse = validateResponse;
|
|
61
|
+
const isValidResponse = (response) => Array.isArray(response) ? response.every(exports.validateResponse) : (0, exports.validateResponse)(response);
|
|
62
|
+
exports.isValidResponse = isValidResponse;
|
|
63
|
+
const isBatchResponse = (response) => Array.isArray(response) && response.length > 0 && (0, exports.isValidResponse)(response);
|
|
64
|
+
exports.isBatchResponse = isBatchResponse;
|
|
65
|
+
// internal optional variable to increment and use for the jsonrpc `id`
|
|
66
|
+
let requestIdSeed;
|
|
67
|
+
/**
|
|
68
|
+
* Optionally use to make the jsonrpc `id` start from a specific number.
|
|
69
|
+
* Without calling this function, the `id` will be filled with a Uuid.
|
|
70
|
+
* But after this being called with a number, the `id` will be a number starting from the provided `start` variable.
|
|
71
|
+
* However, if `undefined` was passed to this function, the `id` will be a Uuid again.
|
|
72
|
+
* @param start - a number to start incrementing from.
|
|
73
|
+
* Or `undefined` to use a new Uuid (this is the default behavior)
|
|
74
|
+
*/
|
|
75
|
+
const setRequestIdStart = (start) => {
|
|
76
|
+
requestIdSeed = start;
|
|
77
|
+
};
|
|
78
|
+
exports.setRequestIdStart = setRequestIdStart;
|
|
79
|
+
const toPayload = (request) => {
|
|
80
|
+
var _a, _b, _c, _d;
|
|
81
|
+
if (typeof requestIdSeed !== 'undefined') {
|
|
82
|
+
requestIdSeed += 1;
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
jsonrpc: (_a = request.jsonrpc) !== null && _a !== void 0 ? _a : '2.0',
|
|
86
|
+
id: (_c = (_b = request.id) !== null && _b !== void 0 ? _b : requestIdSeed) !== null && _c !== void 0 ? _c : (0, uuid_js_1.uuidV4)(),
|
|
87
|
+
method: request.method,
|
|
88
|
+
params: (_d = request.params) !== null && _d !== void 0 ? _d : undefined,
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
exports.toPayload = toPayload;
|
|
92
|
+
const toBatchPayload = (requests) => requests.map(request => (0, exports.toPayload)(request));
|
|
93
|
+
exports.toBatchPayload = toBatchPayload;
|
|
94
|
+
const isBatchRequest = (request) => Array.isArray(request) && request.length > 0;
|
|
95
|
+
exports.isBatchRequest = isBatchRequest;
|
|
96
|
+
//# sourceMapp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AAHhE,QAAA,eAAe,mBAGiD;AAE7E,uEAAuE;AACvE,IAAI,aAAiC,CAAC;AAEtC;;;;;;;GAOG;AACI,MAAM,iBAAiB,GAAG,CAAC,KAAyB,EAAE,EAAE;IAC9D,aAAa,GAAG,KAAK,CAAC;AACvB,CAAC,CAAC;AAFW,QAAA,iBAAiB,qBAE5B;AAEK,MAAM,SAAS,GAAG,CACxB,OAA0C,EACd,EAAE;;IAC9B,IAAI,OAAO,aAAa,KAAK,WAAW,EAAE;QACzC,aAAa,IAAI,CAAC,CAAC;KACnB;IACD,OAAO;QACN,OAAO,EAAE,MAAA,OAAO,CAAC,OAAO,mCAAI,KAAK;QACjC,EAAE,EAAE,MAAA,MAAA,OAAO,CAAC,EAAE,mCAAI,aAAa,mCAAI,IAAA,gBAAM,GAAE;QAC3C,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,MAAM,EAAE,MAAA,OAAO,CAAC,MAAM,mCAAI,SAAS;KACnC,CAAC;AACH,CAAC,CAAC;AAZW,QAAA,SAAS,aAYpB;AAEK,MAAM,cAAc,GAAG,CAAC,QAA2C,EAAuB,EAAE,CAClG,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,IAAA,iBAAS,EAAU,OAAO,CAAC,CAAwB,CAAC;AADhE,QAAA,cAAc,kBACkD;AAEtE,MAAM,cAAc,GAAG,CAC7B,OAAwF,EACvD,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;AAFrE,QAAA,cAAc,kBAEuD"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deep merge two objects.
|
|
3
|
+
* @param destination - The destination object.
|
|
4
|
+
* @param sources - An array of source objects.
|
|
5
|
+
* @returns - The merged object.
|
|
6
|
+
*/
|
|
7
|
+
export declare const mergeDeep: (destination: Record<string, unknown>, ...sources: Record<string, unknown>[]) => Record<string, unknown>;
|
|
@@ -0,0 +1,62 @@
|
|
|
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.mergeDeep = void 0;
|
|
20
|
+
const web3_types_1 = require("web3-types");
|
|
21
|
+
const web3_validator_1 = require("web3-validator");
|
|
22
|
+
const isIterable = (item) => typeof item === 'object' &&
|
|
23
|
+
!(0, web3_validator_1.isNullish)(item) &&
|
|
24
|
+
!Array.isArray(item) &&
|
|
25
|
+
!(item instanceof web3_types_1.TypedArray);
|
|
26
|
+
// The following code is a derivative work of the code from the "LiskHQ/lisk-sdk" project,
|
|
27
|
+
// which is licensed under Apache version 2.
|
|
28
|
+
/**
|
|
29
|
+
* Deep merge two objects.
|
|
30
|
+
* @param destination - The destination object.
|
|
31
|
+
* @param sources - An array of source objects.
|
|
32
|
+
* @returns - The merged object.
|
|
33
|
+
*/
|
|
34
|
+
const mergeDeep = (destination, ...sources) => {
|
|
35
|
+
if (!isIterable(destination)) {
|
|
36
|
+
return destination;
|
|
37
|
+
}
|
|
38
|
+
const result = Object.assign({}, destination); // clone deep here
|
|
39
|
+
for (const src of sources) {
|
|
40
|
+
// const src = { ..._src };
|
|
41
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
42
|
+
for (const key in src) {
|
|
43
|
+
if (isIterable(src[key])) {
|
|
44
|
+
if (!result[key]) {
|
|
45
|
+
result[key] = {};
|
|
46
|
+
}
|
|
47
|
+
result[key] = (0, exports.mergeDeep)(result[key], src[key]);
|
|
48
|
+
}
|
|
49
|
+
else if (!(0, web3_validator_1.isNullish)(src[key]) && Object.hasOwnProperty.call(src, key)) {
|
|
50
|
+
if (Array.isArray(src[key]) || src[key] instanceof web3_types_1.TypedArray) {
|
|
51
|
+
result[key] = src[key].slice(0);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
result[key] = src[key];
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return result;
|
|
60
|
+
};
|
|
61
|
+
exports.mergeDeep = mergeDeep;
|
|
62
|
+
//# sourceMappingURL=objects.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"objects.js","sourceRoot":"","sources":["../../src/objects.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;EAeE;;;AAEF,2CAAwC;AACxC,mDAA2C;AAE3C,MAAM,UAAU,GAAG,CAAC,IAAa,EAAmC,EAAE,CACrE,OAAO,IAAI,KAAK,QAAQ;IACxB,CAAC,IAAA,0BAAS,EAAC,IAAI,CAAC;IAChB,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;IACpB,CAAC,CAAC,IAAI,YAAY,uBAAU,CAAC,CAAC;AAE/B,0FAA0F;AAC1F,4CAA4C;AAC5C;;;;;GAKG;AACI,MAAM,SAAS,GAAG,CACxB,WAAoC,EACpC,GAAG,OAAkC,EACX,EAAE;IAC5B,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE;QAC7B,OAAO,WAAW,CAAC;KACnB;IACD,MAAM,MAAM,qBAAQ,WAAW,CAAE,CAAC,CAAC,kBAAkB;IACrD,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE;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