evm-chains-info 0.0.1

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/README.md ADDED
@@ -0,0 +1,100 @@
1
+
2
+ [comment]: <> (SPDX-License-Identifier: AGPL-3.0)
3
+
4
+ [comment]: <> (----------------------------------------------------)
5
+ [comment]: <> (Copyright © 2024, 2025, 2026 Pellegrino Prevete)
6
+ [comment]: <> (All rights reserved)
7
+ [comment]: <> (----------------------------------------------------)
8
+
9
+ [comment]: <> (This program is free software: you can redistribute)
10
+ [comment]: <> (it and/or modify it under the terms of the GNU Affero)
11
+ [comment]: <> (General Public License as published by the Free)
12
+ [comment]: <> (Software Foundation, either version 3 of the License.)
13
+
14
+ [comment]: <> (This program is distributed in the hope that it will be)
15
+ [comment]: <> (useful, but WITHOUT ANY WARRANTY; without even the)
16
+ [comment]: <> (implied warranty of MERCHANTABILITY or FITNESS FOR A)
17
+ [comment]: <> (PARTICULAR PURPOSE.)
18
+
19
+ [comment]: <> (See the GNU Affero General Public License for more)
20
+ [comment]: <> (details. You should have received a copy of the GNU)
21
+ [comment]: <> (Affero License along with this program.)
22
+ [comment]: <> (If not, see <https://www.gnu.org/licenses/>.)
23
+ [comment]: <> (SPDX-License-Identifier: AGPL-3.0)
24
+
25
+ # EVM Chains Info (`evm-chains-info.js`)
26
+
27
+ [![NPM version](
28
+ https://img.shields.io/npm/e/evmfs/evmfs.svg)](
29
+ https://npmjs.org/package/evmfs)
30
+
31
+ Returns information about EVM chains.
32
+
33
+ ```bash
34
+ evm-chains-info.js \
35
+ [options] \
36
+ <target-chain>
37
+ ```
38
+
39
+ This program is a dependency for the
40
+ [EVM Contracts Tools](
41
+ https://github.com/themartiancompany/evm-contracts-tools)
42
+ and the [libEVM](
43
+ https://github.com/themartiancompany/libevm)
44
+ library.
45
+
46
+ It is written and depends on the
47
+ [Crash Javascript](
48
+ https://github.com/themartiancompany/crash-js)
49
+ library.
50
+
51
+ ## Installation
52
+
53
+ The program in this source repo
54
+ can be installed from source using GNU Make.
55
+
56
+ ```bash
57
+ make \
58
+ install
59
+ ```
60
+
61
+ It has officially published on the
62
+ the uncensorable
63
+ [Ur](
64
+ https://github.com/themartiancompany/ur)
65
+ user repository and application store as
66
+ `evm-chains-info`.
67
+ The source code is published on the
68
+ [Ethereum Virtual Machine File System](
69
+ https://github.com/themartiancompany/evmfs)
70
+ so it can't possibly be taken down.
71
+
72
+ To install it from there just type
73
+
74
+ ```bash
75
+ ur \
76
+ evm-chains-info
77
+ ```
78
+
79
+ A censorable HTTP Github mirror of the recipe published there,
80
+ containing a full list of the software dependencies needed to run the
81
+ tools is hosted on
82
+ [evm-chains-info-ur](
83
+ https://github.com/themartiancompany/encoding-tools-ur).
84
+ Be aware the mirror could go offline any time as Github and more
85
+ in general all HTTP resources are inherently unstable and censorable.
86
+
87
+ The package has also been published
88
+ on the NPM Registry as `evm-chains-info`
89
+ and so it can be installed from there by typing
90
+
91
+ ```bash
92
+ npm \
93
+ install \
94
+ "evm-chains-info"
95
+ ```
96
+
97
+ ## License
98
+
99
+ This program is released by Pellegrino Prevete under the terms
100
+ of the GNU Affero General Public License version 3.
@@ -0,0 +1,345 @@
1
+ #!/usr/bin/env node
2
+
3
+ // SPDX-License-Identifier: AGPL-3.0-or-later
4
+
5
+ /** ----------------------------------------------------------------
6
+ * evm-chains-info.js
7
+ * ----------------------------------------------------------------
8
+ * Copyright ©
9
+ * Pellegrino Prevete
10
+ * 2024, 2025, 2026
11
+ *
12
+ * All rights reserved
13
+ * ----------------------------------------------------------------
14
+ *
15
+ * This program is free software: you can redistribute it and/or
16
+ * modify it under the terms of the GNU General Public License as
17
+ * published by the Free Software Foundation, either version 3 of
18
+ * the License, or (at your option) any later version.
19
+ *
20
+ * This program is distributed in the hope that it will be useful,
21
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ * GNU General Public License for more details.
24
+ *
25
+ * You should have received a copy of the GNU General Public License
26
+ * along with this program.
27
+ * If not, see <https://www.gnu.org/licenses/>.
28
+ */
29
+
30
+ const
31
+ _libcrash =
32
+ require(
33
+ 'crash-js');
34
+ /* global
35
+ _cmdline_check */
36
+ const
37
+ _cmdline_check =
38
+ _libcrash._cmdline_check;
39
+ /* global
40
+ _msg_info */
41
+ const
42
+ _msg_info =
43
+ _libcrash._msg_info;
44
+ /* global
45
+ _msg_error */
46
+ const
47
+ _msg_error =
48
+ _libcrash._msg_error;
49
+ /* global
50
+ _argv_get */
51
+ const
52
+ _argv_get =
53
+ _libcrash._argv_get;
54
+
55
+ const
56
+ _libevm_chains_info =
57
+ require(
58
+ "./libevm-chains-info");
59
+ /* global
60
+ _rpc_backends_get */
61
+ const
62
+ _evm_chains_db_path_get =
63
+ _libevm_chains_info._evm_chains_db_path_get;
64
+ /* global
65
+ _rpc_backends_get */
66
+ const
67
+ _evm_chain_info_get =
68
+ _libevm_chains_info._evm_chain_info_get;
69
+ /* global
70
+ _rpc_backends_get */
71
+ const
72
+ _rpc_backend_get =
73
+ _libevm_chains_info._rpc_backend_get;
74
+ /* global
75
+ _rpc_backends_get */
76
+ const
77
+ _rpc_backends_get =
78
+ _rpc_backends_get;
79
+
80
+ function
81
+ _global_variables() {
82
+ /* global
83
+ app_name:
84
+ writable */
85
+ app_name =
86
+ "evm-chains-info.js";
87
+ /* global
88
+ app_opts:
89
+ writable */
90
+ app_opts =
91
+ [];
92
+ /* global
93
+ encoding_format:
94
+ writable */
95
+ encoding_format =
96
+ "";
97
+ /* global
98
+ buffer_size:
99
+ writable */
100
+ buffer_size =
101
+ "";
102
+ /* global
103
+ string_length:
104
+ writable */
105
+ string_length =
106
+ "";
107
+ /* global
108
+ in_file:
109
+ writable */
110
+ in_file =
111
+ "";
112
+ /* global
113
+ out_txt_prefix:
114
+ writable */
115
+ out_txt_prefix =
116
+ "";
117
+ /* global
118
+ amount_only:
119
+ writable */
120
+ amount_only =
121
+ "";
122
+ /* global
123
+ quiet:
124
+ writable */
125
+ quiet =
126
+ "";
127
+ }
128
+
129
+ function
130
+ _overrides_set() {
131
+ if ( encoding_format == "" ) {
132
+ encoding_format =
133
+ "base64";
134
+ }
135
+ if ( string_length == "" ) {
136
+ string_length =
137
+ "10000";
138
+ }
139
+ if ( buffer_size == "" ) {
140
+ buffer_size =
141
+ "2000000"; // 2MB
142
+ }
143
+ if ( amount_only == "" ) {
144
+ amount_only =
145
+ "false";
146
+ }
147
+ }
148
+
149
+ function
150
+ _config_show() {
151
+ let
152
+ _line,
153
+ _text;
154
+ _text = [
155
+ `${app_name} configuration:`,
156
+ ` Runtime environment: ${runtime_environment}`,
157
+ ` Encoding format: ${encoding_format}`,
158
+ ` Buffer size: ${buffer_size}`,
159
+ ` Chunk string length: ${string_length}`,
160
+ ` Chunks amount only: ${amount_only}`,
161
+ ` In file: ${in_file}`,
162
+ ` Out text prefix: ${out_txt_prefix}`,
163
+ ];
164
+ for ( _line of _text ) {
165
+ _msg_info(
166
+ _line);
167
+ }
168
+ }
169
+
170
+ function
171
+ _usage(
172
+ _exit_code) {
173
+ let
174
+ _line,
175
+ _text;
176
+ _text = [
177
+ "Converts binary to ascii text.",
178
+ "",
179
+ "Usage:",
180
+ "",
181
+ " bin2txt",
182
+ " <in-file>",
183
+ " <out-txt-prefix>",
184
+ "",
185
+ " arguments:",
186
+ " <in-file> An input file.",
187
+ " <out-file-prefix> Prefix for the output file(s).",
188
+ "",
189
+ " options:",
190
+ "",
191
+ " -f --encoding-format Encoding format ('base64').",
192
+ ` <encoding-format> Default: '${encoding_format}`,
193
+ "",
194
+ " -B --buffer-size Size in bytes the input file will",
195
+ " <buffer-size> be split before being read",
196
+ " in memory and passed to",
197
+ " the encoder.",
198
+ ` Default: '${buffer_size}'`,
199
+ "",
200
+ " -L --string-length String chunk length.",
201
+ ` <string-length> Default: '${string_length}'`,
202
+ "",
203
+ " -s --amount-only Only print chunks amount.",
204
+ ` Default: '${amount_only}'`,
205
+ "",
206
+ " -h --help This message.",
207
+ " -v --verbose Enable verbose output."
208
+ ];
209
+ for ( _line of _text ) {
210
+ console.log(
211
+ _line);
212
+ }
213
+ process.exit(
214
+ _exit_code);
215
+ }
216
+
217
+ function
218
+ _cmdline_parse() {
219
+ let
220
+ _argv,
221
+ _help_display,
222
+ _msg;
223
+ _argv =
224
+ _argv_get();
225
+ _options =
226
+ _argv[
227
+ "_"];
228
+ quiet =
229
+ "y";
230
+ runtime_environment =
231
+ "node";
232
+ if ( _options.indexOf(
233
+ "--help") > -1 ||
234
+ _options.indexOf(
235
+ "-h") > -1) {
236
+ _help_display =
237
+ true;
238
+ }
239
+ if ( _help_display ) {
240
+ quiet =
241
+ "n";
242
+ _usage(
243
+ 0);
244
+ }
245
+ if ( typeof(
246
+ _argv) == "undefined" ||
247
+ _argv[
248
+ "_"].length < 1 ) {
249
+ _msg =
250
+ "Input file argument required.";
251
+ _msg_error(
252
+ _msg,
253
+ 0);
254
+ _usage(
255
+ 1);
256
+ }
257
+ in_file =
258
+ _argv[
259
+ "_"][
260
+ 0];
261
+ if ( _argv[
262
+ "_"].length < 2 ) {
263
+ out_txt_prefix =
264
+ in_file +
265
+ ".base64";
266
+ }
267
+ if ( "L" in _argv ) {
268
+ string_length =
269
+ _argv[
270
+ "L"];
271
+ }
272
+ if ( "string-length" in _argv ) {
273
+ string_length =
274
+ _argv[
275
+ "string-length"];
276
+ }
277
+ if ( "s" in _argv ) {
278
+ amount_only =
279
+ _argv[
280
+ "s"];
281
+ }
282
+ if ( "amount-only" in _argv ) {
283
+ amount_only =
284
+ _argv[
285
+ "amount-only"];
286
+ }
287
+ if ( "v" in _argv ) {
288
+ verbose =
289
+ _argv[
290
+ "v"];
291
+ }
292
+ if ( "verbose" in _argv ) {
293
+ verbose =
294
+ _argv[
295
+ "verbose"];
296
+ }
297
+ if ( verbose ) {
298
+ quiet =
299
+ "n";
300
+ }
301
+ }
302
+
303
+ function
304
+ _url_parse() {
305
+ let
306
+ _argv;
307
+ runtime_environment =
308
+ "browser";
309
+ _argv =
310
+ _argv_url_get();
311
+ in_file =
312
+ _argv_url_get(
313
+ "in_file")[
314
+ 0];
315
+ target_planet =
316
+ _argv_url_get(
317
+ "out_txt_prefix")[
318
+ 0];
319
+ quiet =
320
+ _argv_url_get(
321
+ "quiet");
322
+ if ( quiet.length === 0 ) {
323
+ quiet =
324
+ "n";
325
+ }
326
+ }
327
+
328
+ _global_variables();
329
+ if ( _cmdline_check(
330
+ "bin2txt.js") == true ) {
331
+ _cmdline_parse();
332
+ }
333
+ _overrides_set();
334
+ _config_show();
335
+ app_opts = [
336
+ in_file,
337
+ out_txt_prefix,
338
+ encoding_format,
339
+ string_length,
340
+ buffer_size,
341
+ amount_only
342
+ ];
343
+ _bin2txt.apply(
344
+ null,
345
+ app_opts);
@@ -0,0 +1,206 @@
1
+ #!/usr/bin/env node
2
+
3
+
4
+ // SPDX-License-Identifier: AGPL-3.0-or-later
5
+
6
+ /** ----------------------------------------------------------------
7
+ * libevm-chains-info
8
+ * ----------------------------------------------------------------
9
+ * Copyright ©
10
+ * Pellegrino Prevete
11
+ * 2025, 2026
12
+ *
13
+ * All rights reserved
14
+ * ----------------------------------------------------------------
15
+ *
16
+ * This program is free software: you can redistribute it and/or
17
+ * modify it under the terms of the GNU General Public License as
18
+ * published by the Free Software Foundation, either version 3 of
19
+ * the License, or (at your option) any later version.
20
+ *
21
+ * This program 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 General Public License for more details.
25
+ *
26
+ * You should have received a copy of the
27
+ * GNU General Public License
28
+ * along with this program.
29
+ * If not, see <https://www.gnu.org/licenses/>.
30
+ */
31
+
32
+ // const
33
+ // _libcrash =
34
+ // require(
35
+ // '../libcrash-js/crash-js');
36
+ const
37
+ _libcrash_module =
38
+ require(
39
+ "crash-js");
40
+ _file_exists =
41
+ _libcrash_module._file_exists;
42
+ _json_read =
43
+ _libcrash_module._json_read;
44
+ _path_join =
45
+ _libcrash_module._path_join;
46
+
47
+ function
48
+ _evm_chains_db_path_get(
49
+ _user) {
50
+ let
51
+ _db_exists,
52
+ _path;
53
+ if ( _user == undefined ) {
54
+ _user =
55
+ false;
56
+ }
57
+ if ( _user == true ) {
58
+ _path =
59
+ _path_join(
60
+ [process.env.HOME,
61
+ ".local",
62
+ "share",
63
+ "evm-chains",
64
+ "chains.json"])
65
+ _db_exists =
66
+ _file_exists(
67
+ _db_path);
68
+ if ( _db_exists == false ) {
69
+ _user =
70
+ false;
71
+ }
72
+ }
73
+ if ( _user == false ) {
74
+ _path =
75
+ _path_join(
76
+ [process.env.NODE_PATH,
77
+ "..",
78
+ "evm-chains",
79
+ "chains.json"])
80
+ }
81
+ else {
82
+ _msg_error(
83
+ "Input variable '_user' must be a boolean",
84
+ 0);
85
+ }
86
+ return _path;
87
+ }
88
+
89
+ function
90
+ _evm_chain_info_get(
91
+ _chain_id,
92
+ _chain_info,
93
+ _db_path) {
94
+ let
95
+ _db,
96
+ _db_exists;
97
+ if ( _db_path == undefined ) {
98
+ _db_path =
99
+ _evm_chains_db_path_get(
100
+ false);
101
+ }
102
+ _db_exists =
103
+ _file_exists(
104
+ _db_path);
105
+ if ( _db_exists == false ) {
106
+ _msg_error(
107
+ "Database file does not exists.",
108
+ 1);
109
+ }
110
+ _db =
111
+ _json_read(
112
+ _db_path);
113
+ for ( _chain_info of _db) {
114
+ if ( _chain_info["chainId"] == _chain_id ) {
115
+ return _chain_info;
116
+ }
117
+ }
118
+ _msg_error(
119
+ `Network '${_chain_id}' not found.`,
120
+ 1);
121
+ }
122
+
123
+ function
124
+ _rpc_backend_get(
125
+ _network_chain_id,
126
+ _selection_method,
127
+ _db_path) {
128
+ let
129
+ _chain_id,
130
+ _chain_info;
131
+ if ( _network_chain_id == undefined ) {
132
+ _msg_error(
133
+ "Network's ChainID not specified.",
134
+ 1);
135
+ }
136
+ if ( _selection_method == undefined ) {
137
+ _selection_method =
138
+ "kirsh";
139
+ }
140
+ if ( _db_path == undefined ) {
141
+ _db_path =
142
+ _evm_chains_db_path_get(
143
+ false);
144
+ }
145
+ _chain_id =
146
+ Number(
147
+ _network_chain_id);
148
+ _chain_info =
149
+ _evm_chain_info_get(
150
+ _chain_id,
151
+ _db_path);
152
+ if ( _selection_method == "kirsh" ) {
153
+ return _chain_info["rpc"][0];
154
+ }
155
+ else {
156
+ _msg_error(
157
+ "Unknown selection method.",
158
+ 1);
159
+ }
160
+ }
161
+
162
+ function _rpc_backends_get(
163
+ _networks_chain_ids,
164
+ _selection_method,
165
+ _db_path) {
166
+ let
167
+ _chain_id,
168
+ _rpc_backend_get_opts,
169
+ _rpcs;
170
+ if ( _selection_method == undefined ) {
171
+ _selection_method =
172
+ "kirsh";
173
+ }
174
+ if ( _db_path == undefined ) {
175
+ _db_path =
176
+ _evm_chains_db_path_get(
177
+ false);
178
+ }
179
+ _rpcs =
180
+ [];
181
+ for ( _chain_id of _networks_chain_ids ) {
182
+ _rpc_backend_get_opts = [
183
+ _chain_id,
184
+ _selection_method,
185
+ _db_path
186
+ ];
187
+ _rpc_backend =
188
+ _rpc_backend_get.apply(
189
+ null,
190
+ _rpc_backend_get_opts);
191
+ _rpcs.append(
192
+ _rpc_backend);
193
+ }
194
+ return _rpcs;
195
+ }
196
+
197
+ module.exports = {
198
+ _evm_chains_db_path_get:
199
+ _evm_chains_db_path_get,
200
+ _evm_chain_info_get:
201
+ _evm_chain_info_get,
202
+ _rpc_backend_get:
203
+ _rpc_backend_get,
204
+ _rpc_backends_get:
205
+ _rpc_backends_get
206
+ };