-
Notifications
You must be signed in to change notification settings - Fork 1
/
script-keys.ts
47 lines (40 loc) · 1.53 KB
/
script-keys.ts
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
import { execSync } from 'child_process';
import mkdirp from 'mkdirp';
import process from 'process';
import fs from 'fs';
import { Config } from './script-config';
function generateKey(name: string) {
if (!fs.existsSync(name + '.pub')) {
let res = execSync('/usr/bin/ton/utils/generate-random-id -m keys -n ' + name).toString().trim().split(' ');
if (res.length !== 2) {
throw Error('Invalid keys');
}
fs.writeFileSync(name + '.id', res[0]);
fs.writeFileSync(name + '.uid', res[1]);
}
}
(async () => {
// Create directories
await mkdirp(__dirname + '/gen/keys');
process.chdir(__dirname + '/gen/keys');
// Generate Validator Server Key
generateKey('validator-server');
generateKey('validator-client');
generateKey('lite-server');
// Generate Validator Keys
let output: Buffer = Buffer.alloc(0);
for (let i = 0; i < Config.validators.endpoints.length; i++) {
generateKey('validator-' + (i + 1) + '-validator');
generateKey('validator-' + (i + 1) + '-adnl-main');
generateKey('validator-' + (i + 1) + '-adnl-dht');
generateKey('validator-' + (i + 1) + '-adnl-validator');
let fname = 'validator-' + (i + 1) + '-validator.pub';
let pub = fs.readFileSync(fname).slice(4);
output = Buffer.concat([output, pub]);
}
fs.writeFileSync('validator-keys.pub', output);
// Generate DHT Keys
for (let i = 0; i < Config.dht.endpoints.length; i++) {
generateKey('dht-' + (i + 1));
}
})();