[EXPAND] [[messages]] messageTitle = "QB Update for GT 2.8 (#681)" messageBody = """ [QB] [DETAILS] details = ["Fixes many Quest Book issues", "Updates QB with changes in GT 2.8"] [DETAILS] """ [[messages]] messageTitle = "Buildscript Refactor (#681)" messageBody = """ [INTERNAL] [DETAILS] details = ["**Important: Buildscript has changed from `npx gulp...` or `gulp...` to `npm run gulp...`**!", "Moves to Node 16 Package Management + Typescript Strict Mode", "New Port QB, Check QB and Fix QB Tasks"] [DETAILS] """ [EXPAND] Co-authored-by: Integer Limit <103940576+IntegerLimit@users.noreply.github.com> Co-authored-by: Ghzdude <44148655+ghzdude@users.noreply.github.com> Co-authored-by: SparkedTheorem <162088357+SparkedTheorem@users.noreply.github.com>
51 lines
1.1 KiB
TypeScript
51 lines
1.1 KiB
TypeScript
import _sha1 from "sha1";
|
|
import _md5 from "md5";
|
|
|
|
import { HashDef } from "#types/hashDef.ts";
|
|
|
|
/**
|
|
* Returns the hash sum of bytes of given bytes using SHA1.
|
|
*
|
|
* This is what CurseForge and Forge are using to check files.
|
|
*/
|
|
export const sha1 = (inputBuffer: Buffer): string => {
|
|
return _sha1(inputBuffer);
|
|
};
|
|
|
|
/**
|
|
* Returns the hash sum of bytes of given bytes using MD5.
|
|
*
|
|
* This is what CF is using to check files.
|
|
*/
|
|
export const md5 = (inputBuffer: Buffer): string => {
|
|
return _md5(inputBuffer);
|
|
};
|
|
|
|
const hashFuncs: { [key: string]: (buffer: Buffer) => string } = {
|
|
sha1,
|
|
md5,
|
|
};
|
|
|
|
/**
|
|
* Compare buffer to the given HashDef.
|
|
*
|
|
* @param {Buffer} buffer
|
|
* @param {HashDef} hashDef
|
|
*
|
|
* @throws {Error} Throws a generic error if hashes don't match.
|
|
*/
|
|
export const compareBufferToHashDef = (
|
|
buffer: Buffer,
|
|
hashDef: HashDef,
|
|
): boolean => {
|
|
if (!hashFuncs[hashDef.id]) {
|
|
throw new Error(`No hash function found for ${hashDef.id}.`);
|
|
}
|
|
|
|
const sum = hashFuncs[hashDef.id](buffer);
|
|
return (
|
|
(Array.isArray(hashDef.hashes) && hashDef.hashes.includes(sum)) ||
|
|
hashDef.hashes == sum
|
|
);
|
|
};
|