You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Sha512.js 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. "use strict";
  2. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  3. if (k2 === undefined) k2 = k;
  4. var desc = Object.getOwnPropertyDescriptor(m, k);
  5. if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
  6. desc = { enumerable: true, get: function() { return m[k]; } };
  7. }
  8. Object.defineProperty(o, k2, desc);
  9. }) : (function(o, m, k, k2) {
  10. if (k2 === undefined) k2 = k;
  11. o[k2] = m[k];
  12. }));
  13. var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
  14. Object.defineProperty(o, "default", { enumerable: true, value: v });
  15. }) : function(o, v) {
  16. o["default"] = v;
  17. });
  18. var __importStar = (this && this.__importStar) || function (mod) {
  19. if (mod && mod.__esModule) return mod;
  20. var result = {};
  21. if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  22. __setModuleDefault(result, mod);
  23. return result;
  24. };
  25. Object.defineProperty(exports, "__esModule", { value: true });
  26. /* eslint-disable no-bitwise --
  27. * lots of bitwise operators necessary for this */
  28. const hashjs = __importStar(require("hash.js"));
  29. const BigNum = require("bn.js");
  30. class Sha512 {
  31. constructor() {
  32. this.hash = hashjs.sha512();
  33. }
  34. add(bytes) {
  35. this.hash.update(bytes);
  36. return this;
  37. }
  38. addU32(i) {
  39. return this.add([
  40. (i >>> 24) & 0xff,
  41. (i >>> 16) & 0xff,
  42. (i >>> 8) & 0xff,
  43. i & 0xff,
  44. ]);
  45. }
  46. finish() {
  47. return this.hash.digest();
  48. }
  49. first256() {
  50. return this.finish().slice(0, 32);
  51. }
  52. first256BN() {
  53. return new BigNum(this.first256());
  54. }
  55. }
  56. exports.default = Sha512;
  57. //# sourceMappingURL=Sha512.js.map