Sha512.js 810 B

12345678910111213141516171819202122232425262728293031323334
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. /* eslint-disable no-bitwise --
  4. * lots of bitwise operators necessary for this */
  5. const hashjs = require("hash.js");
  6. const BigNum = require("bn.js");
  7. class Sha512 {
  8. constructor() {
  9. this.hash = hashjs.sha512();
  10. }
  11. add(bytes) {
  12. this.hash.update(bytes);
  13. return this;
  14. }
  15. addU32(i) {
  16. return this.add([
  17. (i >>> 24) & 0xff,
  18. (i >>> 16) & 0xff,
  19. (i >>> 8) & 0xff,
  20. i & 0xff,
  21. ]);
  22. }
  23. finish() {
  24. return this.hash.digest();
  25. }
  26. first256() {
  27. return this.finish().slice(0, 32);
  28. }
  29. first256BN() {
  30. return new BigNum(this.first256());
  31. }
  32. }
  33. exports.default = Sha512;
  34. //# sourceMappingURL=Sha512.js.map