-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
79 lines (66 loc) · 2.67 KB
/
main.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
import fs from 'fs';
import path from 'path';
import unzipper from 'unzipper';
import dotenv from 'dotenv';
import { Proof } from './utils/proofValidation.js';
// Load environment variables from .env file
dotenv.config();
// Default to 'production' if NODE_ENV is not set
const environment = process.env.NODE_ENV || 'production';
// Set the input and output directories based on the environment
const INPUT_DIR = environment === 'development' ? './demo/input' : '/input';
const OUTPUT_DIR = environment === 'development' ? './demo/output' : '/output';
const SEALED_DIR = environment === 'development' ? './demo/sealed' : '/sealed';
function loadConfig() {
const config = {
dlpId: process.env.DLP_ID, // dlp_id is 24 for our datadao
inputDir: INPUT_DIR,
// salt: '5EkntCWI',
validatorBaseApiUrl: 'https://9055-2402-a00-408-24a6-9895-bce2-ef09-b88b.ngrok-free.app/api/poc/datavalidation',
awsAccessKeyId: process.env.AWS_ACCESS_KEY_ID,
awsSecretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
};
console.info(`Using config: ${JSON.stringify(config, null, 2)}`);
return config;
}
async function extractInput() {
const inputFiles = fs.readdirSync(INPUT_DIR);
for (const inputFilename of inputFiles) {
const inputFile = path.join(INPUT_DIR, inputFilename);
if (inputFile.endsWith('.zip')) {
await new Promise((resolve, reject) => {
fs.createReadStream(inputFile)
.pipe(unzipper.Extract({ path: INPUT_DIR }))
.on('close', () => {
console.info(`Extracted ${inputFile}`);
resolve();
})
.on('error', reject);
});
}
}
}
async function run() {
const config = loadConfig();
console.log('Running proof generation...', fs.existsSync(INPUT_DIR));
const inputFilesExist = fs.existsSync(INPUT_DIR) && fs.readdirSync(INPUT_DIR).length > 0;
if (!inputFilesExist) {
throw new Error(`No input files found in ${INPUT_DIR}`);
}
await extractInput();
// Assume Proof is asynchronous
const proof = new Proof(config);
const proofResponse = await proof.generate();
const outputPath = path.join(OUTPUT_DIR, 'results.json');
fs.writeFileSync(outputPath, JSON.stringify(proofResponse, null, 2));
console.info(`Proof generation complete: ${JSON.stringify(proofResponse, null, 2)}`);
}
// Call the run function immediately
(async () => {
try {
await run();
console.log('Run function executed successfully.');
} catch (error) {
console.error('Error executing run function:', error);
}
})();