-
Notifications
You must be signed in to change notification settings - Fork 7
/
incrementSalt.cjs
46 lines (37 loc) · 1.17 KB
/
incrementSalt.cjs
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
const fs = require('fs');
const args = process.argv.slice(2);
if (args.length < 1) {
console.error("Usage: node incrementSalt.cjs <fileName>");
process.exit(1);
}
const [fileName] = args;
const filePath = 'deployment-config/'+fileName;
fs.readFile(filePath, 'utf8', (err, data) => {
if (err) {
console.error('Error reading file:', err);
return;
}
let jsonData = JSON.parse(data);
const incrementHex = (hex) => {
let num = BigInt(hex);
num += 1n;
return '0x' + num.toString(16);
};
const incrementSalts = (obj) => {
for (let key in obj) {
if (typeof obj[key] === 'string' && obj[key].startsWith('0x') && key.toLowerCase().includes('salt')) {
obj[key] = incrementHex(obj[key]);
} else if (typeof obj[key] === 'object') {
incrementSalts(obj[key]);
}
}
};
incrementSalts(jsonData);
fs.writeFile(filePath, JSON.stringify(jsonData, null, 2), 'utf8', (err) => {
if (err) {
console.error('Error writing file:', err);
return;
}
console.log('File successfully updated');
});
});