fix: hash all indexed keys

This commit is contained in:
thecodrr
2020-11-09 10:30:33 +05:00
parent 142ec35bfe
commit 4a5daf2a8d
5 changed files with 22 additions and 15 deletions

View File

@@ -1,5 +1,4 @@
import Hashes from "jshashes";
const md5 = new Hashes.MD5();
import SparkMD5 from "spark-md5";
const invalidKeys = ["user", "t", "lastBackupTime"];
const validTypes = ["mobile", "web", "node"];
@@ -44,8 +43,8 @@ export default class Backup {
type,
date: Date.now(),
data,
hash: md5.hex(JSON.stringify(data)),
hash_type: "md5",
hash: SparkMD5.hash(JSON.stringify(data)),
hash_type: "spark-md5",
});
}
@@ -101,8 +100,8 @@ export default class Backup {
_verify(backup) {
const { hash, hash_type, data: db } = backup;
switch (hash_type) {
case "md5": {
return hash === md5.hex(JSON.stringify(db));
case "spark-md5": {
return hash === SparkMD5.hash(JSON.stringify(db));
}
default: {
return false;