mirror of
https://github.com/PretendoNetwork/account.git
synced 2026-09-30 14:18:22 -05:00
/nex_token/@me uses cache and async fs
This commit is contained in:
@@ -122,7 +122,7 @@ router.get('/nex_token/@me', async (request, response) => {
|
||||
|
||||
const cryptoPath = `${__dirname}/../../../../certs/${service_type}/${service_name}`;
|
||||
|
||||
if (!fs.pathExistsSync(cryptoPath)) {
|
||||
if (!await fs.pathExists(cryptoPath)) {
|
||||
// Need to generate keys
|
||||
return response.send(xmlbuilder.create({
|
||||
errors: {
|
||||
@@ -134,12 +134,21 @@ router.get('/nex_token/@me', async (request, response) => {
|
||||
}).end());
|
||||
}
|
||||
|
||||
const publicKey = fs.readFileSync(`${cryptoPath}/public.pem`);
|
||||
const hmacSecret = fs.readFileSync(`${cryptoPath}/secret.key`);
|
||||
let publicKey = cache.getNEXPublicKey(service_name);
|
||||
if (publicKey === null) {
|
||||
publicKey = await fs.readFile(`${cryptoPath}/public.pem`);
|
||||
await cache.setNEXPublicKey(service_name, publicKey);
|
||||
}
|
||||
|
||||
let secretKey = cache.getNEXSecretKey(service_name);
|
||||
if (secretKey === null) {
|
||||
secretKey = await fs.readFile(`${cryptoPath}/secret.key`);
|
||||
await cache.setNEXSecretKey(service_name, secretKey);
|
||||
}
|
||||
|
||||
const cryptoOptions = {
|
||||
public_key: publicKey,
|
||||
hmac_secret: hmacSecret
|
||||
hmac_secret: secretKey
|
||||
};
|
||||
|
||||
const tokenOptions = {
|
||||
|
||||
Reference in New Issue
Block a user