mirror of
https://github.com/codex-team/codex.docs.git
synced 2025-07-22 06:39:42 +02:00
Typescript rewrite (#147)
* Updated highlight.js * Update .codexdocsrc.sample remove undefined page for a fresh new install * backend rewritten in TS * test -> TS, .added dockerignore, bug fixed * Removed compiled js files, eslint codex/ts added * fixed jsdocs warning, leaving editor confirmation * use path.resolve for DB paths * db drives updated + fixed User model * redundant cleared + style fixed * explicit type fixing * fixing testing code * added body block type * compiled JS files -> dist, fixed compiling errors * fixed compiling error, re-organized ts source code * updated Dockerfile * fixed link to parent page * up nodejs version * fix package name * fix deps Co-authored-by: nvc8996 <nvc.8996@gmail.com> Co-authored-by: Taly <vitalik7tv@yandex.ru>
This commit is contained in:
parent
059cfb96f9
commit
34514761f5
99 changed files with 3817 additions and 2249 deletions
45
src/backend/utils/crypto.ts
Normal file
45
src/backend/utils/crypto.ts
Normal file
|
@ -0,0 +1,45 @@
|
|||
import crypto from 'crypto';
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} hexStr - input hex string
|
||||
* @returns {string} - output binary string
|
||||
*/
|
||||
function hexToBinary(hexStr: string): string {
|
||||
return (parseInt(hexStr, 16).toString(2))
|
||||
.padStart(8, '0');
|
||||
}
|
||||
|
||||
/**
|
||||
* Create binary md5
|
||||
*
|
||||
* @param stringToHash - string to hash
|
||||
* @returns {string} - binary hash of argument
|
||||
*/
|
||||
export function binaryMD5(stringToHash: string): string {
|
||||
return hexToBinary(crypto.createHash('md5')
|
||||
.update(stringToHash)
|
||||
.digest('hex'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns 16 random bytes in hex format
|
||||
*
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
export function random16(): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
crypto.randomBytes(16, (err, raw) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
}
|
||||
|
||||
resolve(raw.toString('hex'));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export default {
|
||||
binaryMD5,
|
||||
random16,
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue