-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
executable file
·94 lines (80 loc) · 3.73 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env node
const program = require('commander');
const colour = require('colors');
const pad = require('pad');
const { exec } = require('child_process');
const parseTranscripts = require('./scripts/parseTranscripts')
const signAttestation = require('./scripts/signAttestation');
const fetch = require('./prompts/fetch');
const getValidationType = require('./prompts/validationType');
const dependencies = require('./prompts/dependencies');
const getAddress = require('./prompts/address');
const attestation = require('./prompts/attestation');
async function executeCommand(cmd, prettyName, silent = false) {
return new Promise((resolve, reject) => {
const cmdData = exec(cmd);
const output = [];
cmdData.stdout.on('data', function (data) {
output.push(data.toString());
if (!silent) console.log(data);
});
cmdData.on('exit', function (code, data) {
if (!silent) {
if (code === 0) {
if (!silent) console.log(colour.bold.green(`\n${prettyName} successful.\n`));
} else {
if (!silent) console.log(colour.red(`${prettyName} failed.`));
return reject(data);
}
}
return resolve(output);
});
}).catch(console.log);
}
async function getPythonVersion(bin) {
const [pythonVersion] = await executeCommand(`${bin} --version`, 'Feth python version', true);
if (!pythonVersion) {
return false;
}
const [,version] = pythonVersion.split(' ');
const [mainRelease] = version.split('.');
return parseInt(mainRelease);
}
program
.command('validate')
.description('Validate AZTEC Ignition contribution')
.action(async () => {
const { address: rawAddress } = await getAddress();
const address = rawAddress.trim().toLowerCase();
const { validationType } = await getValidationType();
if (validationType === 'signature' || validationType === 'both') {
console.log(pad(colour.bold.underline.white(`\nValidation of signature for address ${address}\n`), 30));
await executeCommand(`"$(pwd)/scripts/recoverAddress.sh" ${address}`, "Signature validation");
}
if (validationType === 'inclusion' || validationType === 'both') {
console.log(pad(colour.bold.underline.white(`\nValidation of inclusion for address ${address}\n`), 30));
const { confirmDownload } = await fetch();
if (!confirmDownload) {
console.log(colour.yellow("Skipping download, assuming data is in relevant folders."));
} else {
await executeCommand("npm run fetch:essential", "Data download");
}
const pythonVersion = await getPythonVersion('python');
if ((!pythonVersion || pythonVersion < 3) && !(await getPythonVersion('python3'))) {
console.log(colour.red('Please install python3 on your machine.'));
return;
}
parseTranscripts();
const { confirmDependencies } = await dependencies();
if (confirmDependencies) {
const pipBin = (pythonVersion < 3) ? 'pip3' : 'pip';
await executeCommand(`${pipBin} install py_ecc`, "Dependency install");
}
console.log(pad(colour.bold.underline.white(`\nLaunching validation script...\n`), 30));
const pythonBin = (pythonVersion < 3) ? 'python3' : 'python';
await executeCommand(`${pythonBin} "./scripts/checkPairing.py" ${address}`, "Inclusion validation")
}
const { privateKey } = await attestation();
signAttestation(address, privateKey);
});
program.parse(process.argv);