evm-contracts-tools 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.
@@ -0,0 +1,369 @@
1
+ #!/usr/bin/env node
2
+
3
+ // SPDX-License-Identifier: AGPL-3.0-or-later
4
+
5
+ /** ----------------------------------------------------------------------
6
+ * Copyright ©
7
+ * Pellegrino Prevete
8
+ * 2024, 2025, 2026
9
+ *
10
+ * All rights reserved
11
+ * ----------------------------------------------------------------------
12
+ *
13
+ * This program is free software: you can redistribute it and/or modify
14
+ * it under the terms of the GNU General Public License as published by
15
+ * the Free Software Foundation, either version 3 of the License, or
16
+ * (at your option) any later version.
17
+ *
18
+ * This program is distributed in the hope that it will be useful,
19
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ * GNU General Public License for more details.
22
+ *
23
+ * You should have received a copy of the GNU General Public License
24
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
25
+ */
26
+
27
+ const
28
+ _libcrash =
29
+ require(
30
+ '../libcrash-js/crash-js');
31
+ _cmdline_check =
32
+ _libcrash._cmdline_check;
33
+ _msg_info =
34
+ _libcrash._msg_info;
35
+ _msg_error =
36
+ _libcrash._msg_error;
37
+ _printf =
38
+ _libcrash._printf;
39
+ const
40
+ _deployer_get_module =
41
+ require(
42
+ './deployer-get');
43
+ _deployer_get =
44
+ _deployer_get_module._deployer_get;
45
+
46
+ function
47
+ _global_variables() {
48
+ app_name =
49
+ "deployer-verify";
50
+ wallet_seed =
51
+ "";
52
+ retries_max =
53
+ "";
54
+ api_key_path =
55
+ "";
56
+ chain_id =
57
+ "";
58
+ chain_name =
59
+ "";
60
+ target_network =
61
+ "";
62
+ contract_address =
63
+ "";
64
+ contract_deployer =
65
+ "";
66
+ transaction_deployment =
67
+ "";
68
+ quiet =
69
+ "";
70
+ }
71
+
72
+ function
73
+ _delay(
74
+ _time) {
75
+ return new Promise(resolve => setTimeout(resolve, _time));
76
+ }
77
+
78
+ async function
79
+ _deployer_verify(
80
+ _wallet_seed,
81
+ _retries_max,
82
+ _api_key_path,
83
+ _chain_id,
84
+ _chain_name,
85
+ _target_network,
86
+ _contract_address,
87
+ _contract_deployer,
88
+ _transaction_deployment) {
89
+ let
90
+ _deployer_get_opts,
91
+ _deployer_real,
92
+ _is_deployer;
93
+ _deployer_get_opts = [
94
+ _wallet_seed,
95
+ _retries_max,
96
+ _api_key_path,
97
+ _chain_id,
98
+ _chain_name,
99
+ _target_network,
100
+ _contract_address,
101
+ _transaction_deployment
102
+ ];
103
+ _deployer_real =
104
+ await _deployer_get.apply(
105
+ null,
106
+ _deployer_get_opts);
107
+ if ( _deployer_real == undefined ) {
108
+ throw "Error obtaining the deployer from input data."
109
+ }
110
+ if ( _contract_deployer == _deployer_real ) {
111
+ _is_deployer =
112
+ true;
113
+ else if ( _contract_deployer != _deployer_real ) {
114
+ _is_deployer =
115
+ false;
116
+ return _is_deployer;
117
+ }
118
+
119
+ function
120
+ _config_show() {
121
+ let
122
+ _line,
123
+ _method_args,
124
+ _text;
125
+ _text =
126
+ [];
127
+ _text.push(
128
+ "deployer-get configuration:");
129
+ _text.push(
130
+ " Wallet seed: {wallet_seed}".replace(
131
+ "{wallet_seed}",
132
+ wallet_seed));
133
+ _text.push(
134
+ " Max retries: {retries_max}".replace(
135
+ "{retries_max}",
136
+ retries_max));
137
+ _text.push(
138
+ " API Key path: {api_key_path}".replace(
139
+ "{api_key_path}",
140
+ api_key_path));
141
+ _text.push(
142
+ " Chain ID: {chain_id}".replace(
143
+ "{chain_id}",
144
+ chain_id));
145
+ _text.push(
146
+ " Chain Name: {chain_name}".replace(
147
+ "{chain_name}",
148
+ chain_name));
149
+ _text.push(
150
+ " Target network: {target_network}".replace(
151
+ "{target_network}",
152
+ target_network));
153
+ _text.push(
154
+ " Contract address: {contract_address}".replace(
155
+ "{contract_address}",
156
+ contract_address));
157
+ _text.push(
158
+ " Contract deployer: {contract_deployer}".replace(
159
+ "{contract_deployer}",
160
+ contract_deployer));
161
+ _text.push(
162
+ " Deployment transaction: {transaction_deployment}".replace(
163
+ "{transaction_deployment}",
164
+ transaction_deployment));
165
+ for (_line of _text) {
166
+ _msg_info(
167
+ _line);
168
+ }
169
+ }
170
+
171
+ function
172
+ _usage(
173
+ _exit) {
174
+ let
175
+ _line,
176
+ _text;
177
+ _text = [
178
+ "Given a deployment transaction hash",
179
+ "and a contract address, determines",
180
+ "if an input address is the",
181
+ "contract deployer.",
182
+ "",
183
+ "Usage:",
184
+ " deployer-verify",
185
+ " <quiet>",
186
+ " <wallet_seed>",
187
+ " <retries_max>",
188
+ " <api_key_path>",
189
+ " <chain_id>",
190
+ " <chain_name>",
191
+ " <target_network>",
192
+ " <contract_address>",
193
+ " <contract_deployer>",
194
+ " <transaction_deployment>",
195
+ "",
196
+ "Args:",
197
+ " <quiet> Can be 'y' or 'n'",
198
+ " Default: y",
199
+ " <wallet_seed> Path of the file containing",
200
+ " the seed phrase.",
201
+ " <retries_max> Maximum number of retries before",
202
+ " failing.",
203
+ " <api_key_path> Path of the API key for the",
204
+ " contract ABI provider service",
205
+ " <target_network> Network on which the contract",
206
+ " resides.",
207
+ " <contract_address> Address of the contract.",
208
+ " <contract_deployer> Address of the supposed deployer.",
209
+ " <transaction_deployment> Contract deployment transaction.",
210
+ "",
211
+ " Options:",
212
+ " -h This help."
213
+ ];
214
+ for (_line of _text) {
215
+ _msg_info(
216
+ _line);
217
+ }
218
+ process.exit(
219
+ _exit);
220
+ }
221
+
222
+ function
223
+ _overrides_set() {
224
+ if ( retries_max == "" ) {
225
+ retries_max =
226
+ 10;
227
+ }
228
+ }
229
+
230
+ function
231
+ _cmdline_parse() {
232
+ quiet =
233
+ "y";
234
+ process.argv.forEach(
235
+ function (
236
+ _value,
237
+ _index,
238
+ _array) {
239
+ if ( _index == 2 ) {
240
+ quiet =
241
+ _value;
242
+ }
243
+ if ( _index == 3 ) {
244
+ wallet_seed =
245
+ _value;
246
+ }
247
+ if ( _index == 4 ) {
248
+ retries_max =
249
+ _value;
250
+ }
251
+ if ( _index == 5 ) {
252
+ api_key_path =
253
+ _value;
254
+ }
255
+ if ( _index == 6 ) {
256
+ chain_id =
257
+ _value;
258
+ }
259
+ if ( _index == 7 ) {
260
+ chain_name =
261
+ _value;
262
+ }
263
+ if ( _index == 8 ) {
264
+ target_network =
265
+ _value;
266
+ }
267
+ if ( _index == 9 ) {
268
+ contract_address =
269
+ _value;
270
+ }
271
+ if ( _index == 10 ) {
272
+ contract_deployer =
273
+ _value;
274
+ }
275
+ if ( _index == 11 ) {
276
+ transaction_deployment =
277
+ _value;
278
+ }
279
+ if ( _value == "-h" ||
280
+ _value == "--help" ) {
281
+ _usage(
282
+ 0);
283
+ }
284
+ }
285
+ );
286
+ if ( contract_address == "" ) {
287
+ _msg_error(
288
+ "No contract address specified.",
289
+ 0);
290
+ quiet =
291
+ "n";
292
+ _usage(
293
+ 1);
294
+ }
295
+ if ( contract_deployer == "" ) {
296
+ _msg_error(
297
+ "No contract deployer specified.",
298
+ 0);
299
+ quiet =
300
+ "n";
301
+ _usage(
302
+ 1);
303
+ }
304
+ if ( transaction_deployment == "" ) {
305
+ _msg_error(
306
+ "No deployement transaction specified.",
307
+ 0);
308
+ quiet =
309
+ "n";
310
+ _usage(
311
+ 1);
312
+ }
313
+ }
314
+
315
+ async function
316
+ _deployer_verify_cmdline(
317
+ _app_opts) {
318
+ let
319
+ _is_deployer,
320
+ _msg;
321
+ try {
322
+ _is_deployer =
323
+ await _deployer_verify.apply(
324
+ null,
325
+ _app_opts);
326
+ if ( _is_deployer != undefined ) {
327
+ _printf(
328
+ _is_deployer.toString());
329
+ }
330
+ else {
331
+ _msg =
332
+ "It has not been possile to discern from " +
333
+ "input data whether the candidate deployer " +
334
+ "is the contract actual deployer.";
335
+ throw _msg;
336
+ }
337
+ } catch (error) {
338
+ _msg_error(
339
+ error,
340
+ 1);
341
+ }
342
+ }
343
+
344
+ if ( _cmdline_check(
345
+ "deployer-verify") ) {
346
+ _global_variables();
347
+ _cmdline_parse();
348
+ _overrides_set();
349
+ _config_show();
350
+ app_opts = [
351
+ wallet_seed,
352
+ retries_max,
353
+ api_key_path,
354
+ chain_id,
355
+ chain_name,
356
+ target_network,
357
+ contract_address,
358
+ contract_deployer,
359
+ transaction_deployment
360
+ ];
361
+ _deployer_verify_cmdline(
362
+ app_opts);
363
+ }
364
+
365
+ module.exports = {
366
+ _deployer_verify:
367
+ _deployer_verify
368
+ };
369
+