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