Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MR414N-ID
GitHub Repository: MR414N-ID/botku2
Path: blob/master/node_modules/@adiwajshing/baileys/lib/Utils/lt-hash.js
1129 views
1
"use strict";
2
Object.defineProperty(exports, "__esModule", { value: true });
3
exports.LT_HASH_ANTI_TAMPERING = void 0;
4
const crypto_1 = require("./crypto");
5
/**
6
* LT Hash is a summation based hash algorithm that maintains the integrity of a piece of data
7
* over a series of mutations. You can add/remove mutations and it'll return a hash equal to
8
* if the same series of mutations was made sequentially.
9
*/
10
const o = 128;
11
class d {
12
constructor(e) {
13
this.salt = e;
14
}
15
add(e, t) {
16
var r = this;
17
for (const item of t) {
18
e = r._addSingle(e, item);
19
}
20
return e;
21
}
22
subtract(e, t) {
23
var r = this;
24
for (const item of t) {
25
e = r._subtractSingle(e, item);
26
}
27
return e;
28
}
29
subtractThenAdd(e, t, r) {
30
var n = this;
31
return n.add(n.subtract(e, r), t);
32
}
33
_addSingle(e, t) {
34
var r = this;
35
const n = new Uint8Array((0, crypto_1.hkdf)(Buffer.from(t), o, { info: r.salt })).buffer;
36
return r.performPointwiseWithOverflow(e, n, ((e, t) => e + t));
37
}
38
_subtractSingle(e, t) {
39
var r = this;
40
const n = new Uint8Array((0, crypto_1.hkdf)(Buffer.from(t), o, { info: r.salt })).buffer;
41
return r.performPointwiseWithOverflow(e, n, ((e, t) => e - t));
42
}
43
performPointwiseWithOverflow(e, t, r) {
44
const n = new DataView(e), i = new DataView(t), a = new ArrayBuffer(n.byteLength), s = new DataView(a);
45
for (let e = 0; e < n.byteLength; e += 2) {
46
s.setUint16(e, r(n.getUint16(e, !0), i.getUint16(e, !0)), !0);
47
}
48
return a;
49
}
50
}
51
exports.LT_HASH_ANTI_TAMPERING = new d('WhatsApp Patch Integrity');
52
53