-
Notifications
You must be signed in to change notification settings - Fork 0
/
security_config.js
48 lines (42 loc) · 1.6 KB
/
security_config.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
```javascript
// Importing necessary libraries and tools
const crypto = require('crypto');
const fs = require('fs');
const path = require('path');
// Importing blockchain configuration
const blockchainConfig = require('./blockchain_config');
// Security configuration for the project
class SecurityConfig {
constructor() {
this.keys = {
QuantumUnityFramework: this.generateKeys(blockchainConfig.QUANTUM_UNITY_FRAMEWORK_CHAIN_ID),
GlobalDigitalCurrencyNetwork: this.generateKeys(blockchainConfig.GLOBAL_DIGITAL_CURRENCY_NETWORK_CHAIN_ID),
Contudo: this.generateKeys(blockchainConfig.CONTUDO_CHAIN_ID)
};
}
// Function to generate a new pair of keys
generateKeys(chainId) {
// Generating a new pair of keys
const { privateKey, publicKey } = crypto.generateKeyPairSync('rsa', {
modulusLength: 2048,
publicKeyEncoding: {
type: 'spki',
format: 'pem'
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
cipher: 'aes-256-cbc',
passphrase: ''
}
});
// Writing the keys to files
fs.writeFileSync(path.resolve(__dirname, `./keys/${chainId}_private.pem`), privateKey);
fs.writeFileSync(path.resolve(__dirname, `./keys/${chainId}_public.pem`), publicKey);
console.log(`Keys for Chain ID ${chainId} generated successfully.`);
return { privateKey, publicKey };
}
}
// Exporting the security configuration
module.exports = new SecurityConfig();
```