hash.js 771 B

1234567891011121314151617181920212223242526272829
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const encoding_1 = require("./encoding");
  4. /**
  5. * Hash returned from functions in the browser.
  6. */
  7. class Hash extends Uint8Array {
  8. /**
  9. * A constant-time comparison against the other hash/array.
  10. */
  11. equals(other) {
  12. if (!(other instanceof Uint8Array)) {
  13. return false;
  14. }
  15. if (other.length !== this.length) {
  16. return false;
  17. }
  18. let cmp = 0;
  19. for (let i = 0; i < this.length; i++) {
  20. cmp |= this[i] ^ other[i];
  21. }
  22. return cmp === 0;
  23. }
  24. toString(encoding = 'hex') {
  25. return encoding_1.mustGetEncoder(encoding)(this);
  26. }
  27. }
  28. exports.Hash = Hash;
  29. //# sourceMappingURL=hash.js.map