AuthKey.js 879 B

1234567891011121314151617181920212223242526272829303132
  1. const Helpers = require("../utils/Helpers");
  2. class AuthKey {
  3. constructor(data) {
  4. this.key = data;
  5. let offset = 0;
  6. let buffer = Helpers.sha1(data);
  7. this.auxHash = buffer.readBigUInt64LE(offset);
  8. offset = 8 + 4;
  9. this.keyId = buffer.readBigUInt64LE(offset);
  10. }
  11. /**
  12. * Calculates the new nonce hash based on the current class fields' values
  13. * @param new_nonce {Buffer}
  14. * @param number {number}
  15. * @returns {Buffer}
  16. */
  17. calcNewNonceHash(new_nonce, number) {
  18. let tempBuffer = Buffer.alloc(1);
  19. tempBuffer.writeInt8(number, 0);
  20. let secondBuffer = Buffer.alloc(8);
  21. secondBuffer.writeBigUInt64LE(this.auxHash, 0);
  22. let buffer = Buffer.concat([new_nonce, tempBuffer, secondBuffer]);
  23. return Helpers.calcMsgKey(buffer);
  24. }
  25. }
  26. module.exports = AuthKey;