hash.js 675 B

1234567891011121314151617181920212223242526
  1. import { mustGetEncoder } from './encoding.js';
  2. /**
  3. * Hash returned from functions in the browser.
  4. */
  5. export class Hash extends Uint8Array {
  6. /**
  7. * A constant-time comparison against the other hash/array.
  8. */
  9. equals(other) {
  10. if (!(other instanceof Uint8Array)) {
  11. return false;
  12. }
  13. if (other.length !== this.length) {
  14. return false;
  15. }
  16. let cmp = 0;
  17. for (let i = 0; i < this.length; i++) {
  18. cmp |= this[i] ^ other[i];
  19. }
  20. return cmp === 0;
  21. }
  22. toString(encoding = 'hex') {
  23. return mustGetEncoder(encoding)(this);
  24. }
  25. }
  26. //# sourceMappingURL=hash.js.map