mirror of
https://github.com/smogon/pokemon-showdown.git
synced 2026-03-21 17:25:10 -05:00
We're skipping two major typescript-eslint versions, so there are a bunch of changes here, including: - it's catching a lot of things it didn't catch in the past, for reasons unclear to me - no-unused-vars has to be explicitly disabled in global-types now - a lot of `ts-ignore`s were never necessary and have been fixed - Crashlogger can now handle being thrown things that aren't errors. This has never been a problem in the past, but to satisfy TypeScript we might as well not die in a fire on the off chance someone tries to `throw null` or something.
43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
/**
|
|
* Verifier process
|
|
* Pokemon Showdown - http://pokemonshowdown.com/
|
|
*
|
|
* This is just an asynchronous implementation of a verifier for a
|
|
* signed key, because Node.js's crypto functions are synchronous,
|
|
* strangely, considering how everything else is asynchronous.
|
|
*
|
|
* I wrote this one day hoping it would help with performance, but
|
|
* I don't think it had any noticeable effect.
|
|
*
|
|
* @license MIT
|
|
*/
|
|
import * as crypto from 'crypto';
|
|
|
|
import {QueryProcessManager} from '../lib/process-manager';
|
|
|
|
export const PM = new QueryProcessManager<{data: string, signature: string}, boolean>(module, ({data, signature}) => {
|
|
const verifier = crypto.createVerify(Config.loginserverkeyalgo);
|
|
verifier.update(data);
|
|
let success = false;
|
|
try {
|
|
success = verifier.verify(Config.loginserverpublickey, signature, 'hex');
|
|
} catch (e) {}
|
|
|
|
return success;
|
|
});
|
|
|
|
export function verify(data: string, signature: string): Promise<boolean> {
|
|
return PM.query({data, signature});
|
|
}
|
|
|
|
if (!PM.isParentProcess) {
|
|
// This is a child process!
|
|
global.Config = require('./config-loader').Config;
|
|
|
|
const Repl = require('../lib/repl').Repl;
|
|
// eslint-disable-next-line no-eval
|
|
Repl.start('verifier', (cmd: string) => eval(cmd));
|
|
} else {
|
|
PM.spawn(global.Config ? Config.verifierprocesses : 1);
|
|
}
|